use of javax.net.ssl.HostnameVerifier in project camel by apache.
the class HttpComponent method createConnectionManager.
protected HttpClientConnectionManager createConnectionManager(final Map<String, Object> parameters, final SSLContextParameters sslContextParameters) throws GeneralSecurityException, IOException {
if (clientConnectionManager != null) {
return clientConnectionManager;
}
final HostnameVerifier resolvedHostnameVerifier = resolveAndRemoveReferenceParameter(parameters, "x509HostnameVerifier", HostnameVerifier.class);
final HostnameVerifier hostnameVerifier = Optional.ofNullable(resolvedHostnameVerifier).orElse(x509HostnameVerifier);
// need to check the parameters of maxTotalConnections and connectionsPerRoute
final int maxTotalConnections = getAndRemoveParameter(parameters, "maxTotalConnections", int.class, 0);
final int connectionsPerRoute = getAndRemoveParameter(parameters, "connectionsPerRoute", int.class, 0);
final Registry<ConnectionSocketFactory> connectionRegistry = createConnectionRegistry(hostnameVerifier, sslContextParameters);
return createConnectionManager(connectionRegistry, maxTotalConnections, connectionsPerRoute);
}
use of javax.net.ssl.HostnameVerifier in project hadoop by apache.
the class TimelineConnector method initSslConnConfigurator.
private static ConnectionConfigurator initSslConnConfigurator(final int timeout, SSLFactory sslFactory) throws IOException, GeneralSecurityException {
final SSLSocketFactory sf;
final HostnameVerifier hv;
sf = sslFactory.createSSLSocketFactory();
hv = sslFactory.getHostnameVerifier();
return new ConnectionConfigurator() {
@Override
public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection c = (HttpsURLConnection) conn;
c.setSSLSocketFactory(sf);
c.setHostnameVerifier(hv);
}
setTimeouts(conn, timeout);
return conn;
}
};
}
use of javax.net.ssl.HostnameVerifier in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseACustomHostnameVerifierWhenTlsConfigurationNotSpecified.
@Test
public 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 = FieldUtils.getField(SSLConnectionSocketFactory.class, "hostnameVerifier", true);
assertThat(hostnameVerifierField.get(socketFactory)).isSameAs(customVerifier);
}
use of javax.net.ssl.HostnameVerifier in project dropwizard by dropwizard.
the class HttpClientBuilderTest method canUseACustomHostnameVerifierWhenTlsConfigurationSpecified.
@Test
public 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 = FieldUtils.getField(SSLConnectionSocketFactory.class, "hostnameVerifier", true);
assertThat(hostnameVerifierField.get(socketFactory)).isSameAs(customVerifier);
}
use of javax.net.ssl.HostnameVerifier in project qi4j-sdk by Qi4j.
the class AbstractSecureJettyTest method beforeSecureClass.
@BeforeClass
public static void beforeSecureClass() throws IOException, GeneralSecurityException {
defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String string, SSLSession ssls) {
return true;
}
});
KeyStore truststore = KeyStore.getInstance("JCEKS");
truststore.load(new FileInputStream(TRUSTSTORE_FILE), KS_PASSWORD.toCharArray());
SSLContext sslCtx = SSLContext.getInstance("TLS");
TrustManagerFactory caTrustManagerFactory = TrustManagerFactory.getInstance(getX509Algorithm());
caTrustManagerFactory.init(truststore);
sslCtx.init(null, caTrustManagerFactory.getTrustManagers(), null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslCtx.getSocketFactory());
}
Aggregations