]> the.earth.li Git - onak.git/commitdiff
Remove getfullkeyid functionality
authorJonathan McDowell <noodles@earth.li>
Thu, 1 Aug 2019 21:32:51 +0000 (22:32 +0100)
committerJonathan McDowell <noodles@earth.li>
Thu, 1 Aug 2019 21:32:51 +0000 (22:32 +0100)
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.

16 files changed:
gpgwww.c
keyd.c
keydb.c
keydb.h
keydb_db4.c
keydb_dynamic.c
keydb_file.c
keydb_fs.c
keydb_hkp.c
keydb_keyd.c
keydb_keyring.c
keydb_pg.c
keydb_stacked.c
sixdegrees.c
stats.c
wotsap.c

index 73ef738b54fef35278b26451daf6f47c9c5754ca..0fc58fb3762f1b40b539e8bf80cd1352a8f7a149 100644 (file)
--- 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 4520b14e99bfa43873801dac89e79eec1530da57..ddd1366a9bb7c94b56b6d31fc7b181005ae2c663 100644 (file)
--- 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 deedc4994e5f4441938ab3ef709c4e44e46034ba..1a882386bf25933c4ea4ae5fa47853301ce5bd6b 100644 (file)
--- 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 f448215bd3a35719e544a6f74af1b0406edb6915..5dcb4364860e10967eb31709fb808e0a94c494d7 100644 (file)
--- 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.
index d2db2c5a39923f6bd7a9c4fe32f415919beb7f02..e63ac077f1ed07ef92a00d6d66527ee03c69c5e1 100644 (file)
@@ -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;
index b302efbb0c4a0e6d2a2b0c5947d31195d8060de1..52a4af9bec00e062cb5c157a07bf728dc6df78b9 100644 (file)
@@ -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;
        }
 
index c5d3ece2cae2a17aebcb3774968302d264f0159c..ded6a9e2e0c8e9db23f245b93e02a20f67e3a369 100644 (file)
@@ -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;
index 926960f04cbe9a2f7aec564f094e2d26201d05d2..86da08e59b8807d184fa8af2a5c1b1165c753754 100644 (file)
@@ -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;
index 46fceb8dc230811a9c320ba44cead2d722fbf34f..79d5c4b302e30d433a63664092fedba9895b2bc4 100644 (file)
@@ -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)) {
index 597507e5e78d3ecb41b8043c9be162dfe65a9d62..e8f9961b79a6d2f9364ec53e6dd42abe70953ec5 100644 (file)
@@ -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;
index e8c056b7ccdf19f1cc4c1eec7e0cef8cfeac531c..0b865b57efb6554c7489b87b08fac03061869b16 100644 (file)
@@ -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;
index 7663c3db8799ce518994649901d48d557e95068c..7d59640b0fd2a82189f0411fe2f0d5018c7fdf97 100644 (file)
@@ -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;
index c715c63172d2449cacaea01882785cb7936016d4..ee1c5cfa63df4475dbcb22cd9767bb6afe50e70b 100644 (file)
@@ -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;
        }
 
index 214be63e6e0530dc5a8b4dac5574394b192e084e..f7f15200dd0d7b424276e10f9dd90ceb2c02b301 100644 (file)
@@ -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 b9692744c2893338927b10146376c4534f5f2a22..91c916688f4473b88005147424238f2d78871b34 100644 (file)
--- 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<BR>\n",
                                                curkey->keyid,
                                                curkey->keyid,
-                                               (curkey->keyid == fullwant) ?
+                                               (curkey->keyid == want) ?
                                                        "" : " signs");
                                } else if (html && uid != NULL) {
                                        printf("<a href=\"lookup?op=get&search="
@@ -217,7 +213,7 @@ void dofindpath(struct onak_dbctx *dbctx,
                                                curkey->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) {
index 7c71535e762a19d40a9aa0ac72ff1dd2b581a037..8996c9b2d11549ba8e9f7ff93177b8776db4e5e4 100644 (file)
--- 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 {