Search in sources :

Example 31 with NoopHostnameVerifier

use of org.apache.http.conn.ssl.NoopHostnameVerifier in project dropwizard by dropwizard.

the class JerseyClientBuilderTest method usesACustomConnectionFactoryRegistry.

@Test
void usesACustomConnectionFactoryRegistry() throws Exception {
    final SSLContext ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
    ctx.init(null, new TrustManager[] { new X509TrustManager() {

        @Override
        public void checkClientTrusted(X509Certificate[] xcs, String string) {
        }

        @Override
        public void checkServerTrusted(X509Certificate[] xcs, String string) {
        }

        @Override
        @Nullable
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    } }, null);
    final Registry<ConnectionSocketFactory> customRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(ctx, new NoopHostnameVerifier())).build();
    builder.using(customRegistry);
    verify(apacheHttpClientBuilder).using(customRegistry);
}
Also used : SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) X509TrustManager(javax.net.ssl.X509TrustManager) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) X509Certificate(java.security.cert.X509Certificate) Nullable(javax.annotation.Nullable) Test(org.junit.jupiter.api.Test)

Example 32 with NoopHostnameVerifier

use of org.apache.http.conn.ssl.NoopHostnameVerifier in project dropwizard by dropwizard.

the class JerseyClientBuilderTest method usesACustomHostnameVerifier.

@Test
void usesACustomHostnameVerifier() {
    final HostnameVerifier customHostnameVerifier = new NoopHostnameVerifier();
    builder.using(customHostnameVerifier);
    verify(apacheHttpClientBuilder).using(customHostnameVerifier);
}
Also used : NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) Test(org.junit.jupiter.api.Test)

Example 33 with NoopHostnameVerifier

use of org.apache.http.conn.ssl.NoopHostnameVerifier in project oxAuth by GluuFederation.

the class BaseTest method createAcceptSelfSignedSocketFactory.

private static SSLConnectionSocketFactory createAcceptSelfSignedSocketFactory() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
    // Use the TrustSelfSignedStrategy to allow Self Signed Certificates
    SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustSelfSignedStrategy()).build();
    // We can optionally disable hostname verification.
    // If you don't want to further weaken the security, you don't have to include this.
    HostnameVerifier allowAllHosts = new NoopHostnameVerifier();
    // Create an SSL Socket Factory to use the SSLContext with the trust self signed certificate strategy
    // and allow all hosts verifier.
    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, allowAllHosts);
    return connectionFactory;
}
Also used : NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)33 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)22 SSLContext (javax.net.ssl.SSLContext)18 IOException (java.io.IOException)11 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)11 HostnameVerifier (javax.net.ssl.HostnameVerifier)10 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)10 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)7 X509Certificate (java.security.cert.X509Certificate)6 HttpGet (org.apache.http.client.methods.HttpGet)6 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)6 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)6 Test (org.junit.Test)6 CertificateException (java.security.cert.CertificateException)5 HttpResponse (org.apache.http.HttpResponse)5 Test (org.junit.jupiter.api.Test)5 MalformedURLException (java.net.MalformedURLException)4 KeyManagementException (java.security.KeyManagementException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HttpHost (org.apache.http.HttpHost)4