use of io.atomix.utils.AtomixRuntimeException in project atomix by atomix.
the class NettyMessagingService method loadKeyStores.
private boolean loadKeyStores() {
if (!config.getTlsConfig().isEnabled()) {
return false;
}
// Maintain a local copy of the trust and key managers in case anything goes wrong
TrustManagerFactory tmf;
KeyManagerFactory kmf;
try {
String ksLocation = config.getTlsConfig().getKeyStore();
String tsLocation = config.getTlsConfig().getTrustStore();
char[] ksPwd = config.getTlsConfig().getKeyStorePassword().toCharArray();
char[] tsPwd = config.getTlsConfig().getTrustStorePassword().toCharArray();
tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
try (FileInputStream fileInputStream = new FileInputStream(tsLocation)) {
ts.load(fileInputStream, tsPwd);
}
tmf.init(ts);
kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
try (FileInputStream fileInputStream = new FileInputStream(ksLocation)) {
ks.load(fileInputStream, ksPwd);
}
kmf.init(ks, ksPwd);
if (log.isInfoEnabled()) {
logKeyStore(ks, ksLocation, ksPwd);
}
} catch (FileNotFoundException e) {
throw new AtomixRuntimeException("Could not load cluster keystore: {}", e.getMessage());
} catch (Exception e) {
throw new AtomixRuntimeException("Error loading cluster keystore", e);
}
this.trustManager = tmf;
this.keyManager = kmf;
return true;
}
Aggregations