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);
#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
/**
/**
* 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
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;
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
newkeys++;
curkey = &(*curkey)->next;
}
+next:
dbctx->endtrans(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
int (*update_keys)(struct onak_dbctx *,
struct openpgp_publickey **keys,
struct keyarray *blacklist,
+ bool updateonly,
bool sendsync);
/**
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,
static int keyring_update_keys(struct onak_dbctx *dbctx,
struct openpgp_publickey **keys,
struct keyarray *blacklist,
+ bool updateonly,
bool sendsync)
{
return 0;
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 =
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,
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;
}
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,
; 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]
--- /dev/null
+#!/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