Search in sources :

Example 1 with SSLClientSessionCache

use of com.android.org.conscrypt.SSLClientSessionCache in project android_frameworks_base by AOSPA.

the class SSLSessionCacheTest method testInstall_compatibleContext.

public void testInstall_compatibleContext() throws Exception {
    final SSLContext ctx = SSLContext.getDefault();
    final SSLClientSessionCache mock = LittleMock.mock(SSLClientSessionCache.class);
    final ClientSessionContext clientCtx = (ClientSessionContext) ctx.getClientSessionContext();
    try {
        SSLSessionCache.install(new SSLSessionCache(mock), ctx);
        clientCtx.getSession("www.foogle.com", 443);
        LittleMock.verify(mock).getSessionData(LittleMock.anyString(), LittleMock.anyInt());
    } finally {
        // Restore cacheless behaviour.
        SSLSessionCache.install(null, ctx);
        clientCtx.getSession("www.foogle.com", 443);
        LittleMock.verifyNoMoreInteractions(mock);
    }
}
Also used : ClientSessionContext(com.android.org.conscrypt.ClientSessionContext) SSLContext(javax.net.ssl.SSLContext) SSLClientSessionCache(com.android.org.conscrypt.SSLClientSessionCache)

Example 2 with SSLClientSessionCache

use of com.android.org.conscrypt.SSLClientSessionCache in project platform_frameworks_base by android.

the class SSLSessionCacheTest method testInstall_compatibleContext.

public void testInstall_compatibleContext() throws Exception {
    final SSLContext ctx = SSLContext.getDefault();
    final SSLClientSessionCache mock = Mockito.mock(SSLClientSessionCache.class);
    final ClientSessionContext clientCtx = (ClientSessionContext) ctx.getClientSessionContext();
    try {
        SSLSessionCache.install(new SSLSessionCache(mock), ctx);
        clientCtx.getSession("www.foogle.com", 443);
        Mockito.verify(mock).getSessionData(Mockito.anyString(), Mockito.anyInt());
    } finally {
        // Restore cacheless behaviour.
        SSLSessionCache.install(null, ctx);
        clientCtx.getSession("www.foogle.com", 443);
        Mockito.verifyNoMoreInteractions(mock);
    }
}
Also used : ClientSessionContext(com.android.org.conscrypt.ClientSessionContext) SSLContext(javax.net.ssl.SSLContext) SSLClientSessionCache(com.android.org.conscrypt.SSLClientSessionCache)

Example 3 with SSLClientSessionCache

use of com.android.org.conscrypt.SSLClientSessionCache in project android_frameworks_base by DirtyUnicorns.

the class SSLSessionCacheTest method testInstall_compatibleContext.

public void testInstall_compatibleContext() throws Exception {
    final SSLContext ctx = SSLContext.getDefault();
    final SSLClientSessionCache mock = LittleMock.mock(SSLClientSessionCache.class);
    final ClientSessionContext clientCtx = (ClientSessionContext) ctx.getClientSessionContext();
    try {
        SSLSessionCache.install(new SSLSessionCache(mock), ctx);
        clientCtx.getSession("www.foogle.com", 443);
        LittleMock.verify(mock).getSessionData(LittleMock.anyString(), LittleMock.anyInt());
    } finally {
        // Restore cacheless behaviour.
        SSLSessionCache.install(null, ctx);
        clientCtx.getSession("www.foogle.com", 443);
        LittleMock.verifyNoMoreInteractions(mock);
    }
}
Also used : ClientSessionContext(com.android.org.conscrypt.ClientSessionContext) SSLContext(javax.net.ssl.SSLContext) SSLClientSessionCache(com.android.org.conscrypt.SSLClientSessionCache)

Example 4 with SSLClientSessionCache

use of com.android.org.conscrypt.SSLClientSessionCache in project android_frameworks_base by ResurrectionRemix.

the class SSLSessionCacheTest method testInstall_compatibleContext.

public void testInstall_compatibleContext() throws Exception {
    final SSLContext ctx = SSLContext.getDefault();
    final SSLClientSessionCache mock = LittleMock.mock(SSLClientSessionCache.class);
    final ClientSessionContext clientCtx = (ClientSessionContext) ctx.getClientSessionContext();
    try {
        SSLSessionCache.install(new SSLSessionCache(mock), ctx);
        clientCtx.getSession("www.foogle.com", 443);
        LittleMock.verify(mock).getSessionData(LittleMock.anyString(), LittleMock.anyInt());
    } finally {
        // Restore cacheless behaviour.
        SSLSessionCache.install(null, ctx);
        clientCtx.getSession("www.foogle.com", 443);
        LittleMock.verifyNoMoreInteractions(mock);
    }
}
Also used : ClientSessionContext(com.android.org.conscrypt.ClientSessionContext) SSLContext(javax.net.ssl.SSLContext) SSLClientSessionCache(com.android.org.conscrypt.SSLClientSessionCache)

Example 5 with SSLClientSessionCache

use of com.android.org.conscrypt.SSLClientSessionCache 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

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