use of org.apache.http.conn.ssl.TrustSelfSignedStrategy 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;
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project drill by apache.
the class WebUtils method createHttpClient.
private static CloseableHttpAsyncClient createHttpClient(DrillConfig drillConfig) throws Exception {
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
if (drillConfig.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) {
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustSelfSignedStrategy()).build();
SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(sslContext, new String[] { drillConfig.getString(ExecConstants.SSL_PROTOCOL) }, null, SSLIOSessionStrategy.getDefaultHostnameVerifier());
clientBuilder.setSSLStrategy(sessionStrategy);
}
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(drillConfig.getInt(ExecConstants.HTTP_CLIENT_TIMEOUT)).build();
clientBuilder.setDefaultRequestConfig(requestConfig);
return clientBuilder.build();
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefaultWhenUsingSsl.
@Test
void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
this.webServer.start();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).isNullOrEmpty();
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method sslWantsClientAuthenticationSucceedsWithClientCertificate.
@Test
void sslWantsClientAuthenticationSucceedsWithClientCertificate() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
addTestTxtFile(factory);
factory.setSsl(getSsl(ClientAuth.WANT, "password", "classpath:test.jks", null, new String[] { "TLSv1.2" }, null));
this.webServer = factory.getWebServer();
this.webServer.start();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
loadStore(keyStore, new FileSystemResource("src/test/resources/test.jks"));
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).loadKeyMaterial(keyStore, "password".toCharArray()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test");
}
use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method pkcs12KeyStoreAndTrustStore.
@Test
void pkcs12KeyStoreAndTrustStore() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
addTestTxtFile(factory);
factory.setSsl(getSsl(ClientAuth.NEED, null, "classpath:test.p12", "classpath:test.p12", null, null));
this.webServer = factory.getWebServer();
this.webServer.start();
KeyStore keyStore = KeyStore.getInstance("pkcs12");
loadStore(keyStore, new FileSystemResource("src/test/resources/test.p12"));
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).loadKeyMaterial(keyStore, "secret".toCharArray()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test");
}
Aggregations