AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1075514
Accepted
BairDev
BairDev
Asked: 2021-08-25 07:06:34 +0800 CST2021-08-25 07:06:34 +0800 CST 2021-08-25 07:06:34 +0800 CST

如何使用letsencrypt / certbot修复证书链?

  • 772

我无法解决以下问题。使用 openssl 验证服务器证书失败,链不完整。

免责声明:我不是管理员,也没有过多地使用证书。

使用 OpenSSL 进行验证

$ openssl verify -CAfile /etc/letsencrypt/live/co2-avatar.com/fullchain.pem  /etc/letsencrypt/live/co2-avatar.com/cert.pem

# /etc/letsencrypt/live/co2-avatar.com/cert.pem: C = US, O = Internet Security Research Group, CN = ISRG Root X1
# error 2 at 2 depth lookup:unable to get issuer certificate

检查证书中的域之一

openssl s_client -connect co2avatar.org:443 -servername co2avatar.org
# CONNECTED(00000003)
# depth=0 CN = gitlab.sustainable-data-platform.org
# verify error:num=20:unable to get local issuer certificate
# verify return:1
# depth=0 CN = gitlab.sustainable-data-platform.org
# verify error:num=21:unable to verify the first certificate
# verify return:1
# ---
# Certificate chain
#  0 s:CN = gitlab.sustainable-data-platform.org
#    i:C = US, O = Let's Encrypt, CN = R3
# ---
# Server certificate
# -----BEGIN CERTIFICATE-----

或运行

curl -v https://co2avatar.org
# *   Trying 85.214.38.88:443...
# * TCP_NODELAY set
# * Connected to co2avatar.org (85.214.38.88) port 443 (#0)
# * ALPN, offering h2
# * ALPN, offering http/1.1
# * successfully set certificate verify locations:
# *   CAfile: /etc/ssl/certs/ca-certificates.crt
#   CApath: /etc/ssl/certs
# * TLSv1.3 (OUT), TLS handshake, Client hello (1):
# * TLSv1.3 (IN), TLS handshake, Server hello (2):
# * TLSv1.2 (IN), TLS handshake, Certificate (11):
# * TLSv1.2 (OUT), TLS alert, unknown CA (560):
# * SSL certificate problem: unable to get local issuer certificate
# * Closing connection 0
# curl: (60) SSL certificate problem: unable to get local issuer certificate

可能两者都有,我的 Apache VHost 中的域配置错误以及证书链本身的问题。我如何检查最后一个(我搜索了很多,但大多数点击是关于openssl verify或-CAfile关于不同的证书颁发者)?

我是否需要检查根证书包以及如何检查?

有没有类似certbot certonly的-addtrust标志?

ssl-certificate certbot lets-encrypt
  • 1 1 个回答
  • 9677 Views

1 个回答

  • Voted
  1. Best Answer
    Lutz Willek
    2021-08-25T08:02:14+08:002021-08-25T08:02:14+08:00

    尝试 openssl s_client 并让您显示证书。命令是:

    $ openssl s_client -connect co2avatar.org:443 -servername co2avatar.org -showcerts
    

    您会发现您的服务器返回一个证书CN = gitlab.sustainable-data-platform.org和一个主题备用名称,其中包括您的域DNS:co2-avatar.com。所以证书本身没问题。

    如果您想将所有内容组合到一个命令管道中以查看证书的内容:

    echo | openssl s_client -connect co2avatar.org:443 -servername co2avatar.org -showcerts 2>/dev/null |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -noout -text
    

    缺少的是中间证书。这也应该由服务器发送,但第一个命令显示它不存在 - 只有证书是由您的服务器发送的。

    所以失败的 openssl 是正确的,因为确实缺少中间证书。

    所以要解决它,你需要调整你的 apache 配置。这就是您的配置的样子:

    文件名应该类似于/etc/apache2/sites-enabled/co2-avatar.com-le-ssl.conf

    <IfModule mod_ssl.c>
    SSLStaplingCache shmcb:/var/run/apache2/stapling_cache(128000)
    <VirtualHost *:443>
            ServerName co2-avatar.com
            ServerAlias www.co2-avatar.com
    #... 
    #... insert your other stuff here...
    #...
    
    SSLCertificateFile /etc/letsencrypt/live/co2-avatar.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/co2-avatar.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLUseStapling on
    </VirtualHost>
    </IfModule>
    

    根据您的描述,我最好的猜测是您的配置中的以下行是错误的: SSLCertificateFile /etc/letsencrypt/live/co2-avatar.com/cert.pem. 它应该替换为SSLCertificateFile /etc/letsencrypt/live/co2-avatar.com/fullchain.pem, 以便也发送中间体。

    解决方案更新(讨论后)

    在讨论中发现,在这个 CentOS 服务器上使用的 openssl 和 Apache 版本只是旧的,所以一些特性是不受支持的。(Apache 2.4.6,OpenSSL 1.0.2k,中间配置,无 HSTS,无 OCSP)

    根据Mozilla SSL 配置生成器,在这种情况下可以使用以下通用配置:

    <VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile      /path/to/signed_certificate
        SSLCertificateChainFile /path/to/intermediate_certificate
        SSLCertificateKeyFile   /path/to/private_key
    </VirtualHost>
    

    转换为这种特定情况,生成的工作配置如下:

    <VirtualHost *:443>
        ServerName  sustainable-data-platform.org
        ServerAlias co2-avatar.com
        ServerAlias ... <include all other SAN names here>
        
        SSLEngine on
        SSLCertificateFile      /etc/letsencrypt/live/co2-avatar.com/cert.pem
        SSLCertificateChainFile /etc/letsencrypt/live/co2-avatar.com/fullchain.pem
        SSLCertificateKeyFile   /etc/letsencrypt/live/co2-avatar.com/privkey.pem
    
    </VirtualHost>
    

    作为此类旧装置的说明

    Cross-Signed Let's Encrypt R3 和 DST Root CA X3,中间证书和根证书将分别于 2021 年 9 月 29 日和 2021 年 9 月 30 日到期。所以自 2021 年 5 月 4 日起,新颁发的证书使用更长的链,并带有交叉签名的 ISRG Root X1 作为中间证书。

    不幸的是,由于证书路径的构建和验证方式,并非所有 TLS 实现都能成功验证交叉签名。OpenSSL 1.0.2 就是这种情况。因此,在使用 OpenSSL 的 RHEL/CentOS 7 上运行的程序可能无法验证新证书链或建立 TLS 连接。在此类平台上升级到较新的 Openssl 版本并不简单。

    有几个选项:在客户端更新信任库(删除 DST Root CA X3 根证书 - 一旦删除,影响应该是最小的)(或)更改服务器端的证书链。

    对于 Nginx

    对于 Nginx,只有一个参数来指定证书文件。您应该使用fullchain.pemcertbot 提供的来使其正常工作。

    给定虚拟主机的服务器块中的正确配置如下:

    server {
      ...
      ssl_certificate /etc/letsencrypt/live/co2-avatar.com/fullchain.pem;  -> replaced cert.pem for fullchain.pem
      ssl_certificate_key /etc/letsencrypt/live/co2-avatar.com/privkey.pem;
    }
    

    参考

    • DST 根 CA X3 到期(2021 年 9 月)
    • Let's Encrypt 更改会影响 OpenSSL 1.0.x 和 CentOS 7
    • 6

相关问题

  • RHEL/Apache ssl.conf 配置问题

  • IIS7 中的证书信任列表

  • SSL证书的区别?

  • 如何修复邮件服务器 SSL?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve