Search in sources :

Example 11 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project load-balancer by RestComm.

the class ServerChannelConnector method channelConnected.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    Channel channel = e.getChannel();
    channels.add(channel);
    if (configuration.isUseSsl()) {
        SslConfiguration sslConfig = configuration.getSslConfiguration();
        if (sslConfig == null)
            throw new IllegalStateException("sslConfiguration must be set");
        SslContextFactory factory = new SslContextFactory(sslConfig);
        SSLEngine sslEngine = factory.newSslEngine();
        sslEngine.setUseClientMode(false);
        channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine));
    }
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_PDU_DECODER_NAME, new SmppSessionPduDecoder(new DefaultPduTranscoder(new DefaultPduTranscoderContext())));
    ServerConnectionImpl serverConnectionImpl = new ServerConnectionImpl(server.nextSessionId(), channel, lbServerListener, balancerRunner, monitorExecutor, configuration.isUseSsl());
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRAPPER_NAME, new ServerConnectionHandlerImpl(serverConnectionImpl));
}
Also used : SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SSLEngine(javax.net.ssl.SSLEngine) SmppSessionPduDecoder(com.cloudhopper.smpp.channel.SmppSessionPduDecoder) Channel(org.jboss.netty.channel.Channel) DefaultPduTranscoderContext(com.cloudhopper.smpp.transcoder.DefaultPduTranscoderContext) DefaultPduTranscoder(com.cloudhopper.smpp.transcoder.DefaultPduTranscoder) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 12 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project load-balancer by RestComm.

the class MServerChannelConnector method channelConnected.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    Channel channel = e.getChannel();
    channels.add(channel);
    if (configuration.isUseSsl()) {
        SslConfiguration sslConfig = configuration.getSslConfiguration();
        if (sslConfig == null)
            throw new IllegalStateException("sslConfiguration must be set");
        SslContextFactory factory = new SslContextFactory(sslConfig);
        SSLEngine sslEngine = factory.newSslEngine();
        sslEngine.setUseClientMode(false);
        channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine));
    }
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_PDU_DECODER_NAME, new SmppSessionPduDecoder(new DefaultPduTranscoder(new DefaultPduTranscoderContext())));
    MServerConnectionImpl serverConnectionImpl = new MServerConnectionImpl(server.nextSessionId(), channel, lbServerListener, balancerRunner, monitorExecutor, configuration.isUseSsl());
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRAPPER_NAME, new MServerConnectionHandlerImpl(serverConnectionImpl));
}
Also used : SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SSLEngine(javax.net.ssl.SSLEngine) SmppSessionPduDecoder(com.cloudhopper.smpp.channel.SmppSessionPduDecoder) Channel(org.jboss.netty.channel.Channel) DefaultPduTranscoderContext(com.cloudhopper.smpp.transcoder.DefaultPduTranscoderContext) DefaultPduTranscoder(com.cloudhopper.smpp.transcoder.DefaultPduTranscoder) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 13 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project load-balancer by RestComm.

the class MClientConnectionImpl method connect.

@Override
public Boolean connect() {
    // prevent create connection if it's already established https://github.com/RestComm/load-balancer/issues/95
    if (channelFuture != null && channelFuture.getChannel().isConnected()) {
        // if(logger.isDebugEnabled())
        logger.info("LB trying to connect to server but connection is already established so we disconnect it" + "channel is: " + channelFuture.getChannel().getRemoteAddress().toString());
        channelFuture.getChannel().disconnect();
    }
    try {
        if (logger.isDebugEnabled())
            logger.debug("LB trying to connect to server " + config.getHost() + " " + config.getPort());
        channelFuture = clientBootstrap.connect(new InetSocketAddress(config.getHost(), config.getPort()), new InetSocketAddress(localSmppAddress, 0)).sync();
        channel = channelFuture.getChannel();
        if (config.isUseSsl()) {
            isSslConnection = true;
            SslConfiguration sslConfig = config.getSslConfiguration();
            if (sslConfig == null)
                throw new IllegalStateException("sslConfiguration must be set");
            try {
                SslContextFactory factory = new SslContextFactory(sslConfig);
                SSLEngine sslEngine = factory.newSslEngine();
                sslEngine.setUseClientMode(true);
                channel.getPipeline().addFirst(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine));
            } catch (Exception e) {
                logger.error("Unable to create SSL session: " + e.getMessage(), e);
            }
        }
    } catch (Exception ex) {
        return false;
    }
    if (clientState != ClientState.REBINDING)
        clientState = ClientState.OPEN;
    return true;
}
Also used : SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) SslHandler(org.jboss.netty.handler.ssl.SslHandler) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException)

Example 14 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project zookeeper by apache.

the class NettyServerCnxnFactory method initSSL.

