Coverage Report

Created: 2025-12-14 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnupg/g10/keydb.h
Line
Count
Source
1
/* keydb.h - Key database
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3
 *               2006, 2010 Free Software Foundation, Inc.
4
 * Copyright (C) 2015, 2016 g10 Code GmbH
5
 *
6
 * This file is part of GnuPG.
7
 *
8
 * GnuPG is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * GnuPG 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.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#ifndef G10_KEYDB_H
23
#define G10_KEYDB_H
24
25
#include "../common/types.h"
26
#include "../common/util.h"
27
#include "packet.h"
28
29
/* What qualifies as a certification (key-signature in contrast to a
30
 * data signature)?  Note that a back signature is special and can be
31
 * made by key and data signatures capable subkeys.) */
32
204k
#define IS_CERT(s)       (IS_KEY_SIG(s)       \
33
104k
                          || IS_UID_SIG(s)    \
34
104k
                          || IS_SUBKEY_SIG(s) \
35
104k
                          || IS_KEY_REV(s)    \
36
104k
                          || IS_UID_REV(s)    \
37
104k
                          || IS_SUBKEY_REV(s) \
38
204k
                          || IS_ATTST_SIGS(s) )
39
184k
#define IS_SIG(s)        (!IS_CERT(s))
40
846k
#define IS_KEY_SIG(s)    ((s)->sig_class == SIGCLASS_KEY)
41
1.65M
#define IS_UID_SIG(s)    (((s)->sig_class & ~3) == SIGCLASS_CERT)
42
520
#define IS_ATTST_SIGS(s) ((s)->sig_class == 0x16)
43
892k
#define IS_SUBKEY_SIG(s) ((s)->sig_class == SIGCLASS_SUBKEY)
44
700k
#define IS_BACK_SIG(s)   ((s)->sig_class == SIGCLASS_BACKSIG)
45
420k
#define IS_KEY_REV(s)    ((s)->sig_class == SIGCLASS_KEYREV)
46
184k
#define IS_UID_REV(s)    ((s)->sig_class == SIGCLASS_CERTREV)
47
411k
#define IS_SUBKEY_REV(s) ((s)->sig_class == SIGCLASS_SUBREV)
48
49
struct getkey_ctx_s;
50
typedef struct getkey_ctx_s *GETKEY_CTX;
51
typedef struct getkey_ctx_s *getkey_ctx_t;
52
53
/****************
54
 * A Keyblock is all packets which form an entire certificate;
55
 * i.e. the public key, certificate, trust packets, user ids,
56
 * signatures, and subkey.
57
 *
58
 * This structure is also used to bind arbitrary packets together.
59
 */
60
61
struct kbnode_struct
62
{
63
  kbnode_t next;
64
  PACKET *pkt;
65
  int flag;          /* Local use during keyblock processing (not cloned).*/
66
  unsigned int tag;  /* Ditto. */
67
  int private_flag;
68
};
69
70
4.48M
#define is_deleted_kbnode(a)  ((a)->private_flag & 1)
71
8.56M
#define is_cloned_kbnode(a)   ((a)->private_flag & 2)
72
73
74
/*
75
 * A structure to store key identification as well as some stuff
76
 * needed for key validation.
77
 */
78
struct key_item {
79
  struct key_item *next;
80
  unsigned int ownertrust,min_ownertrust;
81
  byte trust_depth;
82
  byte trust_value;
83
  char *trust_regexp;
84
  u32 kid[2];
85
};
86
87
88
/* Bit flags used with build_pk_list.  */
89
enum
90
  {
91
    PK_LIST_ENCRYPT_TO = 1, /* This is an encrypt-to recipient.    */
92
    PK_LIST_HIDDEN     = 2, /* This is a hidden recipient.         */
93
    PK_LIST_CONFIG     = 4, /* Specified via config file.          */
94
    PK_LIST_FROM_FILE  = 8  /* Take key from file with that name.  */
95
  };
96
97
/* To store private data in the flags the private data must be left
98
 * shifted by this value.  */
99
enum
100
  {
101
    PK_LIST_SHIFT = 4
102
  };
103
104
105
/* Structure to hold a couple of public key certificates. */
106
typedef struct pk_list *PK_LIST;  /* Deprecated. */
107
typedef struct pk_list *pk_list_t;
108
struct pk_list
109
{
110
  PK_LIST next;
111
  PKT_public_key *pk;
112
  int flags;           /* See PK_LIST_ constants. */
113
};
114
115
/* Structure to hold a list of secret key certificates.  */
116
typedef struct sk_list *SK_LIST;
117
struct sk_list
118
{
119
  SK_LIST next;
120
  PKT_public_key *pk;
121
  int mark; /* not used */
122
};
123
124
/* structure to collect all information which can be used to
125
 * identify a public key */
126
typedef struct pubkey_find_info *PUBKEY_FIND_INFO;
127
struct pubkey_find_info {
128
    u32  keyid[2];
129
    unsigned nbits;
130
    byte pubkey_algo;
131
    byte fingerprint[MAX_FINGERPRINT_LEN];
132
    char userid[1];
133
};
134
135
136
/* Helper type for preference functions. */
137
struct pref_hint
138
{
139
  int digest_length;  /* We want at least this digest length.  */
140
  int exact;          /* We need to use exactly this length.   */
141
};
142
143
144
/* Constants to describe from where a key was fetched or updated.  */
145
enum
146
  {
147
    KEYORG_UNKNOWN = 0,
148
    KEYORG_KS      = 1, /* Public keyserver.    */
149
    KEYORG_KS_PREF = 2, /* Preferred keysrver.  */
150
    KEYORG_DANE    = 3, /* OpenPGP DANE.        */
151
    KEYORG_WKD     = 4, /* Web Key Directory.   */
152
    KEYORG_URL     = 5, /* Trusted URL.         */
153
    KEYORG_FILE    = 6, /* Trusted file.        */
154
    KEYORG_SELF    = 7  /* We generated it.     */
155
  };
