Search in sources :

Example 1 with OpenSSLContextImpl

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

the class SSLCertificateSocketFactory method makeSocketFactory.

private SSLSocketFactory makeSocketFactory(KeyManager[] keyManagers, TrustManager[] trustManagers) {
    try {
        OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
        sslContext.engineInit(keyManagers, trustManagers, null);
        sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
        return sslContext.engineGetSocketFactory();
    } catch (KeyManagementException e) {
        Log.wtf(TAG, e);
        // Fallback
        return (SSLSocketFactory) SSLSocketFactory.getDefault();
    }
}
Also used : OpenSSLContextImpl(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) KeyManagementException(java.security.KeyManagementException)

Example 2 with OpenSSLContextImpl

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

the class SSLSocketTest method testClientSessionCaching.

/**
     * Tests our in-memory and persistent caching support.
     */
public void testClientSessionCaching() throws IOException, KeyManagementException {
    OpenSSLContextImpl context = new OpenSSLContextImpl();
    // Cache size = 2.
    FakeClientSessionCache fakeCache = new FakeClientSessionCache();
    context.engineInit(null, null, null);
    context.engineGetClientSessionContext().setPersistentCache(fakeCache);
    SSLSocketFactory socketFactory = context.engineGetSocketFactory();
    context.engineGetClientSessionContext().setSessionCacheSize(2);
    makeRequests(socketFactory);
    List<String> smallCacheOps = Arrays.asList("get www.fortify.net", "put www.fortify.net", "get www.paypal.com", "put www.paypal.com", "get www.yellownet.ch", "put www.yellownet.ch", // but the sessions will still be in the persistent cache.
    "get www.fortify.net", "get www.paypal.com", "get www.yellownet.ch");
    assertEquals(smallCacheOps, fakeCache.ops);
    // Cache size = 3.
    fakeCache = new FakeClientSessionCache();
    context.engineInit(null, null, null);
    context.engineGetClientSessionContext().setPersistentCache(fakeCache);
    socketFactory = context.engineGetSocketFactory();
    context.engineGetClientSessionContext().setSessionCacheSize(3);
    makeRequests(socketFactory);
    List<String> bigCacheOps = Arrays.asList("get www.fortify.net", "put www.fortify.net", "get www.paypal.com", "put www.paypal.com", "get www.yellownet.ch", "put www.yellownet.ch");
    assertEquals(bigCacheOps, fakeCache.ops);
    // Cache size = 4.
    fakeCache = new FakeClientSessionCache();
    context.engineInit(null, null, null);
    context.engineGetClientSessionContext().setPersistentCache(fakeCache);
    socketFactory = context.engineGetSocketFactory();
    context.engineGetClientSessionContext().setSessionCacheSize(4);
    makeRequests(socketFactory);
    assertEquals(bigCacheOps, fakeCache.ops);
}
Also used : OpenSSLContextImpl(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 3 with OpenSSLContextImpl

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

the class SSLCertificateSocketFactory method makeSocketFactory.

private SSLSocketFactory makeSocketFactory(KeyManager[] keyManagers, TrustManager[] trustManagers) {
    try {
        OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
        sslContext.engineInit(keyManagers, trustManagers, null);
        sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
        return sslContext.engineGetSocketFactory();
    } catch (KeyManagementException e) {
        Log.wtf(TAG, e);
        // Fallback
        return (SSLSocketFactory) SSLSocketFactory.getDefault();
    }
}
Also used : OpenSSLContextImpl(org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl) KeyManagementException(java.security.KeyManagementException)

Example 4 with OpenSSLContextImpl

use of org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl 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 5 with OpenSSLContextImpl

use of org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl 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)

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