~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to g10/keydb.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* keydb.h - Key database
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
#ifndef G10_KEYDB_H
 
22
#define G10_KEYDB_H
 
23
 
 
24
#include "types.h"
 
25
#include "global.h"
 
26
#include "packet.h"
 
27
#include "cipher.h"
 
28
 
 
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)
 
39
 
 
40
struct getkey_ctx_s;
 
41
typedef struct getkey_ctx_s *GETKEY_CTX;
 
42
 
 
43
/****************
 
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.
 
47
 *
 
48
 * This structure is also used to bind arbitrary packets together.
 
49
 */
 
50
 
 
51
struct kbnode_struct {
 
52
    KBNODE next;
 
53
    PACKET *pkt;
 
54
    int flag;
 
55
    int private_flag;
 
56
    ulong recno;  /* used while updating the trustdb */
 
57
};
 
58
 
 
59
#define is_deleted_kbnode(a)  ((a)->private_flag & 1)
 
60
#define is_cloned_kbnode(a)   ((a)->private_flag & 2)
 
61
 
 
62
 
 
63
enum resource_type {
 
64
    rt_UNKNOWN = 0,
 
65
    rt_RING = 1
 
66
};
 
67
 
 
68
 
 
69
/****************
 
70
 * A data structre to hold information about the external position
 
71
 * of a keyblock.
 
72
 */
 
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 */
 
81
    int valid;
 
82
};
 
83
typedef struct keyblock_pos_struct KBPOS;
 
84
 
 
85
/* structure to hold a couple of public key certificates */
 
86
typedef struct pk_list *PK_LIST;
 
87
struct pk_list {
 
88
    PK_LIST next;
 
89
    PKT_public_key *pk;
 
90
    int flags; /* flag bit 1==throw_keyid */
 
91
};
 
92
 
 
93
/* structure to hold a couple of secret key certificates */
 
94
typedef struct sk_list *SK_LIST;
 
95
struct sk_list {
 
96
    SK_LIST next;
 
97
    PKT_secret_key *sk;
 
98
    int mark; /* not used */
 
99
};
 
100
 
 
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 {
 
105
    u32  keyid[2];
 
106
    unsigned nbits;
 
107
    byte pubkey_algo;
 
108
    byte fingerprint[MAX_FINGERPRINT_LEN];
 
109
    char userid[1];
 
110
};
 
111
 
 
112
 
 
113
typedef struct keydb_handle *KEYDB_HANDLE;
 
114
 
 
115
typedef enum {
 
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
 
130
} KeydbSearchMode;
 
131
 
 
132
struct keydb_search_desc {
 
133
    KeydbSearchMode mode;
 
134
    int (*skipfnc)(void *,u32*);
 
135
    void *skipfncvalue;
 
136
    union {
 
137
        const char *name;
 
138
        char fpr[MAX_FINGERPRINT_LEN];
 
139
        u32  kid[2];
 
140
    } u;
 
141
    int exact;
 
142
};
 
143
 
 
144
/*-- keydb.c --*/
 
145
 
 
146
/*
 
147
  Flag 1 == force
 
148
  Flag 2 == default
 
149
*/
 
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);
 
168
 
 
169
 
 
170
/*-- pkclist.c --*/
 
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);
 
179
 
 
180
/*-- skclist.c --*/
 
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 );
 
184
 
 
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);
 
194
 
 
195
/*-- getkey.c --*/
 
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,
 
212
                                                 size_t fprint_len );
 
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,
 
216
                                                 size_t fprint_len );
 
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);
 
235
 
 
236
/*-- keyid.c --*/
 
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 );
 
252
 
 
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);
 
258
 
 
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 );
 
261
 
 
262
char *serialno_and_fpr_from_sk (const unsigned char *sn, size_t snlen,
 
263
                                PKT_secret_key *sk);
 
264
 
 
265
 
 
266
/*-- kbnode.c --*/
 
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 );
 
282
 
 
283
#endif /*G10_KEYDB_H*/