Search in sources :

Example 1 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project vert.x by eclipse.

the class KeyStoreHelper method getKeyMgrFactory.

public KeyManagerFactory getKeyMgrFactory(VertxInternal vertx) throws Exception {
    KeyManagerFactory fact = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    fact.getProvider();
    KeyStore ks = loadStore(vertx);
    fact.init(ks, password != null ? password.toCharArray() : null);
    return fact;
}
Also used : KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 2 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project elasticsearch by elastic.

the class GceDiscoverTests method getSSLContext.

private static SSLContext getSSLContext() throws Exception {
    char[] passphrase = "keypass".toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    try (InputStream stream = GceDiscoverTests.class.getResourceAsStream("/test-node.jks")) {
        assertNotNull("can't find keystore file", stream);
        ks.load(stream, passphrase);
    }
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, passphrase);
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);
    SSLContext ssl = SSLContext.getInstance("TLS");
    ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    return ssl;
}
Also used : InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 3 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project cas by apereo.

the class FileTrustStoreSslSocketFactory method getKeyManager.

/**
     * Gets key manager.
     *
     * @param algorithm the algorithm
     * @param keystore  the keystore
     * @param password  the password
     * @return the key manager
     * @throws Exception the exception
     */
private static X509KeyManager getKeyManager(final String algorithm, final KeyStore keystore, final char[] password) throws Exception {
    final KeyManagerFactory factory = KeyManagerFactory.getInstance(algorithm);
    factory.init(keystore, password);
    return (X509KeyManager) factory.getKeyManagers()[0];
}
Also used : X509KeyManager(javax.net.ssl.X509KeyManager) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 4 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project flink by apache.

the class SSLUtils method createSSLServerContext.

/**
	 * Creates the SSL Context for the server if SSL is configured
	 *
	 * @param sslConfig
	 *        The application configuration
	 * @return The SSLContext object which can be used by the ssl transport server
	 * 	       Returns null if SSL is disabled
	 * @throws Exception
	 *         Thrown if there is any misconfiguration
	 */
public static SSLContext createSSLServerContext(Configuration sslConfig) throws Exception {
    Preconditions.checkNotNull(sslConfig);
    SSLContext serverSSLContext = null;
    if (getSSLEnabled(sslConfig)) {
        LOG.debug("Creating server SSL context from configuration");
        String keystoreFilePath = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEYSTORE, null);
        String keystorePassword = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEYSTORE_PASSWORD, null);
        String certPassword = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEY_PASSWORD, null);
        String sslProtocolVersion = sslConfig.getString(ConfigConstants.SECURITY_SSL_PROTOCOL, ConfigConstants.DEFAULT_SECURITY_SSL_PROTOCOL);
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        FileInputStream keyStoreFile = null;
        try {
            keyStoreFile = new FileInputStream(new File(keystoreFilePath));
            ks.load(keyStoreFile, keystorePassword.toCharArray());
        } finally {
            if (keyStoreFile != null) {
                keyStoreFile.close();
            }
        }
        // Set up key manager factory to use the server key store
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, certPassword.toCharArray());
        // Initialize the SSLContext
        serverSSLContext = SSLContext.getInstance(sslProtocolVersion);
        serverSSLContext.init(kmf.getKeyManagers(), null, null);
    }
    return serverSSLContext;
}
Also used : SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) File(java.io.File) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 5 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project OpenAM by OpenRock.

the class Client method initializeJSSE.

/**
     * Initializes JSSE enviroment.
     *
     * @throws Exception if an error occurs while initializing JSSE
     */
private static void initializeJSSE() throws Exception {
    // put SunJSSE at fisrt place, so that JSSE will work
    Provider provider = Security.getProvider("SunJSSE");
    if (provider != null) {
        Security.removeProvider("SunJSSE");
        Security.insertProviderAt(provider, 1);
    }
    String algorithm = SystemPropertiesManager.get(SOAP_TRUST_SECMNGR_ALGO_PROP);
    if (algorithm == null || algorithm.length() <= 0) {
        algorithm = "SunX509";
    }
    JKSKeyProvider jkskp = createKeyProvider();
    KeyStore trustStore = jkskp.getKeyStore();
    KeyManagerFactory kf = KeyManagerFactory.getInstance(algorithm);
    kf.init(trustStore, jkskp.getPrivateKeyPass().toCharArray());
    kms = kf.getKeyManagers();
    defaultX509km = (X509KeyManager) kms[0];
    defineTrustManager(trustStore, algorithm);
}
Also used : JKSKeyProvider(com.sun.identity.saml.xmlsig.JKSKeyProvider) KeyStore(java.security.KeyStore) JKSKeyProvider(com.sun.identity.saml.xmlsig.JKSKeyProvider) Provider(java.security.Provider) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

KeyManagerFactory (javax.net.ssl.KeyManagerFactory)431 KeyStore (java.security.KeyStore)315 SSLContext (javax.net.ssl.SSLContext)212 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)197 FileInputStream (java.io.FileInputStream)129 IOException (java.io.IOException)117 InputStream (java.io.InputStream)104 KeyManager (javax.net.ssl.KeyManager)101 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)77 TrustManager (javax.net.ssl.TrustManager)73 KeyStoreException (java.security.KeyStoreException)60 SecureRandom (java.security.SecureRandom)58 CertificateException (java.security.cert.CertificateException)55 UnrecoverableKeyException (java.security.UnrecoverableKeyException)52 KeyManagementException (java.security.KeyManagementException)49 File (java.io.File)37 X509Certificate (java.security.cert.X509Certificate)31 GeneralSecurityException (java.security.GeneralSecurityException)29 X509TrustManager (javax.net.ssl.X509TrustManager)28 Certificate (java.security.cert.Certificate)27