views:

195

answers:

1

I am attempting to connect to a local HTTPS server using the apache DefaultHttpClient on a Android device.

 DefaultHttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://192.168.1.121:4113/services");
 ... header and content filling in ...
 HttpResponse response = httpclient.execute(httppost);

I am getting an error of "javax.net.ssl SSLException: Not trusted server certificate" when the .execute runs. I want to simply allow any certificate to work, regardless of if it is or is not in the android key chain.

I have spent about 40 hours researching and trying to figure out a workaround for this issue. I have seen many examples of how to do this but none so far have worked in Android; they seem to only work for JAVA. Does anyone know how to configure, or override the certificate validation used by the Apache HttpClient in Android so that it will just approve all certificates for a DefaultHttpClient connection?

I thank you for your kind response

A: 

Look at this tutorial http://blog.antoine.li/index.php/2010/10/android-trusting-ssl-certificates/

The tutorial is based on Apache's HttpClient and explains how to use the SSLSocketFactory to trust the defined certificates in your own keystore (also explained how you can create it with the BouncyCastle provider).

I've tested it and it works great. In my opinion this is the secure way.

saxos
Thank you for trying but that is not what I want to do. I do not want to add the certificate into my keystore. I fully realize the security implications of what I am doing. This is for a commercial product and I can't expect the customers to know how to perform those actions. I have found several examples of solving this by adding the cert to the key store but noone has been able to just bypass it entirely.
metalideath
I see. And switching to the plain old java.net libraries is not an option for you? With those you can easily accept all certs.Maybe this helps: http://stackoverflow.com/questions/2703161/apache-httpclient-4-0-ignore-ssl-certificate-errorsDidn't try it.
saxos
Just forgot to mention: http://mobile.synyx.de/2010/06/android-and-self-signed-ssl-certificates/This guy here is implementing an own SSLSocketFactory, which should accept all self-signed certs.
saxos