php关闭证书验证失败,php – SSL错误SSL3_GET_SERVER_CERTIFICATE:证书验证失败

升级到PHP 5.6后,我尝试通过fsockopen()连接到服务器时出现错误..

服务器(主机)上的证书是自签名的

PHP Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

if($fp = fsockopen($host, $port, $errno, $errstr, 20)){

$this->request = 'POST '.substr($this->url, strlen($this->host)).' HTTP/1.1'.$crlf

.'Host: '.$this->host.$crlf

.'Content-Length: '.$content_length.$crlf

.'Connection: Close'.$crlf.$crlf

.$body;

fwrite($fp, $this->request);

while($line = fgets($fp)){

if($line !== false){

$this->response .= $line;

}

}

fclose($fp);

}

试过

# cd /etc/ssl/certs/

# wget http://curl.haxx.se/ca/cacert.pem

php.ini

openssl.cafile = "/etc/ssl/certs/cacert.pem"

但脚本仍然无法工作

更新

这工作

echo file_get_contents("/etc/ssl/certs/cacert.pem");

更新2

$contextOptions = array(

'ssl' => array(

'verify_peer' => true, // You could skip all of the trouble by changing this to false, but it's WAY uncool for security reasons.

'cafile' => '/etc/ssl/certs/cacert.pem',

//'CN_match' => 'example.com', // Change this to your certificates Common Name (or just comment this line out if not needed)

'ciphers' => 'HIGH:!SSLv2:!SSLv3',

'disable_compression' => true,

)

);

$context = stream_context_create($contextOptions);

$fp = stream_socket_client("{$host}:{$port}", $errno, $errstr, 20, STREAM_CLIENT_CONNECT, $context);

错误

PHP Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误是因为SSL证书验证失败,无法获取本地发行者证书所导致的。解决办法是重新打开终端,并输入'pip install --upgrade certifi'来更新certifi库。这个操作应该可以解决该问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [WARNING: Download failure <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed](https://blog.csdn.net/linhs822/article/details/121235164)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [python3 urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get loca](https://blog.csdn.net/huryer/article/details/122728478)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Reading_URL_Content:此文件包含用于使用HTTP请求读取URL内容(包括文本和图像)的python代码](https://download.csdn.net/download/weixin_42151373/15268473)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值