3 * @brief Routines to store and fetch keys.
5 * Copyright 2002-2004 Jonathan McDowell <noodles@earth.li>
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <https://www.gnu.org/licenses/>.
26 #include "keystructs.h"
30 * @brief Context for a database backend
34 * @brief De-initialize the key database.
36 * This function should be called upon program exit to allow the DB to
37 * cleanup after itself.
39 void (*cleanupdb)(struct onak_dbctx *);
42 * @brief Start a transaction.
44 * Start a transaction. Intended to be used if we're about to perform many
45 * operations on the database to help speed it all up, or if we want
46 * something to only succeed if all relevant operations are successful.
48 bool (*starttrans)(struct onak_dbctx *);
51 * @brief End a transaction.
55 void (*endtrans)(struct onak_dbctx *);
58 * @brief Given a keyid fetch the key from storage.
59 * @param keyid The keyid to fetch.
60 * @param publickey A pointer to a structure to return the key in.
61 * @param intrans If we're already in a transaction.
63 * This function returns a public key from whatever storage mechanism we
66 * TODO: What about keyid collisions? Should we use fingerprint instead?
68 int (*fetch_key_id)(struct onak_dbctx *,
70 struct openpgp_publickey **publickey,
74 * @brief Given a fingerprint fetch the key from storage.
75 * @param fp The fingerprint to fetch.
76 * @param fpsize Number of bytes in the fingerprint (16 for v3, 20 for v4)
77 * @param publickey A pointer to a structure to return the key in.
78 * @param intrans If we're already in a transaction.
80 * This function returns a public key from whatever storage mechanism we
83 int (*fetch_key_fp)(struct onak_dbctx *,
84 struct openpgp_fingerprint *fingerprint,
85 struct openpgp_publickey **publickey,
89 * @brief Takes a key and stores it.
90 * @param publickey A pointer to the public key to store.
91 * @param intrans If we're already in a transaction.
92 * @param update If true the key exists and should be updated.
94 * This function stores a public key in whatever storage mechanism we are
95 * using. intrans indicates if we're already in a transaction so don't
96 * need to start one. update indicates if the key already exists and is
99 * TODO: Do we store multiple keys of the same id? Or only one and replace it?
101 int (*store_key)(struct onak_dbctx *,
102 struct openpgp_publickey *publickey, bool intrans,
106 * @brief Given a keyid delete the key from storage.
107 * @param fp The fingerprint of the key to delete.
108 * @param intrans If we're already in a transaction.
110 * This function deletes a public key from whatever storage mechanism we
111 * are using. Returns 0 if the key existed.
113 int (*delete_key)(struct onak_dbctx *, struct openpgp_fingerprint *fp,
117 * @brief Trys to find the keys that contain the supplied text.
118 * @param search The text to search for.
119 * @param publickey A pointer to a structure to return the key in.
121 * This function searches for the supplied text and returns the keys that
124 int (*fetch_key_text)(struct onak_dbctx *, const char *search,
125 struct openpgp_publickey **publickey);
128 * @brief Tries to find the keys from an SKS hash
129 * @param hash The hash to search for.
130 * @param publickey A pointer to a structure to return the key in.
132 * This function looks for the key that is referenced by the supplied
133 * SKS hash and returns it.
135 int (*fetch_key_skshash)(struct onak_dbctx *,
136 const struct skshash *hash,
137 struct openpgp_publickey **publickey);
140 * @brief Takes a list of public keys and updates them in the DB.
141 * @param keys The keys to update in the DB.
142 * @param sendsync If we should send a keysync mail.
144 * Takes a list of keys and adds them to the database, merging them with
145 * the key in the database if it's already present there. The key list is
146 * update to contain the minimum set of updates required to get from what
147 * we had before to what we have now (ie the set of data that was added to
148 * the DB). Returns the number of entirely new keys added.
150 * If sendsync is true then we send out a keysync mail to our sync peers
153 int (*update_keys)(struct onak_dbctx *,
154 struct openpgp_publickey **keys, bool sendsync);
157 * @brief Takes a keyid and returns the primary UID for it.
158 * @param keyid The keyid to lookup.
160 * This function returns a UID for the given key. Returns NULL if the key
163 char * (*keyid2uid)(struct onak_dbctx *, uint64_t keyid);
166 * @brief Gets a linked list of the signatures on a key.
167 * @param keyid The keyid to get the sigs for.
168 * @param revoked Is the key revoked?
170 * This function gets the list of signatures on a key. Used for key
171 * indexing and doing stats bits. If revoked is non-NULL then if the key
172 * is revoked it's set to true.
174 struct ll * (*getkeysigs)(struct onak_dbctx *,
175 uint64_t keyid, bool *revoked);
178 * @brief Gets the signatures on a key.
179 * @param keyid The key we want the signatures for.
181 * This function gets the signatures on a key. It's the same as the
182 * getkeysigs function above except we use the hash module to cache the
184 struct ll * (*cached_getkeysigs)(struct onak_dbctx *,
188 * @brief call a function once for each key in the db.
189 * @param iterfunc The function to call.
190 * @param ctx A context pointer
192 * Calls iterfunc once for each key in the database. ctx is passed
193 * unaltered to iterfunc. This function is intended to aid database dumps
194 * and statistic calculations.
196 * Returns the number of keys we iterated over.
198 int (*iterate_keys)(struct onak_dbctx *,
199 void (*iterfunc)(void *ctx,
200 struct openpgp_publickey *key), void *ctx);
203 * @brief Configuration file information for this backend instance
205 struct onak_db_config *config;
208 * @brief Private backend context information.
213 #endif /* __KEYDB_H__ */