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](https://git.rwth-aachen.de/-/snippets/1058 "S3 Connection Error `dh key too small` in Ubuntu 20.04 (1058) · Snippets · GitLab ")

相关推荐
m0_7461771927 分钟前
小白畅通Linux之旅-----Linux日志管理
linux·运维·服务器
菜菜笔记2 小时前
Ubuntu 挂载新盘
linux·运维·ubuntu
慌糖3 小时前
Ubuntu安装Docker命令清单(以20.04为例)
linux·ubuntu·docker
zhangzhiwei-zzw3 小时前
Linux下使用nmcli连接网络
linux·网络·chrome
枫叶落雨2223 小时前
Git 使用规范指南
git
ZZH1120KQ4 小时前
Linux账号和权限管理
linux·运维
chilx4 小时前
高效易用的 MAC 版 SVN 客户端:macSvn 使用体验
svn
XMAIPC_Robot4 小时前
基于 ZYNQ UltraScale+ OV5640的高速图像传输系统设计,支持国产替代
linux·数码相机·fpga开发·架构·边缘计算
水水沝淼㵘4 小时前
嵌入式开发学习日志(linux系统编程--系统编程之 进程间通信IPC)Day32
linux·运维·学习
IT小饕餮4 小时前
linux登陆硬件检测脚本
linux·运维·服务器