]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/store.h
Rename all getters to use get/get0 in name
[thirdparty/openssl.git] / include / openssl / store.h
CommitLineData
71a5516d 1/*
8020d79b 2 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
71a5516d 3 *
48f4ad77 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
71a5516d
RL
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
ae4186b0
DMSP
10#ifndef OPENSSL_STORE_H
11# define OPENSSL_STORE_H
d86167ec
DMSP
12# pragma once
13
14# include <openssl/macros.h>
936c2b9e 15# ifndef OPENSSL_NO_DEPRECATED_3_0
d86167ec
DMSP
16# define HEADER_OSSL_STORE_H
17# endif
71a5516d
RL
18
19# include <stdarg.h>
50cd4768 20# include <openssl/types.h>
71a5516d
RL
21# include <openssl/pem.h>
22# include <openssl/storeerr.h>
23
24# ifdef __cplusplus
25extern "C" {
26# endif
27
28/*-
29 * The main OSSL_STORE functions.
30 * ------------------------------
31 *
32 * These allow applications to open a channel to a resource with supported
33 * data (keys, certs, crls, ...), read the data a piece at a time and decide
34 * what to do with it, and finally close.
35 */
36
37typedef struct ossl_store_ctx_st OSSL_STORE_CTX;
38
39/*
40 * Typedef for the OSSL_STORE_INFO post processing callback. This can be used
41 * to massage the given OSSL_STORE_INFO, or to drop it entirely (by returning
42 * NULL).
43 */
44typedef OSSL_STORE_INFO *(*OSSL_STORE_post_process_info_fn)(OSSL_STORE_INFO *,
45 void *);
46
47/*
48 * Open a channel given a URI. The given UI method will be used any time the
49 * loader needs extra input, for example when a password or pin is needed, and
50 * will be passed the same user data every time it's needed in this context.
51 *
52 * Returns a context reference which represents the channel to communicate
53 * through.
54 */
34b80d06
RL
55OSSL_STORE_CTX *
56OSSL_STORE_open(const char *uri, const UI_METHOD *ui_method, void *ui_data,
57 OSSL_STORE_post_process_info_fn post_process,
58 void *post_process_data);
59OSSL_STORE_CTX *
b4250010 60OSSL_STORE_open_ex(const char *uri, OSSL_LIB_CTX *libctx, const char *propq,
d8652be0 61 const UI_METHOD *ui_method, void *ui_data,
d382e796 62 const OSSL_PARAM params[],
d8652be0
MC
63 OSSL_STORE_post_process_info_fn post_process,
64 void *post_process_data);
6725682d 65
71a5516d
RL
66/*
67 * Control / fine tune the OSSL_STORE channel. |cmd| determines what is to be
68 * done, and depends on the underlying loader (use OSSL_STORE_get0_scheme to
69 * determine which loader is used), except for common commands (see below).
70 * Each command takes different arguments.
71 */
f2e94543
RL
72# ifndef OPENSSL_NO_DEPRECATED_3_0
73OSSL_DEPRECATEDIN_3_0 int OSSL_STORE_ctrl(OSSL_STORE_CTX *ctx, int cmd,
74 ... /* args */);
75OSSL_DEPRECATEDIN_3_0 int OSSL_STORE_vctrl(OSSL_STORE_CTX *ctx, int cmd,
76 va_list args);
77# endif
a1447076
RL
78
79# ifndef OPENSSL_NO_DEPRECATED_3_0
71a5516d
RL
80
81/*
82 * Common ctrl commands that different loaders may choose to support.
83 */
7852f588
RL
84/* int on = 0 or 1; STORE_ctrl(ctx, STORE_C_USE_SECMEM, &on); */
85# define OSSL_STORE_C_USE_SECMEM 1
71a5516d
RL
86/* Where custom commands start */
87# define OSSL_STORE_C_CUSTOM_START 100
88
a1447076
RL
89# endif
90
71a5516d
RL
91/*
92 * Read one data item (a key, a cert, a CRL) that is supported by the OSSL_STORE
93 * functionality, given a context.
94 * Returns a OSSL_STORE_INFO pointer, from which OpenSSL typed data can be
95 * extracted with OSSL_STORE_INFO_get0_PKEY(), OSSL_STORE_INFO_get0_CERT(), ...
96 * NULL is returned on error, which may include that the data found at the URI
97 * can't be figured out for certain or is ambiguous.
98 */
99OSSL_STORE_INFO *OSSL_STORE_load(OSSL_STORE_CTX *ctx);
100
101/*
102 * Check if end of data (end of file) is reached
103 * Returns 1 on end, 0 otherwise.
104 */
105int OSSL_STORE_eof(OSSL_STORE_CTX *ctx);
106
107/*
68756b12 108 * Check if an error occurred
71a5516d
RL
109 * Returns 1 if it did, 0 otherwise.
110 */
111int OSSL_STORE_error(OSSL_STORE_CTX *ctx);
112
113/*
114 * Close the channel
115 * Returns 1 on success, 0 on error.
116 */
117int OSSL_STORE_close(OSSL_STORE_CTX *ctx);
118
6ab6ecfd
RL
119/*
120 * Attach to a BIO. This works like OSSL_STORE_open() except it takes a
121 * BIO instead of a uri, along with a scheme to use when reading.
122 * The given UI method will be used any time the loader needs extra input,
123 * for example when a password or pin is needed, and will be passed the
124 * same user data every time it's needed in this context.
125 *
126 * Returns a context reference which represents the channel to communicate
127 * through.
128 *
129 * Note that this function is considered unsafe, all depending on what the
130 * BIO actually reads.
131 */
6725682d 132OSSL_STORE_CTX *OSSL_STORE_attach(BIO *bio, const char *scheme,
b4250010 133 OSSL_LIB_CTX *libctx, const char *propq,
6ab6ecfd 134 const UI_METHOD *ui_method, void *ui_data,
d382e796 135 const OSSL_PARAM params[],
6ab6ecfd
RL
136 OSSL_STORE_post_process_info_fn post_process,
137 void *post_process_data);
71a5516d
RL
138
139/*-
140 * Extracting OpenSSL types from and creating new OSSL_STORE_INFOs
141 * ---------------------------------------------------------------
142 */
143
144/*
145 * Types of data that can be ossl_stored in a OSSL_STORE_INFO.
146 * OSSL_STORE_INFO_NAME is typically found when getting a listing of
147 * available "files" / "tokens" / what have you.
148 */
149# define OSSL_STORE_INFO_NAME 1 /* char * */
150# define OSSL_STORE_INFO_PARAMS 2 /* EVP_PKEY * */
2274d22d
RL
151# define OSSL_STORE_INFO_PUBKEY 3 /* EVP_PKEY * */
152# define OSSL_STORE_INFO_PKEY 4 /* EVP_PKEY * */
153# define OSSL_STORE_INFO_CERT 5 /* X509 * */
154# define OSSL_STORE_INFO_CRL 6 /* X509_CRL * */
71a5516d
RL
155
156/*
157 * Functions to generate OSSL_STORE_INFOs, one function for each type we
1fb2993d 158 * support having in them, as well as a generic constructor.
71a5516d 159 *
68756b12 160 * In all cases, ownership of the object is transferred to the OSSL_STORE_INFO
71a5516d
RL
161 * and will therefore be freed when the OSSL_STORE_INFO is freed.
162 */
16feca71 163OSSL_STORE_INFO *OSSL_STORE_INFO_new(int type, void *data);
71a5516d
RL
164OSSL_STORE_INFO *OSSL_STORE_INFO_new_NAME(char *name);
165int OSSL_STORE_INFO_set0_NAME_description(OSSL_STORE_INFO *info, char *desc);
166OSSL_STORE_INFO *OSSL_STORE_INFO_new_PARAMS(EVP_PKEY *params);
2274d22d 167OSSL_STORE_INFO *OSSL_STORE_INFO_new_PUBKEY(EVP_PKEY *pubkey);
71a5516d
RL
168OSSL_STORE_INFO *OSSL_STORE_INFO_new_PKEY(EVP_PKEY *pkey);
169OSSL_STORE_INFO *OSSL_STORE_INFO_new_CERT(X509 *x509);
170OSSL_STORE_INFO *OSSL_STORE_INFO_new_CRL(X509_CRL *crl);
171
172/*
173 * Functions to try to extract data from a OSSL_STORE_INFO.
174 */
175int OSSL_STORE_INFO_get_type(const OSSL_STORE_INFO *info);
16feca71 176void *OSSL_STORE_INFO_get0_data(int type, const OSSL_STORE_INFO *info);
71a5516d
RL
177const char *OSSL_STORE_INFO_get0_NAME(const OSSL_STORE_INFO *info);
178char *OSSL_STORE_INFO_get1_NAME(const OSSL_STORE_INFO *info);
179const char *OSSL_STORE_INFO_get0_NAME_description(const OSSL_STORE_INFO *info);
180char *OSSL_STORE_INFO_get1_NAME_description(const OSSL_STORE_INFO *info);
181EVP_PKEY *OSSL_STORE_INFO_get0_PARAMS(const OSSL_STORE_INFO *info);
182EVP_PKEY *OSSL_STORE_INFO_get1_PARAMS(const OSSL_STORE_INFO *info);
2274d22d
RL
183EVP_PKEY *OSSL_STORE_INFO_get0_PUBKEY(const OSSL_STORE_INFO *info);
184EVP_PKEY *OSSL_STORE_INFO_get1_PUBKEY(const OSSL_STORE_INFO *info);
71a5516d
RL
185EVP_PKEY *OSSL_STORE_INFO_get0_PKEY(const OSSL_STORE_INFO *info);
186EVP_PKEY *OSSL_STORE_INFO_get1_PKEY(const OSSL_STORE_INFO *info);
187X509 *OSSL_STORE_INFO_get0_CERT(const OSSL_STORE_INFO *info);
188X509 *OSSL_STORE_INFO_get1_CERT(const OSSL_STORE_INFO *info);
189X509_CRL *OSSL_STORE_INFO_get0_CRL(const OSSL_STORE_INFO *info);
190X509_CRL *OSSL_STORE_INFO_get1_CRL(const OSSL_STORE_INFO *info);
191
192const char *OSSL_STORE_INFO_type_string(int type);
193
194/*
195 * Free the OSSL_STORE_INFO
196 */
197void OSSL_STORE_INFO_free(OSSL_STORE_INFO *info);
198
fac8673b
RL
199
200/*-
201 * Functions to construct a search URI from a base URI and search criteria
202 * -----------------------------------------------------------------------
203 */
204
205/* OSSL_STORE search types */
206# define OSSL_STORE_SEARCH_BY_NAME 1 /* subject in certs, issuer in CRLs */
207# define OSSL_STORE_SEARCH_BY_ISSUER_SERIAL 2
208# define OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT 3
209# define OSSL_STORE_SEARCH_BY_ALIAS 4
210
211/* To check what search types the scheme handler supports */
212int OSSL_STORE_supports_search(OSSL_STORE_CTX *ctx, int search_type);
213
214/* Search term constructors */
215/*
216 * The input is considered to be owned by the caller, and must therefore
217 * remain present throughout the lifetime of the returned OSSL_STORE_SEARCH
218 */
219OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_name(X509_NAME *name);
220OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_issuer_serial(X509_NAME *name,
221 const ASN1_INTEGER
222 *serial);
223OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_key_fingerprint(const EVP_MD *digest,
224 const unsigned char
225 *bytes, size_t len);
226OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_alias(const char *alias);
227
228/* Search term destructor */
229void OSSL_STORE_SEARCH_free(OSSL_STORE_SEARCH *search);
230
231/* Search term accessors */
232int OSSL_STORE_SEARCH_get_type(const OSSL_STORE_SEARCH *criterion);
e3c4ad28 233X509_NAME *OSSL_STORE_SEARCH_get0_name(const OSSL_STORE_SEARCH *criterion);
fac8673b
RL
234const ASN1_INTEGER *OSSL_STORE_SEARCH_get0_serial(const OSSL_STORE_SEARCH
235 *criterion);
236const unsigned char *OSSL_STORE_SEARCH_get0_bytes(const OSSL_STORE_SEARCH
237 *criterion, size_t *length);
238const char *OSSL_STORE_SEARCH_get0_string(const OSSL_STORE_SEARCH *criterion);
239const EVP_MD *OSSL_STORE_SEARCH_get0_digest(const OSSL_STORE_SEARCH *criterion);
240
072bfcc9 241/*
fac8673b
RL
242 * Add search criterion and expected return type (which can be unspecified)
243 * to the loading channel. This MUST happen before the first OSSL_STORE_load().
072bfcc9
RL
244 */
245int OSSL_STORE_expect(OSSL_STORE_CTX *ctx, int expected_type);
e3c4ad28 246int OSSL_STORE_find(OSSL_STORE_CTX *ctx, const OSSL_STORE_SEARCH *search);
072bfcc9 247
71a5516d 248
c4fc564d
RL
249/*-
250 * Function to fetch a loader and extract data from it
251 * ---------------------------------------------------
252 */
253
254typedef struct ossl_store_loader_st OSSL_STORE_LOADER;
255
256OSSL_STORE_LOADER *OSSL_STORE_LOADER_fetch(const char *scheme,
b4250010 257 OSSL_LIB_CTX *libctx,
c4fc564d
RL
258 const char *properties);
259int OSSL_STORE_LOADER_up_ref(OSSL_STORE_LOADER *loader);
260void OSSL_STORE_LOADER_free(OSSL_STORE_LOADER *loader);
ed576acd 261const OSSL_PROVIDER *OSSL_STORE_LOADER_get0_provider(const OSSL_STORE_LOADER *
c4fc564d 262 loader);
ed576acd
TM
263const char *OSSL_STORE_LOADER_get0_properties(const OSSL_STORE_LOADER *loader);
264int OSSL_STORE_LOADER_get_number(const OSSL_STORE_LOADER *loader);
265const char *OSSL_STORE_LOADER_get0_description(const OSSL_STORE_LOADER *loader);
c4fc564d
RL
266int OSSL_STORE_LOADER_is_a(const OSSL_STORE_LOADER *loader,
267 const char *scheme);
b4250010 268void OSSL_STORE_LOADER_do_all_provided(OSSL_LIB_CTX *libctx,
c4fc564d
RL
269 void (*fn)(OSSL_STORE_LOADER *loader,
270 void *arg),
271 void *arg);
d84f5515
MC
272int OSSL_STORE_LOADER_names_do_all(const OSSL_STORE_LOADER *loader,
273 void (*fn)(const char *name, void *data),
274 void *data);
c4fc564d 275
71a5516d
RL
276/*-
277 * Function to register a loader for the given URI scheme.
278 * -------------------------------------------------------
279 *
280 * The loader receives all the main components of an URI except for the
281 * scheme.
282 */
283
a1447076
RL
284# ifndef OPENSSL_NO_DEPRECATED_3_0
285
71a5516d
RL
286/* struct ossl_store_loader_ctx_st is defined differently by each loader */
287typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX;
6725682d
SL
288typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_open_fn)
289 (const OSSL_STORE_LOADER *loader, const char *uri,
290 const UI_METHOD *ui_method, void *ui_data);
d8652be0 291typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_open_ex_fn)
6725682d 292 (const OSSL_STORE_LOADER *loader,
b4250010 293 const char *uri, OSSL_LIB_CTX *libctx, const char *propq,
6725682d
SL
294 const UI_METHOD *ui_method, void *ui_data);
295
c4fc564d
RL
296typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_attach_fn)
297 (const OSSL_STORE_LOADER *loader, BIO *bio,
b4250010 298 OSSL_LIB_CTX *libctx, const char *propq,
c4fc564d
RL
299 const UI_METHOD *ui_method, void *ui_data);
300typedef int (*OSSL_STORE_ctrl_fn)
301 (OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args);
302typedef int (*OSSL_STORE_expect_fn)
303 (OSSL_STORE_LOADER_CTX *ctx, int expected);
304typedef int (*OSSL_STORE_find_fn)
305 (OSSL_STORE_LOADER_CTX *ctx, const OSSL_STORE_SEARCH *criteria);
306typedef OSSL_STORE_INFO *(*OSSL_STORE_load_fn)
307 (OSSL_STORE_LOADER_CTX *ctx, const UI_METHOD *ui_method, void *ui_data);
308typedef int (*OSSL_STORE_eof_fn)(OSSL_STORE_LOADER_CTX *ctx);
309typedef int (*OSSL_STORE_error_fn)(OSSL_STORE_LOADER_CTX *ctx);
310typedef int (*OSSL_STORE_close_fn)(OSSL_STORE_LOADER_CTX *ctx);
311
a1447076 312# endif
f2e94543
RL
313# ifndef OPENSSL_NO_DEPRECATED_3_0
314OSSL_DEPRECATEDIN_3_0
315OSSL_STORE_LOADER *OSSL_STORE_LOADER_new(ENGINE *e, const char *scheme);
316OSSL_DEPRECATEDIN_3_0
317int OSSL_STORE_LOADER_set_open(OSSL_STORE_LOADER *loader,
318 OSSL_STORE_open_fn open_function);
319OSSL_DEPRECATEDIN_3_0
320int OSSL_STORE_LOADER_set_open_ex(OSSL_STORE_LOADER *loader,
321 OSSL_STORE_open_ex_fn open_ex_function);
322OSSL_DEPRECATEDIN_3_0
323int OSSL_STORE_LOADER_set_attach(OSSL_STORE_LOADER *loader,
324 OSSL_STORE_attach_fn attach_function);
325OSSL_DEPRECATEDIN_3_0
326int OSSL_STORE_LOADER_set_ctrl(OSSL_STORE_LOADER *loader,
327 OSSL_STORE_ctrl_fn ctrl_function);
328OSSL_DEPRECATEDIN_3_0
329int OSSL_STORE_LOADER_set_expect(OSSL_STORE_LOADER *loader,
330 OSSL_STORE_expect_fn expect_function);
331OSSL_DEPRECATEDIN_3_0
332int OSSL_STORE_LOADER_set_find(OSSL_STORE_LOADER *loader,
333 OSSL_STORE_find_fn find_function);
334OSSL_DEPRECATEDIN_3_0
335int OSSL_STORE_LOADER_set_load(OSSL_STORE_LOADER *loader,
336 OSSL_STORE_load_fn load_function);
337OSSL_DEPRECATEDIN_3_0
338int OSSL_STORE_LOADER_set_eof(OSSL_STORE_LOADER *loader,
339 OSSL_STORE_eof_fn eof_function);
340OSSL_DEPRECATEDIN_3_0
341int OSSL_STORE_LOADER_set_error(OSSL_STORE_LOADER *loader,
342 OSSL_STORE_error_fn error_function);
343OSSL_DEPRECATEDIN_3_0
344int OSSL_STORE_LOADER_set_close(OSSL_STORE_LOADER *loader,
345 OSSL_STORE_close_fn close_function);
346OSSL_DEPRECATEDIN_3_0
347const ENGINE *OSSL_STORE_LOADER_get0_engine(const OSSL_STORE_LOADER *loader);
348OSSL_DEPRECATEDIN_3_0
349const char * OSSL_STORE_LOADER_get0_scheme(const OSSL_STORE_LOADER *loader);
350OSSL_DEPRECATEDIN_3_0
351int OSSL_STORE_register_loader(OSSL_STORE_LOADER *loader);
352OSSL_DEPRECATEDIN_3_0
353OSSL_STORE_LOADER *OSSL_STORE_unregister_loader(const char *scheme);
354# endif
71a5516d 355
f91ded1f
RL
356/*-
357 * Functions to list STORE loaders
358 * -------------------------------
359 */
f2e94543
RL
360# ifndef OPENSSL_NO_DEPRECATED_3_0
361OSSL_DEPRECATEDIN_3_0
362int OSSL_STORE_do_all_loaders(void (*do_function)(const OSSL_STORE_LOADER *loader,
363 void *do_arg),
364 void *do_arg);
365# endif
f91ded1f 366
71a5516d
RL
367# ifdef __cplusplus
368}
369# endif
370#endif