跳到主要内容
ecdsa.com
GNU Wget built with OpenSSL (Ubuntu 22.04+, Alpine, RHEL/CentOS)curl

错误信息

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 中止。

原因

修复方法

  1. 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. 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. 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. 4.

    服务器所有者:配置完整证书链

    如果颁发者是公共中间证书,就在服务器上配置叶子证书,并在其后依次附上中间证书。

    bash
    # Server side: serve leaf + intermediates
    cat api.example.com.crt intermediate.crt > fullchain.pem
  5. 5.

    临时诊断:只跳过一次检查

    --no-check-certificate 可以确认在不检查证书的情况下下载能否成功。它会接受任何证书,包括攻击者的证书,所以凡是你要执行或信任的内容,都不要用它下载。

    bash
    # Diagnostic only
    wget --no-check-certificate -O /dev/null https://api.example.com/

相关错误

浏览完整的签名错误库