From c063c72b0e63842f5466e0983183c98d4e05c54e Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Thu, 1 Aug 2019 22:32:51 +0100 Subject: [PATCH] Remove getfullkeyid functionality This expanded a 32 bit key ID into a 64 bit key ID. It's mostly redundant, so encode 64 bit key IDs where necessary and rely on the fetch fallback to 32 bit elsewhere. --- gpgwww.c | 16 +++++------- keyd.c | 25 ------------------- keydb.c | 27 -------------------- keydb.h | 9 ------- keydb_db4.c | 65 ------------------------------------------------- keydb_dynamic.c | 10 -------- keydb_file.c | 2 -- keydb_fs.c | 1 - keydb_hkp.c | 2 -- keydb_keyd.c | 26 -------------------- keydb_keyring.c | 2 -- keydb_pg.c | 2 -- keydb_stacked.c | 19 --------------- sixdegrees.c | 4 +-- stats.c | 18 ++++++-------- wotsap.c | 5 ++-- 16 files changed, 17 insertions(+), 216 deletions(-) diff --git a/gpgwww.c b/gpgwww.c index 73ef738..0fc58fb 100644 --- a/gpgwww.c +++ b/gpgwww.c @@ -69,22 +69,18 @@ int getkeyspath(struct onak_dbctx *dbctx, struct openpgp_packet_list *packets = NULL; struct openpgp_packet_list *list_end = NULL; struct stats_key *keyinfoa, *keyinfob, *curkey; - uint64_t fullhave, fullwant; int pathlen = 0; - fullhave = dbctx->getfullkeyid(dbctx, have); - fullwant = dbctx->getfullkeyid(dbctx, want); - /* * Make sure the keys we have and want are in the cache. */ - dbctx->cached_getkeysigs(dbctx, fullhave); - dbctx->cached_getkeysigs(dbctx, fullwant); + dbctx->cached_getkeysigs(dbctx, have); + dbctx->cached_getkeysigs(dbctx, want); - if ((keyinfoa = findinhash(fullhave)) == NULL) { + if ((keyinfoa = findinhash(have)) == NULL) { return 1; } - if ((keyinfob = findinhash(fullwant)) == NULL) { + if ((keyinfob = findinhash(want)) == NULL) { return 1; } @@ -104,7 +100,7 @@ int getkeyspath(struct onak_dbctx *dbctx, */ curkey = findinhash(keyinfoa->parent); while (curkey != NULL && curkey->keyid != 0) { - if (curkey->keyid != fullwant && + if (curkey->keyid != want && dbctx->fetch_key_id(dbctx, curkey->keyid, &publickey, false)) { @@ -126,7 +122,7 @@ int getkeyspath(struct onak_dbctx *dbctx, /* * Add the destination key to the list of returned keys. */ - if (dbctx->fetch_key_id(dbctx, fullwant, &publickey, false)) { + if (dbctx->fetch_key_id(dbctx, want, &publickey, false)) { flatten_publickey(publickey, &packets, &list_end); diff --git a/keyd.c b/keyd.c index 4520b14..ddd1366 100644 --- a/keyd.c +++ b/keyd.c @@ -459,31 +459,6 @@ static int sock_do(struct onak_dbctx *dbctx, int fd) &fingerprint, false)); } break; - case KEYD_CMD_GETFULLKEYID: - if (!keyd_write_reply(fd, KEYD_REPLY_OK)) { - ret = 1; - } - if (ret == 0) { - bytes = read(fd, &keyid, sizeof(keyid)); - if (bytes != sizeof(keyid)) { - ret = 1; - } - } - if (ret == 0) { - keyid = dbctx->getfullkeyid(dbctx, keyid); - cmd = sizeof(keyid); - bytes = write(fd, &cmd, sizeof(cmd)); - if (bytes != sizeof(cmd)) { - ret = 1; - } - } - if (ret == 0) { - bytes = write(fd, &keyid, sizeof(keyid)); - if (bytes != sizeof(keyid)) { - ret = 1; - } - } - break; case KEYD_CMD_KEYITER: if (!keyd_write_reply(fd, KEYD_REPLY_OK)) { ret = 1; diff --git a/keydb.c b/keydb.c index deedc49..1a88238 100644 --- a/keydb.c +++ b/keydb.c @@ -155,33 +155,6 @@ struct ll *generic_cached_getkeysigs(struct onak_dbctx *dbctx, uint64_t keyid) return key->sigs; } -#ifdef NEED_GETFULLKEYID -/** - * getfullkeyid - Maps a 32bit key id to a 64bit one. - * @keyid: The 32bit keyid. - * - * This function maps a 32bit key id to the full 64bit one. It returns the - * full keyid. If the key isn't found a keyid of 0 is returned. - */ -uint64_t generic_getfullkeyid(struct onak_dbctx *dbctx, uint64_t keyid) -{ - struct openpgp_publickey *publickey = NULL; - - if (keyid < 0x100000000LL) { - dbctx->fetch_key_id(dbctx, keyid, &publickey, false); - if (publickey != NULL) { - get_keyid(publickey, &keyid); - free_publickey(publickey); - publickey = NULL; - } else { - keyid = 0; - } - } - - return keyid; -} -#endif - #ifdef NEED_UPDATEKEYS /** * update_keys - Takes a list of public keys and updates them in the DB. diff --git a/keydb.h b/keydb.h index f448215..5dcb436 100644 --- a/keydb.h +++ b/keydb.h @@ -184,15 +184,6 @@ struct onak_dbctx { struct ll * (*cached_getkeysigs)(struct onak_dbctx *, uint64_t keyid); -/** - * @brief Maps a 32 bit key id to a 64 bit one. - * @param keyid The 32 bit keyid. - * - * This function maps a 32 bit key id to the full 64 bit one. It returns the - * full keyid. If the key isn't found a keyid of 0 is returned. - */ - uint64_t (*getfullkeyid)(struct onak_dbctx *, uint64_t keyid); - /** * @brief call a function once for each key in the db. * @param iterfunc The function to call. diff --git a/keydb_db4.c b/keydb_db4.c index d2db2c5..e63ac07 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -289,70 +289,6 @@ static int db4_upgradedb(struct onak_dbctx *dbctx) return ret; } -/** - * getfullkeyid - Maps a 32bit key id to a 64bit one. - * @keyid: The 32bit keyid. - * - * This function maps a 32bit key id to the full 64bit one. It returns the - * first full keyid that has this short keyid. If the key isn't found a - * keyid of 0 is returned. - * - * FIXME: This should either return the fingerprint or ideally go away - * entirely. - */ -static uint64_t db4_getfullkeyid(struct onak_dbctx *dbctx, uint64_t keyid) -{ - struct onak_db4_dbctx *privctx = (struct onak_db4_dbctx *) dbctx->priv; - DBT key, data; - DBC *cursor = NULL; - uint32_t shortkeyid = 0; - int ret = 0; - int i; - - if (keyid < 0x100000000LL) { - ret = privctx->id32db->cursor(privctx->id32db, - privctx->txn, - &cursor, - 0); /* flags */ - - if (ret != 0) { - return 0; - } - - shortkeyid = keyid & 0xFFFFFFFF; - - memset(&key, 0, sizeof(key)); - memset(&data, 0, sizeof(data)); - key.data = &shortkeyid; - key.size = sizeof(shortkeyid); - data.flags = DB_DBT_MALLOC; - - ret = cursor->c_get(cursor, - &key, - &data, - DB_SET); - - if (ret == 0) { - keyid = 0; - /* Only works for v4, not v3 or v5 */ - for (i = 12; i < 20; i++) { - keyid <<= 8; - keyid |= ((uint8_t *) data.data)[i]; - } - - if (data.data != NULL) { - free(data.data); - data.data = NULL; - } - } - - cursor->c_close(cursor); - cursor = NULL; - } - - return keyid; -} - /** * fetch_key_fp - Given a fingerprint fetch the key from storage. */ @@ -1832,7 +1768,6 @@ struct onak_dbctx *keydb_db4_init(struct onak_db_config *dbcfg, bool readonly) dbctx->getkeysigs = generic_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = generic_keyid2uid; - dbctx->getfullkeyid = db4_getfullkeyid; dbctx->iterate_keys = db4_iterate_keys; return dbctx; diff --git a/keydb_dynamic.c b/keydb_dynamic.c index b302efb..52a4af9 100644 --- a/keydb_dynamic.c +++ b/keydb_dynamic.c @@ -159,15 +159,6 @@ static char *dynamic_keyid2uid(struct onak_dbctx *dbctx, keyid); } -static uint64_t dynamic_getfullkeyid(struct onak_dbctx *dbctx, - uint64_t keyid) -{ - struct onak_dynamic_dbctx *privctx = - (struct onak_dynamic_dbctx *) dbctx->priv; - - return privctx->loadeddbctx->getfullkeyid(privctx->loadeddbctx, keyid); -} - static int dynamic_iterate_keys(struct onak_dbctx *dbctx, void (*iterfunc)(void *ctx, struct openpgp_publickey *key), void *ctx) @@ -320,7 +311,6 @@ struct onak_dbctx *keydb_dynamic_init(struct onak_db_config *dbcfg, dbctx->getkeysigs = dynamic_getkeysigs; dbctx->cached_getkeysigs = dynamic_cached_getkeysigs; dbctx->keyid2uid = dynamic_keyid2uid; - dbctx->getfullkeyid = dynamic_getfullkeyid; dbctx->iterate_keys = dynamic_iterate_keys; } diff --git a/keydb_file.c b/keydb_file.c index c5d3ece..ded6a9e 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -244,7 +244,6 @@ static int file_iterate_keys(struct onak_dbctx *dbctx, */ #define NEED_KEYID2UID 1 #define NEED_GETKEYSIGS 1 -#define NEED_GETFULLKEYID 1 #define NEED_UPDATEKEYS 1 #define NEED_GET_FP 1 #include "keydb.c" @@ -295,7 +294,6 @@ struct onak_dbctx *keydb_file_init(struct onak_db_config *dbcfg, bool readonly) dbctx->getkeysigs = generic_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = generic_keyid2uid; - dbctx->getfullkeyid = generic_getfullkeyid; dbctx->iterate_keys = file_iterate_keys; return dbctx; diff --git a/keydb_fs.c b/keydb_fs.c index 926960f..86da08e 100644 --- a/keydb_fs.c +++ b/keydb_fs.c @@ -706,7 +706,6 @@ struct onak_dbctx *keydb_fs_init(struct onak_db_config *dbcfg, bool readonly) dbctx->getkeysigs = generic_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = generic_keyid2uid; - dbctx->getfullkeyid = fs_getfullkeyid; dbctx->iterate_keys = fs_iterate_keys; return dbctx; diff --git a/keydb_hkp.c b/keydb_hkp.c index 46fceb8..79d5c4b 100644 --- a/keydb_hkp.c +++ b/keydb_hkp.c @@ -321,7 +321,6 @@ static void hkp_endtrans(struct onak_dbctx *dbctx) */ #define NEED_KEYID2UID 1 #define NEED_GETKEYSIGS 1 -#define NEED_GETFULLKEYID 1 #define NEED_UPDATEKEYS 1 #include "keydb.c" @@ -373,7 +372,6 @@ struct onak_dbctx *keydb_hkp_init(struct onak_db_config *dbcfg, bool readonly) dbctx->getkeysigs = generic_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = generic_keyid2uid; - dbctx->getfullkeyid = generic_getfullkeyid; dbctx->iterate_keys = hkp_iterate_keys; if (!hkp_parse_url(privctx, dbcfg->location)) { diff --git a/keydb_keyd.c b/keydb_keyd.c index 597507e..e8f9961 100644 --- a/keydb_keyd.c +++ b/keydb_keyd.c @@ -361,31 +361,6 @@ static int keyd_fetch_key_skshash(struct onak_dbctx *dbctx, return (count > 0) ? 1 : 0; } - -/** - * getfullkeyid - Maps a 32bit key id to a 64bit one. - * @keyid: The 32bit keyid. - * - * This function maps a 32bit key id to the full 64bit one. It returns the - * full keyid. If the key isn't found a keyid of 0 is returned. - */ -static uint64_t keyd_getfullkeyid(struct onak_dbctx *dbctx, uint64_t keyid) -{ - int keyd_fd = (intptr_t) dbctx->priv; - uint32_t cmd = KEYD_CMD_GETFULLKEYID; - - if (keyd_send_cmd(keyd_fd, KEYD_CMD_GETFULLKEYID)) { - write(keyd_fd, &keyid, sizeof(keyid)); - read(keyd_fd, &cmd, sizeof(cmd)); - if (cmd != sizeof(keyid)) { - return 0; - } - read(keyd_fd, &keyid, sizeof(keyid)); - } - - return keyid; -} - /** * iterate_keys - call a function once for each key in the db. * @iterfunc: The function to call. @@ -594,7 +569,6 @@ struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg, bool readonly) dbctx->getkeysigs = generic_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = generic_keyid2uid; - dbctx->getfullkeyid = keyd_getfullkeyid; dbctx->iterate_keys = keyd_iterate_keys; return dbctx; diff --git a/keydb_keyring.c b/keydb_keyring.c index e8c056b..0b865b5 100644 --- a/keydb_keyring.c +++ b/keydb_keyring.c @@ -232,7 +232,6 @@ static int keyring_update_keys(struct onak_dbctx *dbctx, */ #define NEED_KEYID2UID 1 #define NEED_GETKEYSIGS 1 -#define NEED_GETFULLKEYID 1 #define NEED_GET_FP 1 #include "keydb.c" @@ -448,7 +447,6 @@ struct onak_dbctx *keydb_keyring_init(struct onak_db_config *dbcfg, dbctx->getkeysigs = generic_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = generic_keyid2uid; - dbctx->getfullkeyid = generic_getfullkeyid; dbctx->iterate_keys = keyring_iterate_keys; return dbctx; diff --git a/keydb_pg.c b/keydb_pg.c index 7663c3d..7d59640 100644 --- a/keydb_pg.c +++ b/keydb_pg.c @@ -643,7 +643,6 @@ static int pg_iterate_keys(struct onak_dbctx *dbctx, /* * Include the basic keydb routines. */ -#define NEED_GETFULLKEYID 1 #define NEED_UPDATEKEYS 1 #define NEED_GET_FP 1 #include "keydb.c" @@ -712,7 +711,6 @@ struct onak_dbctx *keydb_pg_init(struct onak_db_config *dbcfg, bool readonly) dbctx->getkeysigs = pg_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = pg_keyid2uid; - dbctx->getfullkeyid = generic_getfullkeyid; dbctx->iterate_keys = pg_iterate_keys; return dbctx; diff --git a/keydb_stacked.c b/keydb_stacked.c index c715c63..ee1c5cf 100644 --- a/keydb_stacked.c +++ b/keydb_stacked.c @@ -231,7 +231,6 @@ static int stacked_fetch_key_skshash(struct onak_dbctx *dbctx, */ #define NEED_KEYID2UID 1 #define NEED_GETKEYSIGS 1 -#define NEED_GETFULLKEYID 1 #define NEED_UPDATEKEYS 1 #include "keydb.c" @@ -286,23 +285,6 @@ static char *stacked_keyid2uid(struct onak_dbctx *dbctx, return res; } -static uint64_t stacked_getfullkeyid(struct onak_dbctx *dbctx, - uint64_t keyid) -{ - struct onak_stacked_dbctx *privctx = - (struct onak_stacked_dbctx *) dbctx->priv; - struct onak_dbctx *backend = - (struct onak_dbctx *) privctx->backends->object; - uint64_t res = 0; - - res = backend->getfullkeyid(backend, keyid); - if (res == 0) { - res = generic_getfullkeyid(dbctx, keyid); - } - - return res; -} - static void stacked_cleanupdb(struct onak_dbctx *dbctx) { struct onak_stacked_dbctx *privctx = @@ -393,7 +375,6 @@ struct onak_dbctx *keydb_stacked_init(struct onak_db_config *dbcfg, dbctx->getkeysigs = stacked_getkeysigs; dbctx->cached_getkeysigs = stacked_cached_getkeysigs; dbctx->keyid2uid = stacked_keyid2uid; - dbctx->getfullkeyid = stacked_getfullkeyid; dbctx->iterate_keys = stacked_iterate_keys; } diff --git a/sixdegrees.c b/sixdegrees.c index 214be63..f7f1520 100644 --- a/sixdegrees.c +++ b/sixdegrees.c @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) { int optchar; char *configfile = NULL; - uint64_t keyid = 0x2DA8B985; + uint64_t keyid = 0x94FA372B2DA8B985; struct onak_dbctx *dbctx; while ((optchar = getopt(argc, argv, "c:")) != -1 ) { @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) dbctx = config.dbinit(config.backend, true); if (dbctx != NULL) { inithash(); - sixdegrees(dbctx, dbctx->getfullkeyid(dbctx, keyid)); + sixdegrees(dbctx, keyid); destroyhash(); dbctx->cleanupdb(dbctx); } else { diff --git a/stats.c b/stats.c index b969274..91c9166 100644 --- a/stats.c +++ b/stats.c @@ -136,25 +136,21 @@ void dofindpath(struct onak_dbctx *dbctx, uint64_t have, uint64_t want, bool html, int count) { struct stats_key *keyinfoa, *keyinfob, *curkey; - uint64_t fullhave, fullwant; int rec; int pathnum; char *uid; - fullhave = dbctx->getfullkeyid(dbctx, have); - fullwant = dbctx->getfullkeyid(dbctx, want); - /* * Make sure the keys we have and want are in the cache. */ - (void) dbctx->cached_getkeysigs(dbctx, fullhave); - (void) dbctx->cached_getkeysigs(dbctx, fullwant); + (void) dbctx->cached_getkeysigs(dbctx, have); + (void) dbctx->cached_getkeysigs(dbctx, want); - if ((keyinfoa = findinhash(fullhave)) == NULL) { + if ((keyinfoa = findinhash(have)) == NULL) { printf("Couldn't find key 0x%016" PRIX64 ".\n", have); return; } - if ((keyinfob = findinhash(fullwant)) == NULL) { + if ((keyinfob = findinhash(want)) == NULL) { printf("Couldn't find key 0x%016" PRIX64 ".\n", want); return; } @@ -203,7 +199,7 @@ void dofindpath(struct onak_dbctx *dbctx, "User id not found])%s
\n", curkey->keyid, curkey->keyid, - (curkey->keyid == fullwant) ? + (curkey->keyid == want) ? "" : " signs"); } else if (html && uid != NULL) { printf("keyid, curkey->keyid, txt2html(uid), - (curkey->keyid == fullwant) ? + (curkey->keyid == want) ? "" : " signs"); } else { printf("0x%016" PRIX64 " (%s)%s\n", @@ -225,7 +221,7 @@ void dofindpath(struct onak_dbctx *dbctx, (uid == NULL) ? "[User id not found]" : uid, - (curkey->keyid == fullwant) ? + (curkey->keyid == want) ? "" : " signs"); } if (uid != NULL) { diff --git a/wotsap.c b/wotsap.c index 7c71535..8996c9b 100644 --- a/wotsap.c +++ b/wotsap.c @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) { int optchar; char *configfile = NULL, *dir = NULL; - uint64_t keyid = 0x2DA8B985; + uint64_t keyid = 0x94FA372B2DA8B985; struct onak_dbctx *dbctx; while ((optchar = getopt(argc, argv, "c:")) != -1 ) { @@ -211,8 +211,7 @@ int main(int argc, char *argv[]) dbctx = config.dbinit(config.backend, true); if (dbctx != NULL) { inithash(); - wotsap(dbctx, dbctx->getfullkeyid(dbctx, keyid), - dir ? dir : "."); + wotsap(dbctx, keyid, dir ? dir : "."); destroyhash(); dbctx->cleanupdb(dbctx); } else { -- 2.39.5