Skip to content

Commit 122842f

Browse files
FStelzergitster
authored andcommitted
ssh signing: make fmt-merge-msg consider key lifetime
Set the payload_type for check_signature() when generating merge messages to verify merged tags signatures key lifetimes. Implements the same tests as for verify-commit. Signed-off-by: Fabian Stelzer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd3aa41 commit 122842f

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

fmt-merge-msg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
533533
else {
534534
buf = payload.buf;
535535
len = payload.len;
536+
sigc.payload_type = SIGNATURE_PAYLOAD_TAG;
536537
sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
537538
if (check_signature(&sigc, sig.buf, sig.len) &&
538539
!sigc.output)

t/t6200-fmt-merge-msg.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ test_expect_success GPGSSH 'created ssh signed commit and tag' '
9191
git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left
9292
'
9393

94+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '
95+
test_when_finished "test_unconfig commit.gpgsign" &&
96+
test_config gpg.format ssh &&
97+
git checkout -b signed-expiry-ssh &&
98+
touch file &&
99+
git add file &&
100+
101+
echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
102+
git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed &&
103+
104+
echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
105+
git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed &&
106+
107+
echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
108+
git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed &&
109+
110+
echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
111+
git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed
112+
'
113+
94114
test_expect_success 'message for merging local branch' '
95115
echo "Merge branch ${apos}left${apos}" >expected &&
96116
@@ -139,6 +159,44 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh
139159
! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
140160
grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
141161
'
162+
163+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' '
164+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
165+
git checkout main &&
166+
git fetch . expired-signed &&
167+
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
168+
grep "^Merge tag ${apos}expired-signed${apos}" actual &&
169+
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
170+
'
171+
172+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' '
173+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
174+
git checkout main &&
175+
git fetch . notyetvalid-signed &&
176+
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
177+
grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual &&
178+
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
179+
'
180+
181+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' '
182+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
183+
git checkout main &&
184+
git fetch . timeboxedvalid-signed &&
185+
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
186+
grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual &&
187+
grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
188+
! grep "${GPGSSH_BAD_SIGNATURE}" actual
189+
'
190+
191+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' '
192+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
193+
git checkout main &&
194+
git fetch . timeboxedinvalid-signed &&
195+
git fmt-merge-msg <.git/FETCH_HEAD >actual &&
196+
grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual &&
197+
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
198+
'
199+
142200
test_expect_success 'message for merging external branch' '
143201
echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
144202

0 commit comments

Comments
 (0)