5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2005 - 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcskr/SILC Key Repository
26 * SILC Key Repository is thread safe. Same key repository context can be
27 * safely used in multi threaded environment.
34 /****s* silcskr/SilcSKRAPI/SilcSKR
38 * typedef struct SilcSKRObject *SilcSKR, SilcSKRStruct;
42 * This context is the actual SILC Key Repository and is allocated
43 * by silc_skr_alloc (or initialized by silc_skr_init) and given as
44 * attribute to all silc_skr_* functions. It is freed by the
45 * silc_skr_free (or uninitialized with silc_skr_uninit) function.
48 typedef struct SilcSKRObject *SilcSKR, SilcSKRStruct;
50 /****s* silcskr/SilcSKRAPI/SilcSKRFind
54 * typedef struct SilcSKRFindStruct *SilcSKRFind
58 * This context contains the search constraints used find keys from the
59 * key repository. It is allocated by silc_skr_find_alloc and freed
60 * by silc_skr_find_free. The context is given as argument to all
61 * silc_skr_find* functions.
64 typedef struct SilcSKRFindStruct *SilcSKRFind;
66 /****d* silcskr/SilcSKRAPI/SilcSKRKeyUsage
70 * typedef enum { ... } SilcSKRKeyUsage;
74 * Indicates the usage of the key. Keys can be added for different
75 * reasons and for different purpose to the repository. SilcSKRKeyUsage
76 * indicates for what reason the key exists in the repository. The default
77 * usage is SILC_SKR_USAGE_ANY and allows any kind of usage for the key.
78 * If the usage should be limited then specific usage bitmask can be
79 * specified when adding the key. When searching keys from the
80 * repository at least one of the key usage bits must be found in order
86 SILC_SKR_USAGE_ANY = 0x0000, /* Any usage */
87 SILC_SKR_USAGE_AUTH = 0x0001, /* Signatures/verification */
88 SILC_SKR_USAGE_ENC = 0x0002, /* Encryption/decryption */
89 SILC_SKR_USAGE_KEY_AGREEMENT = 0x0004, /* Key agreement protocol */
90 SILC_SKR_USAGE_IDENTIFICATION = 0x0008, /* Identifying key owner */
91 SILC_SKR_USAGE_SERVICE_AUTHORIZATION = 0x0010, /* Service authorization */
93 /* From 0x0100 reserved for private/application use. */
97 /****s* silcskr/SilcSKRAPI/SilcSKRKey
101 * typedef struct SilcSKRKeyStruct { ... } *SilcSKRKey;
105 * This context holds the public key, optional public key specific
106 * context and public key usage bits. This context is returned in
107 * the SilcSKRFindCallback list. Each entry in the list is SIlcSKRKey.
112 typedef struct SilcSKRKeyStruct {
113 SilcSKRKeyUsage usage; /* Key usage */
114 SilcPublicKey key; /* Public key */
115 void *key_context; /* Optional key specific context */
119 /****d* silcskr/SilcSKRAPI/SilcSKRStatus
123 * typedef enum { ... } SilcSKRStatus;
127 * Indicates the status of the key repository procedures. This is
128 * returned to SilcSKRFindCallback function to indicate the status
129 * of the finding. This is a bitmask, and more than one status may
130 * be set at one time.
132 * If there are no errors only SILC_SKR_OK is set. If error occurred
133 * then at least SILC_SKR_ERROR is set, and possibly other error
139 SILC_SKR_OK = 0x00000001, /* All is Ok */
140 SILC_SKR_ERROR = 0x00000002, /* Generic error status */
141 SILC_SKR_ALREADY_EXIST = 0x00000004, /* Key already exist */
142 SILC_SKR_NOT_FOUND = 0x00000008, /* No keys were found */
143 SILC_SKR_NO_MEMORY = 0x00000010, /* System out of memory */
144 SILC_SKR_UNSUPPORTED_TYPE = 0x00000020, /* Unsupported PKCS type */
148 /****f* silcskr/SilcSKRAPI/SilcSKRFindCallback
152 * typedef void (*SilcSKRFindCallback)(SilcSKR skr, SilcSKRFind find,
153 * SilcSKRStatus status,
154 * SilcDList keys, void *context);
158 * Callback that is given as argument to silc_skr_find and other find
159 * functions. Returns the results of the finding. If keys were found
160 * the `keys' is non-NULL and receiver must free it with silc_dlist_uninit.
161 * Each entry in the `keys' is SilcSKRKey context. The list `keys' is
162 * already at start so calling silc_dlist_start is not necessary when
163 * traversing the list from the start. If the `find' is non-NULL it must
164 * be freed with silc_skr_find_free.
167 typedef void (*SilcSKRFindCallback)(SilcSKR skr, SilcSKRFind find,
168 SilcSKRStatus status,
169 SilcDList keys, void *context);
171 /****f* silcskr/SilcSKRAPI/silc_skr_alloc
175 * SilcSKR silc_skr_alloc(void);
179 * Allocates key repository context.
182 SilcSKR silc_skr_alloc(void);
184 /****f* silcskr/SilcSKRAPI/silc_skr_free
188 * void silc_skr_free(SilcSKR skr);
192 * Free's the key repository context `skr' and all resources in it.
195 void silc_skr_free(SilcSKR skr);
197 /****f* silcskr/SilcSKRAPI/silc_skr_init
201 * SilcBool silc_skr_init(SilcSKR skr);
205 * Initializes a pre-allocated SilcSKR context. This function is
206 * equivalent to silc_skr_alloc but takes pre-allocated context as
207 * argument. Returns FALSE if initialization failed.
210 SilcBool silc_skr_init(SilcSKR skr);
212 /****f* silcskr/SilcSKRAPI/silc_skr_uninit
216 * void silc_skr_uninit(SilcSKR skr);
220 * Uninitializes a pre-allocated SilcSKR context. Use this function if
221 * you called silc_skr_init.
224 void silc_skr_uninit(SilcSKR skr);
226 /****f* silcskr/SilcSKRAPI/silc_skr_add_public_key
230 * SilcSKRStatus silc_skr_add_public_key(SilcSKR skr,
231 * SilcPublicKey public_key,
232 * SilcSKRKeyUsage usage,
233 * void *key_context);
237 * Add a public key to repository. The repository will steal `public_key'
238 * and caller must not free it. The `key_context' is optional key specific
239 * context that will be saved in the repository with the key, and can be
240 * retrieved with the key. Public key can be added only once to the
241 * repository. To add same key more than once to repository different
242 * `key_context' must be used each time.
244 * Returns SILC_SKR_OK if the key was added successfully, and error
245 * status if key could not be added, or has been added already.
249 * // Add a key to repository
250 * if (silc_skr_add_public_key(repository, public_key,
251 * SILC_SKR_USAGE_ANY, NULL) != SILC_SKR_OK)
255 SilcSKRStatus silc_skr_add_public_key(SilcSKR skr,
256 SilcPublicKey public_key,
257 SilcSKRKeyUsage usage,
260 /****f* silcskr/SilcSKRAPI/silc_skr_add_public_key_simple
264 * SilcSKRStatus silc_skr_add_public_key_simple(SilcSKR skr,
265 * SilcPublicKey public_key,
266 * SilcSKRKeyUsage usage,
267 * void *key_context);
271 * Same as silc_skr_add_public_key but adds only the public key, usage
272 * bits and key context. The key cannot be found with any other search
273 * constraint except setting the public key, usage bits and/or key
274 * context as search constraint. This function can be used to add the
275 * key with as little memory as possible to the repository, and makes
276 * it a good way to cheaply store large amounts of public keys.
278 * Returns SILC_SKR_OK if the key was added successfully, and error
279 * status if key could not be added, or has been added already.
282 SilcSKRStatus silc_skr_add_public_key_simple(SilcSKR skr,
283 SilcPublicKey public_key,
284 SilcSKRKeyUsage usage,
287 /****f* silcskr/SilcSKRAPI/silc_skr_find_alloc
291 * SilcSKRFind silc_skr_find_alloc(void);
295 * Allocates SilcSKRFind context that will hold search constraints used
296 * to find specific keys from the repository. Caller must free the
297 * context by calling silc_skr_find_free.
300 SilcSKRFind silc_skr_find_alloc(void);
302 /****f* silcskr/SilcSKRAPI/silc_skr_find_free
306 * void silc_skr_find_free(SilcSKRFind find);
310 * Free's the search constraints context `find' and all resources in it.
313 void silc_skr_find_free(SilcSKRFind find);
315 /****f* silcskr/SilcSKRAPI/silc_skr_find_add_pkcs_type
319 * SilcBool silc_skr_find_add_pkcs_type(SilcSKRFind find,
320 * SilcPKCSType type);
324 * Sets public key cryptosystem type as search constraint. Will search
325 * only for the specific type of key(s).
328 SilcBool silc_skr_find_set_pkcs_type(SilcSKRFind find, SilcPKCSType type);
330 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_username
334 * SilcBool silc_skr_find_set_username(SilcSKRFind find,
335 * const char *username);
339 * Sets username as search constraint. This specific username must be
340 * present in the key.
342 * This may be used with SILC_PKCS_SILC PKCS type only.
345 SilcBool silc_skr_find_set_username(SilcSKRFind find, const char *username);
347 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_host
351 * SilcBool silc_skr_find_set_host(SilcSKRFind find,
356 * Sets host as search constraint. This specific host must be
357 * present in the key. The `host' may be a hostname or IP address.
359 * This may be used with SILC_PKCS_SILC PKCS type only.
362 SilcBool silc_skr_find_set_host(SilcSKRFind find, const char *host);
364 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_realname
368 * SilcBool silc_skr_find_set_realname(SilcSKRFind find,
369 * const char *realname);
373 * Sets real name as search constraint. This specific name must be
374 * present in the key.
376 * This may be used with SILC_PKCS_SILC PKCS type only.
379 SilcBool silc_skr_find_set_realname(SilcSKRFind find, const char *realname);
381 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_email
385 * SilcBool silc_skr_find_set_email(SilcSKRFind find,
386 * const char *email);
390 * Sets email address as search constraint. This specific address must be
391 * present in the key.
393 * This may be used with SILC_PKCS_SILC PKCS type only.
396 SilcBool silc_skr_find_set_email(SilcSKRFind find, const char *email);
398 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_org
402 * SilcBool silc_skr_find_set_org(SilcSKRFind find,
403 * const char *email);
407 * Sets organization as search constraint. This specific organization
408 * must be present in the key.
410 * This may be used with SILC_PKCS_SILC PKCS type only.
413 SilcBool silc_skr_find_set_org(SilcSKRFind find, const char *org);
415 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_country
419 * SilcBool silc_skr_find_set_country(SilcSKRFind find,
420 * const char *email);
424 * Sets country as search constraint. This specific country must be
425 * present in the key.
427 * This may be used with SILC_PKCS_SILC PKCS type only.
430 SilcBool silc_skr_find_set_country(SilcSKRFind find, const char *country);
432 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_public_key
436 * SilcBool silc_skr_find_set_public_key(SilcSKRFind find,
437 * SilcPublicKey public_key);
441 * Sets public key as search constraint. This specific key must be
442 * present in the key.
445 SilcBool silc_skr_find_set_public_key(SilcSKRFind find,
446 SilcPublicKey public_key);
448 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_context
452 * SilcBool silc_skr_find_set_context(SilcSKRFind find, void *context);
456 * Sets public key specific context as search constraint. This specific
457 * context must be associated with the key. This is the context that
458 * was given as argument when adding the key to repository.
461 SilcBool silc_skr_find_set_context(SilcSKRFind find, void *context);
463 /****f* silcskr/SilcSKRAPI/silc_skr_find_set_usage
467 * SilcBool silc_skr_find_set_usage(SilcSKRFind find,
468 * SilcSKRKeyUsage usage);
472 * Sets key usage as search constraint. At least one of the key usage
473 * bits must be present in the key. This search constraint cannot be
474 * used alone to search keys. At least one other search constraint
478 SilcBool silc_skr_find_set_usage(SilcSKRFind find, SilcSKRKeyUsage usage);
480 /****f* silcskr/SilcSKRAPI/silc_skr_find
484 * SilcAsyncOperation silc_skr_find(SilcSKR skr, SilcSchedule schedule,
486 * SilcSKRFindCallback callback,
487 * void *callback_context);
491 * Finds key(s) from key repository `skr' by the search constraints
492 * `find'. As the finding procedure may be asynchronous this returns
493 * SilcAsyncOperation that may be used to control (like abort) the
494 * operation. The `callback' with `callback_context' will be called
495 * to return found keys. If this returns NULL the finding was not
496 * asynchronous, and the `callback' has been called already.
502 * // Find all SILC public keys originating from Finland
503 * find = silc_skr_find_alloc();
504 * silc_skr_find_set_pkcs_type(find, SILC_PKCS_SILC);
505 * silc_skr_find_set_country(find, "FI");
508 * silc_skr_find(skr, schedule, find, find_callback, cb_context);
511 SilcAsyncOperation silc_skr_find(SilcSKR skr, SilcSchedule schedule,
513 SilcSKRFindCallback callback,
514 void *callback_context);
516 #include "silcskr_i.h"
518 #endif /* SILCSKR_H */