}
try {
SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm);
KeyStore ks = KeyStore.getInstance(keyStoreType);
KeyManager[] keystoreManagers = null;
byte[] sslCert = loadClientCredential(keyStoreLocation);
if (sslCert != null && sslCert.length > 0 && keyStorePassword != null) {
ByteArrayInputStream bin = new ByteArrayInputStream(sslCert);
try {
ks.load(bin, keyStorePassword.toCharArray());
kmf.init(ks, keyStorePassword.toCharArray());
keystoreManagers = kmf.getKeyManagers();
LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
} catch (Exception e) {
LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
new Object[]{keyStoreLocation, e.getMessage()});
}
}
if ((keyStorePassword == null) && (keyStoreLocation != null)) {
LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
new Object[]{keyStoreLocation});
}
// ************************* Load Trusted CA file *************************
//TODO could support multiple trust cas
TrustManager[] trustStoreManagers = new TrustManager[1];
KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
trustedCertStore.load(null, "".toCharArray());
CertificateFactory cf = CertificateFactory.getInstance(CERTIFICATE_FACTORY_TYPE);
byte[] caCert = loadCACert(trustStoreLocation);
try {
if (caCert != null) {
ByteArrayInputStream cabin = new ByteArrayInputStream(caCert);
X509Certificate cert = (X509Certificate)cf.generateCertificate(cabin);
trustedCertStore.setCertificateEntry(cert.getIssuerDN().toString(), cert);
cabin.close();
}
} catch (Exception e) {
LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_TRUST_STORE",
new Object[]{trustStoreLocation, e.getMessage()});