156
157
158
/*
159
 * Check whether the signature SIG is in the klist K.
160
 */
161
static inline struct key_item *
162
is_in_klist (struct key_item *k, PKT_signature *sig)
163
0
{
164
0
  for (; k; k = k->next)
165
0
    {
166
0
      if (k->kid[0] == sig->keyid[0] && k->kid[1] == sig->keyid[1])
167
0
        return k;
168
0
    }
169
0
  return NULL;
170
0
}
Unexecuted instantiation: fuzzer_stubs.c:is_in_klist
Unexecuted instantiation: fuzz_import.c:is_in_klist
Unexecuted instantiation: trustdb.c:is_in_klist
Unexecuted instantiation: pkclist.c:is_in_klist
Unexecuted instantiation: trust.c:is_in_klist
Unexecuted instantiation: cpr.c:is_in_klist
Unexecuted instantiation: key-clean.c:is_in_klist
Unexecuted instantiation: tdbio.c:is_in_klist
Unexecuted instantiation: sig-check.c:is_in_klist
Unexecuted instantiation: misc.c:is_in_klist
Unexecuted instantiation: armor.c:is_in_klist
Unexecuted instantiation: call-dirmngr.c:is_in_klist
Unexecuted instantiation: getkey.c:is_in_klist
Unexecuted instantiation: seskey.c:is_in_klist
Unexecuted instantiation: expand-group.c:is_in_klist
Unexecuted instantiation: call-agent.c:is_in_klist
Unexecuted instantiation: call-keyboxd.c:is_in_klist
Unexecuted instantiation: keyid.c:is_in_klist
Unexecuted instantiation: tdbdump.c:is_in_klist
Unexecuted instantiation: server.c:is_in_klist
Unexecuted instantiation: keydb.c:is_in_klist
Unexecuted instantiation: kbnode.c:is_in_klist
Unexecuted instantiation: pkglue.c:is_in_klist
Unexecuted instantiation: import.c:is_in_klist
Unexecuted instantiation: key-check.c:is_in_klist
Unexecuted instantiation: free-packet.c:is_in_klist
Unexecuted instantiation: keylist.c:is_in_klist
Unexecuted instantiation: helptext.c:is_in_klist
Unexecuted instantiation: parse-packet.c:is_in_klist
Unexecuted instantiation: decrypt.c:is_in_klist
Unexecuted instantiation: compress.c:is_in_klist
Unexecuted instantiation: openfile.c:is_in_klist
Unexecuted instantiation: mainproc.c:is_in_klist
Unexecuted instantiation: decrypt-data.c:is_in_klist
Unexecuted instantiation: keyring.c:is_in_klist
Unexecuted instantiation: pubkey-enc.c:is_in_klist
Unexecuted instantiation: keyserver.c:is_in_klist
Unexecuted instantiation: photoid.c:is_in_klist
Unexecuted instantiation: export.c:is_in_klist
Unexecuted instantiation: skclist.c:is_in_klist
Unexecuted instantiation: keyedit.c:is_in_klist
Unexecuted instantiation: objcache.c:is_in_klist
Unexecuted instantiation: encrypt.c:is_in_klist
Unexecuted instantiation: passphrase.c:is_in_klist
Unexecuted instantiation: verify.c:is_in_klist
Unexecuted instantiation: sign.c:is_in_klist
Unexecuted instantiation: build-packet.c:is_in_klist
Unexecuted instantiation: progress.c:is_in_klist
Unexecuted instantiation: plaintext.c:is_in_klist
Unexecuted instantiation: cipher-cfb.c:is_in_klist
Unexecuted instantiation: cipher-aead.c:is_in_klist
Unexecuted instantiation: ecdh.c:is_in_klist
Unexecuted instantiation: keygen.c:is_in_klist
Unexecuted instantiation: textfilter.c:is_in_klist
Unexecuted instantiation: revoke.c:is_in_klist
171
172
173
/*-- call-keyboxd.c --*/
174
175
/* Release all open contexts to the keyboxd.  */
176
void gpg_keyboxd_deinit_session_data (ctrl_t ctrl);
177
178
/* Create a new database handle.  Returns NULL on error, sets ERRNO,
179
 * and prints an error diagnostic. */
180
KEYDB_HANDLE keydb_new (ctrl_t ctrl);
181
182
/* Release a keydb handle.  */
183
void keydb_release (KEYDB_HANDLE hd);
184
185
/* Take a lock if we are not using the keyboxd.  */
186
gpg_error_t keydb_lock (KEYDB_HANDLE hd);
187
188
/* Return the keyblock last found by keydb_search.  */
189
gpg_error_t keydb_get_keyblock (KEYDB_HANDLE hd, kbnode_t *ret_kb);
190
191
/* Update the keyblock KB.  */
192
gpg_error_t keydb_update_keyblock (ctrl_t ctrl, KEYDB_HANDLE hd, kbnode_t kb);
193
194
/* Insert a keyblock into one of the storage system.  */
195
gpg_error_t keydb_insert_keyblock (KEYDB_HANDLE hd, kbnode_t kb);
196
197
/* Delete the currently selected keyblock.  */
198
gpg_error_t keydb_delete_keyblock (KEYDB_HANDLE hd);
199
200
/* Clears the current search result and resets the handle's position.  */
201
gpg_error_t keydb_search_reset (KEYDB_HANDLE hd);
202
203
/* Search the database for keys matching the search description.  */
204
gpg_error_t keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
205
                          size_t ndesc, size_t *descindex);
