エラーメッセージ
Signature verification failed: incorrect signature
別の表記
- Couldn't verify signature: namespace does not match
- Could not verify signature.
この鍵について allowed signers ファイルに記載されていないプリンシパルの場合は、「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` を使います。名前空間は、ある目的のために作成された署名が別の目的に流用されるのを防ぎます。
ID または鍵が allowed_signers にない
ときどき`-I` で指定したプリンシパルが allowed signers ファイルで署名鍵に対応付けられていないか、鍵がローテーションされたのにファイルには古い鍵が記載されたままになっています。
修正方法
- 1.
正しい名前空間で元のバイト列そのものを検証する
元のファイルをパイプで `ssh-keygen -Y verify` に渡し、署名時と同じ名前空間を使ってください。`find-principals` を使うと、鍵がどの ID に対応付けられているかを確認できます。
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` は、allowed signers を参照せずに署名を検証します。成功した場合、問題は ID の対応付けにあります。失敗した場合は、データか署名が間違っています。
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)