From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Elijah Newren <newren@gmail.com>,
Jeff King <peff@peff.net>,
"brian m . carlson" <sandals@crustytoothpaste.net>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Christian Couder <christian.couder@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH v2 6/6] verify-commit: add a --summary flag
Date: Mon, 26 May 2025 12:33:14 +0200 [thread overview]
Message-ID: <20250526103314.1542316-7-christian.couder@gmail.com> (raw)
In-Reply-To: <20250526103314.1542316-1-christian.couder@gmail.com>
The current outputs, with `--raw`, `--verbose` or by default, from
`git verify-commit` are all quite verbose and do not make it easy to
quickly assess signature status.
Let's add a new `--summary` option to `git verify-commit` that prints
a concise, one-line summary of the signature verification to standard
output.
This compact format is useful for scripts and tools that need to
quickly parse signature verification results, while still being
human-readable.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Documentation/git-verify-commit.adoc | 17 ++++++++++++++++-
builtin/verify-commit.c | 4 +++-
gpg-interface.c | 11 +++++++++++
gpg-interface.h | 6 ++++++
t/t7510-signed-commit.sh | 24 ++++++++++++++++++++++++
t/t7528-signed-commit-ssh.sh | 28 ++++++++++++++++++++++++++++
6 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-verify-commit.adoc b/Documentation/git-verify-commit.adoc
index 6a208a0c2a..fb038ae0cf 100644
--- a/Documentation/git-verify-commit.adoc
+++ b/Documentation/git-verify-commit.adoc
@@ -8,7 +8,7 @@ git-verify-commit - Check the signature of commits
SYNOPSIS
--------
[verse]
-'git verify-commit' [-v | --verbose] [--raw] <commit>...
+'git verify-commit' [-v | --verbose] [--raw] [--summary] <commit>...
DESCRIPTION
-----------
@@ -38,6 +38,21 @@ OPTIONS
error instead of the normal human-readable output. The format
of this output is specific to the signature format being used.
+--summary::
+ Print a one-line human-readable summary of the signature check
+ to standard output in the format: `STATUS FORMAT ALGORITHM`.
++
+STATUS is the result character (e.g., G, B, E, U, N, ...) shown by the
+"%G?" pretty format specifier. See the "Pretty Formats" section in
+linkgit:git-log[1].
++
+FORMAT indicates the signature format (`openpgp`, `x509`, or `ssh`) or
+`?` if unknown.
++
+ALGORITHM is the hash algorithm used for GPG/GPGSM signatures
+(e.g. `sha1`, `sha256`, ...), or the key type for SSH signatures
+(`RSA`, `ECDSA`, `ED25519`, ...), or `?` if unknown.
+
-v::
--verbose::
Print the contents of the commit object before validating it.
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 5f749a30da..54b5b7d360 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -14,7 +14,7 @@
#include "gpg-interface.h"
static const char * const verify_commit_usage[] = {
- N_("git verify-commit [-v | --verbose] [--raw] <commit>..."),
+ N_("git verify-commit [-v | --verbose] [--raw] [--summary] <commit>..."),
NULL
};
@@ -27,6 +27,7 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)
ret = check_commit_signature(commit, &signature_check);
print_signature_buffer(&signature_check, flags);
+ print_signature_summary(&signature_check, flags);
signature_check_clear(&signature_check);
return ret;
@@ -60,6 +61,7 @@ int cmd_verify_commit(int argc,
const struct option verify_commit_options[] = {
OPT__VERBOSE(&verbose, N_("print commit contents")),
OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
+ OPT_BIT(0, "summary", &flags, N_("print concise signature verification summary"), GPG_VERIFY_SUMMARY),
OPT_END()
};
diff --git a/gpg-interface.c b/gpg-interface.c
index 182e579769..fc198715c4 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -153,6 +153,7 @@ void signature_check_clear(struct signature_check *sigc)
FREE_AND_NULL(sigc->key);
FREE_AND_NULL(sigc->fingerprint);
FREE_AND_NULL(sigc->primary_key_fingerprint);
+ FREE_AND_NULL(sigc->format_name);
FREE_AND_NULL(sigc->sig_algo);
}
@@ -756,6 +757,8 @@ int check_signature(struct signature_check *sigc,
if (!fmt)
die(_("bad/incompatible signature '%s'"), signature);
+ sigc->format_name = xstrdup(fmt->name);
+
if (parse_payload_metadata(sigc))
return 1;
@@ -782,6 +785,14 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
fputs(output, stderr);
}
+void print_signature_summary(const struct signature_check *sigc, unsigned flags)
+{
+ if (flags & GPG_VERIFY_SUMMARY)
+ printf("%c %s %s\n", sigc->result,
+ sigc->format_name ? sigc->format_name : "?",
+ sigc->sig_algo ? sigc->sig_algo : "?");
+}
+
size_t parse_signed_buffer(const char *buf, size_t size)
{
size_t len = 0;
diff --git a/gpg-interface.h b/gpg-interface.h
index 2b7701ca2c..a9565757f6 100644
--- a/gpg-interface.h
+++ b/gpg-interface.h
@@ -6,6 +6,7 @@ struct strbuf;
#define GPG_VERIFY_VERBOSE (1<<0)
#define GPG_VERIFY_RAW (1<<1)
#define GPG_VERIFY_OMIT_STATUS (1<<2)
+#define GPG_VERIFY_SUMMARY (1<<3)
enum signature_trust_level {
TRUST_UNDEFINED,
@@ -43,6 +44,9 @@ struct signature_check {
char *fingerprint;
char *primary_key_fingerprint;
+ /* "openpgp", "x509", "ssh" */
+ char *format_name;
+
/* hash algo for GPG/GPGSM, key type for SSH */
char *sig_algo;
@@ -95,5 +99,7 @@ int check_signature(struct signature_check *sigc,
const char *signature, size_t slen);
void print_signature_buffer(const struct signature_check *sigc,
unsigned flags);
+void print_signature_summary(const struct signature_check *sigc,
+ unsigned flags);
#endif
diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh
index 39677e859a..47f40862f3 100755
--- a/t/t7510-signed-commit.sh
+++ b/t/t7510-signed-commit.sh
@@ -232,6 +232,30 @@ test_expect_success GPG2 'bare signature' '
test_cmp expect actual
'
+test_expect_success GPG 'verify signatures with --summary' '
+ # GPG-signed commit
+ git verify-commit --summary sixth-signed >actual &&
+ test_grep "^G openpgp sha1" actual &&
+
+ # Non-signed commit
+ test_must_fail git verify-commit --summary seventh-unsigned >actual 2>&1 &&
+ test_grep "^N ? ?" actual &&
+
+ # Trusted signature with alternate key (hash used might depend on the OS)
+ git verify-commit --summary eighth-signed-alt >actual &&
+ test_grep -E "^G openpgp sha(256|512)" actual &&
+
+ # Bad signature
+ test_must_fail git verify-commit --summary $(cat forged1.commit) >actual 2>err &&
+ test_grep "^B openpgp ?" actual
+'
+
+test_expect_success GPG '--summary and --raw work together' '
+ git verify-commit --summary --raw sixth-signed >actual 2>err &&
+ test_grep "^G openpgp sha1" actual &&
+ test_grep "GOODSIG" err
+'
+
test_expect_success GPG 'show good signature with custom format' '
cat >expect <<-\EOF &&
G
diff --git a/t/t7528-signed-commit-ssh.sh b/t/t7528-signed-commit-ssh.sh
index 065f780636..3d0e7d7859 100755
--- a/t/t7528-signed-commit-ssh.sh
+++ b/t/t7528-signed-commit-ssh.sh
@@ -277,6 +277,34 @@ test_expect_success GPGSSH 'detect fudged signature with NUL' '
! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual2
'
+test_expect_success GPGSSH 'verify-commit --summary outputs format and key type for SSH signatures' '
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+
+ # SSH-signed commit with ED25519 key
+ git verify-commit --summary sixth-signed >actual &&
+ test_grep "^G ssh ED25519" actual &&
+
+ # SSH-signed commit with ECDSA key
+ git verify-commit --summary thirteenth-signed-ecdsa >actual &&
+ test_grep "^G ssh ECDSA" actual &&
+
+ # Non-signed commit
+ test_must_fail git verify-commit --summary seventh-unsigned >actual 2>&1 &&
+ test_grep "^N ? ?" actual &&
+
+ # Bad signature
+ test_must_fail git verify-commit --summary $(cat forged1.commit) >actual 2>err &&
+ test_grep "^B ssh ?" actual
+'
+
+test_expect_success GPGSSH '--summary and --raw work together' '
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+
+ git verify-commit --summary --raw sixth-signed >actual 2>err &&
+ test_grep "^G ssh ED25519" actual &&
+ test_grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" err
+'
+
test_expect_success GPGSSH 'amending already signed commit' '
test_config gpg.format ssh &&
test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
--
2.49.0.609.g63c55177e5
next prev parent reply other threads:[~2025-05-26 10:33 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 20:39 [PATCH] fast-(import|export): improve on the signature algorithm name Christian Couder
2025-04-24 21:19 ` Junio C Hamano
2025-04-24 21:59 ` Elijah Newren
2025-04-24 22:58 ` Junio C Hamano
2025-05-26 10:35 ` Christian Couder
2025-05-27 15:18 ` Junio C Hamano
2025-05-28 17:29 ` Junio C Hamano
2025-05-28 20:06 ` Elijah Newren
2025-05-28 21:59 ` Junio C Hamano
2025-05-28 23:15 ` Elijah Newren
2025-05-29 3:14 ` Junio C Hamano
2025-06-02 15:56 ` Christian Couder
2025-06-02 15:56 ` Christian Couder
2025-06-02 16:20 ` Junio C Hamano
2025-05-26 10:34 ` Christian Couder
2025-04-24 21:41 ` Elijah Newren
2025-05-26 10:34 ` Christian Couder
2025-04-24 22:05 ` brian m. carlson
2025-05-26 10:35 ` Christian Couder
2025-04-24 23:25 ` Junio C Hamano
2025-05-26 10:33 ` [PATCH v2 0/6] extract algo information from signatures Christian Couder
2025-05-26 10:33 ` [PATCH v2 1/6] gpg-interface: simplify ssh fingerprint parsing Christian Couder
2025-05-26 10:33 ` [PATCH v2 2/6] gpg-interface: use left shift to define GPG_VERIFY_* Christian Couder
2025-05-26 10:33 ` [PATCH v2 3/6] doc/verify-commit: update and improve the whole doc Christian Couder
2025-05-26 10:33 ` [PATCH v2 4/6] gpg-interface: extract hash algorithm from signature status output Christian Couder
2025-05-26 10:33 ` [PATCH v2 5/6] gpg-interface: extract SSH key type " Christian Couder
2025-05-26 10:33 ` Christian Couder [this message]
2025-05-26 16:03 ` [PATCH v2 0/6] extract algo information from signatures Elijah Newren
2025-06-19 13:38 ` Christian Couder
2025-06-02 22:17 ` brian m. carlson
2025-06-19 13:37 ` Christian Couder
2025-06-18 15:18 ` [PATCH v3] fast-(import|export): improve on commit signature output format Christian Couder
2025-06-19 13:36 ` [PATCH v4] " Christian Couder
2025-06-19 14:55 ` Junio C Hamano
2025-07-08 9:16 ` Christian Couder
2025-06-19 21:44 ` Elijah Newren
2025-06-20 16:12 ` Christian Couder
2025-06-20 19:20 ` Junio C Hamano
2025-07-08 9:16 ` Christian Couder
2025-06-26 19:11 ` Elijah Newren
2025-07-08 9:16 ` Christian Couder
2025-07-07 22:58 ` Junio C Hamano
2025-07-08 3:35 ` Christian Couder
2025-07-08 5:03 ` Junio C Hamano
2025-07-08 6:38 ` Patrick Steinhardt
2025-07-08 11:08 ` Christian Couder
2025-07-08 16:38 ` Junio C Hamano
2025-07-09 0:19 ` Christian Couder
2025-07-09 15:35 ` Junio C Hamano
2025-07-10 8:25 ` Patrick Steinhardt
2025-07-10 15:29 ` Christian Couder
2025-07-10 15:33 ` Junio C Hamano
2025-07-08 10:17 ` Christian Couder
2025-07-08 9:17 ` [PATCH v5] " Christian Couder
2025-07-08 21:58 ` Junio C Hamano
2025-07-08 23:08 ` Elijah Newren
2025-07-09 0:03 ` Junio C Hamano
2025-07-09 0:10 ` Elijah Newren
2025-07-09 10:18 ` Christian Couder
2025-07-09 10:15 ` Christian Couder
2025-07-09 14:12 ` [PATCH v6] " Christian Couder
2025-07-09 23:14 ` Junio C Hamano
2025-07-14 21:07 ` Elijah Newren
2025-07-14 21:23 ` Junio C Hamano
2025-07-25 16:11 ` Christian Couder
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=20250526103314.1542316-7-christian.couder@gmail.com \
--to=christian.couder@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/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).