Created
November 6, 2013 08:16
-
-
Save scottt/7332618 to your computer and use it in GitHub Desktop.
Use custom certificates for SSL/TLS on Android.
From https://github.com/square/okhttp/issues/173 and https://plus.google.com/+JakeWharton/posts/go9jBhHw3TY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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