use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ais-sdk by huaweicloudsdk.
the class AccessServiceImpl method getDefaultHttpClient.
private CloseableHttpClient getDefaultHttpClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
return HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
}
use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project rdf4j by eclipse.
the class HttpClientBuilders method getSSLTrustAllHttpClientBuilder.
/**
* Return an {@link HttpClientBuilder} that can be used to build an {@link HttpClient} which trusts all
* certificates (particularly including self-signed certificates).
*
* @return a {@link HttpClientBuilder} for <i>SSL trust all</i>
*/
public static HttpClientBuilder getSSLTrustAllHttpClientBuilder() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
HostnameVerifier hostNameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), hostNameVerifier);
return HttpClients.custom().setSSLSocketFactory(sslSF).useSystemProperties();
} catch (Exception e) {
// key management exception, etc.
throw new RuntimeException(e);
}
}
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 spring-framework by spring-projects.
the class ServerHttpsRequestIntegrationTests method startServer.
@BeforeEach
void startServer() throws Exception {
this.server.setHandler(new CheckRequestHandler());
this.server.afterPropertiesSet();
this.server.start();
// Set dynamically chosen port
this.port = this.server.getPort();
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(new TrustSelfSignedStrategy());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpclient);
this.restTemplate = new RestTemplate(requestFactory);
}
Aggregations