summaryrefslogtreecommitdiffstats
path: root/kbx/backend-kbx.c
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 /kbx/backend-kbx.c
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 'kbx/backend-kbx.c')
-rw-r--r--kbx/backend-kbx.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/kbx/backend-kbx.c b/kbx/backend-kbx.c
index d8dafe0e5..ff4f56773 100644
--- a/kbx/backend-kbx.c
+++ b/kbx/backend-kbx.c
@@ -271,15 +271,15 @@ be_kbx_search (ctrl_t ctrl, backend_handle_t backend_hd, db_request_t request,
void *buffer;
size_t buflen;
enum pubkey_types pubkey_type;
- unsigned char blobid[20];
+ unsigned char ubid[UBID_LEN];
- err = keybox_get_data (part->kbx_hd, &buffer, &buflen, &pubkey_type);
+ err = keybox_get_data (part->kbx_hd, &buffer, &buflen,
+ &pubkey_type, ubid);
if (err)
goto leave;
- gcry_md_hash_buffer (GCRY_MD_SHA1, blobid, buffer, buflen);
- err = be_return_pubkey (ctrl, buffer, buflen, pubkey_type, blobid);
+ err = be_return_pubkey (ctrl, buffer, buflen, pubkey_type, ubid);
if (!err)
- be_cache_pubkey (ctrl, blobid, buffer, buflen, pubkey_type);
+ be_cache_pubkey (ctrl, ubid, buffer, buflen, pubkey_type);
xfree (buffer);
}
@@ -295,8 +295,7 @@ be_kbx_search (ctrl_t ctrl, backend_handle_t backend_hd, db_request_t request,
* operation starts right after that UBID. */
gpg_error_t
be_kbx_seek (ctrl_t ctrl, backend_handle_t backend_hd,
- db_request_t request, const unsigned char *ubid,
- const unsigned char *fpr, unsigned int fprlen)
+ db_request_t request, const unsigned char *ubid)
{
gpg_error_t err;
db_request_part_t part;
@@ -310,19 +309,8 @@ be_kbx_seek (ctrl_t ctrl, backend_handle_t backend_hd,
log_assert (request);
memset (&desc, 0, sizeof desc);
- if (ubid)
- {
- desc.mode = KEYDB_SEARCH_MODE_FPR;
- memcpy (desc.u.ubid, ubid, 20);
- }
- else
- {
- if (fprlen > sizeof desc.u.fpr)
- return gpg_error (GPG_ERR_TOO_LARGE);
- desc.mode = KEYDB_SEARCH_MODE_FPR;
- memcpy (desc.u.fpr, fpr, fprlen);
- desc.fprlen = fprlen;
- }
+ desc.mode = KEYDB_SEARCH_MODE_UBID;
+ memcpy (desc.u.ubid, ubid, UBID_LEN);
/* Find the specific request part or allocate it. */
err = be_find_request_part (backend_hd, request, &part);