PHP CURL错误:无法使用客户端证书(找不到密钥或密码短语错误?)


PHP CURL error: unable to use client certificate (no key found or wrong pass phrase?)

我正在做这件事:

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, '1'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '2'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); 
curl_setopt($ch, CURLOPT_CAINFO,  getcwd().'/public.pem'); 
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'/private.key'); 
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, '1234');
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, '1234'); 
curl_setopt($ch, CURLOPT_URL, "http://api-xxxxxx.duosecurity.com/auth/v2/preauth");
$dataa = curl_exec($ch);

我收到这个错误:unable to use client certificate (no key found or wrong pass phrase?)

我错过了什么?如果代码是可以的,那么您能否指导我如何使用opensslssh-keygen为此生成一对证书

这就是通过HTTPS 连接到雅虎的方式

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, '1'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '2'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); 
curl_setopt($ch, CURLOPT_URL, "https://m.yahoo.com/");
$dataa = curl_exec($ch);

您不使用客户端证书与HTTPS主机进行通信。

浏览器/客户端不使用客户端证书的原因太多,无法在此列出。

客户端证书似乎是一种对网站进行身份验证或登录的方法——它们不是加密与服务器通信的一部分。

https://en.wikipedia.org/wiki/Client_certificate

https://pilif.github.io/2008/05/why-is-nobody-using-ssl-client-certificates/

http://blogs.msdn.com/b/kaushal/archive/2012/02/18/client-certificates-v-s-server-certificates.aspx

更新

在得知最初的问题涉及duosecurity的API,而不是一个常规的yahoo http连接后,我查看了duo的API文档和JS&PHP客户端库。我找不到任何对客户端SSL证书的引用。

要返回并解决"找不到密钥或通行短语错误"的原始错误,我们应该查看CURLOPT_*设置。

在最初的问题中,证书和密钥被curlopt设置错误地识别。

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, '1'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '2'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1'); 
curl_setopt($ch, CURLOPT_SSLCERT,  getcwd().'/public.pem'); 
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, '1234');
curl_setopt($ch, CURLOPT_SSLKEY, getcwd().'/private.key'); 
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, '1234'); 
curl_setopt($ch, CURLOPT_URL, "http://api-xxxxxx.duosecurity.com/auth/v2/preauth");
$dataa = curl_exec($ch);

使用SSLCERT(密码)和SSLKEY(密码)启用客户端证书。客户端证书不太可能需要CA-CURLOPT_CAINFO仅用于帮助识别对等方,而不是您自己。