Search in sources :

Example 16 with NoopHostnameVerifier

use of org.apache.http.conn.ssl.NoopHostnameVerifier in project ats-framework by Axway.

the class HttpsClient method connect.

/**
     * Connect to a remote host using basic authentication.
     *
     * @param hostname the host to connect to
     * @param userName the user name
     * @param password the password for the provided user name
     * @throws FileTransferException
     */
@Override
public void connect(String hostname, String userName, String password) throws FileTransferException {
    super.connect(hostname, userName, password);
    // trust everybody
    try {
        SSLContext sslContext = SslUtils.getTrustAllSSLContext();
        SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(sslContext, encryptionProtocols, cipherSuites, new NoopHostnameVerifier());
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", ssf).build();
        HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        this.httpBuilder.setConnectionManager(connectionManager).setSchemePortResolver(new DefaultSchemePortResolver());
        this.httpClient = this.httpBuilder.build();
    } catch (Exception e) {
        throw new FileTransferException("Error setting trust manager", e);
    }
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) DefaultSchemePortResolver(org.apache.http.impl.conn.DefaultSchemePortResolver) SSLContext(javax.net.ssl.SSLContext) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) CertificateException(java.security.cert.CertificateException) GeneralSecurityException(java.security.GeneralSecurityException) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 17 with NoopHostnameVerifier

use of org.apache.http.conn.ssl.NoopHostnameVerifier 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

NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)17 SSLContext (javax.net.ssl.SSLContext)11 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)10 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 CertificateException (java.security.cert.CertificateException)5 X509Certificate (java.security.cert.X509Certificate)5 HostnameVerifier (javax.net.ssl.HostnameVerifier)4 X509TrustManager (javax.net.ssl.X509TrustManager)4 HttpClientConnectionManager (org.apache.http.conn.HttpClientConnectionManager)4 TrustManager (javax.net.ssl.TrustManager)3 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)3 URISyntaxException (java.net.URISyntaxException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SecureRandom (java.security.SecureRandom)2 HttpHost (org.apache.http.HttpHost)2