206
207
208
209
/*-- keydb.c --*/
210
211
1
#define KEYDB_RESOURCE_FLAG_PRIMARY  2  /* The primary resource.  */
212
2
#define KEYDB_RESOURCE_FLAG_DEFAULT  4  /* The default one.  */
213
2
#define KEYDB_RESOURCE_FLAG_READONLY 8  /* Open in read only mode.  */
214
1
#define KEYDB_RESOURCE_FLAG_GPGVDEF 16  /* Default file for gpgv.  */
215
216
/* Format a search term for debugging output.  The caller must free
217
   the result.  */
218
char *keydb_search_desc_dump (struct keydb_search_desc *desc);
219
220
/* Register a resource (keyring or keybox).  */
221
gpg_error_t keydb_add_resource (const char *url, unsigned int flags);
222
223
/* Dump some statistics to the log.  */
224
void keydb_dump_stats (void);
225
226
/* Set a flag on the handle to suppress use of cached results.  This
227
   is required for updating a keyring and for key listings.  Fixme:
228
   Using a new parameter for keydb_new might be a better solution.  */
229
void keydb_disable_caching (KEYDB_HANDLE hd);
230
231
/* Save the last found state and invalidate the current selection.  */
232
void keydb_push_found_state (KEYDB_HANDLE hd);
233
234
/* Restore the previous save state.  */
235
void keydb_pop_found_state (KEYDB_HANDLE hd);
236
237
/* Return the file name of the resource.  */
238
const char *keydb_get_resource_name (KEYDB_HANDLE hd);
239
240
/* Find the first writable resource.  */
241
gpg_error_t keydb_locate_writable (KEYDB_HANDLE hd);
242
243
/* Rebuild the on-disk caches of all key resources.  */
244
void keydb_rebuild_caches (ctrl_t ctrl, int noisy);
245
246
/* Return the number of skipped blocks (because they were to large to
247
   read from a keybox) since the last search reset.  */
248
unsigned long keydb_get_skipped_counter (KEYDB_HANDLE hd);
249
250
/* Return the first non-legacy key in the database.  */
251
gpg_error_t keydb_search_first (KEYDB_HANDLE hd);
252
253
/* Return the next key (not the next matching key!).  */
254
gpg_error_t keydb_search_next (KEYDB_HANDLE hd);
255
256
/* This is a convenience function for searching for keys with a long
257
   key id.  */
258
gpg_error_t keydb_search_kid (KEYDB_HANDLE hd, u32 *kid);
259
260
/* This is a convenience function for searching for keys by
261
 * fingerprint.  */
262
gpg_error_t keydb_search_fpr (KEYDB_HANDLE hd, const byte *fpr, size_t fprlen);
263
264
265
/*-- pkclist.c --*/
266
void show_revocation_reason (ctrl_t ctrl, PKT_public_key *pk, int mode );
267
gpg_error_t check_signatures_trust (ctrl_t ctrl, kbnode_t keyblock,
268
                                    PKT_public_key *pk, PKT_signature *sig);
269
270
void release_pk_list (PK_LIST pk_list);
271
int expand_id (const char *id, strlist_t *into, unsigned int flags);
272
strlist_t expand_group (strlist_t input, int prepend_input);
273
int  build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list);
274
gpg_error_t find_and_check_key (ctrl_t ctrl,
275
                                const char *name, unsigned int use,
276
                                int mark_hidden, int from_file,
277
                                pk_list_t *pk_list_addr);
278
279
int  algo_available( preftype_t preftype, int algo,
280
         const struct pref_hint *hint );
281
int  select_algo_from_prefs( PK_LIST pk_list, int preftype,
282
           int request, const struct pref_hint *hint);
283
int  select_mdc_from_pklist (PK_LIST pk_list);
284
aead_algo_t select_aead_from_pklist (pk_list_t pk_list);
285
void warn_missing_aead_from_pklist (PK_LIST pk_list);
286
void warn_missing_aes_from_pklist (PK_LIST pk_list);
287
288
/*-- skclist.c --*/
289
int  random_is_faked (void);
290
void release_sk_list( SK_LIST sk_list );
291
gpg_error_t build_sk_list (ctrl_t ctrl, strlist_t locusr,
292
                           SK_LIST *ret_sk_list, unsigned use);
293
294
/*-- passphrase.h --*/
295
296
/* Flags for passphrase_to_dek */
297
0
#define GETPASSWORD_FLAG_SYMDECRYPT  1
298
299
int  have_static_passphrase(void);
300
const char *get_static_passphrase (void);
301
void set_passphrase_from_string(const char *pass);
302
void read_passphrase_from_fd( int fd );
303
void passphrase_clear_cache (const char *cacheid);
304
DEK *passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
305
                        int create, int nocache,
306
                        const char *tryagain_text, unsigned int flags,
307
                        int *canceled);
