Search in sources :

Example 1 with Resource

use of com.navercorp.pinpoint.grpc.util.Resource 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);
    }
}
Also used : SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Resource(com.navercorp.pinpoint.grpc.util.Resource) SslProvider(io.netty.handler.ssl.SslProvider) SSLException(javax.net.ssl.SSLException) SSLException(javax.net.ssl.SSLException) SslContext(io.netty.handler.ssl.SslContext)

Example 2 with Resource

use of com.navercorp.pinpoint.grpc.util.Resource in project pinpoint by naver.

the class SslContextFactory method create.

public static SslContext create(SslServerConfig serverConfig) throws SSLException {
    Objects.requireNonNull(serverConfig, "serverConfig");
    SslProvider sslProvider = getSslProvider(serverConfig.getSslProviderType());
    SslContextBuilder sslContextBuilder;
    try {
        Resource keyCertChainFileResource = serverConfig.getKeyCertChainResource();
        Resource keyResource = serverConfig.getKeyResource();
        sslContextBuilder = SslContextBuilder.forServer(keyCertChainFileResource.getInputStream(), keyResource.getInputStream());
        SslContext sslContext = createSslContext(sslContextBuilder, sslProvider);
        assertValidCipherSuite(sslContext);
        return sslContext;
    } catch (SSLException e) {
        throw e;
    } catch (Exception e) {
        throw new SSLException(e);
    }
}
Also used : SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) Resource(com.navercorp.pinpoint.grpc.util.Resource) SslProvider(io.netty.handler.ssl.SslProvider) SSLException(javax.net.ssl.SSLException) SSLException(javax.net.ssl.SSLException) SslContext(io.netty.handler.ssl.SslContext)

Example 3 with Resource

use of com.navercorp.pinpoint.grpc.util.Resource in project pinpoint by naver.

the class DefaultChannelFactoryBuilder method build.

@Override
public ChannelFactory build() {
    logger.info("build ChannelFactory:{}", factoryName);
    Objects.requireNonNull(headerFactory, "headerFactory");
    Objects.requireNonNull(clientOption, "clientOption");
    SslClientConfig sslClientConfig = SslClientConfig.DISABLED_CONFIG;
    if (sslOption != null && sslOption.isEnable()) {
        String providerType = sslOption.getProviderType();
        Resource trustCertResource = sslOption.getTrustCertResource();
        sslClientConfig = new SslClientConfig(true, providerType, trustCertResource);
    }
    return new DefaultChannelFactory(factoryName, executorQueueSize, headerFactory, nameResolverProvider, clientOption, sslClientConfig, clientInterceptorList);
}
Also used : SslClientConfig(com.navercorp.pinpoint.grpc.security.SslClientConfig) Resource(com.navercorp.pinpoint.grpc.util.Resource)

Aggregations

Resource (com.navercorp.pinpoint.grpc.util.Resource)3 SslContext (io.netty.handler.ssl.SslContext)2 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)2 SslProvider (io.netty.handler.ssl.SslProvider)2 SSLException (javax.net.ssl.SSLException)2 SslClientConfig (com.navercorp.pinpoint.grpc.security.SslClientConfig)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1