ssh signing: make verify-tag consider key lifetime
Set the payload_type for check_signature() when calling verify-tag. Implements the same tests as for verify-commit. Signed-off-by: Fabian Stelzer <fs@gigacodes.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Fabian Stelzer committed
Dec 9, 2021 at 09:52 UTC
dd3aa418aa109ff3697290ba89b626c3a4b36883
2 files changed
+43
t/t7031-verify-tag-signed-ssh.sh
+42
@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' '
48
git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt
49
'
50
51
+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '
52
+ test_when_finished "test_unconfig commit.gpgsign" &&
53
+ test_config gpg.format ssh &&
54
+
55
+ echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
56
+ git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed &&
57
+
58
+ echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
59
+ git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed &&
60
+
61
+ echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
62
+ git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed &&
63
+
64
+ echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
65
+ git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed
66
+'
67
+
68
test_expect_success GPGSSH 'verify and show ssh signatures' '
69
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
70
(
@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' '
97
)
98
'
99
100
+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' '
101
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
102
+ test_must_fail git verify-tag expired-signed 2>actual &&
103
+ ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
104
+'
105
+
106
+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' '
107
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
108
+ test_must_fail git verify-tag notyetvalid-signed 2>actual &&
109
+ ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
110
+'
111
+
112
+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' '
113
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
114
+ git verify-tag timeboxedvalid-signed 2>actual &&
115
+ grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
116
+ ! grep "${GPGSSH_BAD_SIGNATURE}" actual
117
+'
118
+
119
+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' '
120
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
121
+ test_must_fail git verify-tag timeboxedinvalid-signed 2>actual &&
122
+ ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
123
+'
124
+
125
test_expect_success GPGSSH 'detect fudged ssh signature' '
126
test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
127
git cat-file tag seventh-signed >raw &&
tag.c
+1
@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
25
return error("no signature found");
26
}
27
28
+ sigc.payload_type = SIGNATURE_PAYLOAD_TAG;
29
sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
30
ret = check_signature(&sigc, signature.buf, signature.len);
31