X-Git-Url: https://the.earth.li/gitweb/?p=onak.git;a=blobdiff_plain;f=keydb%2Fkeydb.c;h=692a7b7c902a42590b92d5ec29cbdc01e409e714;hp=f6b9682f2d4b4ade0db0494fbf4c4b312a80171e;hb=a2979c20e1ab2d52e3a961ac7dad45fee9d6345a;hpb=00e37c36f214bf9d2e9794d3089e64522a6275a2 diff --git a/keydb/keydb.c b/keydb/keydb.c index f6b9682..692a7b7 100644 --- a/keydb/keydb.c +++ b/keydb/keydb.c @@ -265,6 +265,9 @@ static int generic_fetch_key_fp(struct onak_dbctx *dbctx, * keys need the top 64 bits. This doesn't work for v3 keys, * but there's no way to map from v3 fingerprint to v3 key ID so * if the backend can't do it we're going to fail anyway. + * + * We are also assuming they store a single key based on the ID, so + * we are implementing fetch_key rather than fetch_key_fp */ keyid = 0; if (fingerprint->length == 20) { @@ -283,3 +286,44 @@ static int generic_fetch_key_fp(struct onak_dbctx *dbctx, return dbctx->fetch_key_id(dbctx, keyid, publickey, intrans); } #endif + +#ifdef NEED_GET +/* + * This fetches a key by fingerprint from the back end, then filters + * out what we got back to ensure it's the primary key that matches the + * fingerprint, and that only one is returned. + */ +static int generic_fetch_key(struct onak_dbctx *dbctx, + struct openpgp_fingerprint *fingerprint, + struct openpgp_publickey **publickey, + bool intrans) +{ + struct openpgp_publickey *curkey, **newkey; + struct openpgp_publickey *keys; + struct openpgp_fingerprint fp; + int count; + + /* Find the last key in the provided set of keys */ + for (newkey = publickey; *newkey != NULL; newkey = &(*newkey)->next) + ; + + keys = NULL; + dbctx->fetch_key_fp(dbctx, fingerprint, &keys, intrans); + + count = 0; + for (curkey = keys; curkey != NULL; curkey = curkey->next) { + if (get_fingerprint(curkey->publickey, &fp) == ONAK_E_OK) { + if (fingerprint_cmp(fingerprint, &fp) == 0) { + *newkey = curkey; + curkey = curkey->next; + (*newkey)->next = NULL; + count = 1; + break; + } + } + } + free_publickey(keys); + + return count; +} +#endif