gpg-interface: use more status letters

According to gpg2's doc/DETAILS: For each signature only one of the codes GOODSIG, BADSIG, EXPSIG, EXPKEYSIG, REVKEYSIG or ERRSIG will be emitted. gpg1 ("classic") behaves the same (although doc/DETAILS differs). Currently, we parse gpg's status output for GOODSIG, BADSIG and trust information and translate that into status codes G, B, U, N for the %G? format specifier. git-verify-* returns success in the GOODSIG case only. This is somewhat in disagreement with gpg, which considers the first 5 of the 6 above as VALIDSIG, but we err on the very safe side. Introduce additional status codes E, X, Y, R for ERRSIG, EXPSIG, EXPKEYSIG, and REVKEYSIG so that a user of %G? gets more information about the absence of a 'G' on first glance. Requested-by: Alex <agrambot@gmail.com> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Oct 12, 2016 at 15:04 UTC 661a1806819ca98c446f82b19e6c98fa174d33a4
4 files changed +34 -6
Documentation/pretty-formats.txt
+8 -2
@@ -143,8 +143,14 @@ ifndef::git-rev-list[]
143 - '%N': commit notes
144 endif::git-rev-list[]
145 - '%GG': raw verification message from GPG for a signed commit
146 -- '%G?': show "G" for a good (valid) signature, "B" for a bad signature,
147 - "U" for a good signature with unknown validity and "N" for no signature
146 +- '%G?': show "G" for a good (valid) signature,
147 + "B" for a bad signature,
148 + "U" for a good signature with unknown validity,
149 + "X" for a good signature that has expired,
150 + "Y" for a good signature made by an expired key,
151 + "R" for a good signature made by a revoked key,
152 + "E" if the signature cannot be checked (e.g. missing key)
153 + and "N" for no signature
154 - '%GS': show the name of the signer for a signed commit
155 - '%GK': show the key used to sign a signed commit
156 - '%gD': reflog selector, e.g., `refs/stash@{1}` or
gpg-interface.c
+10 -3
@@ -33,6 +33,10 @@ static struct {
33 { 'B', "\n[GNUPG:] BADSIG " },
34 { 'U', "\n[GNUPG:] TRUST_NEVER" },
35 { 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
36 + { 'E', "\n[GNUPG:] ERRSIG "},
37 + { 'X', "\n[GNUPG:] EXPSIG "},
38 + { 'Y', "\n[GNUPG:] EXPKEYSIG "},
39 + { 'R', "\n[GNUPG:] REVKEYSIG "},
40 };
41
42 void parse_gpg_output(struct signature_check *sigc)
@@ -54,9 +58,12 @@ void parse_gpg_output(struct signature_check *sigc)
58 /* The trust messages are not followed by key/signer information */
59 if (sigc->result != 'U') {
60 sigc->key = xmemdupz(found, 16);
57 - found += 17;
58 - next = strchrnul(found, '\n');
59 - sigc->signer = xmemdupz(found, next - found);
61 + /* The ERRSIG message is not followed by signer information */
62 + if (sigc-> result != 'E') {
63 + found += 17;
64 + next = strchrnul(found, '\n');
65 + sigc->signer = xmemdupz(found, next - found);
66 + }
67 }
68 }
69 }
pretty.c
+4
@@ -1232,8 +1232,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1232 switch (c->signature_check.result) {
1233 case 'G':
1234 case 'B':
1235 + case 'E':
1236 case 'U':
1237 case 'N':
1238 + case 'X':
1239 + case 'Y':
1240 + case 'R':
1241 strbuf_addch(sb, c->signature_check.result);
1242 }
1243 break;
t/t7510-signed-commit.sh
+12 -1
@@ -2,6 +2,7 @@
2
3 test_description='signed commit tests'
4 . ./test-lib.sh
5 +GNUPGHOME_NOT_USED=$GNUPGHOME
6 . "$TEST_DIRECTORY/lib-gpg.sh"
7
8 test_expect_success GPG 'create signed commits' '
@@ -190,7 +191,7 @@ test_expect_success GPG 'show bad signature with custom format' '
191 test_cmp expect actual
192 '
193
193 -test_expect_success GPG 'show unknown signature with custom format' '
194 +test_expect_success GPG 'show untrusted signature with custom format' '
195 cat >expect <<-\EOF &&
196 U
197 61092E85B7227189
@@ -200,6 +201,16 @@ test_expect_success GPG 'show unknown signature with custom format' '
201 test_cmp expect actual
202 '
203
204 +test_expect_success GPG 'show unknown signature with custom format' '
205 + cat >expect <<-\EOF &&
206 + E
207 + 61092E85B7227189
208 +
209 + EOF
210 + GNUPGHOME="$GNUPGHOME_NOT_USED" git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
211 + test_cmp expect actual
212 +'
213 +
214 test_expect_success GPG 'show lack of signature with custom format' '
215 cat >expect <<-\EOF &&
216 N