Search in sources :

Example 1 with SSLClientSessionCache

use of org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache in project XobotOS by xamarin.

the class SSLConnectionClosedByUserException method initializeEngine.

/**
     * @hide
     *
     * @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 = new OpenSSLContextImpl();
        // 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(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) X509TrustManager(javax.net.ssl.X509TrustManager) IOException(java.io.IOException) SSLClientSessionCache(org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 2 with SSLClientSessionCache

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

the class SSLConnectionClosedByUserException method initializeEngine.

/**
     * @hide
     *
     * @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 = new OpenSSLContextImpl();
        // 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(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) X509TrustManager(javax.net.ssl.X509TrustManager) IOException(java.io.IOException) SSLClientSessionCache(org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 3 with SSLClientSessionCache

use of org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache 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)3 SSLClientSessionCache (org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache)3 IOException (java.io.IOException)2 KeyManagementException (java.security.KeyManagementException)2 X509Certificate (java.security.cert.X509Certificate)2 TrustManager (javax.net.ssl.TrustManager)2 X509TrustManager (javax.net.ssl.X509TrustManager)2 File (java.io.File)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1