当前位置: 首页 > article >正文

OpenSSL 3.0.2 报 dh key too small 的问题

问题复现

运行命令 curl 访问一个 https 网站,可能会出现  "dh key too small" 的问题。

> curl -v --insecure  https://some_web_site
*   Trying 175.21.4.7:443...
* Connected to some_web_site (175.21.4.7) port 443 (#0)
* ALPN: offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.0 (IN), TLS handshake, Certificate (11):
* TLSv1.0 (IN), TLS handshake, Server key exchange (12):
* TLSv1.0 (OUT), TLS alert, handshake failure (552):
* OpenSSL/3.0.15: error:0A00018A:SSL routines::dh key too small
* Closing connection 0
curl: (35) OpenSSL/3.0.15: error:0A00018A:SSL routines::dh key too small

原因是服务器比较老,SSL 协议中使用了较短的 dh key。 而客户端的 openssl 版本较新,默认的安全级别高,当握手时,发现对方的服务器使用了 短的 dh key,就拒绝进一步连接,认为该服务器是不安全的。
然而,现存有大量这样的服务器。由于无法更改服务器的配置,因此不得不降低客户端openssl的安全策略。
 

通常的解决办法( openSSL 3.0 以下)

这个情况实际上已经出现很多年了,大部分的解决方案是修改 openssl 的配置文件 openssl.cnf

将 openssl_conf 修改如下

openssl_conf = default_conf

 并在 文件最后添加下面

[default_conf]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1.2
CipherString = DEFAULT@SECLEVEL=1

更详细的解释可参考
https://askubuntu.com/questions/1233186/ubuntu-20-04-how-to-set-lower-ssl-security-level 

新的解决办法( openSSL 3.0 及以上)

然而,对于 OpenSSL 3.0 以上的系统,例如 Debian 12 自带的是 openSSL 3.0.15, 则老的解决办法就不灵了。需要用另外一种方式。与老的方法差别体现在 【system_default_sect】段的定义

[system_default_sect]
CipherString = 'DEFAULT:!DH'
核心要义是 CipherString = 'DEFAULT:!DH'

问题解决后的效果

$ curl -v --insecure  https://some_web_site
*   Trying 175.21.4.7:443...
* Connected to some_web_site (175.21.4.7) port 443 (#0)
* ALPN: offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.0 (IN), TLS handshake, Certificate (11):
* TLSv1.0 (IN), TLS handshake, Server finished (14):
* TLSv1.0 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.0 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.0 (OUT), TLS handshake, Finished (20):
* TLSv1.0 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1 / AES256-SHA
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: CN=some_web_site
*  start date: Jul 27 09:38:07 2022 GMT
*  expire date: Jul 24 09:38:07 2032 GMT
*  issuer: CN=some_web_site
*  SSL certificate verify result: self-signed certificate (18), continuing anyway.
* using HTTP/1.x
> GET / HTTP/1.1
> Host: some_web_site
> User-Agent: curl/7.88.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Thu, 20 Mar 2025 15:15:20 GMT
< Server: Apache
< Last-Modified: Mon, 25 Jul 2011 04:02:56 GMT
< ETag: "18b-4a8dce3dc9c00"
< Accept-Ranges: bytes
< Content-Length: 395
< Content-Type: text/html
< 
<!DOCTYPE html
  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="0;URL=svn/" http-equiv="refresh"/>
<title>VisualSVN Server</title>
</head>
<body>
<h1>Welcome to VisualSVN Server!</h1>
<p><a href="/svn/">Repositories</a></p>
</body>
</html>
* Connection #0 to host some_web_site left intact

受影响的范围

这个问题影响到通过 https:// 对外提供服务的各种老的应用。例如: 通过 https 的方式对外服务的 svn 或者 gitLab 服务。 如果服务器上的 openssl 安全设置配置较低,则会出现这个问题。但是,svn, git 等客户端的报错不一定会出现 “dh key too small” 的字样。可能是笼统的提示 SSL communication 错误。此时,通过 curl 命令,能够比较清晰的显示这个错误内容,如本文最前面所示。

关于这个问题的详细解释请参考:
S3 Connection Error `dh key too small` in Ubuntu 20.04 ($1058) · Snippets · GitLab


http://www.kler.cn/a/596278.html

相关文章:

  • [AI建模] 使用Pinokio本地化部署混元2D到3D AI建模服务
  • [极客大挑战 2019]Knife——3.20BUUCTF练习day4(2)
  • 田间机器人幼苗视觉检测与护苗施肥装置研究(大纲)
  • 如何在 Flutter 中使用 WebRTC
  • Linux系统中安装各种常用中间件
  • 在QT中进行控件提升操作
  • gitlab-ci.yml文件详解
  • 【C++网络编程】第2篇:简单的TCP服务器与客户端
  • 域名如何绑定服务
  • JetsonNano —— 4、Windows下对JetsonNano板卡烧录刷机Ubuntu20.04版本(官方教程)
  • 【2025】基于springboot+vue的陪玩服务预约系统(源码、万字文档、图文修改、调试答疑)
  • 禁用Git状态标记
  • 修改HuggingFace模型默认缓存路径
  • 【yolo】使用 Netron 可视化深度学习模型:从 YOLOv1 到 YOLOv8 的探索
  • 【css酷炫效果】纯CSS实现球形阴影效果
  • 基于springbo校园安全管理系统(源码+lw+部署文档+讲解),源码可白嫖!
  • IoTDB日志提示Too many open files
  • mac环境下chatwoot客服聊天docker本地部署+对接通义千问Qwen2.5
  • C++代码2-多目标算法求解车辆路径规划
  • 使用PlotNeuralNet绘制ResNet50模型