[Pkg-gnupg-commit] [gnupg2] 169/241: gpg: When comparing keyids, use the keyid, not the fingerprint's suffix.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Dec 9 20:32:12 UTC 2015
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit e9c16fee2576c772de9d4fb5d53fee28e4b84202
Author: Neal H. Walfield <neal at g10code.com>
Date: Tue Nov 24 13:03:24 2015 +0100
gpg: When comparing keyids, use the keyid, not the fingerprint's suffix.
* g10/keyedit.c (menu_select_key): Use spacep and hexdigitp instead of
inline tests. Don't compare P to the suffix of the fingerprint. If P
appears to be a keyid, do an exact compare against the keyid. If it
appears to be a fingerprint, do an exact compare against the
fingerprint.
--
Signed-off-by: Neal H. Walfield <neal at g10code.com>
---
g10/keyedit.c | 53 +++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 41 insertions(+), 12 deletions(-)
diff --git a/g10/keyedit.c b/g10/keyedit.c
index 1511c17..9cf6f44 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -4916,15 +4916,20 @@ menu_select_key (KBNODE keyblock, int idx, char *p)
is_hex_digits = p && strlen (p) >= 8;
if (is_hex_digits)
{
+ /* Skip initial spaces. */
+ while (spacep (p))
+ p ++;
+ /* If the id starts with 0x accept and ignore it. */
+ if (p[0] == '0' && p[1] == 'x')
+ p += 2;
+
for (i = 0, j = 0; p[i]; i ++)
- if (('0' <= p[i] && p[i] <= '9')
- || ('A' <= p[i] && p[i] <= 'F')
- || ('a' <= p[i] && p[i] <= 'f'))
+ if (hexdigitp (&p[i]))
{
p[j] = toupper (p[i]);
j ++;
}
- else if (p[i] == ' ')
+ else if (spacep (&p[i]))
/* Skip spaces. */
{
}
@@ -4939,7 +4944,13 @@ menu_select_key (KBNODE keyblock, int idx, char *p)
p[j] = 0;
/* If we skipped some spaces, make sure that we still have
at least 8 characters. */
- is_hex_digits = strlen (p) >= 8;
+ is_hex_digits = (/* Short keyid. */
+ strlen (p) == 8
+ /* Long keyid. */
+ || strlen (p) == 16
+ /* Fingerprints are (currently) 32 or 40
+ characters. */
+ || strlen (p) >= 32);
}
}
@@ -4950,14 +4961,32 @@ menu_select_key (KBNODE keyblock, int idx, char *p)
if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY
|| node->pkt->pkttype == PKT_SECRET_SUBKEY)
{
- char fp[2*MAX_FINGERPRINT_LEN + 1];
- hexfingerprint (node->pkt->pkt.public_key, fp, sizeof (fp));
- if (strcmp (&fp[strlen (fp) - strlen (p)], p) == 0)
+ int match = 0;
+ if (strlen (p) == 8 || strlen (p) == 16)
{
- if ((node->flag & NODFLG_SELKEY))
- node->flag &= ~NODFLG_SELKEY;
- else
- node->flag |= NODFLG_SELKEY;
+ u32 kid[2];
+ char kid_str[17];
+ keyid_from_pk (node->pkt->pkt.public_key, kid);
+ format_keyid (kid, strlen (p) == 8 ? KF_SHORT : KF_LONG,
+ kid_str, sizeof (kid_str));
+
+ if (strcmp (p, kid_str) == 0)
+ match = 1;
+ }
+ else
+ {
+ char fp[2*MAX_FINGERPRINT_LEN + 1];
+ hexfingerprint (node->pkt->pkt.public_key, fp, sizeof (fp));
+ if (strcmp (fp, p) == 0)
+ match = 1;
+ }
+
+ if (match)
+ {
+ if ((node->flag & NODFLG_SELKEY))
+ node->flag &= ~NODFLG_SELKEY;
+ else
+ node->flag |= NODFLG_SELKEY;
found_one = 1;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list