OpenSSH ssh-keygen -Y verify (SSHSIG)SSH
错误信息
Signature verification failed: incorrect signature
也可能输出为
- Couldn't verify signature: namespace does not match
- Could not verify signature.
如果允许的签名者文件中没有为这个密钥列出该主体(principal),只会报出“Could not verify signature.”(前面没有详细信息行)。
OpenSSH ssh-keygen -Y verify (SSHSIG) — also used by Git for SSH-signed commits
含义
`ssh-keygen -Y verify` 检查了一个 SSHSIG 签名,密码学验证失败:从标准输入读取的数据与签名的数据并不完全相同,或者签名是由另一个密钥生成的。SSH 签名还会绑定一个命名空间(`file`、`git`、`email`……);在不同命名空间下验证签名,会在密码学检查之前就报出“namespace does not match”。每次失败之后都会跟着一行“Could not verify signature.”。
原因
验证的数据与签名的数据不一致
常见文件被修改、换行符不同(`\r\n` 与 `\n`)、编辑器在末尾添加了换行符,或者验证了错误的文件。SSHSIG 签名的是确切字节内容的哈希。
命名空间错误
常见用 `-n file` 创建的签名无法用 `-n git` 验证,而 Git 始终使用 `git`。命名空间可以防止为某一用途生成的签名被挪作他用。
身份或密钥不在 allowed_signers 中
偶见`-I` 指定的主体在允许的签名者文件中没有与签名密钥关联,或者密钥已经轮换,而文件中仍列着旧密钥。
修复方法
- 1.
用正确的命名空间验证原始字节
把原始文件通过管道传给 `ssh-keygen -Y verify`,并使用签名时的命名空间。`find-principals` 会显示该密钥对应哪个身份。
bash # Verify exactly the bytes that were signed, with the namespace used at signing time ssh-keygen -Y verify -f allowed_signers -I release@example.com -n file -s release.txt.sig < release.txt # Which principal does the allowed_signers file map this signature's key to? ssh-keygen -Y find-principals -f allowed_signers -s release.txt.sig - 2.
把密码学验证与信任分开
`check-novalidate` 会验证签名,但不查询允许的签名者文件。如果它通过了,问题出在身份映射上;如果它失败了,就是数据或签名有误。
bash ssh-keygen -Y check-novalidate -n file -s release.txt.sig < release.txt # signature valid at all (no trust check)?
相关错误
error: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh sign…Git (verify-commit, log --show-signature, merge --verify-signatures) with gpg.format=sshinvalid signature when validating ASN.1 encoded signatureSigstore cosign (verify-blob / verify with --key)gpg: BAD signature from "Release Bot <release@example.com>" [ultimate]GnuPG (gpg --verify, git verify-commit / verify-tag)