I have a self signed server certificate (cert.pem) and need to enable it for SSL sockets in an Android application. Ideally I'd like to package the code as .jar file and not need an external certificate file (i.e. include it into the code).
With this code I can accept all certificates, which is not what I want:
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager [] { new MyTrustManager() }, new SecureRandom());
Do I need to add the certificate to a custom KeyManager or the custom TrustManager?
One problem I've encountered is that Android does not accept JKS keystores (KeyStore.getDefaultType() returns "BKS"): "java.security.KeyStoreException: KeyStore JKS implementation not found"
Any ideas how to proceed would be highly appreciated!
Yes, you need to add the certificate to a custom KeyStore. It is basically a 4-step process:
See this link for detailed instructions and sample code:
http://randomizedsort.blogspot.com/2010/09/step-to-step-guide-to-programming.html
Good luck.
Nehc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With