Search in sources :

Example 1 with SslContextFactory

use of com.rabbitmq.client.SslContextFactory in project rabbitmq-java-client by rabbitmq.

the class SslContextFactoryTest method doTestSocketFactoryTakesPrecedenceOverSslContextFactoryWithBlockingIo.

private void doTestSocketFactoryTakesPrecedenceOverSslContextFactoryWithBlockingIo(Supplier<ConnectionFactory> supplier) throws Exception {
    ConnectionFactory connectionFactory = supplier.get();
    connectionFactory.useBlockingIo();
    SslContextFactory sslContextFactory = sslContextFactory();
    connectionFactory.setSslContextFactory(sslContextFactory);
    SSLContext contextAcceptAll = sslContextFactory.create("connection01");
    connectionFactory.setSocketFactory(contextAcceptAll.getSocketFactory());
    Connection connection = connectionFactory.newConnection("connection01");
    TestUtils.close(connection);
    connection = connectionFactory.newConnection("connection02");
    TestUtils.close(connection);
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SslContextFactory(com.rabbitmq.client.SslContextFactory) Connection(com.rabbitmq.client.Connection) SSLContext(javax.net.ssl.SSLContext)

Example 2 with SslContextFactory

use of com.rabbitmq.client.SslContextFactory in project rabbitmq-java-client by rabbitmq.

the class SslContextFactoryTest method doTestSetSslContextFactory.

private void doTestSetSslContextFactory(Supplier<ConnectionFactory> supplier) throws Exception {
    ConnectionFactory connectionFactory = supplier.get();
    SslContextFactory sslContextFactory = sslContextFactory();
    connectionFactory.setSslContextFactory(sslContextFactory);
    Connection connection = connectionFactory.newConnection("connection01");
    TestUtils.close(connection);
    try {
        connectionFactory.newConnection("connection02");
        fail("The SSL context of this client should not trust the server");
    } catch (SSLHandshakeException e) {
    // OK
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SslContextFactory(com.rabbitmq.client.SslContextFactory) Connection(com.rabbitmq.client.Connection) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 3 with SslContextFactory

use of com.rabbitmq.client.SslContextFactory in project rabbitmq-java-client by rabbitmq.

the class SslContextFactoryTest method sslContextFactory.

private SslContextFactory sslContextFactory() throws Exception {
    SSLContext contextAcceptAll = SSLContext.getInstance(tlsProtocol());
    contextAcceptAll.init(null, new TrustManager[] { new TrustEverythingTrustManager() }, null);
    SSLContext contextRejectAll = SSLContext.getInstance(tlsProtocol());
    contextRejectAll.init(null, new TrustManager[] { new TrustNothingTrustManager() }, null);
    Map<String, SSLContext> sslContexts = new HashMap<>();
    sslContexts.put("connection01", contextAcceptAll);
    sslContexts.put("connection02", contextRejectAll);
    SslContextFactory sslContextFactory = name -> sslContexts.get(name);
    return sslContextFactory;
}
Also used : X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) TrustManager(javax.net.ssl.TrustManager) Test(org.junit.Test) HashMap(java.util.HashMap) Connection(com.rabbitmq.client.Connection) CertificateException(java.security.cert.CertificateException) Supplier(java.util.function.Supplier) X509TrustManager(javax.net.ssl.X509TrustManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Map(java.util.Map) SslContextFactory(com.rabbitmq.client.SslContextFactory) Assert.fail(org.junit.Assert.fail) TrustEverythingTrustManager(com.rabbitmq.client.TrustEverythingTrustManager) TrustEverythingTrustManager(com.rabbitmq.client.TrustEverythingTrustManager) SslContextFactory(com.rabbitmq.client.SslContextFactory) HashMap(java.util.HashMap) SSLContext(javax.net.ssl.SSLContext)

Aggregations

Connection (com.rabbitmq.client.Connection)3 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)3 SslContextFactory (com.rabbitmq.client.SslContextFactory)3 SSLContext (javax.net.ssl.SSLContext)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 TrustEverythingTrustManager (com.rabbitmq.client.TrustEverythingTrustManager)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1