keyManager = (X509KeyManager)kms[i];
break;
}
}
if (keyManager == null) {
throw new KeyManagementException("No X509KeyManager found");
}
if (initialize_default) {
// found keyManager is default key manager
defaultKeyManager = keyManager;
}
}
// initialize trust manager
initialize_default = false;
if ((tms == null) || (tms.length == 0)) {
if (defaultTrustManager == null) {
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore)null);
tms = tmf.getTrustManagers();
initialize_default = true;
} else {
trustManager = defaultTrustManager;
}
}
if (trustManager == null) { // was not initialized by default
for (int i = 0; i < tms.length; i++) {
if (tms[i] instanceof X509TrustManager) {
trustManager = (X509TrustManager)tms[i];
break;
}
}
if (trustManager == null) {
throw new KeyManagementException("No X509TrustManager found");
}
if (initialize_default) {
// found trustManager is default trust manager
defaultTrustManager = trustManager;
}
}
} catch (NoSuchAlgorithmException e) {
throw new KeyManagementException(e);
} catch (KeyStoreException e) {
throw new KeyManagementException(e);
} catch (UnrecoverableKeyException e) {
throw new KeyManagementException(e);
}
// initialize secure random
if (sr == null) {
if (defaultSecureRandom == null) {
defaultSecureRandom = new SecureRandom();