leancloud / php-sdk

LeanCloud PHP SDK
Apache License 2.0
53 stars 23 forks source link

Windows curl 没有证书无法发送 https 请求 #28

Closed linzebing closed 9 years ago

linzebing commented 9 years ago
Fatal error: Uncaught exception 'RuntimeException' with message 'CURL connection (https://api.leancloud.cn/1.1/classes/G3Data) error: 60 60'
in C:\xampp\htdocs\crowdsensing\vendor\leancloud\leancloud-sdk\src\LeanCloud\LeanClient.php:315
Stack trace: 
#0 C:\xampp\htdocs\crowdsensing\vendor\leancloud\leancloud-sdk\src\LeanCloud\LeanClient.php(345): LeanCloud\LeanClient::request('GET', '/classes/G3Data', Array, NULL, Array, false)
#1 C:\xampp\htdocs\crowdsensing\vendor\leancloud\leancloud-sdk\src\LeanCloud\LeanQuery.php(687): LeanCloud\LeanClient::get('/classes/G3Data', Array) 
#2 C:\xampp\htdocs\crowdsensing\index.php(9): LeanCloud\LeanQuery->count()
#3 {main} thrown in C:\xampp\htdocs\crowdsensing\vendor\leancloud\leancloud-sdk\src\LeanCloud\LeanClient.php on line 315

你好 这里是什么问题?

juvenn commented 9 years ago

应该是 Windows 下 curl 没有找到证书,无法发送 https 的请求。我们回头再测试并检测 windows 下的部署问题。谢谢报告。

juvenn commented 9 years ago

一个解决办法是,在 php.ini 中指定证书:

[PHP]
curl.cainfo={path}/ca-bundle.crt

如果没有证书,可以参考这里来获取:http://curl.haxx.se/docs/caextract.html

juvenn commented 9 years ago

curl 手册关于证书的说明:

--cacert [file]

curl recognizes the environment variable named 'CURL_CA_BUNDLE' if it is set, and uses the given path as a path to a CA cert bundle. This option overrides that variable.

The windows version of curl will automatically look for a CA certs file named 'curl-ca-bundle.crt', either in the same directory as curl.exe, or in the Current Working Directory, or in any folder along your PATH.

If curl is built against the NSS SSL library, the NSS PEM PKCS#11 module (libnsspem.so) needs to be available for this option to work properly.

juvenn commented 9 years ago

总结两种方案供参考:

  1. 将证书文件 curl-ca-bundle.crt 置于 curl.exe 相同的目录,通常情况下位于 C:\Windows\system32
  2. 将证书文件 curl-ca-bundle.crt 置于自定义的目录,然后在 php.ini 中明确设置证书位置:
[PHP]
curl.cainfo={path}/ca-bundle.crt
linzebing commented 9 years ago

感谢 已修复

ZHENGJerry commented 8 years ago

第一次接触证书问题,能详细说一下获取证书的问题吗?每一个开始和结束都算是一个证书吗?我怎么制作证书呢?

duanqiping commented 8 years ago

我的环境是wampserver2.2,curl.exe文件找不到,我只能使用第2个方法,但是没有任何效果,求助......

image @juvenn

duanqiping commented 8 years ago

找到最简单的方法了。 把Client.php文件中有段代码curl_setopt($req, CURLOPT_SSL_VERIFYPEER, true);改成curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false); 就可以了,何须上面如此麻烦

aisk commented 8 years ago

@duanqiping 这样会引来安全风险,不推荐使用。

juvenn commented 8 years ago

@duanqiping windows 下面的目录分割符应该是 \ ,你试着调整一下:

curl.cainfo=C:\wamp\bin\...\ca-bundle.crt

CURLOPT_SSL_VERIFYPEER 是对数据加密的选项,建议不要设为 false,否则会以明文传输有安全风险。

juvenn commented 8 years ago

@duanqiping 抱歉纠正一下,CURLOPT_SSL_VERIFYPEER 是验证对方的身份,如果设为 false 会有被中间人攻击的风险。数据仍会加密传输。