io.netty.handler.ssl.OpenSslEngine Java Examples

The following examples show how to use io.netty.handler.ssl.OpenSslEngine. 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: NettyOpenSslTransportTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void assertOpenSSL(String message, boolean expected, Transport transport) throws Exception {
    Field channel = null;
    Class<?> transportType = transport.getClass();

    while (transportType != null && channel == null) {
        try {
            channel = transportType.getDeclaredField("channel");
        } catch (NoSuchFieldException error) {
            transportType = transportType.getSuperclass();
            if (Object.class.equals(transportType)) {
                transportType = null;
            }
        }
    }

    assertNotNull("Transport implementation unknown", channel);

    channel.setAccessible(true);

    Channel activeChannel = (Channel) channel.get(transport) ;
    ChannelHandler handler = activeChannel.pipeline().get("ssl");
    assertNotNull("Channel should have an SSL Handler registered");
    assertTrue(handler instanceof SslHandler);
    SslHandler sslHandler = (SslHandler) handler;

    if (expected) {
        assertTrue(message, sslHandler.engine() instanceof OpenSslEngine);
    } else {
        assertFalse(message, sslHandler.engine() instanceof OpenSslEngine);
    }
}
 
Example #2
Source File: TransportSupportTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 100000)
public void testCreateSslHandlerJDK() throws Exception {
    assumeTrue(OpenSsl.isAvailable());
    assumeTrue(OpenSsl.supportsKeyManagerFactory());

    TransportOptions options = new TransportOptions();
    options.setUseOpenSSL(false);

    SslHandler handler = TransportSupport.createSslHandler(null, null, options);
    assertNotNull(handler);
    assertFalse(handler.engine() instanceof OpenSslEngine);
}
 
Example #3
Source File: TransportSupportTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 100000)
public void testCreateSslHandlerOpenSSL() throws Exception {
    assumeTrue(OpenSsl.isAvailable());
    assumeTrue(OpenSsl.supportsKeyManagerFactory());

    TransportOptions options = new TransportOptions();
    options.setUseOpenSSL(true);

    SslHandler handler = TransportSupport.createSslHandler(PooledByteBufAllocator.DEFAULT, null, options);
    assertNotNull(handler);
    assertTrue(handler.engine() instanceof OpenSslEngine);
}
 
Example #4
Source File: ProtocolNegotiators.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void logSslEngineDetails(Level level, ChannelHandlerContext ctx, String msg,
                                              @Nullable Throwable t) {
  if (!log.isLoggable(level)) {
    return;
  }

  SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
  SSLEngine engine = sslHandler.engine();

  StringBuilder builder = new StringBuilder(msg);
  builder.append("\nSSLEngine Details: [\n");
  if (engine instanceof OpenSslEngine) {
    builder.append("    OpenSSL, ");
    builder.append("Version: 0x").append(Integer.toHexString(OpenSsl.version()));
    builder.append(" (").append(OpenSsl.versionString()).append("), ");
    builder.append("ALPN supported: ").append(OpenSsl.isAlpnSupported());
  } else if (JettyTlsUtil.isJettyAlpnConfigured()) {
    builder.append("    Jetty ALPN");
  } else if (JettyTlsUtil.isJettyNpnConfigured()) {
    builder.append("    Jetty NPN");
  } else if (JettyTlsUtil.isJava9AlpnAvailable()) {
    builder.append("    JDK9 ALPN");
  }
  builder.append("\n    TLS Protocol: ");
  builder.append(engine.getSession().getProtocol());
  builder.append("\n    Application Protocol: ");
  builder.append(sslHandler.applicationProtocol());
  builder.append("\n    Need Client Auth: " );
  builder.append(engine.getNeedClientAuth());
  builder.append("\n    Want Client Auth: ");
  builder.append(engine.getWantClientAuth());
  builder.append("\n    Supported protocols=");
  builder.append(Arrays.toString(engine.getSupportedProtocols()));
  builder.append("\n    Enabled protocols=");
  builder.append(Arrays.toString(engine.getEnabledProtocols()));
  builder.append("\n    Supported ciphers=");
  builder.append(Arrays.toString(engine.getSupportedCipherSuites()));
  builder.append("\n    Enabled ciphers=");
  builder.append(Arrays.toString(engine.getEnabledCipherSuites()));
  builder.append("\n]");

  log.log(level, builder.toString(), t);
}
 
Example #5
Source File: ProtocolNegotiators.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static void logSslEngineDetails(Level level, ChannelHandlerContext ctx, String msg,
    @Nullable Throwable t) {
  if (!log.isLoggable(level)) {
    return;
  }

  SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
  SSLEngine engine = sslHandler.engine();

  StringBuilder builder = new StringBuilder(msg);
  builder.append("\nSSLEngine Details: [\n");
  if (engine instanceof OpenSslEngine) {
    builder.append("    OpenSSL, ");
    builder.append("Version: 0x").append(Integer.toHexString(OpenSsl.version()));
    builder.append(" (").append(OpenSsl.versionString()).append("), ");
    builder.append("ALPN supported: ").append(SslProvider.isAlpnSupported(SslProvider.OPENSSL));
  } else if (JettyTlsUtil.isJettyAlpnConfigured()) {
    builder.append("    Jetty ALPN");
  } else if (JettyTlsUtil.isJettyNpnConfigured()) {
    builder.append("    Jetty NPN");
  } else if (JettyTlsUtil.isJava9AlpnAvailable()) {
    builder.append("    JDK9 ALPN");
  }
  builder.append("\n    TLS Protocol: ");
  builder.append(engine.getSession().getProtocol());
  builder.append("\n    Application Protocol: ");
  builder.append(sslHandler.applicationProtocol());
  builder.append("\n    Need Client Auth: " );
  builder.append(engine.getNeedClientAuth());
  builder.append("\n    Want Client Auth: ");
  builder.append(engine.getWantClientAuth());
  builder.append("\n    Supported protocols=");
  builder.append(Arrays.toString(engine.getSupportedProtocols()));
  builder.append("\n    Enabled protocols=");
  builder.append(Arrays.toString(engine.getEnabledProtocols()));
  builder.append("\n    Supported ciphers=");
  builder.append(Arrays.toString(engine.getSupportedCipherSuites()));
  builder.append("\n    Enabled ciphers=");
  builder.append(Arrays.toString(engine.getEnabledCipherSuites()));
  builder.append("\n]");

  log.log(level, builder.toString(), t);
}