简体   繁体   中英

Unable to set private key file using 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM