Unable to set private key file using cURL
Asked Answered
Y

2

6

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?

Yonita answered 1/3, 2011 at 6:19 Comment(2)
Can you tell what the problem is you are having?Glottic
I am getting above error:Unable to set private key file:'filepath'/secure.key type PEM. Note I have not done any settings on my server. Do I need to install /do any setting at client server as well for accessing https site?Yonita
M
3

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

Mattias answered 21/2, 2012 at 16:5 Comment(0)
F
0

N.B. this is a confusing message

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

My problem was actually not related to the private key file (despite the path printed in the message). It was the certificate file which was incorrect and needed to contain the full chain of certs in order including finally the cert for which this is the key.

Feder answered 10/9 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.