Search in sources :

Example 41 with KeyManagerFactory

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);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 42 with KeyManagerFactory

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;
}
Also used : IOException(java.io.IOException) KeyManager(javax.net.ssl.KeyManager) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 43 with KeyManagerFactory

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;
}
Also used : KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 44 with KeyManagerFactory

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());
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SecureRandom(java.security.SecureRandom) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) Before(org.junit.Before)

Example 45 with KeyManagerFactory

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;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) Properties(java.util.Properties) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

KeyManagerFactory (javax.net.ssl.KeyManagerFactory)183 KeyStore (java.security.KeyStore)134 SSLContext (javax.net.ssl.SSLContext)90 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)81 FileInputStream (java.io.FileInputStream)48 IOException (java.io.IOException)39 KeyManager (javax.net.ssl.KeyManager)37 InputStream (java.io.InputStream)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)34 TrustManager (javax.net.ssl.TrustManager)33 KeyStoreException (java.security.KeyStoreException)26 KeyManagementException (java.security.KeyManagementException)23 UnrecoverableKeyException (java.security.UnrecoverableKeyException)23 CertificateException (java.security.cert.CertificateException)23 SecureRandom (java.security.SecureRandom)21 File (java.io.File)12 Certificate (java.security.cert.Certificate)11 X509KeyManager (javax.net.ssl.X509KeyManager)11 URL (java.net.URL)10 X509TrustManager (javax.net.ssl.X509TrustManager)10