summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-11-28 09:39:35 +0100
committerWerner Koch <wk@gnupg.org>2019-11-28 11:16:13 +0100
commit915297705af6f1db74dacf0d6665b83eb0a58459 (patch)
tree7e7cdc2f55f3d7d218a90f9eada3327a4dc534ff /g10
parentdirmngr: Replace no-strict-overflow pragma by wrapv pragma. (diff)
downloadgnupg2-915297705af6f1db74dacf0d6665b83eb0a58459.tar.xz
gnupg2-915297705af6f1db74dacf0d6665b83eb0a58459.zip
kbx: Redefine the UBID which is now the primary fingerprint.
* common/util.h (UBID_LEN): New. Use it at all places. * kbx/keybox-blob.c (create_blob_finish): Do not write the UBID item. * kbx/keybox-dump.c (print_ubib): Remove. (_keybox_dump_blob): Do not print the now removed ubid flag. * kbx/keybox-search-desc.h (struct keydb_search_desc): Use constants for the size of the ubid and grip. * kbx/keybox-search.c (blob_cmp_ubid): New. (has_ubid): Make it a simple wrapper around blob_cmp_ubid. (keybox_get_data): Add arg 'r_ubid'. * kbx/frontend.h (enum kbxd_store_modes): New. * kbx/kbxserver.c (cmd_store): Add new option --insert. * kbx/backend-cache.c (be_cache_initialize): New. (be_cache_add_resource): Call it here. * kbx/backend-kbx.c (be_kbx_seek): Remove args 'fpr' and 'fprlen'. (be_kbx_search): Get the UBID from keybox_get_data. * kbx/backend-support.c (be_fingerprint_from_blob): Replace by ... (be_ubid_from_blob): new. Change all callers. * kbx/frontend.c (kbxd_add_resource): Temporary disable the cache but use the new cache init function. (kbxd_store): Replace arg 'only_update' by 'mode'. Seek using the ubid. Take care of the mode. -- It turned out that using the hash of the entire blob was not helpful. Thus we redefine the Unique-Blob-ID (UBID) as the primary fingerprint of the blob. In case this is a v5 OpenPGP key a left truncated version of the SHA-256 hash is used; in all other cases the full SHA-1 hash. Using a SHA-256 hash does not make sense because v4 keys are and will for some time be the majority of keys and thus padding them with zeroes won't make any difference. Even if fingerprint collisions can eventually be created we will assume that the keys are bogus and that it does not make sense to store its twin also in our key storage. We can also easily extend the update code to detect a collision and reject the update. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'g10')
-rw-r--r--g10/call-keyboxd.c4
-rw-r--r--g10/keydb-private.h2
-rw-r--r--g10/keydb.c8
3 files changed, 7 insertions, 7 deletions
diff --git a/g10/call-keyboxd.c b/g10/call-keyboxd.c
index 9625587ac..99dfac58f 100644
--- a/g10/call-keyboxd.c
+++ b/g10/call-keyboxd.c
@@ -1049,8 +1049,8 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
case KEYDB_SEARCH_MODE_UBID:
{
- unsigned char hexubid[20 * 2 + 1];
- bin2hex (desc[0].u.grip, 20, hexubid);
+ unsigned char hexubid[UBID_LEN * 2 + 1];
+ bin2hex (desc[0].u.grip, UBID_LEN, hexubid);
snprintf (line, sizeof line, "SEARCH ^%s", hexubid);
}
break;
diff --git a/g10/keydb-private.h b/g10/keydb-private.h
index 47a09ca93..fdc905edf 100644
--- a/g10/keydb-private.h
+++ b/g10/keydb-private.h
@@ -100,7 +100,7 @@ struct keydb_handle_s
unsigned int last_ubid_valid:1;
/* The UBID of the last returned keyblock. */
- unsigned char last_ubid[20];
+ unsigned char last_ubid[UBID_LEN];
/* END USE_KEYBOXD */
diff --git a/g10/keydb.c b/g10/keydb.c
index 57d51e7b7..bf411371e 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -456,8 +456,8 @@ keydb_search_desc_dump (struct keydb_search_desc *desc)
char b[MAX_FORMATTED_FINGERPRINT_LEN + 1];
char fpr[2 * MAX_FINGERPRINT_LEN + 1];
-#if MAX_FINGERPRINT_LEN < 20
-#error MAX_FINGERPRINT_LEN shorter than GRIP and UBID length/
+#if MAX_FINGERPRINT_LEN < UBID_LEN || MAX_FINGERPRINT_LEN < KEYGRIP_LEN
+#error MAX_FINGERPRINT_LEN is shorter than KEYGRIP or UBID length.
#endif
switch (desc->mode)
@@ -499,10 +499,10 @@ keydb_search_desc_dump (struct keydb_search_desc *desc)
case KEYDB_SEARCH_MODE_SUBJECT:
return xasprintf ("SUBJECT: '%s'", desc->u.name);
case KEYDB_SEARCH_MODE_KEYGRIP:
- bin2hex (desc[0].u.grip, 20, fpr);
+ bin2hex (desc[0].u.grip, KEYGRIP_LEN, fpr);
return xasprintf ("KEYGRIP: %s", fpr);
case KEYDB_SEARCH_MODE_UBID:
- bin2hex (desc[0].u.ubid, 20, fpr);
+ bin2hex (desc[0].u.ubid, UBID_LEN, fpr);
return xasprintf ("UBID: %s", fpr);
case KEYDB_SEARCH_MODE_FIRST:
return xasprintf ("FIRST");