Using HttpsUrlConnection on Android, if I connect to a server with an untrusted certificate, most likely a self signed one, I'll get an error. When something similar happens in a browser for instance, I get the option to accept that certificate anyway.
- The plan is to run the URL connection as normal.
- If an certificate error occurs, rerun it with the Dummy "trust all" settings, while of course still breaking the connection as soon at the certificates have been received (in the X509TrustManager and then the HostNameVerifier). Returning false in the HostNameVerifier does that trick quite nicely.
- Ask the user if they really want to use this certificate.
Now, how do I add this certificate to the application's store, for it to be used next time a connection is made to that server?
Or do I need to cook my own X509TrustManager/HostNameVerifier, and compare the incoming certificate data to the one stored, while maintaining normal function for all CA signed certificates.
In other words.
- Retrive the public certificate from the server (done)
- Ask the user if they want to use it anyway.
- IMPORT that public certificate somewhere in the app's own store for use in future connections.
- fallback to the regular trust chain for all CA trusted certificates.
Because I've seen this with all other questions asking something similar to this, where people start offering all the wrong solutions. I do NOT want an AcceptAllVerifier. I can NOT use anything that requires me to import the certificate manually.