【问题标题】:Curl OpenSSL error 141A318A tls_process_ske_dhe:dh key too small卷曲 OpenSSL 错误 141A318A tls_process_ske_dhe:dh 密钥太小
【发布时间】:2020-11-23 21:30:13
【问题描述】:

我有一个 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 调用中是否缺少某些内容?

【问题讨论】:

  • 目标服务器的证书要么需要改进,要么您必须以某种方式配置 openssl 以允许 dh 密钥太小。我不是一个 PHP 人,所以这是我能告诉你的最好的。可能在系统范围内更改设置会起作用,但它不是超级安全。 askubuntu.com/questions/1233186/…

标签: php curl https openssl


【解决方案1】:

针对此错误的通常建议是将 /etc/ssl/openssl.cnf 中的“CipherString”参数设置为“DEFAULT:@SECLEVEL=1”。

在 PHP 中,您可以使用 curl_setopt() 实现相同的目的:

curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT@SECLEVEL=1');

这是一个比编辑 openssl.cnf 更好的解决方案,因为它允许您放松对一个特定调用的安全性,而不是整个系统。

【讨论】:

    【解决方案2】:

    如果你使用的是 file_get_contents() 函数,这很好用

    $context=array(
        "ssl"=>array(
            'ciphers' => 'DEFAULT:!DH'
        ),
    ); 
    
    $json = file_get_contents($url, false, stream_context_create($context));
    

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 2015-05-31
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2019-02-25
      相关资源
      最近更新 更多