use of javax.net.ssl.HostnameVerifier in project Gargoyle by callakrsos.
the class HostNameVertifierInitializer method initialize.
@Override
public void initialize() throws Exception {
LOGGER.debug(getClass().getName() + " initialize.");
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
LOGGER.debug(arg0);
return true;
}
});
}
use of javax.net.ssl.HostnameVerifier in project ddf by codice.
the class CometDClient method doTrustAllCertificates.
private void doTrustAllCertificates() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HostnameVerifier hostnameVerifier = (s, sslSession) -> s.equalsIgnoreCase(sslSession.getPeerHost());
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
}
use of javax.net.ssl.HostnameVerifier in project dropwizard by dropwizard.
the class HttpClientBuilderTest method createClientCanPassCustomVerifierToApacheBuilder.
@Test
public void createClientCanPassCustomVerifierToApacheBuilder() throws Exception {
final HostnameVerifier customVerifier = (s, sslSession) -> false;
assertThat(builder.using(customVerifier).createClient(apacheBuilder, connectionManager, "test")).isNotNull();
final Field hostnameVerifierField = FieldUtils.getField(org.apache.http.impl.client.HttpClientBuilder.class, "hostnameVerifier", true);
assertThat(hostnameVerifierField.get(apacheBuilder)).isSameAs(customVerifier);
}
use of javax.net.ssl.HostnameVerifier 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 javax.net.ssl.HostnameVerifier in project jetty.project by eclipse.
the class SSLEngineTest method testURLConnectionChunkedPost.
@Test
public void testURLConnectionChunkedPost() throws Exception {
StreamHandler handler = new StreamHandler();
server.setHandler(handler);
server.start();
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
URL url = new URL("https://localhost:" + connector.getLocalPort() + "/test");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection) conn).setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
});
}
conn.setConnectTimeout(10000);
conn.setReadTimeout(100000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/plain");
conn.setChunkedStreamingMode(128);
conn.connect();
byte[] b = new byte[BODY_SIZE];
for (int i = 0; i < BODY_SIZE; i++) {
b[i] = 'x';
}
OutputStream os = conn.getOutputStream();
os.write(b);
os.flush();
int len = 0;
InputStream is = conn.getInputStream();
int bytes = 0;
while ((len = is.read(b)) > -1) bytes += len;
is.close();
assertEquals(BODY_SIZE, handler.bytes);
assertEquals(BODY_SIZE, bytes);
}
Aggregations