Skip to content

Instantly share code, notes, and snippets.

@MikeThomsen
Created April 20, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeThomsen/4062e14611387e17bf18d57244703d6a to your computer and use it in GitHub Desktop.
Save MikeThomsen/4062e14611387e17bf18d57244703d6a to your computer and use it in GitHub Desktop.
Change to ElasticSearchClientImpl
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