use of org.apache.http.conn.ssl.TrustStrategy in project janusgraph by JanusGraph.
the class SSLConfigurationCallback method customizeHttpClient.
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
final SSLContext sslcontext;
final TrustStrategy trustStrategy = allowSelfSignedCertificates ? new TrustSelfSignedStrategy() : null;
try {
if (StringUtils.isNotEmpty(trustStoreFile)) {
sslContextBuilder.loadTrustMaterial(new File(trustStoreFile), trustStorePassword.toCharArray(), trustStrategy);
} else {
sslContextBuilder.loadTrustMaterial(trustStrategy);
}
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException e) {
throw new RuntimeException("Invalid trust store file " + trustStoreFile, e);
} catch (IOException e) {
throw new RuntimeException("Unable to load trust store data from " + trustStoreFile, e);
}
try {
if (StringUtils.isNotEmpty(keyStoreFile)) {
sslContextBuilder.loadKeyMaterial(new File(keyStoreFile), keyStorePassword.toCharArray(), keyPassword.toCharArray());
}
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
throw new RuntimeException("Invalid key store file " + keyStoreFile, e);
} catch (IOException e) {
throw new RuntimeException("Unable to load key store data from " + keyStoreFile, e);
}
try {
sslcontext = sslContextBuilder.build();
} catch (KeyManagementException | NoSuchAlgorithmException e) {
throw new RuntimeException("SSL context initialization failed", e);
}
httpClientBuilder.setSSLContext(sslcontext);
if (disableHostNameVerification) {
httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
return httpClientBuilder;
}
Aggregations