io.netty.handler.ssl.OpenSslServerContext Java Examples

The following examples show how to use io.netty.handler.ssl.OpenSslServerContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocketSslClientRenegotiateTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(new JdkSslClientContext(CERT_FILE));

    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        OpenSslServerContext context = new OpenSslServerContext(CERT_FILE, KEY_FILE);
        serverContexts.add(context);
    } 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 (int i = 0; i < 32; i++) {
                params.add(new Object[] { sc, cc});
            }
        }
    }

    return params;
}
 
Example #2
Source File: SocketSslGreetingTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    serverContexts.add(new JdkSslServerContext(CERT_FILE, KEY_FILE));

    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(new JdkSslClientContext(CERT_FILE));

    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        serverContexts.add(new OpenSslServerContext(CERT_FILE, KEY_FILE));
        clientContexts.add(new OpenSslClientContext(CERT_FILE));
    } 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) {
            params.add(new Object[] { sc, cc });
        }
    }
    return params;
}
 
Example #3
Source File: SocketStartTlsTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    serverContexts.add(new JdkSslServerContext(CERT_FILE, KEY_FILE));

    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(new JdkSslClientContext(CERT_FILE));

    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        serverContexts.add(new OpenSslServerContext(CERT_FILE, KEY_FILE));
        clientContexts.add(new OpenSslClientContext(CERT_FILE));
    } 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) {
            params.add(new Object[] { sc, cc });
        }
    }
    return params;
}
 
Example #4
Source File: SslFactory.java    From hivemq-community-edition with Apache License 2.0 4 votes vote down vote up
public void verifySslAtBootstrap(@NotNull final Listener listener, @NotNull final Tls tls) {
    try {
        if (!sslContextStore.contains(tls)) {
            final SslContext sslContext = sslContextFactory.createSslContext(tls);
            sslContextStore.putAtStart(tls, sslContext);

            final SSLEngine sslEngine = sslContext.newEngine(new PooledByteBufAllocator());
            enableProtocols(sslEngine, tls.getProtocols());
            log.info("Enabled protocols for {} at address {} and port {}: {}", listener.readableName(), listener.getBindAddress(), listener.getPort(), Arrays.toString(sslEngine.getEnabledProtocols()));
            final String[] enabledCipherSuites = sslEngine.getEnabledCipherSuites();
            log.info("Enabled cipher suites for {} at address {} and port {}: {}", listener.readableName(), listener.getBindAddress(), listener.getPort(), Arrays.toString(enabledCipherSuites));

            final List<String> cipherSuites = tls.getCipherSuites();
            if (cipherSuites.size() > 0) {
                final Set<String> unknownCipherSuitesSet;

                if (sslContext instanceof OpenSslServerContext) {
                    // the prefixes TLS_ and SSL_ are ignored by OpenSSL
                    final Set<String> enabledCipherSuitesSet = new HashSet<>();
                    for (final String enabledCipherSuite : enabledCipherSuites) {
                        enabledCipherSuitesSet.add(enabledCipherSuite.substring(4));
                    }
                    unknownCipherSuitesSet = new HashSet<>();
                    for (final String cipherSuite : cipherSuites) {

                        if (cipherSuite == null) {
                            continue;
                        }

                        if (!enabledCipherSuitesSet.contains(cipherSuite.substring(4))) {
                            unknownCipherSuitesSet.add(cipherSuite);
                        }
                    }
                } else {
                    unknownCipherSuitesSet = Sets.difference(ImmutableSet.copyOf(cipherSuites), ImmutableSet.copyOf(enabledCipherSuites));
                }

                if (unknownCipherSuitesSet.size() > 0) {
                    log.warn("Unknown cipher suites for {} at address {} and port {}: {}", listener.readableName(), listener.getBindAddress(), listener.getPort(), unknownCipherSuitesSet);
                }
            }
        }
    } catch (final Exception e) {
        log.error("Not able to create SSL server context", e);
        throw new UnrecoverableException(false);
    }
}
 
Example #5
Source File: SocketSslEchoTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@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(new JdkSslServerContext(CERT_FILE, KEY_FILE));

    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(new JdkSslClientContext(CERT_FILE));

    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        serverContexts.add(new OpenSslServerContext(CERT_FILE, KEY_FILE));
        clientContexts.add(new OpenSslClientContext(CERT_FILE));
    } 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;
                }

                Renegotiation r;
                if (rt == RenegotiationType.NONE) {
                    r = Renegotiation.NONE;
                } else {
                    r = new Renegotiation(rt, "SSL_RSA_WITH_RC4_128_SHA");
                }

                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;
}