308
void set_next_passphrase( const char *s );
309
char *get_last_passphrase(void);
310
void next_to_last_passphrase(void);
311
312
void emit_status_need_passphrase (ctrl_t ctrl, u32 *keyid,
313
                                  u32 *mainkeyid, int pubkey_algo);
314
315
0
#define FORMAT_KEYDESC_NORMAL  0
316
0
#define FORMAT_KEYDESC_IMPORT  1
317
0
#define FORMAT_KEYDESC_EXPORT  2
318
0
#define FORMAT_KEYDESC_DELKEY  3
319
0
#define FORMAT_KEYDESC_KEYGRIP 4
320
char *gpg_format_keydesc (ctrl_t ctrl,
321
                          PKT_public_key *pk, int mode, int escaped);
322
323
324
/*-- getkey.c --*/
325
326
/* Cache a copy of a public key in the public key cache.  */
327
void cache_public_key( PKT_public_key *pk );
328
329
/* Disable and drop the public key cache.  */
330
void getkey_disable_caches(void);
331
332
/* Return the public key used for signature SIG and store it at PK.  */
333
gpg_error_t get_pubkey_for_sig (ctrl_t ctrl,
334
                                PKT_public_key *pk, PKT_signature *sig,
335
                                PKT_public_key *forced_pk,
336
                                kbnode_t *r_keyblock);
337
338
/* Return the public key with the key id KEYID and store it at PK.
339
 * Optionally return the entire keyblock.  */
340
gpg_error_t get_pubkey_bykid (ctrl_t ctrl, PKT_public_key *pk,
341
                              kbnode_t *r_keyblock, u32 *keyid);
342
343
/* Same as get_pubkey_bykid but w/o r_keyblock.  */
344
int get_pubkey (ctrl_t ctrl, PKT_public_key *pk, u32 *keyid);
345
346
/* Same as get_pubkey but with auto LDAP fetch.  */
347
gpg_error_t get_pubkey_with_ldap_fallback (ctrl_t ctrl,
348
                                           PKT_public_key *pk, u32 * keyid);
349
350
/* Similar to get_pubkey, but it does not take PK->REQ_USAGE into
351
   account nor does it merge in the self-signed data.  This function
352
   also only considers primary keys.  */
353
int get_pubkey_fast (ctrl_t ctrl, PKT_public_key *pk, u32 *keyid);
354
355
/* Return the entire keyblock used to create SIG.  This is a
356
 * specialized version of get_pubkeyblock.  */
357
kbnode_t get_pubkeyblock_for_sig (ctrl_t ctrl, PKT_signature *sig);
358
359
/* Return the key block for the key with KEYID.  */
360
kbnode_t get_pubkeyblock_ext (ctrl_t ctrl, u32 *keyid, unsigned int flags);
361
kbnode_t get_pubkeyblock (ctrl_t ctrl, u32 *keyid);
362
363
/* A list used by get_pubkeys to gather all of the matches.  */
364
struct pubkey_s
365
{
366
  struct pubkey_s *next;
367
  /* The key to use (either the public key or the subkey).  */
368
  PKT_public_key *pk;
369
  kbnode_t keyblock;
370
};
371
typedef struct pubkey_s *pubkey_t;
372
373
/* Free a list of public keys.  */
374
void pubkeys_free (pubkey_t keys);
375
376
377
/* Mode flags for get_pubkey_byname.  */
378
enum get_pubkey_modes
379
  {
380
   GET_PUBKEY_NORMAL = 0,
381
   GET_PUBKEY_NO_AKL = 1,
382
   GET_PUBKEY_NO_LOCAL = 2,
383
   GET_PUBKEY_TRY_LDAP = 3
384
  };
385
386
/* Other flags for functions in getkey.c  */
387
0
#define GETKEY_WANT_SECRET   1  /* Only return keys having a secret key.  */
388
0
#define GETKEY_WITH_UNUSABLE 2  /* Include unusable keys.  */
389
0
#define GETKEY_ALLOW_ADSK    4  /* Always return ADSK keys.  */
390
391
392
/* Find a public key identified by NAME.  */
393
int get_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
394
                       GETKEY_CTX *retctx, PKT_public_key *pk,
395
           const char *name,
396
                       KBNODE *ret_keyblock, KEYDB_HANDLE *ret_kdbhd,
397
           int include_unusable);
398
399
/* Likewise, but only return the best match if NAME resembles a mail
400
 * address.  */
401
gpg_error_t get_best_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
402
                                    GETKEY_CTX *retctx, PKT_public_key *pk,
403
                                    const char *name, KBNODE *ret_keyblock,
404
                                    int include_unusable);
405
406
/* Get a public key directly from file FNAME.  */
407
gpg_error_t get_pubkey_fromfile (ctrl_t ctrl,
408
                                 PKT_public_key *pk, const char *fname,
409
                                 kbnode_t *r_keyblock);
410
411
/* Get a public key from a buffer.  */
412
gpg_error_t get_pubkey_from_buffer (ctrl_t ctrl, PKT_public_key *pkbuf,
413
                                    const void *buffer, size_t buflen,
414
                                    u32 *want_keyid, kbnode_t *r_keyblock);
415
416
/* Return the public key with the key id KEYID iff the secret key is
417
 * available and store it at PK.  */
418
gpg_error_t get_seckey (ctrl_t ctrl, PKT_public_key *pk, u32 *keyid);
419
420
/* Lookup a key with the specified fingerprint.  */
421
int get_pubkey_byfpr (ctrl_t ctrl, PKT_public_key *pk, kbnode_t *r_keyblock,
422
                      const byte *fpr, size_t fprlen);
