]> the.earth.li Git - onak.git/commitdiff
Add option to only accept updates for existing keys
authorJonathan McDowell <noodles@earth.li>
Wed, 21 Aug 2019 17:56:57 +0000 (18:56 +0100)
committerJonathan McDowell <noodles@earth.li>
Wed, 21 Aug 2019 17:56:57 +0000 (18:56 +0100)
It's plausible in a curated keyring scenario where a keyserver should
accept updates to existing keys (new signatures, updated expiries, new
subkeys) but no entirely new keys. Add a configuration file option which
enforces this behaviour.

cgi/add.c
cleankey.h
keydb.c
keydb.h
keydb_dynamic.c
keydb_keyring.c
keydb_stacked.c
onak-conf.c
onak.c
onak.ini.in
t/all-036-update-only.t [new file with mode: 0755]

index 02eb3eb00703a1bca1bff3e4b20b10e8cb37f304..e17d3d9b2f18c05599502013ce54d2db6e4adfde 100644 (file)
--- a/cgi/add.c
+++ b/cgi/add.c
@@ -93,7 +93,9 @@ int main(int argc, char *argv[])
                                        count);
 
                        count = dbctx->update_keys(dbctx, &keys,
-                                       &config.blacklist, true);
+                               &config.blacklist,
+                               config.clean_policies & ONAK_CLEAN_UPDATE_ONLY,
+                               true);
                        logthing(LOGTHING_NOTICE, "Got %d new keys.",
                                count);
 
index 834b6225766b57f4edebb6c7bf1cae7a8fe5e941..22a7e45c94c58b65f5c8ecc7558f90afe7de1b8c 100644 (file)
@@ -24,6 +24,7 @@
 #define ONAK_CLEAN_CHECK_SIGHASH       (1 << 0)
 #define ONAK_CLEAN_LARGE_PACKETS       (1 << 1)
 #define ONAK_CLEAN_DROP_V3_KEYS                (1 << 2)
