commit: ignore additional signatures when parsing signed commits

When we create a commit with multiple signatures, neither of these
signatures includes the other.  Consequently, when we produce the
payload which has been signed so we can verify the commit, we must strip
off any other signatures, or the payload will differ from what was
signed.  Do so, and in preparation for verifying with multiple
algorithms, pass the algorithm we want to verify into
parse_signed_commit.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson
2021-01-18 23:49:11 +00:00
committed by Junio C Hamano
parent 83dff3eb2e
commit 1fb5cf0da6
4 changed files with 79 additions and 23 deletions

View File

@ -172,7 +172,7 @@ test_expect_success GPG 'show signed commit with signature' '
git cat-file commit initial >cat &&
grep -v -e "gpg: " -e "Warning: " show >show.commit &&
grep -e "gpg: " -e "Warning: " show >show.gpg &&
grep -v "^ " cat | grep -v "^$(test_oid header) " >cat.commit &&
grep -v "^ " cat | grep -v "^gpgsig.* " >cat.commit &&
test_cmp show.commit commit &&
test_cmp show.gpg verify.2 &&
test_cmp cat.commit verify.1
@ -334,4 +334,45 @@ test_expect_success GPG 'show double signature with custom format' '
test_cmp expect actual
'
test_expect_success GPG 'verify-commit verifies multiply signed commits' '
git init multiply-signed &&
cd multiply-signed &&
test_commit first &&
echo 1 >second &&
git add second &&
tree=$(git write-tree) &&
parent=$(git rev-parse HEAD^{commit}) &&
git commit --gpg-sign -m second &&
git cat-file commit HEAD &&
# Avoid trailing whitespace.
sed -e "s/^Q//" -e "s/^Z/ /" >commit <<-EOF &&
Qtree $tree
Qparent $parent
Qauthor A U Thor <author@example.com> 1112912653 -0700
Qcommitter C O Mitter <committer@example.com> 1112912653 -0700
Qgpgsig -----BEGIN PGP SIGNATURE-----
QZ
Q iHQEABECADQWIQRz11h0S+chaY7FTocTtvUezd5DDQUCX/uBDRYcY29tbWl0dGVy
Q QGV4YW1wbGUuY29tAAoJEBO29R7N3kMNd+8AoK1I8mhLHviPH+q2I5fIVgPsEtYC
Q AKCTqBh+VabJceXcGIZuF0Ry+udbBQ==
Q =tQ0N
Q -----END PGP SIGNATURE-----
Qgpgsig-sha256 -----BEGIN PGP SIGNATURE-----
QZ
Q iHQEABECADQWIQRz11h0S+chaY7FTocTtvUezd5DDQUCX/uBIBYcY29tbWl0dGVy
Q QGV4YW1wbGUuY29tAAoJEBO29R7N3kMN/NEAn0XO9RYSBj2dFyozi0JKSbssYMtO
Q AJwKCQ1BQOtuwz//IjU8TiS+6S4iUw==
Q =pIwP
Q -----END PGP SIGNATURE-----
Q
Qsecond
EOF
head=$(git hash-object -t commit -w commit) &&
git reset --hard $head &&
git verify-commit $head 2>actual &&
grep "Good signature from" actual &&
! grep "BAD signature from" actual
'
test_done