aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/backend-support.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-09-27 07:24:58 +0000
committerWerner Koch <[email protected]>2019-09-27 07:24:58 +0000
commit280e9c9cfac31ae5ac874c928eee063cc922e27e (patch)
treecd7c774f8fd8b2fa64d162083d755bcc37aaba7a /kbx/backend-support.c
parentdoc: Minor doc updates and a typo fix. (diff)
downloadgnupg-280e9c9cfac31ae5ac874c928eee063cc922e27e.tar.gz
gnupg-280e9c9cfac31ae5ac874c928eee063cc922e27e.zip
kbx: First take on a cache for the keyboxd.
* kbx/backend.h (enum database_types): Add DB_TYPE_CACHE. (struct db_request_part_s): Add seqno fields. (struct db_request_s): Add infos for the cache backend. * kbx/backend-support.c (struct backend_handle_s): Add 'backend_id'. (strdbtype): Support DB_TYPE_CACHE. (be_generic_release_backend): Ditto. (be_find_request_part): New. (be_return_pubkey): New arg UBID and chnage status name. * kbx/backend-cache.c: New. * kbx/backend-kbx.c (be_kbx_init_request_part): New. (be_kbx_search): Factor some code out to a support function. (be_kbx_seek): New. * kbx/frontend.c (kbxd_add_resource): Support DB_TYPE_CACHE. (kbxd_search): Support the NEXR operation with the cache. * kbx/keybox-search-desc.h (KEYDB_SEARCH_MODE_UBID): New. (struct keydb_search_desc): Add field u.ubid. * kbx/keybox-search.c (has_ubid): New. (keybox_search): Support the UBID search. -- This adds a caching backend to the keyboxd. This tries to accommodate for duplicate use of fingerprints and thus be correct in case a fingerprint is used in several keys. It also turned out that we need to have a unique identifier (UBID) to identify a keyblock or X.509 certificate. In particular with an OpenPGP keyblob we can't easily use the primary fingerprint as an identifier because that fingerprint may also be used as subkey in another key. Thus using a hash of the entire keyblock is a better identifier to be used to address a keyblock for restarting a search or for identifying the keyblock to be updated. Note that this new UBID is not a permanent identifier because it changes with all keyblock update; it should be viewed as a handle to the keyblock or X509 cert.
Diffstat (limited to 'kbx/backend-support.c')
-rw-r--r--kbx/backend-support.c57
1 files changed, 50 insertions, 7 deletions
diff --git a/kbx/backend-support.c b/kbx/backend-support.c
index 28b51875c..62551cafa 100644
--- a/kbx/backend-support.c
+++ b/kbx/backend-support.c
@@ -28,12 +28,15 @@
#include "../common/i18n.h"
#include "../common/asshelp.h"
#include "backend.h"
+#include "keybox.h"
-/* Common definition part of all backend handle. */
+/* Common definition part of all backend handle. All definitions of
+ * this structure must start with these fields. */
struct backend_handle_s
{
enum database_types db_type;
+ unsigned int backend_id;
};
@@ -45,6 +48,7 @@ strdbtype (enum database_types t)
switch (t)
{
case DB_TYPE_NONE: return "none";
+ case DB_TYPE_CACHE:return "cache";
case DB_TYPE_KBX: return "keybox";
}
return "?";
@@ -76,6 +80,9 @@ be_generic_release_backend (ctrl_t ctrl, backend_handle_t hd)
case DB_TYPE_NONE:
xfree (hd);
break;
+ case DB_TYPE_CACHE:
+ be_cache_release_resource (ctrl, hd);
+ break;
case DB_TYPE_KBX:
be_kbx_release_resource (ctrl, hd);
break;
@@ -104,16 +111,53 @@ be_release_request (db_request_t req)
}
+/* Given the backend handle BACKEND_HD and the REQUEST find or
+ * allocate a request part for that backend and store it at R_PART.
+ * On error R_PART is set to NULL and an error returned. */
+gpg_error_t
+be_find_request_part (backend_handle_t backend_hd, db_request_t request,
+ db_request_part_t *r_part)
+{
+ gpg_error_t err;
+ db_request_part_t part;
+
+ for (part = request->part; part; part = part->next)
+ if (part->backend_id == backend_hd->backend_id)
+ break;
+ if (!part)
+ {
+ part = xtrycalloc (1, sizeof *part);
+ if (!part)
+ return gpg_error_from_syserror ();
+ part->backend_id = backend_hd->backend_id;
+ if (backend_hd->db_type == DB_TYPE_KBX)
+ {
+ err = be_kbx_init_request_part (backend_hd, part);
+ if (err)
+ {
+ xfree (part);
+ return err;
+ }
+ }
+ part->next = request->part;
+ request->part = part;
+ }
+ *r_part = part;
+ return 0;
+}
+
+
/* Return the public key (BUFFER,BUFLEN) which has the type
- * PUBVKEY_TYPE to the caller. Owenership of BUFFER is taken by thgis
- * function even in the error case. */
+ * PUBKEY_TYPE to the caller. */
gpg_error_t
-be_return_pubkey (ctrl_t ctrl, void *buffer, size_t buflen,
- enum pubkey_types pubkey_type)
+be_return_pubkey (ctrl_t ctrl, const void *buffer, size_t buflen,
+ enum pubkey_types pubkey_type, const unsigned char *ubid)
{
gpg_error_t err;
+ char hexubid[41];
- err = status_printf (ctrl, "PUBKEY_TYPE", "%d", pubkey_type);
+ bin2hex (ubid, 20, hexubid);
+ err = status_printf (ctrl, "PUBKEY_INFO", "%d %s", pubkey_type, hexubid);
if (err)
goto leave;
@@ -123,6 +167,5 @@ be_return_pubkey (ctrl_t ctrl, void *buffer, size_t buflen,
err = kbxd_write_data_line(ctrl, buffer, buflen);
leave:
- xfree (buffer);
return err;
}