use of javax.net.ssl.X509KeyManager in project ddf by codice.
the class SecureCxfClientFactoryTest method testAliasSelectorKeyManager.
@Test
public void testAliasSelectorKeyManager() {
X509KeyManager keyManager = mock(X509KeyManager.class);
String alias = "testAlias";
String[] aliases = new String[] { alias };
when(keyManager.chooseClientAlias(any(), any(), any())).thenReturn(alias);
when(keyManager.getClientAliases(any(), any())).thenReturn(aliases);
AliasSelectorKeyManager aliasSelectorKeyManager = new AliasSelectorKeyManager(keyManager, alias);
String chosenAlias = aliasSelectorKeyManager.chooseClientAlias(new String[] { "x509" }, null, null);
assertThat(chosenAlias, is(alias));
}
use of javax.net.ssl.X509KeyManager in project ddf by codice.
the class SecureCxfClientFactoryImpl method getSSLSocketFactory.
private SSLSocketFactory getSSLSocketFactory(String sslProtocol, String alias, KeyManager[] keyManagers, TrustManager[] trustManagers) throws KeyManagementException, NoSuchAlgorithmException {
if (ArrayUtils.isNotEmpty(keyManagers)) {
for (int i = 0; i < keyManagers.length; i++) {
if (keyManagers[i] instanceof X509KeyManager) {
keyManagers[i] = new AliasSelectorKeyManager((X509KeyManager) keyManagers[i], alias);
}
}
}
SSLContext context = SSLContext.getInstance(sslProtocol);
context.init(keyManagers, trustManagers, null);
return context.getSocketFactory();
}
use of javax.net.ssl.X509KeyManager in project cas by apereo.
the class CompositeX509KeyManagerTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
val ks = KeyStore.getInstance("JKS");
ks.load(null, "changeit".toCharArray());
kmf.init(ks, "changeit".toCharArray());
val km = kmf.getKeyManagers();
val managers = Arrays.stream(km).filter(tm -> tm instanceof X509KeyManager).map(X509KeyManager.class::cast).collect(Collectors.toList());
val input = new CompositeX509KeyManager(managers);
assertNull(input.chooseClientAlias(new String[] { "any" }, new Principal[] {}, mock(Socket.class)));
assertNull(input.chooseServerAlias("any", new Principal[] {}, mock(Socket.class)));
assertNull(input.getCertificateChain("cas"));
assertEquals(0, input.getClientAliases("cas", new Principal[] {}).length);
assertEquals(0, input.getServerAliases("cas", new Principal[] {}).length);
}
use of javax.net.ssl.X509KeyManager in project zookeeper by apache.
the class X509UtilTest method testLoadPEMKeyStoreWithWrongPassword.
@ParameterizedTest
@MethodSource("data")
public void testLoadPEMKeyStoreWithWrongPassword(X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception {
init(caKeyType, certKeyType, keyPassword, paramIndex);
assertThrows(X509Exception.KeyManagerException.class, () -> {
// Attempting to load with the wrong key password should fail
X509KeyManager km = X509Util.createKeyManager(x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), // intentionally use the wrong password
"wrong password", KeyStoreFileType.PEM.getPropertyValue());
});
}
use of javax.net.ssl.X509KeyManager in project zookeeper by apache.
the class X509UtilTest method testLoadJKSKeyStore.
@ParameterizedTest
@MethodSource("data")
public void testLoadJKSKeyStore(X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception {
init(caKeyType, certKeyType, keyPassword, paramIndex);
// Make sure we can instantiate a key manager from the JKS file on disk
X509KeyManager km = X509Util.createKeyManager(x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getKeyStorePassword(), KeyStoreFileType.JKS.getPropertyValue());
}
Aggregations