Search in sources :

Example 1 with TLSSocketFactory

use of eu.siacs.conversations.utils.TLSSocketFactory 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 2 with TLSSocketFactory

use of eu.siacs.conversations.utils.TLSSocketFactory in project Conversations by siacs.

the class HttpConnectionManager method setupTrustManager.

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

Aggregations

TLSSocketFactory (eu.siacs.conversations.utils.TLSSocketFactory)2 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 X509TrustManager (javax.net.ssl.X509TrustManager)2 StrictHostnameVerifier (org.apache.http.conn.ssl.StrictHostnameVerifier)2 HostnameVerifier (javax.net.ssl.HostnameVerifier)1