423
424
/* This function is similar to get_pubkey_byfpr, but it doesn't
425
   merge the self-signed data into the public key and subkeys or into
426
   the user ids.  */
427
gpg_error_t get_pubkey_byfpr_fast (ctrl_t ctrl, PKT_public_key *pk,
428
                                   const byte *fpr, size_t fprlen);
429
430
/* This function is similar to get_pubkey_byfprint, but it doesn't
431
   merge the self-signed data into the public key and subkeys or into
432
   the user ids.  */
433
gpg_error_t get_keyblock_byfpr_fast (ctrl_t ctrl,
434
                                     kbnode_t *r_keyblock,
435
                                     KEYDB_HANDLE *r_hd,
436
                                     int primary_only,
437
                                     const byte *fpr, size_t fprlen,
438
                                     int lock);
439
440
441
/* Returns true if a secret key is available for the public key with
442
   key id KEYID.  */
443
int have_secret_key_with_kid (ctrl_t ctrl, u32 *keyid);
444
445
/* Parse the --default-key parameter.  Returns the last key (in terms
446
   of when the option is given) that is available.  */
447
const char *parse_def_secret_key (ctrl_t ctrl);
448
449
/* Look up a secret key.  */
450
gpg_error_t get_seckey_default (ctrl_t ctrl, PKT_public_key *pk);
451
gpg_error_t get_seckey_default_or_card (ctrl_t ctrl, PKT_public_key *pk,
452
                                        const byte *fpr, size_t fpr_len);
453
454
/* Search for keys matching some criteria.  */
455
gpg_error_t getkey_bynames (ctrl_t ctrl,
456
                            getkey_ctx_t *retctx, PKT_public_key *pk,
457
                            strlist_t names, unsigned int flags,
458
                            kbnode_t *ret_keyblock);
459
460
/* Search for one key matching some criteria.  */
461
gpg_error_t getkey_byname (ctrl_t ctrl,
462
                           getkey_ctx_t *retctx, PKT_public_key *pk,
463
                           const char *name, int want_secret,
464
                           kbnode_t *ret_keyblock);
465
466
/* Return the next search result.  */
467
gpg_error_t getkey_next (ctrl_t ctrl, getkey_ctx_t ctx,
468
                         PKT_public_key *pk, kbnode_t *ret_keyblock);
469
470
/* Release any resources used by a key listing context.  */
471
void getkey_end (ctrl_t ctrl, getkey_ctx_t ctx);
472
473
/* Return the database handle used by this context.  The context still
474
   owns the handle.  */
475
KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx);
476
477
/* Enumerate some secret keys.  */
478
gpg_error_t enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *pk);
479
480
/* Set the mainkey_id fields for all keys in KEYBLOCK.  */
481
void setup_main_keyids (kbnode_t keyblock);
482
483
/* This function merges information from the self-signed data into the
484
   data structures.  */
485
void merge_keys_and_selfsig (ctrl_t ctrl, kbnode_t keyblock);
486
487
/* This function parses the key flags and returns PUBKEY_USAGE_ flags.  */
488
unsigned int parse_key_usage (PKT_signature *sig);
489
490
char *get_user_id_string_native (ctrl_t ctrl, u32 *keyid);
491
char *get_long_user_id_string (ctrl_t ctrl, u32 *keyid);
492
char *get_user_id (ctrl_t ctrl, u32 *keyid, size_t *rn, int *r_nouid);
493
char *get_user_id_native (ctrl_t ctrl, u32 *keyid);
494
char *get_user_id_byfpr_native (ctrl_t ctrl, const byte *fpr, size_t fprlen);
495
496
void release_akl(void);
497
int akl_empty_or_only_local (void);
498
int parse_auto_key_locate(const char *options);
499
int parse_key_origin (char *string);
500
const char *key_origin_string (int origin);
501
502
/* Return an error if KEYBLOCK has a primary or subkey with the fpr.  */
503
gpg_error_t has_key_with_fingerprint (kbnode_t keyblock,
504
                                      const byte *fpr, size_t fprlen);
505
506
/*-- keyid.c --*/
507
int pubkey_letter( int algo );
508
char *pubkey_string (PKT_public_key *pk, char *buffer, size_t bufsize);
509
int compare_pubkey_string (const char *astr, const char *bstr);
510
#define PUBKEY_STRING_SIZE 32
511
u32 v3_keyid (gcry_mpi_t a, u32 *ki);
512
void hash_public_key( gcry_md_hd_t md, PKT_public_key *pk );
513
char *format_keyid (u32 *keyid, int format, char *buffer, int len);
514
515
/* Return PK's keyid.  The memory is owned by PK.  */
516
u32 *pk_keyid (PKT_public_key *pk);
517
518
/* Return the keyid of the primary key associated with PK.  The memory
519
   is owned by PK.  */
520
u32 *pk_main_keyid (PKT_public_key *pk);
521
522
/* Order A and B.  If A < B then return -1, if A == B then return 0,
523
   and if A > B then return 1.  */
