Overriding the SSL Trust Manager in Android
If you never initialise the origTrustmanager
instance variable, it will have its default value of null
, which will indeed cause an NPE any time you're trying to use it.
I've just edited my previous answer on this to show an example of TrustManager initialisation. (I haven't tried on Android, but it works fine in plain Java.)
Be careful not to catch too much. Here, you're catching CertificateException
and Exception
in your trust manager: this is as good as having nothing, since these methods are meant to throw those exceptions. Make sure you only catch CertificateExpiredException
if you want to ignore expiration dates.
Note that this is only a trick that relies on the fact that, in practice, the certificate verification is done after the general trust verification (at least in the OpenJDK implementation). As far as I know, there's nothing in the specifications that says that the certificate expiration is verified after. It was done before other verification on elements of trust and you ignored that exception, you could let more certificate through than you want.