+#define ONAK_CLEAN_UPDATE_ONLY         (1 << 3)
 #define ONAK_CLEAN_ALL                 (uint64_t) -1
 
 /**
diff --git a/keydb.c b/keydb.c
index f362b1adddf3e59fc338ea686e9b70c89992b331..f6b9682f2d4b4ade0db0494fbf4c4b312a80171e 100644 (file)
--- a/keydb.c
+++ b/keydb.c
@@ -159,6 +159,8 @@ struct ll *generic_cached_getkeysigs(struct onak_dbctx *dbctx, uint64_t keyid)
 /**
  *     update_keys - Takes a list of public keys and updates them in the DB.
  *     @keys: The keys to update in the DB.
+ *     @blacklist: A keyarray of key fingerprints not to accept.
+ *     @updateonly: Only update existing keys, don't add new ones.
  *     @sendsync: Should we send a sync mail to our peers.
  *
  *     Takes a list of keys and adds them to the database, merging them with
@@ -170,12 +172,13 @@ struct ll *generic_cached_getkeysigs(struct onak_dbctx *dbctx, uint64_t keyid)
 int generic_update_keys(struct onak_dbctx *dbctx,
                struct openpgp_publickey **keys,
                struct keyarray *blacklist,
+               bool updateonly,
                bool sendsync)
 {
        struct openpgp_publickey **curkey, *tmp = NULL;
        struct openpgp_publickey *oldkey = NULL;
        struct openpgp_fingerprint fp;
-       int newkeys = 0;
+       int newkeys = 0, ret;
        bool intrans;
 
        curkey = keys;
@@ -192,10 +195,13 @@ int generic_update_keys(struct onak_dbctx *dbctx,
 
                intrans = dbctx->starttrans(dbctx);
 
-               logthing(LOGTHING_INFO,
-                       "Fetching key, result: %d",
-                       dbctx->fetch_key_fp(dbctx, &fp, &oldkey,
-                                       intrans));
+               ret = dbctx->fetch_key_fp(dbctx, &fp, &oldkey, intrans);
+               if (ret == 0 && updateonly) {
+                       logthing(LOGTHING_INFO,
+                               "Skipping new key as update only set.");
+                       curkey = &(*curkey)->next;
+                       goto next;
+               }
 
                /*
                 * If we already have the key stored in the DB then merge it
@@ -228,6 +234,7 @@ int generic_update_keys(struct onak_dbctx *dbctx,
                        newkeys++;
                        curkey = &(*curkey)->next;
                }
+next:
                dbctx->endtrans(dbctx);
        }
 
diff --git a/keydb.h b/keydb.h
index a1078c76afd423963965613515c6a3aca3365386..7297a7664b39fe53ceccefb23c791951acfb586a 100644 (file)
--- a/keydb.h
+++ b/keydb.h
@@ -141,6 +141,7 @@ struct onak_dbctx {
  * @brief Takes a list of public keys and updates them in the DB.
  * @param keys The keys to update in the DB.
  * @param blacklist A keyarray of fingerprints that shouldn't be added.
+ * @updateonly: Only update existing keys, don't add new ones.
  * @param sendsync If we should send a keysync mail.
  *
  * Takes a list of keys and adds them to the database, merging them with
@@ -155,6 +156,7 @@ struct onak_dbctx {
        int (*update_keys)(struct onak_dbctx *,
                        struct openpgp_publickey **keys,
                        struct keyarray *blacklist,
+                       bool updateonly,
                        bool sendsync);
 
 /**
index cf9d87fa030af270ae48bacfa154e139c6a7577a..385c09cbb5ef3600e2b9e9a59a79b61d423f4c03 100644 (file)
@@ -122,13 +122,14 @@ static int dynamic_delete_key(struct onak_dbctx *dbctx,
 static int dynamic_update_keys(struct onak_dbctx *dbctx,
                struct openpgp_publickey **keys,
                struct keyarray *blacklist,
+               bool updateonly,
                bool sendsync)
 {
        struct onak_dynamic_dbctx *privctx =
                        (struct onak_dynamic_dbctx *) dbctx->priv;
 
        return privctx->loadeddbctx->update_keys(privctx->loadeddbctx,
-                       keys, blacklist, sendsync);
+                       keys, blacklist, updateonly, sendsync);
 }
 
 static struct ll *dynamic_getkeysigs(struct onak_dbctx *dbctx,
index 0f24366d05864106527d1721010bb1da68b49db5..9550434c612d5b027f3cf4a369b001d696d8e9fe 100644 (file)
@@ -224,6 +224,7 @@ static int keyring_iterate_keys(struct onak_dbctx *dbctx,
 static int keyring_update_keys(struct onak_dbctx *dbctx,
                struct openpgp_publickey **keys,
                struct keyarray *blacklist,
+               bool updateonly,
                bool sendsync)
 {
        return 0;
index b702c84b97a41d152f909e13deeac57e48cd518a..7e997d99d08cf784bc48e29e7f5d4f67fb502ebc 100644 (file)
@@ -87,6 +87,7 @@ static int stacked_delete_key(struct onak_dbctx *dbctx,
 static int stacked_update_keys(struct onak_dbctx *dbctx,
                struct openpgp_publickey **keys,
                struct keyarray *blacklist,
+               bool updateonly,
                bool sendsync)
 {
        struct onak_stacked_dbctx *privctx =
@@ -94,7 +95,8 @@ static int stacked_update_keys(struct onak_dbctx *dbctx,
        struct onak_dbctx *backend =
                        (struct onak_dbctx *) privctx->backends->object;
 
-       return backend->update_keys(backend, keys, blacklist, sendsync);
+       return backend->update_keys(backend, keys, blacklist, updateonly,
+                       sendsync);
 }
 
 static int stacked_iterate_keys(struct onak_dbctx *dbctx,
index f0768a0f11657f008ccf8623e7f3a9a82493233d..a67c950432e2c05322eff4de91f43a37b01059ad 100644 (file)
@@ -313,6 +313,15 @@ static bool parseconfigline(char *line)
                                config.clean_policies &=
                                        ~ONAK_CLEAN_LARGE_PACKETS;
                        }
+               } else if (MATCH("verification", "update_only")) {
+                       if (parsebool(value, config.clean_policies &
+                                       ONAK_CLEAN_UPDATE_ONLY)) {
+                               config.clean_policies |=
+                                       ONAK_CLEAN_UPDATE_ONLY;
+                       } else {
+                               config.clean_policies &=
+                                       ~ONAK_CLEAN_UPDATE_ONLY;
+                       }
                } else {
                        return false;
                }
diff --git a/onak.c b/onak.c
index 70f54348ccf39b5fa733b37425f523ef0ba04b72..030d46819bf6c5198655b57203cf2ebf27ee1cfa 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -242,6 +242,8 @@ int main(int argc, char *argv[])
                        logthing(LOGTHING_NOTICE, "Got %d new keys.",
                                        dbctx->update_keys(dbctx, &keys,
                                                &config.blacklist,
+                                               (config.clean_policies &
+                                                ONAK_CLEAN_UPDATE_ONLY),
                                                false));
                        if (keys != NULL && update) {
                                flatten_publickey(keys,
index a9745cd4a38c125ab5c42a27e4acad0f575552c5..dc68e1f0173f6df9a8d8aea404313787d66ef93d 100644 (file)
@@ -25,6 +25,10 @@ check_sighash=true
 ; Drop v3 (and older) keys. These are long considered insecure, so unless there
 ; is a good reason you should accept this default.
 drop_v3=true
+; Only allow keys that already exist to be update; silently drop the addition
+; of any key we don't already know about. Useful for allowing updates to
+; curated keys without the addition of new keys.
+;update_only=false
 
 ; Settings related to the email interface to onak.
 [mail]
diff --git a/t/all-036-update-only.t b/t/all-036-update-only.t
new file mode 100755 (executable)
index 0000000..e0b3027
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Check we can't submit a new key when update_only is set
+
+set -e
+
+cd ${WORKDIR}
+cp $1 update-only.ini
+echo update_only=true >> update-only.ini
+${BUILDDIR}/onak -b -c update-only.ini add < ${TESTSDIR}/../keys/noodles.key || true
+rm update-only.ini
+if ! ${BUILDDIR}/onak -c $1 get 0x94FA372B2DA8B985 2>&1 | \
+       grep -q 'Key not found'; then
+       echo "* Did not correctly error on update-only key"
+       exit 1
+fi
+
+exit 0