Search in sources :

Example 6 with OpenSSLContextImpl

use of org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl in project android_frameworks_base by ParanoidAndroid.

the class SSLSocketTest method testFileBasedClientSessionCache.

public void testFileBasedClientSessionCache() throws IOException, KeyManagementException {
    OpenSSLContextImpl context = new OpenSSLContextImpl();
    String tmpDir = System.getProperty("java.io.tmpdir");
    if (tmpDir == null) {
        fail("Please set 'java.io.tmpdir' system property.");
    }
    File cacheDir = new File(tmpDir + "/" + SSLSocketTest.class.getName() + "/cache");
    deleteDir(cacheDir);
    SSLClientSessionCache fileCache = FileClientSessionCache.usingDirectory(cacheDir);
    try {
        ClientSessionCacheProxy cacheProxy = new ClientSessionCacheProxy(fileCache);
        context.engineInit(null, null, null);
        context.engineGetClientSessionContext().setPersistentCache(cacheProxy);
        SSLSocketFactory socketFactory = context.engineGetSocketFactory();
        context.engineGetClientSessionContext().setSessionCacheSize(1);
        makeRequests(socketFactory);
        List<String> expected = Arrays.asList("unsuccessful get www.fortify.net", "put www.fortify.net", "unsuccessful get www.paypal.com", "put www.paypal.com", "unsuccessful get www.yellownet.ch", "put www.yellownet.ch", // but the sessions will still be in the persistent cache.
        "successful get www.fortify.net", "successful get www.paypal.com", "successful get www.yellownet.ch");
        assertEquals(expected, cacheProxy.ops);
        // Try again now that file-based cache is populated.
        fileCache = FileClientSessionCache.usingDirectory(cacheDir);
        cacheProxy = new ClientSessionCacheProxy(fileCache);
        context.engineInit(null, null, null);
        context.engineGetClientSessionContext().setPersistentCache(cacheProxy);
        socketFactory = context.engineGetSocketFactory();
        context.engineGetClientSessionContext().setSessionCacheSize(1);
        makeRequests(socketFactory);
        expected = Arrays.asList("successful get www.fortify.net", "successful get www.paypal.com", "successful get www.yellownet.ch", "successful get www.fortify.net", "successful get www.paypal.com", "successful get www.yellownet.ch");
        assertEquals(expected, cacheProxy.ops);
    } finally {
        deleteDir(cacheDir);
    }
}
Also used : OpenSSLContextImpl(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) File(java.io.File) SSLClientSessionCache(org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache)

Aggregations

OpenSSLContextImpl (org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl)6 KeyManagementException (java.security.KeyManagementException)4 SSLClientSessionCache (org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache)3 IOException (java.io.IOException)2 X509Certificate (java.security.cert.X509Certificate)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 TrustManager (javax.net.ssl.TrustManager)2 X509TrustManager (javax.net.ssl.X509TrustManager)2 File (java.io.File)1