SSL/TLS操作失败PHP5.6-curl-ca-bundle.crt&;cacert.pem


SSL/TLS operations failing PHP5.6 - curl-ca-bundle.crt & cacert.pem

这几周来一直让我抓狂。

我通常在centos7盒子上进行开发,但最近我开始在Windows10上使用Xampp,并使用centosbox将代码提交到&客户端测试。

在linux上一切都很好,但在Windows上,任何SSL/TLS调用都会失败,据我所知,这是由于新的PHP5.6功能,默认情况下验证对等证书和主机名-http://php.net/manual/en/migration56.openssl.php

我在网上和SO上读过几乎每一本指南,据我所知,我已经尝试了一切,但都无济于事。

有人能帮忙吗?!

php.ini中启用了扩展extension=php_openssl.dllextension=php_curl.dll也是。

我还下载了证书文件,并将以下内容添加到我的php.ini…中

curl.cainfo = "‪C:'xampp'php'certs'curl-ca-bundle.crt"
curl.capath = "‪C:'xampp'php'certs'"

openssl.cafile= "‪C:'xampp'php'certs'curl-ca-bundle.crt"
openssl.capath= "‪C:'xampp'php'certs'"

我得到的错误是:

对于使用TLS的SMTP呼叫:

PHP Warning:  stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in W:'libraries'Zend'Mail'Protocol'Smtp.php on line 206

对于cURL调用:

API call to messages/send failed: error setting certificate verify locations: CAfile: ‪C:'xampp'php'certs'cacert.pem CApath: none

C:'xampp'php'certs'目录的内容为:

ca-bundle.trust.crt
cacert.pem
curl-ca-bundle.crt

我已经重新启动了Apache,甚至尝试在命令行中使用curl.exe作为独立程序,它可以很好地请求HTTPS域(不确定这是否相关,但我还是尝试过!)

我还尝试将以下内容添加到php.ini中(并重新启动Apache),但没有效果。。

openssl.verify_peer= false
openssl.verify_peer_name = false

有什么想法吗?

错误消息error setting certificate verify locations来自libcurl本身,意味着它找不到或无法打开指定的CAFile。

在Windows上,我认为如果你从更改路径,它会起作用

curl.cainfo = "‪C:'xampp'php'certs'curl-ca-bundle.crt"

curl.cainfo = "‪C:/xampp/php/certs/curl-ca-bundle.crt"

OpenSSL可能也是如此,但我还没有进行测试来确认。

原来这是权限问题,证书文件没有被读取-将C:/xampp/php/certs/文件夹移动到另一个位置(例如我的用户目录中)解决了问题:)