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
14 #include <openssl/x509.h>
16 int X509_STORE_CTX_get_error(const 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(const 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(const 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(const X509_STORE_CTX *ctx);
24 STACK_OF(X509) *X509_STORE_CTX_get1_chain(const X509_STORE_CTX *ctx);
26 const char *X509_verify_cert_error_string(long n);
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.
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.
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
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.
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.
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.
52 X509_STORE_CTX_set_current_cert() sets the certificate B<x> in B<ctx> which
54 This value is not intended to remain valid for very long, and remains owned by
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
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
64 X509_STORE_CTX_get0_cert() retrieves an internal pointer to the
65 certificate being verified by the B<ctx>.
67 X509_STORE_CTX_get1_chain() returns a complete validate chain if a previous
68 call to X509_verify_cert() is successful. If the call to X509_verify_cert()
69 is B<not> successful the returned chain may be incomplete or invalid. The
70 returned chain persists after the B<ctx> structure is freed, when it is
71 no longer needed it should be free up using:
73 sk_X509_pop_free(chain, X509_free);
75 X509_verify_cert_error_string() returns a human readable error string for
76 verification error B<n>.
80 X509_STORE_CTX_get_error() returns B<X509_V_OK> or an error code.
82 X509_STORE_CTX_get_error_depth() returns a non-negative error depth.
84 X509_STORE_CTX_get_current_cert() returns the certificate which caused the
85 error or B<NULL> if no certificate is relevant to the error.
87 X509_verify_cert_error_string() returns a human readable error string for
88 verification error B<n>.
92 A list of error codes and messages is shown below. Some of the
93 error codes are defined but currently never returned: these are described as
98 =item B<X509_V_OK: ok>
100 The operation was successful.
102 =item B<X509_V_ERR_UNSPECIFIED: unspecified certificate verification error>
104 Unspecified error; should not happen.
106 =item B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate>
108 The issuer certificate of a locally looked up certificate could not be found.
109 This normally means the list of trusted certificates is not complete.
111 =item B<X509_V_ERR_UNABLE_TO_GET_CRL: unable to get certificate CRL>
113 The CRL of a certificate could not be found.
115 =item B<X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature>
117 The certificate signature could not be decrypted. This means that the actual
118 signature value could not be determined rather than it not matching the
119 expected value, this is only meaningful for RSA keys.
121 =item B<X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature>
123 The CRL signature could not be decrypted: this means that the actual signature
124 value could not be determined rather than it not matching the expected value.
127 =item B<X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key>
129 The public key in the certificate C<SubjectPublicKeyInfo> field could
132 =item B<X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure>
134 The signature of the certificate is invalid.
136 =item B<X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure>
138 The signature of the certificate is invalid.
140 =item B<X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid>
142 The certificate is not yet valid: the C<notBefore> date is after the
145 =item B<X509_V_ERR_CERT_HAS_EXPIRED: certificate has expired>
147 The certificate has expired: that is the C<notAfter> date is before the
150 =item B<X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid>
152 The CRL is not yet valid.
154 =item B<X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired>
158 =item B<X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field>
160 The certificate B<notBefore> field contains an invalid time.
162 =item B<X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field>
164 The certificate B<notAfter> field contains an invalid time.
166 =item B<X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field>
168 The CRL B<lastUpdate> field contains an invalid time.
170 =item B<X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field>
172 The CRL B<nextUpdate> field contains an invalid time.
174 =item B<X509_V_ERR_OUT_OF_MEM: out of memory>
176 An error occurred trying to allocate memory.
178 =item B<X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate>
180 The passed certificate is self-signed and the same certificate cannot be found
181 in the list of trusted certificates.
183 =item B<X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain>
185 The certificate chain could be built up using the untrusted certificates but
186 the root could not be found locally.
188 =item B<X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate>
190 The issuer certificate could not be found: this occurs if the issuer certificate
191 of an untrusted certificate cannot be found.
193 =item B<X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate>
195 No signatures could be verified because the chain contains only one certificate
196 and it is not self signed.
198 =item B<X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long>
200 The certificate chain length is greater than the supplied maximum depth. Unused.
202 =item B<X509_V_ERR_CERT_REVOKED: certificate revoked>
204 The certificate has been revoked.
206 =item B<X509_V_ERR_INVALID_CA: invalid CA certificate>
208 A CA certificate is invalid. Either it is not a CA or its extensions are not
209 consistent with the supplied purpose.
211 =item B<X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded>
213 The basicConstraints path-length parameter has been exceeded.
215 =item B<X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose>
217 The supplied certificate cannot be used for the specified purpose.
219 =item B<X509_V_ERR_CERT_UNTRUSTED: certificate not trusted>
221 The root CA is not marked as trusted for the specified purpose.
223 =item B<X509_V_ERR_CERT_REJECTED: certificate rejected>
225 The root CA is marked to reject the specified purpose.
227 =item B<X509_V_ERR_SUBJECT_ISSUER_MISMATCH: subject issuer mismatch>
229 The current candidate issuer certificate was rejected because its subject name
230 did not match the issuer name of the current certificate.
232 =item B<X509_V_ERR_AKID_SKID_MISMATCH: authority and subject key identifier mismatch>
234 The current candidate issuer certificate was rejected because its subject key
235 identifier was present and did not match the authority key identifier current
237 Not used as of OpenSSL 1.1.0.
239 =item B<X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: authority and issuer serial number mismatch>
241 The current candidate issuer certificate was rejected because its issuer name
242 and serial number was present and did not match the authority key identifier of
243 the current certificate.
244 Not used as of OpenSSL 1.1.0.
246 =item B<X509_V_ERR_KEYUSAGE_NO_CERTSIGN:key usage does not include certificate signing>
248 The current candidate issuer certificate was rejected because its B<keyUsage>
249 extension does not permit certificate signing.
250 Not used as of OpenSSL 1.1.0.
252 =item B<X509_V_ERR_INVALID_EXTENSION: invalid or inconsistent certificate extension>
254 A certificate extension had an invalid value (for example an incorrect
255 encoding) or some value inconsistent with other extensions.
257 =item B<X509_V_ERR_INVALID_POLICY_EXTENSION: invalid or inconsistent certificate policy extension>
259 A certificate policies extension had an invalid value (for example an incorrect
260 encoding) or some value inconsistent with other extensions. This error only
261 occurs if policy processing is enabled.
263 =item B<X509_V_ERR_NO_EXPLICIT_POLICY: no explicit policy>
265 The verification flags were set to require and explicit policy but none was
268 =item B<X509_V_ERR_DIFFERENT_CRL_SCOPE: Different CRL scope>
270 The only CRLs that could be found did not match the scope of the certificate.
272 =item B<X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: Unsupported extension feature>
274 Some feature of a certificate extension is not supported. Unused.
276 =item B<X509_V_ERR_PERMITTED_VIOLATION: permitted subtree violation>
278 A name constraint violation occurred in the permitted subtrees.
280 =item B<X509_V_ERR_EXCLUDED_VIOLATION: excluded subtree violation>
282 A name constraint violation occurred in the excluded subtrees.
284 =item B<X509_V_ERR_SUBTREE_MINMAX: name constraints minimum and maximum not supported>
286 A certificate name constraints extension included a minimum or maximum field:
287 this is not supported.
289 =item B<X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE: unsupported name constraint type>
291 An unsupported name constraint type was encountered. OpenSSL currently only
292 supports directory name, DNS name, email and URI types.
294 =item B<X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX: unsupported or invalid name constraint syntax>
296 The format of the name constraint is not recognised: for example an email
297 address format of a form not mentioned in RFC3280. This could be caused by
298 a garbage extension or some new feature not currently supported.
300 =item B<X509_V_ERR_CRL_PATH_VALIDATION_ERROR: CRL path validation error>
302 An error occurred when attempting to verify the CRL path. This error can only
303 happen if extended CRL checking is enabled.
305 =item B<X509_V_ERR_APPLICATION_VERIFICATION: application verification failure>
307 An application specific error. This will never be returned unless explicitly
308 set by an application callback.
310 =item B<X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER: unable to get CRL issuer certificate>
312 Unable to get CRL issuer certificate.
314 =item B<X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: unhandled critical extension>
316 Unhandled critical extension.
318 =item B<X509_V_ERR_KEYUSAGE_NO_CRL_SIGN: key usage does not include CRL signing>
320 Key usage does not include CRL signing.
322 =item B<X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION: unhandled critical CRL extension>
324 Unhandled critical CRL extension.
326 =item B<X509_V_ERR_INVALID_NON_CA: invalid non-CA certificate (has CA markings)>
328 Invalid non-CA certificate has CA markings.
330 =item B<X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED: proxy path length contraint exceeded>
332 Proxy path length constraint exceeded.
334 =item B<X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE: key usage does not include digital signature>
336 Key usage does not include digital signature, and therefore cannot sign
339 =item B<X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED: proxy certificates not allowed, please set the appropriate flag>
341 Proxy certificates not allowed unless the B<-allow_proxy_certs> option is used.
343 =item B<X509_V_ERR_UNNESTED_RESOURCE: RFC 3779 resource not subset of parent's resrouces>
345 See RFC 3779 for details.
347 =item B<X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: unsupported or invalid name syntax>
349 Unsupported or invalid name syntax.
351 =item B<X509_V_ERR_PATH_LOOP: path loop>
355 =item B<X509_V_ERR_HOSTNAME_MISMATCH: hostname mismatch>
359 =item B<X509_V_ERR_EMAIL_MISMATCH: email address mismatch>
361 Email address mismatch.
363 =item B<X509_V_ERR_IP_ADDRESS_MISMATCH: IP address mismatch>
367 =item B<X509_V_ERR_DANE_NO_MATCH: no matching DANE TLSA records>
369 DANE TLSA authentication is enabled, but no TLSA records matched the
371 This error is only possible in L<openssl-s_client(1)>.
373 =item B<X509_V_ERR_EE_KEY_TOO_SMALL: EE certificate key too weak>
375 EE certificate key too weak.
377 =item B<X509_ERR_CA_KEY_TOO_SMALL: CA certificate key too weak>
379 CA certificate key too weak.
381 =item B<X509_ERR_CA_MD_TOO_WEAK: CA signature digest algorithm too weak>
383 CA signature digest algorithm too weak.
385 =item B<X509_V_ERR_INVALID_CALL: invalid certificate verification context>
387 invalid certificate verification context.
389 =item B<X509_V_ERR_STORE_LOOKUP: issuer certificate lookup error>
391 Issuer certificate lookup error.
393 =item B<X509_V_ERR_NO_VALID_SCTS: certificate transparency required, but no valid SCTs found>
395 Certificate Transparency required, but no valid SCTs found.
397 =item B<X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION: proxy subject name violation>
399 Proxy subject name violation.
401 =item B<X509_V_ERR_OCSP_VERIFY_NEEDED: OCSP verification needed>
403 Returned by the verify callback to indicate an OCSP verification is needed.
405 =item B<X509_V_ERR_OCSP_VERIFY_FAILED: OCSP verification failed>
407 Returned by the verify callback to indicate OCSP verification failed.
409 =item B<X509_V_ERR_OCSP_CERT_UNKNOWN: OCSP unknown cert>
411 Returned by the verify callback to indicate that the certificate is not
412 recognized by the OCSP responder.
414 =item B<509_V_ERROR_NO_ISSUER_PUBLI_KEY, issuer certificate doesn't have a public key>
416 The issuer certificate does not have a public key.
418 =item B<X509_V_ERROR_SIGNATURE_ALGORITHM_MISMATCH, Subject signature algorithm and issuer public key algoritm mismatch>
420 The issuer's public key is not of the type required by the signature in
421 the subject's certificate.
427 The above functions should be used instead of directly referencing the fields
428 in the B<X509_VERIFY_CTX> structure.
430 In versions of OpenSSL before 1.0 the current certificate returned by
431 X509_STORE_CTX_get_current_cert() was never B<NULL>. Applications should
432 check the return value before printing out any debugging information relating
433 to the current certificate.
435 If an unrecognised error code is passed to X509_verify_cert_error_string() the
436 numerical value of the unknown code is returned in a static buffer. This is not
437 thread safe but will never happen unless an invalid code is passed.
441 L<X509_verify_cert(3)>,
447 Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
449 Licensed under the Apache License 2.0 (the "License"). You may not use
450 this file except in compliance with the License. You can obtain a copy
451 in the file LICENSE in the source distribution or at
452 L<https://www.openssl.org/source/license.html>.