KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(theKeyStore, keyPassword);
keyManagers = keyManagerFactory.getKeyManagers();
} catch (IOException e) {
throw new CliInitializationException(e);
} catch (GeneralSecurityException e) {
throw new CliInitializationException(e);
} finally {
StreamUtils.safeClose(fis);
}
}
trustStore = sslConfig.getTrustStore();
trustStorePassword = sslConfig.getTrustStorePassword();
modifyTrustStore = sslConfig.isModifyTrustStore();
}
if (trustStore == null) {
final String userHome = SecurityActions.getSystemProperty("user.home");
File trustStoreFile = new File(userHome, ".jboss-cli.truststore");
trustStore = trustStoreFile.getAbsolutePath();
trustStorePassword = "cli_truststore"; // Risk of modification but no private keys to be stored in the truststore.
}
trustManager = new LazyDelagatingTrustManager(trustStore, trustStorePassword, modifyTrustStore);
trustManagers = new TrustManager[] { trustManager };
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, null);
this.sslContext = sslContext;
} catch (GeneralSecurityException e) {
throw new CliInitializationException(e);
}
}