From bdd2fd518bac805e379ab6b23cc450d257d524fa Mon Sep 17 00:00:00 2001 From: Colomban Wendling <ban@herbesfolles.org> Date: Wed, 16 Nov 2016 22:39:53 +0100 Subject: [PATCH 6/7] daemon: Add a hack to find subkeys identities The SeahorseContext does not contain PGP subkeys IDs, so is unable to find the object corresponding to them. This is problematic for example for finding the identity corresponding to a signing key if that key ID is a subkey of the primary PGP key. For the moment, add a hack to search through all PGP keys and check whether they have a corresponding ID when the normal hash table lookup failed. A better solution might be registering the subkey IDs in the context's hash table so that the normal lookup would find the corresponding key. However, such a change is not trivial as each module is not responsible for registering with a specific ID but only for reporting one single ID corresponding to the key to add. Also, registering subkey IDs might have more deep incidence on other code, which makes it a riskier change when not being familiar with the code base. https://bugzilla.gnome.org/show_bug.cgi?id=774611 --- daemon/seahorse-context.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/daemon/seahorse-context.c b/daemon/seahorse-context.c index 0601c079..78eb676b 100644 --- a/daemon/seahorse-context.c +++ b/daemon/seahorse-context.c @@ -850,6 +850,13 @@ seahorse_context_get_objects (SeahorseContext *self, SeahorseSource *source) return seahorse_context_find_objects_full (self, &pred); } +static gboolean +predicate_pgp_subkey (SeahorseObject *obj, void *user_data) +{ + return (SEAHORSE_IS_PGP_KEY (obj) && + seahorse_pgp_key_has_keyid ((SeahorsePgpKey *) obj, user_data)); +} + /** * seahorse_context_find_object: * @sctx: The #SeahorseContext to work with (can be NULL) @@ -871,6 +878,25 @@ seahorse_context_find_object (SeahorseContext *sctx, GQuark id, SeahorseLocation g_return_val_if_fail (SEAHORSE_IS_CONTEXT (sctx), NULL); sobj = (SeahorseObject*)g_hash_table_lookup (sctx->pv->objects_by_type, GUINT_TO_POINTER (id)); + /* FIXME: hack for PGP subkeys: we just search all PGP keys and look for a + * matching subkey. Ugly, but meh. */ + if (! sobj) { + SeahorseObjectPredicate pred = { 0 }; + + pred.custom = predicate_pgp_subkey; + pred.custom_target = (gpointer) g_quark_to_string (id); + if (g_str_has_prefix (pred.custom_target, "openpgp:")) { + GList *objects; + + pred.custom_target += 8; /* strip "openpgp:" prefix */ + objects = seahorse_context_find_objects_full (sctx, &pred); + if (objects) { + sobj = objects->data; + g_warn_if_fail (objects->next == NULL); + g_list_free (objects); + } + } + } while (sobj) { /* If at the end and no more objects in list, return */ -- 2.17.0