use of org.apache.http.conn.ssl.NoopHostnameVerifier in project cas by apereo.
the class SimpleHttpClientTests method verifyBypassedInvalidHttpsUrl.
@Test
public void verifyBypassedInvalidHttpsUrl() throws Exception {
final SimpleHttpClientFactoryBean clientFactory = new SimpleHttpClientFactoryBean();
clientFactory.setSslSocketFactory(getFriendlyToAllSSLSocketFactory());
clientFactory.setHostnameVerifier(new NoopHostnameVerifier());
clientFactory.setAcceptableCodes(CollectionUtils.wrapList(200, 403));
final SimpleHttpClient client = clientFactory.getObject();
assertTrue(client.isValidEndPoint("https://wrong.host.badssl.com/"));
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project openremote by openremote.
the class ExtensibleResteasyClientBuilder method initDefaultEngine43.
// The rest is copy/paste pretty much
public static ApacheHttpClient43Engine initDefaultEngine43(ExtensibleResteasyClientBuilder that) {
HttpClient httpClient = null;
HostnameVerifier verifier = null;
if (that.verifier != null) {
verifier = new ExtensibleResteasyClientBuilder.VerifierWrapper(that.verifier);
} else {
switch(that.policy) {
case ANY:
verifier = new NoopHostnameVerifier();
break;
case WILDCARD:
verifier = new DefaultHostnameVerifier();
break;
case STRICT:
verifier = new DefaultHostnameVerifier();
break;
}
}
try {
SSLConnectionSocketFactory sslsf = null;
SSLContext theContext = that.sslContext;
if (that.disableTrustManager) {
theContext = SSLContext.getInstance("SSL");
theContext.init(null, new TrustManager[] { new PassthroughTrustManager() }, new SecureRandom());
verifier = new NoopHostnameVerifier();
sslsf = new SSLConnectionSocketFactory(theContext, verifier);
} else if (theContext != null) {
sslsf = new SSLConnectionSocketFactory(theContext, verifier) {
@Override
protected void prepareSocket(SSLSocket socket) throws IOException {
that.prepareSocketForSni(socket);
}
};
} else if (that.clientKeyStore != null || that.truststore != null) {
SSLContext ctx = SSLContexts.custom().useProtocol(SSLConnectionSocketFactory.TLS).setSecureRandom(null).loadKeyMaterial(that.clientKeyStore, that.clientPrivateKeyPassword != null ? that.clientPrivateKeyPassword.toCharArray() : null).loadTrustMaterial(that.truststore, TrustSelfSignedStrategy.INSTANCE).build();
sslsf = new SSLConnectionSocketFactory(ctx, verifier) {
@Override
protected void prepareSocket(SSLSocket socket) throws IOException {
that.prepareSocketForSni(socket);
}
};
} else {
final SSLContext tlsContext = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
tlsContext.init(null, null, null);
sslsf = new SSLConnectionSocketFactory(tlsContext, verifier);
}
final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
HttpClientConnectionManager cm = null;
if (that.connectionPoolSize > 0) {
PoolingHttpClientConnectionManager tcm = new PoolingHttpClientConnectionManager(registry, null, null, null, that.connectionTTL, that.connectionTTLUnit);
tcm.setMaxTotal(that.connectionPoolSize);
if (that.maxPooledPerRoute == 0) {
that.maxPooledPerRoute = that.connectionPoolSize;
}
tcm.setDefaultMaxPerRoute(that.maxPooledPerRoute);
cm = tcm;
} else {
cm = new BasicHttpClientConnectionManager(registry);
}
RequestConfig.Builder rcBuilder = RequestConfig.custom();
if (that.socketTimeout > -1) {
rcBuilder.setSocketTimeout((int) that.socketTimeoutUnits.toMillis(that.socketTimeout));
}
if (that.establishConnectionTimeout > -1) {
rcBuilder.setConnectTimeout((int) that.establishConnectionTimeoutUnits.toMillis(that.establishConnectionTimeout));
}
if (that.connectionCheckoutTimeoutMs > -1) {
rcBuilder.setConnectionRequestTimeout(that.connectionCheckoutTimeoutMs);
}
// The magic configure()
httpClient = that.configure(HttpClientBuilder.create().setConnectionManager(cm).setDefaultRequestConfig(rcBuilder.build()).setProxy(that.defaultProxy).disableContentCompression()).build();
ApacheHttpClient43Engine engine = (ApacheHttpClient43Engine) ApacheHttpClient4EngineFactory.create(httpClient, true);
engine.setResponseBufferSize(that.responseBufferSize);
engine.setHostnameVerifier(verifier);
// this may be null. We can't really support this with Apache Client.
engine.setSslContext(theContext);
return engine;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project mica2 by obiba.
the class AgateRestService method getSocketFactory.
/**
* Do not check anything from the remote host (Agate server is trusted).
*
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
private SSLConnectionSocketFactory getSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {
// Accepts any SSL certificate
TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { tm }, null);
return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project janusgraph by JanusGraph.
the class SSLConfigurationCallbackTest method testDisableHostNameVerification.
@Test
public void testDisableHostNameVerification() throws Exception {
final SSLConfigurationCallback cb = SSLConfigurationCallback.Builder.createCustom(sslContextBuilderMock).disableHostNameVerification().build();
cb.customizeHttpClient(httpAsyncClientBuilderMock);
final ArgumentCaptor<HostnameVerifier> hostnameVerifierCaptor = ArgumentCaptor.forClass(HostnameVerifier.class);
verify(httpAsyncClientBuilderMock).setSSLHostnameVerifier(hostnameVerifierCaptor.capture());
verify(sslContextBuilderMock).loadTrustMaterial((TrustStrategy) null);
verify(sslContextBuilderMock).build();
verify(httpAsyncClientBuilderMock).setSSLContext(sslContextMock);
verifyNoMoreInteractions(sslContextMock, sslContextBuilderMock, httpAsyncClientBuilderMock);
assertEquals(1, hostnameVerifierCaptor.getAllValues().size());
final HostnameVerifier verifier = hostnameVerifierCaptor.getValue();
// this assertion is implementation-specific but should be good enough
// given the simplicity of the class under test
assertTrue(verifier instanceof NoopHostnameVerifier);
}
use of org.apache.http.conn.ssl.NoopHostnameVerifier in project dropwizard by dropwizard.
the class SslReloadAppTest method postIt.
/** Configure SSL and POST request parameters */
private void postIt(HttpsURLConnection conn) throws Exception {
final SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(null, new TrustManager[] { TRUST_ALL }, null);
conn.setHostnameVerifier(new NoopHostnameVerifier());
conn.setSSLSocketFactory(sslCtx.getSocketFactory());
// Make it a POST
conn.setDoOutput(true);
conn.getOutputStream().write(new byte[] {});
}
Aggregations