Example usage for io.netty.handler.ssl SslProvider JDK

List of usage examples for io.netty.handler.ssl SslProvider JDK

Introduction

In this page you can find the example usage for io.netty.handler.ssl SslProvider JDK.

Prototype

SslProvider JDK

To view the source code for io.netty.handler.ssl SslProvider JDK.

Click Source Link

Document

JDK's default implementation.

Usage

From source file:org.apache.bookkeeper.tls.TLSContextFactory.java

License:Apache License

private SslProvider getTLSProvider(String sslProvider) {
    if (sslProvider.trim().equalsIgnoreCase("OpenSSL")) {
        if (OpenSsl.isAvailable()) {
            LOG.info("Security provider - OpenSSL");
            return SslProvider.OPENSSL;
        }//  w  ww. j a v  a2  s.  c  o m

        Throwable causeUnavailable = OpenSsl.unavailabilityCause();
        LOG.warn("OpenSSL Unavailable: ", causeUnavailable);

        LOG.info("Security provider - JDK");
        return SslProvider.JDK;
    }

    LOG.info("Security provider - JDK");
    return SslProvider.JDK;
}

From source file:org.apache.drill.exec.ssl.SSLConfigClient.java

License:Apache License

@Override
public SslProvider getProvider() {
    return provider.equalsIgnoreCase("JDK") ? SslProvider.JDK : SslProvider.OPENSSL;
}

From source file:org.apache.rocketmq.remoting.netty.TlsHelper.java

License:Apache License

public static SslContext buildSslContext(boolean forClient) throws IOException, CertificateException {
    File configFile = new File(TlsSystemConfig.tlsConfigFile);
    extractTlsConfigFromFile(configFile);
    logTheFinalUsedTlsConfig();//from   ww  w  .  ja v  a  2s .c  o  m

    SslProvider provider;
    if (OpenSsl.isAvailable()) {
        provider = SslProvider.OPENSSL;
        LOGGER.info("Using OpenSSL provider");
    } else {
        provider = SslProvider.JDK;
        LOGGER.info("Using JDK SSL provider");
    }

    if (forClient) {
        if (tlsTestModeEnable) {
            return SslContextBuilder.forClient().sslProvider(SslProvider.JDK)
                    .trustManager(InsecureTrustManagerFactory.INSTANCE).build();
        } else {
            SslContextBuilder sslContextBuilder = SslContextBuilder.forClient().sslProvider(SslProvider.JDK);

            if (!tlsClientAuthServer) {
                sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);
            } else {
                if (!isNullOrEmpty(tlsClientTrustCertPath)) {
                    sslContextBuilder.trustManager(new File(tlsClientTrustCertPath));
                }
            }

            return sslContextBuilder
                    .keyManager(
                            !isNullOrEmpty(tlsClientCertPath) ? new FileInputStream(tlsClientCertPath) : null,
                            !isNullOrEmpty(tlsClientKeyPath)
                                    ? decryptionStrategy.decryptPrivateKey(tlsClientKeyPath, true)
                                    : null,
                            !isNullOrEmpty(tlsClientKeyPassword) ? tlsClientKeyPassword : null)
                    .build();
        }
    } else {

        if (tlsTestModeEnable) {
            SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate();
            return SslContextBuilder
                    .forServer(selfSignedCertificate.certificate(), selfSignedCertificate.privateKey())
                    .sslProvider(SslProvider.JDK).clientAuth(ClientAuth.OPTIONAL).build();
        } else {
            SslContextBuilder sslContextBuilder = SslContextBuilder
                    .forServer(
                            !isNullOrEmpty(tlsServerCertPath) ? new FileInputStream(tlsServerCertPath) : null,
                            !isNullOrEmpty(tlsServerKeyPath)
                                    ? decryptionStrategy.decryptPrivateKey(tlsServerKeyPath, false)
                                    : null,
                            !isNullOrEmpty(tlsServerKeyPassword) ? tlsServerKeyPassword : null)
                    .sslProvider(provider);

            if (!tlsServerAuthClient) {
                sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);
            } else {
                if (!isNullOrEmpty(tlsServerTrustCertPath)) {
                    sslContextBuilder.trustManager(new File(tlsServerTrustCertPath));
                }
            }

            sslContextBuilder.clientAuth(parseClientAuthMode(tlsServerNeedClientAuth));
            return sslContextBuilder.build();
        }
    }
}

