use of javax.net.ssl.SSLSocketFactory in project camel by apache.
the class CamelSSLIRCConnection method connect.
@Override
public void connect() throws IOException {
if (sslContextParameters == null) {
super.connect();
} else {
if (level != 0) {
throw new SocketException("Socket closed or already open (" + level + ")");
}
IOException exception = null;
final SSLContext sslContext;
try {
sslContext = sslContextParameters.createSSLContext(camelContext);
} catch (GeneralSecurityException e) {
throw new RuntimeCamelException("Error in SSLContextParameters configuration or instantiation.", e);
}
final SSLSocketFactory sf = sslContext.getSocketFactory();
SSLSocket s = null;
for (int i = 0; i < ports.length && s == null; i++) {
try {
s = (SSLSocket) sf.createSocket(host, ports[i]);
s.startHandshake();
exception = null;
} catch (SSLNotSupportedException exc) {
if (s != null) {
s.close();
}
s = null;
throw exc;
} catch (IOException exc) {
if (s != null) {
s.close();
}
s = null;
exception = exc;
}
}
if (exception != null) {
// connection wasn't successful at any port
throw exception;
}
prepare(s);
}
}
use of javax.net.ssl.SSLSocketFactory in project robovm by robovm.
the class URLConnectionTest method testHttpsWithCustomTrustManager.
public void testHttpsWithCustomTrustManager() throws Exception {
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
RecordingTrustManager trustManager = new RecordingTrustManager();
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[] { trustManager }, new java.security.SecureRandom());
HostnameVerifier defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
SSLSocketFactory defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
try {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setBody("ABC"));
server.enqueue(new MockResponse().setBody("DEF"));
server.enqueue(new MockResponse().setBody("GHI"));
server.play();
URL url = server.getUrl("/");
assertEquals("ABC", readAscii(url.openStream(), Integer.MAX_VALUE));
assertEquals("DEF", readAscii(url.openStream(), Integer.MAX_VALUE));
assertEquals("GHI", readAscii(url.openStream(), Integer.MAX_VALUE));
assertEquals(Arrays.asList("verify " + hostName), hostnameVerifier.calls);
assertEquals(Arrays.asList("checkServerTrusted [" + "CN=" + hostName + " 1, " + "CN=Test Intermediate Certificate Authority 1, " + "CN=Test Root Certificate Authority 1" + "] RSA"), trustManager.calls);
} finally {
HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
}
}
use of javax.net.ssl.SSLSocketFactory in project gocd by gocd.
the class WeakSSLConfigTest method shouldIncludeAllSuitesIfTheMagicThreeDoNotExist.
@Test
public void shouldIncludeAllSuitesIfTheMagicThreeDoNotExist() throws Exception {
SSLSocketFactory socketFactory = mock(SSLSocketFactory.class);
String[] supportedSuites = { "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" };
when(socketFactory.getSupportedCipherSuites()).thenReturn(supportedSuites);
WeakSSLConfig goSSLConfig = new WeakSSLConfig(socketFactory);
List<String> includedSuites = Arrays.asList(goSSLConfig.getCipherSuitesToBeIncluded());
assertThat(includedSuites.size(), is(supportedSuites.length));
for (String cipherSuite : includedSuites) {
assertThat(Arrays.asList(supportedSuites).contains(cipherSuite), is(true));
}
}
use of javax.net.ssl.SSLSocketFactory in project gocd by gocd.
the class WeakSSLConfigTest method shouldIncludeTheMagicThreeWhichAreSupportedByOurJetty.
@Test
public void shouldIncludeTheMagicThreeWhichAreSupportedByOurJetty() throws Exception {
SSLSocketFactory socketFactory = mock(SSLSocketFactory.class);
when(socketFactory.getSupportedCipherSuites()).thenReturn(new String[] { "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA256", "SSL_RSA_WITH_RC4_128_SHA", "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "SSL_RSA_WITH_RC4_128_MD5", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" });
WeakSSLConfig sslConfig = new WeakSSLConfig(socketFactory);
assertThat(Arrays.asList(sslConfig.getCipherSuitesToBeIncluded()), is(Arrays.asList("SSL_RSA_WITH_RC4_128_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_WITH_RC4_128_MD5")));
}
use of javax.net.ssl.SSLSocketFactory in project gocd by gocd.
the class GoServerTest method shouldLoadAllJarsInTheAddonsDirectoryIntoClassPath.
@Test
public void shouldLoadAllJarsInTheAddonsDirectoryIntoClassPath() throws Exception {
File addonsDirectory = createInAddonDir("some-addon-dir");
FileSystemUtils.createFile("addon-1.JAR", addonsDirectory);
FileSystemUtils.createFile("addon-2.jar", addonsDirectory);
FileSystemUtils.createFile("addon-3.jAR", addonsDirectory);
FileSystemUtils.createFile("some-file-which-does-not-end-with-dot-jar.txt", addonsDirectory);
File oneAddonDirectory = createInAddonDir("one-addon-dir");
FileSystemUtils.createFile("addon-1.jar", oneAddonDirectory);
File noAddonDirectory = createInAddonDir("no-addon-dir");
SSLSocketFactory sslSocketFactory = mock(SSLSocketFactory.class);
when(sslSocketFactory.getSupportedCipherSuites()).thenReturn(new String[0]);
GoServer goServerWithMultipleAddons = new GoServer(setAddonsPathTo(addonsDirectory), sslSocketFactory);
goServerWithMultipleAddons.startServer();
AppServerStub appServer = (AppServerStub) com.thoughtworks.go.util.ReflectionUtil.getField(goServerWithMultipleAddons, "server");
assertExtraClasspath(appServer, "test-addons/some-addon-dir/addon-1.JAR", "test-addons/some-addon-dir/addon-2.jar", "test-addons/some-addon-dir/addon-3.jAR");
GoServer goServerWithOneAddon = new GoServer(setAddonsPathTo(oneAddonDirectory), sslSocketFactory);
goServerWithOneAddon.startServer();
appServer = (AppServerStub) com.thoughtworks.go.util.ReflectionUtil.getField(goServerWithOneAddon, "server");
assertExtraClasspath(appServer, "test-addons/one-addon-dir/addon-1.jar");
GoServer goServerWithNoAddon = new GoServer(setAddonsPathTo(noAddonDirectory), sslSocketFactory);
goServerWithNoAddon.startServer();
appServer = (AppServerStub) com.thoughtworks.go.util.ReflectionUtil.getField(goServerWithNoAddon, "server");
assertExtraClasspath(appServer, "");
GoServer goServerWithInaccessibleAddonDir = new GoServer(setAddonsPathTo(new File("non-existent-directory")), sslSocketFactory);
goServerWithInaccessibleAddonDir.startServer();
appServer = (AppServerStub) com.thoughtworks.go.util.ReflectionUtil.getField(goServerWithNoAddon, "server");
assertExtraClasspath(appServer, "");
}
Aggregations