524
static int GPGRT_ATTR_UNUSED
525
keyid_cmp (const u32 *a, const u32 *b)
526
18.2k
{
527
18.2k
  if (a[0] < b[0])
528
1.55k
    return -1;
529
16.6k
  if (a[0] > b[0])
530
5.66k
    return 1;
531
11.0k
  if (a[1] < b[1])
532
243
    return -1;
533
10.7k
  if (a[1] > b[1])
534
551
    return 1;
535
10.2k
  return 0;
536
10.7k
}
Unexecuted instantiation: fuzzer_stubs.c:keyid_cmp
Unexecuted instantiation: fuzz_import.c:keyid_cmp
Unexecuted instantiation: trustdb.c:keyid_cmp
Unexecuted instantiation: pkclist.c:keyid_cmp
Unexecuted instantiation: trust.c:keyid_cmp
Unexecuted instantiation: cpr.c:keyid_cmp
Unexecuted instantiation: key-clean.c:keyid_cmp
Unexecuted instantiation: tdbio.c:keyid_cmp
sig-check.c:keyid_cmp
Line
Count
Source
526
3.81k
{
527
3.81k
  if (a[0] < b[0])
528
0
    return -1;
529
3.81k
  if (a[0] > b[0])
530
0
    return 1;
531
3.81k
  if (a[1] < b[1])
532
0
    return -1;
533
3.81k
  if (a[1] > b[1])
534
0
    return 1;
535
3.81k
  return 0;
536
3.81k
}
Unexecuted instantiation: misc.c:keyid_cmp
Unexecuted instantiation: armor.c:keyid_cmp
Unexecuted instantiation: call-dirmngr.c:keyid_cmp
Unexecuted instantiation: getkey.c:keyid_cmp
Unexecuted instantiation: seskey.c:keyid_cmp
Unexecuted instantiation: expand-group.c:keyid_cmp
Unexecuted instantiation: call-agent.c:keyid_cmp
Unexecuted instantiation: call-keyboxd.c:keyid_cmp
Unexecuted instantiation: keyid.c:keyid_cmp
Unexecuted instantiation: tdbdump.c:keyid_cmp
Unexecuted instantiation: server.c:keyid_cmp
Unexecuted instantiation: keydb.c:keyid_cmp
Unexecuted instantiation: kbnode.c:keyid_cmp
Unexecuted instantiation: pkglue.c:keyid_cmp
Unexecuted instantiation: import.c:keyid_cmp
key-check.c:keyid_cmp
Line
Count
Source
526
14.4k
{
527
14.4k
  if (a[0] < b[0])
528
1.55k
    return -1;
529
12.8k
  if (a[0] > b[0])
530
5.66k
    return 1;
531
7.20k
  if (a[1] < b[1])
532
243
    return -1;
533
6.96k
  if (a[1] > b[1])
534
551
    return 1;
535
6.41k
  return 0;
536
6.96k
}
Unexecuted instantiation: free-packet.c:keyid_cmp
Unexecuted instantiation: keylist.c:keyid_cmp
Unexecuted instantiation: helptext.c:keyid_cmp
Unexecuted instantiation: parse-packet.c:keyid_cmp
Unexecuted instantiation: decrypt.c:keyid_cmp
Unexecuted instantiation: compress.c:keyid_cmp
Unexecuted instantiation: openfile.c:keyid_cmp
Unexecuted instantiation: mainproc.c:keyid_cmp
Unexecuted instantiation: decrypt-data.c:keyid_cmp
Unexecuted instantiation: keyring.c:keyid_cmp
Unexecuted instantiation: pubkey-enc.c:keyid_cmp
Unexecuted instantiation: keyserver.c:keyid_cmp
Unexecuted instantiation: photoid.c:keyid_cmp
Unexecuted instantiation: export.c:keyid_cmp
Unexecuted instantiation: skclist.c:keyid_cmp
Unexecuted instantiation: keyedit.c:keyid_cmp
Unexecuted instantiation: objcache.c:keyid_cmp
Unexecuted instantiation: encrypt.c:keyid_cmp
Unexecuted instantiation: passphrase.c:keyid_cmp
Unexecuted instantiation: verify.c:keyid_cmp
Unexecuted instantiation: sign.c:keyid_cmp
Unexecuted instantiation: build-packet.c:keyid_cmp
Unexecuted instantiation: progress.c:keyid_cmp
Unexecuted instantiation: plaintext.c:keyid_cmp
Unexecuted instantiation: cipher-cfb.c:keyid_cmp
Unexecuted instantiation: cipher-aead.c:keyid_cmp
Unexecuted instantiation: ecdh.c:keyid_cmp
Unexecuted instantiation: keygen.c:keyid_cmp
Unexecuted instantiation: textfilter.c:keyid_cmp
Unexecuted instantiation: revoke.c:keyid_cmp
537
538
/* Return true if both keyids are equal. */
539
static int GPGRT_ATTR_UNUSED
540
keyid_eq (const u32 *a, const u32 *b)
541
0
{
542
0
  return a[0] == b[0] && a[1] == b[1];
543
0
}
Unexecuted instantiation: fuzzer_stubs.c:keyid_eq
Unexecuted instantiation: fuzz_import.c:keyid_eq
Unexecuted instantiation: trustdb.c:keyid_eq
Unexecuted instantiation: pkclist.c:keyid_eq
Unexecuted instantiation: trust.c:keyid_eq
Unexecuted instantiation: cpr.c:keyid_eq
Unexecuted instantiation: key-clean.c:keyid_eq
Unexecuted instantiation: tdbio.c:keyid_eq
Unexecuted instantiation: sig-check.c:keyid_eq
Unexecuted instantiation: misc.c:keyid_eq
Unexecuted instantiation: armor.c:keyid_eq
Unexecuted instantiation: call-dirmngr.c:keyid_eq
Unexecuted instantiation: getkey.c:keyid_eq
Unexecuted instantiation: seskey.c:keyid_eq
Unexecuted instantiation: expand-group.c:keyid_eq
Unexecuted instantiation: call-agent.c:keyid_eq
Unexecuted instantiation: call-keyboxd.c:keyid_eq
Unexecuted instantiation: keyid.c:keyid_eq
Unexecuted instantiation: tdbdump.c:keyid_eq
Unexecuted instantiation: server.c:keyid_eq
Unexecuted instantiation: keydb.c:keyid_eq
Unexecuted instantiation: kbnode.c:keyid_eq
Unexecuted instantiation: pkglue.c:keyid_eq
Unexecuted instantiation: import.c:keyid_eq
Unexecuted instantiation: key-check.c:keyid_eq
Unexecuted instantiation: free-packet.c:keyid_eq
Unexecuted instantiation: keylist.c:keyid_eq
Unexecuted instantiation: helptext.c:keyid_eq
Unexecuted instantiation: parse-packet.c:keyid_eq
Unexecuted instantiation: decrypt.c:keyid_eq
Unexecuted instantiation: compress.c:keyid_eq
Unexecuted instantiation: openfile.c:keyid_eq
Unexecuted instantiation: mainproc.c:keyid_eq
Unexecuted instantiation: decrypt-data.c:keyid_eq
Unexecuted instantiation: keyring.c:keyid_eq
Unexecuted instantiation: pubkey-enc.c:keyid_eq
Unexecuted instantiation: keyserver.c:keyid_eq
Unexecuted instantiation: photoid.c:keyid_eq
Unexecuted instantiation: export.c:keyid_eq
Unexecuted instantiation: skclist.c:keyid_eq
Unexecuted instantiation: keyedit.c:keyid_eq
Unexecuted instantiation: objcache.c:keyid_eq
Unexecuted instantiation: encrypt.c:keyid_eq
Unexecuted instantiation: passphrase.c:keyid_eq
Unexecuted instantiation: verify.c:keyid_eq
Unexecuted instantiation: sign.c:keyid_eq
Unexecuted instantiation: build-packet.c:keyid_eq
Unexecuted instantiation: progress.c:keyid_eq
Unexecuted instantiation: plaintext.c:keyid_eq
Unexecuted instantiation: cipher-cfb.c:keyid_eq
Unexecuted instantiation: cipher-aead.c:keyid_eq
Unexecuted instantiation: ecdh.c:keyid_eq
Unexecuted instantiation: keygen.c:keyid_eq
Unexecuted instantiation: textfilter.c:keyid_eq
Unexecuted instantiation: revoke.c:keyid_eq
544
545
/* Return whether PK is a primary key.  */
546
static int GPGRT_ATTR_UNUSED
547
pk_is_primary (PKT_public_key *pk)
548
0
{
549
0
  return keyid_eq (pk_keyid (pk), pk_main_keyid (pk));
550
0
}
Unexecuted instantiation: fuzzer_stubs.c:pk_is_primary
Unexecuted instantiation: fuzz_import.c:pk_is_primary
Unexecuted instantiation: trustdb.c:pk_is_primary
Unexecuted instantiation: pkclist.c:pk_is_primary
Unexecuted instantiation: trust.c:pk_is_primary
Unexecuted instantiation: cpr.c:pk_is_primary
Unexecuted instantiation: key-clean.c:pk_is_primary
Unexecuted instantiation: tdbio.c:pk_is_primary
Unexecuted instantiation: sig-check.c:pk_is_primary
Unexecuted instantiation: misc.c:pk_is_primary
Unexecuted instantiation: armor.c:pk_is_primary
Unexecuted instantiation: call-dirmngr.c:pk_is_primary
Unexecuted instantiation: getkey.c:pk_is_primary
Unexecuted instantiation: seskey.c:pk_is_primary
Unexecuted instantiation: expand-group.c:pk_is_primary
Unexecuted instantiation: call-agent.c:pk_is_primary
Unexecuted instantiation: call-keyboxd.c:pk_is_primary
Unexecuted instantiation: keyid.c:pk_is_primary
Unexecuted instantiation: tdbdump.c:pk_is_primary
Unexecuted instantiation: server.c:pk_is_primary
Unexecuted instantiation: keydb.c:pk_is_primary
Unexecuted instantiation: kbnode.c:pk_is_primary
Unexecuted instantiation: pkglue.c:pk_is_primary
Unexecuted instantiation: import.c:pk_is_primary
Unexecuted instantiation: key-check.c:pk_is_primary
Unexecuted instantiation: free-packet.c:pk_is_primary
Unexecuted instantiation: keylist.c:pk_is_primary
Unexecuted instantiation: helptext.c:pk_is_primary
Unexecuted instantiation: parse-packet.c:pk_is_primary
Unexecuted instantiation: decrypt.c:pk_is_primary
Unexecuted instantiation: compress.c:pk_is_primary
Unexecuted instantiation: openfile.c:pk_is_primary
Unexecuted instantiation: mainproc.c:pk_is_primary
Unexecuted instantiation: decrypt-data.c:pk_is_primary
Unexecuted instantiation: keyring.c:pk_is_primary
Unexecuted instantiation: pubkey-enc.c:pk_is_primary
Unexecuted instantiation: keyserver.c:pk_is_primary
Unexecuted instantiation: photoid.c:pk_is_primary
Unexecuted instantiation: export.c:pk_is_primary
Unexecuted instantiation: skclist.c:pk_is_primary
Unexecuted instantiation: keyedit.c:pk_is_primary
Unexecuted instantiation: objcache.c:pk_is_primary
Unexecuted instantiation: encrypt.c:pk_is_primary
Unexecuted instantiation: passphrase.c:pk_is_primary
Unexecuted instantiation: verify.c:pk_is_primary
Unexecuted instantiation: sign.c:pk_is_primary
Unexecuted instantiation: build-packet.c:pk_is_primary
Unexecuted instantiation: progress.c:pk_is_primary
Unexecuted instantiation: plaintext.c:pk_is_primary
Unexecuted instantiation: cipher-cfb.c:pk_is_primary
Unexecuted instantiation: cipher-aead.c:pk_is_primary
Unexecuted instantiation: ecdh.c:pk_is_primary
Unexecuted instantiation: keygen.c:pk_is_primary
Unexecuted instantiation: textfilter.c:pk_is_primary
Unexecuted instantiation: revoke.c:pk_is_primary
551
552
/* Copy the keyid in SRC to DEST and return DEST.  */
553
u32 *keyid_copy (u32 *dest, const u32 *src);
554
555
size_t keystrlen(void);
556
const char *keystr(u32 *keyid);
557
const char *keystr_with_sub (u32 *main_kid, u32 *sub_kid);
558
const char *keystr_from_pk(PKT_public_key *pk);
559
const char *keystr_from_pk_with_sub (PKT_public_key *main_pk,
560
                                     PKT_public_key *sub_pk);
