I'm trying to use loopj for making async HTTP
requests. Works great, except when I try to access https site with self-signed cert. I get
javax.net.ssl.SSLPeerUnverifiedException: No peer certificate.
I guess the default ssl options can be overriding using setSSLSocketFactory(SSLSocketFactory sslSocketFactory)
method, but I'm not sure how to do it or it might not be the right way at all.
Please suggest how can I solve this issue ?
You do it almost exactly the same as explained here for HttpClient except a little bit simpler - Trusting all certificates using HttpClient over HTTPS
Create a custom class:
Then when you create your client instance:
As explained in many places simply bypassing verification of the certificates is wrong on so many levels. Do not do that!
What you should do instead is to create
.bks
file from your cert(for that purpose you gonna need Bouncy Castle):Next place your newly created
outputname.bks
insideres/raw
folder.Create helper function(it could be inside own class or whatever you like):
And last but not least, set your
AsyncHttpClient
to use the new socket factory:You can use constructor AsyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int httpsPort). From version loopj library 1.4.4 and bigger. For example
and you get warning message to logcat at the Verbose log.
With
Https
andcertificate
I have done it successfully with the help of two docs HttpsUrlConnection and Portecle.Don't NUKE all SSL certificates.. Trusting all certificates is a BAD PRACTICE!!!
Take a look at my solution. Some contents from this Gist can help your to figure how to do this.
OBS.: I'm using Android Volley.
https://gist.github.com/ivanlmj/f11fb50d35fa1f2b9698bfb06aedcbcd
Simpler way is to use built-in MySSLSocketFactory in loopj, so you don't have to create another class