Search in sources :

Example 6 with SslHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project async-http-client by AsyncHttpClient.

the class ChannelManager method addSslHandler.

public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtualHost) {
    String peerHost;
    int peerPort;
    if (virtualHost != null) {
        int i = virtualHost.indexOf(':');
        if (i == -1) {
            peerHost = virtualHost;
            peerPort = uri.getSchemeDefaultPort();
        } else {
            peerHost = virtualHost.substring(0, i);
            peerPort = Integer.valueOf(virtualHost.substring(i + 1));
        }
    } else {
        peerHost = uri.getHost();
        peerPort = uri.getExplicitPort();
    }
    SslHandler sslHandler = createSslHandler(peerHost, peerPort);
    pipeline.addFirst(ChannelManager.SSL_HANDLER, sslHandler);
    return sslHandler;
}
Also used : SslHandler(io.netty.handler.ssl.SslHandler)

Example 7 with SslHandler

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

the class ApnProxyServerChannelInitializer method initChannel.

@Override
public void initChannel(SocketChannel channel) throws Exception {
    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("idlestate", new IdleStateHandler(0, 0, 3, TimeUnit.MINUTES));
    pipeline.addLast("idlehandler", new ApnProxyIdleHandler());
    pipeline.addLast("datalog", new LoggingHandler("PRE_BYTE_LOGGER", LogLevel.DEBUG));
    if (ApnProxyConfig.getConfig().getListenType() == ApnProxyListenType.SSL) {
        SSLEngine engine = ApnProxySSLContextFactory.createServerSSLSSLEngine();
        pipeline.addLast("apnproxy.encrypt", new SslHandler(engine));
    } else if (ApnProxyConfig.getConfig().getListenType() == ApnProxyListenType.AES) {
        byte[] key = ApnProxyConfig.getConfig().getKey();
        byte[] iv = ApnProxyConfig.getConfig().getIv();
        pipeline.addLast("apnproxy.encrypt", new ApnProxyAESEncoder(key, iv));
        pipeline.addLast("apnproxy.decrypt", new ApnProxyAESDecoder(key, iv));
    }
    pipeline.addLast("log", new LoggingHandler("BYTE_LOGGER", LogLevel.INFO));
    pipeline.addLast("codec", new HttpServerCodec());
    pipeline.addLast(ApnProxyPreHandler.HANDLER_NAME, new ApnProxyPreHandler());
    pipeline.addLast(ApnProxySchemaHandler.HANDLER_NAME, new ApnProxySchemaHandler());
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) SSLEngine(javax.net.ssl.SSLEngine) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 8 with SslHandler

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

the class ApnProxyTunnelChannelInitializer method initChannel.

/**
     * @see io.netty.channel.ChannelInitializer#initChannel(io.netty.channel.Channel)
     */
@Override
protected 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));
    }
    if (apnProxyRemote.getRemoteListenType() == ApnProxyListenType.PLAIN) {
    // nothing to do
    }
    pipeline.addLast(new ApnProxyRelayHandler(apnProxyRemote.getRemoteAddr() + " --> UA", uaChannel));
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ApnProxyRemote(com.xx_dev.apn.proxy.remotechooser.ApnProxyRemote) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 9 with SslHandler

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

the class ProtocolNegotiatorsTest method tlsHandler_userEventTriggeredSslEvent_supportedProtocolGrpcExp.

@Test
public void tlsHandler_userEventTriggeredSslEvent_supportedProtocolGrpcExp() throws Exception {
    SslHandler goodSslHandler = new SslHandler(engine, false) {

        @Override
        public String applicationProtocol() {
            return "grpc-exp";
        }
    };
    ChannelHandler handler = new ServerTlsHandler(sslContext, grpcHandler);
    pipeline.addLast(handler);
    pipeline.replace(SslHandler.class, null, goodSslHandler);
    channelHandlerCtx = pipeline.context(handler);
    Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
    pipeline.fireUserEventTriggered(sslEvent);
    assertTrue(channel.isOpen());
    ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
    assertNotNull(grpcHandlerCtx);
}
Also used : ServerTlsHandler(io.grpc.netty.ProtocolNegotiators.ServerTlsHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Example 10 with SslHandler

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

the class Http2AlpnHandler method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
        if (handshakeEvent.isSuccess()) {
            LOG.debug("SSL handshake succeeded");
            SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
            if (sslHandler == null) {
                ctx.fireExceptionCaught(new IllegalStateException("cannot find a SslHandler in the pipeline (required for " + "application-level protocol negotiation)"));
                return;
            }
            String protocol = sslHandler.applicationProtocol();
            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                LOG.debug("HTTP/2 is negotiated");
                // Add HTTP/2 handler
                ctx.pipeline().addAfter("sslHandler", "http2Handler", _http2Handler);
                // Remove handler from pipeline after negotiation is complete
                ctx.pipeline().remove(this);
                _alpnPromise.setSuccess();
            } else {
                LOG.error("Protocol {}, instead of HTTP/2, is negotiated through ALPN", protocol);
                _alpnPromise.setFailure(new IllegalStateException("HTTP/2 ALPN negotiation failed"));
            }
        } else {
            LOG.error("SSL handshake failed", handshakeEvent.cause());
            _alpnPromise.setFailure(handshakeEvent.cause());
        }
    }
    ctx.fireUserEventTriggered(evt);
}
Also used : SslHandshakeCompletionEvent(io.netty.handler.ssl.SslHandshakeCompletionEvent) SslHandler(io.netty.handler.ssl.SslHandler)

Aggregations

SslHandler (io.netty.handler.ssl.SslHandler)178 SSLEngine (javax.net.ssl.SSLEngine)63 ChannelPipeline (io.netty.channel.ChannelPipeline)51 Channel (io.netty.channel.Channel)36 SslContext (io.netty.handler.ssl.SslContext)31 ChannelHandler (io.netty.channel.ChannelHandler)28 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)26 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)21 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)19 Test (org.junit.Test)19 SocketChannel (io.netty.channel.socket.SocketChannel)18 IOException (java.io.IOException)17 InetSocketAddress (java.net.InetSocketAddress)16 SSLSession (javax.net.ssl.SSLSession)16 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)15 SSLParameters (javax.net.ssl.SSLParameters)15 ChannelInitializer (io.netty.channel.ChannelInitializer)14 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)14 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)13 ByteBuf (io.netty.buffer.ByteBuf)13