use of org.apache.http.conn.ssl.NoopHostnameVerifier in project oxTrust by GluuFederation.
the class BaseApiTest method createAcceptSelfSignedCertificateClient.
private static CloseableHttpClient createAcceptSelfSignedCertificateClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustSelfSignedStrategy()).build();
HostnameVerifier allowAllHosts = new NoopHostnameVerifier();
SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, allowAllHosts);
return HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).setSSLSocketFactory(connectionFactory).build();
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project iaf by ibissource.
the class HttpSenderBase method getSSLConnectionSocketFactory.
protected SSLConnectionSocketFactory getSSLConnectionSocketFactory() throws SenderException {
SSLConnectionSocketFactory sslSocketFactory;
HostnameVerifier hostnameVerifier = verifyHostname ? new DefaultHostnameVerifier() : new NoopHostnameVerifier();
try {
javax.net.ssl.SSLSocketFactory socketfactory = AuthSSLContextFactory.createSSLSocketFactory(this, this, getProtocol());
sslSocketFactory = new SSLConnectionSocketFactory(socketfactory, hostnameVerifier);
} catch (Exception e) {
throw new SenderException("cannot create or initialize SocketFactory", e);
}
// Can still be null when no default or an invalid system sslSocketFactory has been defined
if (sslSocketFactory != null) {
httpClientBuilder.setSSLSocketFactory(sslSocketFactory);
}
return sslSocketFactory;
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project janusgraph by JanusGraph.
the class SSLConfigurationCallback method customizeHttpClient.
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
final SSLContext sslcontext;
final TrustStrategy trustStrategy = allowSelfSignedCertificates ? new TrustSelfSignedStrategy() : null;
try {
if (StringUtils.isNotEmpty(trustStoreFile)) {
sslContextBuilder.loadTrustMaterial(new File(trustStoreFile), trustStorePassword.toCharArray(), trustStrategy);
} else {
sslContextBuilder.loadTrustMaterial(trustStrategy);
}
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException e) {
throw new RuntimeException("Invalid trust store file " + trustStoreFile, e);
} catch (IOException e) {
throw new RuntimeException("Unable to load trust store data from " + trustStoreFile, e);
}
try {
if (StringUtils.isNotEmpty(keyStoreFile)) {
sslContextBuilder.loadKeyMaterial(new File(keyStoreFile), keyStorePassword.toCharArray(), keyPassword.toCharArray());
}
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
throw new RuntimeException("Invalid key store file " + keyStoreFile, e);
} catch (IOException e) {
throw new RuntimeException("Unable to load key store data from " + keyStoreFile, e);
}
try {
sslcontext = sslContextBuilder.build();
} catch (KeyManagementException | NoSuchAlgorithmException e) {
throw new RuntimeException("SSL context initialization failed", e);
}
httpClientBuilder.setSSLContext(sslcontext);
if (disableHostNameVerification) {
httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
return httpClientBuilder;
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project ats-framework by Axway.
the class HttpClient method setupSSL.
/**
* Setup SSL. Pass the trusted certificates and client private key and certificate,
* if applicable.
*
* @param httpClientBuilder The client builder
* @throws HttpException
*/
private void setupSSL(HttpClientBuilder httpClientBuilder) throws HttpException {
try {
SSLContextBuilder sslContextBuilder = SSLContexts.custom();
// set trust material
if (trustedServerCertificates != null && trustedServerCertificates.length > 0) {
sslContextBuilder.loadTrustMaterial(convertToKeyStore(trustedServerCertificates), new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return checkIsTrusted(chain);
}
});
} else {
// no trust material provided, we will trust no matter the remote party
sslContextBuilder.loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
}
// set key material
if (clientSSLKeyStore != null) {
sslContextBuilder.loadKeyMaterial(clientSSLKeyStore, clientSSLKeyStorePassword.toCharArray());
}
SSLContext sslContext = sslContextBuilder.build();
// Allow all supported protocols
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, new NoopHostnameVerifier());
httpClientBuilder.setSSLSocketFactory(sslsf);
} catch (Exception e) {
throw new HttpException("Exception occurred when setting up SSL.", e);
}
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project tutorials by eugenp.
the class HttpsClientSslLiveTest method givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate.
@Test
public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
final SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
final NoopHostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
final CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).setSSLSocketFactory(sslsf).build();
// new
final HttpGet getMethod = new HttpGet(HOST_WITH_SSL);
final HttpResponse response = httpClient.execute(getMethod);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
httpClient.close();
}
Aggregations