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/>.
27 #include "keystructs.h"
31 * @brief Context for a database backend
35 * @brief De-initialize the key database.
37 * This function should be called upon program exit to allow the DB to
38 * cleanup after itself.
40 void (*cleanupdb)(struct onak_dbctx *);
43 * @brief Start a transaction.
45 * Start a transaction. Intended to be used if we're about to perform many
46 * operations on the database to help speed it all up, or if we want
47 * something to only succeed if all relevant operations are successful.
49 bool (*starttrans)(struct onak_dbctx *);
52 * @brief End a transaction.
56 void (*endtrans)(struct onak_dbctx *);
59 * @brief Given a fingerprint fetch the key from storage.
60 * @param fp The fingerprint to fetch.
61 * @param fpsize Number of bytes in the fingerprint (16 for v3, 20 for v4)
62 * @param publickey A pointer to a structure to return the key in.
63 * @param intrans If we're already in a transaction.
65 * This function returns a public key from whatever storage mechanism we
66 * are using. This only searches for the fingerprint of the primary key
67 * and will thus only ever return at most a single key.
69 int (*fetch_key)(struct onak_dbctx *,
70 struct openpgp_fingerprint *fingerprint,
71 struct openpgp_publickey **publickey,
75 * @brief Given a keyid fetch the key from storage.
76 * @param keyid The keyid to fetch.
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
81 * are using. It may return multiple keys in the case where there are
84 int (*fetch_key_id)(struct onak_dbctx *,
86 struct openpgp_publickey **publickey,
90 * @brief Given a fingerprint fetch the key from storage.
91 * @param fp The fingerprint to fetch.
92 * @param fpsize Number of bytes in the fingerprint (16 for v3, 20 for v4)
93 * @param publickey A pointer to a structure to return the key in.
94 * @param intrans If we're already in a transaction.
96 * This function returns a public key from whatever storage mechanism we
97 * are using. Although the fingerprint should be unique this function may
98 * also search subkeys, which could be bound to multiple primary keys. As
99 * a result multiple keys may be returned.
101 int (*fetch_key_fp)(struct onak_dbctx *,
102 struct openpgp_fingerprint *fingerprint,
103 struct openpgp_publickey **publickey,
107 * @brief Tries to find the keys that contain the supplied text.
108 * @param search The text to search for.
109 * @param publickey A pointer to a structure to return the key in.
111 * This function searches for the supplied text and returns the keys that
112 * contain it. It is likely it will return multiple keys.
114 int (*fetch_key_text)(struct onak_dbctx *, const char *search,
115 struct openpgp_publickey **publickey);
118 * @brief Tries to find the keys from an SKS hash
119 * @param hash The hash to search for.
120 * @param publickey A pointer to a structure to return the key in.
122 * This function looks for the key that is referenced by the supplied
123 * SKS hash and returns it.
125 int (*fetch_key_skshash)(struct onak_dbctx *,
126 const struct skshash *hash,
127 struct openpgp_publickey **publickey);
130 * @brief Takes a key and stores it.
131 * @param publickey A pointer to the public key to store.
132 * @param intrans If we're already in a transaction.
133 * @param update If true the key exists and should be updated.
135 * This function stores a public key in whatever storage mechanism we are
136 * using. intrans indicates if we're already in a transaction so don't
137 * need to start one. update indicates if the key already exists and is
138 * just being updated.
140 * TODO: Do we store multiple keys of the same id? Or only one and replace it?
142 int (*store_key)(struct onak_dbctx *,
143 struct openpgp_publickey *publickey, bool intrans,
147 * @brief Given a keyid delete the key from storage.
148 * @param fp The fingerprint of the key to delete.
149 * @param intrans If we're already in a transaction.
151 * This function deletes a public key from whatever storage mechanism we
152 * are using. Returns 0 if the key existed.
154 int (*delete_key)(struct onak_dbctx *, struct openpgp_fingerprint *fp,
158 * @brief Takes a list of public keys and updates them in the DB.
159 * @param keys The keys to update in the DB.
160 * @param blacklist A keyarray of fingerprints that shouldn't be added.
161 * @updateonly: Only update existing keys, don't add new ones.
162 * @param sendsync If we should send a keysync mail.
164 * Takes a list of keys and adds them to the database, merging them with
165 * the key in the database if it's already present there. The key list is
166 * update to contain the minimum set of updates required to get from what
167 * we had before to what we have now (ie the set of data that was added to
168 * the DB). Returns the number of entirely new keys added.
170 * If sendsync is true then we send out a keysync mail to our sync peers
173 int (*update_keys)(struct onak_dbctx *,
174 struct openpgp_publickey **keys,
175 struct keyarray *blacklist,
180 * @brief Takes a keyid and returns the primary UID for it.
181 * @param keyid The keyid to lookup.
183 * This function returns a UID for the given key. Returns NULL if the key
186 char * (*keyid2uid)(struct onak_dbctx *, uint64_t keyid);
189 * @brief Gets a linked list of the signatures on a key.
190 * @param keyid The keyid to get the sigs for.
191 * @param revoked Is the key revoked?
193 * This function gets the list of signatures on a key. Used for key
194 * indexing and doing stats bits. If revoked is non-NULL then if the key
195 * is revoked it's set to true.
197 struct ll * (*getkeysigs)(struct onak_dbctx *,
198 uint64_t keyid, bool *revoked);
201 * @brief Gets the signatures on a key.
202 * @param keyid The key we want the signatures for.
204 * This function gets the signatures on a key. It's the same as the
205 * getkeysigs function above except we use the hash module to cache the
207 struct ll * (*cached_getkeysigs)(struct onak_dbctx *,
211 * @brief call a function once for each key in the db.
212 * @param iterfunc The function to call.
213 * @param ctx A context pointer
215 * Calls iterfunc once for each key in the database. ctx is passed
216 * unaltered to iterfunc. This function is intended to aid database dumps
217 * and statistic calculations.
219 * Returns the number of keys we iterated over.
221 int (*iterate_keys)(struct onak_dbctx *,
222 void (*iterfunc)(void *ctx,
223 struct openpgp_publickey *key), void *ctx);
226 * @brief Configuration file information for this backend instance
228 struct onak_db_config *config;
231 * @brief Private backend context information.
236 #endif /* __KEYDB_H__ */