1 /* keybox.h - Keybox operations
2 * Copyright (C) 2001, 2003, 2012 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 3 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, see <https://www.gnu.org/licenses/>.
29 #include "../common/iobuf.h"
30 #include "keybox-search-desc.h"
32 #ifdef KEYBOX_WITH_X509
36 typedef struct keybox_handle *KEYBOX_HANDLE;
41 KEYBOX_FLAG_BLOB, /* The blob flags. */
42 KEYBOX_FLAG_VALIDITY, /* The validity of the entire key. */
43 KEYBOX_FLAG_OWNERTRUST, /* The assigned ownertrust. */
44 KEYBOX_FLAG_KEY, /* The key flags; requires a key index. */
45 KEYBOX_FLAG_UID, /* The user ID flags; requires an uid index. */
46 KEYBOX_FLAG_UID_VALIDITY,/* The validity of a specific uid, requires
48 KEYBOX_FLAG_CREATED_AT, /* The date the block was created. */
49 KEYBOX_FLAG_SIG_INFO, /* The signature info block. */
52 /* Flag values used with KEYBOX_FLAG_BLOB. */
53 #define KEYBOX_FLAG_BLOB_SECRET 1
54 #define KEYBOX_FLAG_BLOB_EPHEMERAL 2
56 /* The keybox blob types. */
59 KEYBOX_BLOBTYPE_EMPTY = 0,
60 KEYBOX_BLOBTYPE_HEADER = 1,
61 KEYBOX_BLOBTYPE_PGP = 2,
62 KEYBOX_BLOBTYPE_X509 = 3
66 /*-- keybox-init.c --*/
67 gpg_error_t keybox_register_file (const char *fname, int secret,
69 int keybox_is_writable (void *token);
71 KEYBOX_HANDLE keybox_new_openpgp (void *token, int secret);
72 KEYBOX_HANDLE keybox_new_x509 (void *token, int secret);
73 void keybox_release (KEYBOX_HANDLE hd);
74 void keybox_push_found_state (KEYBOX_HANDLE hd);
75 void keybox_pop_found_state (KEYBOX_HANDLE hd);
76 const char *keybox_get_resource_name (KEYBOX_HANDLE hd);
77 int keybox_set_ephemeral (KEYBOX_HANDLE hd, int yes);
79 gpg_error_t keybox_lock (KEYBOX_HANDLE hd, int yes);
81 /*-- keybox-file.c --*/
82 /* Fixme: This function does not belong here: Provide a better
83 interface to create a new keybox file. */
84 int _keybox_write_header_blob (FILE *fp, int openpgp_flag);
86 /*-- keybox-search.c --*/
87 gpg_error_t keybox_get_keyblock (KEYBOX_HANDLE hd, iobuf_t *r_iobuf,
88 int *r_uid_no, int *r_pk_no, u32 **sigstatus);
89 #ifdef KEYBOX_WITH_X509
90 int keybox_get_cert (KEYBOX_HANDLE hd, ksba_cert_t *ret_cert);
91 #endif /*KEYBOX_WITH_X509*/
92 int keybox_get_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int *value);
94 gpg_error_t keybox_search_reset (KEYBOX_HANDLE hd);
95 gpg_error_t keybox_search (KEYBOX_HANDLE hd,
96 KEYBOX_SEARCH_DESC *desc, size_t ndesc,
97 keybox_blobtype_t want_blobtype,
98 size_t *r_descindex, unsigned long *r_skipped);
100 off_t keybox_offset (KEYBOX_HANDLE hd);
101 gpg_error_t keybox_seek (KEYBOX_HANDLE hd, off_t offset);
103 /*-- keybox-update.c --*/
104 gpg_error_t keybox_insert_keyblock (KEYBOX_HANDLE hd,
105 const void *image, size_t imagelen,
107 gpg_error_t keybox_update_keyblock (KEYBOX_HANDLE hd,
108 const void *image, size_t imagelen);
110 #ifdef KEYBOX_WITH_X509
111 int keybox_insert_cert (KEYBOX_HANDLE hd, ksba_cert_t cert,
112 unsigned char *sha1_digest);
113 int keybox_update_cert (KEYBOX_HANDLE hd, ksba_cert_t cert,
114 unsigned char *sha1_digest);
115 #endif /*KEYBOX_WITH_X509*/
116 int keybox_set_flags (KEYBOX_HANDLE hd, int what, int idx, unsigned int value);
118 int keybox_delete (KEYBOX_HANDLE hd);
119 int keybox_compress (KEYBOX_HANDLE hd);
125 int keybox_locate_writable (KEYBOX_HANDLE hd);
126 int keybox_rebuild_cache (void *);
130 /*-- keybox-util.c --*/
131 void keybox_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
132 void *(*new_realloc_func)(void *p, size_t n),
133 void (*new_free_func)(void*) );
135 gpg_error_t keybox_tmp_names (const char *filename, int for_keyring,
136 char **r_bakname, char **r_tmpname);