]> the.earth.li Git - onak.git/commitdiff
Pass a keydb context into cleankeys in preparation for signature checks
authorJonathan McDowell <noodles@earth.li>
Wed, 28 Aug 2019 07:20:03 +0000 (08:20 +0100)
committerJonathan McDowell <noodles@earth.li>
Wed, 28 Aug 2019 07:20:03 +0000 (08:20 +0100)
In order to validate signatures cleankeys() will need to do key lookups
of the signing keys. Plumb in the database context in preparation for
this.

cgi/add.c
cgi/lookup.c
cleankey.c
cleankey.h
keydb/keydb_stacked.c
onak.c
stripkey.c

index e17d3d9b2f18c05599502013ce54d2db6e4adfde..5775e81ce3f209702ac25a5620920e612360a212 100644 (file)
--- a/cgi/add.c
+++ b/cgi/add.c
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
                        catchsignals();
                        dbctx = config.dbinit(config.backend, false);
                        
-                       count = cleankeys(&keys, config.clean_policies);
+                       count = cleankeys(dbctx, &keys, config.clean_policies);
                        logthing(LOGTHING_INFO, "%d keys cleaned.",
                                        count);
 
index 35c039bf906c8c9d59e8706e052261f9dd481cc9..5977ad0fd838ec0b2a225b7988e680106ddf371c 100644 (file)
@@ -252,7 +252,8 @@ int main(int argc, char *argv[])
                                        result,
                                        search);
                                puts("<pre>");
-                               cleankeys(&publickey, config.clean_policies);
+                               cleankeys(dbctx, &publickey,
+                                               config.clean_policies);
                                flatten_publickey(publickey,
                                                        &packets,
                                                        &list_end);
index 52d482a486dac01eed5adab5b84f150f7a0ca222..55e3161d0d87bb35ebb7d6be2826c919a6571fff 100644 (file)
@@ -255,7 +255,8 @@ int clean_large_packets(struct openpgp_publickey *key)
  *     made, otherwise the number of keys cleaned. Note that some options
  *     may result in keys being removed entirely from the list.
  */
-int cleankeys(struct openpgp_publickey **keys, uint64_t policies)
+int cleankeys(struct onak_dbctx *dbctx, struct openpgp_publickey **keys,
+               uint64_t policies)
 {
        struct openpgp_publickey **curkey, *tmp;
        int changed = 0, count = 0;
index 22a7e45c94c58b65f5c8ecc7558f90afe7de1b8c..4671d207b15cbfa15fac511386d93626e9d2c7ae 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef __CLEANKEY_H__
 #define __CLEANKEY_H__
 
+#include "keydb.h"
 #include "keystructs.h"
 
 #define ONAK_CLEAN_CHECK_SIGHASH       (1 << 0)
@@ -29,6 +30,7 @@
 
 /**
  *     cleankeys - Apply all available cleaning options on a list of keys.
+ *     @dbctx: A database context suitable for looking up signing keys
  *     @publickey: The list of keys to clean.
  *     @policies: The cleaning policies to apply.
  *
@@ -38,6 +40,7 @@
  *     made, otherwise the number of keys cleaned. Note that some options
  *     may result in keys being removed entirely from the list.
  */
-int cleankeys(struct openpgp_publickey **keys, uint64_t policies);
+int cleankeys(struct onak_dbctx *dbctx, struct openpgp_publickey **keys,
+               uint64_t policies);
 
 #endif
index 7e997d99d08cf784bc48e29e7f5d4f67fb502ebc..6cfb1f76eed1b073a84b2926337ad7820b41a2b2 100644 (file)
@@ -118,7 +118,7 @@ static void store_on_fallback(struct onak_stacked_dbctx *privctx,
                        (struct onak_dbctx *) privctx->backends->object;
        struct openpgp_publickey *curkey;
 
-       cleankeys(&publickey, config.clean_policies);
+       cleankeys(backend, &publickey, config.clean_policies);
        /*
         * If we walked the stack at all, store the key in the first
         * backend if configured to do so. It's not an update as we
diff --git a/onak.c b/onak.c
index 030d46819bf6c5198655b57203cf2ebf27ee1cfa..717402ee41137e0e90aa6862d87c8a4396d3f552 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -234,11 +234,12 @@ int main(int argc, char *argv[])
                        logthing(LOGTHING_INFO, "Finished reading %d keys.",
                                        result);
 
-                       result = cleankeys(&keys, config.clean_policies);
+                       dbctx = config.dbinit(config.backend, false);
+                       result = cleankeys(dbctx, &keys,
+                                       config.clean_policies);
                        logthing(LOGTHING_INFO, "%d keys cleaned.",
                                        result);
 
-                       dbctx = config.dbinit(config.backend, false);
                        logthing(LOGTHING_NOTICE, "Got %d new keys.",
                                        dbctx->update_keys(dbctx, &keys,
                                                &config.blacklist,
@@ -275,6 +276,7 @@ int main(int argc, char *argv[])
                        logthing(LOGTHING_NOTICE, "No changes.");
                }
        } else if (!strcmp("clean", argv[optind])) {
+               dbctx = config.dbinit(config.backend, true);
                if (binary) {
                        result = read_openpgp_stream(stdin_getchar, NULL,
                                 &packets, 0);
@@ -292,7 +294,7 @@ int main(int argc, char *argv[])
                                        result);
 
                        if (keys != NULL) {
-                               result = cleankeys(&keys,
+                               result = cleankeys(dbctx, &keys,
                                                config.clean_policies);
                                logthing(LOGTHING_INFO, "%d keys cleaned.",
                                                result);
@@ -322,6 +324,7 @@ int main(int argc, char *argv[])
                        free_publickey(keys);
                        keys = NULL;
                }
+               dbctx->cleanupdb(dbctx);
        } else if (!strcmp("dumpconfig", argv[optind])) {
                if ((argc - optind) == 2) {
                        writeconfig(argv[optind + 1]);
@@ -462,7 +465,7 @@ int main(int argc, char *argv[])
                        if (dbctx->fetch_key_id(dbctx, keyid, &keys, true)) {
                                get_fingerprint(keys->publickey, &fingerprint);
                                dbctx->delete_key(dbctx, &fingerprint, true);
-                               cleankeys(&keys, config.clean_policies);
+                               cleankeys(dbctx, &keys, config.clean_policies);
                                dbctx->store_key(dbctx, keys, true, false);
                        } else {
                                puts("Key not found");
index 5579236cdedb143faf0deeed22d2a5e8289d8d9b..af1578472a174aa5356ba287e9efdd50b2f70f6d 100644 (file)
@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
   parse_keys( packets, &keys );
   free_packet_list(packets);
   packets = NULL;
-  cleankeys(&keys, ONAK_CLEAN_ALL);
+  cleankeys(NULL, &keys, ONAK_CLEAN_ALL);
   /* Iterate over the keys... */
   for( key = keys; key; key = key->next ) {
     uint64_t keyid;