jpayne@69
|
1 /*
|
jpayne@69
|
2 * Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
jpayne@69
|
3 *
|
jpayne@69
|
4 * Licensed under the OpenSSL license (the "License"). You may not use
|
jpayne@69
|
5 * this file except in compliance with the License. You can obtain a copy
|
jpayne@69
|
6 * in the file LICENSE in the source distribution or at
|
jpayne@69
|
7 * https://www.openssl.org/source/license.html
|
jpayne@69
|
8 */
|
jpayne@69
|
9
|
jpayne@69
|
10 #ifndef HEADER_OSSL_STORE_H
|
jpayne@69
|
11 # define HEADER_OSSL_STORE_H
|
jpayne@69
|
12
|
jpayne@69
|
13 # include <stdarg.h>
|
jpayne@69
|
14 # include <openssl/ossl_typ.h>
|
jpayne@69
|
15 # include <openssl/pem.h>
|
jpayne@69
|
16 # include <openssl/storeerr.h>
|
jpayne@69
|
17
|
jpayne@69
|
18 # ifdef __cplusplus
|
jpayne@69
|
19 extern "C" {
|
jpayne@69
|
20 # endif
|
jpayne@69
|
21
|
jpayne@69
|
22 /*-
|
jpayne@69
|
23 * The main OSSL_STORE functions.
|
jpayne@69
|
24 * ------------------------------
|
jpayne@69
|
25 *
|
jpayne@69
|
26 * These allow applications to open a channel to a resource with supported
|
jpayne@69
|
27 * data (keys, certs, crls, ...), read the data a piece at a time and decide
|
jpayne@69
|
28 * what to do with it, and finally close.
|
jpayne@69
|
29 */
|
jpayne@69
|
30
|
jpayne@69
|
31 typedef struct ossl_store_ctx_st OSSL_STORE_CTX;
|
jpayne@69
|
32
|
jpayne@69
|
33 /*
|
jpayne@69
|
34 * Typedef for the OSSL_STORE_INFO post processing callback. This can be used
|
jpayne@69
|
35 * to massage the given OSSL_STORE_INFO, or to drop it entirely (by returning
|
jpayne@69
|
36 * NULL).
|
jpayne@69
|
37 */
|
jpayne@69
|
38 typedef OSSL_STORE_INFO *(*OSSL_STORE_post_process_info_fn)(OSSL_STORE_INFO *,
|
jpayne@69
|
39 void *);
|
jpayne@69
|
40
|
jpayne@69
|
41 /*
|
jpayne@69
|
42 * Open a channel given a URI. The given UI method will be used any time the
|
jpayne@69
|
43 * loader needs extra input, for example when a password or pin is needed, and
|
jpayne@69
|
44 * will be passed the same user data every time it's needed in this context.
|
jpayne@69
|
45 *
|
jpayne@69
|
46 * Returns a context reference which represents the channel to communicate
|
jpayne@69
|
47 * through.
|
jpayne@69
|
48 */
|
jpayne@69
|
49 OSSL_STORE_CTX *OSSL_STORE_open(const char *uri, const UI_METHOD *ui_method,
|
jpayne@69
|
50 void *ui_data,
|
jpayne@69
|
51 OSSL_STORE_post_process_info_fn post_process,
|
jpayne@69
|
52 void *post_process_data);
|
jpayne@69
|
53
|
jpayne@69
|
54 /*
|
jpayne@69
|
55 * Control / fine tune the OSSL_STORE channel. |cmd| determines what is to be
|
jpayne@69
|
56 * done, and depends on the underlying loader (use OSSL_STORE_get0_scheme to
|
jpayne@69
|
57 * determine which loader is used), except for common commands (see below).
|
jpayne@69
|
58 * Each command takes different arguments.
|
jpayne@69
|
59 */
|
jpayne@69
|
60 int OSSL_STORE_ctrl(OSSL_STORE_CTX *ctx, int cmd, ... /* args */);
|
jpayne@69
|
61 int OSSL_STORE_vctrl(OSSL_STORE_CTX *ctx, int cmd, va_list args);
|
jpayne@69
|
62
|
jpayne@69
|
63 /*
|
jpayne@69
|
64 * Common ctrl commands that different loaders may choose to support.
|
jpayne@69
|
65 */
|
jpayne@69
|
66 /* int on = 0 or 1; STORE_ctrl(ctx, STORE_C_USE_SECMEM, &on); */
|
jpayne@69
|
67 # define OSSL_STORE_C_USE_SECMEM 1
|
jpayne@69
|
68 /* Where custom commands start */
|
jpayne@69
|
69 # define OSSL_STORE_C_CUSTOM_START 100
|
jpayne@69
|
70
|
jpayne@69
|
71 /*
|
jpayne@69
|
72 * Read one data item (a key, a cert, a CRL) that is supported by the OSSL_STORE
|
jpayne@69
|
73 * functionality, given a context.
|
jpayne@69
|
74 * Returns a OSSL_STORE_INFO pointer, from which OpenSSL typed data can be
|
jpayne@69
|
75 * extracted with OSSL_STORE_INFO_get0_PKEY(), OSSL_STORE_INFO_get0_CERT(), ...
|
jpayne@69
|
76 * NULL is returned on error, which may include that the data found at the URI
|
jpayne@69
|
77 * can't be figured out for certain or is ambiguous.
|
jpayne@69
|
78 */
|
jpayne@69
|
79 OSSL_STORE_INFO *OSSL_STORE_load(OSSL_STORE_CTX *ctx);
|
jpayne@69
|
80
|
jpayne@69
|
81 /*
|
jpayne@69
|
82 * Check if end of data (end of file) is reached
|
jpayne@69
|
83 * Returns 1 on end, 0 otherwise.
|
jpayne@69
|
84 */
|
jpayne@69
|
85 int OSSL_STORE_eof(OSSL_STORE_CTX *ctx);
|
jpayne@69
|
86
|
jpayne@69
|
87 /*
|
jpayne@69
|
88 * Check if an error occurred
|
jpayne@69
|
89 * Returns 1 if it did, 0 otherwise.
|
jpayne@69
|
90 */
|
jpayne@69
|
91 int OSSL_STORE_error(OSSL_STORE_CTX *ctx);
|
jpayne@69
|
92
|
jpayne@69
|
93 /*
|
jpayne@69
|
94 * Close the channel
|
jpayne@69
|
95 * Returns 1 on success, 0 on error.
|
jpayne@69
|
96 */
|
jpayne@69
|
97 int OSSL_STORE_close(OSSL_STORE_CTX *ctx);
|
jpayne@69
|
98
|
jpayne@69
|
99
|
jpayne@69
|
100 /*-
|
jpayne@69
|
101 * Extracting OpenSSL types from and creating new OSSL_STORE_INFOs
|
jpayne@69
|
102 * ---------------------------------------------------------------
|
jpayne@69
|
103 */
|
jpayne@69
|
104
|
jpayne@69
|
105 /*
|
jpayne@69
|
106 * Types of data that can be ossl_stored in a OSSL_STORE_INFO.
|
jpayne@69
|
107 * OSSL_STORE_INFO_NAME is typically found when getting a listing of
|
jpayne@69
|
108 * available "files" / "tokens" / what have you.
|
jpayne@69
|
109 */
|
jpayne@69
|
110 # define OSSL_STORE_INFO_NAME 1 /* char * */
|
jpayne@69
|
111 # define OSSL_STORE_INFO_PARAMS 2 /* EVP_PKEY * */
|
jpayne@69
|
112 # define OSSL_STORE_INFO_PKEY 3 /* EVP_PKEY * */
|
jpayne@69
|
113 # define OSSL_STORE_INFO_CERT 4 /* X509 * */
|
jpayne@69
|
114 # define OSSL_STORE_INFO_CRL 5 /* X509_CRL * */
|
jpayne@69
|
115
|
jpayne@69
|
116 /*
|
jpayne@69
|
117 * Functions to generate OSSL_STORE_INFOs, one function for each type we
|
jpayne@69
|
118 * support having in them, as well as a generic constructor.
|
jpayne@69
|
119 *
|
jpayne@69
|
120 * In all cases, ownership of the object is transferred to the OSSL_STORE_INFO
|
jpayne@69
|
121 * and will therefore be freed when the OSSL_STORE_INFO is freed.
|
jpayne@69
|
122 */
|
jpayne@69
|
123 OSSL_STORE_INFO *OSSL_STORE_INFO_new_NAME(char *name);
|
jpayne@69
|
124 int OSSL_STORE_INFO_set0_NAME_description(OSSL_STORE_INFO *info, char *desc);
|
jpayne@69
|
125 OSSL_STORE_INFO *OSSL_STORE_INFO_new_PARAMS(EVP_PKEY *params);
|
jpayne@69
|
126 OSSL_STORE_INFO *OSSL_STORE_INFO_new_PKEY(EVP_PKEY *pkey);
|
jpayne@69
|
127 OSSL_STORE_INFO *OSSL_STORE_INFO_new_CERT(X509 *x509);
|
jpayne@69
|
128 OSSL_STORE_INFO *OSSL_STORE_INFO_new_CRL(X509_CRL *crl);
|
jpayne@69
|
129
|
jpayne@69
|
130 /*
|
jpayne@69
|
131 * Functions to try to extract data from a OSSL_STORE_INFO.
|
jpayne@69
|
132 */
|
jpayne@69
|
133 int OSSL_STORE_INFO_get_type(const OSSL_STORE_INFO *info);
|
jpayne@69
|
134 const char *OSSL_STORE_INFO_get0_NAME(const OSSL_STORE_INFO *info);
|
jpayne@69
|
135 char *OSSL_STORE_INFO_get1_NAME(const OSSL_STORE_INFO *info);
|
jpayne@69
|
136 const char *OSSL_STORE_INFO_get0_NAME_description(const OSSL_STORE_INFO *info);
|
jpayne@69
|
137 char *OSSL_STORE_INFO_get1_NAME_description(const OSSL_STORE_INFO *info);
|
jpayne@69
|
138 EVP_PKEY *OSSL_STORE_INFO_get0_PARAMS(const OSSL_STORE_INFO *info);
|
jpayne@69
|
139 EVP_PKEY *OSSL_STORE_INFO_get1_PARAMS(const OSSL_STORE_INFO *info);
|
jpayne@69
|
140 EVP_PKEY *OSSL_STORE_INFO_get0_PKEY(const OSSL_STORE_INFO *info);
|
jpayne@69
|
141 EVP_PKEY *OSSL_STORE_INFO_get1_PKEY(const OSSL_STORE_INFO *info);
|
jpayne@69
|
142 X509 *OSSL_STORE_INFO_get0_CERT(const OSSL_STORE_INFO *info);
|
jpayne@69
|
143 X509 *OSSL_STORE_INFO_get1_CERT(const OSSL_STORE_INFO *info);
|
jpayne@69
|
144 X509_CRL *OSSL_STORE_INFO_get0_CRL(const OSSL_STORE_INFO *info);
|
jpayne@69
|
145 X509_CRL *OSSL_STORE_INFO_get1_CRL(const OSSL_STORE_INFO *info);
|
jpayne@69
|
146
|
jpayne@69
|
147 const char *OSSL_STORE_INFO_type_string(int type);
|
jpayne@69
|
148
|
jpayne@69
|
149 /*
|
jpayne@69
|
150 * Free the OSSL_STORE_INFO
|
jpayne@69
|
151 */
|
jpayne@69
|
152 void OSSL_STORE_INFO_free(OSSL_STORE_INFO *info);
|
jpayne@69
|
153
|
jpayne@69
|
154
|
jpayne@69
|
155 /*-
|
jpayne@69
|
156 * Functions to construct a search URI from a base URI and search criteria
|
jpayne@69
|
157 * -----------------------------------------------------------------------
|
jpayne@69
|
158 */
|
jpayne@69
|
159
|
jpayne@69
|
160 /* OSSL_STORE search types */
|
jpayne@69
|
161 # define OSSL_STORE_SEARCH_BY_NAME 1 /* subject in certs, issuer in CRLs */
|
jpayne@69
|
162 # define OSSL_STORE_SEARCH_BY_ISSUER_SERIAL 2
|
jpayne@69
|
163 # define OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT 3
|
jpayne@69
|
164 # define OSSL_STORE_SEARCH_BY_ALIAS 4
|
jpayne@69
|
165
|
jpayne@69
|
166 /* To check what search types the scheme handler supports */
|
jpayne@69
|
167 int OSSL_STORE_supports_search(OSSL_STORE_CTX *ctx, int search_type);
|
jpayne@69
|
168
|
jpayne@69
|
169 /* Search term constructors */
|
jpayne@69
|
170 /*
|
jpayne@69
|
171 * The input is considered to be owned by the caller, and must therefore
|
jpayne@69
|
172 * remain present throughout the lifetime of the returned OSSL_STORE_SEARCH
|
jpayne@69
|
173 */
|
jpayne@69
|
174 OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_name(X509_NAME *name);
|
jpayne@69
|
175 OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_issuer_serial(X509_NAME *name,
|
jpayne@69
|
176 const ASN1_INTEGER
|
jpayne@69
|
177 *serial);
|
jpayne@69
|
178 OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_key_fingerprint(const EVP_MD *digest,
|
jpayne@69
|
179 const unsigned char
|
jpayne@69
|
180 *bytes, size_t len);
|
jpayne@69
|
181 OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_alias(const char *alias);
|
jpayne@69
|
182
|
jpayne@69
|
183 /* Search term destructor */
|
jpayne@69
|
184 void OSSL_STORE_SEARCH_free(OSSL_STORE_SEARCH *search);
|
jpayne@69
|
185
|
jpayne@69
|
186 /* Search term accessors */
|
jpayne@69
|
187 int OSSL_STORE_SEARCH_get_type(const OSSL_STORE_SEARCH *criterion);
|
jpayne@69
|
188 X509_NAME *OSSL_STORE_SEARCH_get0_name(OSSL_STORE_SEARCH *criterion);
|
jpayne@69
|
189 const ASN1_INTEGER *OSSL_STORE_SEARCH_get0_serial(const OSSL_STORE_SEARCH
|
jpayne@69
|
190 *criterion);
|
jpayne@69
|
191 const unsigned char *OSSL_STORE_SEARCH_get0_bytes(const OSSL_STORE_SEARCH
|
jpayne@69
|
192 *criterion, size_t *length);
|
jpayne@69
|
193 const char *OSSL_STORE_SEARCH_get0_string(const OSSL_STORE_SEARCH *criterion);
|
jpayne@69
|
194 const EVP_MD *OSSL_STORE_SEARCH_get0_digest(const OSSL_STORE_SEARCH *criterion);
|
jpayne@69
|
195
|
jpayne@69
|
196 /*
|
jpayne@69
|
197 * Add search criterion and expected return type (which can be unspecified)
|
jpayne@69
|
198 * to the loading channel. This MUST happen before the first OSSL_STORE_load().
|
jpayne@69
|
199 */
|
jpayne@69
|
200 int OSSL_STORE_expect(OSSL_STORE_CTX *ctx, int expected_type);
|
jpayne@69
|
201 int OSSL_STORE_find(OSSL_STORE_CTX *ctx, OSSL_STORE_SEARCH *search);
|
jpayne@69
|
202
|
jpayne@69
|
203
|
jpayne@69
|
204 /*-
|
jpayne@69
|
205 * Function to register a loader for the given URI scheme.
|
jpayne@69
|
206 * -------------------------------------------------------
|
jpayne@69
|
207 *
|
jpayne@69
|
208 * The loader receives all the main components of an URI except for the
|
jpayne@69
|
209 * scheme.
|
jpayne@69
|
210 */
|
jpayne@69
|
211
|
jpayne@69
|
212 typedef struct ossl_store_loader_st OSSL_STORE_LOADER;
|
jpayne@69
|
213 OSSL_STORE_LOADER *OSSL_STORE_LOADER_new(ENGINE *e, const char *scheme);
|
jpayne@69
|
214 const ENGINE *OSSL_STORE_LOADER_get0_engine(const OSSL_STORE_LOADER *loader);
|
jpayne@69
|
215 const char *OSSL_STORE_LOADER_get0_scheme(const OSSL_STORE_LOADER *loader);
|
jpayne@69
|
216 /* struct ossl_store_loader_ctx_st is defined differently by each loader */
|
jpayne@69
|
217 typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX;
|
jpayne@69
|
218 typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_open_fn)(const OSSL_STORE_LOADER
|
jpayne@69
|
219 *loader,
|
jpayne@69
|
220 const char *uri,
|
jpayne@69
|
221 const UI_METHOD *ui_method,
|
jpayne@69
|
222 void *ui_data);
|
jpayne@69
|
223 int OSSL_STORE_LOADER_set_open(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
224 OSSL_STORE_open_fn open_function);
|
jpayne@69
|
225 typedef int (*OSSL_STORE_ctrl_fn)(OSSL_STORE_LOADER_CTX *ctx, int cmd,
|
jpayne@69
|
226 va_list args);
|
jpayne@69
|
227 int OSSL_STORE_LOADER_set_ctrl(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
228 OSSL_STORE_ctrl_fn ctrl_function);
|
jpayne@69
|
229 typedef int (*OSSL_STORE_expect_fn)(OSSL_STORE_LOADER_CTX *ctx, int expected);
|
jpayne@69
|
230 int OSSL_STORE_LOADER_set_expect(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
231 OSSL_STORE_expect_fn expect_function);
|
jpayne@69
|
232 typedef int (*OSSL_STORE_find_fn)(OSSL_STORE_LOADER_CTX *ctx,
|
jpayne@69
|
233 OSSL_STORE_SEARCH *criteria);
|
jpayne@69
|
234 int OSSL_STORE_LOADER_set_find(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
235 OSSL_STORE_find_fn find_function);
|
jpayne@69
|
236 typedef OSSL_STORE_INFO *(*OSSL_STORE_load_fn)(OSSL_STORE_LOADER_CTX *ctx,
|
jpayne@69
|
237 const UI_METHOD *ui_method,
|
jpayne@69
|
238 void *ui_data);
|
jpayne@69
|
239 int OSSL_STORE_LOADER_set_load(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
240 OSSL_STORE_load_fn load_function);
|
jpayne@69
|
241 typedef int (*OSSL_STORE_eof_fn)(OSSL_STORE_LOADER_CTX *ctx);
|
jpayne@69
|
242 int OSSL_STORE_LOADER_set_eof(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
243 OSSL_STORE_eof_fn eof_function);
|
jpayne@69
|
244 typedef int (*OSSL_STORE_error_fn)(OSSL_STORE_LOADER_CTX *ctx);
|
jpayne@69
|
245 int OSSL_STORE_LOADER_set_error(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
246 OSSL_STORE_error_fn error_function);
|
jpayne@69
|
247 typedef int (*OSSL_STORE_close_fn)(OSSL_STORE_LOADER_CTX *ctx);
|
jpayne@69
|
248 int OSSL_STORE_LOADER_set_close(OSSL_STORE_LOADER *loader,
|
jpayne@69
|
249 OSSL_STORE_close_fn close_function);
|
jpayne@69
|
250 void OSSL_STORE_LOADER_free(OSSL_STORE_LOADER *loader);
|
jpayne@69
|
251
|
jpayne@69
|
252 int OSSL_STORE_register_loader(OSSL_STORE_LOADER *loader);
|
jpayne@69
|
253 OSSL_STORE_LOADER *OSSL_STORE_unregister_loader(const char *scheme);
|
jpayne@69
|
254
|
jpayne@69
|
255 /*-
|
jpayne@69
|
256 * Functions to list STORE loaders
|
jpayne@69
|
257 * -------------------------------
|
jpayne@69
|
258 */
|
jpayne@69
|
259 int OSSL_STORE_do_all_loaders(void (*do_function) (const OSSL_STORE_LOADER
|
jpayne@69
|
260 *loader, void *do_arg),
|
jpayne@69
|
261 void *do_arg);
|
jpayne@69
|
262
|
jpayne@69
|
263 # ifdef __cplusplus
|
jpayne@69
|
264 }
|
jpayne@69
|
265 # endif
|
jpayne@69
|
266 #endif
|