如何强制较旧的 debian 忘记 DST Root CA X3 过期并使用 ISRG Root X1 - SSL 证书问题:证书已过期

How to force older debian to forget about DST Root CA X3 Expiration and use ISRG Root X1 - SSL certificate problem: certificate has expired

这与DST Root CA X3 Expiration (September 2021)
有关 当在线搜索修复程序以应用于旧服务器(在我的例子中是 Debian 8)时,它确实调用了使用 curl 的 letsencrypt 加密的站点,它们现在似乎失败并显示以下消息:

示例:

curl -fsSL https://deb.nodesource.com/setup_14.x | bash -

静静地失败,然后手动尝试并删除静默标志和 bash 管道,如下所示:

curl -L https://deb.nodesource.com/setup_14.x
curl: (60) SSL certificate problem: certificate has expired
More details here: http://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.

尝试以下命令无法解决问题:

apt update
apt install -y ca-certificates openssl
update-ca-certificates

我能做什么!? (回答我自己的问题)⬇️

免责声明;我不是安全专家(我知道事情,但你知道)。在应用此处共享的任何修复程序之前,请确保您了解自己所做的事情

通过升级您的实例来修复

升级您的实例。在 debian 9 或更高版本上不会发生此问题。

在下面的示例中,我在基于 Debian 8(可以认为是旧版本)的 ruby:2.4.1 docker 映像上遇到了这个问题。升级到更新的 docker 映像可修复此问题。升级到更新的 Debian 版本应该也能解决这个问题。

我确认在使用基于 Debian 11 的 ruby:2.7.0 docker 映像时不会发生这种情况,如下所示:

docker run --rm -it ruby:2.7.4 bash -c "cat /etc/issue"
Debian GNU/Linux 11 \n \l

通过从 /etc/ca-certificates.conf

评论 DST_Root_CA_X3.crt 修复 Debian 8

即使 ISRG Root X1 存在,如果 DST Root CA X3 仍然存在并在使用中,其验证似乎首先发生,所以我们可以通过这样做来摆脱它:

  1. 安装ca-certificates
  2. 评论 /mozilla/DST_Root_CA_X3.crt 来自 /etc/ca-certificates.conf
  3. 确保 /usr/share/ca-certificates/mozilla/ISRG_Root_X1.crt 存在(应该存在)
  4. update-ca-certificates
  5. 更新 ca 证书

直接在您的实例上举例

cat /etc/issue
Debian GNU/Linux 8 \n \l
sudo apt install -y ca-certificates
sudo sed -i '/^mozilla\/DST_Root_CA_X3.crt$/ s/^/!/' /etc/ca-certificates.conf
sudo update-ca-certificates

示例Dockerfile

FROM ruby:2.4.1 # uses debian 8

