跳到主要内容
ecdsa.com
OpenSSL CLI (openssl s_client / openssl verify -purpose)OpenSSL CLI

错误信息

verify error:num=26:unsuitable certificate purpose

也可能输出为

  • Verify return code: 26 (unsuitable certificate purpose)
  • error 26 at 0 depth lookup: unsuitable certificate purpose

s_client 输出“verify error:num=26:…”和“Verify return code: 26 (…)”;openssl verify 输出“error 26 at <depth> depth lookup: unsuitable certificate purpose”。Go 把同样的问题报告为“x509: certificate specifies an incompatible key usage”。

OpenSSL CLI (openssl s_client / openssl verify -purpose) — X509_V_ERR_INVALID_PURPOSE

含义

OpenSSL 错误 26(X509_V_ERR_INVALID_PURPOSE):证书链在其他方面都有效,但某张证书的扩展不允许所检查的用途。s_client 按 TLS 服务器用途检查服务器证书,因此 extendedKeyUsage 中只列出 clientAuth(或 emailProtection)的证书无法通过;openssl verify 则检查你用 -purpose 指定的用途。

原因

修复方法

  1. 1.

    查看用途相关的扩展

    extendedKeyUsage、keyUsage 和 basicConstraints 说明了证书可以用于什么;openssl verify -purpose 可以检查某个特定用途。

    bash
    openssl x509 -in server.pem -noout -ext extendedKeyUsage,keyUsage,basicConstraints
    # Check against the purpose you need: sslserver, sslclient, smimesign, ...
    openssl verify -CAfile root.pem -purpose sslserver server.pem
  2. 2.

    按正确的用途重新签发

    TLS 服务器证书的 extendedKeyUsage 中需要有 serverAuth(如果存在该扩展),keyUsage 中需要有 digitalSignature。

    bash
    openssl req -new -key server.key -out server.csr -subj "/CN=api.example.com" \
      -addext "subjectAltName=DNS:api.example.com" -addext "extendedKeyUsage=serverAuth"

相关错误

浏览完整的签名错误库