From source file:org.apache.tinkerpop.gremlin.driver.Cluster.java

License:Apache License

SslContext createSSLContext() throws Exception {
    // if the context is provided then just use that and ignore the other settings
    if (manager.sslContextOptional.isPresent())
        return manager.sslContextOptional.get();

    final SslProvider provider = SslProvider.JDK;
    final Settings.ConnectionPoolSettings connectionPoolSettings = connectionPoolSettings();
    final SslContextBuilder builder = SslContextBuilder.forClient();

    if (connectionPoolSettings.trustCertChainFile != null)
        builder.trustManager(new File(connectionPoolSettings.trustCertChainFile));
    else {/*from   w w  w. j  av a  2s.c o m*/
        logger.warn(
                "SSL configured without a trustCertChainFile and thus trusts all certificates without verification (not suitable for production)");
        builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
    }

    if (null != connectionPoolSettings.keyCertChainFile && null != connectionPoolSettings.keyFile) {
        final File keyCertChainFile = new File(connectionPoolSettings.keyCertChainFile);
        final File keyFile = new File(connectionPoolSettings.keyFile);

        // note that keyPassword may be null here if the keyFile is not password-protected.
        builder.keyManager(keyCertChainFile, keyFile, connectionPoolSettings.keyPassword);
    }

    builder.sslProvider(provider);

    return builder.build();
}

From source file:org.apache.tinkerpop.gremlin.server.AbstractChannelizer.java

License:Apache License

private SslContext createSSLContext(final Settings settings) {
    final Settings.SslSettings sslSettings = settings.ssl;

    if (sslSettings.getSslContext().isPresent()) {
        logger.info("Using the SslContext override");
        return sslSettings.getSslContext().get();
    }// w ww  .j a v a  2 s.co  m

    final SslProvider provider = SslProvider.JDK;

    final SslContextBuilder builder;

    // if the config doesn't contain a cert or key then use a self signed cert - not suitable for production
    if (null == sslSettings.keyCertChainFile || null == sslSettings.keyFile) {
        try {
            logger.warn("Enabling SSL with self-signed certificate (NOT SUITABLE FOR PRODUCTION)");
            final SelfSignedCertificate ssc = new SelfSignedCertificate();
            builder = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey());
        } catch (CertificateException ce) {
            logger.error("There was an error creating the self-signed certificate for SSL - SSL is not enabled",
                    ce);
            return null;
        }
    } else {
        final File keyCertChainFile = new File(sslSettings.keyCertChainFile);
        final File keyFile = new File(sslSettings.keyFile);
        final File trustCertChainFile = null == sslSettings.trustCertChainFile ? null
                : new File(sslSettings.trustCertChainFile);

        // note that keyPassword may be null here if the keyFile is not password-protected. passing null to
        // trustManager is also ok (default will be used)
        builder = SslContextBuilder.forServer(keyCertChainFile, keyFile, sslSettings.keyPassword)
                .trustManager(trustCertChainFile);
    }

    builder.sslProvider(provider);

    try {
        return builder.build();
    } catch (SSLException ssle) {
        logger.error("There was an error enabling SSL", ssle);
        return null;
    }
}

From source file:org.apache.tinkerpop.gremlin.server.GremlinServerIntegrateTest.java

License:Apache License

private static SslContext createServerSslContext() {
    final SslProvider provider = SslProvider.JDK;

    try {/*from w  w w  . j  av a  2  s  . c o m*/
        // this is not good for production - just testing
        final SelfSignedCertificate ssc = new SelfSignedCertificate();
        return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(provider).build();
    } catch (Exception ce) {
        throw new RuntimeException("Couldn't setup self-signed certificate for test");
    }
}

