Php 文件\u获取\u内容:无法设置本地证书链文件
我们正在使用composer用Satis升级依赖项。在最近的服务器升级之后,我们无法这样做。缩小可能的原因,我们发现,file_get_contents php函数在尝试建立ssl连接时失败 我们正在使用以下脚本测试ssl:Php 文件\u获取\u内容:无法设置本地证书链文件,php,ssl,zend-framework,composer-php,satis,Php,Ssl,Zend Framework,Composer Php,Satis,我们正在使用composer用Satis升级依赖项。在最近的服务器升级之后,我们无法这样做。缩小可能的原因,我们发现,file_get_contents php函数在尝试建立ssl连接时失败 我们正在使用以下脚本测试ssl: <?php $url = 'https://satis.work.com/packages.json'; $contextOptions = [ 'ssl' => [ 'verify_peer' => false,
<?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";
只有在PEM文件中的“开始证书”部分之前省略明文元数据(颁发者、有效性等)时,才会出现这种情况。对于较新版本的PHP(包括7.0),这一部分现在似乎是强制性的。到目前为止,我还没有发现更多,但我的猜测是,这是一个openssl问题。
续订证书,包括openssl生成的元数据部分,为我解决了这个问题。只有在PEM文件中的“开始证书”部分之前省略明文元数据(颁发者、有效性等)时,才会出现这种情况。对于较新版本的PHP(包括7.0),这一部分现在似乎是强制性的。到目前为止,我还没有发现更多,但我的猜测是,这是一个openssl问题。
续订证书,包括openssl生成的元数据部分,为我解决了这个问题。我也为我解决了同样的问题。看来明文元数据并不重要。
类似的代码在使用openssl 1.1.0j的PHP7.0上运行,在使用openssl 1.1.1c的PHP7.3上被破坏-我得到了相同的错误文本。
添加明文元数据对我没有帮助。在当前ca证书中添加cafile
上下文参数对我也没有帮助
当我尝试使用curl发出相同的请求时,出现了错误:
curl -k --cert cert.pem https://myservice.com/soap/ShopService/
curl: (58) could not load PEM client certificate, OpenSSL error error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak, (no key found, wrong pass phrase, or wrong file format?)
因此我发现现有的旧客户端证书是使用弱SHA1和RSA加密算法签名的。
私钥的长度是2048位-没问题(如果您有1024位-现在不安全,您还需要一个新的更长的密钥)
我已使用实际的sha256哈希重新发布了客户端证书(openssl选项-sha256)。我的CA证书具有相同的弱哈希sha1,但无需更改它,只需更改客户端证书即可。命令:
# here:
# cert.pem - my old client certificate with private key
# ca.pem - service's current CA certificate for signing client certificates with it's private key
# cert2.pem - my new working client certificate with the same old private key
#
# make new certificate request from current client certificate
openssl x509 -x509toreq -in cert.pem -out cert2.csr -signkey cert.pem -sha256
# make new certificate
openssl x509 -req -in cert2.csr -out cert2.pem -CA ca.pem -sha256 -days 730 -set_serial 0x51ca170d
# append private key
openssl rsa -in cert.pem >> cert2.pem
几个小时的疼痛,现在没事了)
php似乎为此错误发送了不正确的错误消息。我为自己解决了同样的问题。看来明文元数据并不重要。
类似的代码在使用openssl 1.1.0j的PHP7.0上运行,在使用openssl 1.1.1c的PHP7.3上被破坏-我得到了相同的错误文本。
添加明文元数据对我没有帮助。在当前ca证书中添加cafile
上下文参数对我也没有帮助
当我尝试使用curl发出相同的请求时,出现了错误:
curl -k --cert cert.pem https://myservice.com/soap/ShopService/
curl: (58) could not load PEM client certificate, OpenSSL error error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak, (no key found, wrong pass phrase, or wrong file format?)
因此我发现现有的旧客户端证书是使用弱SHA1和RSA加密算法签名的。
私钥的长度是2048位-没问题(如果您有1024位-现在不安全,您还需要一个新的更长的密钥)
我已使用实际的sha256哈希重新发布了客户端证书(openssl选项-sha256)。我的CA证书具有相同的弱哈希sha1,但无需更改它,只需更改客户端证书即可。命令:
# here:
# cert.pem - my old client certificate with private key
# ca.pem - service's current CA certificate for signing client certificates with it's private key
# cert2.pem - my new working client certificate with the same old private key
#
# make new certificate request from current client certificate
openssl x509 -x509toreq -in cert.pem -out cert2.csr -signkey cert.pem -sha256
# make new certificate
openssl x509 -req -in cert2.csr -out cert2.pem -CA ca.pem -sha256 -days 730 -set_serial 0x51ca170d
# append private key
openssl rsa -in cert.pem >> cert2.pem
几个小时的疼痛,现在没事了)
php似乎为此错误发送了错误消息。您是否尝试验证您的证书?应该是这样的“openssl verify-verbose/home/work/.ssl/deployer.pem”verify工作正常:命令(openssl verify-verbose-CAfile/home/work/.ssl/ca.pem/home/work/.ssl/deployer.pem)导致(/home/work/.ssl/deployer.pem):确定)您是否尝试过验证您的证书?应该是这样的“openssl验证-verbose/home/work/.ssl/deployer.pem”验证工作正常:命令(openssl验证-verbose-CAfile/home/work/.ssl/ca.pem/home/work/.ssl/deployer.pem)导致(/home/work/.ssl/deployer.pem:OK)