Search in sources :

Example 1 with AtomixRuntimeException

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;
}
Also used : AtomixRuntimeException(io.atomix.utils.AtomixRuntimeException) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) FileNotFoundException(java.io.FileNotFoundException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) AtomixRuntimeException(io.atomix.utils.AtomixRuntimeException) TimeoutException(java.util.concurrent.TimeoutException) FileNotFoundException(java.io.FileNotFoundException) SSLException(javax.net.ssl.SSLException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MessagingException(io.atomix.cluster.messaging.MessagingException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

MessagingException (io.atomix.cluster.messaging.MessagingException)1 AtomixRuntimeException (io.atomix.utils.AtomixRuntimeException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 KeyStore (java.security.KeyStore)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 SSLException (javax.net.ssl.SSLException)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1