From source file:org.apache.tinkerpop.gremlin.server.GremlinServerIntegrateTest.java

License:Apache License

@Test
public void shouldEnableSslWithSslContextProgrammaticallySpecified() throws Exception {
    // just for testing - this is not good for production use
    final SslContextBuilder builder = SslContextBuilder.forClient();
    builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
    builder.sslProvider(SslProvider.JDK);

    final Cluster cluster = TestClientFactory.build().enableSsl(true).sslContext(builder.build()).create();
    final Client client = cluster.connect();

    try {/*w w w. j  av  a2  s  .com*/
        // this should return "nothing" - there should be no exception
        assertEquals("test", client.submit("'test'").one().getString());
    } finally {
        cluster.close();
    }
}

From source file:org.asynchttpclient.netty.ssl.DefaultSslEngineFactory.java

License:Open Source License

private SslContext buildSslContext(AsyncHttpClientConfig config) throws SSLException {
    if (config.getSslContext() != null)
        return config.getSslContext();

    SslContextBuilder sslContextBuilder = SslContextBuilder.forClient()//
            .sslProvider(config.isUseOpenSsl() ? SslProvider.OPENSSL : SslProvider.JDK)//
            .sessionCacheSize(config.getSslSessionCacheSize())//
            .sessionTimeout(config.getSslSessionTimeout());

    if (config.isAcceptAnyCertificate())
        sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);

    return configureSslContextBuilder(sslContextBuilder).build();
}

From source file:org.ballerinalang.test.util.http2.HTTP2Client.java

License:Open Source License

public HTTP2Client(boolean ssl, String host, int port) throws Exception {
    try {//from  w w  w.j a  v  a  2 s.c  om
        final SslContext sslCtx;
        if (ssl) {
            SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
            sslCtx = SslContextBuilder.forClient().sslProvider(provider)
                    .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
                    .trustManager(InsecureTrustManagerFactory.INSTANCE)
                    .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN,
                            // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
                            SelectorFailureBehavior.NO_ADVERTISE,
                            // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
                            SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2,
                            ApplicationProtocolNames.HTTP_1_1))
                    .build();
        } else {
            sslCtx = null;
        }
        workerGroup = new NioEventLoopGroup();
        HTTP2ClientInitializer initializer = new HTTP2ClientInitializer(sslCtx, Integer.MAX_VALUE);

        // Configure the client.
        Bootstrap b = new Bootstrap();
        b.group(workerGroup);
        b.channel(NioSocketChannel.class);
        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.remoteAddress(host, port);
        b.handler(initializer);

        // Start the client.
        channel = b.connect().syncUninterruptibly().channel();
        log.info("Connected to [" + host + ':' + port + ']');

        // Wait for the HTTP/2 upgrade to occur.
        HTTP2SettingsHandler http2SettingsHandler = initializer.settingsHandler();
        http2SettingsHandler.awaitSettings(TestConstant.HTTP2_RESPONSE_TIME_OUT,
                TestConstant.HTTP2_RESPONSE_TIME_UNIT);
        responseHandler = initializer.responseHandler();
        scheme = ssl ? HttpScheme.HTTPS : HttpScheme.HTTP;
        hostName = new AsciiString(host + ':' + port);
    } catch (Exception ex) {
        log.error("Error while initializing http2 client " + ex);
        this.close();
    }
}

From source file:org.curioswitch.common.server.framework.ServerModule.java

License:Open Source License

private static SslContextBuilder serverSslContext(InputStream keyCertChainFile, InputStream keyFile) {
    SslContextBuilder builder = SslContextKeyConverter.execute(keyCertChainFile, keyFile,
            (cert, key) -> SslContextBuilder.forServer(cert, key, null));
    return builder.sslProvider(Flags.useOpenSsl() ? SslProvider.OPENSSL : SslProvider.JDK)
            .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
            .applicationProtocolConfig(HTTPS_ALPN_CFG);
}