I'm trying to send a GET request using PHP curl by passing a certificate
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$pemFile = tmpfile();
fwrite($pemFile, "demo-cert.p12");//the path for the pem file
$tempPemPath = stream_get_meta_data($pemFile);
$tempPemPath = $tempPemPath['uri'];
curl_setopt($ch, CURLOPT_SSLCERT, $tempPemPath);
$result = curl_exec($ch);
if(!$result)
{
echo "Curl Error: " . curl_error($ch);
}
else
{
echo "Success: ". $result;
}
But don't know how to pass the "password" so I get this error
Curl Error: could not load PEM client certificate, OpenSSL error error:0906D06C:PEM
routines:PEM_read_bio:no start line, (no key found, wrong pass phrase, or wrong file format?)
[update]
Changed demo-cert.p12 to demo-cert.pem which exists with the php file but still getting the same issue because no password sent. The certificate folder contains other 2 files: demo-combined.pem and demo-key.pem but first need to send the password.
[update2]
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSLCERT, 'demo-key.pem');
curl_setopt($ch, CURLOPT_SSLKEY, 'demo-cert.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'pass');
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, 'pass');
These files are stored with the PHP file in the same directory. Still getting the same error
[update 3]
How to edit the code to send the server certificate as well?
curl --show-error --verbose --cacert server-cert.pem --cert cert2.pem
curl_setopt($ch, CURLOPT_SSLCERT, 'demo-cert.pem');
curl_setopt($ch, CURLOPT_SSLKEY, 'demo-key.pem');
The result is:
Success: SOAP-ENV:ClientData required for operation
Not returning XML data as did while opening the same URL in the browser. Anything wrong yet?