curl命令ssl错误_PHP,SSL和cURL SSL3_GET_SERVER_CERTIFICATE错误

curl命令ssl错误

I recently developed a complex system for a customer that involved PHP, cURL, and a SSL connection to a third party vendor. The third party vendor would validate the security certificate of the source (the system I created) and either allow or reject access. My code looked like this:

我最近为客户开发了一个复杂的系统,该系统涉及PHP,cURL和与第三方供应商的SSL连接。 第三方供应商将验证源(我创建的系统)的安全证书,并允许或拒绝访问。 我的代码如下所示:


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://thirdparty.com/token.php'); //not the actual site
curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'customer_id='.$cid.'&password='.$pass);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); 
curl_setopt($ch,CURLOPT_CAINFO,'ca-bundle.crt'); /* problem here! */
$result = curl_exec($ch);
if(empty($result)) { /* error: nothing returned */ } else { /* success! */ }
curl_close($ch);


Unfortunately I was persistently receiving the following error message:

不幸的是,我一直收到以下错误消息:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

It turns out that the SSL bundle file I was using was old, as was the default bundle that came with the old version of cURL the shared hosting server. Essentially the third party didn't trust that the system's SSL certificate was valid. I downloaded Mozilla's bundle file, named it mozilla.pem and changed my PHP code to:

事实证明,我使用的SSL捆绑包文件很旧,而旧版本的cURL(共享托管服务器)随附的默认捆绑包也很旧。 本质上,第三方不信任系统的SSL证书有效。 我下载了Mozilla的捆绑文件 ,将其命名为mozilla.pem并将PHP代码更改为:


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://thirdparty.com/token.php'); //not the actual site
curl_setopt($ch,CURLOPT_TIMEOUT,60);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'customer_id='.$cid.'&password='.$pass);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); 
curl_setopt($ch,CURLOPT_CAINFO,'mozilla.pem'); /* fixed! */
$result = curl_exec($ch);
if(empty($result)) { /* error: nothing returned */ } else { /* success! */ }
curl_close($ch);


I share this with you because it cost me over three hours. Hopefully this will save someone time and frustration in the future.

我与您分享,因为这花费了我三个多小时。 希望这可以节省将来的时间和挫败感。

翻译自: https://davidwalsh.name/php-ssl-curl-error

curl命令ssl错误

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值