Search in sources :

Example 6 with OpenSSLContextImpl

use of com.android.org.conscrypt.OpenSSLContextImpl in project platform_external_apache-http by android.

the class SSLConnectionClosedByUserException method initializeEngine.

/**
     * @param sessionDir directory to cache SSL sessions
     */
public static void initializeEngine(File sessionDir) {
    try {
        SSLClientSessionCache cache = null;
        if (sessionDir != null) {
            Log.d("HttpsConnection", "Caching SSL sessions in " + sessionDir + ".");
            cache = FileClientSessionCache.usingDirectory(sessionDir);
        }
        OpenSSLContextImpl sslContext = (OpenSSLContextImpl) Conscrypt.newPreferredSSLContextSpi();
        // here, trust managers is a single trust-all manager
        TrustManager[] trustManagers = new TrustManager[] { new X509TrustManager() {

            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
        sslContext.engineInit(null, trustManagers, null);
        sslContext.engineGetClientSessionContext().setPersistentCache(cache);
        synchronized (HttpsConnection.class) {
            mSslSocketFactory = sslContext.engineGetSocketFactory();
        }
    } catch (KeyManagementException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : OpenSSLContextImpl(com.android.org.conscrypt.OpenSSLContextImpl) X509TrustManager(javax.net.ssl.X509TrustManager) IOException(java.io.IOException) SSLClientSessionCache(com.android.org.conscrypt.SSLClientSessionCache) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Aggregations

OpenSSLContextImpl (com.android.org.conscrypt.OpenSSLContextImpl)6 KeyManagementException (java.security.KeyManagementException)6 SSLClientSessionCache (com.android.org.conscrypt.SSLClientSessionCache)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1