activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-6187
Date Fri, 26 Feb 2016 18:42:38 GMT
Repository: activemq
Updated Branches:
  refs/heads/master c530b69e1 -> 6e2edf08c


https://issues.apache.org/jira/browse/AMQ-6187

Create a proper SSLContext for the MQTT client provider in the tests to
avoid failure on newer JDKs

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/6e2edf08
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/6e2edf08
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/6e2edf08

Branch: refs/heads/master
Commit: 6e2edf08c3e3dda7656dffa1af8c92b6ed333c22
Parents: c530b69
Author: Timothy Bish <tabish121@gmail.com>
Authored: Fri Feb 26 13:42:16 2016 -0500
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Fri Feb 26 13:42:16 2016 -0500

----------------------------------------------------------------------
 .../transport/mqtt/MQTTTestSupport.java         | 53 +++++++++-----------
 1 file changed, 24 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/6e2edf08/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTestSupport.java
----------------------------------------------------------------------
diff --git a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTestSupport.java
b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTestSupport.java
index 0b58687..198b6c4 100644
--- a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTestSupport.java
+++ b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTestSupport.java
@@ -21,9 +21,6 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.security.ProtectionDomain;
-import java.security.SecureRandom;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
@@ -32,10 +29,6 @@ import java.util.concurrent.TimeUnit;
 import javax.jms.JMSException;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerPlugin;
@@ -309,9 +302,18 @@ public class MQTTTestSupport {
         if (!isUseSSL()) {
             provider.connect("tcp://localhost:" + port);
         } else {
-            SSLContext ctx = SSLContext.getInstance("TLS");
-            ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() },
new SecureRandom());
-            provider.setSslContext(ctx);
+            // Setup SSL context...
+            File trustStore = new File(basedir(), "src/test/resources/server.keystore");
+            File keyStore = new File(basedir(), "src/test/resources/client.keystore");
+
+            final ResourceLoadingSslContext sslContext = new ResourceLoadingSslContext();
+            sslContext.setKeyStore(keyStore.getCanonicalPath());
+            sslContext.setKeyStorePassword("password");
+            sslContext.setTrustStore(trustStore.getCanonicalPath());
+            sslContext.setTrustStorePassword("password");
+            sslContext.afterPropertiesSet();
+
+            provider.setSslContext(sslContext.getSSLContext());
             provider.connect("ssl://localhost:" + port);
         }
     }
@@ -419,9 +421,18 @@ public class MQTTTestSupport {
         }
         mqtt.setCleanSession(clean);
 
-        SSLContext ctx = SSLContext.getInstance("TLS");
-        ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new
SecureRandom());
-        mqtt.setSslContext(ctx);
+        // Setup SSL context...
+        File trustStore = new File(basedir(), "src/test/resources/server.keystore");
+        File keyStore = new File(basedir(), "src/test/resources/client.keystore");
+
+        final ResourceLoadingSslContext sslContext = new ResourceLoadingSslContext();
+        sslContext.setKeyStore(keyStore.getCanonicalPath());
+        sslContext.setKeyStorePassword("password");
+        sslContext.setTrustStore(trustStore.getCanonicalPath());
+        sslContext.setTrustStorePassword("password");
+        sslContext.afterPropertiesSet();
+
+        mqtt.setSslContext(sslContext.getSSLContext());
         return mqtt;
     }
 
@@ -443,20 +454,4 @@ public class MQTTTestSupport {
             }
         };
     }
-
-    static class DefaultTrustManager implements X509TrustManager {
-
-        @Override
-        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws
CertificateException {
-        }
-
-        @Override
-        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws
CertificateException {
-        }
-
-        @Override
-        public X509Certificate[] getAcceptedIssuers() {
-            return new X509Certificate[0];
-        }
-    }
 }


Mime
View raw message