561
562
/* Return PK's key id as a string using the default format.  PK owns
563
   the storage.  */
564
const char *pk_keyid_str (PKT_public_key *pk);
565
566
const char *keystr_from_desc(KEYDB_SEARCH_DESC *desc);
567
u32 keyid_from_pk( PKT_public_key *pk, u32 *keyid );
568
u32 keyid_from_sig (PKT_signature *sig, u32 *keyid );
569
u32 keyid_from_fingerprint (ctrl_t ctrl, const byte *fprint, size_t fprint_len,
570
                            u32 *keyid);
571
byte *namehash_from_uid(PKT_user_id *uid);
572
unsigned nbits_from_pk( PKT_public_key *pk );
573
574
/* Convert an UTC TIMESTAMP into an UTC yyyy-mm-dd string.  Return
575
 * that string.  The caller should pass a buffer with at least a size
576
 * of MK_DATESTR_SIZE.  */
577
char *mk_datestr (char *buffer, size_t bufsize, u32 timestamp);
578
#define MK_DATESTR_SIZE 11
579
580
const char *dateonlystr_from_pk (PKT_public_key *pk);
581
const char *datestr_from_pk( PKT_public_key *pk );
582
const char *dateonlystr_from_sig( PKT_signature *sig );
583
const char *datestr_from_sig( PKT_signature *sig );
584
const char *expirestr_from_pk( PKT_public_key *pk );
585
const char *expirestr_from_sig( PKT_signature *sig );
586
const char *revokestr_from_pk( PKT_public_key *pk );
587
const char *usagestr_from_pk (PKT_public_key *pk, int fill);
588
const char *colon_strtime (u32 t);
589
const char *colon_datestr_from_pk (PKT_public_key *pk);
590
const char *colon_datestr_from_sig (PKT_signature *sig);
591
const char *colon_expirestr_from_sig (PKT_signature *sig);
592
byte *fingerprint_from_pk( PKT_public_key *pk, byte *buf, size_t *ret_len );
593
byte *v5_fingerprint_from_pk (PKT_public_key *pk, byte *array, size_t *ret_len);
594
void fpr20_from_pk (PKT_public_key *pk, byte array[20]);
595
void fpr20_from_fpr (const byte *fpr, unsigned int fprlen, byte array[20]);
596
char *hexfingerprint (PKT_public_key *pk, char *buffer, size_t buflen);
597
char *v5hexfingerprint (PKT_public_key *pk, char *buffer, size_t buflen);
598
char *format_hexfingerprint (const char *fingerprint,
599
                             char *buffer, size_t buflen);
