1=pod
2
3=head1 NAME
4
5X509_STORE_CTX_new_ex, X509_STORE_CTX_new, X509_STORE_CTX_cleanup,
6X509_STORE_CTX_free, X509_STORE_CTX_init, X509_STORE_CTX_set0_trusted_stack,
7X509_STORE_CTX_set_cert, X509_STORE_CTX_set0_crls,
8X509_STORE_CTX_get0_param, X509_STORE_CTX_set0_param,
9X509_STORE_CTX_get0_untrusted, X509_STORE_CTX_set0_untrusted,
10X509_STORE_CTX_get_num_untrusted,
11X509_STORE_CTX_get0_chain, X509_STORE_CTX_set0_verified_chain,
12X509_STORE_CTX_set_default,
13X509_STORE_CTX_set_verify,
14X509_STORE_CTX_verify_fn
15- X509_STORE_CTX initialisation
16
17=head1 SYNOPSIS
18
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=head1 DESCRIPTION
49
50These functions initialise an B<X509_STORE_CTX> structure for subsequent use
51by L<X509_verify_cert(3)> or L<X509_STORE_CTX_verify(3)>.
52
53X509_STORE_CTX_new_ex() returns a newly initialised B<X509_STORE_CTX>
54structure associated with the specified library context I<libctx> and property
55query string I<propq>. Any cryptographic algorithms fetched while performing
56processing with the X509_STORE_CTX will use that library context and property
57query string.
58
59X509_STORE_CTX_new() is the same as X509_STORE_CTX_new_ex() except that
60the default library context and a NULL property query string are used.
61
62X509_STORE_CTX_cleanup() internally cleans up an B<X509_STORE_CTX> structure.
63It is used by X509_STORE_CTX_init() and X509_STORE_CTX_free().
64
65X509_STORE_CTX_free() completely frees up I<ctx>. After this call I<ctx>
66is no longer valid.
67If I<ctx> is NULL nothing is done.
68
69It must be called before each call to L<X509_verify_cert(3)> or
70L<X509_STORE_CTX_verify(3)>, i.e., a context is only good for one verification.
71If you want to verify a further certificate or chain with the same I<ctx>
72then you must call X509_STORE_CTX_init() again.
73The trusted certificate store is set to I<trust_store> of type B<X509_STORE>.
74This may be NULL because there are no trusted certificates or because
75they are provided simply as a list using X509_STORE_CTX_set0_trusted_stack().
76The certificate to be verified is set to I<target>,
77and a list of additional certificates may be provided in I<untrusted>,
78which will be untrusted but may be used to build the chain.
79Each of the I<trust_store>, I<target> and I<untrusted> parameters can be NULL.
80Yet note that L<X509_verify_cert(3)> and L<X509_STORE_CTX_verify(3)>
81will need a verification target.
82This can also be set using X509_STORE_CTX_set_cert().
83For L<X509_STORE_CTX_verify(3)>, which takes by default the first element of the
84list of untrusted certificates as its verification target,
85this can be also set indirectly using X509_STORE_CTX_set0_untrusted().
86
87X509_STORE_CTX_set0_trusted_stack() sets the set of trusted certificates of
88I<ctx> to I<sk>. This is an alternative way of specifying trusted certificates
89instead of using an B<X509_STORE> where its complexity is not needed
90or to make sure that only the given set I<sk> of certificates are trusted.
91
92X509_STORE_CTX_set_cert() sets the target certificate to be verified in I<ctx>
93to I<target>.
94
95X509_STORE_CTX_set0_verified_chain() sets the validated chain to I<chain>.
96Ownership of the chain is transferred to I<ctx>,
97and so it should not be free'd by the caller.
98
99X509_STORE_CTX_get0_chain() returns the internal pointer used by the
100I<ctx> that contains the constructed (output) chain.
101
102X509_STORE_CTX_set0_crls() sets a set of CRLs to use to aid certificate
103verification to I<sk>. These CRLs will only be used if CRL verification is
104enabled in the associated B<X509_VERIFY_PARAM> structure. This might be
105used where additional "useful" CRLs are supplied as part of a protocol,
106for example in a PKCS#7 structure.
107
108X509_STORE_CTX_get0_param() retrieves an internal pointer
109to the verification parameters associated with I<ctx>.
110
111X509_STORE_CTX_set0_param() sets the internal verification parameter pointer
112to I<param>. After this call B<param> should not be used.
113
114X509_STORE_CTX_get0_untrusted() retrieves an internal pointer to the
115stack of untrusted certificates associated with I<ctx>.
116
117X509_STORE_CTX_set0_untrusted() sets the internal pointer to the stack
118of untrusted certificates associated with I<ctx> to I<sk>.
119X509_STORE_CTX_verify() will take the first element, if any,
120as its default target if the target certificate is not set explicitly.
121
122X509_STORE_CTX_get_num_untrusted() returns the number of untrusted certificates
123that were used in building the chain.
124This is can be used after calling L<X509_verify_cert(3)> and similar functions.
125With L<X509_STORE_CTX_verify(3)>, this does not count the first chain element.
126
127X509_STORE_CTX_get0_chain() returns the internal pointer used by the
128I<ctx> that contains the validated chain.
129
130Details of the chain building and checking process are described in
131L<openssl-verification-options(1)/Certification Path Building> and
132L<openssl-verification-options(1)/Certification Path Validation>.
133
134X509_STORE_CTX_set0_verified_chain() sets the validated chain used
135by I<ctx> to be I<chain>.
136Ownership of the chain is transferred to I<ctx>,
137and so it should not be free'd by the caller.
138
139X509_STORE_CTX_set_default() looks up and sets the default verification
140method to I<name>. This uses the function X509_VERIFY_PARAM_lookup() to
141find an appropriate set of parameters from the purpose identifier I<name>.
142Currently defined purposes are C<sslclient>, C<sslserver>, C<nssslserver>,
143C<smimesign>, C<smimeencrypt>, C<crlsign>, C<ocsphelper>, C<timestampsign>,
144and C<any>.
145
146X509_STORE_CTX_set_verify() provides the capability for overriding the default
147verify function. This function is responsible for verifying chain signatures and
148expiration times.
149
150A verify function is defined as an X509_STORE_CTX_verify type which has the
151following signature:
152
153 int (*verify)(X509_STORE_CTX *);
154
155This function should receive the current X509_STORE_CTX as a parameter and
156return 1 on success or 0 on failure.
157
158=head1 NOTES
159
160The certificates and CRLs in a store are used internally and should B<not>
161be freed up until after the associated B<X509_STORE_CTX> is freed.
162
163=head1 BUGS
164
165The certificates and CRLs in a context are used internally and should B<not>
166be freed up until after the associated B<X509_STORE_CTX> is freed. Copies
167should be made or reference counts increased instead.
168
169=head1 RETURN VALUES
170
171X509_STORE_CTX_new() returns a newly allocated context or NULL if an
172error occurred.
173
174X509_STORE_CTX_init() returns 1 for success or 0 if an error occurred.
175
176X509_STORE_CTX_get0_param() returns a pointer to an B<X509_VERIFY_PARAM>
177structure or NULL if an error occurred.
178
179X509_STORE_CTX_cleanup(), X509_STORE_CTX_free(),
180X509_STORE_CTX_set0_trusted_stack(),
181X509_STORE_CTX_set_cert(),
182X509_STORE_CTX_set0_crls() and X509_STORE_CTX_set0_param() do not return
183values.
184
185X509_STORE_CTX_set_default() returns 1 for success or 0 if an error occurred.
186
187X509_STORE_CTX_get_num_untrusted() returns the number of untrusted certificates
188used.
189
190=head1 SEE ALSO
191
192L<X509_verify_cert(3)>, L<X509_STORE_CTX_verify(3)>,
193L<X509_VERIFY_PARAM_set_flags(3)>
194
195=head1 HISTORY
196
197The X509_STORE_CTX_set0_crls() function was added in OpenSSL 1.0.0.
198The X509_STORE_CTX_get_num_untrusted() function was added in OpenSSL 1.1.0.
199The X509_STORE_CTX_new_ex() function was added in OpenSSL 3.0.
200
201There is no need to call X509_STORE_CTX_cleanup() explicitly since OpenSSL 3.0.
202
203=head1 COPYRIGHT
204
205Copyright 2009-2021 The OpenSSL Project Authors. All Rights Reserved.
206
207Licensed under the Apache License 2.0 (the "License").  You may not use
208this file except in compliance with the License.  You can obtain a copy
209in the file LICENSE in the source distribution or at
210L<https://www.openssl.org/source/license.html>.
211
212=cut
213