.setKeystorePassword(keyStorePassword) .setTruststoreProvider(trustStoreProvider) .setTruststorePath(trustStorePath) .setTruststorePassword(trustStorePassword) .setSslProvider(sslProvider)
.setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider) .setTruststorePath(truststorePath) .setTruststorePassword(truststorePassword) .setTrustAll(trustAll)
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); }
.setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider) .setTruststorePath(truststorePath) .setTruststorePassword(truststorePassword) .setTrustAll(trustAll)
.setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider) .setTruststorePath(truststorePath) .setTruststorePassword(truststorePassword) .setSslProvider(sslProvider)
.setKeystorePassword(keystorePassword) .setTruststoreProvider(truststoreProvider) .setTruststorePath(truststorePath) .setTruststorePassword(truststorePassword) .setSslProvider(sslProvider)
@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; }
@Test public void testOneWaySSLUsingDefaultSslContext() throws Exception { createCustomSslServer(); String text = RandomUtil.randomString(); tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true); tc.getParams().put(TransportConstants.USE_DEFAULT_SSL_CONTEXT_PROP_NAME, true); SSLContext.setDefault(new SSLSupport() .setTruststoreProvider(storeType) .setTruststorePath(CLIENT_SIDE_TRUSTSTORE) .setTruststorePassword(PASSWORD) .createContext()); ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc)); ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator)); ClientSession session = addClientSession(sf.createSession(false, true, true)); session.createQueue(CoreClientOverOneWaySSLTest.QUEUE, CoreClientOverOneWaySSLTest.QUEUE, false); ClientProducer producer = addClientProducer(session.createProducer(CoreClientOverOneWaySSLTest.QUEUE)); ClientMessage message = createTextMessage(session, text); producer.send(message); ClientConsumer consumer = addClientConsumer(session.createConsumer(CoreClientOverOneWaySSLTest.QUEUE)); session.start(); ClientMessage m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(text, m.getBodyBuffer().readString()); }