mirror of https://github.com/apache/activemq.git
Create a proper SSLContext for the MQTT client provider in the tests to avoid failure on newer JDKs
This commit is contained in:
parent
c530b69e16
commit
6e2edf08c3
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue