OpenSSL CLI (openssl s_client / openssl verify)OpenSSL CLI
错误信息
verify error:num=10:certificate has expired
也可能输出为
- error 10 at 0 depth lookup: certificate has expired
- Verify return code: 10 (certificate has expired)
s_client 输出“verify error:num=10:certificate has expired”,随后是“notAfter=…”;openssl verify 输出“error 10 at <depth> depth lookup: certificate has expired”。尚未生效的证书会产生错误 9,即“certificate is not yet valid”。
OpenSSL CLI (openssl s_client / openssl verify) — X509_V_ERR_CERT_HAS_EXPIRED
含义
OpenSSL 错误 10(X509_V_ERR_CERT_HAS_EXPIRED):证书链中某张证书的 notAfter 日期早于验证时间;除非指定了 -attime,验证时间就是本地时钟。与错误一同输出的 depth 行会告诉你是哪张证书:0 是服务器自己的证书,更大的数字是中间证书。
原因
服务器的证书已过期(深度 0)
常见续期失败,或者服务器或负载均衡器从未加载续期后的证书。
服务器提供的证书链中有中间证书已过期
偶见CA 已经换用新的证书,旧的证书链文件却还在继续提供已过期的中间证书或交叉签名证书;用 CA 当前的证书链替换它。
执行验证的机器时钟偏快
偶见时钟超前会让有效的证书看起来已经过期;-attime 有助于区分时钟问题和真正的过期。
修复方法
- 1.
找出已过期的证书
查看 depth 行和 notAfter 行;-checkend 可以告诉你证书文件是否会在指定秒数内过期,很适合用于监控。
bash # The depth printed with the error identifies the certificate; s_client also prints notAfter echo | openssl s_client -connect api.example.com:443 -servername api.example.com 2>&1 | grep -E '^depth|verify error|notAfter' # Check a file, and whether it expires within 30 days (exit 1 = yes) openssl x509 -in server.pem -noout -enddate -checkend 2592000 - 2.
在指定时间点验证
openssl verify -attime <unix time> 会显示证书链在那个时刻是否有效,从而把过期与其他错误区分开。
bash # Would the chain verify at another moment? (useful to separate clock problems) openssl verify -attime "$(date -d '2025-02-01' +%s)" -CAfile root.pem server.pem - 3.
续期并重新加载
为证书续期,重新加载负责终止 TLS 的组件,然后从网络一侧确认新的过期时间。
bash sudo certbot renew && sudo systemctl reload nginx echo | openssl s_client -connect api.example.com:443 -servername api.example.com 2>/dev/null | openssl x509 -noout -enddate
相关错误
curl: (60) SSL certificate problem: certificate has expiredcurl (OpenSSL backend)x509: certificate has expired or is not yet valid: current time 2026-08-20T15:4…Go crypto/x509[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has exp…Python ssl module (OpenSSL)certificate has expiredNode.js tls / https / fetch