Debian 版本更改影響使用curl 和 HTTPS 的腳本

Debian 版本更改影響使用curl 和 HTTPS 的腳本

最近,我開始使用 Debian 9(9.4,從 Debian 8.x 開始),一個涉及curl 的腳本停止運作。我透過連接到父代理的本機主機上的魷魚代理程式連接到網際網路。

我的環境變數是這樣配置的

root@server:~# printenv | grep -i proxy
HTTP_PROXY=http://127.0.0.1:3128
FTP_PROXY=http://127.0.0.1:3128
https_proxy=https://127.0.0.1:3128
http_proxy=http://127.0.0.1:3128
HTTPS_PROXY=https://127.0.0.1:3128
ftp_proxy=http://127.0.0.1:3128

當我使用 wget 時,它有效:

root@server:~# wget https://www.google.com.cu
--2018-03-14 09:08:53--  https://www.google.com.cu/
Connecting to 127.0.0.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html                  [ <=>                          ]  11.12K  --.-KB/s    in 0.001s

2018-03-14 09:08:54 (14.9 MB/s) - ‘index.html’ saved [11389]

當我使用curl時,這就是我得到的

root@server:~# curl -v https://www.google.com.cu
* Rebuilt URL to: https://www.google.com.cu/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to (nil) (127.0.0.1) port 3128 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection:     ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Curl_http_done: called premature == 0
* Closing connection 0
curl: (35) error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

我知道這兩個命令並不等同,這只是為了說明 HTTPS 傳輸問題。

我需要使用curl,因為腳本使用Web API,因此它需要使用POST而不是GET請求,並為POST請求設定一些標頭和資料。 (api.dropboxapi.com 是目標網站)

這一切過去都可以在 Debian 8 上順利運行,除了 wget 可以工作之外,只有curl 因 debian 版本更改而失敗。所有其他 HTTPS 用戶端似乎都不受影響(FF、Chrome、Edge、wget 似乎都像往常一樣工作)

有人知道這個問題嗎?是否有任何解決方法、修復、命令列選項更改或其他使 debian 9 版本的curl 工作的方法?

“curl -V”的輸出

root@server:~# curl -V
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.2l zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL

答案1

非常非常感謝邁克爾漢普頓(請參閱評論)。事實證明問題出在代理配置。應該說

https_proxy=http://127.0.0.1:3128
HTTPS_PROXY=http://127.0.0.1:3128

因此,curl 嘗試使用 TLS 連接到魷魚,當然失敗了。

相關內容