gpt4 book ai didi

php - 文件获取内容 : Unable to set local cert chain file

转载 作者:太空宇宙 更新时间:2023-11-03 13:34:14 25 4
gpt4 key购买 nike

我们正在使用 Composer 升级与 Satis 的依赖关系。在最近一次服务器升级后,我们无法这样做。缩小可能的原因,我们发现,file_get_contents php 函数在尝试建立 ssl 连接时失败。

我们正在使用以下脚本来测试我们的 ssl:

<?php
$url = 'https://satis.work.com/packages.json';
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'local_cert' => '/home/work/.ssl/deployer.pem',
]
];
$sslContext = stream_context_create($contextOptions);
$result = file_get_contents($url, false, $sslContext);
echo $result, "\n";

这是抛出的:

PHP Warning: file_get_contents(): Unable to set local cert chain file `/home/work/.ssl/deployer.pem'; Check that your cafile/capath settings include details of your certificate and its issuer in /home/omlook/test-ssl.php on line 12 PHP Warning: file_get_contents(): Failed to enable crypto in /home/work/test-ssl.php on line 12 PHP Warning: file_get_contents(https://satis.work.com/packages.json): failed to open stream: operation failed in /home/work/test-ssl.php on line 12

绝对不是权限或文件所有权的问题,脚本可以读取 .pem 就好了。令人困惑的是,完全相同的脚本和 .pem key 如何在我的本地环境中正常工作,而且版本差异似乎并不那么重要。

本地环境:

PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.18-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

OpenSSL 1.0.2g 1 Mar 2016

服务器:

PHP 7.1.7-1+ubuntu14.04.1+deb.sury.org+1 (cli) (built: Jul 7 2017 10:07:42) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.1.7-1+ubuntu14.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

OpenSSL 1.1.0f 25 May 2017

最佳答案

这似乎只有在 PEM 文件中的“BEGIN CERTIFICATE”部分之前省略明文元数据(发行者、有效性等)时才会发生。对于较新版本的 PHP(包括 7.0),这部分现在似乎是强制性的。到目前为止我还没有发现更多,但我的猜测是,这是一个 openssl 问题。更新证书,包括 openssl 生成的元数据部分,解决了我的问题。

关于php - 文件获取内容 : Unable to set local cert chain file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45208159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com