use of org.apache.http.conn.ssl.NoopHostnameVerifier in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesACustomHostnameVerifier.
@Test
public void usesACustomHostnameVerifier() {
final HostnameVerifier customHostnameVerifier = new NoopHostnameVerifier();
builder.using(customHostnameVerifier);
verify(apacheHttpClientBuilder).using(customHostnameVerifier);
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesACustomConnectionFactoryRegistry.
@Test
public void usesACustomConnectionFactoryRegistry() throws Exception {
final SSLContext ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
ctx.init(null, new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} }, null);
final Registry<ConnectionSocketFactory> customRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(ctx, new NoopHostnameVerifier())).build();
builder.using(customRegistry);
verify(apacheHttpClientBuilder).using(customRegistry);
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project openhab1-addons by openhab.
the class Tr064Comm method createTr064HttpClient.
/***
* Creates a apache HTTP Client object, ignoring SSL Exceptions like self signed certificates
* and sets Auth. Scheme to Digest Auth
*
* @param fboxUrl the URL from config file of fbox to connect to
* @return the ready-to-use httpclient for tr064 requests
*/
private CloseableHttpClient createTr064HttpClient(String fboxUrl) {
CloseableHttpClient hc = null;
// Convert URL String from config in easy explotable URI object
URIBuilder uriFbox = null;
try {
uriFbox = new URIBuilder(fboxUrl);
} catch (URISyntaxException e) {
logger.error("Invalid FritzBox URL! {}", e.getMessage());
return null;
}
// Create context of the http client
_httpClientContext = HttpClientContext.create();
CookieStore cookieStore = new BasicCookieStore();
_httpClientContext.setCookieStore(cookieStore);
// SETUP AUTH
// Auth is specific for this target
HttpHost target = new HttpHost(uriFbox.getHost(), uriFbox.getPort(), uriFbox.getScheme());
// Add digest authentication with username/pw from global config
CredentialsProvider credp = new BasicCredentialsProvider();
credp.setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(_user, _pw));
// Create AuthCache instance. Manages authentication based on server response
AuthCache authCache = new BasicAuthCache();
// Generate DIGEST scheme object, initialize it and add it to the local auth cache. Digeste is standard for fbox
// auth SOAP
DigestScheme digestAuth = new DigestScheme();
// known from fbox specification
digestAuth.overrideParamter("realm", "HTTPS Access");
// never known at first request
digestAuth.overrideParamter("nonce", "");
authCache.put(target, digestAuth);
// Add AuthCache to the execution context
_httpClientContext.setAuthCache(authCache);
// SETUP SSL TRUST
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
SSLConnectionSocketFactory sslsf = null;
try {
// accept self signed certs
sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
// dont
sslsf = new SSLConnectionSocketFactory(sslContextBuilder.build(), null, null, new NoopHostnameVerifier());
// verify
// hostname
// against
// cert
// CN
} catch (Exception ex) {
logger.error(ex.getMessage());
}
// Set timeout values
RequestConfig rc = RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(4000).setConnectTimeout(4000).setConnectionRequestTimeout(4000).build();
// BUILDER
// setup builder with parameters defined before
hc = // set the SSL options which trust every self signed
HttpClientBuilder.create().setSSLSocketFactory(sslsf).setDefaultCredentialsProvider(// set auth options using digest
credp).setDefaultRequestConfig(// set the request config specifying timeout
rc).build();
return hc;
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project wildfly by wildfly.
the class WebSecurityCERTTestCase method getHttpsClient.
private static CloseableHttpClient getHttpsClient(String alias) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
JBossJSSESecurityDomain jsseSecurityDomain = new JBossJSSESecurityDomain("client-cert");
jsseSecurityDomain.setKeyStorePassword("changeit");
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
URL keystore = tccl.getResource("security/client.keystore");
jsseSecurityDomain.setKeyStoreURL(keystore.getPath());
jsseSecurityDomain.setClientAlias(alias);
jsseSecurityDomain.reloadKeyAndTrustStore();
KeyManager[] keyManagers = jsseSecurityDomain.getKeyManagers();
TrustManager[] trustManagers = jsseSecurityDomain.getTrustManagers();
ctx.init(keyManagers, trustManagers, null);
HostnameVerifier verifier = (string, ssls) -> true;
//SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(ctx, verifier);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", ssf).build();
HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
return HttpClientBuilder.create().setSSLSocketFactory(ssf).setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionManager(ccm).build();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
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();
sslContextBuilder.loadTrustMaterial(convertToKeyStore(trustedServerCertificates), new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return checkIsTrusted(chain);
}
});
if (clientSSLKeyStore != null) {
sslContextBuilder.loadKeyMaterial(clientSSLKeyStore, "".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);
}
}
Aggregations