use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLEngineTest method doTest.
private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
server.close();
HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
server = vertx.createHttpServer(options);
server.requestHandler(req -> {
assertEquals(req.version(), version);
assertTrue(req.isSSL());
req.response().end();
});
try {
startServer();
if (error != null) {
fail("Was expecting failure: " + error);
}
} catch (Exception e) {
if (error == null) {
fail(e);
} else {
assertEquals(error, e.getMessage());
if (expectCause) {
assertNotSame(e, e.getCause());
}
return;
}
}
SSLHelper sslHelper = ((HttpServerImpl) server).sslHelper();
SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
switch(expectedSslContext != null ? expectedSslContext : "jdk") {
case "jdk":
assertTrue(ctx instanceof JdkSslContext);
break;
case "openssl":
assertTrue(ctx instanceof OpenSslContext);
break;
}
client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
testComplete();
}));
}));
await();
}
use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class Http1xServerConnection method netSocket.
void netSocket(Promise<NetSocket> promise) {
context.execute(() -> {
// Flush out all pending data
flush();
// remove old http handlers and replace the old handler with one that handle plain sockets
ChannelPipeline pipeline = chctx.pipeline();
ChannelHandler compressor = pipeline.get(HttpChunkContentCompressor.class);
if (compressor != null) {
pipeline.remove(compressor);
}
pipeline.remove("httpDecoder");
if (pipeline.get("chunkedWriter") != null) {
pipeline.remove("chunkedWriter");
}
pipeline.replace("handler", "handler", VertxHandler.create(ctx -> {
NetSocketImpl socket = new NetSocketImpl(context, ctx, sslHelper, metrics) {
@Override
protected void handleClosed() {
if (metrics != null) {
Http1xServerRequest request = Http1xServerConnection.this.responseInProgress;
metrics.responseEnd(request.metric(), request.response(), request.response().bytesWritten());
}
super.handleClosed();
}
@Override
public synchronized void handleMessage(Object msg) {
if (msg instanceof HttpContent) {
ReferenceCountUtil.release(msg);
return;
}
super.handleMessage(msg);
}
};
socket.metric(metric());
return socket;
}));
// check if the encoder can be removed yet or not.
pipeline.remove("httpEncoder");
//
VertxHandler<NetSocketImpl> handler = (VertxHandler<NetSocketImpl>) pipeline.get("handler");
promise.complete(handler.getConnection());
});
}
use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLEngineTest method doTest.
private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
server.close();
HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
try {
server = vertx.createHttpServer(options);
} catch (VertxException e) {
e.printStackTrace();
if (error == null) {
fail(e);
} else {
assertEquals(error, e.getMessage());
if (expectCause) {
assertNotSame(e, e.getCause());
}
}
return;
}
server.requestHandler(req -> {
assertEquals(req.version(), version);
assertTrue(req.isSSL());
req.response().end();
});
server.listen(onSuccess(s -> {
HttpServerImpl impl = (HttpServerImpl) s;
SSLHelper sslHelper = impl.getSslHelper();
SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
switch(expectedSslContext) {
case "jdk":
assertTrue(ctx instanceof JdkSslContext);
break;
case "openssl":
assertTrue(ctx instanceof OpenSslContext);
break;
}
client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(200, resp.statusCode());
testComplete();
});
}));
await();
}
use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLHelperTest method testPreserveEnabledCipherSuitesOrder.
@Test
public void testPreserveEnabledCipherSuitesOrder() throws Exception {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLEngine engine = context.createSSLEngine();
HttpServerOptions options = new HttpServerOptions();
for (String suite : engine.getEnabledCipherSuites()) {
options.addEnabledCipherSuite(suite);
}
assertEquals(new ArrayList<>(options.getEnabledCipherSuites()), Arrays.asList(engine.getEnabledCipherSuites()));
assertEquals(new ArrayList<>(new HttpServerOptions(options).getEnabledCipherSuites()), Arrays.asList(engine.getEnabledCipherSuites()));
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).getEnabledCipherSuites()), Arrays.asList(engine.getEnabledCipherSuites()));
SSLHelper helper = new SSLHelper(options, Cert.SERVER_JKS.get(), null);
assertEquals(Arrays.asList(helper.createSslHandler((VertxInternal) vertx).engine().getEnabledCipherSuites()), Arrays.asList(engine.getEnabledCipherSuites()));
}
use of io.vertx.core.net.impl.SSLHelper in project vert.x by eclipse.
the class SSLHelperTest method testOpenSslServerSessionContext.
private void testOpenSslServerSessionContext(boolean testDefault) {
HttpServerOptions httpServerOptions = new HttpServerOptions().setOpenSslEngineOptions(new OpenSSLEngineOptions());
if (!testDefault) {
httpServerOptions.setOpenSslEngineOptions(new OpenSSLEngineOptions().setSessionCacheEnabled(false));
}
SSLHelper defaultHelper = new SSLHelper(httpServerOptions, Cert.SERVER_PEM.get(), Trust.SERVER_PEM.get());
SslContext ctx = defaultHelper.getContext((VertxInternal) vertx);
assertTrue(ctx instanceof OpenSslServerContext);
SSLSessionContext sslSessionContext = ctx.sessionContext();
assertTrue(sslSessionContext instanceof OpenSslServerSessionContext);
if (sslSessionContext instanceof OpenSslServerSessionContext) {
assertEquals(testDefault, ((OpenSslServerSessionContext) sslSessionContext).isSessionCacheEnabled());
}
}
Aggregations