chiark / gitweb /
dirmngr: New debug message on correctly initialized libdns.
[gnupg2.git] / g10 / trustdb.h
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 <https://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 #define TRUST_FLAG_TOFU_BASED    512 /* The trust value is based on
39                                       * the TOFU information.  */
40
41 /* Private value used in tofu.c - must be different from the trust
42    values.  */
43 #define _tofu_GET_TRUST_ERROR 100
44
45 /* Length of the hash used to select UIDs in keyedit.c.  */
46 #define NAMEHASH_LEN  20
47
48
49 /*
50  * A structure to store key identification as well as some stuff needed
51  * for validation
52  */
53 struct key_item {
54   struct key_item *next;
55   unsigned int ownertrust,min_ownertrust;
56   byte trust_depth;
57   byte trust_value;
58   char *trust_regexp;
59   u32 kid[2];
60 };
61
62
63 /*
64  * Check whether the signature SIG is in the klist K.
65  */
66 static inline struct key_item *
67 is_in_klist (struct key_item *k, PKT_signature *sig)
68 {
69   for (; k; k = k->next)
70     {
71       if (k->kid[0] == sig->keyid[0] && k->kid[1] == sig->keyid[1])
72         return k;
73     }
74   return NULL;
75 }
76
77
78
79 /*-- trust.c --*/
80 int cache_disabled_value (PKT_public_key *pk);
81 void register_trusted_keyid (u32 *keyid);
82 void register_trusted_key (const char *string);
83
84 const char *trust_value_to_string (unsigned int value);
85 int string_to_trust_value (const char *str);
86 const char *uid_trust_string_fixed (ctrl_t ctrl,
87                                     PKT_public_key *key, PKT_user_id *uid);
88
89 unsigned int get_ownertrust (PKT_public_key *pk);
90 void update_ownertrust (PKT_public_key *pk, unsigned int new_trust);
91 int clear_ownertrusts (PKT_public_key *pk);
92
93 void revalidation_mark (void);
94 void check_trustdb_stale (ctrl_t ctrl);
95 void check_or_update_trustdb (ctrl_t ctrl);
96
97 unsigned int get_validity (ctrl_t ctrl, kbnode_t kb, PKT_public_key *pk,
98                            PKT_user_id *uid,
99                            PKT_signature *sig, int may_ask);
100 int get_validity_info (ctrl_t ctrl, kbnode_t kb, PKT_public_key *pk,
101                        PKT_user_id *uid);
102 const char *get_validity_string (ctrl_t ctrl,
103                                  PKT_public_key *pk, PKT_user_id *uid);
104
105 void mark_usable_uid_certs (kbnode_t keyblock, kbnode_t uidnode,
106                             u32 *main_kid, struct key_item *klist,
107                             u32 curtime, u32 *next_expire);
108
109 void clean_one_uid (kbnode_t keyblock, kbnode_t uidnode,
110                     int noisy, int self_only,
111                     int *uids_cleaned, int *sigs_cleaned);
112 void clean_key (kbnode_t keyblock, int noisy, int self_only,
113                 int *uids_cleaned,int *sigs_cleaned);
114
115
116
117 /*-- trustdb.c --*/
118 void tdb_register_trusted_keyid (u32 *keyid);
119 void tdb_register_trusted_key (const char *string);
120 /* Returns whether KID is on the list of ultimately trusted keys.  */
121 int tdb_keyid_is_utk (u32 *kid);
122 /* Return the list of ultimately trusted keys.  The caller must not
123  * modify this list nor must it free the list.  */
124 struct key_item *tdb_utks (void);
125 void check_trustdb (ctrl_t ctrl);
126 void update_trustdb (ctrl_t ctrl);
127 int setup_trustdb( int level, const char *dbname );
128 void how_to_fix_the_trustdb (void);
129 const char *trust_model_string (int model);
130 void init_trustdb( void );
131 void tdb_check_trustdb_stale (ctrl_t ctrl);
132 void sync_trustdb( void );
133
134 void tdb_revalidation_mark (void);
135 int trustdb_pending_check(void);
136 void tdb_check_or_update (ctrl_t ctrl);
137
138 int tdb_cache_disabled_value (PKT_public_key *pk);
139
140 unsigned int tdb_get_validity_core (ctrl_t ctrl, kbnode_t kb,
141                                     PKT_public_key *pk, PKT_user_id *uid,
142                                     PKT_public_key *main_pk,
143                                     PKT_signature *sig, int may_ask);
144
145 void list_trust_path( const char *username );
146 int enum_cert_paths( void **context, ulong *lid,
147                      unsigned *ownertrust, unsigned *validity );
148 void enum_cert_paths_print( void **context, FILE *fp,
149                                            int refresh, ulong selected_lid );
150
151 void read_trust_options(byte *trust_model,ulong *created,ulong *nextcheck,
152                         byte *marginals,byte *completes,byte *cert_depth,
153                         byte *min_cert_level);
154
155 unsigned int tdb_get_ownertrust (PKT_public_key *pk);
156 unsigned int tdb_get_min_ownertrust (PKT_public_key *pk);
157 int get_ownertrust_info (PKT_public_key *pk);
158 const char *get_ownertrust_string (PKT_public_key *pk);
159
160 void tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust);
161 int tdb_clear_ownertrusts (PKT_public_key *pk);
162
163 /*-- tdbdump.c --*/
164 void list_trustdb (estream_t fp, const char *username);
165 void export_ownertrust(void);
166 void import_ownertrust(const char *fname);
167
168 /*-- pkclist.c --*/
169 int edit_ownertrust (ctrl_t ctrl, PKT_public_key *pk, int mode);
170
171 #endif /*G10_TRUSTDB_H*/