I have a pfx certificate which dosent work with curl command. Than I am try to import this file to NSS DB and after this curl command from terminal will work, but i can’t figure out how to add this certificate to curl in php file.
import certificate to NSS DB
pk12util -i key.pfx -d sql:/etc/pki/nssdb
certutil -L -d sql:/etc/pki/nssdb
"pfx-key" is the cert name in NSS DB "password" is the password when importing certificate to NSS DB
curl --cert pfx-key:password --location --request POST 'https://example.com' --header 'Content-Type: application/json' --data '{}'
- this command works
but how make it works from code?
curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-type: application/json']);
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_SSLCERT, 'pfx-key');
curl_setopt($ch, CURLOPT_SSLKEY, 'pfx-key');
curl_setopt($ch, CURLOPT_KEYPASSWD, 'password');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (! $result = curl_exec($ch)) {
var_dump(curl_error($ch));
}
curl_close($ch);