summaryrefslogtreecommitdiffstats
path: root/common/userids.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-03-14 08:54:59 +0100
committerWerner Koch <wk@gnupg.org>2019-03-14 11:26:54 +0100
commitf40e9d6a528521d12795e1a6cc15c849b216be92 (patch)
treebebe6f71b5d00e8dda7d67dae3b3f4e27e12a815 /common/userids.c
parentgpg: Implemented latest rfc4880bis version 5 packet hashing. (diff)
downloadgnupg2-f40e9d6a528521d12795e1a6cc15c849b216be92.tar.xz
gnupg2-f40e9d6a528521d12795e1a6cc15c849b216be92.zip
kbx: Add support for 32 byte fingerprints.
* common/userids.c (classify_user_id): Support 32 byte fingerprints. * kbx/keybox-search-desc.h (KEYDB_SEARCH_MODE_FPR32): New. (struct keydb_search_desc): Add field fprlen. * kbx/keybox-defs.h (struct _keybox_openpgp_key_info): Add field version and increase size of fpr to 32. * kbx/keybox-blob.c: Define new version 2 for PGP and X509 blobs. (struct keyboxblob_key): Add field fprlen and increase size of fpr. (pgp_create_key_part_single): Allow larger fingerprints. (create_blob_header): Implement blob version 2 and add arg want_fpr32. (_keybox_create_openpgp_blob): Detect the need for blob version 2. * kbx/keybox-search.c (blob_get_first_keyid): Support 32 byte fingerprints. (blob_cmp_fpr): Ditto. (blob_cmp_fpr_part): Ditto. (has_fingerprint): Add arg fprlen and pass on. (keybox_search): Support KEYDB_SEARCH_MODE_FPR32 and adjust for changed has_fingerprint. * kbx/keybox-openpgp.c (parse_key): Support version 5 keys. * kbx/keybox-dump.c (_keybox_dump_blob): Support blob version 2. * g10/delkey.c (do_delete_key): Support KEYDB_SEARCH_MODE_FPR32. * g10/export.c (exact_subkey_match_p): Ditto. * g10/gpg.c (main): Ditto. * g10/getkey.c (get_pubkey_byfprint): Adjust for changed KEYDB_SEARCH_MODE_FPR. * g10/keydb.c (keydb_search_desc_dump): Support KEYDB_SEARCH_MODE_FPR32 and adjust for changed KEYDB_SEARCH_MODE_FPR. (keydb_search): Add new arg fprlen and change all callers. * g10/keyedit.c (find_by_primary_fpr): Ditto. * g10/keyid.c (keystr_from_desc): Ditto. * g10/keyring.c (keyring_search): Ditto. * g10/keyserver.c (print_keyrec): Ditto. (parse_keyrec): Ditto. (keyserver_export): Ditto. (keyserver_retrieval_screener): Ditto. (keyserver_import): Ditto. (keyserver_import_fprint): Ditto. (keyidlist): Ditto. (keyserver_get_chunk): Ditto. * g10/keydb.c (keydb_search): Add new arg fprlen and change all callers. * sm/keydb.c (keydb_search_fpr): Adjust for changed KEYDB_SEARCH_MODE_FPR. -- This prepares the support for OpenPGP v5 keys. The new version 2 blob format is needed for the longer fingerprints and we also use this opportunity to prepare for storing the keygrip in the blob for faster lookup by keygrip. Right now this is not yet functional. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'common/userids.c')
-rw-r--r--common/userids.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/common/userids.c b/common/userids.c
index 01f2cd84b..41cf2876c 100644
--- a/common/userids.c
+++ b/common/userids.c
@@ -226,14 +226,15 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack)
goto out;
}
}
- if (i != 32 && i != 40)
+ if (i != 32 && i != 40 && i != 64)
{
rc = gpg_error (GPG_ERR_INV_USER_ID); /* Invalid length of fpr. */
goto out;
}
for (i=0,si=s; si < se; i++, si +=2)
desc->u.fpr[i] = hextobyte(si);
- for (; i < 20; i++)
+ desc->fprlen = i;
+ for (; i < 32; i++)
desc->u.fpr[i]= 0;
mode = KEYDB_SEARCH_MODE_FPR;
}
@@ -326,6 +327,8 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack)
}
desc->u.fpr[i] = c;
}
+ for (; i < 32; i++)
+ desc->u.fpr[i]= 0;
mode = KEYDB_SEARCH_MODE_FPR16;
}
else if ((hexlength == 40
@@ -333,7 +336,7 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack)
|| (s[hexlength] == '!' && s[hexlength + 1] == 0)))
|| (!hexprefix && hexlength == 41 && *s == '0'))
{
- /* SHA1/RMD160 fingerprint. */
+ /* SHA1 fingerprint. */
int i;
if (hexlength == 41)
s++;
@@ -347,8 +350,31 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack)
}
desc->u.fpr[i] = c;
}
+ for (; i < 32; i++)
+ desc->u.fpr[i]= 0;
mode = KEYDB_SEARCH_MODE_FPR20;
}
+ else if ((hexlength == 64
+ && (s[hexlength] == 0
+ || (s[hexlength] == '!' && s[hexlength + 1] == 0)))
+ || (!hexprefix && hexlength == 65 && *s == '0'))
+ {
+ /* SHA256 fingerprint. */
+ int i;
+ if (hexlength == 65)
+ s++;
+ for (i=0; i < 32; i++, s+=2)
+ {
+ int c = hextobyte(s);
+ if (c == -1)
+ {
+ rc = gpg_error (GPG_ERR_INV_USER_ID);
+ goto out;
+ }
+ desc->u.fpr[i] = c;
+ }
+ mode = KEYDB_SEARCH_MODE_FPR32;
+ }
else if (!hexprefix)
{
/* The fingerprint in an X.509 listing is often delimited by
@@ -368,14 +394,17 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack)
}
if (i == 20)
mode = KEYDB_SEARCH_MODE_FPR20;
+ for (; i < 32; i++)
+ desc->u.fpr[i]= 0;
}
if (!mode)
{
/* Still not found. Now check for a space separated
- OpenPGP v4 fingerprint like:
- 8061 5870 F5BA D690 3336 86D0 F2AD 85AC 1E42 B367
- or
- 8061 5870 F5BA D690 3336 86D0 F2AD 85AC 1E42 B367
+ * OpenPGP v4 fingerprint like:
+ * 8061 5870 F5BA D690 3336 86D0 F2AD 85AC 1E42 B367
+ * or
+ * 8061 5870 F5BA D690 3336 86D0 F2AD 85AC 1E42 B367
+ * FIXME: Support OpenPGP v5 fingerprint
*/
hexlength = strspn (s, " 0123456789abcdefABCDEF");
if (s[hexlength] && s[hexlength] != ' ')
@@ -410,6 +439,8 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack)
}
if (i == 20)
mode = KEYDB_SEARCH_MODE_FPR20;
+ for (; i < 32; i++)
+ desc->u.fpr[i]= 0;
}
}
if (!mode) /* Default to substring search. */