600
gpg_error_t keygrip_from_pk (PKT_public_key *pk, unsigned char *array,
601
                             int get_second);
602
gpg_error_t hexkeygrip_from_pk (PKT_public_key *pk, char **r_grip);
603
char *ecdh_param_str_from_pk (PKT_public_key *pk);
604
605
606
/*-- kbnode.c --*/
607
KBNODE new_kbnode( PACKET *pkt );
608
kbnode_t new_kbnode2 (kbnode_t list, PACKET *pkt);
609
KBNODE clone_kbnode( KBNODE node );
610
void release_kbnode( KBNODE n );
611
void delete_kbnode( KBNODE node );
612
void add_kbnode( KBNODE root, KBNODE node );
613
void insert_kbnode( KBNODE root, KBNODE node, int pkttype );
614
void move_kbnode( KBNODE *root, KBNODE node, KBNODE where );
615
void remove_kbnode( KBNODE *root, KBNODE node );
616
KBNODE find_prev_kbnode( KBNODE root, KBNODE node, int pkttype );
617
KBNODE find_next_kbnode( KBNODE node, int pkttype );
618
KBNODE find_kbnode( KBNODE node, int pkttype );
619
KBNODE walk_kbnode( KBNODE root, KBNODE *context, int all );
620
void clear_kbnode_flags( KBNODE n );
621
int  commit_kbnode( KBNODE *root );
622
void dump_kbnode( KBNODE node );
623
624
#endif /*G10_KEYDB_H*/