Twilio PHP - SSL证书:证书链中的自签名证书

时间:2015-03-19 19:58:22

标签: php ssl curl twilio

尝试使用他们的PHP library通过Twilio发送消息时,我正在努力解决此错误:

Fatal error: Uncaught exception Services_Twilio_TinyHttpException with message SSL certificate problem: self signed certificate in certificate chain thrown in F:\path\to\site\twilio-php\Services\Twilio\TinyHttp.php on line 119

我在Windows 7上使用wamp。

我当然找到了有关证书错误的所有其他帖子。从我所看到的情况来看,通常更新或添加cacert.pem文件可以解决问题。但是,即使这样做了,我仍然会遇到同样的错误。

正如这里的理智检查正是我所做的:

  1. 从此处下载最新证书:http://curl.haxx.se/ca/cacert.pem
  2. 将此文件放在以下位置c:/wamp/certs/cacert.pem
  3. 更新了php.ini,如下所示:curl.cainfo = c:/wamp/certs/cacert.pem
  4. 重新启动所有wamp服务,包括apache
  5. 我仍然得到同样的错误。我已经验证我正在使用phpinfo()编辑正确的php.ini。我不知道为什么还在抱怨。

    有没有办法100%验证我的cacert.pem文件是否被找到并读取?我已经检查了phpinfo(),但那里没有提到它。它应该说某个地方,如果它正在使用cacert.pem吗?

    谢谢!

9 个答案:

答案 0 :(得分:53)

I had the exact same issue

Follow these steps:

Download the following file - cacert.pem

Then download the following file - thawte_Premium_Server_CA.pem

Open the second file in a text editor and copy its contents into the first file (cacert.pem at the bottom/end).

Save cacert.pem and add the following lines to your php.ini :

[curl]
curl.cainfo=c:/xampp/php/cacert.pem

Obviously change the directory to the one where your pem is located. Restart the php local server (xampp/wamp). Then it will work flawlessly.

thanks.

答案 1 :(得分:8)

编辑TinyHttp.php

并在$ opts数组中添加CURLOPT_SSL_VERIFYPEER => FALSE,

答案 2 :(得分:3)

我没有使用Twilio,但是我在Windows上并且遇到了OP中描述的确切问题。我通过从此页面下载ca-bundle.crt文件并将我的php.ini指向它来解决此问题: http://curl.haxx.se/docs/caextract.html

答案 3 :(得分:1)

在我的情况下,上面的下载链接中的cacert.pem对我来说不起作用,但是来自之前的twilio php库包的cacert.pem如3.12.5有效。我在较新的包中修改了twilio.php以添加以下两行

CURLOPT_CAINFO => dirname(FILE) . '/cacert.pem'
'cafile' => dirname(FILE) . '/cacert.pem'

作为旧包的相应位置,并将cacert.pem复制到更新的包中。

答案 4 :(得分:1)

您可以通过使用您选择的选项调用Twilio的CurlClient构造函数来添加您自己的cURL选项,而不是攻击tiny_http.php,例如:

    $client = new \Twilio\Rest\Client($accountSid, $authToken);
    $curlOptions = [ CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false];
    $client->setHttpClient(new CurlClient($curlOptions));

    try {
        $call = $client->calls->create($from_phone, $phone_number, $callback_url);
        print 'Call queued with Twilio';
    } catch (\Exception $ex) {
        print 'Twilio error: ' . $ex->getMessage();
    }

答案 5 :(得分:0)

对我来说,这里发布的答案都没有。

但后来我将PHP升级到7.0.1 *,我不再遇到此错误:Services_Twilio_TinyHttpException: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL

*(C:\wamp\bin\php\php-7.0.1-Win32-VC14-x64代替C:\wamp\bin\php\php5.4.3

我的C:\wamp\bin\php\php-7.0.1-Win32-VC14-x64\php.ini已经包含curl.cainfo=C:/wamp/cacert.pem

答案 6 :(得分:0)

以下是Twilio的官方回答:

要尝试解决此问题,请尝试执行以下操作:

1下载以下pem文件:https://twilio.zendesk.com/attachments/token/EenviU5Rv4KHUzGM6VP5UijB0/?name=cacert.pem

2将此文件复制到c:\cert\cacert.pem(Windows)或Unix / Linux / Mac安装上的任何其他路径

3在您喜欢的编辑器中打开php.ini文件

如果您的php.ini中存在以下配置string: curl.cainfo,请通过删除“;”取消注释,然后修改路径以将其指向附加到此e的cacert.pem文件邮件,例如:

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

curl.cainfo=c:\cert\cacert.pem

5请重新启动Apache服务以应用更改(非常重要!)

答案 7 :(得分:0)

添加此答案是因为没有人提到[ini-tag]

php.ini

[curl]
curl.cainfo=C:\cacert.pem

cacert.pem在此处下载:https://twilio.zendesk.com/attachments/token/EenviU5Rv4KHUzGM6VP5UijB0/?name=cacert.pem

答案 8 :(得分:-1)

我遇到了同样的问题,但我一直在研究这篇文章,也许它可以帮到你。 http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

查看您的cURL版本。你必须在7.4x

相关问题