Example usage for io.netty.handler.ssl SslContext newClientContext

List of usage examples for io.netty.handler.ssl SslContext newClientContext

Introduction

In this page you can find the example usage for io.netty.handler.ssl SslContext newClientContext.

Prototype

@Deprecated
public static SslContext newClientContext(SslProvider provider, File trustCertCollectionFile,
        TrustManagerFactory trustManagerFactory, File keyCertChainFile, File keyFile, String keyPassword,
        KeyManagerFactory keyManagerFactory, Iterable<String> ciphers, CipherSuiteFilter cipherFilter,
        ApplicationProtocolConfig apn, long sessionCacheSize, long sessionTimeout) throws SSLException 

Source Link

Document

Creates a new client-side SslContext .

Usage

From source file:com.foilen.smalltools.net.netty.NettyClient.java

License:Open Source License

public void connect(String hostname, int port, final RSATrustedCertificates trustedCertificates,
        final RSACertificate certificate, final List<ChannelHandlerContainer> channelHandlerContainers) {

    AssertTools.assertNull(channel, "Client is already connected");

    try {//from  w  w  w . j a  va 2s.  c om
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(NettyCommon.EVENT_LOOP_GROUP);
        bootstrap.channel(NioSocketChannel.class);
        bootstrap.option(ChannelOption.SO_KEEPALIVE, true);

        bootstrap.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel socketChannel) throws Exception {

                // Add sslCtx if needed
                if (trustedCertificates != null || certificate != null) {
                    TrustManagerFactory trustManagerFactory = trustedCertificates == null ? null
                            : RSATools.createTrustManagerFactory(trustedCertificates);
                    KeyManagerFactory keyManagerFactory = certificate == null ? null
                            : RSATools.createKeyManagerFactory(certificate);

                    CipherSuiteFilter cipherFilter = IdentityCipherSuiteFilter.INSTANCE;
                    SslContext sslCtx = SslContext.newClientContext(SslProvider.JDK, null, trustManagerFactory,
                            null, null, null, keyManagerFactory, null, cipherFilter, null, 0, 0);
                    socketChannel.pipeline().addLast(sslCtx.newHandler(socketChannel.alloc()));
                }

                // Add the channel handlers
                for (ChannelHandlerContainer channelHandlerContainer : channelHandlerContainers) {
                    socketChannel.pipeline()
                            .addLast(ReflectionTools.instantiate(
                                    channelHandlerContainer.getChannelHandlerClass(),
                                    channelHandlerContainer.getConstructorParams()));
                }

            }
        });

        logger.info("Connecting to {}:{}", hostname, port);
        channel = bootstrap.connect(hostname, port).sync().channel();
    } catch (InterruptedException e) {
        logger.info("Connection to {}:{} was interrupted while being created", hostname, port);
        throw new SmallToolsException("Connection was interrupted");
    }

}

From source file:org.opendaylight.usc.manager.UscSecureServiceImpl.java

License:Open Source License

@Override
public ChannelOutboundHandler getTcpClientHandler(Channel ch) throws SSLException {
    SslContext sslClientCtx = SslContext.newClientContext(null, trustCertChainFile, null, publicCertChainFile,
            privateKeyFile, null, null, null, IdentityCipherSuiteFilter.INSTANCE, null, 0, 0);
    // mutual authentication as client
    return sslClientCtx.newHandler(ch.alloc());
}