Skip to content

Commit 4bbf378

Browse files
FStelzergitster
authored andcommitted
ssh signing: make git log verify key lifetime
Set the payload_type for check_signature() when calling git log. 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 6393c95 commit 4bbf378

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

log-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
513513
if (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0)
514514
goto out;
515515

516+
sigc.payload_type = SIGNATURE_PAYLOAD_COMMIT;
516517
sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
517518
status = check_signature(&sigc, signature.buf, signature.len);
518519
if (status && !sigc.output)
@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit,
583584
status = -1;
584585
if (parse_signature(extra->value, extra->len, &payload, &signature)) {
585586
/* could have a good signature */
587+
sigc.payload_type = SIGNATURE_PAYLOAD_TAG;
586588
sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
587589
status = check_signature(&sigc, signature.buf, signature.len);
588590
if (sigc.output)

t/t4202-log.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,24 @@ test_expect_success GPGSSH 'setup sshkey signed branch' '
16771677
git commit -S -m signed_commit
16781678
'
16791679

1680+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed commits with keys having defined lifetimes' '
1681+
test_config gpg.format ssh &&
1682+
touch file &&
1683+
git add file &&
1684+
1685+
echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
1686+
git tag expired-signed &&
1687+
1688+
echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
1689+
git tag notyetvalid-signed &&
1690+
1691+
echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
1692+
git tag timeboxedvalid-signed &&
1693+
1694+
echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
1695+
git tag timeboxedinvalid-signed
1696+
'
1697+
16801698
test_expect_success GPGSM 'log x509 fingerprint' '
16811699
echo "F8BF62E0693D0694816377099909C779FA23FD65 | " >expect &&
16821700
git log -n1 --format="%GF | %GP" signed-x509 >actual &&
@@ -1714,6 +1732,31 @@ test_expect_success GPGSSH 'log --graph --show-signature ssh' '
17141732
grep "${GOOD_SIGNATURE_TRUSTED}" actual
17151733
'
17161734

1735+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure on expired signature key' '
1736+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
1737+
git log --graph --show-signature -n1 expired-signed >actual &&
1738+
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
1739+
'
1740+
1741+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure on not yet valid signature key' '
1742+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
1743+
git log --graph --show-signature -n1 notyetvalid-signed >actual &&
1744+
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
1745+
'
1746+
1747+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log show success with commit date and key validity matching' '
1748+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
1749+
git log --graph --show-signature -n1 timeboxedvalid-signed >actual &&
1750+
grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
1751+
! grep "${GPGSSH_BAD_SIGNATURE}" actual
1752+
'
1753+
1754+
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure with commit date outside of key validity' '
1755+
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
1756+
git log --graph --show-signature -n1 timeboxedinvalid-signed >actual &&
1757+
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
1758+
'
1759+
17171760
test_expect_success GPG 'log --graph --show-signature for merged tag' '
17181761
test_when_finished "git reset --hard && git checkout main" &&
17191762
git checkout -b plain main &&

0 commit comments

Comments
 (0)