2 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
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
10 #include <openssl/core_dispatch.h>
11 #include "internal/thread_once.h"
12 #include "internal/refcount.h"
13 #include <openssl/dsa.h>
14 #include <openssl/engine.h>
15 #include <openssl/evp.h>
16 #include <openssl/lhash.h>
17 #include <openssl/x509.h>
18 #include <openssl/store.h>
19 #include "internal/passphrase.h"
22 * OSSL_STORE_INFO stuff
23 * ---------------------
26 struct ossl_store_info_st {
29 void *data; /* used internally as generic pointer */
34 } name; /* when type == OSSL_STORE_INFO_NAME */
36 EVP_PKEY *params; /* when type == OSSL_STORE_INFO_PARAMS */
37 EVP_PKEY *pubkey; /* when type == OSSL_STORE_INFO_PUBKEY */
38 EVP_PKEY *pkey; /* when type == OSSL_STORE_INFO_PKEY */
39 X509 *x509; /* when type == OSSL_STORE_INFO_CERT */
40 X509_CRL *crl; /* when type == OSSL_STORE_INFO_CRL */
43 DEFINE_STACK_OF(OSSL_STORE_INFO)
46 * OSSL_STORE_SEARCH stuff
47 * -----------------------
50 struct ossl_store_search_st {
54 * Used by OSSL_STORE_SEARCH_BY_NAME and
55 * OSSL_STORE_SEARCH_BY_ISSUER_SERIAL
59 /* Used by OSSL_STORE_SEARCH_BY_ISSUER_SERIAL */
60 const ASN1_INTEGER *serial;
62 /* Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT */
66 * Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT and
67 * OSSL_STORE_SEARCH_BY_ALIAS
69 const unsigned char *string;
74 * OSSL_STORE_LOADER stuff
75 * -----------------------
78 int ossl_store_register_loader_int(OSSL_STORE_LOADER *loader);
79 OSSL_STORE_LOADER *ossl_store_unregister_loader_int(const char *scheme);
82 struct ossl_store_loader_st {
83 #ifndef OPENSSL_NO_DEPRECATED_3_0
87 OSSL_STORE_open_fn open;
88 OSSL_STORE_attach_fn attach;
89 OSSL_STORE_ctrl_fn ctrl;
90 OSSL_STORE_expect_fn expect;
91 OSSL_STORE_find_fn find;
92 OSSL_STORE_load_fn load;
93 OSSL_STORE_eof_fn eof;
94 OSSL_STORE_error_fn error;
95 OSSL_STORE_close_fn closefn;
96 OSSL_STORE_open_ex_fn open_ex;
103 const char *description;
105 CRYPTO_REF_COUNT refcnt;
108 OSSL_FUNC_store_open_fn *p_open;
109 OSSL_FUNC_store_attach_fn *p_attach;
110 OSSL_FUNC_store_settable_ctx_params_fn *p_settable_ctx_params;
111 OSSL_FUNC_store_set_ctx_params_fn *p_set_ctx_params;
112 OSSL_FUNC_store_load_fn *p_load;
113 OSSL_FUNC_store_eof_fn *p_eof;
114 OSSL_FUNC_store_close_fn *p_close;
115 OSSL_FUNC_store_export_object_fn *p_export_object;
117 DEFINE_LHASH_OF(OSSL_STORE_LOADER);
119 const OSSL_STORE_LOADER *ossl_store_get0_loader_int(const char *scheme);
120 void ossl_store_destroy_loaders_int(void);
122 #ifdef OPENSSL_NO_DEPRECATED_3_0
123 /* struct ossl_store_loader_ctx_st is defined differently by each loader */
124 typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX;
128 * OSSL_STORE_CTX stuff
129 * ---------------------
132 struct ossl_store_ctx_st {
133 const OSSL_STORE_LOADER *loader; /* legacy */
134 OSSL_STORE_LOADER *fetched_loader;
135 OSSL_STORE_LOADER_CTX *loader_ctx;
136 OSSL_STORE_post_process_info_fn post_process;
137 void *post_process_data;
142 /* 0 before the first STORE_load(), 1 otherwise */
144 /* 1 on load error, only valid for fetched loaders */
148 * Cache of stuff, to be able to return the contents of a PKCS#12
149 * blob, one object at a time.
151 STACK_OF(OSSL_STORE_INFO) *cached_info;
153 struct ossl_passphrase_data_st pwdata;
157 * 'file' scheme stuff
158 * -------------------
161 OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp);
162 int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx);
166 * -------------------
168 OSSL_STORE_LOADER *ossl_store_loader_fetch(OSSL_LIB_CTX *libctx,
170 const char *properties);
171 OSSL_STORE_LOADER *ossl_store_loader_fetch_by_number(OSSL_LIB_CTX *libctx,
173 const char *properties);
175 /* Standard function to handle the result from OSSL_FUNC_store_load() */
176 struct ossl_load_result_data_st {
177 OSSL_STORE_INFO *v; /* To be filled in */
180 OSSL_CALLBACK ossl_store_handle_load_result;