{"id":30,"date":"2007-03-10T06:46:00","date_gmt":"2007-03-10T11:46:00","guid":{"rendered":"http:\/\/www.rajatswarup.com\/blog\/?p=30"},"modified":"2010-02-10T23:54:21","modified_gmt":"2010-02-11T04:54:21","slug":"using-certificates-with-curl","status":"publish","type":"post","link":"https:\/\/www.rajatswarup.com\/blog\/2007\/03\/10\/using-certificates-with-curl\/","title":{"rendered":"Using Certificates with cURL"},"content":{"rendered":"<p><span style=\"font-weight: bold;\">The problem<\/span>: Using Digital Certificates issued by a Certification Authority (CA) with <a href=\"http:\/\/curl.haxx.se\/\">curl<\/a>.<\/p>\n<p><span style=\"font-weight: bold;\">The situation<\/span>: I have a .cer (Digital Certificate) file, .pfx (Personal Information Exchange file i.e., the private key for the certificate).  I cannot use either of these to authenticate to the web service as curl would not accept these formats.<\/p>\n<p><span style=\"font-weight: bold;\">The solution<\/span>:<br \/>1) Convert it into PEM format (X.509 certificate) using <a href=\"http:\/\/www2.blogger.com\/www.openssl.org\">openssl<\/a>.<br \/><span style=\"font-family:courier new;\">openssl pkcs12 -in abcd.pfx -out abcd.pem<\/span><br \/>Enter a passphrase and a password.<br \/>2) Still you cannot use this with curl because you&#8217;d get a few errors.<br \/>3) Convert this PEM certificate into three different certificates for the client, the private key and the certification authority certificate.<br \/><span style=\"font-family:courier new;\">    openssl pkcs12 -in abcd.pfx -out ca.pem -cacerts -nokeys<\/span><br \/><span style=\"font-family:courier new;\">    openssl pkcs12 -in abcd.pfx -out client.pem -clcerts -nokeys<\/span><br \/><span style=\"font-family:courier new;\">    openssl pkcs12 -in abcd.pfx -out key.pem -nocerts<\/span><br \/>4) Use the following command:<br \/><span style=\"font-family:courier new;\">  curl -k https:\/\/www.thesitetoauthenticate.com\/test -v &#8211;key key.pem &#8211;cacert  ca.pem &#8211;cert client.pem:<the_key_selected_in_step_1><\/the_key_selected_in_step_1><\/span><\/p>\n<p>This stuff is also mentioned on curl forum at <a href=\"http:\/\/curl.haxx.se\/mail\/archive-2005-09\/0138.html\">http:\/\/curl.haxx.se\/mail\/archive-2005-09\/0138.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The problem: Using Digital Certificates issued by a Certification Authority (CA) with curl. The situation: I have a .cer (Digital Certificate) file, .pfx (Personal Information Exchange file i.e., the private key for the certificate). I cannot use either of these to authenticate to the web service as curl would not accept these formats. The solution:1) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[195,197,193],"tags":[216,330,235],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-crypto","category-tools","category-webappsec","tag-certificates","tag-curl","tag-x-509"],"_links":{"self":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":1,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}