Search in sources :

Example 26 with X509KeyManager

use of javax.net.ssl.X509KeyManager in project Payara by payara.

the class IIOPSSLUtilImpl method getKeyManagers.

@Override
public KeyManager[] getKeyManagers(String alias) {
    KeyManager[] mgrs = null;
    try {
        if (alias != null && !sslUtils.isTokenKeyAlias(alias)) {
            throw new IllegalStateException(getFormatMessage("iiop.cannot_find_keyalias", new Object[] { alias }));
        }
        mgrs = sslUtils.getKeyManagers();
        if (alias != null && mgrs != null && mgrs.length > 0) {
            KeyManager[] newMgrs = new KeyManager[mgrs.length];
            for (int i = 0; i < mgrs.length; i++) {
                if (_logger.isLoggable(Level.FINE)) {
                    StringBuffer msg = new StringBuffer("Setting J2EEKeyManager for ");
                    msg.append(" alias : " + alias);
                    _logger.log(Level.FINE, msg.toString());
                }
                newMgrs[i] = new J2EEKeyManager((X509KeyManager) mgrs[i], alias);
            }
            mgrs = newMgrs;
        }
    } catch (Exception e) {
        // TODO: log here
        throw new RuntimeException(e);
    }
    return mgrs;
}
Also used : X509KeyManager(javax.net.ssl.X509KeyManager) J2EEKeyManager(com.sun.enterprise.security.ssl.J2EEKeyManager) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) J2EEKeyManager(com.sun.enterprise.security.ssl.J2EEKeyManager)

Example 27 with X509KeyManager

use of javax.net.ssl.X509KeyManager in project Payara by payara.

the class SSLSocketFactory method initStoresAtStartup.

// V3: to break dependency of SSLUtils on this class
// public static void setManagers(KeyManager[] kmgrs, TrustManager[] tmgrs) {
// keyManagers = kmgrs;
// trustManagers = tmgrs;
// }
// V3: Copied from SSLUtils to break dependency of SSLUtils on this class
public static synchronized void initStoresAtStartup() throws Exception {
    if (initialized) {
        return;
    }
    ServiceLocator habitat = Globals.getDefaultHabitat();
    SSLUtils sslUtils = habitat.getService(SSLUtils.class);
    keyManagers = sslUtils.getKeyManagers();
    trustManagers = sslUtils.getTrustManagers();
    // Creating a default SSLContext and HttpsURLConnection for clients
    // that use Https
    SSLContext ctx = SSLContext.getInstance("TLS");
    String keyAlias = System.getProperty(SSLUtils.HTTPS_OUTBOUND_KEY_ALIAS);
    KeyManager[] kMgrs = sslUtils.getKeyManagers();
    if (keyAlias != null && keyAlias.length() > 0 && kMgrs != null) {
        for (int i = 0; i < kMgrs.length; i++) {
            kMgrs[i] = new J2EEKeyManager((X509KeyManager) kMgrs[i], keyAlias);
        }
    }
    ctx.init(kMgrs, sslUtils.getTrustManagers(), null);
    HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
    initialized = true;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) X509KeyManager(javax.net.ssl.X509KeyManager) SSLContext(javax.net.ssl.SSLContext) J2EEKeyManager(com.sun.enterprise.security.ssl.J2EEKeyManager) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) J2EEKeyManager(com.sun.enterprise.security.ssl.J2EEKeyManager) SSLUtils(com.sun.enterprise.security.ssl.SSLUtils)

Example 28 with X509KeyManager

use of javax.net.ssl.X509KeyManager in project Payara by payara.

the class GlassfishServerSocketFactory method getKeyManagers.

@Override
protected KeyManager[] getKeyManagers(String algorithm, String keyAlias) throws Exception {
    if (sslUtils == null) {
        initSSLUtils();
    }
    String keystoreFile = (String) attributes.get("keystore");
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Keystore file= {0}", keystoreFile);
    }
    String keystoreType = (String) attributes.get("keystoreType");
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Keystore type= {0}", keystoreType);
    }
    // validate that the alias is in one of the keystores otherwise emit warning
    boolean aliasFound = false;
    for (KeyStore keyStore : sslUtils.getKeyStores()) {
        if (keyStore.isKeyEntry(keyAlias)) {
            aliasFound = true;
            break;
        }
    }
    if (!aliasFound) {
        logger.log(Level.WARNING, "Unable to find key pair alias {0} in any of the configured key stores, therefore the server may not be able to present a valid SSL Certificate", keyAlias);
    }
    KeyManager[] kMgrs = sslUtils.getKeyManagers(algorithm);
    if (keyAlias != null && keyAlias.length() > 0 && kMgrs != null) {
        for (int i = 0; i < kMgrs.length; i++) {
            kMgrs[i] = new J2EEKeyManager((X509KeyManager) kMgrs[i], keyAlias);
        }
    }
    return kMgrs;
}
Also used : X509KeyManager(javax.net.ssl.X509KeyManager) KeyStore(java.security.KeyStore) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager)

Example 29 with X509KeyManager

use of javax.net.ssl.X509KeyManager in project Payara by payara.

the class SecuritySupportImpl method getKeyManagers.

public KeyManager[] getKeyManagers(String algorithm) throws IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
    KeyStore[] kstores = getKeyStores();
    ArrayList<KeyManager> keyManagers = new ArrayList<KeyManager>();
    for (int i = 0; i < kstores.length; i++) {
        checkCertificateDates(kstores[i]);
        KeyManagerFactory kmf = KeyManagerFactory.getInstance((algorithm != null) ? algorithm : KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(kstores[i], keyStorePasswords.get(i));
        KeyManager[] kmgrs = kmf.getKeyManagers();
        if (kmgrs != null) {
            keyManagers.addAll(Arrays.asList(kmgrs));
        }
    }
    KeyManager keyManager = new UnifiedX509KeyManager(keyManagers.toArray(new X509KeyManager[keyManagers.size()]), getTokenNames());
    return new KeyManager[] { keyManager };
}
Also used : UnifiedX509KeyManager(com.sun.enterprise.security.ssl.manager.UnifiedX509KeyManager) ArrayList(java.util.ArrayList) X509KeyManager(javax.net.ssl.X509KeyManager) UnifiedX509KeyManager(com.sun.enterprise.security.ssl.manager.UnifiedX509KeyManager) KeyStore(java.security.KeyStore) X509KeyManager(javax.net.ssl.X509KeyManager) UnifiedX509KeyManager(com.sun.enterprise.security.ssl.manager.UnifiedX509KeyManager) KeyManager(javax.net.ssl.KeyManager) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

X509KeyManager (javax.net.ssl.X509KeyManager)29 KeyManager (javax.net.ssl.KeyManager)16 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)11 IOException (java.io.IOException)10 KeyStore (java.security.KeyStore)9 CertificateException (java.security.cert.CertificateException)8 X509Certificate (java.security.cert.X509Certificate)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 X509ExtendedKeyManager (javax.net.ssl.X509ExtendedKeyManager)7 SSLContext (javax.net.ssl.SSLContext)6 KeyFactory (java.security.KeyFactory)4 KeyPair (java.security.KeyPair)4 KeyPairGenerator (java.security.KeyPairGenerator)4 PublicKey (java.security.PublicKey)4 DHPublicKey (javax.crypto.interfaces.DHPublicKey)4 DHParameterSpec (javax.crypto.spec.DHParameterSpec)4 DHPublicKeySpec (javax.crypto.spec.DHPublicKeySpec)4 SSLException (javax.net.ssl.SSLException)4 TrustManager (javax.net.ssl.TrustManager)4