I am porting an application which internally makes cURL calls to connect to a server securely. It uses downloaded certificate and private key file before making request to the server.
I have a “My_Private_key.pem” file containing RSA Private key, a “My_Certificate.pem” file containing the certificate server sent and a password with which “My_Private_key.pem” is encrypted. Now cURL has an option for setting SSLKey,SSLCertificate and Password.
Example
curl_easy_setopt(curl, CURLOPT_SSLCERT, credentials->certfile);
curl_easy_setopt(curl, CURLOPT_SSLKEY, credentials->keyfile);
curl_easy_setopt(curl, CURLOPT_KEYPASSWD, credentials->passwd);
Then cURL uses this information to request the server. I want to do a similar thing in Android. I have gone through many links which help me creating my own HttpClient which uses EasySSLSocketFactory,EasyX509TrustManager but i could not find a way to set these options in Android.
What is the equivalent way to do in Android ?
I am very new to SSL and so my question can be a little naive so please bear with it 🙂
You have to create a PKCS#12 file from your key and certificate, load it as a keystore and initialize HttpClient (or HttpsURLConnection) with it. For HttpClient you can use the SSLSocketFactory class to initialize the client with your key and certificate.
You can use something like this to create the PKCS#12 file:
$ openssl pkcs12 -export -in mycert.pem -inkey mykey.key -out mystore.pfx