Search in sources :

Example 1 with SslConfiguration

use of com.cloudhopper.smpp.ssl.SslConfiguration 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 2 with SslConfiguration

use of com.cloudhopper.smpp.ssl.SslConfiguration 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 3 with SslConfiguration

use of com.cloudhopper.smpp.ssl.SslConfiguration 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 4 with SslConfiguration

use of com.cloudhopper.smpp.ssl.SslConfiguration in project load-balancer by RestComm.

the class HttpClientPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    pipeline.addLast("decoder", new HttpResponseDecoder());
    // Remove the following line if you don't want automatic content decompression.
    // pipeline.addLast("inflater", new HttpContentDecompressor());
    pipeline.addLast("encoder", new HttpRequestEncoder());
    // http://code.google.com/p/commscale/issues/detail?id=5 support for HttpChunks,
    // https://telestax.atlassian.net/browse/LB-8 if commented accessing the RestComm Management console fails, so making the maxContentLength Configurable
    // pipeline.addLast("aggregator", new HttpChunkAggregator(maxContentLength));
    pipeline.addLast("handler", new HttpResponseHandler(balancerRunner));
    if (isUseSsl) {
        SslConfiguration sslConfig = new SslConfiguration();
        sslConfig.setTrustAll(true);
        sslConfig.setValidateCerts(true);
        sslConfig.setValidatePeerCerts(true);
        SslContextFactory factory = new SslContextFactory(sslConfig);
        SSLEngine sslEngine = factory.newSslEngine();
        sslEngine.setUseClientMode(true);
        pipeline.addFirst("ssl", new SslHandler(sslEngine));
    }
    return pipeline;
}
Also used : SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SSLEngine(javax.net.ssl.SSLEngine) HttpRequestEncoder(org.jboss.netty.handler.codec.http.HttpRequestEncoder) HttpResponseDecoder(org.jboss.netty.handler.codec.http.HttpResponseDecoder) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 5 with SslConfiguration

use of com.cloudhopper.smpp.ssl.SslConfiguration in project load-balancer by RestComm.

the class HttpServerPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    if (isSecure) {
        SslConfiguration sslConfig = new SslConfiguration();
        sslConfig.setKeyStorePath(balancerRunner.balancerContext.lbConfig.getSslConfiguration().getKeyStore());
        sslConfig.setKeyStorePassword(balancerRunner.balancerContext.lbConfig.getSslConfiguration().getKeyStorePassword());
        sslConfig.setTrustStorePath(balancerRunner.balancerContext.lbConfig.getSslConfiguration().getTrustStore());
        sslConfig.setTrustStorePassword(balancerRunner.balancerContext.lbConfig.getSslConfiguration().getTrustStorePassword());
        String sProtocols = balancerRunner.balancerContext.lbConfig.getSslConfiguration().getTlsClientProtocols();
        String sCipherSuites = balancerRunner.balancerContext.lbConfig.getSslConfiguration().getEnabledCipherSuites();
        if (sProtocols != null) {
            String[] protocols = sProtocols.split(",");
            sslConfig.setIncludeProtocols(protocols);
        }
        if (sCipherSuites != null) {
            String[] cipherSuites = sCipherSuites.split(",");
            sslConfig.setIncludeCipherSuites(cipherSuites);
        }
        SslContextFactory factory = new SslContextFactory(sslConfig);
        SSLEngine sslEngine = factory.newSslEngine();
        sslEngine.setUseClientMode(false);
        pipeline.addLast("ssl", new SslHandler(sslEngine));
    }
    pipeline.addLast("decoder", new HttpRequestDecoder());
    // http://code.google.com/p/commscale/issues/detail?id=5 support for HttpChunks
    // https://telestax.atlassian.net/browse/LB-8 if commented accessing the RestComm Management console fails, so making the maxContentLength Configurable
    // pipeline.addLast("aggregator", new HttpChunkAggregator(maxContentLength));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    // pipeline.addLast("deflater", new HttpContentCompressor());
    if (balancerRunner.balancerContext.terminateTLSTraffic)
        pipeline.addLast("handler", new HttpRequestHandler(balancerRunner, false));
    else
        pipeline.addLast("handler", new HttpRequestHandler(balancerRunner, isSecure));
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SSLEngine(javax.net.ssl.SSLEngine) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Aggregations

SslConfiguration (com.cloudhopper.smpp.ssl.SslConfiguration)10 SslContextFactory (com.cloudhopper.smpp.ssl.SslContextFactory)7 SSLEngine (javax.net.ssl.SSLEngine)7 SslHandler (org.jboss.netty.handler.ssl.SslHandler)7 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)3 SmppServerConfiguration (com.cloudhopper.smpp.SmppServerConfiguration)2 SmppSessionPduDecoder (com.cloudhopper.smpp.channel.SmppSessionPduDecoder)2 DefaultPduTranscoder (com.cloudhopper.smpp.transcoder.DefaultPduTranscoder)2 DefaultPduTranscoderContext (com.cloudhopper.smpp.transcoder.DefaultPduTranscoderContext)2 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)2 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)2 InetSocketAddress (java.net.InetSocketAddress)2 Channel (org.jboss.netty.channel.Channel)2 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)2 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)2 SmppSessionConfiguration (com.cloudhopper.smpp.SmppSessionConfiguration)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 HttpChunkAggregator (org.jboss.netty.handler.codec.http.HttpChunkAggregator)1 HttpRequestEncoder (org.jboss.netty.handler.codec.http.HttpRequestEncoder)1 HttpResponseDecoder (org.jboss.netty.handler.codec.http.HttpResponseDecoder)1