public SSLContextBuilder loadKeyMaterial( final URL url, final char[] storePassword, final char[] keyPassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { return loadKeyMaterial(url, storePassword, keyPassword, null); }
public SSLContextBuilder loadKeyMaterial( final URL url, final char[] storePassword, final char[] keyPassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { return loadKeyMaterial(url, storePassword, keyPassword, null); }
public SSLContextBuilder loadKeyMaterial( final File file, final char[] storePassword, final char[] keyPassword, final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { Args.notNull(file, "Keystore file"); final KeyStore identityStore = KeyStore.getInstance(keyStoreType); try (final FileInputStream inStream = new FileInputStream(file)) { identityStore.load(inStream, storePassword); } return loadKeyMaterial(identityStore, keyPassword, aliasStrategy); }
public SSLContextBuilder loadKeyMaterial( final File file, final char[] storePassword, final char[] keyPassword, final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { Args.notNull(file, "Keystore file"); final KeyStore identityStore = KeyStore.getInstance(keyStoreType); try (final FileInputStream inStream = new FileInputStream(file)) { identityStore.load(inStream, storePassword); } return loadKeyMaterial(identityStore, keyPassword, aliasStrategy); }
public SSLContextBuilder loadKeyMaterial( final URL url, final char[] storePassword, final char[] keyPassword, final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { Args.notNull(url, "Keystore URL"); final KeyStore identityStore = KeyStore.getInstance(keyStoreType); try (final InputStream inStream = url.openStream()) { identityStore.load(inStream, storePassword); } return loadKeyMaterial(identityStore, keyPassword, aliasStrategy); }
public SSLContextBuilder loadKeyMaterial( final URL url, final char[] storePassword, final char[] keyPassword, final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { Args.notNull(url, "Keystore URL"); final KeyStore identityStore = KeyStore.getInstance(keyStoreType); try (final InputStream inStream = url.openStream()) { identityStore.load(inStream, storePassword); } return loadKeyMaterial(identityStore, keyPassword, aliasStrategy); }
@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(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(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 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()); }
final String keyPassword = "nopassword"; final SSLContext serverSslContext = SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertNotNull(serverSslContext);
final String keyPassword = "nopassword"; final SSLContext serverSslContext = SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertNotNull(serverSslContext);
final String keyPassword = "nopassword"; final SSLContext serverSslContext = SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertNotNull(serverSslContext);
final String keyPassword = "nopassword"; final SSLContext serverSslContext = SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertNotNull(serverSslContext);
final String keyPassword = "nopassword"; final SSLContext serverSslContext = SSLContextBuilder.create() .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray()) .build(); Assert.assertNotNull(serverSslContext);
@Test public void testBuildAllDefaults() throws Exception { final SSLContext sslContext = SSLContextBuilder.create() .setKeyStoreType(KeyStore.getDefaultType()) .setKeyManagerFactoryAlgorithm(KeyManagerFactory.getDefaultAlgorithm()) .setTrustManagerFactoryAlgorithm(TrustManagerFactory.getDefaultAlgorithm()) .setProvider(PROVIDER_SUN_JSSE) .setProtocol("TLS") .setSecureRandom(null) .loadTrustMaterial((KeyStore) null, null) .loadKeyMaterial((KeyStore) null, null, null) .build(); Assert.assertNotNull(sslContext); Assert.assertEquals("TLS", sslContext.getProtocol()); Assert.assertEquals(PROVIDER_SUN_JSSE, sslContext.getProvider().getName()); }
@Test public void testBuildAllNull_deprecated() throws Exception { final SSLContext sslContext = SSLContextBuilder.create() .setProtocol(null) .setSecureRandom(null) .loadTrustMaterial((KeyStore) null, null) .loadKeyMaterial((KeyStore) null, null, null) .build(); Assert.assertNotNull(sslContext); Assert.assertEquals("TLS", sslContext.getProtocol()); }
@Test public void testBuildAllNull() throws Exception { final SSLContext sslContext = SSLContextBuilder.create() .setKeyStoreType(null) .setKeyManagerFactoryAlgorithm(null) .setTrustManagerFactoryAlgorithm(null) .setProtocol(null) .setProvider((String) null) .setSecureRandom(null) .loadTrustMaterial((KeyStore) null, null) .loadKeyMaterial((KeyStore) null, null, null) .build(); Assert.assertNotNull(sslContext); Assert.assertEquals("TLS", sslContext.getProtocol()); Assert.assertEquals(PROVIDER_SUN_JSSE, sslContext.getProvider().getName()); }