private KeyStore createKeyStore() { final KeyStore keyStore = createStore(this.keyStoreType); InputStream keyStoreStream = null; if (this.keyStoreSource != null) { keyStoreStream = createStoreStream(this.keyStoreSource); } try { keyStore.load(keyStoreStream, toCharArray(this.keyStorePassword)); } catch (IOException ex) { if (ex.getCause() instanceof UnrecoverableKeyException) { throw new IllegalArgumentException("Failed to load keystore. Maybe the password is not correct.", ex); } throw new IllegalStateException("Failed to load keystore. Maybe the keystore type is not correct.", ex); } catch (NoSuchAlgorithmException ex) { throw new IllegalStateException("Failed to load keystore.", ex); } catch (CertificateException ex) { throw new IllegalStateException("Failed to load keystore.", ex); } finally { Closeables.closeQuietly(keyStoreStream); } return keyStore; }
private KeyStore createTrustStore() { final KeyStore trustStore = createStore(this.trustStoreType); InputStream trustStoreStream = null; if (this.trustStoreSource != null) { trustStoreStream = createStoreStream(this.trustStoreSource); } try { trustStore.load(trustStoreStream, toCharArray(this.trustStorePassword)); } catch (IOException ex) { if (ex.getCause() instanceof UnrecoverableKeyException) { throw new IllegalArgumentException("Failed to load truststore. Maybe the password is not correct.", ex); } throw new IllegalStateException("Failed to load truststore. Maybe the truststore type is not correct.", ex); } catch (NoSuchAlgorithmException ex) { throw new IllegalStateException("Failed to load truststore.", ex); } catch (CertificateException ex) { throw new IllegalStateException("Failed to load truststore.", ex); } finally { Closeables.closeQuietly(trustStoreStream); } return trustStore; }