Search in sources :

Example 1 with OpenSslContext

use of io.netty.handler.ssl.OpenSslContext 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();
}
Also used : VertxException(io.vertx.core.VertxException) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) SSLEngineOptions(io.vertx.core.net.SSLEngineOptions) VertxInternal(io.vertx.core.impl.VertxInternal) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext) Test(org.junit.Test) Cert(io.vertx.test.core.tls.Cert) SSLHelper(io.vertx.core.net.impl.SSLHelper) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) HttpTestBase(io.vertx.test.core.HttpTestBase) HttpVersion(io.vertx.core.http.HttpVersion) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) JdkSSLEngineOptions(io.vertx.core.net.JdkSSLEngineOptions) SSLHelper(io.vertx.core.net.impl.SSLHelper) VertxInternal(io.vertx.core.impl.VertxInternal) JdkSslContext(io.netty.handler.ssl.JdkSslContext) VertxException(io.vertx.core.VertxException) OpenSslContext(io.netty.handler.ssl.OpenSslContext) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext)

Example 2 with OpenSslContext

use of io.netty.handler.ssl.OpenSslContext in project netty by netty.

the class SocketSslEchoTest method data.

@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}, renegotiation = {2}, " + "serverUsesDelegatedTaskExecutor = {3}, clientUsesDelegatedTaskExecutor = {4}, " + "autoRead = {5}, useChunkedWriteHandler = {6}, useCompositeByteBuf = {7}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build());
    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(CERT_FILE).build());
    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.OPENSSL).build());
        clientContexts.add(SslContextBuilder.forClient().sslProvider(SslProvider.OPENSSL).trustManager(CERT_FILE).build());
    } else {
        logger.warn("OpenSSL is unavailable and thus will not be tested.", OpenSsl.unavailabilityCause());
    }
    List<Object[]> params = new ArrayList<Object[]>();
    for (SslContext sc : serverContexts) {
        for (SslContext cc : clientContexts) {
            for (RenegotiationType rt : RenegotiationType.values()) {
                if (rt != RenegotiationType.NONE && (sc instanceof OpenSslContext || cc instanceof OpenSslContext)) {
                    // TODO: OpenSslEngine does not support renegotiation yet.
                    continue;
                }
                final Renegotiation r;
                switch(rt) {
                    case NONE:
                        r = Renegotiation.NONE;
                        break;
                    case SERVER_INITIATED:
                        r = new Renegotiation(rt, sc.cipherSuites().get(sc.cipherSuites().size() - 1));
                        break;
                    case CLIENT_INITIATED:
                        r = new Renegotiation(rt, cc.cipherSuites().get(cc.cipherSuites().size() - 1));
                        break;
                    default:
                        throw new Error();
                }
                for (int i = 0; i < 32; i++) {
                    params.add(new Object[] { sc, cc, r, (i & 16) != 0, (i & 8) != 0, (i & 4) != 0, (i & 2) != 0, (i & 1) != 0 });
                }
            }
        }
    }
    return params;
}
Also used : OpenSslContext(io.netty.handler.ssl.OpenSslContext) ArrayList(java.util.ArrayList) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

OpenSslContext (io.netty.handler.ssl.OpenSslContext)2 SslContext (io.netty.handler.ssl.SslContext)2 JdkSslContext (io.netty.handler.ssl.JdkSslContext)1 VertxException (io.vertx.core.VertxException)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 HttpVersion (io.vertx.core.http.HttpVersion)1 HttpServerImpl (io.vertx.core.http.impl.HttpServerImpl)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 JdkSSLEngineOptions (io.vertx.core.net.JdkSSLEngineOptions)1 OpenSSLEngineOptions (io.vertx.core.net.OpenSSLEngineOptions)1 SSLEngineOptions (io.vertx.core.net.SSLEngineOptions)1 SSLHelper (io.vertx.core.net.impl.SSLHelper)1 HttpTestBase (io.vertx.test.core.HttpTestBase)1 Cert (io.vertx.test.core.tls.Cert)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Parameters (org.junit.runners.Parameterized.Parameters)1