像
curl
和 wget
这样的命令会出现以下错误:curl: (35) error:0A000152:SSL routines::unsafe legacy renegotiation disabled
。我正在使用 WSL2 Ubuntu 并在公司防火墙上。我确实将受信任的根 ca 证书导出到 WSL 并更新了证书。然而,在下载 Jenkins、Terraform 等工具时仍然面临这个问题。例如尝试获取 Jenkins 时。
curl -fsSL http://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jen
kins-keyring.asc > /dev/null
curl: (35) error:0A000152:SSL routines::unsafe legacy renegotiation disabled
我使用的是公司 VPN。没有 VPN 命令可以正常工作,但是使用公司网络上的 VPN 时我会收到这些错误。如果我与固件团队一起进行 SSL 绕过,它就会起作用。不确定这里是否还有其他问题。
sudo vim /etc/ssl/openssl.cnf
`#
# OpenSSL example configuration file.
# See doc/man5/config.pod for more info.
#
# This is mostly being used for generation of certificate requests,
# but may be used for auto loading of providers
# Note that you can include other files from the main configuration
# file using the .include directive.
#.include filename
# This definition stops the following lines choking if HOME isn't
# defined.
HOME = .
# Use this in order to automatically load providers.
openssl_conf = openssl_init
# Comment out the next line to ignore configuration errors
config_diagnostics = 1
# Extra OBJECT IDENTIFIER info:
# oid_file = $ENV::HOME/.oid
oid_section = new_oids
# To use this configuration file with the "-extfile" option of the
# "openssl x509" utility, name here the section containing the
# X.509v3 extensions to use:
# extensions =
# (Alternatively, use a configuration file that has only
# X.509v3 extensions in its main [= default] section.)
[ new_oids ]
# We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
"/etc/ssl/openssl.cnf" 397L, 12419B `
此错误是由于远程服务器不支持 RFC5746 安全重新协商(或者您的公司防火墙不支持)引起的。在 OpenSSL 1.1.1 中设置了标志
SSL_OP_LEGACY_SERVER_CONNECT
,但 OpenSSL 3 中并非如此,来自 迁移指南:
现在默认情况下 TLS 连接需要安全重新协商 现在默认情况下需要支持 RFC 5746 安全重新协商才能成功实现 SSL 或 TLS 连接。需要能够连接到旧版对等点的应用程序需要显式设置 SSL_OP_LEGACY_SERVER_CONNECT。因此,SSL_OP_LEGACY_SERVER_CONNECT 不再设置为 SSL_OP_ALL 的一部分。
可以通过在 OpenSSL conf 中设置它来再次打开此标志,这是一个名为
UnsafeLegacyServerConnect
的选项:
UnsafeLegacyServerConnect:仅允许 OpenSSL 客户端使用不安全的旧版重新协商。相当于 SSL_OP_LEGACY_SERVER_CONNECT。
来源:https://www.openssl.org/docs/man3.0/man3/SSL_CONF_cmd.html
具有此设置的最小 OpenSSL 配置:
openssl_conf = openssl_init
[openssl_init]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
Options = UnsafeLegacyServerConnect
您也可以将
Options = UnsafeLegacyServerConnect
添加到 /etc/ssl/openssl.cnf
下现有的 [system_default_sect]
。
注意。在 OpenSSL 中< 3.0.4 有一个错误忽略了
UnsafeLegacyServerConnect
选项。如果您被 <= 3.0.3, you could use (the more unsafe) UnsafeLegacyRenegotiation
困住了。
如果您不想对系统进行永久更改,您可以尝试在内存中运行配置,如下所示:
OPENSSL_CONF=<(cat /etc/ssl/openssl.cnf ; echo Options = UnsafeLegacyRenegotiation) curl https://something.com/
展开形式:
OPENSSL_CONF=<(
cat /etc/ssl/openssl.cnf
echo Options = UnsafeLegacyRenegotiation
) curl https://something.com/
让我解释一下它的作用。
这部分将为以下命令临时设置一个环境变量。大多数与 SSL 库链接的程序都会识别此变量并使用指示的配置文件:
OPENSSL_CONF="value" command
顺便说一句,我尝试使用 OPENSSL_CONF_INCLUDE 变量,但那个不起作用。
但是我没有使用真实的文件,而是使用这个 bash 构造
<( ... )
,它创建一个临时虚拟文件,其内容是内部命令的输出:
OPENSSL_CONF=<( ... )
内部部分仅打印当前的openssl.cnf文件,后面是所需的配置行:
cat /etc/ssl/openssl.cnf ; echo Options = UnsafeLegacyRenegotiation
总而言之,我们使用添加我们所需行的配置来运行curl。
它在 WSL 的 Ubuntu 中对我有用。