I am using the Apache HttpClient library to establish an https connection. Unfortunately, Android gives me the error "Invalid server certificate". If I go to the site using my phoneβs browser, it validates the certificate correctly, which makes me think that I need to make HttpClient βawareβ of the root certificates on the phone. This is my HttpClient installation code:
HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout( params, 20000 ); HttpConnectionParams.setSoTimeout( params, 20000 ); HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset( params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue( params, false); SchemeRegistry schReg = new SchemeRegistry(); schReg.register( new Scheme( "http", PlainSocketFactory.getSocketFactory(), 80 ) ); schReg.register( new Scheme( "https", SSLSocketFactory.getSocketFactory(), 443 ) ); ClientConnectionManager conMgr = new ThreadSafeClientConnManager( params, schReg ); DefaultHttpClient defaultHttpClient = new DefaultHttpClient( conMgr, params ); return ( defaultHttpClient );
As you can see, I am not doing anything with SSLSocketFactory. How can I get the HttpClient library to check my site without adding a special certificate to the keystore ?. Should I create a custom SSLSocketFactory and download cacerts.bks from an Android phone? In this case, I may have problems with different passwords for the keystore on different phones?
Please let me know if you need more information. This SSL stuff is pretty complicated for me.
source share