Debian Codegraph @

upstream/debian-trixie/man3/X509_STORE_CTX_new.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "X509_STORE_CTX_NEW 3SSL"
58 .TH X509_STORE_CTX_NEW 3SSL 2026-04-07 3.5.6 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 X509_STORE_CTX_new_ex, X509_STORE_CTX_new, X509_STORE_CTX_cleanup,
65 X509_STORE_CTX_free, X509_STORE_CTX_init,
66 X509_STORE_CTX_init_rpk,
67 X509_STORE_CTX_set0_trusted_stack,
68 X509_STORE_CTX_set_cert, X509_STORE_CTX_set0_crls,
69 X509_STORE_CTX_set0_rpk,
70 X509_STORE_CTX_get0_param, X509_STORE_CTX_set0_param,
71 X509_STORE_CTX_get0_untrusted, X509_STORE_CTX_set0_untrusted,
72 X509_STORE_CTX_get_num_untrusted,
73 X509_STORE_CTX_get0_chain, X509_STORE_CTX_set0_verified_chain,
74 X509_STORE_CTX_get0_rpk,
75 X509_STORE_CTX_set_default,
76 X509_STORE_CTX_set_verify,
77 X509_STORE_CTX_verify_fn,
78 X509_STORE_CTX_set_purpose,
79 X509_STORE_CTX_set_trust,
80 X509_STORE_CTX_purpose_inherit
81 \&\- X509_STORE_CTX initialisation
82 .SH SYNOPSIS
83 .IX Header "SYNOPSIS"
84 .Vb 1
85 \& #include <openssl/x509_vfy.h>
86 \&
87 \& X509_STORE_CTX *X509_STORE_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq);
88 \& X509_STORE_CTX *X509_STORE_CTX_new(void);
89 \& void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
90 \& void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
91 \&
92 \& int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *trust_store,
93 \& X509 *target, STACK_OF(X509) *untrusted);
94 \& int X509_STORE_CTX_init_rpk(X509_STORE_CTX *ctx, X509_STORE *trust_store,
95 \& EVP_PKEY *rpk);
96 \&
97 \& void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
98 \&
99 \& void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *target);
100 \& void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk);
101 \& void X509_STORE_CTX_set0_rpk(X509_STORE_CTX *ctx, EVP_PKEY *target);
102 \&
103 \& X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(const X509_STORE_CTX *ctx);
104 \& void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
105 \&
106 \& STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx);
107 \& void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
108 \&
109 \& int X509_STORE_CTX_get_num_untrusted(const X509_STORE_CTX *ctx);
110 \& STACK_OF(X509) *X509_STORE_CTX_get0_chain(const X509_STORE_CTX *ctx);
111 \& void X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *chain);
112 \& EVP_PKEY *X509_STORE_CTX_get0_rpk(const X509_STORE_CTX *ctx);
113 \&
114 \& int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
115 \& typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *);
116 \& void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, X509_STORE_CTX_verify_fn verify);
117 \&
118 \& int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
119 \& int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
120 \& int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
121 \& int purpose, int trust);
122 .Ve
123 .SH DESCRIPTION
124 .IX Header "DESCRIPTION"
125 These functions initialise an \fBX509_STORE_CTX\fR structure for subsequent use
126 by \fBX509_verify_cert\fR\|(3) or \fBX509_STORE_CTX_verify\fR\|(3).
127 .PP
128 \&\fBX509_STORE_CTX_new_ex()\fR returns a newly initialised \fBX509_STORE_CTX\fR
129 structure associated with the specified library context \fIlibctx\fR and property
130 query string \fIpropq\fR. Any cryptographic algorithms fetched while performing
131 processing with the X509_STORE_CTX will use that library context and property
132 query string.
133 .PP
134 \&\fBX509_STORE_CTX_new()\fR is the same as \fBX509_STORE_CTX_new_ex()\fR except that
135 the default library context and a NULL property query string are used.
136 .PP
137 \&\fBX509_STORE_CTX_cleanup()\fR internally cleans up an \fBX509_STORE_CTX\fR structure.
138 It is used by \fBX509_STORE_CTX_init()\fR and \fBX509_STORE_CTX_free()\fR.
139 .PP
140 \&\fBX509_STORE_CTX_free()\fR completely frees up \fIctx\fR. After this call \fIctx\fR
141 is no longer valid.
142 If \fIctx\fR is NULL nothing is done.
143 .PP
144 \&\fBX509_STORE_CTX_init()\fR sets up \fIctx\fR for a subsequent verification operation.
145 .PP
146 \&\fBX509_STORE_CTX_init()\fR initializes the internal state and resources of the
147 given \fIctx\fR. Among others, it sets the verification parameters associated
148 with the method name \f(CW\*(C`default\*(C'\fR, which includes the \f(CW\*(C`any\*(C'\fR purpose,
149 and takes over callback function pointers from \fItrust_store\fR (unless NULL).
150 It must be called before each call to \fBX509_verify_cert\fR\|(3) or
151 \&\fBX509_STORE_CTX_verify\fR\|(3), i.e., a context is only good for one verification.
152 If you want to verify a further certificate or chain with the same \fIctx\fR
153 then you must call \fBX509_STORE_CTX_init()\fR again.
154 The trusted certificate store is set to \fItrust_store\fR of type \fBX509_STORE\fR.
155 This may be NULL because there are no trusted certificates or because
156 they are provided simply as a list using \fBX509_STORE_CTX_set0_trusted_stack()\fR.
157 The certificate to be verified is set to \fItarget\fR,
158 and a list of additional certificates may be provided in \fIuntrusted\fR,
159 which will be untrusted but may be used to build the chain.
160 The \fItarget\fR certificate is not copied (its reference count is not updated),
161 and the caller must not free it before verification is complete.
162 Each of the \fItrust_store\fR, \fItarget\fR and \fIuntrusted\fR parameters can be NULL.
163 Yet note that \fBX509_verify_cert\fR\|(3) and \fBX509_STORE_CTX_verify\fR\|(3)
164 will need a verification target.
165 This can also be set using \fBX509_STORE_CTX_set_cert()\fR.
166 For \fBX509_STORE_CTX_verify\fR\|(3), which takes by default the first element of the
167 list of untrusted certificates as its verification target,
168 this can be also set indirectly using \fBX509_STORE_CTX_set0_untrusted()\fR.
169 .PP
170 \&\fBX509_STORE_CTX_init_rpk()\fR sets up \fIctx\fR for a subsequent verification
171 operation for the \fItarget\fR raw public key.
172 It behaves similarly to \fBX509_STORE_CTX_init()\fR.
173 The \fItarget\fR raw public key can also be supplied separately, via
174 \&\fBX509_STORE_CTX_set0_rpk()\fR.
175 The \fItarget\fR public key is not copied (its reference count is not updated),
176 and the caller must not free it before verification is complete.
177 .PP
178 \&\fBX509_STORE_CTX_set0_trusted_stack()\fR sets the set of trusted certificates of
179 \&\fIctx\fR to \fIsk\fR. This is an alternative way of specifying trusted certificates
180 instead of using an \fBX509_STORE\fR where its complexity is not needed
181 or to make sure that only the given set \fIsk\fR of certificates are trusted.
182 .PP
183 \&\fBX509_STORE_CTX_set_cert()\fR sets the target certificate to be verified in \fIctx\fR
184 to \fItarget\fR.
185 The target certificate is not copied (its reference count is not updated),
186 and the caller must not free it before verification is complete.
187 .PP
188 \&\fBX509_STORE_CTX_set0_rpk()\fR sets the target raw public key to be verified in \fIctx\fR
189 to \fItarget\fR, a non-NULL raw public key preempts any target certificate, which
190 is then ignored.
191 The \fItarget\fR public key is not copied (its reference count is not updated),
192 and the caller must not free it before verification is complete.
193 .PP
194 \&\fBX509_STORE_CTX_set0_verified_chain()\fR sets the validated chain to \fIchain\fR.
195 Ownership of the chain is transferred to \fIctx\fR,
196 and so it should not be free'd by the caller.
197 .PP
198 \&\fBX509_STORE_CTX_get0_chain()\fR returns the internal pointer used by the
199 \&\fIctx\fR that contains the constructed (output) chain.
200 .PP
201 \&\fBX509_STORE_CTX_get0_rpk()\fR returns the internal pointer used by the
202 \&\fIctx\fR that contains the raw public key.
203 .PP
204 \&\fBX509_STORE_CTX_set0_crls()\fR sets a set of CRLs to use to aid certificate
205 verification to \fIsk\fR. These CRLs will only be used if CRL verification is
206 enabled in the associated \fBX509_VERIFY_PARAM\fR structure. This might be
207 used where additional "useful" CRLs are supplied as part of a protocol,
208 for example in a PKCS#7 structure.
209 .PP
210 \&\fBX509_STORE_CTX_get0_param()\fR retrieves an internal pointer
211 to the verification parameters associated with \fIctx\fR.
212 .PP
213 \&\fBX509_STORE_CTX_set0_param()\fR sets the internal verification parameter pointer
214 to \fIparam\fR. After this call \fBparam\fR should not be used.
215 .PP
216 \&\fBX509_STORE_CTX_get0_untrusted()\fR retrieves an internal pointer to the
217 stack of untrusted certificates associated with \fIctx\fR.
218 .PP
219 \&\fBX509_STORE_CTX_set0_untrusted()\fR sets the internal pointer to the stack
220 of untrusted certificates associated with \fIctx\fR to \fIsk\fR.
221 \&\fBX509_STORE_CTX_verify()\fR will take the first element, if any,
222 as its default target if the target certificate is not set explicitly.
223 .PP
224 \&\fBX509_STORE_CTX_get_num_untrusted()\fR returns the number of untrusted certificates
225 that were used in building the chain.
226 This is can be used after calling \fBX509_verify_cert\fR\|(3) and similar functions.
227 With \fBX509_STORE_CTX_verify\fR\|(3), this does not count the first chain element.
228 .PP
229 \&\fBX509_STORE_CTX_get0_chain()\fR returns the internal pointer used by the
230 \&\fIctx\fR that contains the validated chain.
231 .PP
232 Details of the chain building and checking process are described in
233 "Certification Path Building" in \fBopenssl\-verification\-options\fR\|(1) and
234 "Certification Path Validation" in \fBopenssl\-verification\-options\fR\|(1).
235 .PP
236 \&\fBX509_STORE_CTX_set0_verified_chain()\fR sets the validated chain used
237 by \fIctx\fR to be \fIchain\fR.
238 Ownership of the chain is transferred to \fIctx\fR,
239 and so it should not be free'd by the caller.
240 .PP
241 \&\fBX509_STORE_CTX_set_default()\fR looks up and sets the default verification method.
242 This uses the function \fBX509_VERIFY_PARAM_lookup()\fR to find
243 the set of parameters associated with the given verification method \fIname\fR.
244 Among others, the parameters determine the trust model and verification purpose.
245 More detail, including the list of currently predefined methods,
246 is described for the \fB\-verify_name\fR command-line option
247 in "Verification Options" in \fBopenssl\-verification\-options\fR\|(1).
248 .PP
249 \&\fBX509_STORE_CTX_set_verify()\fR provides the capability for overriding the default
250 verify function. This function is responsible for verifying chain signatures and
251 expiration times.
252 .PP
253 A verify function is defined as an X509_STORE_CTX_verify type which has the
254 following signature:
255 .PP
256 .Vb 1
257 \& int (*verify)(X509_STORE_CTX *);
258 .Ve
259 .PP
260 This function should receive the current X509_STORE_CTX as a parameter and
261 return 1 on success or 0 on failure.
262 .PP
263 X509 certificates may contain information about what purposes keys contained
264 within them can be used for. For example "TLS WWW Server Authentication" or
265 "Email Protection". This "key usage" information is held internally to the
266 certificate itself. In addition the trust store containing trusted certificates
267 can declare what purposes we trust different certificates for. This "trust"
268 information is not held within the certificate itself but is "meta" information
269 held alongside it. This "meta" information is associated with the certificate
270 after it is issued and could be determined by a system administrator. For
271 example a certificate might declare that it is suitable for use for both
272 "TLS WWW Server Authentication" and "TLS Client Authentication", but a system
273 administrator might only trust it for the former. An X.509 certificate extension
274 exists that can record extended key usage information to supplement the purpose
275 information described above. This extended mechanism is arbitrarily extensible
276 and not well suited for a generic library API; applications that need to
277 validate extended key usage information in certificates will need to define a
278 custom "purpose" (see below) or supply a nondefault verification callback
279 (\fBX509_STORE_set_verify_cb_func\fR\|(3)).
280 .PP
281 \&\fBX509_STORE_CTX_set_purpose()\fR sets the purpose for the target certificate being
282 verified in the \fIctx\fR. Built-in available values for the \fIpurpose\fR argument
283 are \fBX509_PURPOSE_SSL_CLIENT\fR, \fBX509_PURPOSE_SSL_SERVER\fR,
284 \&\fBX509_PURPOSE_NS_SSL_SERVER\fR, \fBX509_PURPOSE_SMIME_SIGN\fR,
285 \&\fBX509_PURPOSE_SMIME_ENCRYPT\fR, \fBX509_PURPOSE_CRL_SIGN\fR, \fBX509_PURPOSE_ANY\fR,
286 \&\fBX509_PURPOSE_OCSP_HELPER\fR, \fBX509_PURPOSE_TIMESTAMP_SIGN\fR and
287 \&\fBX509_PURPOSE_CODE_SIGN\fR. It is also
288 possible to create a custom purpose value. Setting a purpose requests that
289 the key usage and extended key usage (EKU) extensions optionally declared within
290 the certificate and its chain are verified to be consistent with that purpose.
291 For SSL client, SSL server, and S/MIME purposes, the EKU is checked also for the
292 CA certificates along the chain, including any given trust anchor certificate.
293 Potentially also further checks are done (depending on the purpose given).
294 Every purpose also has an associated default trust value, which will also be set
295 at the same time. During verification, this trust setting will be verified
296 to check whether it is consistent with the trust set by the system administrator
297 for certificates in the chain.
298 .PP
299 \&\fBX509_STORE_CTX_set_trust()\fR sets the trust value for the target certificate
300 being verified in the \fIctx\fR. Built-in available values for the \fItrust\fR
301 argument are \fBX509_TRUST_COMPAT\fR, \fBX509_TRUST_SSL_CLIENT\fR,
302 \&\fBX509_TRUST_SSL_SERVER\fR, \fBX509_TRUST_EMAIL\fR, \fBX509_TRUST_OBJECT_SIGN\fR,
303 \&\fBX509_TRUST_OCSP_SIGN\fR, \fBX509_TRUST_OCSP_REQUEST\fR and \fBX509_TRUST_TSA\fR. It is
304 also possible to create a custom trust value. Since \fBX509_STORE_CTX_set_purpose()\fR
305 also sets the trust value it is normally sufficient to only call that function.
306 If both are called then \fBX509_STORE_CTX_set_trust()\fR should be called after
307 \&\fBX509_STORE_CTX_set_purpose()\fR since the trust setting of the last call will be
308 used.
309 .PP
310 It should not normally be necessary for end user applications to call
311 \&\fBX509_STORE_CTX_purpose_inherit()\fR directly. Typically applications should call
312 \&\fBX509_STORE_CTX_set_purpose()\fR or \fBX509_STORE_CTX_set_trust()\fR instead. Using this
313 function it is possible to set the purpose and trust values for the \fIctx\fR at
314 the same time.
315 Both \fIctx\fR and its internal verification parameter pointer must not be NULL.
316 The \fIdef_purpose\fR and \fIpurpose\fR arguments can have the same
317 purpose values as described for \fBX509_STORE_CTX_set_purpose()\fR above. The \fItrust\fR
318 argument can have the same trust values as described in
319 \&\fBX509_STORE_CTX_set_trust()\fR above. Any of the \fIdef_purpose\fR, \fIpurpose\fR or
320 \&\fItrust\fR values may also have the value 0 to indicate that the supplied
321 parameter should be ignored. After calling this function the purpose to be used
322 for verification is set from the \fIpurpose\fR argument unless the purpose was
323 already set in \fIctx\fR before, and the trust is set from the \fItrust\fR argument
324 unless the trust was already set in \fIctx\fR before.
325 If \fItrust\fR is 0 then the trust value will be set from
326 the default trust value for \fIpurpose\fR. If the default trust value for the
327 purpose is \fIX509_TRUST_DEFAULT\fR and \fItrust\fR is 0 then the default trust value
328 associated with the \fIdef_purpose\fR value is used for the trust setting instead.
329 .SH NOTES
330 .IX Header "NOTES"
331 The certificates and CRLs in a store are used internally and should \fBnot\fR
332 be freed up until after the associated \fBX509_STORE_CTX\fR is freed.
333 .SH BUGS
334 .IX Header "BUGS"
335 The certificates and CRLs in a context are used internally and should \fBnot\fR
336 be freed up until after the associated \fBX509_STORE_CTX\fR is freed. Copies
337 should be made or reference counts increased instead.
338 .SH "RETURN VALUES"
339 .IX Header "RETURN VALUES"
340 \&\fBX509_STORE_CTX_new()\fR returns a newly allocated context or NULL if an
341 error occurred.
342 .PP
343 \&\fBX509_STORE_CTX_init()\fR and \fBX509_STORE_CTX_init_rpk()\fR return 1 for success
344 or 0 if an error occurred.
345 .PP
346 \&\fBX509_STORE_CTX_get0_param()\fR returns a pointer to an \fBX509_VERIFY_PARAM\fR
347 structure or NULL if an error occurred.
348 .PP
349 \&\fBX509_STORE_CTX_get0_rpk()\fR returns a pointer to an \fBEVP_PKEY\fR structure if
350 present, or NULL if absent.
351 .PP
352 \&\fBX509_STORE_CTX_cleanup()\fR, \fBX509_STORE_CTX_free()\fR,
353 \&\fBX509_STORE_CTX_set0_trusted_stack()\fR,
354 \&\fBX509_STORE_CTX_set_cert()\fR,
355 \&\fBX509_STORE_CTX_set0_crls()\fR and \fBX509_STORE_CTX_set0_param()\fR do not return
356 values.
357 .PP
358 \&\fBX509_STORE_CTX_set_default()\fR returns 1 for success or 0 if an error occurred.
359 .PP
360 \&\fBX509_STORE_CTX_get_num_untrusted()\fR returns the number of untrusted certificates
361 used.
362 .SH "SEE ALSO"
363 .IX Header "SEE ALSO"
364 \&\fBX509_verify_cert\fR\|(3), \fBX509_STORE_CTX_verify\fR\|(3),
365 \&\fBX509_VERIFY_PARAM_set_flags\fR\|(3)
366 .SH HISTORY
367 .IX Header "HISTORY"
368 The \fBX509_STORE_CTX_set0_crls()\fR function was added in OpenSSL 1.0.0.
369 The \fBX509_STORE_CTX_get_num_untrusted()\fR function was added in OpenSSL 1.1.0.
370 The \fBX509_STORE_CTX_new_ex()\fR function was added in OpenSSL 3.0.
371 The \fBX509_STORE_CTX_init_rpk()\fR, \fBX509_STORE_CTX_get0_rpk()\fR, and
372 \&\fBX509_STORE_CTX_set0_rpk()\fR functions were added in OpenSSL 3.2.
373 .PP
374 There is no need to call \fBX509_STORE_CTX_cleanup()\fR explicitly since OpenSSL 3.0.
375 .SH COPYRIGHT
376 .IX Header "COPYRIGHT"
377 Copyright 2009\-2025 The OpenSSL Project Authors. All Rights Reserved.
378 .PP
379 Licensed under the Apache License 2.0 (the "License"). You may not use
380 this file except in compliance with the License. You can obtain a copy
381 in the file LICENSE in the source distribution or at
382 <https://www.openssl.org/source/license.html>.