描述
在archlinux下,希望使用curl產生一條使用sslv3的https訪問請求。
使用curl的如下命令:
curl -k -vvv --sslv3 https://192.168.7.9:8080
然而很遺憾,因為sslv3太老了,所以它不支持,
╰─>$ curl -k -vvv --sslv3 https://192.168.7.9:8080 * Trying 192.168.7.9:8080... * TCP_NODELAY set * Connected to 192.168.7.9 (192.168.7.9) port 8080 (#0) * OpenSSL was built without SSLv3 support * Closing connection 0 curl: (4) OpenSSL was built without SSLv3 support
根據提示,是openssl不支持。用openssl自身提供的工具進行驗證,果然是不支持的,連這個參數也沒有。
╰─>$ openssl s_client -ssl3 -connect t9:5000 -CAfile ~/Keys/https/root/root.cer -servername test3.www.local s_client: Option unknown option -ssl3 s_client: Use -help for summary.
man openssl s_client可以看到,這個選項是依賴編譯時的。
-ssl3, -tls1, -tls1_1, -tls1_2, -tls1_3, -no_ssl3, -no_tls1, -no_tls1_1, -no_tls1_2, -no_tls1_3 These options require or disable the use of the specified SSL or TLS protocols. By default s_client will negotiate the highest mutually supported protocol version. When a specific TLS version is required, only that version will be offered to and accepted from the server. Note that not all protocols and flags may be available, depending on how OpenSSL was built.
重編openssl
一
openssl在默認的編譯選項里關閉了SSLv3,只需要增加如下的編譯選項,即可完成支持SSLv3的重新編譯:
enable-ssl3. (enable-ssl3-method 是干嘛的???)
./Configure enable-ssl3 enable-ssl3-method linux-x86_64
二 archlinux 打包
我的openssl是包管理的,為了方便版本管理,我需要打個包。
a, 首先去下載源包的打包腳本, https://git.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/openssl
-rw-r--r-- PKGBUILD
-rw-r--r-- ca-dir.patch
修改PKGBUILD
╰─>$ diff PKGBUILD.org PKGBUILD 7c7 < pkgrel=1 --- > pkgrel=2 15c15 < source=("https://www.openssl.org/source/${pkgname}-${_ver}.tar.gz"{,.asc} --- > source=("${pkgname}-${_ver}.tar.gz" 35c34 < shared no-ssl3-method enable-ec_nistp_64_gcc_128 linux-x86_64 \ --- > shared enable-ssl3 enable-ssl3-method enable-ec_nistp_64_gcc_128 linux-x86_64 \
改了,版本號,文件路徑,編譯選項。
b 把一份源碼帶包到當前目錄 openssl-1.1.1d.tar.gz, 然后運行makepkg命令生效安裝包 openssl-1.1.1.d-2-x86_64.pkg.tar.xz
c 安裝新的包,替換官方包
sudo pacman -U openssl-1.1.1.d-2-x86_64.pkg.tar.xz
三 測試
更新之后,使用前文的curl和openssl命令分別測試,openssl s_client已經支持了sslv3,但是curl仍然不支持。
╰─>$ openssl s_client -ssl3 -connect t9:5000 -CAfile ~/Keys/https/root/root.cer -servername test3.www.local
CONNECTED(00000003) 140060394198272:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert ... SSL-Session: Protocol : SSLv3 ...
握手雖然失敗,但那是server的問題。
重新編譯 curl
在github下載最新的curl代碼。使用如下命令重新編譯,
這里需要注意的是:一,編譯選項已經默認使用ssl。二,在archlinux下openssl不區分開發包和運行包,所以編譯過程中curl
會默認的使用系統路徑下的openssl進行鏈接,也就是上文中我們剛剛修改過的。
bash-5.0$ ./buildconf bash-5.0$ ./configure bash-5.0$ make
另外, 提一點關於autoconf的迷思,如果沒有buildconf命令的話,需要先后執行如下的命令,以替代之:
bash-5.0$ aclocal bash-5.0$ autoheader bash-5.0$ autoconf bash-5.0$ automake
最后
最后生出來的curl是靜態鏈接的,與計划有點差距。(當然變成動態的也不難,不過那不是我們所關心的。)
╰─>$ ldd src/curl not a dynamic executable
總之,現在可以sslv3了
─>$ ./src/curl -k -vvv --sslv3 https://192.168.7.9:8080 * Trying 192.168.7.9:8080... * TCP_NODELAY set * Connected to 192.168.7.9 (192.168.7.9) port 8080 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none * SSLv3 (OUT), TLS handshake, Client hello (1): * SSLv3 (IN), TLS alert, handshake failure (552): * error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure * Closing connection 0 curl: (35) error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure