[PATCH] gpgme_key_sig_t: Add the signing key’s fingerprint as fpr
Philip Withnall
philip at tecnocode.co.uk
Mon Oct 26 16:59:06 CET 2026
As described in
https://github.com/gpg/gnupg/blob/master/doc/DETAILS (field 13),
the signing key’s fingerprint is available unless the signature could
not be verified, so this does not fully replace the keyid field.
However, when available, the fpr field will be useful for associating
key signatures with their signing keys without worrying about key ID
collisions.
This includes some tests following the pattern of the existing tests.
Signed-off-by: Philip Withnall <pwithnall at gnome.org>
---
doc/gpgme.texi | 4 ++++
src/gpgme.h.in | 4 ++++
src/json-core.c | 1 +
src/key.c | 1 +
src/keylist.c | 9 +++++++++
tests/gpg/t-keylist-sig.c | 27 ++++++++++++++++++++++++---
tests/run-keylist.c | 1 +
7 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index dc4adf2e..856d4904 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -3966,6 +3966,10 @@ This is the email component of @code{uid}, if available.
@item gpgme_sig_notation_t notations
This is a linked list with the notation data and policy URLs.
+
+ at item char *fpr
+The fingerprint of the key used to create the signature, if available. It might
+not be available if the signature doesn’t verify.
@end table
@end deftp
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 54c5c900..c8fb3379 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -755,6 +755,10 @@ struct _gpgme_key_sig
/* The scope of a trust signature. Might be NULL. */
char *trust_scope;
+
+ /* The fingerprint of the key used to create the signature. Might be NULL if
+ * the signature didn’t verify correctly. */
+ char *fpr;
};
diff --git a/src/json-core.c b/src/json-core.c
index f04d062b..806765eb 100644
--- a/src/json-core.c
+++ b/src/json-core.c
@@ -622,6 +622,7 @@ key_sig_to_json (gpgme_key_sig_t sig)
xjson_AddStringToObject0 (result, "pubkey_algo_name",
gpgme_pubkey_algo_name (sig->pubkey_algo));
xjson_AddStringToObject0 (result, "keyid", sig->keyid);
+ xjson_AddStringToObject0 (result, "fpr", sig->fpr);
xjson_AddStringToObject0 (result, "status", gpgme_strerror (sig->status));
xjson_AddStringToObject0 (result, "name", sig->name);
xjson_AddStringToObject0 (result, "email", sig->email);
diff --git a/src/key.c b/src/key.c
index 7e6165a7..2cfbcd79 100644
--- a/src/key.c
+++ b/src/key.c
@@ -413,6 +413,7 @@ gpgme_key_unref (gpgme_key_t key)
}
free (keysig->trust_scope);
+ free (keysig->fpr);
free (keysig);
keysig = next_keysig;
}
diff --git a/src/keylist.c b/src/keylist.c
index 06a0de7f..6543f756 100644
--- a/src/keylist.c
+++ b/src/keylist.c
@@ -1094,6 +1094,15 @@ keylist_colon_handler (void *priv, char *line)
keysig->exportable = 1;
}
+ /* Field 13 has the fingerprint, but it may only be filled if the
+ * signature verified correctly. */
+ if (fields >= 13 && field[12] && *field[12])
+ {
+ keysig->fpr = strdup (field[12]);
+ if (!keysig->fpr)
+ return gpg_error_from_syserror ();
+ }
+
opd->tmp_keysig = keysig;
break;
diff --git a/tests/gpg/t-keylist-sig.c b/tests/gpg/t-keylist-sig.c
index 250214c1..74a9d002 100644
--- a/tests/gpg/t-keylist-sig.c
+++ b/tests/gpg/t-keylist-sig.c
@@ -47,6 +47,7 @@ struct
{
gpgme_pubkey_algo_t algo;
const char *keyid;
+ const char *fpr;
const char *name;
const char *comment;
const char *email;
@@ -59,13 +60,13 @@ keys[] =
{
{ "A0FF4590BB6122EDEF6E3C542D727CC768697734", "6AE6D7EE46A871F8",
{ { "Alfa Test", "demo key", "alfa at example.net",
- { GPGME_PK_DSA, "2D727CC768697734",
+ { GPGME_PK_DSA, "2D727CC768697734", "A0FF4590BB6122EDEF6E3C542D727CC768697734",
"Alfa Test", "demo key", "alfa at example.net", 19, 1 } },
{ "Alpha Test", "demo key", "alpha at example.net",
- { GPGME_PK_DSA, "2D727CC768697734",
+ { GPGME_PK_DSA, "2D727CC768697734", NULL,
"Alfa Test", "demo key", "alfa at example.net", 19, 1 } },
{ "Alice", "demo key", NULL,
- { GPGME_PK_DSA, "2D727CC768697734",
+ { GPGME_PK_DSA, "2D727CC768697734", "A0FF4590BB6122EDEF6E3C542D727CC768697734",
"Alfa Test", "demo key", "alfa at example.net", 19, 1 } } } },
{ NULL }
};
@@ -393,6 +394,12 @@ main (void)
key->uids->signatures->keyid);
exit (1);
}
+ if (strcmp (keys[i].uid[0].sig.fpr, key->uids->signatures->fpr))
+ {
+ fprintf (stderr, "Unexpected fingerprint in first user ID sig: %s\n",
+ key->uids->signatures->fpr);
+ exit (1);
+ }
if (strcmp (keys[i].uid[0].sig.name, key->uids->signatures->name))
{
fprintf (stderr, "Unexpected name in first user ID sig: %s\n",
@@ -482,6 +489,14 @@ main (void)
key->uids->next->signatures->keyid);
exit (1);
}
+ if ((key->uids->next->signatures->fpr == NULL) != (keys[i].uid[1].sig.fpr == NULL) ||
+ (key->uids->next->signatures->fpr != NULL &&
+ strcmp (keys[i].uid[1].sig.fpr, key->uids->next->signatures->fpr)))
+ {
+ fprintf (stderr, "Unexpected fingerprint in second user ID sig: %s\n",
+ key->uids->next->signatures->fpr);
+ exit (1);
+ }
if (strcmp (keys[i].uid[1].sig.name, key->uids->next->signatures->name))
{
fprintf (stderr, "Unexpected name in second user ID sig: %s\n",
@@ -571,6 +586,12 @@ main (void)
key->uids->next->next->signatures->keyid);
exit (1);
}
+ if (strcmp (keys[i].uid[2].sig.fpr, key->uids->next->next->signatures->fpr))
+ {
+ fprintf (stderr, "Unexpected fingerprint in third user ID sig: %s\n",
+ key->uids->next->next->signatures->fpr);
+ exit (1);
+ }
if (strcmp (keys[i].uid[2].sig.name, key->uids->next->next->signatures->name))
{
fprintf (stderr, "Unexpected name in third user ID sig: %s\n",
diff --git a/tests/run-keylist.c b/tests/run-keylist.c
index 44a16596..e5ab98d7 100644
--- a/tests/run-keylist.c
+++ b/tests/run-keylist.c
@@ -426,6 +426,7 @@ main (int argc, char **argv)
{
printf ("signature %d: %s\n", nsigs, nonnull (ks->uid));
printf (" keyid: %s\n", nonnull (ks->keyid));
+ printf (" fpr: %s\n", nonnull (ks->fpr));
printf (" created: %s\n", isotimestr(ks->timestamp));
printf (" expires: %s\n", isotimestr(ks->expires));
printf (" class: %x\n", ks->sig_class);
--
2.56.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20261026/eea58464/attachment.sig>
More information about the Gnupg-devel
mailing list