@Test(expected=KeyStoreException.class) public void testBuildNoSuchKeyStoreType() throws Exception { final URL resource1 = getResource("/test-keypasswd.keystore"); final String storePassword = "nopassword"; final String keyPassword = "password"; SSLContextBuilder.create() .setKeyStoreType(" BAD ") .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); }
@Test public void testSSLHandshakeProtocolMismatch1() throws Exception { if (isWindows()) { thrown.expect(IOException.class); } else { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; .build(); Assert.assertNotNull(serverSslContext); final URL resource2 = getResource("/test-client.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test public void testSSLHandshakeProtocolMismatch2() throws Exception { if (isWindows()) { thrown.expect(IOException.class); } else { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; .build(); Assert.assertNotNull(serverSslContext); final URL resource2 = getResource("/test-client.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test(expected=NoSuchAlgorithmException.class) public void testBuildNoSuchKeyManagerFactoryAlgorithm() throws Exception { final URL resource1 = getResource("/test-keypasswd.keystore"); final String storePassword = "nopassword"; final String keyPassword = "password"; SSLContextBuilder.create() .setKeyManagerFactoryAlgorithm(" BAD ") .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); }
@Test public void testKeyWithAlternatePasswordInvalid() throws Exception { thrown.expect(UnrecoverableKeyException.class); final URL resource1 = getResource("/test-keypasswd.keystore"); final String storePassword = "nopassword"; final String keyPassword = "!password"; SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .loadTrustMaterial(resource1, storePassword.toCharArray()) .build(); }
@Test public void testBuildWithProvider() throws Exception { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; final SSLContext sslContext=SSLContextBuilder.create() .setProvider(Security.getProvider(PROVIDER_SUN_JSSE)) .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertEquals(PROVIDER_SUN_JSSE, sslContext.getProvider().getName()); }
@Test public void testKeyWithAlternatePassword() throws Exception { final URL resource1 = getResource("/test-keypasswd.keystore"); final String storePassword = "nopassword"; final String keyPassword = "password"; final SSLContext sslContext = SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .loadTrustMaterial(resource1, storePassword.toCharArray()) .build(); Assert.assertNotNull(sslContext); final SSLSocketFactory socketFactory = sslContext.getSocketFactory(); Assert.assertNotNull(socketFactory); }
@Test public void testBuildWithProviderName() throws Exception { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; final SSLContext sslContext=SSLContextBuilder.create() .setProvider(PROVIDER_SUN_JSSE) .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertEquals(PROVIDER_SUN_JSSE, sslContext.getProvider().getName()); }
@Test(expected=NoSuchAlgorithmException.class) public void testBuildNoSuchTrustManagerFactoryAlgorithm() throws Exception { final URL resource1 = getResource("/test-keypasswd.keystore"); final String storePassword = "nopassword"; SSLContextBuilder.create() .setTrustManagerFactoryAlgorithm(" BAD ") .loadTrustMaterial(resource1, storePassword.toCharArray()) .build(); }
thrown.expect(IOException.class); final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; .build(); Assert.assertNotNull(serverSslContext); final URL resource2 = getResource("/test.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test public void testSSLHandshakeServerTrusted() throws Exception { final URL resource1 = getResource("/test.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword";
thrown.expect(IOException.class); final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; .build(); Assert.assertNotNull(serverSslContext); final URL resource2 = getResource("/test-client.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test public void testSSLHandshakeClientAuthenticated() throws Exception { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; .build(); Assert.assertNotNull(serverSslContext); final URL resource2 = getResource("/test-client.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test public void testSSLHandshakeClientUnauthenticated() throws Exception { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; .build(); Assert.assertNotNull(serverSslContext); final URL resource2 = getResource("/test-client.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test public void testSSLHandshakeClientAuthenticatedPrivateKeyStrategy() throws Exception { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword"; final URL resource2 = getResource("/test-client.keystore"); final SSLContext clientSslContext = SSLContextBuilder.create() .loadTrustMaterial(resource2, storePassword.toCharArray())
@Test public void testSSLHandshakeServerCustomTrustStrategy() throws Exception { final URL resource1 = getResource("/test-server.keystore"); final String storePassword = "nopassword"; final String keyPassword = "nopassword";