忽略 PHP CURL CURLOPT_SSL_VERIFYPEER

由于某种原因,我无法在 HTTPS 中使用 CURL。在我运行 curl 库升级之前,一切都运行良好。现在我在尝试执行 CURL 请求时遇到了这种响应: SSL CA 证书有问题(路径? 访问权限?)

以下是我就相关问题提出的一些建议:

  • 禁用主机和对等机的验证

    curl_setopt($cHandler, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($cHandler, CURLOPT_SSL_VERIFYPEER, true);
    
  • Enable CURLOPT_SSL_VERIFYPEER and point to cacert.pem downloaded from http://curl.haxx.se/docs/caextract.html

    curl_setopt($cHandler, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($cHandler, CURLOPT_CAINFO, getcwd() . "/positiveSSL.ca-bundle");
    
  • I also tried to do the same thing with positiveSSL.ca-bundle which was provided as bundle CA certificate for the server I am trying to connect to.

  • Edit php ini settings with curl.cainfo=cacert.pem (file in the same directory and accessible by apache)

  • Rename /etc/pki/nssdb to /etc/pki/nssdb.old

Unfortunatelly none of the above are able to solve my problem and I constantly get Problem with the SSL CA cert (path? access rights?) message.

And I don't need this verification in the first place (I am aware of security issues).

Does anybody have any other suggestions?

UPDATE

After updating to the latest libraries and restart of the whole box, not just apache which I was doing it all seems to be working now again!!!

373053 次浏览

根据文档: 要验证主机证书或对等证书,您需要使用 CURLOPT_CAINFO选项指定备用证书,或者使用 CURLOPT_CAPATH选项指定证书目录。

再看看 CURLOPT_SSL_VERIFYHOST:

  • 1检查 SSL 对等证书中是否存在公共名称。
  • 2检查是否存在通用名称,并验证它是否与所提供的主机名匹配。

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

我们在 CentOS7机器上遇到了同样的问题。禁用 VERIFYHOST VERIFYPEER并没有解决问题,我们不再有 cURL 错误,但是响应仍然是无效的。对与 cURL 相同的链接执行 wget也会导致证书错误。

- > 我们的解决方案也是重新启动 VPS,这解决了它,我们能够再次完成请求。

对我们来说,这似乎是一个内存损坏的问题。重新启动 VPS 再次加载内存中的库,现在它可以工作了。因此,如果上述来自 @clover的解决方案不起作用,尝试重新启动您的机器。

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return data inplace of echoing on screen
curl_setopt($ch, CURLOPT_URL, $strURL);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Skip SSL Verification
$rsData = curl_exec($ch);
curl_close($ch);
return $rsData;