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;
}
Aggregations