Search in sources :

Example 1 with JmeterKeyStore

use of org.apache.jmeter.util.keystore.JmeterKeyStore in project jmeter by apache.

the class JsseSSLManager method createContext.

/*
     * 
     * Creates new SSL context
     * 
     * @return SSL context
     * 
     * @throws GeneralSecurityException when the algorithm for the context can
     * not be found or the keys have problems
     */
private SSLContext createContext() throws GeneralSecurityException {
    SSLContext context;
    if (pro != null) {
        // $NON-NLS-1$
        context = SSLContext.getInstance(DEFAULT_SSL_PROTOCOL, pro);
    } else {
        // $NON-NLS-1$
        context = SSLContext.getInstance(DEFAULT_SSL_PROTOCOL);
    }
    KeyManagerFactory managerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    JmeterKeyStore keys = this.getKeyStore();
    managerFactory.init(null, defaultpw == null ? new char[] {} : defaultpw.toCharArray());
    KeyManager[] managers = managerFactory.getKeyManagers();
    KeyManager[] newManagers = new KeyManager[managers.length];
    if (log.isDebugEnabled()) {
        log.debug("JmeterKeyStore type: {}", keys.getClass());
    }
    // Now wrap the default managers with our key manager
    for (int i = 0; i < managers.length; i++) {
        if (managers[i] instanceof X509KeyManager) {
            X509KeyManager manager = (X509KeyManager) managers[i];
            newManagers[i] = new WrappedX509KeyManager(manager, keys);
        } else {
            newManagers[i] = managers[i];
        }
    }
    // Get the default trust managers
    TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmfactory.init(this.getTrustStore());
    // Wrap the defaults in our custom trust manager
    TrustManager[] trustmanagers = tmfactory.getTrustManagers();
    for (int i = 0; i < trustmanagers.length; i++) {
        if (trustmanagers[i] instanceof X509TrustManager) {
            trustmanagers[i] = new CustomX509TrustManager((X509TrustManager) trustmanagers[i]);
        }
    }
    context.init(newManagers, trustmanagers, this.rand);
    if (log.isDebugEnabled()) {
        String[] dCiphers = context.getSocketFactory().getDefaultCipherSuites();
        String[] sCiphers = context.getSocketFactory().getSupportedCipherSuites();
        int len = (dCiphers.length > sCiphers.length) ? dCiphers.length : sCiphers.length;
        for (int i = 0; i < len; i++) {
            if (i < dCiphers.length) {
                log.debug("Default Cipher: {}", dCiphers[i]);
            }
            if (i < sCiphers.length) {
                log.debug("Supported Cipher: {}", sCiphers[i]);
            }
        }
    }
    return context;
}
Also used : JmeterKeyStore(org.apache.jmeter.util.keystore.JmeterKeyStore) SSLContext(javax.net.ssl.SSLContext) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) X509KeyManager(javax.net.ssl.X509KeyManager) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) X509ExtendedKeyManager(javax.net.ssl.X509ExtendedKeyManager)

Aggregations

KeyManager (javax.net.ssl.KeyManager)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 X509ExtendedKeyManager (javax.net.ssl.X509ExtendedKeyManager)1 X509KeyManager (javax.net.ssl.X509KeyManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 JmeterKeyStore (org.apache.jmeter.util.keystore.JmeterKeyStore)1