Line data Source code
1 : /* trustdb.h - Trust database
2 : * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 : * 2005, 2012 Free Software Foundation, Inc.
4 : *
5 : * This file is part of GnuPG.
6 : *
7 : * GnuPG is free software; you can redistribute it and/or modify
8 : * it under the terms of the GNU General Public License as published by
9 : * the Free Software Foundation; either version 3 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * GnuPG is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU General Public License
18 : * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #ifndef G10_TRUSTDB_H
22 : #define G10_TRUSTDB_H
23 :
24 : /* Trust values must be sorted in ascending order */
25 : #define TRUST_MASK 15
26 : #define TRUST_UNKNOWN 0 /* o: not yet calculated/assigned */
27 : #define TRUST_EXPIRED 1 /* e: calculation may be invalid */
28 : #define TRUST_UNDEFINED 2 /* q: not enough information for calculation */
29 : #define TRUST_NEVER 3 /* n: never trust this pubkey */
30 : #define TRUST_MARGINAL 4 /* m: marginally trusted */
31 : #define TRUST_FULLY 5 /* f: fully trusted */
32 : #define TRUST_ULTIMATE 6 /* u: ultimately trusted */
33 : /* trust values not covered by the mask */
34 : #define TRUST_FLAG_REVOKED 32 /* r: revoked */
35 : #define TRUST_FLAG_SUB_REVOKED 64 /* r: revoked but for subkeys */
36 : #define TRUST_FLAG_DISABLED 128 /* d: key/uid disabled */
37 : #define TRUST_FLAG_PENDING_CHECK 256 /* a check-trustdb is pending */
38 :
39 : /* Private value used in tofu.c - must be different from the trust
40 : values. */
41 : #define _tofu_GET_TRUST_ERROR 100
42 :
43 : /* Length of the hash used to select UIDs in keyedit.c. */
44 : #define NAMEHASH_LEN 20
45 :
46 :
47 : /*
48 : * A structure to store key identification as well as some stuff needed
49 : * for validation
50 : */
51 : struct key_item {
52 : struct key_item *next;
53 : unsigned int ownertrust,min_ownertrust;
54 : byte trust_depth;
55 : byte trust_value;
56 : char *trust_regexp;
57 : u32 kid[2];
58 : };
59 :
60 :
61 : /*
62 : * Check whether the signature SIG is in the klist K.
63 : */
64 : static inline struct key_item *
65 0 : is_in_klist (struct key_item *k, PKT_signature *sig)
66 : {
67 0 : for (; k; k = k->next)
68 : {
69 0 : if (k->kid[0] == sig->keyid[0] && k->kid[1] == sig->keyid[1])
70 0 : return k;
71 : }
72 0 : return NULL;
73 : }
74 :
75 :
76 :
77 : /*-- trust.c --*/
78 : int cache_disabled_value (PKT_public_key *pk);
79 : void register_trusted_keyid (u32 *keyid);
80 : void register_trusted_key (const char *string);
81 :
82 : const char *trust_value_to_string (unsigned int value);
83 : int string_to_trust_value (const char *str);
84 : const char *uid_trust_string_fixed (PKT_public_key *key, PKT_user_id *uid);
85 :
86 : unsigned int get_ownertrust (PKT_public_key *pk);
87 : void update_ownertrust (PKT_public_key *pk, unsigned int new_trust);
88 : int clear_ownertrusts (PKT_public_key *pk);
89 :
90 : void revalidation_mark (void);
91 : void check_trustdb_stale (void);
92 : void check_or_update_trustdb (void);
93 :
94 : unsigned int get_validity (PKT_public_key *pk, PKT_user_id *uid,
95 : PKT_signature *sig, int may_ask);
96 : int get_validity_info (PKT_public_key *pk, PKT_user_id *uid);
97 : const char *get_validity_string (PKT_public_key *pk, PKT_user_id *uid);
98 :
99 : void mark_usable_uid_certs (kbnode_t keyblock, kbnode_t uidnode,
100 : u32 *main_kid, struct key_item *klist,
101 : u32 curtime, u32 *next_expire);
102 :
103 : void clean_one_uid (kbnode_t keyblock, kbnode_t uidnode,
104 : int noisy, int self_only,
105 : int *uids_cleaned, int *sigs_cleaned);
106 : void clean_key (kbnode_t keyblock, int noisy, int self_only,
107 : int *uids_cleaned,int *sigs_cleaned);
108 :
109 :
110 :
111 : /*-- trustdb.c --*/
112 : void tdb_register_trusted_keyid (u32 *keyid);
113 : void tdb_register_trusted_key (const char *string);
114 : /* Returns whether KID is on the list of ultimately trusted keys. */
115 : int tdb_keyid_is_utk (u32 *kid);
116 : void check_trustdb (void);
117 : void update_trustdb (void);
118 : int setup_trustdb( int level, const char *dbname );
119 : void how_to_fix_the_trustdb (void);
120 : void init_trustdb( void );
121 : void tdb_check_trustdb_stale (void);
122 : void sync_trustdb( void );
123 :
124 : void tdb_revalidation_mark (void);
125 : int trustdb_pending_check(void);
126 : void tdb_check_or_update (void);
127 :
128 : int tdb_cache_disabled_value (PKT_public_key *pk);
129 :
130 : unsigned int tdb_get_validity_core (PKT_public_key *pk, PKT_user_id *uid,
131 : PKT_public_key *main_pk,
132 : PKT_signature *sig, int may_ask);
133 :
134 : void list_trust_path( const char *username );
135 : int enum_cert_paths( void **context, ulong *lid,
136 : unsigned *ownertrust, unsigned *validity );
137 : void enum_cert_paths_print( void **context, FILE *fp,
138 : int refresh, ulong selected_lid );
139 :
140 : void read_trust_options(byte *trust_model,ulong *created,ulong *nextcheck,
141 : byte *marginals,byte *completes,byte *cert_depth,
142 : byte *min_cert_level);
143 :
144 : unsigned int tdb_get_ownertrust (PKT_public_key *pk);
145 : unsigned int tdb_get_min_ownertrust (PKT_public_key *pk);
146 : int get_ownertrust_info (PKT_public_key *pk);
147 : const char *get_ownertrust_string (PKT_public_key *pk);
148 :
149 : void tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust);
150 : int tdb_clear_ownertrusts (PKT_public_key *pk);
151 :
152 : /*-- tdbdump.c --*/
153 : void list_trustdb (estream_t fp, const char *username);
154 : void export_ownertrust(void);
155 : void import_ownertrust(const char *fname);
156 :
157 : /*-- pkclist.c --*/
158 : int edit_ownertrust (PKT_public_key *pk, int mode );
159 :
160 : #endif /*G10_TRUSTDB_H*/
|