private synchronized void initSSL(ChannelPipeline p) throws X509Exception, KeyManagementException, NoSuchAlgorithmException {
    String authProviderProp = System.getProperty(ZKConfig.SSL_AUTHPROVIDER);
    SSLContext sslContext;
    if (authProviderProp == null) {
        sslContext = X509Util.createSSLContext();
    } else {
        sslContext = SSLContext.getInstance("TLSv1");
        X509AuthenticationProvider authProvider = (X509AuthenticationProvider) ProviderRegistry.getProvider(System.getProperty(ZKConfig.SSL_AUTHPROVIDER, "x509"));
        if (authProvider == null) {
            LOG.error("Auth provider not found: {}", authProviderProp);
            throw new SSLContextException("Could not create SSLContext with specified auth provider: " + authProviderProp);
        }
        sslContext.init(new X509KeyManager[] { authProvider.getKeyManager() }, new X509TrustManager[] { authProvider.getTrustManager() }, null);
    }
    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(false);
    sslEngine.setNeedClientAuth(true);
    p.addLast("ssl", new SslHandler(sslEngine));
    LOG.info("SSL handler added for channel: {}", p.getChannel());
}
Also used : X509AuthenticationProvider(org.apache.zookeeper.server.auth.X509AuthenticationProvider) SSLEngine(javax.net.ssl.SSLEngine) SSLContextException(org.apache.zookeeper.common.X509Exception.SSLContextException) SSLContext(javax.net.ssl.SSLContext) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 15 with SslHandler

use of org.jboss.netty.handler.ssl.SslHandler in project graylog2-server by Graylog2.

the class AbstractTcpTransport method buildSslHandlerCallable.

private Callable<ChannelHandler> buildSslHandlerCallable() {
    return new Callable<ChannelHandler>() {

        @Override
        public ChannelHandler call() throws Exception {
            try {
                return new SslHandler(createSslEngine());
            } catch (SSLException e) {
                LOG.error("Error creating SSL context. Make sure the certificate and key are in the correct format: cert=X.509 key=PKCS#8");
                throw e;
            }
        }

        private SSLEngine createSslEngine() throws IOException, GeneralSecurityException {
            final SSLContext instance = SSLContext.getInstance("TLS");
            TrustManager[] initTrustStore = new TrustManager[0];
            if (TLS_CLIENT_AUTH_OPTIONAL.equals(tlsClientAuth) || TLS_CLIENT_AUTH_REQUIRED.equals(tlsClientAuth)) {
                if (tlsClientAuthCertFile.exists()) {
                    initTrustStore = KeyUtil.initTrustStore(tlsClientAuthCertFile);
                } else {
                    LOG.warn("client auth configured, but no authorized certificates / certificate authorities configured");
                }
            }
            instance.init(KeyUtil.initKeyStore(tlsKeyFile, tlsCertFile, tlsKeyPassword), initTrustStore, new SecureRandom());
            final SSLEngine engine = instance.createSSLEngine();
            engine.setUseClientMode(false);
            switch(tlsClientAuth) {
                case TLS_CLIENT_AUTH_DISABLED:
                    LOG.debug("Not using TLS client authentication");
                    break;
                case TLS_CLIENT_AUTH_OPTIONAL:
                    LOG.debug("Using optional TLS client authentication");
                    engine.setWantClientAuth(true);
                    break;
                case TLS_CLIENT_AUTH_REQUIRED:
                    LOG.debug("Using mandatory TLS client authentication");
                    engine.setNeedClientAuth(true);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown TLS client authentication mode: " + tlsClientAuth);
            }
            return engine;
        }
    };
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) SSLException(javax.net.ssl.SSLException) Callable(java.util.concurrent.Callable) SslHandler(org.jboss.netty.handler.ssl.SslHandler) TrustManager(javax.net.ssl.TrustManager)

Aggregations

SslHandler (org.jboss.netty.handler.ssl.SslHandler)24 SSLEngine (javax.net.ssl.SSLEngine)16 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)10 SslConfiguration (com.cloudhopper.smpp.ssl.SslConfiguration)8 SslContextFactory (com.cloudhopper.smpp.ssl.SslContextFactory)8 InetSocketAddress (java.net.InetSocketAddress)7 ChannelHandler (org.jboss.netty.channel.ChannelHandler)5 Channel (org.jboss.netty.channel.Channel)4 ChannelFuture (org.jboss.netty.channel.ChannelFuture)4 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)4 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)4 SmppSessionPduDecoder (com.cloudhopper.smpp.channel.SmppSessionPduDecoder)3 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)3 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)3 SocketAddress (java.net.SocketAddress)3 SSLContext (javax.net.ssl.SSLContext)3 DefaultPduTranscoder (com.cloudhopper.smpp.transcoder.DefaultPduTranscoder)2 DefaultPduTranscoderContext (com.cloudhopper.smpp.transcoder.DefaultPduTranscoderContext)2 Executor (java.util.concurrent.Executor)2 ChannelHandlerFactory (org.apache.camel.component.netty.ChannelHandlerFactory)2