Search in sources :

Example 1 with TrustEverythingTrustManager

use of com.rabbitmq.client.TrustEverythingTrustManager 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)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 SslContextFactory (com.rabbitmq.client.SslContextFactory)1 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 SSLContext (javax.net.ssl.SSLContext)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)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