1X509_STORE_CTX_NEW(3ossl) OpenSSL X509_STORE_CTX_NEW(3ossl)
2
3
4
6 X509_STORE_CTX_new_ex, X509_STORE_CTX_new, X509_STORE_CTX_cleanup,
7 X509_STORE_CTX_free, X509_STORE_CTX_init,
8 X509_STORE_CTX_set0_trusted_stack, X509_STORE_CTX_set_cert,
9 X509_STORE_CTX_set0_crls, X509_STORE_CTX_get0_param,
10 X509_STORE_CTX_set0_param, X509_STORE_CTX_get0_untrusted,
11 X509_STORE_CTX_set0_untrusted, X509_STORE_CTX_get_num_untrusted,
12 X509_STORE_CTX_get0_chain, X509_STORE_CTX_set0_verified_chain,
13 X509_STORE_CTX_set_default, X509_STORE_CTX_set_verify,
14 X509_STORE_CTX_verify_fn, X509_STORE_CTX_set_purpose,
15 X509_STORE_CTX_set_trust, X509_STORE_CTX_purpose_inherit -
16 X509_STORE_CTX initialisation
17
19 #include <openssl/x509_vfy.h>
20
21 X509_STORE_CTX *X509_STORE_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq);
22 X509_STORE_CTX *X509_STORE_CTX_new(void);
23 void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
24 void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
25
26 int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *trust_store,
27 X509 *target, STACK_OF(X509) *untrusted);
28
29 void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
30
31 void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *target);
32 void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk);
33
34 X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(const X509_STORE_CTX *ctx);
35 void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
36
37 STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx);
38 void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
39
40 int X509_STORE_CTX_get_num_untrusted(const X509_STORE_CTX *ctx);
41 STACK_OF(X509) *X509_STORE_CTX_get0_chain(const X509_STORE_CTX *ctx);
42 void X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *chain);
43
44 int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
45 typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *);
46 void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, X509_STORE_CTX_verify_fn verify);
47
48 int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
49 int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
50 int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
51 int purpose, int trust);
52
54 These functions initialise an X509_STORE_CTX structure for subsequent
55 use by X509_verify_cert(3) or X509_STORE_CTX_verify(3).
56
57 X509_STORE_CTX_new_ex() returns a newly initialised X509_STORE_CTX
58 structure associated with the specified library context libctx and
59 property query string propq. Any cryptographic algorithms fetched while
60 performing processing with the X509_STORE_CTX will use that library
61 context and property query string.
62
63 X509_STORE_CTX_new() is the same as X509_STORE_CTX_new_ex() except that
64 the default library context and a NULL property query string are used.
65
66 X509_STORE_CTX_cleanup() internally cleans up an X509_STORE_CTX
67 structure. It is used by X509_STORE_CTX_init() and
68 X509_STORE_CTX_free().
69
70 X509_STORE_CTX_free() completely frees up ctx. After this call ctx is
71 no longer valid. If ctx is NULL nothing is done.
72
73 It must be called before each call to X509_verify_cert(3) or
74 X509_STORE_CTX_verify(3), i.e., a context is only good for one
75 verification. If you want to verify a further certificate or chain
76 with the same ctx then you must call X509_STORE_CTX_init() again. The
77 trusted certificate store is set to trust_store of type X509_STORE.
78 This may be NULL because there are no trusted certificates or because
79 they are provided simply as a list using
80 X509_STORE_CTX_set0_trusted_stack(). The certificate to be verified is
81 set to target, and a list of additional certificates may be provided in
82 untrusted, which will be untrusted but may be used to build the chain.
83 Each of the trust_store, target and untrusted parameters can be NULL.
84 Yet note that X509_verify_cert(3) and X509_STORE_CTX_verify(3) will
85 need a verification target. This can also be set using
86 X509_STORE_CTX_set_cert(). For X509_STORE_CTX_verify(3), which takes
87 by default the first element of the list of untrusted certificates as
88 its verification target, this can be also set indirectly using
89 X509_STORE_CTX_set0_untrusted().
90
91 X509_STORE_CTX_set0_trusted_stack() sets the set of trusted
92 certificates of ctx to sk. This is an alternative way of specifying
93 trusted certificates instead of using an X509_STORE where its
94 complexity is not needed or to make sure that only the given set sk of
95 certificates are trusted.
96
97 X509_STORE_CTX_set_cert() sets the target certificate to be verified in
98 ctx to target.
99
100 X509_STORE_CTX_set0_verified_chain() sets the validated chain to chain.
101 Ownership of the chain is transferred to ctx, and so it should not be
102 free'd by the caller.
103
104 X509_STORE_CTX_get0_chain() returns the internal pointer used by the
105 ctx that contains the constructed (output) chain.
106
107 X509_STORE_CTX_set0_crls() sets a set of CRLs to use to aid certificate
108 verification to sk. These CRLs will only be used if CRL verification is
109 enabled in the associated X509_VERIFY_PARAM structure. This might be
110 used where additional "useful" CRLs are supplied as part of a protocol,
111 for example in a PKCS#7 structure.
112
113 X509_STORE_CTX_get0_param() retrieves an internal pointer to the
114 verification parameters associated with ctx.
115
116 X509_STORE_CTX_set0_param() sets the internal verification parameter
117 pointer to param. After this call param should not be used.
118
119 X509_STORE_CTX_get0_untrusted() retrieves an internal pointer to the
120 stack of untrusted certificates associated with ctx.
121
122 X509_STORE_CTX_set0_untrusted() sets the internal pointer to the stack
123 of untrusted certificates associated with ctx to sk.
124 X509_STORE_CTX_verify() will take the first element, if any, as its
125 default target if the target certificate is not set explicitly.
126
127 X509_STORE_CTX_get_num_untrusted() returns the number of untrusted
128 certificates that were used in building the chain. This is can be used
129 after calling X509_verify_cert(3) and similar functions. With
130 X509_STORE_CTX_verify(3), this does not count the first chain element.
131
132 X509_STORE_CTX_get0_chain() returns the internal pointer used by the
133 ctx that contains the validated chain.
134
135 Details of the chain building and checking process are described in
136 "Certification Path Building" in openssl-verification-options(1) and
137 "Certification Path Validation" in openssl-verification-options(1).
138
139 X509_STORE_CTX_set0_verified_chain() sets the validated chain used by
140 ctx to be chain. Ownership of the chain is transferred to ctx, and so
141 it should not be free'd by the caller.
142
143 X509_STORE_CTX_set_default() looks up and sets the default verification
144 method to name. This uses the function X509_VERIFY_PARAM_lookup() to
145 find an appropriate set of parameters from the purpose identifier name.
146 Currently defined purposes are "sslclient", "sslserver", "nssslserver",
147 "smimesign", "smimeencrypt", "crlsign", "ocsphelper", "timestampsign",
148 and "any".
149
150 X509_STORE_CTX_set_verify() provides the capability for overriding the
151 default verify function. This function is responsible for verifying
152 chain signatures and expiration times.
153
154 A verify function is defined as an X509_STORE_CTX_verify type which has
155 the following signature:
156
157 int (*verify)(X509_STORE_CTX *);
158
159 This function should receive the current X509_STORE_CTX as a parameter
160 and return 1 on success or 0 on failure.
161
162 X509 certificates may contain information about what purposes keys
163 contained within them can be used for. For example "TLS WWW Server
164 Authentication" or "Email Protection". This "key usage" information is
165 held internally to the certificate itself. In addition the trust store
166 containing trusted certificates can declare what purposes we trust
167 different certificates for. This "trust" information is not held within
168 the certificate itself but is "meta" information held alongside it.
169 This "meta" information is associated with the certificate after it is
170 issued and could be determined by a system administrator. For example a
171 certificate might declare that it is suitable for use for both "TLS WWW
172 Server Authentication" and "TLS Client Authentication", but a system
173 administrator might only trust it for the former. An X.509 certificate
174 extension exists that can record extended key usage information to
175 supplement the purpose information described above. This extended
176 mechanism is arbitrarily extensible and not well suited for a generic
177 library API; applications that need to validate extended key usage
178 information in certificates will need to define a custom "purpose" (see
179 below) or supply a nondefault verification callback
180 (X509_STORE_set_verify_cb_func(3)).
181
182 X509_STORE_CTX_set_purpose() sets the purpose for the target
183 certificate being verified in the ctx. Built-in available values for
184 the purpose argument are X509_PURPOSE_SSL_CLIENT,
185 X509_PURPOSE_SSL_SERVER, X509_PURPOSE_NS_SSL_SERVER,
186 X509_PURPOSE_SMIME_SIGN, X509_PURPOSE_SMIME_ENCRYPT,
187 X509_PURPOSE_CRL_SIGN, X509_PURPOSE_ANY, X509_PURPOSE_OCSP_HELPER and
188 X509_PURPOSE_TIMESTAMP_SIGN. It is also possible to create a custom
189 purpose value. Setting a purpose will ensure that the key usage
190 declared within certificates in the chain being verified is consistent
191 with that purpose as well as, potentially, other checks. Every purpose
192 also has an associated default trust value which will also be set at
193 the same time. During verification this trust setting will be verified
194 to check it is consistent with the trust set by the system
195 administrator for certificates in the chain.
196
197 X509_STORE_CTX_set_trust() sets the trust value for the target
198 certificate being verified in the ctx. Built-in available values for
199 the trust argument are X509_TRUST_COMPAT, X509_TRUST_SSL_CLIENT,
200 X509_TRUST_SSL_SERVER, X509_TRUST_EMAIL, X509_TRUST_OBJECT_SIGN,
201 X509_TRUST_OCSP_SIGN, X509_TRUST_OCSP_REQUEST and X509_TRUST_TSA. It is
202 also possible to create a custom trust value. Since
203 X509_STORE_CTX_set_purpose() also sets the trust value it is normally
204 sufficient to only call that function. If both are called then
205 X509_STORE_CTX_set_trust() should be called after
206 X509_STORE_CTX_set_purpose() since the trust setting of the last call
207 will be used.
208
209 It should not normally be necessary for end user applications to call
210 X509_STORE_CTX_purpose_inherit() directly. Typically applications
211 should call X509_STORE_CTX_set_purpose() or X509_STORE_CTX_set_trust()
212 instead. Using this function it is possible to set the purpose and
213 trust values for the ctx at the same time. Both ctx and its internal
214 verification parameter pointer must not be NULL. The def_purpose and
215 purpose arguments can have the same purpose values as described for
216 X509_STORE_CTX_set_purpose() above. The trust argument can have the
217 same trust values as described in X509_STORE_CTX_set_trust() above. Any
218 of the def_purpose, purpose or trust values may also have the value 0
219 to indicate that the supplied parameter should be ignored. After
220 calling this function the purpose to be used for verification is set
221 from the purpose argument unless the purpose was already set in ctx
222 before, and the trust is set from the trust argument unless the trust
223 was already set in ctx before. If trust is 0 then the trust value will
224 be set from the default trust value for purpose. If the default trust
225 value for the purpose is X509_TRUST_DEFAULT and trust is 0 then the
226 default trust value associated with the def_purpose value is used for
227 the trust setting instead.
228
230 The certificates and CRLs in a store are used internally and should not
231 be freed up until after the associated X509_STORE_CTX is freed.
232
234 The certificates and CRLs in a context are used internally and should
235 not be freed up until after the associated X509_STORE_CTX is freed.
236 Copies should be made or reference counts increased instead.
237
239 X509_STORE_CTX_new() returns a newly allocated context or NULL if an
240 error occurred.
241
242 X509_STORE_CTX_init() returns 1 for success or 0 if an error occurred.
243
244 X509_STORE_CTX_get0_param() returns a pointer to an X509_VERIFY_PARAM
245 structure or NULL if an error occurred.
246
247 X509_STORE_CTX_cleanup(), X509_STORE_CTX_free(),
248 X509_STORE_CTX_set0_trusted_stack(), X509_STORE_CTX_set_cert(),
249 X509_STORE_CTX_set0_crls() and X509_STORE_CTX_set0_param() do not
250 return values.
251
252 X509_STORE_CTX_set_default() returns 1 for success or 0 if an error
253 occurred.
254
255 X509_STORE_CTX_get_num_untrusted() returns the number of untrusted
256 certificates used.
257
259 X509_verify_cert(3), X509_STORE_CTX_verify(3),
260 X509_VERIFY_PARAM_set_flags(3)
261
263 The X509_STORE_CTX_set0_crls() function was added in OpenSSL 1.0.0.
264 The X509_STORE_CTX_get_num_untrusted() function was added in OpenSSL
265 1.1.0. The X509_STORE_CTX_new_ex() function was added in OpenSSL 3.0.
266
267 There is no need to call X509_STORE_CTX_cleanup() explicitly since
268 OpenSSL 3.0.
269
271 Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
272
273 Licensed under the Apache License 2.0 (the "License"). You may not use
274 this file except in compliance with the License. You can obtain a copy
275 in the file LICENSE in the source distribution or at
276 <https://www.openssl.org/source/license.html>.
277
278
279
2803.1.1 2023-08-31 X509_STORE_CTX_NEW(3ossl)