`curl` 如何在 macOS 中访问 SSL 证书?

Sea*_*mus 2 curl https macos

我使用的是 macOS 10.15.5 的 Macbook。我有 MacPorts,但我使用的是curl.

% curl --version
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
Run Code Online (Sandbox Code Playgroud)

当我尝试 d/l 最新的时youtube-dl,我收到证书错误:

% sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     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.
Run Code Online (Sandbox Code Playgroud)

我确实查看了“上述网页”,但没有找到解决方案。GitHub 上的 youtube-dl 维护者坚称他们的证书是有效的且是最新的。他们提供这份文件作为“答案”,但我发现其中没有任何用处。curl能够毫无问题地下载其他 SSL 网页,因此我认为该问题是该证书/网站所特有的。

我从来没有遇到过这个问题。我有一台装有 Mojave 的旧 Macbook - 我已更新或重新安装youtube-dl好几次,没有出现任何问题,但现在也失败了。不过,我可以在我的 Ubuntu Linux 机器上运行相同的curl命令,而且效果很好。我不得不猜测这意味着两台 Mac 都“缺少了一些东西”——Mojave Mac 曾经拥有但已被删除的东西。

我需要对 Mac 执行什么操作才能curl处理 SSL 证书?

noh*_*ide 5

根据https://curl.haxx.se/mail/lib-2020-06/0010.html,这似乎是过期证书和 LibreSSl 的问题。可能的解决方法是

  • 使用curl -k在受影响的网站上但这会禁用证书检查,因此存在一些风险
  • (卡特琳娜上)套装CURL_SSL_BACKEND=secure-transport
  • (在所有 macOS 版本上)运行brew install curl并设置 PATH 以使用以下命令获取自制版本export PATH="/usr/local/opt/curl/bin:$PATH"

PS:您还可以尝试按照https://curl.haxx.se/docs/caextract.html上的说明加载新证书,但即使加载后我也遇到相同的错误。

PPS: https: //security.stackexchange.com/questions/232445/https-connection-to-specific-sites-fail-with-curl-on-macos对此有更多内容,包括替代解决方案,例如AddTrust/etc/ssl/cert.pem