跳到主要内容
ecdsa.com
Go crypto/x509Go

错误信息

x509: invalid signature: parent certificate cannot sign this kind of certificate

也可能输出为

  • x509: certificate signed by unknown authority (possibly because of "x509: invalid signature: parent certificate cannot sign this kind of certificate" while trying to verify candidate authority certificate "Example Issuing Server")

Go 把它包装为“x509: certificate signed by unknown authority (possibly because of \"x509: invalid signature: parent certificate cannot sign this kind of certificate\" while trying to verify candidate authority certificate \"<issuer CN>\")”。其中的颁发者名称来自你的证书链。

Go crypto/x509 — ConstraintViolationError: the issuer is not a CA (basicConstraints CA:FALSE or missing keyCertSign)

含义

Go 为某张证书找到了一个候选颁发者(即末尾引号中的名称),但该颁发者不允许签发证书:它的 basicConstraints 为 CA:FALSE(或者缺失),或者它的 keyUsage 中没有 keyCertSign。因此 Go 丢弃了这个候选者,又没有其他路径可用,于是报告“certificate signed by unknown authority”,并引用这个原因作为可能的起因。

原因

修复方法

  1. 1.

    检查颁发者的 basicConstraints 和 keyUsage

    引号中的候选证书必须具有 CA:TRUE 和 keyCertSign。OpenSSL 3.5 把同一缺陷报告为错误 79:“invalid CA certificate”。

    bash
    # Every issuing certificate needs CA:TRUE (and keyCertSign if keyUsage is present)
    openssl x509 -in intermediate.pem -noout -subject -ext basicConstraints,keyUsage
    openssl verify -CAfile root.pem -untrusted intermediate.pem server.pem   # OpenSSL 3.5: error 79, invalid CA certificate
  2. 2.

    将中间证书重新签发为 CA 证书

    签发时设置 basicConstraints critical CA:TRUE(按需设置 pathlen)以及 keyUsage keyCertSign、cRLSign,然后重新签发叶子证书,或者把它们重新接到新的证书链上。

    bash
    # Issue the intermediate as a real CA
    printf 'basicConstraints=critical,CA:TRUE,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign\n' > ca.ext
    openssl x509 -req -in int.csr -CA root.pem -CAkey root.key -days 1825 -extfile ca.ext -out int.pem

相关错误

浏览完整的签名错误库