context = new SSLSupport() .setKeystoreProvider(keyStoreProvider) .setKeystorePath(keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(trustStoreProvider)
private void setupSsl() throws Exception { SSLContext context = new SSLSupport() .setKeystoreProvider(keyStoreProvider) .setKeystorePath(keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(trustStoreProvider) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); SSLServerSocketFactory sssf = context.getServerSocketFactory(); RMIServerSocketFactory rssf = new ArtemisSslRMIServerSocketFactory(sssf, this.isClientAuth(), rmiServerHost); RMIClientSocketFactory rcsf = new SslRMIClientSocketFactory(); environment.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, rssf); environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, rcsf); }
context = new SSLSupport() .setKeystoreProvider(keystoreProvider) .setKeystorePath(keystorePath) .setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider)
context = new SSLSupport() .setKeystoreProvider(keystoreProvider) .setKeystorePath(keystorePath) .setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider)
.setKeystorePath(keystorePath) .setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider)
.setKeystorePath(keystorePath) .setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider)
.setKeystorePath(keystorePath) .setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider)
@Test public void testContextWithKeyStorePathAsFile() throws Exception { URL url = Thread.currentThread().getContextClassLoader().getResource(keyStorePath); File file = new File(url.toURI()); new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(file.getAbsolutePath()) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); }
@Test public void testContextWithKeyStorePathAsURL() throws Exception { URL url = Thread.currentThread().getContextClassLoader().getResource(keyStorePath); new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(url.toString()) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); }
@Test public void testContextWithKeyStorePathAsRelativePath() throws Exception { // this test is dependent on a path relative to the tests directory. // it will fail if launch from somewhere else (or from an IDE) File currentDir = new File(System.getProperty("user.dir")); if (!currentDir.getAbsolutePath().endsWith("tests")) { return; } new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath("src/test/resources/" + keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); }
public String[] getEnabledCipherSuites() throws Exception { SSLContext context = new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(SERVER_SIDE_KEYSTORE) .setKeystorePassword(PASSWORD) .setTruststoreProvider(storeType) .setTruststorePath(CLIENT_SIDE_TRUSTSTORE) .setTruststorePassword(PASSWORD) .createContext(); SSLEngine engine = context.createSSLEngine(); return engine.getEnabledCipherSuites(); }
@Test public void testContextWithRightParameters() throws Exception { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); }
@Test public void testContextWithBadKeyStorePath() throws Exception { try { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath("not a keystore") .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); Assert.fail(); } catch (Exception e) { } }
@Test public void testContextWithNullKeyStorePath() throws Exception { try { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(null) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); } catch (Exception e) { Assert.fail(); } }
@Test public void testContextWithBadKeyStorePassword() throws Exception { try { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(keyStorePath) .setKeystorePassword("bad password") .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); Assert.fail(); } catch (Exception e) { } }
@Test public void testContextWithBadTrustStorePath() throws Exception { try { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath("not a trust store") .setTruststorePassword(trustStorePassword) .createContext(); Assert.fail(); } catch (Exception e) { } }
@Test public void testContextWithBadTrustStorePassword() throws Exception { try { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword("bad passord") .createContext(); Assert.fail(); } catch (Exception e) { } }
@Test public void testContextWithTrustAll() throws Exception { //This is using a bad password but should not fail because the trust store should be ignored with //the trustAll flag set to true new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(keyStorePath) .setKeystorePassword(keyStorePassword) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword("bad passord") .setTrustAll(true) .createContext(); } }
@Test public void testContextWithNullKeyStorePassword() throws Exception { try { new SSLSupport() .setKeystoreProvider(storeType) .setKeystorePath(keyStorePath) .setKeystorePassword(null) .setTruststoreProvider(storeType) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .createContext(); Assert.fail(); } catch (Exception e) { assertFalse(e instanceof NullPointerException); } }
private BlockingConnection retrieveMQTTConnection(String host, String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception { MQTT mqtt = new MQTT(); mqtt.setConnectAttemptsMax(1); mqtt.setReconnectAttemptsMax(0); mqtt.setHost(host); SSLContext sslContext = new SSLSupport() .setKeystorePath(keystorePath) .setKeystorePassword(keystorePass) .setTruststorePath(truststorePath) .setTruststorePassword(truststorePass) .createContext(); mqtt.setSslContext(sslContext); BlockingConnection connection = mqtt.blockingConnection(); connection.connect(); return connection; }