Created
April 20, 2019 14:22
-
-
Save MikeThomsen/4062e14611387e17bf18d57244703d6a to your computer and use it in GitHub Desktop.
Change to ElasticSearchClientImpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private SSLContext buildSslContext(SSLContextService sslService) throws IOException, CertificateException, | |
NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException { | |
KeyManagerFactory kmf = null; | |
if (sslService.isKeyStoreConfigured()) { | |
KeyStore keyStore = KeyStore.getInstance(sslService.getKeyStoreType()); | |
try (final InputStream is = new FileInputStream(sslService.getKeyStoreFile())) { | |
keyStore.load(is, sslService.getKeyStorePassword().toCharArray()); | |
} | |
kmf = KeyManagerFactory.getInstance(KeyManagerFactory | |
.getDefaultAlgorithm()); | |
kmf.init(keyStore, sslService.getKeyStorePassword().toCharArray()); | |
} | |
TrustManagerFactory tmf = null; | |
if (sslService.isTrustStoreConfigured()) { | |
KeyStore trustStore = KeyStore.getInstance("JKS"); | |
try (final InputStream is = new FileInputStream(sslService.getTrustStoreFile())) { | |
trustStore.load(is, sslService.getTrustStorePassword().toCharArray()); | |
} | |
tmf = TrustManagerFactory.getInstance(TrustManagerFactory | |
.getDefaultAlgorithm()); | |
tmf.init(trustStore); | |
} | |
SSLContext context1 = SSLContext.getInstance(sslService.getSslAlgorithm()); | |
context1.init(kmf != null ? kmf.getKeyManagers() : null, tmf != null ? tmf.getTrustManagers() : null, new SecureRandom()); | |
return context1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment