From: Tom Grennan <tom.grennan@ericsson.com>
To: git@vger.kernel.org
Cc: jasampler@gmail.com
Subject: [RFC/PATCH] verify-tag: check sig of all tags to given object
Date: Fri, 3 Feb 2012 17:25:51 -0800 [thread overview]
Message-ID: <1328318751-4470-1-git-send-email-tom.grennan@ericsson.com> (raw)
If the command argument is a non-tag object, scan and verify all tags to
the given object; for example:
john$ git tag -s -m "I approve" john-README master:README
...
john$ git tag -s -m "I recommend" john-HEAD HEAD
...
john$ git push <url> tag john-README
john$ git push <url> tag john-HEAD
jane$ git fetch --tags <url>
jane$ git tag -s -m "I also approve" jane-README master:README
...
jane$ git push <url> tag jane-README
jeff$ git fetch --tags <url>
jeff$ git verify-tag master:README
tag john-README: OK
tag jane-README: OK
jeff$ git verify-tag HEAD
tag john-HEAD: OK
Signed-off-by: Tom Grennan <tom.grennan@ericsson.com>
---
Documentation/git-verify-tag.txt | 6 +++-
builtin/verify-tag.c | 53 +++++++++++++++++++++++++++++++++++---
2 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-verify-tag.txt b/Documentation/git-verify-tag.txt
index 5ff76e8..ce47f95 100644
--- a/Documentation/git-verify-tag.txt
+++ b/Documentation/git-verify-tag.txt
@@ -8,7 +8,7 @@ git-verify-tag - Check the GPG signature of tags
SYNOPSIS
--------
[verse]
-'git verify-tag' <tag>...
+'git verify-tag' <object>...
DESCRIPTION
-----------
@@ -20,8 +20,10 @@ OPTIONS
--verbose::
Print the contents of the tag object before validating it.
-<tag>...::
+<object>...::
SHA1 identifiers of git tag objects.
+ For non-tag objects, scan and verify all tags to the given
+ object.
GIT
---
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 28c2174..df9e93c 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -7,6 +7,7 @@
*/
#include "cache.h"
#include "builtin.h"
+#include "refs.h"
#include "tag.h"
#include "run-command.h"
#include <signal.h>
@@ -14,7 +15,7 @@
#include "gpg-interface.h"
static const char * const verify_tag_usage[] = {
- "git verify-tag [-v|--verbose] <tag>...",
+ "git verify-tag [-v|--verbose] <object>...",
NULL
};
@@ -32,6 +33,46 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
return verify_signed_buffer(buf, len, buf + len, size - len, NULL);
}
+struct obj_filter {
+ const unsigned char *sha1;
+ int verbose;
+ struct strbuf sb;
+};
+
+static int verify_tag_of_obj(const char *refname, const unsigned char *sha1,
+ int flag, void *cb_data)
+{
+ struct obj_filter *obj = cb_data;
+ enum object_type type;
+ unsigned long size;
+ int len, ret;
+ char *buf = NULL;
+ unsigned char tagged_sha1[20];
+
+ if ((type = sha1_object_info(sha1, NULL), type == OBJ_TAG) \
+ && (buf = read_sha1_file(sha1, &type, &size), buf) \
+ && !memcmp("object ", buf, 7) \
+ && !get_sha1_hex(buf + 7, tagged_sha1) \
+ && buf[47] == '\n' \
+ && !memcmp(obj->sha1, tagged_sha1, 20) \
+ && (len = parse_signature(buf, size), len != size)) {
+ strbuf_reset(&obj->sb);
+ ret = verify_signed_buffer(buf, len, buf + len, size - len,
+ &obj->sb);
+ if (obj->verbose) {
+ write_in_full(1, buf, len);
+ write_in_full(1, obj->sb.buf, obj->sb.len);
+ } else if (ret) {
+ printf("tag %s: FAILED\n", refname);
+ write_in_full(1, obj->sb.buf, obj->sb.len);
+ } else
+ printf("tag %s: OK\n", refname);
+ }
+ if (buf)
+ free(buf);
+ return 0;
+}
+
static int verify_tag(const char *name, int verbose)
{
enum object_type type;
@@ -44,9 +85,13 @@ static int verify_tag(const char *name, int verbose)
return error("tag '%s' not found.", name);
type = sha1_object_info(sha1, NULL);
- if (type != OBJ_TAG)
- return error("%s: cannot verify a non-tag object of type %s.",
- name, typename(type));
+ if (type != OBJ_TAG) {
+ struct obj_filter obj = { sha1, verbose };
+ strbuf_init(&obj.sb, 4096);
+ for_each_tag_ref(verify_tag_of_obj, (void *) &obj);
+ strbuf_release(&obj.sb);
+ return 0;
+ }
buf = read_sha1_file(sha1, &type, &size);
if (!buf)
--
1.7.9.dirty
next reply other threads:[~2012-02-04 1:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-04 1:25 Tom Grennan [this message]
2012-02-04 3:16 ` [RFC/PATCH] verify-tag: check sig of all tags to given object Junio C Hamano
[not found] ` <D140688E-B86C-4A67-9AD6-56160C26884D@ericsson.com>
2012-02-04 5:08 ` Tom Grennan
2012-02-04 5:22 ` Junio C Hamano
2012-02-04 5:56 ` Tom Grennan
2012-02-04 6:20 ` Junio C Hamano
2012-02-04 6:49 ` Tom Grennan
2012-02-04 5:16 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328318751-4470-1-git-send-email-tom.grennan@ericsson.com \
--to=tom.grennan@ericsson.com \
--cc=git@vger.kernel.org \
--cc=jasampler@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).