问题现象
您在服务器安装SSL证书后,本地使用curl客户端访问站点可能会遇到以下问题:Peer certificate cannot be authenticated with known CA certificates(对端证书的根不可信任)。
[root@iZwz # curl https://xxx
sResultQuery
curl: (60) Peer certificate cannot be authenticated with known CA certificates
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问题原因
客户端需要保证证书链完整,即包含对应的根证书(CA证书),否则SSL证书会校验失败。
可能是当前版本的curl客户端中没有包含对应的根证书,证书链不完整,因此导致的SSL证书校验失败。
如何查看当前客户端的根证书
以CentOS系统为例,当前客户端的根证书目录为:/etc/pki/tls/certs/,查看根证书目录下是否含DigiCert Global Root G2根证书。
您可以通过执行以下命令查看当前客户端的根证书列表:
cd /etc/pki/tls/certs/ && cat ca-bundle.crt |grep DigiCert如下所示,输出了所有DigiCert品牌的所有根证书:
[root@xxx /etc/pki/tls/certs]# cat ca-bundle.crt |grep DigiCert
Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Assured ID Root CA
Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Assured ID Root CA
Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root CA
Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root CA
Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA
Subject: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert High Assurance EV Root CA可以看到,根证书列表中,不包含对应的DigiCert Global Root G2根证书。
解决方案
方案一:升级客户端版本(推荐)
建议升级使用的curl客户端版本。
如何升级curl客户端版本
以CentOS 8为例,您可以通过以下命令升级curl版本。(仅供参考,具体升级的方式和curl的安装方式有关。)
sudo dnf update curl -y # CentOS 8/Stream 8方案二:手动安装根证书(推荐)
如果暂时无法升级客户端版本,则可以手动拷贝根证书到客户端CA根证书文件(ca-bundle.crt)中,客户端即可正常校验。
以CentOS 8为例,手动安装根证书的步骤如下:
解压下载的根证书压缩包,找到对应的根证书,拷贝至
/etc/pki/tls/certs/ca-bundle.crt文件中。
方案三:指定CA证书验证TLS/SSL连接
您也可以将SSL证书对应的CA根证书拷贝至当前Linux系统的任意目录,随后使用指定本地CA根证书文件路径的方式,发起连接验证。
# 请将证书路径和服务器地址,替换为实际地址。
curl --cacert /path/to/ca_certificate.crt https://example.com如何快速查看SSL证书的信任根(CA证书)
明确目标域名证书的颁发机构根证书(CA根)后,才能确认当前客户端是否包含对应的根证书。
以Chrome浏览器为例,访问目标站点,在地址栏点击
图标,依次选择,即可看到完整的证书层级结构。
可以看到,SSL证书对应的根证书为:DigiCert Global Root G2。