Skip to content

Commit 2f3cbcd

Browse files
szedergitster
authored andcommitted
tests: make forging GPG signed commits and tags more robust
A couple of test scripts create forged GPG signed commits or tags to check that such forgery can't fool various git commands' signature verification. All but one of those test scripts are prone to occasional failures because the forgery creates a bogus GPG signature, and git commands error out with an unexpected error message, e.g. "Commit deadbee does not have a GPG signature" instead of "... has a bad GPG signature". 't5573-pull-verify-signatures.sh', 't7510-signed-commit.sh' and 't7612-merge-verify-signatures.sh' create forged signed commits like this: git commit -S -m "bad on side" && git cat-file commit side-bad >raw && sed -e "s/bad/forged bad/" raw >forged && git hash-object -w -t commit forged >forged.commit On rare occasions the given pattern occurs not only in the commit message but in the GPG signature as well, and after it's replaced in the signature the resulting signature becomes invalid, GPG will report CRC error and that it couldn't find any signature, which will then ultimately cause the test failure. Since in all three cases the pattern to be replaced during the forgery is the first word of the commit message's subject line, and since the GPG signature in the commit object is indented by a space, let's just anchor those patterns to the beginning of the line to prevent this issue. The test script 't7030-verify-tag.sh' creates a forged signed tag object in a similar way by replacing the pattern "seventh", but the GPG signature in tag objects is not indented by a space, so the above solution is not applicable in this case. However, in the tag object in question the pattern "seventh" occurs not only in the tag message but in the 'tag' header as well. To create a forged tag object it's sufficient to replace only one of the two occurences, so modify the sed script to limit the pattern to the 'tag' header (i.e. a line beginning with "tag ", which, because of the space character, can never occur in the base64-encoded GPG signature). Note that the forgery in 't7004-tag.sh' is not affected by this issue: while 't7004' does create a forged signed tag kind of the same way, it replaces "signed-tag" in the tag object, which, because of the '-' character, can never occur in the base64-encoded GPG signarute. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9dd3982 commit 2f3cbcd

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

t/t5573-pull-verify-signatures.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test_expect_success GPG 'create repositories with signed commits' '
2929
echo 4 >d && git add d &&
3030
test_tick && git commit -S -m "bad" &&
3131
git cat-file commit HEAD >raw &&
32-
sed -e "s/bad/forged bad/" raw >forged &&
32+
sed -e "s/^bad/forged bad/" raw >forged &&
3333
git hash-object -w -t commit forged >forged.commit &&
3434
git checkout $(cat forged.commit)
3535
) &&

t/t7030-verify-tag.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test_expect_success GPG 'verify and show signatures' '
7474

7575
test_expect_success GPG 'detect fudged signature' '
7676
git cat-file tag seventh-signed >raw &&
77-
sed -e "s/seventh/7th forged/" raw >forged1 &&
77+
sed -e "/^tag / s/seventh/7th forged/" raw >forged1 &&
7878
git hash-object -w -t tag forged1 >forged1.tag &&
7979
test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
8080
grep "BAD signature from" actual1 &&

t/t7510-signed-commit.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ test_expect_success GPG 'show signed commit with signature' '
142142

143143
test_expect_success GPG 'detect fudged signature' '
144144
git cat-file commit seventh-signed >raw &&
145-
146-
sed -e "s/seventh/7th forged/" raw >forged1 &&
145+
sed -e "s/^seventh/7th forged/" raw >forged1 &&
147146
git hash-object -w -t commit forged1 >forged1.commit &&
148147
test_must_fail git verify-commit $(cat forged1.commit) &&
149148
git show --pretty=short --show-signature $(cat forged1.commit) >actual1 &&

t/t7612-merge-verify-signatures.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test_expect_success GPG 'create signed commits' '
2323
echo 3 >bar && git add bar &&
2424
test_tick && git commit -S -m "bad on side" &&
2525
git cat-file commit side-bad >raw &&
26-
sed -e "s/bad/forged bad/" raw >forged &&
26+
sed -e "s/^bad/forged bad/" raw >forged &&
2727
git hash-object -w -t commit forged >forged.commit &&
2828
git checkout initial &&
2929

0 commit comments

Comments
 (0)