Debian 版本更改影响使用 curl 和 HTTPS 的脚本

Debian 版本更改影响使用 curl 和 HTTPS 的脚本

最近我开始使用 Debian 9(9.4,来自 Debian 8.x),涉及 curl 的脚本停止工作。我通过连接到父代理的本地主机上的 squid 代理连接到互联网。

我的环境变量配置如下

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

非常感谢 Michael Hampton(见评论)。结果发现问题出在代理配置上。应该说

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

因此 curl 尝试使用 TLS 连接到 squid,但当然失败了。

相关内容