Skip to content

Commit 9b27b49

Browse files
bk2204gitster
authored andcommitted
gpg-interface: remove other signature headers before verifying
When we have a multiply signed commit, we need to remove the signature in the header before verifying the object, since the trailing signature will not be over both pieces of data. Do so, and verify that we validate the signature appropriately. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88bce0e commit 9b27b49

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gpg-interface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "commit.h"
23
#include "config.h"
34
#include "run-command.h"
45
#include "strbuf.h"
@@ -366,6 +367,7 @@ int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct
366367
size_t match = parse_signed_buffer(buf, size);
367368
if (match != size) {
368369
strbuf_add(payload, buf, match);
370+
remove_signature(payload);
369371
strbuf_add(signature, buf + match, size - match);
370372
return 1;
371373
}

t/t7004-tag.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ tag_exists () {
1717
git show-ref --quiet --verify refs/tags/"$1"
1818
}
1919

20+
test_expect_success 'setup' '
21+
test_oid_cache <<-EOM
22+
othersigheader sha1:gpgsig-sha256
23+
othersigheader sha256:gpgsig
24+
EOM
25+
'
26+
2027
test_expect_success 'listing all tags in an empty tree should succeed' '
2128
git tag -l &&
2229
git tag
@@ -1371,6 +1378,24 @@ test_expect_success GPG \
13711378
'test_config gpg.program echo &&
13721379
test_must_fail git tag -s -m tail tag-gpg-failure'
13731380

1381+
# try to produce invalid signature
1382+
test_expect_success GPG 'git verifies tag is valid with double signature' '
1383+
git tag -s -m tail tag-gpg-double-sig &&
1384+
git cat-file tag tag-gpg-double-sig >tag &&
1385+
othersigheader=$(test_oid othersigheader) &&
1386+
sed -ne "/^\$/q;p" tag >new-tag &&
1387+
cat <<-EOM >>new-tag &&
1388+
$othersigheader -----BEGIN PGP SIGNATURE-----
1389+
someinvaliddata
1390+
-----END PGP SIGNATURE-----
1391+
EOM
1392+
sed -e "1,/^tagger/d" tag >>new-tag &&
1393+
new_tag=$(git hash-object -t tag -w new-tag) &&
1394+
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1395+
git verify-tag tag-gpg-double-sig &&
1396+
git fsck
1397+
'
1398+
13741399
# try to sign with bad user.signingkey
13751400
test_expect_success GPGSM \
13761401
'git tag -s fails if gpgsm is misconfigured (bad key)' \

0 commit comments

Comments
 (0)