Search in sources :

Example 1 with NoopHostnameVerifier

use of org.apache.hc.client5.http.ssl.NoopHostnameVerifier in project wiremock by wiremock.

the class WireMockTestClient method getViaProxy.

public WireMockResponse getViaProxy(String url, int proxyPort, String scheme) {
    URI targetUri = URI.create(url);
    HttpHost proxy = new HttpHost(scheme, address, proxyPort);
    HttpClient httpClientUsingProxy = HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries().disableCookieManagement().disableRedirectHandling().setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(buildTrustWireMockDefaultCertificateSSLContext()).setHostnameVerifier(new NoopHostnameVerifier()).build()).build()).setProxy(proxy).build();
    try {
        HttpHost target = new HttpHost(targetUri.getScheme(), targetUri.getHost(), targetUri.getPort());
        HttpGet req = new HttpGet(targetUri.getPath() + (isNullOrEmpty(targetUri.getQuery()) ? "" : "?" + targetUri.getQuery()));
        req.removeHeaders("Host");
        System.out.println("executing request to " + targetUri + "(" + target + ") via " + proxy);
        ClassicHttpResponse httpResponse = httpClientUsingProxy.execute(target, req);
        return new WireMockResponse(httpResponse);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
Also used : ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) HttpHost(org.apache.hc.core5.http.HttpHost) HttpClient(org.apache.hc.client5.http.classic.HttpClient) CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with NoopHostnameVerifier

use of org.apache.hc.client5.http.ssl.NoopHostnameVerifier in project JAuswertung by dennisfabri.

the class HttpUtils method createAcceptSelfSignedCertificateClient.

private static CloseableHttpClient createAcceptSelfSignedCertificateClient() throws KeyManagementException, NoSuchAlgorithmException, 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();
    PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(sslContext).setHostnameVerifier(allowAllHosts).setTlsVersions(TLS.V_1_3, TLS.V_1_2).build()).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(Timeout.ofSeconds(5)).build()).setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT).setConnPoolPolicy(PoolReusePolicy.LIFO).setConnectionTimeToLive(TimeValue.ofMinutes(1L)).build();
    return HttpClients.custom().setConnectionManager(connectionManager).setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(Timeout.ofSeconds(60)).setResponseTimeout(Timeout.ofSeconds(60)).setCookieSpec(StandardCookieSpec.STRICT).build()).build();
}
Also used : NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) SSLContext(javax.net.ssl.SSLContext) TrustSelfSignedStrategy(org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy) HostnameVerifier(javax.net.ssl.HostnameVerifier) NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Example 3 with NoopHostnameVerifier

use of org.apache.hc.client5.http.ssl.NoopHostnameVerifier in project wiremock by wiremock.

the class HttpsBrowserProxyClientAuthAcceptanceTest method buildHttpClient.

private CloseableHttpClient buildHttpClient() throws Exception {
    KeyStore trustStore = readKeyStore(TRUST_STORE_PATH, TRUST_STORE_PASSWORD);
    SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new TrustSelfSignedStrategy()).loadKeyMaterial(trustStore, TRUST_STORE_PASSWORD.toCharArray()).build();
    HttpHost proxyInfo = new HttpHost("localhost", proxy.getPort());
    return HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries().disableCookieManagement().disableRedirectHandling().setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().setSslContext(sslcontext).setHostnameVerifier(new NoopHostnameVerifier()).build()).build()).setProxy(proxyInfo).build();
}
Also used : NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) HttpHost(org.apache.hc.core5.http.HttpHost) SSLContext(javax.net.ssl.SSLContext) HttpsAcceptanceTest.readKeyStore(com.github.tomakehurst.wiremock.HttpsAcceptanceTest.readKeyStore) KeyStore(java.security.KeyStore) TrustSelfSignedStrategy(org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy)

Example 4 with NoopHostnameVerifier

use of org.apache.hc.client5.http.ssl.NoopHostnameVerifier in project wiremock by wiremock.

the class HttpClientFactory method buildSslConnectionSocketFactory.

private static LayeredConnectionSocketFactory buildSslConnectionSocketFactory(final SSLContext sslContext) {
    final String[] supportedProtocols = split(System.getProperty("https.protocols"));
    final String[] supportedCipherSuites = split(System.getProperty("https.cipherSuites"));
    return new SSLConnectionSocketFactory(new HostVerifyingSSLSocketFactory(sslContext.getSocketFactory()), supportedProtocols, supportedCipherSuites, // using Java's hostname verification
    new NoopHostnameVerifier());
}
Also used : NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)

Aggregations

NoopHostnameVerifier (org.apache.hc.client5.http.ssl.NoopHostnameVerifier)4 SSLContext (javax.net.ssl.SSLContext)2 TrustSelfSignedStrategy (org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy)2 HttpHost (org.apache.hc.core5.http.HttpHost)2 HttpsAcceptanceTest.readKeyStore (com.github.tomakehurst.wiremock.HttpsAcceptanceTest.readKeyStore)1 IOException (java.io.IOException)1 URI (java.net.URI)1 KeyStore (java.security.KeyStore)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 HttpClient (org.apache.hc.client5.http.classic.HttpClient)1 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)1 PoolingHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)1 SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)1 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)1