verify-tag: add option to print raw gpg status information
verify-tag by default displays human-readable output on standard error. However, it can also be useful to get access to the raw gpg status information, which is machine-readable, allowing automated implementation of signing policy. Add a --raw option to make verify-tag produce the gpg status information on standard error instead of the human-readable format. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jun 21, 2015 at 23:14 UTC
e18443ece711564145d545b650851c4615717128
3 files changed
+46
-6
Documentation/git-verify-tag.txt
+4
@@ -16,6 +16,10 @@ Validates the gpg signature created by 'git tag'.
16
17
OPTIONS
18
-------
19
+--raw::
20
+ Print the raw gpg status output to standard error instead of the normal
21
+ human-readable output.
22
+
23
-v::
24
--verbose::
25
Print the contents of the tag object before validating it.
builtin/verify-tag.c
+11
-6
@@ -18,7 +18,7 @@ static const char * const verify_tag_usage[] = {
18
NULL
19
};
20
21
-static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
21
+static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
22
{
23
struct signature_check sigc;
24
int len;
@@ -29,19 +29,19 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
29
len = parse_signature(buf, size);
30
31
if (size == len) {
32
- if (verbose)
32
+ if (flags & GPG_VERIFY_VERBOSE)
33
write_in_full(1, buf, len);
34
return error("no signature found");
35
}
36
37
ret = check_signature(buf, len, buf + len, size - len, &sigc);
38
- print_signature_buffer(&sigc, verbose ? GPG_VERIFY_VERBOSE : 0);
38
+ print_signature_buffer(&sigc, flags);
39
40
signature_check_clear(&sigc);
41
return ret;
42
}
43
44
-static int verify_tag(const char *name, int verbose)
44
+static int verify_tag(const char *name, unsigned flags)
45
{
46
enum object_type type;
47
unsigned char sha1[20];
@@ -61,7 +61,7 @@ static int verify_tag(const char *name, int verbose)
61
if (!buf)
62
return error("%s: unable to read file.", name);
63
64
- ret = run_gpg_verify(buf, size, verbose);
64
+ ret = run_gpg_verify(buf, size, flags);
65
66
free(buf);
67
return ret;
@@ -78,8 +78,10 @@ static int git_verify_tag_config(const char *var, const char *value, void *cb)
78
int cmd_verify_tag(int argc, const char **argv, const char *prefix)
79
{
80
int i = 1, verbose = 0, had_error = 0;
81
+ unsigned flags = 0;
82
const struct option verify_tag_options[] = {
83
OPT__VERBOSE(&verbose, N_("print tag contents")),
84
+ OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
85
OPT_END()
86
};
87
@@ -90,11 +92,14 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
92
if (argc <= i)
93
usage_with_options(verify_tag_usage, verify_tag_options);
94
95
+ if (verbose)
96
+ flags |= GPG_VERIFY_VERBOSE;
97
+
98
/* sometimes the program was terminated because this signal
99
* was received in the process of writing the gpg input: */
100
signal(SIGPIPE, SIG_IGN);
101
while (i < argc)
97
- if (verify_tag(argv[i++], verbose))
102
+ if (verify_tag(argv[i++], flags))
103
had_error = 1;
104
return had_error;
105
}
t/t7030-verify-tag.sh
+31
@@ -81,4 +81,35 @@ test_expect_success GPG 'detect fudged signature' '
81
! grep "Good signature from" actual1
82
'
83
84
+test_expect_success GPG 'verify signatures with --raw' '
85
+ (
86
+ for tag in initial second merge fourth-signed sixth-signed seventh-signed
87
+ do
88
+ git verify-tag --raw $tag 2>actual &&
89
+ grep "GOODSIG" actual &&
90
+ ! grep "BADSIG" actual &&
91
+ echo $tag OK || exit 1
92
+ done
93
+ ) &&
94
+ (
95
+ for tag in fourth-unsigned fifth-unsigned sixth-unsigned
96
+ do
97
+ test_must_fail git verify-tag --raw $tag 2>actual &&
98
+ ! grep "GOODSIG" actual &&
99
+ ! grep "BADSIG" actual &&
100
+ echo $tag OK || exit 1
101
+ done
102
+ ) &&
103
+ (
104
+ for tag in eighth-signed-alt
105
+ do
106
+ git verify-tag --raw $tag 2>actual &&
107
+ grep "GOODSIG" actual &&
108
+ ! grep "BADSIG" actual &&
109
+ grep "TRUST_UNDEFINED" actual &&
110
+ echo $tag OK || exit 1
111
+ done
112
+ )
113
+'
114
+
115
test_done