错误信息
ERROR: cannot verify api.example.com's certificate, issued by 'CN=Example Private CA':
也可能输出为
- Unable to locally verify the issuer's authority.
主机名和颁发者的可分辨名称随网站而变。使用 GnuTLS 构建的 wget(Debian)会把同样的失败报告为“ERROR: The certificate of '<host>' is not trusted.”。
含义
wget 的 OpenSSL 后端无法验证服务器证书,“issued by”后面引号中的就是该证书的颁发者。wget 接下来打印的缩进行给出了 OpenSSL 的原因;“Unable to locally verify the issuer's authority”表示颁发者不在本地 CA 证书包中,服务器也没有发送能通向证书包中某个 CA 的证书。wget 以退出状态 5 中止。
原因
颁发者是私有 CA 或公司 CA
常见如果引用的颁发者是你所在组织的 CA,或者是 Kubernetes、Vault 等工具的 CA,那么它的根证书不在这台机器的公共证书包中。
服务器没有发送中间证书
常见如果颁发者是公共中间证书(“R13”、“GTS CA 1C3”、“Sectigo RSA Domain Validation…”),说明服务器没有发送它;缺少它,OpenSSL 就无法把叶子证书连接到受信任的根证书。
证书由执行 TLS 检查的代理签发
偶见如果公共网站证书的颁发者名称属于某家安全厂商或你的公司,说明有代理在对流量重新签名。必须把该代理的根证书安装到运行 wget 的机器上。
CA 证书包已过时
罕见多年未更新 ca-certificates 的系统,可能缺少较新的公共证书所追溯到的根证书。
修复方法
- 1.
查看缩进的原因行
ERROR 报错下面的那一行会告诉你 OpenSSL 的哪项检查失败了,由此可以判断该修复的是信任、服务器的证书链,还是日期。
text ERROR: cannot verify api.example.com's certificate, issued by 'CN=Example Private CA': Unable to locally verify the issuer's authority. <- issuer unknown: CA or chain problem Self-signed certificate encountered. <- server certificate is self-signed Issued certificate has expired. <- date problem - 2.
为 wget 指定 CA
用 --ca-certificate 传入根证书(或证书包),或者在 ~/.wgetrc 或 /etc/wgetrc 中设置 ca_certificate。
bash wget --ca-certificate=/opt/certs/corp-root-ca.pem https://api.example.com/ echo 'ca_certificate = /opt/certs/corp-root-ca.pem' >> ~/.wgetrc - 3.
把根证书安装到系统证书包中
基于 OpenSSL 的 wget 读取发行版的证书包,因此把根证书加到那里,就能一次性修复这台机器上的 wget、curl 和大多数其他工具。
bash # Ubuntu / Alpine sudo cp corp-root-ca.pem /usr/local/share/ca-certificates/corp-root-ca.crt && sudo update-ca-certificates # RHEL / Fedora sudo cp corp-root-ca.pem /etc/pki/ca-trust/source/anchors/ && sudo update-ca-trust - 4.
服务器所有者:配置完整证书链
如果颁发者是公共中间证书,就在服务器上配置叶子证书,并在其后依次附上中间证书。
bash # Server side: serve leaf + intermediates cat api.example.com.crt intermediate.crt > fullchain.pem - 5.
临时诊断:只跳过一次检查
--no-check-certificate 可以确认在不检查证书的情况下下载能否成功。它会接受任何证书,包括攻击者的证书,所以凡是你要执行或信任的内容,都不要用它下载。
bash # Diagnostic only wget --no-check-certificate -O /dev/null https://api.example.com/
相关错误
ERROR: The certificate of 'api.example.com' is not trusted.GNU Wget built with GnuTLS (Debian, Ubuntu before 22.04 used it too)curl: (60) SSL certificate problem: unable to get local issuer certificatecurl (OpenSSL backend)verify error:num=20:unable to get local issuer certificateOpenSSL CLI (openssl s_client / openssl verify)