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();
}
}
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);
}
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();
}
}
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);
}
}
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);
}
}
Aggregations