use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLHelperTest method testPreserveEnabledSecureTransportProtocolOrder.
@Test
public void testPreserveEnabledSecureTransportProtocolOrder() throws Exception {
String[] protocols = { "SSLv2Hello", "TLSv1", "TLSv1.1", "TLSv1.2" };
HttpServerOptions options = new HttpServerOptions();
for (String protocol : protocols) {
options.addEnabledSecureTransportProtocol(protocol);
}
assertEquals(new ArrayList<>(options.getEnabledSecureTransportProtocols()), Arrays.asList(protocols));
assertEquals(new ArrayList<>(new HttpServerOptions(options).getEnabledSecureTransportProtocols()), Arrays.asList(protocols));
JsonObject json = new JsonObject();
NetworkOptionsConverter.toJson(options, json);
TCPSSLOptionsConverter.toJson(options, json);
NetServerOptionsConverter.toJson(options, json);
HttpServerOptionsConverter.toJson(options, json);
assertEquals(new ArrayList<>(new HttpServerOptions(json).getEnabledSecureTransportProtocols()), Arrays.asList(protocols));
SSLHelper helper = new SSLHelper(options, Cert.SERVER_JKS.get(), null);
List<String> engineProtocols = Arrays.asList(helper.createSslHandler((VertxInternal) vertx).engine().getEnabledProtocols());
List<String> expectedProtocols = new ArrayList<>(Arrays.asList(protocols));
expectedProtocols.retainAll(engineProtocols);
assertEquals(engineProtocols, expectedProtocols);
}
use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLHelperTest method testUseOpenSSLCiphersWhenNotSpecified.
@Test
public void testUseOpenSSLCiphersWhenNotSpecified() throws Exception {
Set<String> expected = OpenSsl.availableCipherSuites();
SSLHelper helper = new SSLHelper(new HttpClientOptions().setOpenSslEngineOptions(new OpenSSLEngineOptions()), Cert.CLIENT_PEM.get(), Trust.SERVER_PEM.get());
SslContext ctx = helper.getContext((VertxInternal) vertx);
assertEquals(expected, new HashSet<>(ctx.cipherSuites()));
}
use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLHelperTest method testUseJdkCiphersWhenNotSpecified.
@Test
public void testUseJdkCiphersWhenNotSpecified() throws Exception {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLEngine engine = context.createSSLEngine();
String[] expected = engine.getEnabledCipherSuites();
SSLHelper helper = new SSLHelper(new HttpClientOptions(), Cert.CLIENT_JKS.get(), Trust.SERVER_JKS.get());
SslContext ctx = helper.getContext((VertxInternal) vertx);
assertEquals(new HashSet<>(Arrays.asList(expected)), new HashSet<>(ctx.cipherSuites()));
}
use of io.vertx.core.net.impl.SSLHelper 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;
}
Aggregations