X509_STORE_CTX_get_error.pod 17 KB

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