php - 卷曲 OpenSSL 错误 141A318A tls_process_ske_dhe:dh 密钥太小
问题描述
我有一个 web 应用程序,它对不同的站点进行 curl 调用以获取数据。由于我的网络空间提供商 (ionos) 对服务器进行了一些更改,因此 curl 调用不再有效。
我的 curl 调用如下所示:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sResult = curl_exec($ch);
curl_close($ch);
它没有用。$sResult 为空。我更改了代码并尝试了
$test = file_get_contents($link);
这给了我错误:
PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small
我的 curl 调用或 file_get_contents 调用中是否缺少某些内容?
解决方案
针对此错误的通常建议是将 /etc/ssl/openssl.cnf 中的“CipherString”参数设置为“DEFAULT:@SECLEVEL=1”。
在 PHP 中,您可以通过以下方式实现相同的目的curl_setopt()
:
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT@SECLEVEL=1');
这是一个比编辑 openssl.cnf 更好的解决方案,因为它允许您仅放松一个特定调用的安全性,而不是系统范围的安全性。
推荐阅读
- python - Keras Lambda 层计算平均值
- arrays - 在 Swift 中从二进制文件中读取整数
- django - 任何人都可以为我的 django 项目建议一个数据库模式吗?
- javascript - 提交空搜索请求时出现错误“TypeError: Cannot read property 'map' of undefined”
- jira - Leverice 中的 Jira 通道状态
- powershell - pwsh -Command 正在删除引号
- python-3.x - 如何替换 python.pandas 中的数据头?
- c++ - 如何用qt实现定时器?
- node.js - 使用 Node.js 向用户发送通知
- javascript - 在本地使用 NodeJs、Express 和 React 的 Cors 问题