Fix some X509_STORE macros
[openssl.git] / doc / crypto / X509_STORE_CTX_new.pod
1 =pod
2
3 =head1 NAME
4
5 X509_STORE_CTX_new, X509_STORE_CTX_cleanup, X509_STORE_CTX_free,
6 X509_STORE_CTX_init, X509_STORE_CTX_set0_trusted_stack, X509_STORE_CTX_set_cert,
7 X509_STORE_CTX_set0_crls,
8 X509_STORE_CTX_get0_chain, X509_STORE_CTX_set0_verified_chain,
9 X509_STORE_CTX_get0_param, X509_STORE_CTX_set0_param,
10 X509_STORE_CTX_get0_cert,
11 X509_STORE_CTX_get0_untrusted, X509_STORE_CTX_set0_untrusted,
12 X509_STORE_CTX_get_num_untrusted,
13 X509_STORE_CTX_set_default,
14 X509_STORE_CTX_get_verify_cb,
15 X509_STORE_CTX_set_verify,
16 X509_STORE_CTX_get_verify - X509_STORE_CTX initialisation
17
18 =head1 SYNOPSIS
19
20  #include <openssl/x509_vfy.h>
21
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 *store,
27                          X509 *x509, STACK_OF(X509) *chain);
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 *x);
32  STACK_OF(X509) *X509_STORE_CTX_get0_chain(X609_STORE_CTX *ctx);
33  void X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *chain);
34  void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk);
35
36  X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx);
37  void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
38  int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
39
40  X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx);
41  STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx);
42  void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
43
44  int X509_STORE_CTX_get_num_untrusted(X509_STORE_CTX *ctx);
45
46  typedef int (*X509_STORE_CTX_verify)(X509_STORE_CTX *);
47  X509_STORE_CTX_verify X509_STORE_CTX_get_verify(X509_STORE_CTX *ctx);
48  void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, X509_STORE_CTX_verify verify);
49
50  void X509_STORE_set_verify(X509_STORE *ctx, X509_STORE_CTX_verify verify);
51
52 =head1 DESCRIPTION
53
54 These functions initialise an B<X509_STORE_CTX> structure for subsequent use
55 by X509_verify_cert().
56
57 X509_STORE_CTX_new() returns a newly initialised B<X509_STORE_CTX> structure.
58
59 X509_STORE_CTX_cleanup() internally cleans up an B<X509_STORE_CTX> structure.
60 The context can then be reused with an new call to X509_STORE_CTX_init().
61
62 X509_STORE_CTX_free() completely frees up B<ctx>. After this call B<ctx>
63 is no longer valid.
64 If B<ctx> is NULL nothing is done.
65
66 X509_STORE_CTX_init() sets up B<ctx> for a subsequent verification operation.
67 It must be called before each call to X509_verify_cert(), i.e. a B<ctx> is only
68 good for one call to X509_verify_cert(); if you want to verify a second
69 certificate with the same B<ctx> then you must call X509_XTORE_CTX_cleanup()
70 and then X509_STORE_CTX_init() again before the second call to
71 X509_verify_cert(). The trusted certificate store is set to B<store>, the end
72 entity certificate to be verified is set to B<x509> and a set of additional
73 certificates (which will be untrusted but may be used to build the chain) in
74 B<chain>. Any or all of the B<store>, B<x509> and B<chain> parameters can be
75 B<NULL>.
76
77 X509_STORE_CTX_set0_trusted_stack() sets the set of trusted certificates of
78 B<ctx> to B<sk>. This is an alternative way of specifying trusted certificates
79 instead of using an B<X509_STORE>.
80
81 X509_STORE_CTX_set_cert() sets the certificate to be verified in B<ctx> to
82 B<x>.
83
84 X509_STORE_CTX_set0_verified_chain() sets the validated chain used
85 by B<ctx> to be B<chain>.
86 Ownership of the chain is transferred to B<ctx> and should not be
87 free'd by the caller.
88 X509_STORE_CTX_get0_chain() returns a the internal pointer used by the
89 B<ctx> that contains the validated chain.
90
91 X509_STORE_CTX_set0_crls() sets a set of CRLs to use to aid certificate
92 verification to B<sk>. These CRLs will only be used if CRL verification is
93 enabled in the associated B<X509_VERIFY_PARAM> structure. This might be
94 used where additional "useful" CRLs are supplied as part of a protocol,
95 for example in a PKCS#7 structure.
96
97 X509_STORE_CTX_get0_param() retrieves an internal pointer
98 to the verification parameters associated with B<ctx>.
99
100 X509_STORE_CTX_get0_cert() retrieves an internal pointer to the
101 certificate being verified by the B<ctx>.
102
103 X509_STORE_CTX_get0_untrusted() retrieves an internal pointer to the
104 stack of untrusted certifieds associated with B<ctx>.
105
106 X509_STORE_CTX_set0_untrusted() sets the internal point to the stack
107 of unstrusted certificates associated with B<ctx> to B<sk>.
108
109 X509_STORE_CTX_set0_param() sets the internal verification parameter pointer
110 to B<param>. After this call B<param> should not be used.
111
112 X509_STORE_CTX_set_default() looks up and sets the default verification
113 method to B<name>. This uses the function X509_VERIFY_PARAM_lookup() to
114 find an appropriate set of parameters from B<name>.
115
116 X509_STORE_CTX_get_num_untrusted() returns the number of untrusted certificates
117 that were used in building the chain following a call to X509_verify_cert().
118
119 X509_STORE_CTX_set_verify() provides the capability for overriding the default
120 verify function. This function is responsible for verifying chain signatures and
121 expiration times. X509_STORE_CTX_get_verify() obtains the current verify
122 function being used.
123
124 X509_STORE_set_verify() works in the same way as for X509_STORE_CTX_set_verify()
125 but sets the default verify function to be used by all X509_STORE_CTX objects
126 created for this X509_STORE.
127
128 A verify function is defined as an X509_STORE_CTX_verify type which has the
129 following signature:
130
131  int (*verify)(X509_STORE_CTX *); 
132
133 This function should receive the current X509_STORE_CTX as a parameter and
134 return 1 on success or 0 on failure.
135
136 =head1 NOTES
137
138 The certificates and CRLs in a store are used internally and should B<not>
139 be freed up until after the associated B<X509_STORE_CTX> is freed.
140
141 =head1 BUGS
142
143 The certificates and CRLs in a context are used internally and should B<not>
144 be freed up until after the associated B<X509_STORE_CTX> is freed. Copies
145 should be made or reference counts increased instead.
146
147 =head1 RETURN VALUES
148
149 X509_STORE_CTX_new() returns an newly allocates context or B<NULL> is an
150 error occurred.
151
152 X509_STORE_CTX_init() returns 1 for success or 0 if an error occurred.
153
154 X509_STORE_CTX_get0_param() returns a pointer to an B<X509_VERIFY_PARAM>
155 structure or B<NULL> if an error occurred.
156
157 X509_STORE_CTX_cleanup(), X509_STORE_CTX_free(),
158 X509_STORE_CTX_set0_trusted_stack(),
159 X509_STORE_CTX_set_cert(),
160 X509_STORE_CTX_set0_crls() and X509_STORE_CTX_set0_param() do not return
161 values.
162
163 X509_STORE_CTX_set_default() returns 1 for success or 0 if an error occurred.
164
165 X509_STORE_CTX_get_num_untrusted() returns the number of untrusted certificates
166 used.
167
168 X509_STORE_CTX_get_verify() returns the current verify function in use for this
169 X509_STORE_CTX.
170
171 =head1 SEE ALSO
172
173 L<X509_verify_cert(3)>
174 L<X509_VERIFY_PARAM_set_flags(3)>
175
176 =head1 HISTORY
177
178 X509_STORE_CTX_set0_crls() was first added to OpenSSL 1.0.0
179 X509_STORE_CTX_get_num_untrusted() was first added to OpenSSL 1.1.0
180 X509_STORE_set_verify() wsa first added to OpenSSL 1.1.0. It was previously
181 available as a macro X509_STORE_set_verify_func(). This macro still exists but
182 simply calls this function.
183
184 =cut