rustls 0.23 (via reqwest, ureq, hyper-rustls)Rust
错误信息
invalid peer certificate: certificate expired: verification time
完整形式为:“invalid peer certificate: certificate expired: verification time <unix> (UNIX), but certificate is not valid after <unix> (<n> seconds ago)”。早期的 rustls 版本只打印变体名称(“invalid peer certificate: Expired”)。尚未生效的证书会产生另一个变体“not valid yet”。
rustls 0.23 (via reqwest, ureq, hyper-rustls) — CertificateError::ExpiredContext
含义
rustls 验证了证书链,但其中有一张证书在验证时刻已超过其 notAfter 日期。rustls 0.23 会以 Unix 时间戳给出这两个时刻,并说明证书在多少秒前过期,由此可以立即判断出错的是证书还是时钟。
原因
服务器证书已过期
常见续期失败,或者服务器尚未提供续期后的证书。
客户端的时钟不准确
偶见嵌入式设备,以及宿主机未启用 NTP 的容器,时钟可能偏差很大;把消息中的验证时间与实际时间对比一下。
被固定为信任锚的过期证书
罕见有些客户端把服务器证书本身添加为根证书;服务器续期后,它们仍会拿那张旧证书来验证。
修复方法
- 1.
转换时间戳
date -u -d @<seconds> 可以把这两个值转换为可读的 UTC 时间。
bash # The message gives both instants as Unix seconds date -u -d @1743465600 # certificate's notAfter date -u # this machine's time - 2.
续期并重新部署
续期服务器证书,重新加载服务,然后从网络一侧确认新的到期日期。
bash echo | openssl s_client -connect api.example.com:443 -servername api.example.com 2>/dev/null | openssl x509 -noout -enddate sudo certbot renew && sudo systemctl reload nginx