1
/* keydb.h - Key database
2
* Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
29
/* What qualifies as a certification (rather than a signature?) */
30
#define IS_CERT(s) (IS_KEY_SIG(s) || IS_UID_SIG(s) || IS_SUBKEY_SIG(s) \
31
|| IS_KEY_REV(s) || IS_UID_REV(s) || IS_SUBKEY_REV(s))
32
#define IS_SIG(s) (!IS_CERT(s))
33
#define IS_KEY_SIG(s) ((s)->sig_class == 0x1f)
34
#define IS_UID_SIG(s) (((s)->sig_class & ~3) == 0x10)
35
#define IS_SUBKEY_SIG(s) ((s)->sig_class == 0x18)
36
#define IS_KEY_REV(s) ((s)->sig_class == 0x20)
37
#define IS_UID_REV(s) ((s)->sig_class == 0x30)
38
#define IS_SUBKEY_REV(s) ((s)->sig_class == 0x28)
41
typedef struct getkey_ctx_s *GETKEY_CTX;
44
* A Keyblock is all packets which form an entire certificate;
45
* i.e. the public key, certificate, trust packets, user ids,
46
* signatures, and subkey.
48
* This structure is also used to bind arbitrary packets together.
51
struct kbnode_struct {
56
ulong recno; /* used while updating the trustdb */
59
#define is_deleted_kbnode(a) ((a)->private_flag & 1)
60
#define is_cloned_kbnode(a) ((a)->private_flag & 2)
70
* A data structre to hold information about the external position
73
struct keyblock_pos_struct {
74
int resno; /* resource number */
75
enum resource_type rt;
76
off_t offset; /* position information */
77
unsigned count; /* length of the keyblock in packets */
78
iobuf_t fp; /* used by enum_keyblocks */
79
int secret; /* working on a secret keyring */
80
PACKET *pkt; /* ditto */
83
typedef struct keyblock_pos_struct KBPOS;
85
/* structure to hold a couple of public key certificates */
86
typedef struct pk_list *PK_LIST;
90
int flags; /* flag bit 1==throw_keyid */
93
/* structure to hold a couple of secret key certificates */
94
typedef struct sk_list *SK_LIST;
98
int mark; /* not used */
101
/* structure to collect all information which can be used to
102
* identify a public key */
103
typedef struct pubkey_find_info *PUBKEY_FIND_INFO;
104
struct pubkey_find_info {
108
byte fingerprint[MAX_FINGERPRINT_LEN];
113
typedef struct keydb_handle *KEYDB_HANDLE;
116
KEYDB_SEARCH_MODE_NONE,
117
KEYDB_SEARCH_MODE_EXACT,
118
KEYDB_SEARCH_MODE_SUBSTR,
119
KEYDB_SEARCH_MODE_MAIL,
120
KEYDB_SEARCH_MODE_MAILSUB,
121
KEYDB_SEARCH_MODE_MAILEND,
122
KEYDB_SEARCH_MODE_WORDS,
123
KEYDB_SEARCH_MODE_SHORT_KID,
124
KEYDB_SEARCH_MODE_LONG_KID,
125
KEYDB_SEARCH_MODE_FPR16,
126
KEYDB_SEARCH_MODE_FPR20,
127
KEYDB_SEARCH_MODE_FPR,
128
KEYDB_SEARCH_MODE_FIRST,
129
KEYDB_SEARCH_MODE_NEXT
132
struct keydb_search_desc {
133
KeydbSearchMode mode;
134
int (*skipfnc)(void *,u32*);
138
char fpr[MAX_FINGERPRINT_LEN];
150
int keydb_add_resource (const char *url, int flags, int secret);
151
KEYDB_HANDLE keydb_new (int secret);
152
void keydb_release (KEYDB_HANDLE hd);
153
const char *keydb_get_resource_name (KEYDB_HANDLE hd);
154
int keydb_get_keyblock (KEYDB_HANDLE hd, KBNODE *ret_kb);
155
int keydb_update_keyblock (KEYDB_HANDLE hd, KBNODE kb);
156
int keydb_insert_keyblock (KEYDB_HANDLE hd, KBNODE kb);
157
int keydb_delete_keyblock (KEYDB_HANDLE hd);
158
int keydb_locate_writable (KEYDB_HANDLE hd, const char *reserved);
159
void keydb_rebuild_caches (void);
160
int keydb_search_reset (KEYDB_HANDLE hd);
161
#define keydb_search(a,b,c) keydb_search2((a),(b),(c),NULL)
162
int keydb_search2 (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
163
size_t ndesc, size_t *descindex);
164
int keydb_search_first (KEYDB_HANDLE hd);
165
int keydb_search_next (KEYDB_HANDLE hd);
166
int keydb_search_kid (KEYDB_HANDLE hd, u32 *kid);
167
int keydb_search_fpr (KEYDB_HANDLE hd, const byte *fpr);
171
void show_revocation_reason( PKT_public_key *pk, int mode );
172
int check_signatures_trust( PKT_signature *sig );
173
void release_pk_list( PK_LIST pk_list );
174
int build_pk_list( STRLIST rcpts, PK_LIST *ret_pk_list, unsigned use );
175
int algo_available( preftype_t preftype, int algo, void *hint );
176
int select_algo_from_prefs( PK_LIST pk_list, int preftype,
177
int request, void *hint );
178
int select_mdc_from_pklist (PK_LIST pk_list);
181
void release_sk_list( SK_LIST sk_list );
182
int build_sk_list( STRLIST locusr, SK_LIST *ret_sk_list,
183
int unlock, unsigned use );
185
/*-- passphrase.h --*/
186
int have_static_passphrase(void);
187
void read_passphrase_from_fd( int fd );
188
void passphrase_clear_cache ( u32 *keyid, int algo );
189
DEK *passphrase_to_dek( u32 *keyid, int pubkey_algo,
190
int cipher_algo, STRING2KEY *s2k, int mode,
191
const char *tryagain_text, int *canceled);
192
void set_next_passphrase( const char *s );
193
char *get_last_passphrase(void);
196
int classify_user_id( const char *name, KEYDB_SEARCH_DESC *desc);
197
void cache_public_key( PKT_public_key *pk );
198
void getkey_disable_caches(void);
199
int get_pubkey( PKT_public_key *pk, u32 *keyid );
200
int get_pubkey_fast ( PKT_public_key *pk, u32 *keyid );
201
KBNODE get_pubkeyblock( u32 *keyid );
202
int get_pubkey_byname( PKT_public_key *pk, const char *name,
203
KBNODE *ret_keyblock, KEYDB_HANDLE *ret_kdbhd,
204
int include_disabled );
205
int get_pubkey_bynames( GETKEY_CTX *rx, PKT_public_key *pk,
206
STRLIST names, KBNODE *ret_keyblock );
207
int get_pubkey_next( GETKEY_CTX ctx, PKT_public_key *pk, KBNODE *ret_keyblock );
208
void get_pubkey_end( GETKEY_CTX ctx );
209
int get_seckey( PKT_secret_key *sk, u32 *keyid );
210
int get_primary_seckey( PKT_secret_key *sk, u32 *keyid );
211
int get_pubkey_byfprint( PKT_public_key *pk, const byte *fprint,
213
int get_pubkey_byfprint_fast (PKT_public_key *pk,
214
const byte *fprint, size_t fprint_len);
215
int get_keyblock_byfprint( KBNODE *ret_keyblock, const byte *fprint,
217
int get_keyblock_bylid( KBNODE *ret_keyblock, ulong lid );
218
int seckey_available( u32 *keyid );
219
int get_seckey_byname( PKT_secret_key *sk, const char *name, int unlock );
220
int get_seckey_bynames( GETKEY_CTX *rx, PKT_secret_key *sk,
221
STRLIST names, KBNODE *ret_keyblock );
222
int get_seckey_byfprint( PKT_secret_key *sk,
223
const byte *fprint, size_t fprint_len);
224
int get_seckey_next( GETKEY_CTX ctx, PKT_secret_key *sk, KBNODE *ret_keyblock );
225
void get_seckey_end( GETKEY_CTX ctx );
226
int enum_secret_keys( void **context, PKT_secret_key *sk,
227
int with_subkeys, int with_spm );
228
void merge_keys_and_selfsig( KBNODE keyblock );
229
char*get_user_id_string( u32 *keyid );
230
char*get_user_id_string_printable( u32 *keyid );
231
char*get_long_user_id_string( u32 *keyid );
232
char*get_user_id( u32 *keyid, size_t *rn );
233
char*get_user_id_printable( u32 *keyid );
234
KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx);
237
int pubkey_letter( int algo );
238
u32 v3_keyid (gcry_mpi_t a, u32 *ki);
239
u32 keyid_from_sk( PKT_secret_key *sk, u32 *keyid );
240
u32 keyid_from_pk( PKT_public_key *pk, u32 *keyid );
241
u32 keyid_from_sig( PKT_signature *sig, u32 *keyid );
242
u32 keyid_from_fingerprint( const byte *fprint, size_t fprint_len, u32 *keyid );
243
byte *namehash_from_uid(PKT_user_id *uid);
244
unsigned nbits_from_pk( PKT_public_key *pk );
245
unsigned nbits_from_sk( PKT_secret_key *sk );
246
const char *datestr_from_pk( PKT_public_key *pk );
247
const char *datestr_from_sk( PKT_secret_key *sk );
248
const char *datestr_from_sig( PKT_signature *sig );
249
const char *expirestr_from_pk( PKT_public_key *pk );
250
const char *expirestr_from_sk( PKT_secret_key *sk );
251
const char *expirestr_from_sig( PKT_signature *sig );
253
const char *colon_strtime (u32 t);
254
const char *colon_datestr_from_pk (PKT_public_key *pk);
255
const char *colon_datestr_from_sk (PKT_secret_key *sk);
256
const char *colon_datestr_from_sig (PKT_signature *sig);
257
const char *colon_expirestr_from_sig (PKT_signature *sig);
259
byte *fingerprint_from_sk( PKT_secret_key *sk, byte *buf, size_t *ret_len );
260
byte *fingerprint_from_pk( PKT_public_key *pk, byte *buf, size_t *ret_len );
262
char *serialno_and_fpr_from_sk (const unsigned char *sn, size_t snlen,
267
KBNODE new_kbnode( PACKET *pkt );
268
KBNODE clone_kbnode( KBNODE node );
269
void release_kbnode( KBNODE n );
270
void delete_kbnode( KBNODE node );
271
void add_kbnode( KBNODE root, KBNODE node );
272
void insert_kbnode( KBNODE root, KBNODE node, int pkttype );
273
void move_kbnode( KBNODE *root, KBNODE node, KBNODE where );
274
void remove_kbnode( KBNODE *root, KBNODE node );
275
KBNODE find_prev_kbnode( KBNODE root, KBNODE node, int pkttype );
276
KBNODE find_next_kbnode( KBNODE node, int pkttype );
277
KBNODE find_kbnode( KBNODE node, int pkttype );
278
KBNODE walk_kbnode( KBNODE root, KBNODE *context, int all );
279
void clear_kbnode_flags( KBNODE n );
280
int commit_kbnode( KBNODE *root );
281
void dump_kbnode( KBNODE node );
283
#endif /*G10_KEYDB_H*/