Search in sources :

Example 71 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project Conversations by siacs.

the class HttpConnectionManager method setupTrustManager.

public void setupTrustManager(final HttpsURLConnection connection, final boolean interactive) {
    final X509TrustManager trustManager;
    final HostnameVerifier hostnameVerifier;
    if (interactive) {
        trustManager = mXmppConnectionService.getMemorizingTrustManager().getInteractive();
        hostnameVerifier = mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifier(new StrictHostnameVerifier());
    } else {
        trustManager = mXmppConnectionService.getMemorizingTrustManager().getNonInteractive();
        hostnameVerifier = mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifierNonInteractive(new StrictHostnameVerifier());
    }
    try {
        final SSLSocketFactory sf = new TLSSocketFactory(new X509TrustManager[] { trustManager }, mXmppConnectionService.getRNG());
        connection.setSSLSocketFactory(sf);
        connection.setHostnameVerifier(hostnameVerifier);
    } catch (final KeyManagementException | NoSuchAlgorithmException ignored) {
    }
}
Also used : StrictHostnameVerifier(org.apache.http.conn.ssl.StrictHostnameVerifier) TLSSocketFactory(eu.siacs.conversations.utils.TLSSocketFactory) X509TrustManager(javax.net.ssl.X509TrustManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) KeyManagementException(java.security.KeyManagementException) StrictHostnameVerifier(org.apache.http.conn.ssl.StrictHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 72 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project Conversations by siacs.

the class XmppConnection method getTlsFactoryVerifier.

private TlsFactoryVerifier getTlsFactoryVerifier() throws NoSuchAlgorithmException, KeyManagementException, IOException {
    final SSLContext sc = SSLSocketHelper.getSSLContext();
    MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager();
    KeyManager[] keyManager;
    if (account.getPrivateKeyAlias() != null && account.getPassword().isEmpty()) {
        keyManager = new KeyManager[] { new MyKeyManager() };
    } else {
        keyManager = null;
    }
    String domain = account.getJid().getDomainpart();
    sc.init(keyManager, new X509TrustManager[] { mInteractive ? trustManager.getInteractive(domain) : trustManager.getNonInteractive(domain) }, mXmppConnectionService.getRNG());
    final SSLSocketFactory factory = sc.getSocketFactory();
    final HostnameVerifier verifier;
    if (mInteractive) {
        verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier());
    } else {
        verifier = trustManager.wrapHostnameVerifierNonInteractive(new XmppDomainVerifier());
    }
    return new TlsFactoryVerifier(factory, verifier);
}
Also used : MemorizingTrustManager(de.duenndns.ssl.MemorizingTrustManager) XmppDomainVerifier(eu.siacs.conversations.crypto.XmppDomainVerifier) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 73 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project CloudStack-archive by CloudStack-extras.

the class VmwareContext method getRawHTTPConnection.

public HttpURLConnection getRawHTTPConnection(String urlString) throws Exception {
    HostnameVerifier hv = new HostnameVerifier() {

        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    URL url = new URL(urlString);
    return (HttpURLConnection) url.openConnection();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) SSLSession(javax.net.ssl.SSLSession) URL(java.net.URL) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 74 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project spring-boot by spring-projects.

the class SampleTomcatTwoConnectorsApplicationTests method testHello.

@Test
public void testHello() throws Exception {
    RestTemplate template = new RestTemplate();
    final MySimpleClientHttpRequestFactory factory = new MySimpleClientHttpRequestFactory(new HostnameVerifier() {

        @Override
        public boolean verify(final String hostname, final SSLSession session) {
            // these guys are alright by me...
            return true;
        }
    });
    template.setRequestFactory(factory);
    ResponseEntity<String> entity = template.getForEntity("http://localhost:" + this.context.getBean("port") + "/hello", String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getBody()).isEqualTo("hello");
    ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello", String.class);
    assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(httpsEntity.getBody()).isEqualTo("hello");
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) SSLSession(javax.net.ssl.SSLSession) HostnameVerifier(javax.net.ssl.HostnameVerifier) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 75 with HostnameVerifier

use of javax.net.ssl.HostnameVerifier in project okhttp by square.

the class OkHttp method prepare.

@Override
public void prepare(Benchmark benchmark) {
    super.prepare(benchmark);
    client = new OkHttpClient.Builder().protocols(benchmark.protocols).build();
    if (benchmark.tls) {
        SslClient sslClient = SslClient.localhost();
        SSLSocketFactory socketFactory = sslClient.socketFactory;
        HostnameVerifier hostnameVerifier = new HostnameVerifier() {

            @Override
            public boolean verify(String s, SSLSession session) {
                return true;
            }
        };
        client = new OkHttpClient.Builder().sslSocketFactory(socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build();
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) SslClient(okhttp3.internal.tls.SslClient) SSLSession(javax.net.ssl.SSLSession) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

HostnameVerifier (javax.net.ssl.HostnameVerifier)94 SSLSession (javax.net.ssl.SSLSession)41 SSLContext (javax.net.ssl.SSLContext)30 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)27 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)24 TrustManager (javax.net.ssl.TrustManager)19 IOException (java.io.IOException)18 URL (java.net.URL)18 X509Certificate (java.security.cert.X509Certificate)17 X509TrustManager (javax.net.ssl.X509TrustManager)17 Test (org.junit.Test)16 HttpURLConnection (java.net.HttpURLConnection)14 SecureRandom (java.security.SecureRandom)14 InputStream (java.io.InputStream)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 CertificateException (java.security.cert.CertificateException)10 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)10 KeyManagementException (java.security.KeyManagementException)9 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8