aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/kbxserver.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-11-28 08:39:35 +0000
committerWerner Koch <[email protected]>2019-11-28 10:16:13 +0000
commit915297705af6f1db74dacf0d6665b83eb0a58459 (patch)
tree7e7cdc2f55f3d7d218a90f9eada3327a4dc534ff /kbx/kbxserver.c
parentdirmngr: Replace no-strict-overflow pragma by wrapv pragma. (diff)
downloadgnupg-915297705af6f1db74dacf0d6665b83eb0a58459.tar.gz
gnupg-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 <[email protected]>
Diffstat (limited to 'kbx/kbxserver.c')
-rw-r--r--kbx/kbxserver.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/kbx/kbxserver.c b/kbx/kbxserver.c
index 0da937f39..511362004 100644
--- a/kbx/kbxserver.c
+++ b/kbx/kbxserver.c
@@ -466,29 +466,38 @@ cmd_next (assuan_context_t ctx, char *line)
static const char hlp_store[] =
- "STORE [--update]\n"
+ "STORE [--update|--insert]\n"
"\n"
"Insert a key into the database. Whether to insert or update\n"
"the key is decided by looking at the primary key's fingerprint.\n"
- "With option --update the key must already exist. The actual key\n"
- "material is requested by this function using\n"
+ "With option --update the key must already exist.\n"
+ "With option --insert the key must not already exist.\n"
+ "The actual key material is requested by this function using\n"
" INQUIRE BLOB";
static gpg_error_t
cmd_store (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
- int opt_update;
+ int opt_update, opt_insert;
+ enum kbxd_store_modes mode;
gpg_error_t err;
unsigned char *value = NULL;
size_t valuelen;
opt_update = has_option (line, "--update");
+ opt_insert = has_option (line, "--insert");
line = skip_options (line);
if (*line)
{
err = set_error (GPG_ERR_INV_ARG, "no args expected");
goto leave;
}
+ if (opt_update && !opt_insert)
+ mode = KBXD_STORE_UPDATE;
+ else if (!opt_update && opt_insert)
+ mode = KBXD_STORE_INSERT;
+ else
+ mode = KBXD_STORE_AUTO;
/* Ask for the key material. */
err = assuan_inquire (ctx, "BLOB", &value, &valuelen, 0);
@@ -504,7 +513,7 @@ cmd_store (assuan_context_t ctx, char *line)
goto leave;
}
- err = kbxd_store (ctrl, value, valuelen, opt_update);
+ err = kbxd_store (ctrl, value, valuelen, mode);
leave: