use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseACustomHostnameVerifierWhenTlsConfigurationSpecified.
@Test
void canUseACustomHostnameVerifierWhenTlsConfigurationSpecified() throws Exception {
final TlsConfiguration tlsConfiguration = new TlsConfiguration();
tlsConfiguration.setVerifyHostname(true);
configuration.setTlsConfiguration(tlsConfiguration);
final HostnameVerifier customVerifier = (s, sslSession) -> false;
final Registry<ConnectionSocketFactory> configuredRegistry;
configuredRegistry = builder.using(configuration).using(customVerifier).createConfiguredRegistry();
assertThat(configuredRegistry).isNotNull();
final SSLConnectionSocketFactory socketFactory = (SSLConnectionSocketFactory) configuredRegistry.lookup("https");
assertThat(socketFactory).isNotNull();
final Field hostnameVerifierField = getInaccessibleField(SSLConnectionSocketFactory.class, "hostnameVerifier");
assertThat(hostnameVerifierField.get(socketFactory)).isSameAs(customVerifier);
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseACustomHostnameVerifierWhenTlsConfigurationNotSpecified.
@Test
void canUseACustomHostnameVerifierWhenTlsConfigurationNotSpecified() throws Exception {
final HostnameVerifier customVerifier = (s, sslSession) -> false;
final Registry<ConnectionSocketFactory> configuredRegistry;
configuredRegistry = builder.using(customVerifier).createConfiguredRegistry();
assertThat(configuredRegistry).isNotNull();
final SSLConnectionSocketFactory socketFactory = (SSLConnectionSocketFactory) configuredRegistry.lookup("https");
assertThat(socketFactory).isNotNull();
final Field hostnameVerifierField = getInaccessibleField(SSLConnectionSocketFactory.class, "hostnameVerifier");
assertThat(hostnameVerifierField.get(socketFactory)).isSameAs(customVerifier);
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project cdap-ingest by caskdata.
the class RestUtil method getRegistryWithDisabledCertCheck.
public static Registry<ConnectionSocketFactory> getRegistryWithDisabledCertCheck() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
}
} }, new SecureRandom());
SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
return RegistryBuilder.<ConnectionSocketFactory>create().register("https", sf).register("http", PlainConnectionSocketFactory.getSocketFactory()).build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project hazelcast by hazelcast.
the class HTTPCommunicator method newClient.
private CloseableHttpClient newClient() throws IOException {
HttpClientBuilder builder = HttpClients.custom();
if (sslEnabled) {
SSLContext sslContext;
try {
sslContext = SSLContext.getInstance(tlsProtocol);
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
try {
sslContext.init(clientKeyManagers, clientTrustManagers, new SecureRandom());
} catch (KeyManagementException e) {
throw new IOException(e);
}
builder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER));
}
return builder.build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project calcite-avatica by apache.
the class CommonsHttpClientPoolCache method configureHttpsRegistry.
private static void configureHttpsRegistry(RegistryBuilder<ConnectionSocketFactory> registryBuilder, ConnectionConfig config) {
try {
SSLContext sslContext = getSSLContext(config);
final HostnameVerifier verifier = getHostnameVerifier(config.hostnameVerification());
SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext, verifier);
registryBuilder.register("https", sslFactory);
} catch (Exception e) {
LOG.error("HTTPS registry configuration failed");
throw new RuntimeException(e);
}
}
Aggregations