String trustStore = null;
String trustStorePassword = null;
boolean modifyTrustStore = true;
SSLConfig sslConfig = config.getSslConfig();
if (sslConfig != null) {
String keyStoreLoc = sslConfig.getKeyStore();
if (keyStoreLoc != null) {
char[] keyStorePassword = sslConfig.getKeyStorePassword().toCharArray();
String tmpKeyPassword = sslConfig.getKeyPassword();
char[] keyPassword = tmpKeyPassword != null ? tmpKeyPassword.toCharArray() : keyStorePassword;
File keyStoreFile = new File(keyStoreLoc);
FileInputStream fis = null;
try {
fis = new FileInputStream(keyStoreFile);
KeyStore theKeyStore = KeyStore.getInstance("JKS");
theKeyStore.load(fis, keyStorePassword);
String alias = sslConfig.getAlias();
if (alias != null) {
KeyStore replacement = KeyStore.getInstance("JKS");
replacement.load(null);
KeyStore.ProtectionParameter protection = new KeyStore.PasswordProtection(keyPassword);
replacement.setEntry(alias, theKeyStore.getEntry(alias, protection), protection);
theKeyStore = replacement;
}
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");