Skip to content

Commit ddd7c7a

Browse files
jltoblergitster
authored andcommitted
fast-import: add 'abort-if-invalid' mode to '--signed-tags=<mode>'
In git-fast-import(1), the 'abort-if-invalid' mode for the '--signed-commits' option verifies commit signatures during import and aborts the entire operation when verification fails. Extend the same behavior to signed tag objects by introducing an 'abort-if-invalid' mode for the '--signed-tags' option. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2b1546c commit ddd7c7a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

builtin/fast-import.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,9 @@ static void handle_tag_signature_if_invalid(struct strbuf *buf,
31093109
if (!check_signature(&sigc, signature.buf, signature.len))
31103110
goto out;
31113111

3112+
if (signed_tag_mode == SIGN_ABORT_IF_INVALID)
3113+
die(_("aborting due to invalid signature"));
3114+
31123115
strbuf_setlen(msg, sig_offset);
31133116

31143117
if (signed_tag_mode == SIGN_SIGN_IF_INVALID) {
@@ -3156,6 +3159,7 @@ static void handle_tag_signature(struct strbuf *buf, struct strbuf *msg, const c
31563159
/* Truncate the buffer to remove the signature */
31573160
strbuf_setlen(msg, sig_offset);
31583161
break;
3162+
case SIGN_ABORT_IF_INVALID:
31593163
case SIGN_SIGN_IF_INVALID:
31603164
case SIGN_STRIP_IF_INVALID:
31613165
handle_tag_signature_if_invalid(buf, msg, sig_offset);
@@ -3165,9 +3169,6 @@ static void handle_tag_signature(struct strbuf *buf, struct strbuf *msg, const c
31653169
case SIGN_ABORT:
31663170
die(_("encountered signed tag; use "
31673171
"--signed-tags=<mode> to handle it"));
3168-
case SIGN_ABORT_IF_INVALID:
3169-
die(_("'abort-if-invalid' is not a valid mode for "
3170-
"git fast-import with --signed-tags=<mode>"));
31713172
default:
31723173
BUG("invalid signed_tag_mode value %d from tag '%s'",
31733174
signed_tag_mode, name);

t/t9306-fast-import-signed-tags.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ test_expect_success GPGSSH 'import SSH signed tag with --signed-tags=strip' '
7777
test_grep ! "SSH SIGNATURE" out
7878
'
7979

80-
for mode in strip-if-invalid sign-if-invalid
80+
for mode in strip-if-invalid sign-if-invalid abort-if-invalid
8181
do
8282
test_expect_success GPG "import tag with no signature with --signed-tags=$mode" '
8383
test_when_finished rm -rf import &&
@@ -112,6 +112,14 @@ do
112112
# `data <length>` command would have to be changed too.
113113
sed "s/OpenPGP signed tag/OpenPGP forged tag/" output >modified &&
114114
115+
if test "$mode" = abort-if-invalid
116+
then
117+
test_must_fail git -C import fast-import --quiet \
118+
--signed-tags=$mode <modified >log 2>&1 &&
119+
test_grep "aborting due to invalid signature" log &&
120+
return 0
121+
fi &&
122+
115123
git -C import fast-import --quiet --signed-tags=$mode <modified >log 2>&1 &&
116124
117125
IMPORTED=$(git -C import rev-parse --verify refs/tags/openpgp-signed) &&

0 commit comments

Comments
 (0)