use of javax.net.ssl.KeyManagerFactory in project zm-mailbox by Zimbra.
the class NioServer method initSSLContext.
private static SSLContext initSSLContext() throws Exception {
FileInputStream fis = null;
try {
KeyStore ks = KeyStore.getInstance("JKS");
char[] pass = LC.mailboxd_keystore_password.value().toCharArray();
fis = new FileInputStream(LC.mailboxd_keystore.value());
ks.load(fis, pass);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, pass);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return context;
} finally {
ByteUtil.closeStream(fis);
}
}
use of javax.net.ssl.KeyManagerFactory in project jmeter by apache.
the class Proxy method getWrappedKeyManagers.
/**
* Return the key managers, wrapped to return a specific alias
*/
private KeyManager[] getWrappedKeyManagers(final String keyAlias) throws GeneralSecurityException, IOException {
if (!keyStore.containsAlias(keyAlias)) {
throw new IOException("Keystore does not contain alias " + keyAlias);
}
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEYMANAGERFACTORY);
kmf.init(keyStore, keyPassword.toCharArray());
final KeyManager[] keyManagers = kmf.getKeyManagers();
// Check if alias is suitable here, rather than waiting for connection to fail
final int keyManagerCount = keyManagers.length;
final KeyManager[] wrappedKeyManagers = new KeyManager[keyManagerCount];
for (int i = 0; i < keyManagerCount; i++) {
wrappedKeyManagers[i] = new ServerAliasKeyManager(keyManagers[i], keyAlias);
}
return wrappedKeyManagers;
}
use of javax.net.ssl.KeyManagerFactory in project logging-log4j2 by apache.
the class KeyStoreConfiguration method initKeyManagerFactory.
public KeyManagerFactory initKeyManagerFactory() throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException {
final KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(this.keyManagerFactoryAlgorithm);
kmFactory.init(this.getKeyStore(), this.getPasswordAsCharArray());
return kmFactory;
}
use of javax.net.ssl.KeyManagerFactory in project karaf by apache.
the class LdapPoolingTest method keystore.
@Before
public void keystore() throws Exception {
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream("src/test/resources/org/apache/karaf/jaas/modules/ldap/ldaps.jks"), "123456".toCharArray());
kmf.init(ks, "123456".toCharArray());
tmf.init(ks);
String javaVendor = System.getProperty("java.vendor");
if (javaVendor.contains("IBM")) {
sslContext = SSLContext.getInstance("SSL_TLSv2", "IBMJSSE2");
} else {
sslContext = SSLContext.getInstance("TLSv1.2");
}
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
}
use of javax.net.ssl.KeyManagerFactory in project wildfly by wildfly.
the class RemotingLoginModuleUseNewClientCertTestCase method configureEjbClient.
// Private methods -------------------------------------------------------
/**
* Configure {@link SSLContext} and create EJB client properties.
*
* @param clientName
* @return
* @throws Exception
*/
private Properties configureEjbClient(String clientName) throws Exception {
// create new SSLContext based on client keystore and truststore and use this SSLContext instance as a default for this test
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(KeyStoreUtil.getKeyStore(getClientKeystoreFile(clientName), KEYSTORE_PASSWORD.toCharArray()), KEYSTORE_PASSWORD.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(KeyStoreUtil.getKeyStore(CLIENTS_TRUSTSTORE_FILE, KEYSTORE_PASSWORD.toCharArray()));
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
SSLContext.setDefault(sslContext);
final Properties env = new Properties();
env.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
env.put("java.naming.provider.url", "remote://" + mgmtClient.getMgmtAddress() + ":" + REMOTING_PORT_TEST);
env.put("jboss.naming.client.ejb.context", "true");
env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "testing");
// SSL related config parameters
env.put("jboss.naming.client.remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "true");
env.put("jboss.naming.client.connect.options.org.xnio.Options.SSL_STARTTLS", "true");
return env;
}
Aggregations