I am trying to consume a REST API that requires Client certificate authentication on my PHP code. I have the certificate converted into a .pem, .pfx, .crt, .key and .keystore format The API also requires Basic authentication using username and password
I have tried different implementation on the server, but I keep getting the Error "unable to load client cert: -8018 (SEC_ERROR_UNKNOWN_PKCS11_ERROR"
It's a linux box, RedHat, running on Apache and PHP.
Here is the Code snippet I currently have implemented
$username="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$password="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
$certFile = "/etc/ssl/certs/cert/example.pem";
$certPass = "examplepass";
$keyFile = "/etc/ssl/certs/cert/example.key";
$caFile = "/etc/ssl/certs/cert/example.crt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://www.example.com/some_protected_page');
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
"Content-type: $content_type",
));
// The --cert option
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_CAINFO, $certFile);
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLCERT, $certFile);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass);
//curl_setopt($ch, CURLOPT_SSLKEY, $keyFile);
//curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $certPass);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$adata = curl_exec($ch);