Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL with a PKCS#12 certificate in a bash script

i have to connect to a webservice, where a pkcs12 certificate is a must. the idea was to use curl in a bash script (under OS X, to be specific).

i have learnt that one of the few things curl cannot do in communication, is handling pkcs12 certificates (.p12). what are my options?

i have read that converting the certificate to PEM format would work (using openssl), however i have no idea how to tell curl that it gets a PEM and should communicate with a webservice requesting PKCS12 certificates.

converting pkcs12 to pem would be done like this (e.g.), it worked for me, however i haven't successfully used them with curl:

openssl pkcs12 -in mycert.p12 -out file.key.pem -nocerts -nodes openssl pkcs12 -in mycert.p12 -out file.crt.pem -clcerts -nokeys 

any hints? or, any alternatives to curl? the solution should be commandline based.

like image 697
svenson Avatar asked Aug 27 '15 15:08

svenson


People also ask

Is PKCS same as PFX?

PKCS#12 (also known as PKCS12 or PFX) is a binary format for storing a certificate chain and private key in a single, encryptable file. PKCS#12 files are commonly used to import and export certificates and private keys on Windows and macOS computers, and usually have the filename extensions . p12 or . pfx .

How do you curl with a client certificate?

To authenticate with a private key and certificate using curl, you will need to provide the --key and --cert options to your request. The private key must be decrypted in plain text. The provided certificate must contain the corresponding public key.


1 Answers

I think you have allready resolved but i had a the same problem. I answer for share my solution.

If you have a .p12 file your approach is right. First of all you have to get the cert and the key separated from the p12 file. As an example, if you have a mycert.p12 file execute

openssl pkcs12 -in mycert.p12 -out file.key.pem -nocerts -nodes openssl pkcs12 -in mycert.p12 -out file.crt.pem -clcerts -nokeys 

Then you have to make the call to your url. For instance assume that you want to get the wsdl of a specific webservice

curl -E ./file.crt.pem --key ./file.key.pem https://myservice.com/service?wsdl 

If the files file.crt.pem and file.key.pem are in your working folder "./" is mandatory.

like image 82
Smalltree1989 Avatar answered Sep 23 '22 06:09

Smalltree1989