use of io.netty.handler.ssl.SslHandler in project ratpack by ratpack.
the class DefaultRatpackServer method buildChannel.
protected Channel buildChannel(final ServerConfig serverConfig, final ChannelHandler handlerAdapter) throws InterruptedException {
SSLContext sslContext = serverConfig.getSslContext();
boolean requireClientSslAuth = serverConfig.isRequireClientSslAuth();
this.useSsl = sslContext != null;
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverConfig.getConnectTimeoutMillis().ifPresent(i -> {
serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, i);
serverBootstrap.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, i);
});
serverConfig.getMaxMessagesPerRead().ifPresent(i -> {
FixedRecvByteBufAllocator allocator = new FixedRecvByteBufAllocator(i);
serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, allocator);
serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, allocator);
});
serverConfig.getReceiveBufferSize().ifPresent(i -> {
serverBootstrap.option(ChannelOption.SO_RCVBUF, i);
serverBootstrap.childOption(ChannelOption.SO_RCVBUF, i);
});
serverConfig.getWriteSpinCount().ifPresent(i -> {
serverBootstrap.option(ChannelOption.WRITE_SPIN_COUNT, i);
serverBootstrap.childOption(ChannelOption.WRITE_SPIN_COUNT, i);
});
return serverBootstrap.group(execController.getEventLoopGroup()).channel(ChannelImplDetector.getServerSocketChannelImpl()).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (sslContext != null) {
SSLEngine sslEngine = sslContext.createSSLEngine();
sslEngine.setUseClientMode(false);
sslEngine.setNeedClientAuth(requireClientSslAuth);
pipeline.addLast("ssl", new SslHandler(sslEngine));
}
pipeline.addLast("decoder", new HttpRequestDecoder(serverConfig.getMaxInitialLineLength(), serverConfig.getMaxHeaderSize(), serverConfig.getMaxChunkSize(), false));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("deflater", new IgnorableHttpContentCompressor());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
pipeline.addLast("adapter", handlerAdapter);
ch.config().setAutoRead(false);
}
}).bind(buildSocketAddress(serverConfig)).sync().channel();
}
use of io.netty.handler.ssl.SslHandler in project camel by apache.
the class HttpServerSharedInitializerFactory method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
pipeline.addLast("encoder", new HttpResponseEncoder());
if (configuration.isChunked()) {
pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
}
if (configuration.isCompression()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
pipeline.addLast("handler", channelFactory.getChannelHandler());
}
use of 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);
}
use of io.netty.handler.ssl.SslHandler in project rest.li by linkedin.
the class Http2InitializerHandler method configureHttpsPipeline.
/**
* Sets up HTTP/2 over TLS through ALPN (h2) pipeline
*/
private void configureHttpsPipeline(ChannelHandlerContext ctx) throws Exception {
JdkSslContext context = new JdkSslContext(_sslContext, IS_CLIENT, Arrays.asList(_sslParameters.getCipherSuites()), IdentityCipherSuiteFilter.INSTANCE, new ApplicationProtocolConfig(ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE, ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1), _sslParameters.getNeedClientAuth() ? ClientAuth.REQUIRE : ClientAuth.OPTIONAL);
SslHandler sslHandler = context.newHandler(ctx.alloc());
Http2StreamCodec http2Codec = new Http2StreamCodecBuilder().connection(_connection).maxContentLength(_maxResponseSize).maxHeaderSize(_maxHeaderSize).gracefulShutdownTimeoutMillis(_gracefulShutdownTimeout).streamingTimeout(_streamingTimeout).scheduler(_scheduler).build();
Http2AlpnHandler alpnHandler = new Http2AlpnHandler(sslHandler, http2Codec);
Http2SchemeHandler schemeHandler = new Http2SchemeHandler(HttpScheme.HTTPS.toString());
Http2StreamResponseHandler responseHandler = new Http2StreamResponseHandler();
Http2ChannelPoolHandler channelPoolHandler = new Http2ChannelPoolHandler();
ctx.pipeline().addBefore(ctx.name(), "alpnHandler", alpnHandler);
ctx.pipeline().addBefore(ctx.name(), "schemeHandler", schemeHandler);
ctx.pipeline().addBefore(ctx.name(), "responseHandler", responseHandler);
ctx.pipeline().addBefore(ctx.name(), "channelHandler", channelPoolHandler);
_setupComplete = true;
}
use of 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());
}
Aggregations