KeyStore ks = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getKeyStore();
String pw = ContextHolder.getContext().getConfig().retrieveProperty(new ContextKey("webServer.keystore.sslCertificate.password"));
KeyManager[] kma = new KeyManager[] { new CustomKeyManager(pw) };
TrustManager[] tma = null;
if(trustManager == null) {
TrustManagerFactory tm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tm.init(ks);
tma = tm.getTrustManagers();
}
else {
// LDP - Add the existing trust managers so that outgoing certificates are still trusted.
TrustManagerFactory tm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tm.init(ks);
tma = new TrustManager[tm.getTrustManagers().length + 1];
for(int i=0;i<tm.getTrustManagers().length-1;i++) {
tma[i] = tm.getTrustManagers()[i];
}
tma[tma.length-1] = trustManager;
}
SSLContext sslc = SSLContext.getInstance("SSL");
sslc.init(kma, tma, SecureRandom.getInstance("SHA1PRNG"));