Search in sources :

Example 66 with SslHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project hive by apache.

the class ShuffleHandler method initPipeline.

private void initPipeline(ServerBootstrap bootstrap, Configuration conf) throws Exception {
    SHUFFLE = getShuffle(conf);
    // TODO Setup SSL Shuffle
    // if (conf.getBoolean(MRConfig.SHUFFLE_SSL_ENABLED_KEY,
    // MRConfig.SHUFFLE_SSL_ENABLED_DEFAULT)) {
    // LOG.info("Encrypted shuffle is enabled.");
    // sslFactory = new SSLFactory(SSLFactory.Mode.SERVER, conf);
    // sslFactory.init();
    // }
    ChannelInitializer<NioSocketChannel> channelInitializer = new ChannelInitializer<NioSocketChannel>() {

        @Override
        public void initChannel(NioSocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            if (sslFactory != null) {
                pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
            }
            pipeline.addLast("decoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpObjectAggregator(1 << 16));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("chunking", new ChunkedWriteHandler());
            pipeline.addLast("shuffle", SHUFFLE);
            pipeline.addLast("idle", new IdleStateHandler(0, connectionKeepAliveTimeOut, 0));
            pipeline.addLast(TIMEOUT_HANDLER, new TimeoutHandler());
        }
    };
    bootstrap.childHandler(channelInitializer);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 67 with SslHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project apn-proxy by apn-proxy.

the class ApnProxyRemoteForwardChannelInitializer method initChannel.

@Override
public void initChannel(SocketChannel channel) throws Exception {
    ApnProxyRemote apnProxyRemote = uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).get().getRemote();
    channel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).set(uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).get());
    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("idlestate", new IdleStateHandler(0, 0, 3, TimeUnit.MINUTES));
    pipeline.addLast("idlehandler", new ApnProxyIdleHandler());
    if (apnProxyRemote.getRemoteListenType() == ApnProxyListenType.SSL) {
        SSLEngine engine = ApnProxySSLContextFactory.createClientSSLEnginForRemoteAddress(apnProxyRemote.getRemoteHost(), apnProxyRemote.getRemotePort());
        engine.setUseClientMode(true);
        pipeline.addLast("ssl", new SslHandler(engine));
    } else if (apnProxyRemote.getRemoteListenType() == ApnProxyListenType.AES) {
        byte[] key = ((ApnProxyAESRemote) apnProxyRemote).getKey();
        byte[] iv = ((ApnProxyAESRemote) apnProxyRemote).getIv();
        pipeline.addLast("apnproxy.encrypt", new ApnProxyAESEncoder(key, iv));
        pipeline.addLast("apnproxy.decrypt", new ApnProxyAESDecoder(key, iv));
    }
    pipeline.addLast("codec", new HttpClientCodec());
    pipeline.addLast(ApnProxyRemoteForwardHandler.HANDLER_NAME, new ApnProxyRemoteForwardHandler(uaChannel, remoteChannelInactiveCallback));
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ApnProxyRemote(com.xx_dev.apn.proxy.remotechooser.ApnProxyRemote) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 68 with SslHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project vert.x by eclipse.

the class Http2ClientTest method createH2Server.

private ServerBootstrap createH2Server(BiFunction<Http2ConnectionDecoder, Http2ConnectionEncoder, Http2FrameListener> handler) {
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.channel(NioServerSocketChannel.class);
    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup();
    eventLoopGroups.add(eventLoopGroup);
    bootstrap.group(eventLoopGroup);
    bootstrap.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            SSLHelper sslHelper = new SSLHelper(serverOptions, Cert.SERVER_JKS.get(), null);
            SslHandler sslHandler = sslHelper.setApplicationProtocols(Arrays.asList(HttpVersion.HTTP_2, HttpVersion.HTTP_1_1)).createSslHandler((VertxInternal) vertx, DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT);
            ch.pipeline().addLast(sslHandler);
            ch.pipeline().addLast(new ApplicationProtocolNegotiationHandler("whatever") {

                @Override
                protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
                    if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                        ChannelPipeline p = ctx.pipeline();
                        Http2ConnectionHandler clientHandler = createHttpConnectionHandler(handler);
                        p.addLast("handler", clientHandler);
                        return;
                    }
                    ctx.close();
                    throw new IllegalStateException("unknown protocol: " + protocol);
                }
            });
        }
    });
    return bootstrap;
}
Also used : TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) VertxInternal(io.vertx.core.impl.VertxInternal) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) AsciiString(io.netty.util.AsciiString) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Http2Exception(io.netty.handler.codec.http2.Http2Exception) StreamResetException(io.vertx.core.http.StreamResetException) ConnectException(java.net.ConnectException) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) SslHandler(io.netty.handler.ssl.SslHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) SSLHelper(io.vertx.core.net.impl.SSLHelper) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 69 with SslHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project vert.x by eclipse.

the class NetServerImpl method initChannel.

@Override
protected void initChannel(ChannelPipeline pipeline) {
    if (sslHelper.isSSL()) {
        SslHandler sslHandler = sslHelper.createSslHandler(vertx);
        pipeline.addLast("ssl", sslHandler);
    }
    if (logEnabled) {
        pipeline.addLast("logging", new LoggingHandler());
    }
    if (sslHelper.isSSL()) {
        // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
        // For large file / sendfile support
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    }
    if (options.getIdleTimeout() > 0) {
        pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout()));
    }
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) SslHandler(io.netty.handler.ssl.SslHandler)

Example 70 with SslHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project vert.x by eclipse.

the class NetSocketImpl method upgradeToSsl.

@Override
public synchronized NetSocket upgradeToSsl(final Handler<Void> handler) {
    SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
    if (sslHandler == null) {
        if (host != null) {
            sslHandler = helper.createSslHandler(vertx, host, port);
        } else {
            sslHandler = helper.createSslHandler(vertx, this.remoteName(), this.remoteAddress().port());
        }
        channel.pipeline().addFirst("ssl", sslHandler);
    }
    sslHandler.handshakeFuture().addListener(future -> context.executeFromIO(() -> {
        if (future.isSuccess()) {
            handler.handle(null);
        } else {
            log.error(future.cause());
        }
    }));
    return this;
}
Also used : SslHandler(io.netty.handler.ssl.SslHandler)

Aggregations

SslHandler (io.netty.handler.ssl.SslHandler)141 SSLEngine (javax.net.ssl.SSLEngine)51 ChannelPipeline (io.netty.channel.ChannelPipeline)37 Channel (io.netty.channel.Channel)29 ChannelHandler (io.netty.channel.ChannelHandler)23 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)23 SslContext (io.netty.handler.ssl.SslContext)21 IOException (java.io.IOException)16 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)15 Test (org.junit.Test)15 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)14 ChannelInitializer (io.netty.channel.ChannelInitializer)13 SocketChannel (io.netty.channel.socket.SocketChannel)13 SSLSession (javax.net.ssl.SSLSession)12 ByteBuf (io.netty.buffer.ByteBuf)11 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)11 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)11 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)10 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)10 File (java.io.File)10