本文整理汇总了Java中io.grpc.netty.GrpcSslContexts类的典型用法代码示例。如果您正苦于以下问题:Java GrpcSslContexts类的具体用法?Java GrpcSslContexts怎么用?Java GrpcSslContexts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GrpcSslContexts类属于io.grpc.netty包,在下文中一共展示了GrpcSslContexts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws IOException {
AfricasTalking.initialize(Fixtures.USERNAME, Fixtures.API_KEY);
server = new Server(new Authenticator() {
@Override
public boolean authenticate(String client) {
return client.compareToIgnoreCase(TEST_CLIENT_ID) == 0;
}
});
server.addSipCredentials("test", "secret", "sip://at.dev");
server.start(certFile, privateKeyFile, TEST_PORT);
ManagedChannel ch = NettyChannelBuilder.forAddress("localhost", TEST_PORT)
.sslContext(GrpcSslContexts.forClient().trustManager(certFile).build())
.build();
client = SdkServerServiceGrpc.newBlockingStub(ch)
.withCallCredentials(new CallCredentials(){
@Override
public void applyRequestMetadata(MethodDescriptor<?, ?> method, Attributes attrs, Executor appExecutor,
final MetadataApplier applier) {
appExecutor.execute(new Runnable(){
@Override
public void run() {
try {
Metadata headers = new Metadata();
Metadata.Key<String> clientIdKey = Metadata.Key.of("X-Client-Id", Metadata.ASCII_STRING_MARSHALLER);
headers.put(clientIdKey, TEST_CLIENT_ID);
applier.apply(headers);
} catch(Throwable ex) {
applier.fail(Status.UNAUTHENTICATED.withCause(ex));
}
}
});
}
});
}
示例2: getGenomicsManagedChannel
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
private static ManagedChannel getGenomicsManagedChannel(List<ClientInterceptor> interceptors)
throws SSLException {
// Java 8's implementation of GCM ciphers is extremely slow. Therefore we disable
// them here.
List<String> defaultCiphers = GrpcSslContexts.forClient().ciphers(null).build().cipherSuites();
List<String> performantCiphers = new ArrayList<>();
for (String cipher : defaultCiphers) {
if (!cipher.contains("GCM")) {
performantCiphers.add(cipher);
}
}
return NettyChannelBuilder.forAddress(GENOMICS_ENDPOINT, 443)
.negotiationType(NegotiationType.TLS)
.sslContext(GrpcSslContexts.forClient().ciphers(performantCiphers).build())
.intercept(interceptors)
.build();
}
示例3: createSslContext
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
private synchronized static SslContext createSslContext() throws SSLException {
if (sslBuilder == null) {
sslBuilder = GrpcSslContexts.forClient().ciphers(null);
// gRPC uses tcnative / OpenSsl by default, if it's available. It defaults to alpn-boot
// if tcnative is not in the classpath.
if (OpenSsl.isAvailable()) {
LOG.info(
"SslContext: gRPC is using the OpenSSL provider (tcnactive jar - Open Ssl version: {})",
OpenSsl.versionString());
} else {
if (isJettyAlpnConfigured()) {
// gRPC uses jetty ALPN as a backup to tcnative.
LOG.info("SslContext: gRPC is using the JDK provider (alpn-boot jar)");
} else {
LOG.info("SslContext: gRPC cannot be configured. Neither OpenSsl nor Alpn are available.");
}
}
}
return sslBuilder.build();
}
示例4: newClient
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@Override
public PubsubClient newClient(
@Nullable String timestampAttribute, @Nullable String idAttribute, PubsubOptions options)
throws IOException {
ManagedChannel channel = NettyChannelBuilder
.forAddress(PUBSUB_ADDRESS, PUBSUB_PORT)
.negotiationType(NegotiationType.TLS)
.sslContext(GrpcSslContexts.forClient().ciphers(null).build())
.build();
return new PubsubGrpcClient(timestampAttribute,
idAttribute,
DEFAULT_TIMEOUT_S,
channel,
options.getGcpCredential());
}
示例5: startServer
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
/** Starts the server with HTTPS. */
@BeforeClass
public static void startServer() throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
ssc = new SelfSignedCertificate("example.com");
ServerBuilder sb = new ServerBuilder()
.port(0, SessionProtocol.HTTPS)
.defaultMaxRequestLength(16 * 1024 * 1024)
.sslContext(GrpcSslContexts.forServer(ssc.certificate(), ssc.privateKey())
.applicationProtocolConfig(ALPN)
.trustManager(TestUtils.loadCert("ca.pem"))
.build());
final ArmeriaGrpcServerBuilder builder = new ArmeriaGrpcServerBuilder(sb, new GrpcServiceBuilder(),
ctxCapture);
startStaticServer(builder);
server = builder.builtServer();
}
示例6: start
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@VisibleForTesting
void start() throws Exception {
executor = Executors.newSingleThreadScheduledExecutor();
SslContext sslContext = null;
if (useTls) {
sslContext = GrpcSslContexts.forServer(
TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")).build();
}
server = NettyServerBuilder.forPort(port)
.sslContext(sslContext)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.addService(ServerInterceptors.intercept(
new TestServiceImpl(executor),
TestServiceImpl.interceptors()))
.build().start();
}
示例7: newServer
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
/**
* Creates and starts a new {@link TestServiceImpl} server.
*/
private Server newServer() throws CertificateException, IOException {
File serverCertChainFile = TestUtils.loadCert("server1.pem");
File serverPrivateKeyFile = TestUtils.loadCert("server1.key");
X509Certificate[] serverTrustedCaCerts = {
TestUtils.loadX509Cert("ca.pem")
};
SslContext sslContext =
GrpcSslContexts.forServer(serverCertChainFile, serverPrivateKeyFile)
.trustManager(serverTrustedCaCerts)
.clientAuth(ClientAuth.REQUIRE)
.build();
return NettyServerBuilder.forPort(0)
.sslContext(sslContext)
.addService(new TestServiceImpl(serverExecutor))
.build()
.start();
}
示例8: newClientChannel
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
private ManagedChannel newClientChannel() throws CertificateException, IOException {
File clientCertChainFile = TestUtils.loadCert("client.pem");
File clientPrivateKeyFile = TestUtils.loadCert("client.key");
X509Certificate[] clientTrustedCaCerts = {
TestUtils.loadX509Cert("ca.pem")
};
SslContext sslContext =
GrpcSslContexts.forClient()
.keyManager(clientCertChainFile, clientPrivateKeyFile)
.trustManager(clientTrustedCaCerts)
.build();
return NettyChannelBuilder.forAddress("localhost", server.getPort())
.overrideAuthority(TestUtils.TEST_SERVER_HOST)
.negotiationType(NegotiationType.TLS)
.sslContext(sslContext)
.build();
}
示例9: getServerBuilder
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
// Starts the server with HTTPS.
try {
SslProvider sslProvider = SslContext.defaultServerProvider();
if (sslProvider == SslProvider.OPENSSL && !OpenSsl.isAlpnSupported()) {
// OkHttp only supports Jetty ALPN on OpenJDK. So if OpenSSL doesn't support ALPN, then we
// are forced to use Jetty ALPN for Netty instead of OpenSSL.
sslProvider = SslProvider.JDK;
}
SslContextBuilder contextBuilder = SslContextBuilder
.forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"));
GrpcSslContexts.configure(contextBuilder, sslProvider);
contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE);
return NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(contextBuilder.build());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例10: setUp
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@Before
public void setUp() throws NoSuchAlgorithmException {
executor = Executors.newSingleThreadScheduledExecutor();
if (sslProvider == SslProvider.OPENSSL) {
Assume.assumeTrue(OpenSsl.isAvailable());
}
if (sslProvider == SslProvider.JDK) {
Assume.assumeTrue(Arrays.asList(
SSLContext.getDefault().getSupportedSSLParameters().getCipherSuites())
.contains("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
try {
GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.JDK);
} catch (IllegalArgumentException ex) {
Assume.assumeNoException("Jetty ALPN does not seem available", ex);
}
}
clientContextBuilder = GrpcSslContexts.configure(SslContextBuilder.forClient(), sslProvider);
}
示例11: getServerBuilder
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
// Starts the server with HTTPS.
try {
return NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024)
.maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(GrpcSslContexts
.forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
.clientAuth(ClientAuth.REQUIRE)
.trustManager(TestUtils.loadCert("ca.pem"))
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
.sslProvider(SslProvider.OPENSSL)
.build());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例12: createChannel
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
@Override
protected ManagedChannel createChannel() {
try {
NettyChannelBuilder builder = NettyChannelBuilder
.forAddress(TestUtils.testServerAddress(getPort()))
.flowControlWindow(65 * 1024)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
.sslContext(GrpcSslContexts
.forClient()
.keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key"))
.trustManager(TestUtils.loadX509Cert("ca.pem"))
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
.sslProvider(SslProvider.OPENSSL)
.build());
io.grpc.internal.TestingAccessor.setStatsImplementation(
builder, createClientCensusStatsModule());
return builder.build();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例13: initCache
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
private static LoadingCache<UserAuth, String> initCache() {
try {
currentAuth = ApprcHolder.get().currentAuth();
URI uri = new URI(currentAuth.getApiserver());
logger.info(String.format("Connecting to apiserver: %s host: %s port: %s",
currentAuth.getApiserver(), uri.getHost(), uri.getPort()));
NettyChannelBuilder builder = NettyChannelBuilder
.forAddress(uri.getHost(), uri.getPort())
.nameResolverFactory(new DnsNameResolverProvider());
if (useTLS(currentAuth)) {
File trustCertCollectionFile = null;
builder
.sslContext(GrpcSslContexts.forClient().trustManager(trustCertCollectionFile).build())
.negotiationType(NegotiationType.TLS);
} else {
builder.negotiationType(NegotiationType.PLAINTEXT);
}
channel = builder.build();
return CacheBuilder.newBuilder()
.expireAfterAccess(DESCRIPTOR.getAuthCacheTtl(), TimeUnit.SECONDS)
.build(
new CacheLoader<UserAuth, String>() {
@Override
public String load(UserAuth key) throws Exception {
if (isToken(key.getSecret())) {
return checkToken(key.getUsername(),
key.getSecret().substring(BEARER_PREFIX.length()));
}
return checkPassword(key.getUsername(), key.getSecret());
}
}
);
} catch (URISyntaxException | SSLException e) {
logger.log(Level.SEVERE, e.getMessage());
}
return null;
}
示例14: configureSsl
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
private void configureSsl(NettyServerBuilder builder) throws NoSuchAlgorithmException, CertificateEncodingException, NoSuchProviderException, InvalidKeyException, SignatureException, SSLException {
NativeLibraryLoader.loadFirstAvailable(ClassLoader.getSystemClassLoader(),
"netty_tcnative_osx_x86_64",
"netty_tcnative_linux_x86_64",
"netty_tcnative_windows_x86_64"
);
ECKeyPair ecKeyPair = ethereumConfig.getMainCredentials().getEcKeyPair();
KeyPair keyPair = CryptoUtil.decodeKeyPair(ecKeyPair);
SslContextBuilder contextBuilder = SslContextBuilder.forServer(
keyPair.getPrivate(),
CryptoUtil.genCert(keyPair)
);
builder.sslContext(GrpcSslContexts.configure(contextBuilder).build());
}
示例15: buildClientSslContext
import io.grpc.netty.GrpcSslContexts; //导入依赖的package包/类
private SslContext buildClientSslContext() {
try {
InputStream certs = SslUtil.loadInputStreamCert("server.pem");
return GrpcSslContexts
.configure(SslContextBuilder.forClient()//
.trustManager(certs))//
.build();
} catch (SSLException e) {
throw new RpcFrameworkException(e);
}
}