CURL with SSL certificates fails: error 58 cannot install the private key file

I am trying to connect to a remote host using cURL. Connection requires the use of a certificate and a secret key that is password protected. So far I have not been crowned with this code below:

<?php $wsdl = 'https://domain.com/?wsdl'; $certFile = getcwd() . '/auth/cert.pem'; $keyFile = getcwd() . '/auth/key.pem'; $password = 'pwd'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $wsdl); curl_setopt($ch, CURLOPT_SSLCERT, $certFile); curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $password); curl_setopt($ch, CURLOPT_SSLKEY, $keyFile); #curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); #curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); #curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $output = curl_exec($ch); var_dump(curl_errno($ch)); var_dump(curl_error($ch)); 

As a result, I get error 58 : unable to set private key file: '/home/.../domains/.../public_html/auth/key.pem' type PEM .

Things I've tried so far:

I'm sure the problem lies in my configuration, but I'm not sure where to look.

+6
source share
2 answers

I fixed this problem. I think because of the number of questions regarding this problem and the number of different solutions, others will benefit from the solution. Here:

I used the openssl CLI program to convert the .p12 key file to a .pem key file. The trick is how the transformation happens.

First, I converted it using this command, and I had a problem as described in the question:

openssl pkcs12 -in key.p12 -out key.pem -nodes -clcerts

While the command below did the trick:

openssl pkcs12 -in key.p12 -out key.pem -clcerts

For more information, see the source I used: https://community.qualys.com/docs/DOC-3273

+10
source

Just in case, this is useful for others looking for this problem, I found that CURLOPT_SSLCERT and CURLOPT_SSLKEY do not work with relative paths.

This is with WAMP, php version 5.5 on Windows.

0
source

Source: https://habr.com/ru/post/978612/


All Articles