public static SSLContext newSSLContext(final KeyStore ks, final String password,
final String ksAlgorithm) throws InvalidSSLConfig {
try {
// Get a KeyManager and initialize it
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(ksAlgorithm);
kmf.init(ks, password.toCharArray());
// Get a TrustManagerFactory with the DEFAULT KEYSTORE, so we have all
// the certificates in cacerts trusted
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(ksAlgorithm);
tmf.init((KeyStore)null);
// Get the SSLContext to help create SSLSocketFactory
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return sslContext;
} catch (final GeneralSecurityException e) {
throw new InvalidSSLConfig(e);
}
}