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;
}
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());
}
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));
}
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);
}
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);
}
Aggregations