Re: [PATCH] show s/mime keyid for successfully checked signatures
"Kevin J. McCarthy" <[email protected]> Fri, 3 Jul 2026 10:34:08 +0800
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <[email protected]> |
--kDGDZpjoqevACj10 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 02, 2026 at 10:26:32PM +0200, Robert J=C3=A4schke via Mutt-dev = wrote: >Thank you. That's a good idea. In principle, it's working. > >PGP example: > >> [-- Begin signature information --] >> Good signature from: Kevin J. McCarthy <[email protected]> >> Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA >> created: Thu Jul 2 09:15:12 2026 >> WARNING: It is NOT certain that the key belongs to the person named as s= hown above >> [-- End signature information --] > >S/MIME example: > >> [-- Begin signature information --] >> Good signature from: 1.2.840.113549.1.9.1=3D#726F626572742E6A61657363686= B654068752D6265726C696E2E6465,CN=3DRobert >> +Jaeschke,2.5.4.42=3D#526F62657274,2.5.4.4=3D#4A61657363686B65,2.5.4.97= =3D#474F5644452B4245,O=3DHumboldt-Universitaet zu Berlin,ST=3DBerlin,C=3DDE >> aka: <[email protected]> >> Fingerprint: E4:76:AD:AA:61:4A:7E:1C:FD:C3:D5:D1:7F:37:8D:99:80:76:E6:16 >> created: Wed Jul 1 10:36:10 2026 >> [-- End signature information --] > >So only the alignment needs to be fixed, which I did by modifying >show_fingerprint() (I had to add the "msg" argument which is not nice >but since the function is used only once, that could be fine.) I agree. It's not pretty, but since it's only called once it should be=20 okay. > >So here are my two patches (thanks also to Alejandro for the tipps to >improve my code): Please move the helper function back inside crypt-gpgme.c and make it a static function there. There is no reason to put it in curs_lib.c, as I mentioned before. Otherwise this looks good. Thank you for the work. >-- >8 -- >Subject: [PATCH 1/2] refactored alignment of strings into function > >--- > crypt-gpgme.c | 19 +++---------------- > curs_lib.c | 11 +++++++++++ > protos.h | 1 + > 3 files changed, 15 insertions(+), 16 deletions(-) > >diff --git a/crypt-gpgme.c b/crypt-gpgme.c >index ccae5503..4e0be87f 100644 >--- a/crypt-gpgme.c >+++ b/crypt-gpgme.c >@@ -1619,9 +1619,8 @@ static void show_one_sig_validity(gpgme_ctx_t ctx, i= nt idx, STATE *s) > static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, > gpgme_key_t key, STATE *s) > { >- int msgwid; > gpgme_user_id_t uids =3D NULL; >- int i, aka =3D 0; >+ int aka =3D 0; > > state_puts(msg, s); > state_puts(" ", s); >@@ -1633,14 +1632,7 @@ static void print_smime_keyinfo(const char *msg, gp= gme_signature_t sig, > if (uids->revoked) > continue; > if (aka) >- { >- msgwid =3D mutt_strwidth(msg) - mutt_strwidth(_("aka: ")) + 1; >- if (msgwid < 0) >- msgwid =3D 0; >- for (i =3D 0; i < msgwid; i++) >- state_puts(" ", s); >- state_puts(_("aka: "), s); >- } >+ mutt_align_to_msg(msg, _("aka: "), s); > state_puts(uids->uid, s); > state_puts("\n", s); > >@@ -1666,12 +1658,7 @@ static void print_smime_keyinfo(const char *msg, gp= gme_signature_t sig, > "Jan 1 1970" is not the created date. */ > if (sig->timestamp) > { >- msgwid =3D mutt_strwidth(msg) - mutt_strwidth(_("created: ")) + 1; >- if (msgwid < 0) >- msgwid =3D 0; >- for (i =3D 0; i < msgwid; i++) >- state_puts(" ", s); >- state_puts(_("created: "), s); >+ mutt_align_to_msg(msg, _("created: "), s); > print_time(sig->timestamp, s); > state_puts("\n", s); > } >diff --git a/curs_lib.c b/curs_lib.c >index 5c93cbb0..9cf1b76f 100644 >--- a/curs_lib.c >+++ b/curs_lib.c >@@ -1654,3 +1654,14 @@ int mutt_strwidth(const char *s) > } > return w; > } >+ >+void mutt_align_to_msg(const char *msg, const char *key, STATE *s) >+{ >+ int msgwid =3D mutt_strwidth(msg) - mutt_strwidth(_(key)) + 1; >+ >+ if (msgwid < 0) >+ msgwid =3D 0; >+ for (int i =3D 0; i < msgwid; i++) >+ state_puts(" ", s); >+ state_puts(key, s); >+} >diff --git a/protos.h b/protos.h >index 4958aa0e..3dad301d 100644 >--- a/protos.h >+++ b/protos.h >@@ -407,6 +407,7 @@ int mutt_smtp_send(const ADDRESS *, const ADDRESS *, c= onst ADDRESS *, > size_t mutt_wstr_trunc(const char *, size_t, size_t, size_t *); > int mutt_charlen(const char *s, int *); > int mutt_strwidth(const char *); >+void mutt_align_to_msg(const char *msg, const char *key, STATE *s); > int mutt_compose_menu(SEND_CONTEXT *); > int mutt_thread_set_flag(HEADER *, int, int, int); > int mutt_user_is_recipient(HEADER *); >--=20 >2.47.3 > >-- >8 -- >Subject: [PATCH 2/2] show s/mime keyid for successfully checked signatures > >--- > crypt-gpgme.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > >diff --git a/crypt-gpgme.c b/crypt-gpgme.c >index 4e0be87f..5fa7b7e5 100644 >--- a/crypt-gpgme.c >+++ b/crypt-gpgme.c >@@ -1528,12 +1528,11 @@ static int show_sig_summary(unsigned long sum, > } > > >-static void show_fingerprint(gpgme_key_t key, STATE *state) >+static void show_fingerprint(const char *msg, gpgme_key_t key, STATE *sta= te) > { > const char *s; > int i, is_pgp; > char *buf, *p; >- const char *prefix =3D _("Fingerprint: "); > > if (!key) > return; >@@ -1542,9 +1541,9 @@ static void show_fingerprint(gpgme_key_t key, STATE = *state) > return; > is_pgp =3D (key->protocol =3D=3D GPGME_PROTOCOL_OpenPGP); > >- buf =3D safe_malloc( strlen(prefix) + strlen(s) * 4 + 2 ); >- strcpy(buf, prefix); /* __STRCPY_CHECKED__ */ >- p =3D buf + strlen(buf); >+ mutt_align_to_msg(msg, _("Fingerprint: "), state); >+ buf =3D safe_malloc( strlen(s) * 4 + 2 ); >+ p =3D buf; > if (is_pgp && strlen(s) =3D=3D 40) > { /* PGP v4 style formatted. */ > for (i=3D0; *s && s[1] && s[2] && s[3] && s[4]; s +=3D 4, i++) >@@ -1638,6 +1637,8 @@ static void print_smime_keyinfo(const char *msg, gpg= me_signature_t sig, > > aka =3D 1; > } >+ >+ show_fingerprint(msg, key, s); > } > else > { >@@ -1755,7 +1756,6 @@ static int show_one_sig_status(gpgme_ctx_t ctx, int = idx, STATE *s) > ultimate). */ > print_smime_keyinfo(_("Good signature from:"), sig, key, s); > show_one_sig_validity(ctx, idx, s); >- show_fingerprint(key,s); > if (show_sig_summary(sum, ctx, key, idx, s, sig)) > anywarn =3D 1; > } >--=20 >2.47.3 > > --=20 Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA --kDGDZpjoqevACj10 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEiXWpszqjeRA4XFMIre92hIAxa9oFAmpHH6AACgkQre92hIAx a9olEhAA3mDrsiCq/yAR0QtZh2dDIq7LAbnadtarKQv+l2BeebasdrRmm6xL1Bct 4lnxHNz0RXNXr10kuvFZPdqNXTDlvuTbxUkd06PzkQiQR+yf4+hUM3ZZV3TSs6/z QrgG8uAzcrodkPoG9hwZIbTZF0HFoXn1x+kuran+wFlZjq9k7W8MH/dsp+pCjlcj auuQDwHO5Q07MLtslcc3asPXJMzAYGDqVt4rLYrLyEpAsZAW7DUbYtjdFMiA+WOH aMIW8XkafeJ112N7SouESjkaLuudB5NvwLny8ikwk335vKFyFhOXD3r/2CcZ2cA6 MRwQ3FBiJXJVA4s7noE7iq3MoSkLYtBOpW+OB/4Ga6Ao5mT93/jkDZeJrtB7RMBj 8D64wRp+Kmro1v0j4RVFXA32D5F5WdxUwOfjMm3zQo3o2kXwWoABZjqYVcyWlOlI 3betndzwWhAkntn9TyrEItLYuxBKEXx72BI50hAj3CA+EEYgEx+nPOkA8qKD4xUm Py9cl6GGNG34AFBmcAZJRlTWd2xeM8Szzb/PNhfqteDpz1z+iHUduo5EWfvULdgF kXmh1rsHimcQZ3z/LdtGmOCMJYlm9yCvDUw0gv9F121AK++Y3rHF8hu7Cf5+Uxfg oMZwp0nvQvrt0c+vWHzwN48jjz3Rji4Vh4sJvXOpZSsYIyd4hS4= =Um1X -----END PGP SIGNATURE----- --kDGDZpjoqevACj10--