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 <fs@gigacodes.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Fabian Stelzer committed
Dec 9, 2021 at 09:52 UTC
122842fd93eefadac237cfd73a4227b65c8b78ee
2 files changed
+59
fmt-merge-msg.c
+1
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
533
else {
534
buf = payload.buf;
535
len = payload.len;
536
+ sigc.payload_type = SIGNATURE_PAYLOAD_TAG;
537
sigc.payload = strbuf_detach(&payload, &sigc.payload_len);
538
if (check_signature(&sigc, sig.buf, sig.len) &&
539
!sigc.output)
t/t6200-fmt-merge-msg.sh
+58
@@ -91,6 +91,26 @@ test_expect_success GPGSSH 'created ssh signed commit and tag' '
91
git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left
92
'
93
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
+
114
test_expect_success 'message for merging local branch' '
115
echo "Merge branch ${apos}left${apos}" >expected &&
116
@@ -139,6 +159,44 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh
159
! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
160
grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
161
'
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
+
200
test_expect_success 'message for merging external branch' '
201
echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
202