]>
Commit | Line | Data |
---|---|---|
71a5516d | 1 | /* |
33388b44 | 2 | * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. |
71a5516d | 3 | * |
5c0d0c86 | 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 | ||
c4fc564d | 10 | #include <openssl/core_dispatch.h> |
71a5516d | 11 | #include "internal/thread_once.h" |
c4fc564d | 12 | #include "internal/refcount.h" |
71a5516d RL |
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> | |
34b80d06 | 19 | #include "internal/passphrase.h" |
71a5516d RL |
20 | |
21 | /*- | |
22 | * OSSL_STORE_INFO stuff | |
23 | * --------------------- | |
24 | */ | |
25 | ||
26 | struct ossl_store_info_st { | |
27 | int type; | |
28 | union { | |
50ecedda RL |
29 | void *data; /* used internally as generic pointer */ |
30 | ||
71a5516d RL |
31 | struct { |
32 | char *name; | |
33 | char *desc; | |
34 | } name; /* when type == OSSL_STORE_INFO_NAME */ | |
35 | ||
36 | EVP_PKEY *params; /* when type == OSSL_STORE_INFO_PARAMS */ | |
2274d22d | 37 | EVP_PKEY *pubkey; /* when type == OSSL_STORE_INFO_PUBKEY */ |
71a5516d RL |
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 */ | |
71a5516d RL |
41 | } _; |
42 | }; | |
71a5516d RL |
43 | DEFINE_STACK_OF(OSSL_STORE_INFO) |
44 | ||
fac8673b RL |
45 | /*- |
46 | * OSSL_STORE_SEARCH stuff | |
47 | * ----------------------- | |
48 | */ | |
49 | ||
50 | struct ossl_store_search_st { | |
51 | int search_type; | |
52 | ||
53 | /* | |
54 | * Used by OSSL_STORE_SEARCH_BY_NAME and | |
55 | * OSSL_STORE_SEARCH_BY_ISSUER_SERIAL | |
56 | */ | |
8cc86b81 | 57 | X509_NAME *name; /* TODO constify this; leads to API incompatibility */ |
fac8673b RL |
58 | |
59 | /* Used by OSSL_STORE_SEARCH_BY_ISSUER_SERIAL */ | |
60 | const ASN1_INTEGER *serial; | |
61 | ||
62 | /* Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT */ | |
63 | const EVP_MD *digest; | |
64 | ||
65 | /* | |
66 | * Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT and | |
67 | * OSSL_STORE_SEARCH_BY_ALIAS | |
68 | */ | |
69 | const unsigned char *string; | |
70 | size_t stringlength; | |
71 | }; | |
72 | ||
71a5516d RL |
73 | /*- |
74 | * OSSL_STORE_LOADER stuff | |
75 | * ----------------------- | |
76 | */ | |
77 | ||
78 | int ossl_store_register_loader_int(OSSL_STORE_LOADER *loader); | |
79 | OSSL_STORE_LOADER *ossl_store_unregister_loader_int(const char *scheme); | |
80 | ||
81 | /* loader stuff */ | |
82 | struct ossl_store_loader_st { | |
a1447076 | 83 | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
c4fc564d | 84 | /* Legacy stuff */ |
71a5516d | 85 | const char *scheme; |
f91ded1f | 86 | ENGINE *engine; |
71a5516d | 87 | OSSL_STORE_open_fn open; |
6ab6ecfd | 88 | OSSL_STORE_attach_fn attach; |
71a5516d | 89 | OSSL_STORE_ctrl_fn ctrl; |
072bfcc9 | 90 | OSSL_STORE_expect_fn expect; |
fac8673b | 91 | OSSL_STORE_find_fn find; |
71a5516d RL |
92 | OSSL_STORE_load_fn load; |
93 | OSSL_STORE_eof_fn eof; | |
94 | OSSL_STORE_error_fn error; | |
95 | OSSL_STORE_close_fn close; | |
d8652be0 | 96 | OSSL_STORE_open_ex_fn open_ex; |
a1447076 | 97 | #endif |
c4fc564d RL |
98 | |
99 | /* Provider stuff */ | |
100 | OSSL_PROVIDER *prov; | |
101 | int scheme_id; | |
102 | const char *propdef; | |
103 | ||
104 | CRYPTO_REF_COUNT refcnt; | |
105 | CRYPTO_RWLOCK *lock; | |
106 | ||
107 | OSSL_FUNC_store_open_fn *p_open; | |
108 | OSSL_FUNC_store_attach_fn *p_attach; | |
109 | OSSL_FUNC_store_settable_ctx_params_fn *p_settable_ctx_params; | |
110 | OSSL_FUNC_store_set_ctx_params_fn *p_set_ctx_params; | |
111 | OSSL_FUNC_store_load_fn *p_load; | |
112 | OSSL_FUNC_store_eof_fn *p_eof; | |
113 | OSSL_FUNC_store_close_fn *p_close; | |
114 | OSSL_FUNC_store_export_object_fn *p_export_object; | |
71a5516d RL |
115 | }; |
116 | DEFINE_LHASH_OF(OSSL_STORE_LOADER); | |
117 | ||
118 | const OSSL_STORE_LOADER *ossl_store_get0_loader_int(const char *scheme); | |
119 | void ossl_store_destroy_loaders_int(void); | |
120 | ||
a1447076 RL |
121 | #ifdef OPENSSL_NO_DEPRECATED_3_0 |
122 | /* struct ossl_store_loader_ctx_st is defined differently by each loader */ | |
123 | typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX; | |
124 | #endif | |
125 | ||
34b80d06 RL |
126 | /*- |
127 | * OSSL_STORE_CTX stuff | |
128 | * --------------------- | |
129 | */ | |
130 | ||
131 | struct ossl_store_ctx_st { | |
132 | const OSSL_STORE_LOADER *loader; /* legacy */ | |
133 | OSSL_STORE_LOADER *fetched_loader; | |
134 | OSSL_STORE_LOADER_CTX *loader_ctx; | |
135 | OSSL_STORE_post_process_info_fn post_process; | |
136 | void *post_process_data; | |
137 | int expected_type; | |
138 | ||
139 | char *properties; | |
140 | ||
141 | /* 0 before the first STORE_load(), 1 otherwise */ | |
142 | int loading; | |
143 | /* 1 on load error, only valid for fetched loaders */ | |
144 | int error_flag; | |
145 | ||
146 | /* | |
147 | * Cache of stuff, to be able to return the contents of a PKCS#12 | |
148 | * blob, one object at a time. | |
149 | */ | |
150 | STACK_OF(OSSL_STORE_INFO) *cached_info; | |
151 | ||
152 | struct ossl_passphrase_data_st pwdata; | |
153 | }; | |
154 | ||
c4fc564d RL |
155 | /*- |
156 | * 'file' scheme stuff | |
157 | * ------------------- | |
158 | */ | |
159 | ||
160 | OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp); | |
161 | int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx); | |
162 | ||
163 | /*- | |
164 | * Provider stuff | |
165 | * ------------------- | |
166 | */ | |
b4250010 | 167 | OSSL_STORE_LOADER *ossl_store_loader_fetch(OSSL_LIB_CTX *libctx, |
c4fc564d RL |
168 | const char *scheme, |
169 | const char *properties); | |
b4250010 | 170 | OSSL_STORE_LOADER *ossl_store_loader_fetch_by_number(OSSL_LIB_CTX *libctx, |
c4fc564d RL |
171 | int scheme_id, |
172 | const char *properties); | |
34b80d06 RL |
173 | |
174 | /* Standard function to handle the result from OSSL_FUNC_store_load() */ | |
175 | struct ossl_load_result_data_st { | |
176 | OSSL_STORE_INFO *v; /* To be filled in */ | |
177 | OSSL_STORE_CTX *ctx; | |
178 | }; | |
179 | OSSL_CALLBACK ossl_store_handle_load_result; |