26fcf607c3c96e81cf135c2c72c9ee49c063da14
[openssl.git] / doc / crypto / X509_STORE_CTX_get_error.pod
1 =pod
2
3 =head1 NAME
4
5 X509_STORE_CTX_get_error, X509_STORE_CTX_set_error,
6 X509_STORE_CTX_get_error_depth, X509_STORE_CTX_set_error_depth,
7 X509_STORE_CTX_get_current_cert, X509_STORE_CTX_set_current_cert,
8 X509_STORE_CTX_get0_cert, X509_STORE_CTX_get1_chain,
9 X509_verify_cert_error_string - get or set certificate verification status
10 information
11
12 =head1 SYNOPSIS
13
14  #include <openssl/x509.h>
15
16  int   X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
17  void  X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s);
18  int   X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
19  void  X509_STORE_CTX_set_error_depth(X509_STORE_CTX *ctx, int depth);
20  X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
21  void  X509_STORE_CTX_set_current_cert(X509_STORE_CTX *ctx, X509 *x);
22  X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx);
23
24  STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
25
26  const char *X509_verify_cert_error_string(long n);
27
28 =head1 DESCRIPTION
29
30 These functions are typically called after X509_verify_cert() has indicated
31 an error or in a verification callback to determine the nature of an error.
32
33 X509_STORE_CTX_get_error() returns the error code of B<ctx>, see
34 the B<ERROR CODES> section for a full description of all error codes.
35
36 X509_STORE_CTX_set_error() sets the error code of B<ctx> to B<s>. For example
37 it might be used in a verification callback to set an error based on additional
38 checks.
39
40 X509_STORE_CTX_get_error_depth() returns the B<depth> of the error. This is a
41 non-negative integer representing where in the certificate chain the error
42 occurred. If it is zero it occurred in the end entity certificate, one if
43 it is the certificate which signed the end entity certificate and so on.
44
45 X509_STORE_CTX_set_error_depth() sets the error B<depth>.
46 This can be used in combination with X509_STORE_CTX_set_error() to set the
47 depth at which an error condition was detected.
48
49 X509_STORE_CTX_get_current_cert() returns the certificate in B<ctx> which
50 caused the error or B<NULL> if no certificate is relevant.
51
52 X509_STORE_CTX_set_current_cert() sets the certificate B<x> in B<ctx> which
53 caused the error.
54 This value is not intended to remain valid for very long, and remains owned by
55 the caller.
56 It may be examined by a verification callback invoked to handle each error
57 encountered during chain verification and is no longer required after such a
58 callback.
59 If a callback wishes the save the certificate for use after it returns, it
60 needs to increment its reference count via L<X509_up_ref(3)>.
61 Once such a I<saved> certificate is no longer needed it can be freed with
62 L<X509_free(3)>.
63
64 X509_STORE_CTX_get0_cert() returns the leaf certificate being verified.
65
66 X509_STORE_CTX_get1_chain() returns a complete validate chain if a previous
67 call to X509_verify_cert() is successful. If the call to X509_verify_cert()
68 is B<not> successful the returned chain may be incomplete or invalid. The
69 returned chain persists after the B<ctx> structure is freed, when it is
70 no longer needed it should be free up using:
71
72   sk_X509_pop_free(chain, X509_free);
73
74 X509_verify_cert_error_string() returns a human readable error string for
75 verification error B<n>.
76
77 =head1 RETURN VALUES
78
79 X509_STORE_CTX_get_error() returns B<X509_V_OK> or an error code.
80
81 X509_STORE_CTX_get_error_depth() returns a non-negative error depth.
82
83 X509_STORE_CTX_get_current_cert() returns the certificate which caused the
84 error or B<NULL> if no certificate is relevant to the error.
85
86 X509_verify_cert_error_string() returns a human readable error string for
87 verification error B<n>.
88
89 =head1 ERROR CODES
90
91 A list of error codes and messages is shown below.  Some of the
92 error codes are defined but currently never returned: these are described as
93 "unused".
94
95 =over 4
96
97 =item B<X509_V_OK: ok>
98
99 the operation was successful.
100
101 =item B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate>
102
103 the issuer certificate could not be found: this occurs if the issuer certificate
104 of an untrusted certificate cannot be found.
105
106 =item B<X509_V_ERR_UNABLE_TO_GET_CRL: unable to get certificate CRL>
107
108 the CRL of a certificate could not be found.
109
110 =item B<X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature>
111
112 the certificate signature could not be decrypted. This means that the actual
113 signature value could not be determined rather than it not matching the
114 expected value, this is only meaningful for RSA keys.
115
116 =item B<X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature>
117
118 the CRL signature could not be decrypted: this means that the actual signature
119 value could not be determined rather than it not matching the expected value.
120 Unused.
121
122 =item B<X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key>
123
124 the public key in the certificate SubjectPublicKeyInfo could not be read.
125
126 =item B<X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure>
127
128 the signature of the certificate is invalid.
129
130 =item B<X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure>
131
132 the signature of the certificate is invalid.
133
134 =item B<X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid>
135
136 the certificate is not yet valid: the notBefore date is after the current time.
137
138 =item B<X509_V_ERR_CERT_HAS_EXPIRED: certificate has expired>
139
140 the certificate has expired: that is the notAfter date is before the current time.
141
142 =item B<X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid>
143
144 the CRL is not yet valid.
145
146 =item B<X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired>
147
148 the CRL has expired.
149
150 =item B<X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field>
151
152 the certificate notBefore field contains an invalid time.
153
154 =item B<X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field>
155
156 the certificate notAfter field contains an invalid time.
157
158 =item B<X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field>
159
160 the CRL lastUpdate field contains an invalid time.
161
162 =item B<X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field>
163
164 the CRL nextUpdate field contains an invalid time.
165
166 =item B<X509_V_ERR_OUT_OF_MEM: out of memory>
167
168 an error occurred trying to allocate memory. This should never happen.
169
170 =item B<X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate>
171
172 the passed certificate is self signed and the same certificate cannot be found
173 in the list of trusted certificates.
174
175 =item B<X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain>
176
177 the certificate chain could be built up using the untrusted certificates but
178 the root could not be found locally.
179
180 =item B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate>
181
182 the issuer certificate of a locally looked up certificate could not be found.
183 This normally means the list of trusted certificates is not complete.
184
185 =item B<X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate>
186
187 no signatures could be verified because the chain contains only one certificate
188 and it is not self signed.
189
190 =item B<X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long>
191
192 the certificate chain length is greater than the supplied maximum depth. Unused.
193
194 =item B<X509_V_ERR_CERT_REVOKED: certificate revoked>
195
196 the certificate has been revoked.
197
198 =item B<X509_V_ERR_INVALID_CA: invalid CA certificate>
199
200 a CA certificate is invalid. Either it is not a CA or its extensions are not
201 consistent with the supplied purpose.
202
203 =item B<X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded>
204
205 the basicConstraints pathlength parameter has been exceeded.
206
207 =item B<X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose>
208
209 the supplied certificate cannot be used for the specified purpose.
210
211 =item B<X509_V_ERR_CERT_UNTRUSTED: certificate not trusted>
212
213 the root CA is not marked as trusted for the specified purpose.
214
215 =item B<X509_V_ERR_CERT_REJECTED: certificate rejected>
216
217 the root CA is marked to reject the specified purpose.
218
219 =item B<X509_V_ERR_SUBJECT_ISSUER_MISMATCH: subject issuer mismatch>
220
221 the current candidate issuer certificate was rejected because its subject name
222 did not match the issuer name of the current certificate. This is only set
223 if issuer check debugging is enabled it is used for status notification and
224 is B<not> in itself an error.
225
226 =item B<X509_V_ERR_AKID_SKID_MISMATCH: authority and subject key identifier mismatch>
227
228 the current candidate issuer certificate was rejected because its subject key
229 identifier was present and did not match the authority key identifier current
230 certificate. This is only set if issuer check debugging is enabled it is used
231 for status notification and is B<not> in itself an error.
232
233 =item B<X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: authority and issuer serial number mismatch>
234
235 the current candidate issuer certificate was rejected because its issuer name
236 and serial number was present and did not match the authority key identifier of
237 the current certificate. This is only set if issuer check debugging is enabled
238 it is used for status notification and is B<not> in itself an error.
239
240 =item B<X509_V_ERR_KEYUSAGE_NO_CERTSIGN:key usage does not include certificate signing>
241
242 the current candidate issuer certificate was rejected because its keyUsage
243 extension does not permit certificate signing. This is only set if issuer check
244 debugging is enabled it is used for status notification and is B<not> in itself
245 an error.
246
247 =item B<X509_V_ERR_INVALID_EXTENSION: invalid or inconsistent certificate extension>
248
249 A certificate extension had an invalid value (for example an incorrect
250 encoding) or some value inconsistent with other extensions.
251
252
253 =item B<X509_V_ERR_INVALID_POLICY_EXTENSION: invalid or inconsistent certificate policy extension>
254
255 A certificate policies extension had an invalid value (for example an incorrect
256 encoding) or some value inconsistent with other extensions. This error only
257 occurs if policy processing is enabled.
258
259 =item B<X509_V_ERR_NO_EXPLICIT_POLICY: no explicit policy>
260
261 The verification flags were set to require and explicit policy but none was
262 present.
263
264 =item B<X509_V_ERR_DIFFERENT_CRL_SCOPE: Different CRL scope>
265
266 The only CRLs that could be found did not match the scope of the certificate.
267
268 =item B<X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: Unsupported extension feature>
269
270 Some feature of a certificate extension is not supported. Unused.
271
272 =item B<X509_V_ERR_PERMITTED_VIOLATION: permitted subtree violation>
273
274 A name constraint violation occurred in the permitted subtrees.
275
276 =item B<X509_V_ERR_EXCLUDED_VIOLATION: excluded subtree violation>
277
278 A name constraint violation occurred in the excluded subtrees.
279
280 =item B<X509_V_ERR_SUBTREE_MINMAX: name constraints minimum and maximum not supported>
281
282 A certificate name constraints extension included a minimum or maximum field:
283 this is not supported.
284
285 =item B<X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE: unsupported name constraint type>
286
287 An unsupported name constraint type was encountered. OpenSSL currently only
288 supports directory name, DNS name, email and URI types.
289
290 =item B<X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX: unsupported or invalid name constraint syntax>
291
292 The format of the name constraint is not recognised: for example an email
293 address format of a form not mentioned in RFC3280. This could be caused by
294 a garbage extension or some new feature not currently supported.
295
296 =item B<X509_V_ERR_CRL_PATH_VALIDATION_ERROR: CRL path validation error>
297
298 An error occurred when attempting to verify the CRL path. This error can only
299 happen if extended CRL checking is enabled.
300
301 =item B<X509_V_ERR_APPLICATION_VERIFICATION: application verification failure>
302
303 an application specific error. This will never be returned unless explicitly
304 set by an application.
305
306 =back
307
308 =head1 NOTES
309
310 The above functions should be used instead of directly referencing the fields
311 in the B<X509_VERIFY_CTX> structure.
312
313 In versions of OpenSSL before 1.0 the current certificate returned by
314 X509_STORE_CTX_get_current_cert() was never B<NULL>. Applications should
315 check the return value before printing out any debugging information relating
316 to the current certificate.
317
318 If an unrecognised error code is passed to X509_verify_cert_error_string() the
319 numerical value of the unknown code is returned in a static buffer. This is not
320 thread safe but will never happen unless an invalid code is passed.
321
322 =head1 SEE ALSO
323
324 L<X509_verify_cert(3)>,
325 L<X509_up_ref(3)>,
326 L<X509_free(3)>.
327
328 =head1 COPYRIGHT
329
330 Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved.
331
332 Licensed under the OpenSSL license (the "License").  You may not use
333 this file except in compliance with the License.  You can obtain a copy
334 in the file LICENSE in the source distribution or at
335 L<https://www.openssl.org/source/license.html>.
336
337 =cut