| X509_STORE_CTX_GET_ERROR(3) | Library Functions Manual | X509_STORE_CTX_GET_ERROR(3) |
X509_STORE_CTX_get_error,
X509_STORE_CTX_set_error,
X509_STORE_CTX_get_error_depth,
X509_STORE_CTX_set_error_depth,
X509_STORE_CTX_get_current_cert,
X509_STORE_CTX_set_current_cert,
X509_STORE_CTX_get0_current_issuer,
X509_STORE_CTX_get0_current_crl,
X509_STORE_CTX_get0_parent_ctx,
X509_STORE_CTX_get_num_untrusted,
X509_STORE_CTX_get0_chain,
X509_STORE_CTX_get_chain,
X509_STORE_CTX_get1_chain,
X509_STORE_CTX_set0_verified_chain,
X509_verify_cert_error_string —
get or set certificate verification status
information
#include
<openssl/x509_vfy.h>
int
X509_STORE_CTX_get_error(X509_STORE_CTX
*ctx);
void
X509_STORE_CTX_set_error(X509_STORE_CTX
*ctx, int s);
int
X509_STORE_CTX_get_error_depth(X509_STORE_CTX
*ctx);
void
X509_STORE_CTX_set_error_depth(X509_STORE_CTX
*ctx, int depth);
X509 *
X509_STORE_CTX_get_current_cert(X509_STORE_CTX
*ctx);
void
X509_STORE_CTX_set_current_cert(X509_STORE_CTX
*ctx, X509 *cert);
X509 *
X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX
*ctx);
X509_CRL *
X509_STORE_CTX_get0_current_crl(X509_STORE_CTX
*ctx);
X509_STORE_CTX *
X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX
*ctx);
int
X509_STORE_CTX_get_num_untrusted(X509_STORE_CTX
*ctx);
STACK_OF(X509) *
X509_STORE_CTX_get0_chain(X509_STORE_CTX
*ctx);
STACK_OF(X509) *
X509_STORE_CTX_get_chain(X509_STORE_CTX
*ctx);
STACK_OF(X509) *
X509_STORE_CTX_get1_chain(X509_STORE_CTX
*ctx);
void
X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX
*ctx, STACK_OF(X509) *chain);
#include
<openssl/x509.h>
const char *
X509_verify_cert_error_string(long
n);
Most of these functions are typically called after X509_verify_cert(3) to inspect status information related to certificate verification. Some may also be called in a verification callback to determine the nature of an error.
X509_STORE_CTX_get_error()
returns the error code of ctx. See the
ERROR
CODES section for a full description of all error codes.
X509_STORE_CTX_set_error()
sets the error code of ctx to s.
For example it might be used in a verification callback to set an error
based on additional checks.
X509_STORE_CTX_get_error_depth()
returns the depth of the error. This is a non-negative integer representing
where in the certificate chain the error occurred. If it is zero, it
occurred in the end entity certificate, one if it is the certificate which
signed the end entity certificate, and so on.
X509_STORE_CTX_set_error_depth()
sets the error depth. This can be used in combination with
X509_STORE_CTX_set_error() to set the depth at which
an error condition was detected.
X509_STORE_CTX_get_current_cert()
returns the certificate in ctx which caused the error
or NULL if no certificate is relevant.
X509_STORE_CTX_set_current_cert()
sets the certificate which caused the error in ctx to
the given cert. This value is not intended to remain
valid for very long, and remains owned by the caller. It may be examined by
a verification callback invoked to handle each error encountered during
chain verification and is no longer required after such a callback. If a
callback wishes the save the certificate for use after it returns, it needs
to increment its reference count via
X509_up_ref(3). Once such a
saved certificate is no longer needed, it can be freed with
X509_free(3).
X509_STORE_CTX_get0_current_issuer()
returns the certificate that caused issuer validation to fail or
NULL if no CA certificate is relevant.
X509_STORE_CTX_get0_current_crl()
returns the certificate revocation list that caused CRL checking to fail or
NULL if no CRL is relevant.
When, during certification
path validation, the need arises to check the validity of the certification
path of a CRL issuer certificate, the library creates a new, temporary
X509_STORE_CTX object. If
X509_STORE_CTX_get0_parent_ctx()
is called on that temporary object, a pointer to the original certification
path validation context is returned. This may be useful in callback
functions called from
X509_verify_cert(3) or
from its subroutines to find out whether the callback is called from the
path validation of the target certificate or from the path validation of a
related CRL issuer certificate, and if the latter, what the target
certificate is.
X509_STORE_CTX_get0_chain()
returns an internal pointer to a complete validate chain if a previous call
to X509_verify_cert(3)
was successful. If the call to
X509_verify_cert(3) was
not successful, the returned chain may be incomplete or invalid.
X509_STORE_CTX_get_chain()
is a deprecated alias of
X509_STORE_CTX_get0_chain().
X509_STORE_CTX_get1_chain()
returns a deep copy of the same chain which persists even after the
ctx structure is freed. When it is no longer needed,
it should be freed using
sk_X509_pop_free(chain,
X509_free).
X509_STORE_CTX_set0_verified_chain()
frees the validate chain generated by if a previous call to
X509_verify_cert(3), if
any, and replaces it with the given chain. Ownership
of the chain is transferred to the
ctx, so it should not be freed by the caller.
X509_verify_cert_error_string()
returns a human readable error string for verification error
n.
The above functions should be used instead of directly referencing the fields in the X509_VERIFY_CTX structure.
In versions of OpenSSL
before 1.0, the current certificate returned by
X509_STORE_CTX_get_current_cert()
was never NULL. Applications should check the return
value before printing out any debugging information relating to the current
certificate.
If an unrecognised error code
is passed to
X509_verify_cert_error_string(),
"Unknown certificate verification error" is returned. This should
never happen unless an invalid code is passed.
X509_STORE_CTX_get_error() returns
X509_V_OK or an error code.
X509_STORE_CTX_get_error_depth() returns a
non-negative error depth.
X509_STORE_CTX_get_current_cert(),
X509_STORE_CTX_get0_current_issuer(), and
X509_STORE_CTX_get0_current_crl() return the object
which caused the error or NULL if no object of the
requested kind is relevant to the error.
X509_STORE_CTX_get0_parent_ctx() returns
the parent context or NULL if
ctx is not a temporary child context used for path
validation of a CRL issuer certificate.
X509_STORE_CTX_get_num_untrusted() returns
the number of untrusted certificates that were used in building the chain
during a call to
X509_verify_cert(3).
X509_STORE_CTX_get0_chain(),
X509_STORE_CTX_get_chain(), and
X509_STORE_CTX_get1_chain() return a pointer to a
stack of certificates or NULL if an error
occurs.
X509_verify_cert_error_string() returns a
human readable error string for verification error
n.
A list of error codes and messages is shown below. Some of the error codes are defined but currently never returned: these are described as "unused".
X509_V_OK:
okX509_V_ERR_UNSPECIFIED:
Unspecified certificate verification errorX509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
unable to get issuer certificateX509_V_ERR_UNABLE_TO_GET_CRL:
unable to get certificate CRLX509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
unable to decrypt certificate's signatureX509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
unable to decrypt CRL's signatureX509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
unable to decode issuer public keyX509_V_ERR_CERT_SIGNATURE_FAILURE:
certificate signature failureX509_V_ERR_CRL_SIGNATURE_FAILURE:
CRL signature failureX509_V_ERR_CERT_NOT_YET_VALID:
certificate is not yet validX509_V_ERR_CERT_HAS_EXPIRED:
certificate has expiredX509_V_ERR_CRL_NOT_YET_VALID:
CRL is not yet validX509_V_ERR_CRL_HAS_EXPIRED:
CRL has expiredX509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
format error in certificate's notBefore fieldX509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
format error in certificate's notAfter fieldX509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
format error in CRL's lastUpdate fieldX509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
format error in CRL's nextUpdate fieldX509_V_ERR_OUT_OF_MEM:
out of memoryX509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
self signed certificateX509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
self signed certificate in certificate chainX509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
unable to get local issuer certificateX509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
unable to verify the first certificateX509_V_ERR_CERT_CHAIN_TOO_LONG:
certificate chain too longX509_V_ERR_CERT_REVOKED:
certificate revokedX509_V_ERR_INVALID_CA:
invalid CA certificateX509_V_ERR_PATH_LENGTH_EXCEEDED:
path length constraint exceededX509_V_ERR_INVALID_PURPOSE:
unsupported certificate purposeX509_V_ERR_CERT_UNTRUSTED:
certificate not trustedX509_V_ERR_CERT_REJECTED:
certificate rejectedX509_V_ERR_SUBJECT_ISSUER_MISMATCH:
subject issuer mismatchX509_V_ERR_AKID_SKID_MISMATCH:
authority and subject key identifier mismatchX509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
authority and issuer serial number mismatchX509_V_ERR_KEYUSAGE_NO_CERTSIGN:
key usage does not include certificate signingX509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
unable to get CRL issuer certificateX509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
unhandled critical extensionX509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
key usage does not include CRL signingX509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
unhandled critical CRL extensionX509_V_ERR_INVALID_EXTENSION:
invalid or inconsistent certificate extensionX509_V_ERR_INVALID_POLICY_EXTENSION:
invalid or inconsistent certificate policy
extensionX509_V_ERR_NO_EXPLICIT_POLICY:
no explicit policyX509_V_ERR_DIFFERENT_CRL_SCOPE:
different CRL scopeX509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE:
unsupported extension featureX509_V_ERR_UNNESTED_RESOURCE:
RFC 3779 resource not subset of parent's
resourcesX509_V_ERR_PERMITTED_VIOLATION:
permitted subtree violationX509_V_ERR_EXCLUDED_VIOLATION:
excluded subtree violationX509_V_ERR_SUBTREE_MINMAX:
name constraints minimum and maximum not
supportedX509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:
unsupported name constraint typeX509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX:
unsupported or invalid name constraint syntaxX509_V_ERR_CRL_PATH_VALIDATION_ERROR:
CRL path validation errorX509_V_ERR_APPLICATION_VERIFICATION:
application verification failureX509_STORE_CTX_new(3), X509_STORE_CTX_set_verify(3), X509_STORE_CTX_set_verify_cb(3), X509_STORE_set_verify_cb(3), X509_up_ref(3), X509_verify_cert(3)
X509_STORE_CTX_get_error(),
X509_STORE_CTX_set_error(),
X509_STORE_CTX_get_error_depth(),
X509_STORE_CTX_get_current_cert(),
X509_STORE_CTX_get_chain(), and
X509_verify_cert_error_string() first appeared in
SSLeay 0.8.0 and have been available since OpenBSD
2.4.
X509_STORE_CTX_get1_chain() first appeared
in OpenSSL 0.9.5 and has been available since OpenBSD
2.7.
X509_STORE_CTX_get0_current_issuer(),
X509_STORE_CTX_get0_current_crl(), and
X509_STORE_CTX_get0_parent_ctx() first appeared in
OpenSSL 1.0.0 and have been available since OpenBSD
4.9.
X509_STORE_CTX_get0_chain() first appeared
in OpenSSL 1.1.0 and has been available since OpenBSD
6.3.
X509_STORE_CTX_set_error_depth(),
X509_STORE_CTX_set_current_cert(),
X509_STORE_CTX_get_num_untrusted(), and
X509_STORE_CTX_set0_verified_chain() first appeared
in OpenSSL 1.1.0 and have been available since OpenBSD
7.1.
| June 6, 2023 | openbsd |