use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project pinpoint by naver.
the class PinpointNettyServerBuilder method useTransportSecurity.
@Override
public PinpointNettyServerBuilder useTransportSecurity(InputStream certChain, InputStream privateKey) {
checkState(!freezeProtocolNegotiatorFactory, "Cannot change security when using ServerCredentials");
SslContext sslContext;
try {
sslContext = GrpcSslContexts.forServer(certChain, privateKey).build();
} catch (SSLException e) {
// This should likely be some other, easier to catch exception.
throw new RuntimeException(e);
}
protocolNegotiatorFactory = ProtocolNegotiators.serverTlsFactory(sslContext);
return this;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project pinpoint by naver.
the class DefaultChannelFactory method build.
@Override
public ManagedChannel build(String channelName, String host, int port) {
final NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
channelBuilder.usePlaintext();
logger.info("ChannelType:{}", channelType.getSimpleName());
channelBuilder.channelType(channelType);
channelBuilder.eventLoopGroup(eventLoopGroup);
setupInternal(channelBuilder);
channelBuilder.defaultLoadBalancingPolicy(GrpcUtil.DEFAULT_LB_POLICY);
addHeader(channelBuilder);
addClientInterceptor(channelBuilder);
channelBuilder.executor(executorService);
if (nameResolverProvider != null) {
logger.info("Set nameResolverProvider {}. channelName={}, host={}, port={}", this.nameResolverProvider, channelName, host, port);
setNameResolverFactory(channelBuilder, this.nameResolverProvider);
}
setupClientOption(channelBuilder);
if (sslClientConfig.isEnable()) {
SslContext sslContext = null;
try {
sslContext = SslContextFactory.create(sslClientConfig);
} catch (SSLException e) {
throw new SecurityException(e);
}
channelBuilder.sslContext(sslContext);
channelBuilder.negotiationType(NegotiationType.TLS);
}
channelBuilder.maxTraceEvents(clientOption.getMaxTraceEvent());
final ManagedChannel channel = channelBuilder.build();
return channel;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project pinpoint by naver.
the class SslContextFactory method create.
public static SslContext create(SslClientConfig clientConfig) throws SSLException {
Objects.requireNonNull(clientConfig, "clientConfig");
if (!clientConfig.isEnable()) {
throw new IllegalArgumentException("sslConfig is disabled.");
}
SslProvider sslProvider = getSslProvider(clientConfig.getSslProviderType());
SslContextBuilder sslContextBuilder = null;
try {
sslContextBuilder = SslContextBuilder.forClient();
Resource trustCertResource = clientConfig.getTrustCertResource();
if (trustCertResource != null) {
sslContextBuilder.trustManager(trustCertResource.getInputStream());
} else {
// Loads default Root CA certificates (generally, from JAVA_HOME/lib/cacerts)
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
sslContextBuilder.trustManager(trustManagerFactory);
}
SslContext sslContext = createSslContext(sslContextBuilder, sslProvider);
assertValidCipherSuite(sslContext);
return sslContext;
} catch (SSLException e) {
throw e;
} catch (Exception e) {
throw new SSLException(e);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project instrumentation-java by census-instrumentation.
the class OcAgentMetricsExporterConfigurationTest method setAndGet.
@Test
public void setAndGet() throws SSLException {
Duration oneMinute = Duration.create(60, 0);
Duration fiveMinutes = Duration.create(300, 0);
SslContext sslContext = SslContextBuilder.forClient().build();
OcAgentMetricsExporterConfiguration configuration = OcAgentMetricsExporterConfiguration.builder().setEndPoint("192.168.0.1:50051").setServiceName("service").setUseInsecure(false).setSslContext(sslContext).setRetryInterval(fiveMinutes).setExportInterval(oneMinute).build();
assertThat(configuration.getEndPoint()).isEqualTo("192.168.0.1:50051");
assertThat(configuration.getServiceName()).isEqualTo("service");
assertThat(configuration.getUseInsecure()).isFalse();
assertThat(configuration.getSslContext()).isEqualTo(sslContext);
assertThat(configuration.getRetryInterval()).isEqualTo(fiveMinutes);
assertThat(configuration.getExportInterval()).isEqualTo(oneMinute);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext in project netty by netty.
the class OcspTest method testServerOcspNotEnabled.
private static void testServerOcspNotEnabled(SslProvider sslProvider) throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
try {
SslContext context = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(sslProvider).build();
try {
SslHandler sslHandler = context.newHandler(ByteBufAllocator.DEFAULT);
final ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
try {
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
engine.setOcspResponse(new byte[] { 1, 2, 3 });
}
});
} finally {
engine.release();
}
} finally {
ReferenceCountUtil.release(context);
}
} finally {
ssc.delete();
}
}
Aggregations