Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set private key file using cURL

Tags:

php

curl

I want to connect to a secured site using PHP cURL. The site owners gave us four files:

  1. sitename.key
  2. sitename.p12
  3. sitename.pem
  4. icom-live-ca.pem

And the PEM pass phrase.

$curl_resource = curl_init ();

curl_setopt ( $curl_resource, CURLOPT_URL, $sHost );        
curl_setopt ( $curl_resource, CURLOPT_POST, 1 );
curl_setopt ( $curl_resource, CURLOPT_POSTFIELDS, $post_string );
curl_setopt ( $curl_resource, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl_resource, CURLOPT_HTTPHEADER, $headerdata);
curl_setopt ( $curl_resource, CURLOPT_HEADER, true);
curl_setopt ( $curl_resource, CURLOPT_SSLCERT , HOMEDIR.'cert/icom-live-ca.pem');
curl_setopt ( $curl_resource, CURLOPT_SSLCERTPASSWD, 'PEM pass phrase');
curl_setopt ( $curl_resource, CURLOPT_SSLKEY, HOMEDIR.'cert/secure.key');
curl_setopt ( $curl_resource, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ( $curl_resource, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ( $curl_resource, CURLOPT_SSLCERTTYPE, 'PEM');

I am getting the following error:

Unable to set private key file:'filepath'/secure.key type PEM.

I have not done any settings on my server. Do I need to install/change any setting at client server as well for accessing HTTPS sites?

like image 484
devel Avatar asked Nov 06 '22 02:11

devel


1 Answers

You should check the file permissions of the files and directory they are in to make sure your program can read them properly. If that doesn't work check the .pem file to make sure the certificate is followed by the cert of its issuer.

See this question and answers for more info: Unable to use libcurl to access a site requiring client authentication

like image 117
mc_kennedy Avatar answered Nov 12 '22 18:11

mc_kennedy