RUN apt update -qq \
    && apt install -y ca-certificates \
    && sed -i '/^mozilla\/DST_Root_CA_X3.crt$/ s/^/!/' /etc/ca-certificates.conf \
    && update-ca-certificates \
    && rm -rf /var/lib/apt/lists/*

使用 dpkg-reconfigure ca-certificates 修复

如评论中所述,您还可以在实例上使用以下命令以交互方式修复此问题(需要安装 ca-certificates 包):

dpkg-reconfigure ca-certificates

然后从列表中禁用 mozilla/DST_Root_CA_X3.crt

结论

如果您想了解更多信息,您应该阅读 Scott Helme's post: Let's Encrypt's Root Certificate is expiring!

您现在可以 curl 使用这些安全眼镜安全地加密站点:

不清楚您的 Debian 有多“旧”。

拥有最新的 Linux OS 不会导致此问题。 在将您的发行版升级到最新版本之前考虑一切!

以下适用于我的旧版 Debian 和 Ubuntu 系统。

澄清问题是关于“cacert-bundle”的 CA Root X3 证书部分。 从今天开始,可以在这里找到“cacert-bundle”:https://curl.se/docs/caextract.html 作为捆绑包的一部分 https://curl.se/ca/cacert.pem.

过期的证书是:

Certificate:
    Data:
    Version: 3 (0x2)
    Serial Number:
    44:af:b0:80:d6:a3:27:ba:89:30:39:86:2e:f8:40:6b
    Signature Algorithm: sha1WithRSAEncryption
    Issuer: O=Digital Signature Trust Co., CN=DST Root CA X3
Validity
    Not Before: Sep 30 21:12:19 2000 GMT
    Not After : Sep 30 14:01:15 2021 GMT
    Subject: O=Digital Signature Trust Co., CN=DST Root CA X3
    Subject Public Key Info:
    Public Key Algorithm: rsaEncryption
    Public-Key: (2048 bit)

用于使用 Let's Encrypt 颁发的证书验证对网站的 curl 调用中的对等点。

查找 CURL 使用的 CA 证书包:

strace curl https://www.google.com |& grep open 

结果:

root@debian:/tmp# strace curl https://www.google.com |& grep open
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/x86_64-linux-gnu/libcurl.so.4", O_RDONLY|O_CLOEXEC) = 3
...
...
open("/usr/lib/ssl/openssl.cnf", O_RDONLY) = 3
open("/etc/ssl/certs/ca-certificates.crt", O_RDONLY) = 4
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 4

接近尾声时,您应该会看到证书包。在这种情况下:/etc/ssl/certs/ca-certificates.crt

解决此问题的一个选项是替换该 CA 证书包,但这可能不是您的 OS 和其他受影响的应用程序和软件包(例如:php libcurl)的全局解决方案.

现在剖析根 CA 捆绑证书,使用:

openssl crl2pkcs7 -nocrl -certfile /etc/ssl/certs/ca-certificates.crt | openssl pkcs7 -print_certs -text -noout | grep "Not After"

注意:命令中的证书位置 (/etc/ssl/certs/ca-certificates.crt) 来自上面的“strace”步骤。

这将 return 包含捆绑包中所有根 CA 证书到期日期的长列表。

root@L36630:/tmp# openssl crl2pkcs7 -nocrl -certfile cacert.pem | openssl pkcs7 -print_certs -text -noout | grep "Not After"
        Not After : Sep 30 04:20:49 2023 GMT
        Not After : Sep 30 14:01:15 2021 GMT
        Not After : Sep 22 11:22:02 2030 GMT
        Not After : Sep 15 16:00:00 2025 GMT
        ...
        ...

在这种情况下,我们的过期证书是“不晚于:9 月 30 日 14:01:15 2021 GMT”。

您可以删除 | grep "Not After" 查看完整的解密列表。

这是对 cacert 包进行故障排除的分步方法。 如果将来发生这种情况,您知道该怎么做。

现在让我们开始解决问题。

修复

Let's Encrypt 最初使用的是“DST Root CA X3”CA Root 证书。 Let's encrypt 现在使用“ISRG Root X1”和“ISRG Root X2”作为根 CA,“Let's Encrypt R3”作为中间证书。

要解决此问题,您需要将 2 个新的根 CA 添加到您的服务器或设备:

中级证书(PEM 格式):

在 Linux:

上安装根 CA 证书

sudo mkdir /usr/local/share/ca-certificates/extra

sudo cp root.cert.pem /usr/local/share/ca-certificates/extra/root.cert.crt

sudo update-ca-certificates

NodeJS

Node.js 7.3.0(以及 LTS 版本 6.10.0 和 4.8.0)添加了 NODE_EXTRA_CA_CERTS 环境变量,供您传递 CA 证书文件。

$ export NODE_EXTRA_CA_CERTS=[custom Root CA certificate file path]

或者,您可以 blacklist/remove 来自 OS 的 CA 证书包的 DST 证书。

DEBIAN/UBUNTU

您可以使用 dpkg 在 Ubuntu/Debian 中重新配置。

sudo dpkg-reconfigure ca-certificates
  1. 您将看到带有“ca 证书配置”(ca-certificates configuration image 1) 的终端 window。 Select“是”以信任来自证书颁发机构的新证书。
  2. 按“确定”
  3. window 将关闭,在下一步中您将看到包含 CA 证书 (ca-certificates configuration image 1) 的实际列表。按名称“DST_Root_CA_X3.crt”找到证书,取消选中它并按“确定”。
  4. 现在您将看到“正在更新 /etc/ssl/certs 中的证书...”。等到进程完成。

下一步从终端重新测试您的 curl 调用。 您应该不会再看到 CURL 错误:

root@debian:/tmp# curl https://example.com
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.

另一种选择(Ubuntu/Debian):

CA 列表存储在文件 /etc/ca-certificates.conf 中。您可以手动编辑此文件并 运行:

sudo update-ca-certificates

自动化:

# Make sure the ca-certificates.conf location is correct 
sed '/DST_Root_CA_X3.crt/d' /etc/ca-certificates.conf > /tmp/cacerts.conf && mv /tmp/cacerts.conf /etc/ca-certificates.conf
update-ca-certificates

RHEL/CENTOS

在 RedHat 中将该证书添加到 ca-trust 黑名单:/etc/pki/ca-trust/source/blacklist

  1. 创建 dstrootca.pem 文件:

DST Root CA X3
==============
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/MSQwIgYDVQQK
ExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMTDkRTVCBSb290IENBIFgzMB4X
DTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVowPzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1
cmUgVHJ1c3QgQ28uMRcwFQYDVQQDEw5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBAN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmT
rE4Orz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEqOLl5CjH9
UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9bxiqKqy69cK3FCxolkHRy
xXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40d
utolucbY38EVAjqr2m7xPi71XAicPNaDaeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0T
AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQ
MA0GCSqGSIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69ikug
dB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXrAvHRAosZy5Q6XkjE
GB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZzR8srzJmwN0jP41ZL9c8PDHIyh8bw
RLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubS
fZGL+T0yjWW06XyxV3bqxbYoOb8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
-----END CERTIFICATE-----

  1. 将文件添加到您的黑名单位置:/etc/pki/ca-trust/source/blacklist

  2. 运行 sudo update-ca-trust

来源:https://www.openssl.org/blog/blog/2021/09/13/LetsEncryptRootCertExpire/

Let's Encrypt 正式文章:https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021/