Bai*_*Dev 2 ssl-certificate lets-encrypt certbot
我无法解决以下问题。使用 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
Run Code Online (Sandbox Code Playgroud)
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-----
Run Code Online (Sandbox Code Playgroud)
或者运行
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
Run Code Online (Sandbox Code Playgroud)
可能两者都有,我的 Apache VHost 中的域配置错误以及证书链本身存在问题。我如何检查最后一个(我已经用谷歌搜索了很多,但大多数点击都是关于openssl verify
不同-CAfile
的证书颁发者)?
我是否需要检查根证书包以及具体如何检查?
有没有类似于certbot certonly-addtrust
标志的东西?
尝试 openssl s_client 并让您显示证书。命令是:
\n$ openssl s_client -connect co2avatar.org:443 -servername co2avatar.org -showcerts\n
Run Code Online (Sandbox Code Playgroud)\n您会发现您的服务器返回证书CN = gitlab.sustainable-data-platform.org
和主题备用名称,其中包括您的域DNS:co2-avatar.com
。所以证书本身没问题。
如果您想将所有内容合并到一个命令管道中以查看证书的内容:
\necho | 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\n
Run Code Online (Sandbox Code Playgroud)\n缺少的是中级证书。这也应该由服务器发送,但第一个命令显示它不存在 - 只有证书是由服务器发送的。
\n所以失败的 openssl 是正确的,因为中间证书确实丢失了。
\n所以要解决这个问题,你需要调整你的 apache 配置。您的配置可能如下所示:
\n文件名应该类似于/etc/apache2/sites-enabled/co2-avatar.com-le-ssl.conf
<IfModule mod_ssl.c>\nSSLStaplingCache shmcb:/var/run/apache2/stapling_cache(128000)\n<VirtualHost *:443>\n ServerName co2-avatar.com\n ServerAlias www.co2-avatar.com\n#... \n#... insert your other stuff here...\n#...\n\nSSLCertificateFile /etc/letsencrypt/live/co2-avatar.com/fullchain.pem\nSSLCertificateKeyFile /etc/letsencrypt/live/co2-avatar.com/privkey.pem\nInclude /etc/letsencrypt/options-ssl-apache.conf\nSSLUseStapling on\n</VirtualHost>\n</IfModule>\n
Run Code Online (Sandbox Code Playgroud)\n根据您的描述,我最好的猜测是您的配置中的以下行是错误的:\n 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)
\n根据Mozilla SSL 配置生成器,在这种情况下可以使用以下通用配置:
\n<VirtualHost *:443>\n SSLEngine on\n SSLCertificateFile /path/to/signed_certificate\n SSLCertificateChainFile /path/to/intermediate_certificate\n SSLCertificateKeyFile /path/to/private_key\n</VirtualHost>\n
Run Code Online (Sandbox Code Playgroud)\n转换为这种特定情况,最终的工作配置将如下所示:
\n<VirtualHost *:443>\n ServerName sustainable-data-platform.org\n ServerAlias co2-avatar.com\n ServerAlias ... <include all other SAN names here>\n \n SSLEngine on\n SSLCertificateFile /etc/letsencrypt/live/co2-avatar.com/cert.pem\n SSLCertificateChainFile /etc/letsencrypt/live/co2-avatar.com/fullchain.pem\n SSLCertificateKeyFile /etc/letsencrypt/live/co2-avatar.com/privkey.pem\n\n</VirtualHost>\n
Run Code Online (Sandbox Code Playgroud)\n交叉签名的 Let\xe2\x80\x99s 加密 R3 和 DST 根 CA X3、中间证书和根证书将分别于 2021 年 9 月 29 日和 2021 年 9 月 30 日到期。因此自2021年5月4日起,新颁发的证书使用更长的链,并带有交叉签名的ISRG Root X1作为中间证书。
\n不幸的是,由于证书路径的构建和验证方式,并非所有 TLS 实现都可以成功验证交叉签名。OpenSSL 1.0.2 就是这种情况。因此,在使用 OpenSSL 的 RHEL/CentOS 7 上运行的程序可能无法验证新证书链或建立 TLS 连接。在此类平台上升级到较新的 Openssl 版本并不简单。
\n有几个选项:要么在客户端更新信任存储(删除 DST Root CA X3 根证书 - 一旦删除,影响应该很小)(或者)更改服务器端的证书链。
\n对于 Nginx,只有一个参数来指定证书文件。您应该使用fullchain.pem
certbot 提供的工具来使其正常工作。
给定虚拟主机的服务器块中的正确配置如下:
\nserver {\n ...\n ssl_certificate /etc/letsencrypt/live/co2-avatar.com/fullchain.pem; -> replaced cert.pem for fullchain.pem\n ssl_certificate_key /etc/letsencrypt/live/co2-avatar.com/privkey.pem;\n}\n
Run Code Online (Sandbox Code Playgroud)\n 归档时间: |
|
查看次数: |
16914 次 |
最近记录: |