Monday, 27 October 2014

Android SSL/TLS/HTTPS - IOException: No peer certificate

I love it when I think I have deployed my app and it is all ready to test and the first thing that happens when someone tests it is a nice big fat error!

I got the device, put some logging in and found that an IOException was occurring when it was contacting a web service over SSL and the message was, "No peer certificate".

This is one of those errors that can be related to a whole number of problems with SSL certificate types and chains but fortunately, I knew it was basically working because my phone worked fine.

The problem was that the phone that was failing was not on a phone network so the "automatic date and time" was not working and the date was therefore set to January 1980. What this means is that phone date is not within the validity of the certificate being obtained from the web service. This effectively makes the certificate invalid and causes the error!

I guess I need either some kind of date/time check performed over non-ssl before attempting the SSL handshake or I need to modify the error message to prompt the user to check their date/time....
Post a Comment