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