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);
}
}
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();
}
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();
}
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());
}
Aggregations