couchbase/couchbase-lite-android-core — pull request #9 by NandishSimpragma (2013-10-31 16:36:57+00:00)
Title: Added a API to pass SSLSocketFactory

This feature will ensure that the user can pass the SSLSocketFactory with the custom KeyStores.
An example where the ca.pem file is in assets folder

private void initializeSecurity() throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException, InterruptedException, UnrecoverableKeyException {
AssetManager am = getAssets();
InputStream is = am.open("ca.pem");
// Load CAs from an InputStream
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = new BufferedInputStream(is);
Certificate ca;
try {
ca = cf.generateCertificate(caInput);
} finally {
caInput.close();
}
// Create a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
CBLHttpClientFactory.INSTANCE.setSSLSocketFactory(sf);
}

Simply call `CBLHttpClientFactory.INSTANCE.setSSLSocketFactory(sf);`

This feature is tested on my app.
Test case1: Load the custom ssl factory with verified certificates. The replication to an ssl end point should pass
Test case2: Call the `CBLHttpClientFactory.INSTANCE.setSSLSocketFactory(sf);` and it should fail
Test case3: Pass null in `CBLHttpClientFactory.INSTANCE.setSSLSocketFactory(null)` and the library picks up the default SSLSocketFactory and proceeds