]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: make forging GPG signed commits and tags more robust
authorSZEDER Gábor <szeder.dev@gmail.com>
Mon, 4 Jun 2018 13:39:26 +0000 (15:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Jun 2018 17:19:03 +0000 (10:19 -0700)
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 deadbeef 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 <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5573-pull-verify-signatures.sh
t/t7030-verify-tag.sh
t/t7510-signed-commit.sh
t/t7612-merge-verify-signatures.sh

index 9594e891f45d4c0d29b73190c1b5345b4c4d54b6..747775c147612f3b09a599661fe3dc7d3b1d34bd 100755 (executable)
@@ -29,7 +29,7 @@ test_expect_success GPG 'create repositories with signed commits' '
                echo 4 >d && git add d &&
                test_tick && git commit -S -m "bad" &&
                git cat-file commit HEAD >raw &&
-               sed -e "s/bad/forged bad/" raw >forged &&
+               sed -e "s/^bad/forged bad/" raw >forged &&
                git hash-object -w -t commit forged >forged.commit &&
                git checkout $(cat forged.commit)
        ) &&
index b4b49eeb08313df8d260a17414a19e7ac2fdc901..291a1e2b07417559d3f3defd6a60043b505eb3c7 100755 (executable)
@@ -74,7 +74,7 @@ test_expect_success GPG 'verify and show signatures' '
 
 test_expect_success GPG 'detect fudged signature' '
        git cat-file tag seventh-signed >raw &&
-       sed -e "s/seventh/7th forged/" raw >forged1 &&
+       sed -e "/^tag / s/seventh/7th forged/" raw >forged1 &&
        git hash-object -w -t tag forged1 >forged1.tag &&
        test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
        grep "BAD signature from" actual1 &&
index 663bf68def8ea0bf32475a9a932c7bc4eed280b8..6e2015ed9a199d6c6240a5fee850e72fd2fa65c3 100755 (executable)
@@ -142,8 +142,7 @@ test_expect_success GPG 'show signed commit with signature' '
 
 test_expect_success GPG 'detect fudged signature' '
        git cat-file commit seventh-signed >raw &&
-
-       sed -e "s/seventh/7th forged/" raw >forged1 &&
+       sed -e "s/^seventh/7th forged/" raw >forged1 &&
        git hash-object -w -t commit forged1 >forged1.commit &&
        test_must_fail git verify-commit $(cat forged1.commit) &&
        git show --pretty=short --show-signature $(cat forged1.commit) >actual1 &&
index e797c741124ef86eae0e3a8d6a5372b0a84c91e2..e2b1df817a50a48132964124d359c7dc29a89e23 100755 (executable)
@@ -23,7 +23,7 @@ test_expect_success GPG 'create signed commits' '
        echo 3 >bar && git add bar &&
        test_tick && git commit -S -m "bad on side" &&
        git cat-file commit side-bad >raw &&
-       sed -e "s/bad/forged bad/" raw >forged &&
+       sed -e "s/^bad/forged bad/" raw >forged &&
        git hash-object -w -t commit forged >forged.commit &&
        git checkout initial &&