![我可以让 curl(或 wget)忽略特定的 TLS 错误吗?(绕过过期的证书而不禁用证书验证)](https://linux22.com/image/762952/%E6%88%91%E5%8F%AF%E4%BB%A5%E8%AE%A9%20curl%EF%BC%88%E6%88%96%20wget%EF%BC%89%E5%BF%BD%E7%95%A5%E7%89%B9%E5%AE%9A%E7%9A%84%20TLS%20%E9%94%99%E8%AF%AF%E5%90%97%EF%BC%9F%EF%BC%88%E7%BB%95%E8%BF%87%E8%BF%87%E6%9C%9F%E7%9A%84%E8%AF%81%E4%B9%A6%E8%80%8C%E4%B8%8D%E7%A6%81%E7%94%A8%E8%AF%81%E4%B9%A6%E9%AA%8C%E8%AF%81%EF%BC%89.png)
我正在编写一个依赖于我无法控制的远程 API 端点的脚本。
今天,我的脚本停止工作了,因为终端的 SSL 证书今天已过期,但他们还没有修复它。运行后curl -v
,我得到了以下输出:
wug@server:~$ curl -v -G -m5 [redacted]
* Connecting to hostname: 10.12.112.1
* Trying 10.12.112.1:19999...
* TCP_NODELAY set
* Connected to 10.12.112.1 (10.12.112.1) port 19999 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /[redact]/ca.rsa.4096.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (OUT), TLS alert, certificate expired (557):
* SSL certificate problem: certificate has expired
* Closing connection 0
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
我对此很恼火,但这超出了我的控制范围。这里需要考虑安全性,所以我不想禁用所有 TLS 验证curl -k
。理想情况下,我会传递一个参数,指示 curl 有选择地忽略有关过期证书的错误(似乎是 TLS 1.3 错误 557)。可以这样做吗?如果不行,可以wget
做到吗?
答案1
我没有找到有选择地忽略有关证书过期的错误的方法。
使用服务器证书的哈希值可能会有所帮助--pinnedpubkey
。缺点是,显然,每当服务器证书更新时,您都必须更改哈希值。
如果哈希值正确,我不太确定会发生什么,但当证书过期时。就我的用例而言,事实证明可以--pinnedpubkey
结合--insecure
没有 --insecure
覆盖--pinnedpubkey
设置,但我不知道这是否是可能随着 curl 版本而改变的保证行为。