【问题标题】:How to compile Curl with legacy SSL support on Ubuntu?如何在 Ubuntu 上使用旧版 SSL 支持编译 Curl?
【发布时间】:2019-05-30 11:12:38
【问题描述】:

我在尝试使用 Curl 连接到启用 HTTPS 的旧网站时遇到以下错误:

curl https://10.11.1.44
curl: (35) error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol

更详细:

* Expire in 0 ms for 6 (transfer 0x55a4192abdd0)
*   Trying 10.11.1.44...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55a4192abdd0)
* Connected to 10.11.1.44 (10.11.1.44) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (OUT), TLS alert, protocol version (582):
* error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol
* Closing connection 0
curl: (35) error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol

如果我尝试使用 --ssl2--ssl3 选项,我会收到以下错误:

root@kali:~# curl https://10.11.1.44/ --sslv2
curl: (4) OpenSSL was built without SSLv2 support
root@kali:~# curl https://10.11.1.44/ --sslv3
curl: (4) OpenSSL was built without SSLv3 support

我已经查阅了以下页面,了解如何使用 SSL2/3 支持构建 Curl,但我不确定如何启用它?

https://curl.haxx.se/docs/install.html

有什么想法吗?

【问题讨论】:

  • 这里的明智解决方案是升级 10.11.1.44 的服务器以支持 TLS,而不是降级 curl 以支持 SSL,如果可能的话,您应该这样做。不过,如果这不可行,请阅读下面的答案(我这样做的个人借口是,对戴尔 DRAC 固件进行逆向工程以将 DRAC Web 服务器更改为古老的服务器 x.x 是不可行的)

标签: curl ubuntu-18.04


【解决方案1】:

更新:curl dropped support for --sslv2 / sslv3 在 curl 版本 7.76.1 发布后的某个时间,因此您必须确保还编译 curl 版本 7.76.1 或更早版本。已更新说明以确保生成 curl 7.76.1。 (感谢Matias Barros的更新)

你需要从源代码编译 curl 和你的 ssl 后端,显然你需要一个 C 编译器,可能还有更多的东西,但不知道什么,希望这应该涵盖它:

sudo apt-get install gcc build-essential make cmake autoconf git automake libtool

这可能可以通过几个 ssl 后端来完成,但由于我最熟悉 OpenSSL,我将继续使用 OpenSSL,以构建 openssl 转到位于 https://github.com/openssl/openssl 的 openssl 存储库并找到合适的 openssl 版本,在这个例子我选择了版本1.1.1k(这是最新的稳定的openssl版本),

git clone -b 'OpenSSL_1_1_1k' --single-branch --depth 1 https://github.com/openssl/openssl
cd openssl
./config no-shared enable-ssl2 enable-ssl3 enable-ssl3-method
make -j $(nproc)

(最后一步可能需要一段时间)但是openSSL的构建脚本不会创建lib文件夹,但是curl的构建脚本期望lib文件在openssl文件夹内的lib文件夹中,所以在make之后,运行

mkdir lib
cp *.a lib;

一旦完成,就该做 curl 了,所以 cd .. 离开那里并克隆 the last version of curl supporting the --sslv2 / --sslv3 switches 7.76.1

git clone -b 'curl-7_76_1' --single-branch --depth 1 https://github.com/curl/curl.git
cd curl
./buildconf
LDFLAGS="-static" ./configure --with-ssl=$(realpath ../openssl) --disable-shared  --enable-static
make -j $(nproc)

(如果您想知道我为什么使用 realpath:curl 的构建脚本中似乎存在一个错误,如果您提供相对路径,它会使其失败,因此似乎需要绝对路径。如果您想知道为什么我制作了一个静态build aka --disable-shared --enable-static,您的 $PATH 中可能有不同的 libopenssl 库,因此为避免与 ubuntu 的内置 libopenssl 冲突,静态构建更安全。)

最后,

/temp2/curl# ./src/curl --sslv3 https://google.com
curl: (35) error:1409442E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version

(因为https://google.com 根本不再支持 sslv3。)

TL;DR

git clone -b 'OpenSSL_1_1_1k' --single-branch --depth 1 https://github.com/openssl/openssl
cd openssl
./config no-shared enable-ssl2 enable-ssl3 enable-ssl3-method
make -j $(nproc)
mkdir lib
cp *.a lib;
cd ..
git clone -b 'curl-7_76_1' --single-branch --depth 1 https://github.com/curl/curl.git
cd curl
./buildconf
LDFLAGS="-static" ./configure --with-ssl=$(realpath ../openssl) --disable-shared  --enable-static
make -j $(nproc)
./src/curl --sslv3 https://google.com

【讨论】:

  • 请注意,在 Alpine 上构建所需的软件包是:apk add git autoconf automake libtool make cmake binutils gcc g++ linux-headers
【解决方案2】:

错误“protocol version (582)”表示服务器最大支持TLSv1.0

TLSv1.0 为 deprecated 并在最新发行版(例如 Ubuntu 19+、Debian Buster+)中被禁用。

指定 --tlsv1.0 curl 参数将无济于事,因为 OpenSSL 中禁用了协议。

要么升级你正在连接的服务器(首选),

...或在/etc/openssl.cnf 中启用TLSv1.0

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

改成

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

注意:SECLEVEL=1 启用 SHA-1 并允许 RSA 密钥小于 2048 位(可能需要连接到旧服务器)。

(无需重新编译任何东西)

【讨论】:

  • 默认情况下,SSLv3 支持不再使用 OpenSSL 编译,它需要特殊的编译时标志才能启用,我刚刚检查了与 Xubuntu 20.04 捆绑的 openssl,它没有使用 SSLv3 支持编译(最低的是 TLS1.0),所以如果你需要 sslv3 或 v2,你必须从源代码编译 openssl,而不仅仅是配置与 Ubuntu 捆绑的那个
猜你喜欢
  • 2012-07-07
  • 1970-01-01
  • 2020-09-22
  • 2017-01-16
  • 2019-09-12
  • 2016-04-13
  • 2016-12-18
  • 2015-07-12
  • 2021-07-05
相关资源
最近更新 更多