Search in sources :

Example 16 with TrustStrategy

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;
}
Also used : TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) File(java.io.File) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy)

Aggregations

TrustStrategy (org.apache.http.conn.ssl.TrustStrategy)16 SSLContext (javax.net.ssl.SSLContext)9 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)8 IOException (java.io.IOException)7 CertificateException (java.security.cert.CertificateException)7 X509Certificate (java.security.cert.X509Certificate)7 X509HostnameVerifier (org.apache.http.conn.ssl.X509HostnameVerifier)5 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)5 HttpClient (org.apache.http.client.HttpClient)4 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)4 Scheme (org.apache.http.conn.scheme.Scheme)4 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)4 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)4 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)4 AllowAllHostnameVerifier (org.apache.http.conn.ssl.AllowAllHostnameVerifier)4 SSLContextBuilder (org.apache.http.conn.ssl.SSLContextBuilder)4 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)4 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)4 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)4 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)4