Skip to content

Commit 73dd290

Browse files
chriscoolgitster
authored andcommitted
fast-export: handle all kinds of tag signatures
Currently the handle_tag() function in "builtin/fast-export.c" searches only for "\n-----BEGIN PGP SIGNATURE-----\n" in the tag message to find a tag signature. This doesn't handle all kinds of OpenPGP signatures as some can start with "-----BEGIN PGP MESSAGE-----" too, and this doesn't handle SSH and X.509 signatures either as they use "-----BEGIN SSH SIGNATURE-----" and "-----BEGIN SIGNED MESSAGE-----" respectively. To handle all these kinds of tag signatures supported by Git, let's use the parse_signed_buffer() function to properly find signatures in tag messages. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1fc1e8 commit 73dd290

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

builtin/fast-export.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,8 @@ static void handle_tag(const char *name, struct tag *tag)
931931

932932
/* handle signed tags */
933933
if (message) {
934-
const char *signature = strstr(message,
935-
"\n-----BEGIN PGP SIGNATURE-----\n");
936-
if (signature)
934+
size_t sig_offset = parse_signed_buffer(message, message_size);
935+
if (sig_offset < message_size)
937936
switch (signed_tag_mode) {
938937
case SIGN_ABORT:
939938
die("encountered signed tag %s; use "
@@ -950,7 +949,7 @@ static void handle_tag(const char *name, struct tag *tag)
950949
oid_to_hex(&tag->object.oid));
951950
/* fallthru */
952951
case SIGN_STRIP:
953-
message_size = signature + 1 - message;
952+
message_size = sig_offset;
954953
break;
955954
}
956955
}

t/t9350-fast-export.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,54 @@ test_expect_success 'signed-tags=warn-strip' '
279279
test -s err
280280
'
281281

282+
test_expect_success GPGSM 'setup X.509 signed tag' '
283+
284+
test_config gpg.format x509 &&
285+
test_config user.signingkey $GIT_COMMITTER_EMAIL &&
286+
287+
git tag -s -m "X.509 signed tag" x509-signed $(git rev-parse HEAD) &&
288+
ANNOTATED_TAG_COUNT=$((ANNOTATED_TAG_COUNT + 1))
289+
290+
'
291+
292+
test_expect_success GPGSM 'signed-tags=verbatim with X.509' '
293+
294+
git fast-export --signed-tags=verbatim x509-signed > output &&
295+
test_grep "SIGNED MESSAGE" output
296+
297+
'
298+
299+
test_expect_success GPGSM 'signed-tags=strip with X.509' '
300+
301+
git fast-export --signed-tags=strip x509-signed > output &&
302+
test_grep ! "SIGNED MESSAGE" output
303+
304+
'
305+
306+
test_expect_success GPGSSH 'setup SSH signed tag' '
307+
308+
test_config gpg.format ssh &&
309+
test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
310+
311+
git tag -s -m "SSH signed tag" ssh-signed $(git rev-parse HEAD) &&
312+
ANNOTATED_TAG_COUNT=$((ANNOTATED_TAG_COUNT + 1))
313+
314+
'
315+
316+
test_expect_success GPGSSH 'signed-tags=verbatim with SSH' '
317+
318+
git fast-export --signed-tags=verbatim ssh-signed > output &&
319+
test_grep "SSH SIGNATURE" output
320+
321+
'
322+
323+
test_expect_success GPGSSH 'signed-tags=strip with SSH' '
324+
325+
git fast-export --signed-tags=strip ssh-signed > output &&
326+
test_grep ! "SSH SIGNATURE" output
327+
328+
'
329+
282330
test_expect_success GPG 'set up signed commit' '
283331
284332
# Generate a commit with both "gpgsig" and "encoding" set, so

0 commit comments

Comments
 (0)