Openssl_get_publickey () and curl "cannot use client certificate"

I got the following code.

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

$keystore = '/var/www/html/key.pem';
$url = 'https://myurl';
$keystorepassword = '123';

$key2 = "/var/www/html/public.pem";


$handler = fopen($key2, "r"); 
$kkey = fread($handler, 8192);
fclose($handler);
$pubkey = openssl_get_publickey($kkey);
openssl_free_key($pubkey);


$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
//curl_setopt($curl, CURLOPT_SSLVERSION,3);
curl_setopt($curl, CURLOPT_SSLCERT, $keystore);
curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keystorepassword);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'data');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result =curl_exec ($curl);
var_dump($result);
if(curl_error($curl)){
    $result = curl_error($curl);
    var_dump($result);
}
curl_close ($curl);
?>

And it returns "inability to use a client certificate (without a key or an incorrect phrase?)". If I comment out the line "$ pubkey = openssl_get_publickey ($ kkey);" then curl works fine. Is there a chance that “something” remains in memory, and curl uses it?

+1
source share

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


All Articles