use of 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));
}
use of io.netty.handler.ssl.SslHandler in project moco by dreamhead.
the class MocoHttpServer method toSslHandler.
private Function<HttpsCertificate, SslHandler> toSslHandler() {
return new Function<HttpsCertificate, SslHandler>() {
@Override
public SslHandler apply(final HttpsCertificate certificate) {
SSLEngine sslEngine = certificate.createSSLEngine();
sslEngine.setUseClientMode(false);
return new SslHandler(sslEngine);
}
};
}
use of 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;
}
use of 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()));
}
}
use of 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;
}
Aggregations