Skip to content

Instantly share code, notes, and snippets.

@scottt
Created November 6, 2013 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottt/7332618 to your computer and use it in GitHub Desktop.
Save scottt/7332618 to your computer and use it in GitHub Desktop.
SSLSocketFactory goodSslSocketFactory(Context context) {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.truststore);
trusted.load(in, TRUST_STORE_PASSWORD);
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trusted);
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
return sslContext.getSocketFactory();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment