【问题标题】:SSL certificate problem: certificate has expire in macOSSSL 证书问题:macOS 中的证书已过期
【发布时间】:2021-10-11 06:36:49
【问题描述】:

当我使用这个命令拉取代码时:

➜  rt-analysis-multibranch_zhuolian git:(zhuolian) git pull
fatal: unable to access 'https://gitlab.example.com/development/soa-report-analysis.git/': SSL certificate problem: certificate has expired

我确定证书没有过期,因为在其他 macOS PC 上我可以从同一个 url 中提取代码。服务器端证书由 Let's Encrypt 生成。 macOS Catalina openssl 版本为:

➜  ~ openssl version
LibreSSL 2.6.5

我尝试使用 curl,错误如下:

➜  rt-analysis-multibranch_zhuolian git:(zhuolian) curl https://gitlab.example.com/development/soa-report-analysis.git
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
HTTPS-proxy has similar options --proxy-cacert and --proxy-insecure.

为什么会这样?我应该怎么做才能解决它?我可以使用相同的 url 从 Google Chrome 浏览器访问 repo。

我最后发现我上次更新 let's encrypt 证书时默认使用 ISRG Root X1 根证书。 ISRG Root X1 仅与 macOS 10.12.1 兼容。但是为什么 curl 命令似乎验证了旧证书。为什么会这样?

【问题讨论】:

  • 实际服务器(不是 example.com)是否使用带有 LE 的“兼容性”链的 LetsEncrypt 证书?你的 curl 和 git 是否使用低于 3.2.7 或 3.3.5 的 OpenSSL 1.0.2 或 LibreSSL(我认为后者更可能在 Mac 上)并且他们是否使用包含 DST X3 根证书的 CA 文件(又名包) (除了 ISRG X1 根证书)?如果是这样,那是您的问题,您需要更改服务器的证书链(如果您控制它),使用新的(er)SSL 库更新到软件,或者更新或修改 CA 文件?
  • 我粘贴了所有我知道的版本信息,我不确定服务器端证书是否是 LE 的“兼容性”链。 @dave_thompson_085 我应该如何处理我的服务器端证书?
  • 如果您执行或知道证书颁发:如果使用 certbot 而不指定特定链,则默认为“兼容性”链,因为 LE 认为这是个好主意。对于 certbot 以外的任何内容,您都必须提供详细信息。如果您不知道发行,但服务器正在使用 PEM 格式文件,请查看它们的内容,它们可能已经识别了主题和发行者,否则将每个 PEM 块放在单独的文件中并执行openssl x509 -in <onecert -noout -subject -issuer.如果它们采用其他格式,您需要提供详细信息。 ...
  • ... 如果您无权访问服务器文件或无法解码它们,请执行openssl s_client -connect theserver:443 -servername theserver -showcerts </dev/null 并捕获输出;它将包含几个 PEM 块。将彼此放在一个单独的文件中,然后像上面一样继续。在任何一种情况下,如果最后一个证书(PEM 块)的颁发者带有CN=DST Root CA X3,那就是兼容性链。要更改它,如果使用 certbot,您可以使用 --preferred-chain 'ISRG Root X1' 进行更新。否则,根据文件格式,您可以编辑它们;详细说明。 ...
  • ... 或者,正如我所说,您可以从 client 信任库中删除 DST。运行curl -v any_https_url 将显示它正在使用的 CA 文件;你可以修改它,或者如果它是一个系统文件,你不能或不想修改,复制它,修改副本,然后使用curl --cacert your_fixed_file。但是,我不知道git 是否与curl 使用相同,因此您可能需要更多来解决您的实际问题。

标签: https


【解决方案1】:

thisAsk Different的回答,无耻转帖如下:

macOS 上的 OpenSSL 不使用系统钥匙串(这很有意义,因为它是一个跨平台库),而是有自己的 .pem 文件,其中包含其根证书。即使我的系统使用自制软件和/或 MacPorts 安装了较新版本的 OpenSSL,位于 /etc/ssl/cert.pem 的系统范围的 OpenSSL pem 文件也已过期,并且不包含 ISRG Root X1 证书。

解决办法:

  1. /etc/ssl/cert.pem 重命名为其他名称。 (我建议/etc/ssl/cert.pem.org
  2. https://curl.se/docs/caextract.html下载最新的cacert.pem
  3. 重命名为cert.pem
  4. 复制到/etc/ssl/cert.pem

现在curl 和任何其他使用 OpenSSL 的应用程序都可以访问使用当前 Let's Encrypt 证书签名的网站。

或者,MacPorts 包 curl-ca-bundle 安装一个包含 ISRG Root X1 到 /opt/local/etc/openssl/cert.pem.pem 文件,该文件也可以使用。

其他可能的解决方案:

  • 手动将 ISRG Root X1 证书添加到 /etc/ssl/cert.pem
  • 将 OpenSSL 配置为对其根证书使用不同的 .pem 文件,例如 /opt/local/etc/openssl/cert.pem

(另一种可能的解决方案是使用 curl 的 -k/--insecure 标志。

【讨论】:

    猜你喜欢
    • 2020-09-18
    • 2019-12-11
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 2020-05-18
    • 2022-01-11
    • 2019-12-11
    相关资源
    最近更新 更多