Java Code Examples for io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder#trustManager()

The following examples show how to use io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder#trustManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrpcExecutionFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
private static NettyChannelBuilder createSecureChannel(
    String host, int port, Optional<Path> certPath, Optional<Path> keyPath, Optional<Path> caPath)
    throws SSLException {

  SslContextBuilder contextBuilder = GrpcSslContexts.forClient();
  if (certPath.isPresent() && keyPath.isPresent()) {
    contextBuilder.keyManager(certPath.get().toFile(), keyPath.get().toFile());
  }
  if (caPath.isPresent()) {
    contextBuilder.trustManager(caPath.get().toFile());
  }

  return channelBuilder(host, port)
      .sslContext(contextBuilder.build())
      .negotiationType(NegotiationType.TLS);
}
 
Example 2
Source File: GrpcConfig.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
private SslContextBuilder getSslContextBuilder() {
    log.info("Grpc config: Configuring ssl cert {} key {} trust {}",
            grpcProperties.getTls().getCertChainFile(), grpcProperties.getTls().getPrivateKeyFile(), grpcProperties.getTls().getTrustCertCollectionFile());

    SslContextBuilder sslClientContextBuilder = SslContextBuilder.forServer(
            new File(grpcProperties.getTls().getCertChainFile()),
            new File(grpcProperties.getTls().getPrivateKeyFile())
    );

    if (grpcProperties.getTls().getTrustCertCollectionFile() != null) {
        sslClientContextBuilder.trustManager(new File(grpcProperties.getTls().getTrustCertCollectionFile()));
        sslClientContextBuilder.clientAuth(ClientAuth.REQUIRE);
    }
    return GrpcSslContexts.configure(sslClientContextBuilder, SslProvider.OPENSSL);
}
 
Example 3
Source File: ClientGrpcConfig.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
private static SslContext buildSslContext(String trustCertCollectionFilePath,
                                          String clientCertChainFilePath,
                                          String clientPrivateKeyFilePath) throws SSLException {
    SslContextBuilder builder = GrpcSslContexts.forClient();
    if (trustCertCollectionFilePath != null) {
        builder.trustManager(new File(trustCertCollectionFilePath));
    }
    if (clientCertChainFilePath != null && clientPrivateKeyFilePath != null) {
        builder.keyManager(new File(clientCertChainFilePath), new File(clientPrivateKeyFilePath));
    }
    return builder.build();
}