跳到主要内容
ecdsa.com
curl (OpenSSL backend)curl

错误信息

curl: (60) SSL certificate problem: certificate has expired

也可能输出为

  • curl: (60) SSL certificate OpenSSL verify result: certificate has expired (10)

在基于 OpenSSL 1.1.1、3.0 和 3.5 构建的 curl 中,原因文本完全相同。较新的 curl 版本(我们测试的是 8.22.0)会写作“SSL certificate OpenSSL verify result: certificate has expired (10)”。尚未生效的证书会给出另一个原因:“certificate is not yet valid”。

curl (OpenSSL backend) — CURLE_PEER_FAILED_VERIFICATION, X509_V_ERR_CERT_HAS_EXPIRED (10)

含义

curl 构建的证书链中,有一张证书的 notAfter 日期早于运行 curl 的机器上的当前时间。通常是服务器自己的证书,但过期的中间证书或交叉签名的根证书也会产生同样的文本。检查依据的是本地时钟,因此时钟错误看起来与证书过期完全一样。

原因

修复方法

  1. 1.

    找出过期的证书

    打印服务器发送的每张证书的 notAfter 日期。如果叶子证书已过期,就续期;如果是中间证书过期,就用 CA 当前发布的证书链文件替换现有的证书链文件。

    bash
    # Split the served chain into cert1.pem (leaf), cert2.pem, ... and print each expiry date
    openssl s_client -connect api.example.com:443 -servername api.example.com -showcerts </dev/null 2>/dev/null \
      | awk '/BEGIN CERT/{n++; f="cert" n ".pem"} /BEGIN CERT/,/END CERT/{print > f}'
    for f in cert*.pem; do openssl x509 -in "$f" -noout -subject -enddate; done
  2. 2.

    续期、重新加载,并检查实际提供的证书

    续期后,重新加载为该主机名终止 TLS 的所有进程和设备,然后从网络侧确认日期,而不是查看磁盘上的文件。

    bash
    sudo certbot renew                    # or your ACME client / CA portal
    sudo systemctl reload nginx           # the server keeps serving the old file until reloaded
    echo | openssl s_client -connect api.example.com:443 -servername api.example.com 2>/dev/null \
      | openssl x509 -noout -enddate      # confirm the new date is what the network sees
  3. 3.

    校正客户端时钟

    如果证书在其他机器上没有问题,就用 NTP 同步出错机器的时间。容器的时钟来自宿主机,因此要在宿主机上修复。

    bash
    date -u                       # compare with the real UTC time
    timedatectl status            # "System clock synchronized: yes"?
    sudo timedatectl set-ntp true
  4. 4.

    更新客户端的 CA 证书包

    在长期运行的系统上,更新后的 ca-certificates 软件包会移除已退役的根证书并加入当前的根证书,让 OpenSSL 能够选择有效的路径,而不是已过期的路径。

    bash
    # Old clients: refresh the root store so they stop building paths through retired roots
    sudo apt-get update && sudo apt-get install --only-upgrade ca-certificates   # Debian/Ubuntu
    sudo dnf upgrade ca-certificates                                             # RHEL/Fedora

相关错误

浏览完整的签名错误库