LIBRESSL-X509_STORE_CTX_GET_ERROR(3)
π X509_STORE_CTX_GET_ERROR(3) β get or set certificate verification status information
okay so first things first, bestie: this whole page lives in the Library Functions Manual and it's all about libcrypto, k? It's a big ol' grab bag of getters and setters that let you peek at (or poke at) the status info from a certificate verification run. Buckle up, there's a lot of functions but like... in a good way π
β¨ NAME β¨
The full squad, in order, no cap:
X509_STORE_CTX_get_errorX509_STORE_CTX_set_errorX509_STORE_CTX_get_error_depthX509_STORE_CTX_set_error_depthX509_STORE_CTX_get_current_certX509_STORE_CTX_set_current_certX509_STORE_CTX_get0_current_issuerX509_STORE_CTX_get0_current_crlX509_STORE_CTX_get0_parent_ctxX509_STORE_CTX_get_num_untrustedX509_STORE_CTX_get0_chainX509_STORE_CTX_get_chainX509_STORE_CTX_get1_chainX509_STORE_CTX_set0_verified_chainX509_verify_cert_error_string
...and together they get or set certificate verification status information. iconic π
#include <openssl/x509_vfy.h>
πΈ SYNOPSIS πΈ
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);
and then a whole separate include for this last one:
#include <openssl/x509.h>
const char *
X509_verify_cert_error_string(long n);
π¦ DESCRIPTION π¦
okay so like, most of these are the "what just happened" functions β you call them after X509_verify_cert(3) to inspect the status info from certificate verification. Some of them you can also call from inside a verification callback, to figure out the nature of an error while it's happening. very useful, very demure β¨
the error itself
X509_STORE_CTX_get_error()β returns the error code ofctx. peek the ERROR CODES section for the full rundown of every single one, no skipping π₯X509_STORE_CTX_set_error()β sets the error code ofctxtos. for example, a verification callback might use this to set an error based on some additional checks it did.
how deep does it go
X509_STORE_CTX_get_error_depth()β returns the depth of the error. it's a non-negative integer representing where in the certificate chain the error occurred.0? that's the end entity certificate.1? that's the certificate which signed the end entity certificate. and so on, you get the vibe πX509_STORE_CTX_set_error_depth()β sets the error depth. use it in combination withX509_STORE_CTX_set_error()to set the depth at which an error condition was detected.
which cert tho
X509_STORE_CTX_get_current_cert()β returns the certificate inctxwhich caused the error, orNULLif no certificate is relevant.X509_STORE_CTX_set_current_cert()β sets the certificate which caused the error inctxto the givencert. bestie, listen: this value is not intended to remain valid for very long, and it remains owned by the caller. it may be examined by a verification callback invoked to handle each error encountered during chain verification, and it's no longer required after such a callback. if a callback wants to save the certificate for use after it returns, it needs to increment its reference count viaX509_up_ref(3). once such a saved certificate is no longer needed, it can be freed withX509_free(3).π«Ά (well,X509_free(3)β you know what I mean)
issuer + CRL drama
X509_STORE_CTX_get0_current_issuer()β returns the certificate that caused issuer validation to fail, orNULLif no CA certificate is relevant.X509_STORE_CTX_get0_current_crl()β returns the certificate revocation list that caused CRL checking to fail, orNULLif no CRL is relevant.
the parent context plot twist π
so 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. and if you call X509_STORE_CTX_get0_parent_ctx() on that temporary object, you get a pointer to the original certification path validation context. main character energy.
this may be useful in callback functions called from X509_verify_cert(3) or from its subroutines, to find out whether the callback is being called from the path validation of the target certificate or from the path validation of a related CRL issuer certificate β and if it's the latter, what the target certificate is. iykyk π
chain hangout
X509_STORE_CTX_get0_chain()β returns an internal pointer to a complete validated chain of certificates if a previous call toX509_verify_cert(3)was successful. if that call was not successful, the returned chain may be incomplete or invalid. β οΈX509_STORE_CTX_get_chain()β a deprecated alias ofX509_STORE_CTX_get0_chain(), periodt.X509_STORE_CTX_get1_chain()β returns a deep copy of the same chain, which persists even after thectxstructure is freed. when it's no longer needed, it should be freed usingsk_X509_pop_free(chain, X509_free).X509_STORE_CTX_set0_verified_chain()β frees the validated chain generated by a previous call toX509_verify_cert(3), if any, and replaces it with the givenchain. ownership of the chain is transferred to thectx, so it should not be freed by the caller. don't do it, bestie π
the error string
X509_verify_cert_error_string()β returns a human readable error string for verification errorn. slay, readable output.
π¨ real talk: the above functions should be used instead of directly referencing the fields in the X509_VERIFY_CTX structure. like, don't touch the internals, use the good functions, k?
π history lesson: in versions of OpenSSL before 1.0, the current certificate returned byX509_STORE_CTX_get_current_cert()was neverNULL. so applications should check the return value before printing out any debugging information relating to the current certificate.
π and if an unrecognised error code is passed toX509_verify_cert_error_string(), the string"Unknown certificate verification error"is returned. this should never happen unless an invalid code is passed. literally should not be possible unless something's gone wrong.
π RETURN VALUES π
X509_STORE_CTX_get_error()returnsX509_V_OKor 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(), andX509_STORE_CTX_get0_current_crl()return the object which caused the error, orNULLif no object of the requested kind is relevant to the error.X509_STORE_CTX_get0_parent_ctx()returns the parent context, orNULLifctxis 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 toX509_verify_cert(3).X509_STORE_CTX_get0_chain(),X509_STORE_CTX_get_chain(), andX509_STORE_CTX_get1_chain()return a pointer to a stack of certificates, orNULLif an error occurs.X509_verify_cert_error_string()returns a human readable error string for verification errorn.
β¨ ERROR CODES β¨
Okay bestie, hereβs the full error-code lineup π. Some of these are defined but currently never returned β those are marked βunusedβ below. Do not come for me, Iβm just the messenger π«Ά.
X509_V_OKβokβ the operation was successful. Slay. β¨X509_V_ERR_UNSPECIFIEDβUnspecified certificate verification errorβ an error popped up during certificate verification and the internal routines failed to set a more specific error. Not them being vague π.X509_V_ERR_UNABLE_TO_GET_ISSUER_CERTβunable to get issuer certificateβ the issuer certificate of a locally looked up certificate could not be found. This normally means the list of trusted certificates is not complete. π₯²X509_V_ERR_UNABLE_TO_GET_CRLβunable to get certificate CRLβ the CRL of a certificate could not be found.X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATUREβunable to decrypt certificate's signatureβ the certificate signature could not be decrypted. This means the actual signature value could not be determined rather than it not matching the expected value. This is only meaningful for RSA keys. πX509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATUREβunable to decrypt CRL's signatureβ the CRL signature could not be decrypted: this means the actual signature value could not be determined rather than it not matching the expected value. Unused. πX509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEYβunable to decode issuer public keyβ the public key in the certificate SubjectPublicKeyInfo could not be read.X509_V_ERR_CERT_SIGNATURE_FAILUREβcertificate signature failureβ the signature of the certificate is invalid. Not iconic. πX509_V_ERR_CRL_SIGNATURE_FAILUREβCRL signature failureβ the signature of the CRL is invalid.X509_V_ERR_CERT_NOT_YET_VALIDβcertificate is not yet validβ the certificate is not yet valid: thenotBeforedate is after the current time. Early bird behavior, honestly. β°X509_V_ERR_CERT_HAS_EXPIREDβcertificate has expiredβ the certificate has expired: that is thenotAfterdate is before the current time. RIP boo πͺ¦.X509_V_ERR_CRL_NOT_YET_VALIDβCRL is not yet validβ the CRL is not yet valid.X509_V_ERR_CRL_HAS_EXPIREDβCRL has expiredβ the CRL has expired.X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELDβformat error in certificate's notBefore fieldβ the certificatenotBeforefield contains an invalid time.X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELDβformat error in certificate's notAfter fieldβ the certificatenotAfterfield contains an invalid time.X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELDβformat error in CRL's lastUpdate fieldβ the CRLthisUpdatefield (sic!) contains an invalid time. Both the name of the error constant and the text of the error message give a wrong name for the field that contains the problem. Not the typo doing a little chaos π.X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELDβformat error in CRL's nextUpdate fieldβ the CRLnextUpdatefield contains an invalid time.X509_V_ERR_OUT_OF_MEMβout of memoryβ an error occurred trying to allocate memory. This should never happen. Bestie if this happens weβre in our flop era π.X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERTβself signed certificateβ the passed certificate is self signed and the same certificate cannot be found in the list of trusted certificates.X509_V_ERR_SELF_SIGNED_CERT_IN_CHAINβself signed certificate in certificate chainβ the certificate chain could be built up using the untrusted certificates but the root could not be found locally.X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLYβunable to get local issuer certificateβ the issuer certificate could not be found: this occurs if the issuer certificate of an untrusted certificate cannot be found.X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATUREβunable to verify the first certificateβ no signatures could be verified because the chain contains only one certificate and it is not self signed. πX509_V_ERR_CERT_CHAIN_TOO_LONGβcertificate chain too longβ the certificate chain length is greater than the supplied maximum depth. Itβs giving βtoo muchβ π .X509_V_ERR_CERT_REVOKEDβcertificate revokedβ the certificate has been revoked.X509_V_ERR_INVALID_CAβinvalid CA certificateβ a CA certificate is invalid. Either it is not a CA or its extensions are not consistent with the supplied purpose.X509_V_ERR_PATH_LENGTH_EXCEEDEDβpath length constraint exceededβ thebasicConstraintspath-length parameter has been exceeded.X509_V_ERR_INVALID_PURPOSEβunsupported certificate purposeβ the supplied certificate cannot be used for the specified purpose.X509_V_ERR_CERT_UNTRUSTEDβcertificate not trustedβ the root CA is not marked as trusted for the specified purpose.X509_V_ERR_CERT_REJECTEDβcertificate rejectedβ the root CA is marked to reject the specified purpose. Blocked and reported π«.X509_V_ERR_SUBJECT_ISSUER_MISMATCHβsubject issuer mismatchβ the current candidate issuer certificate was rejected because its subject name did not match the issuer name of the current certificate. This is only set if issuer check debugging is enabled; it is used for status notification and is not in itself an error.X509_V_ERR_AKID_SKID_MISMATCHβauthority and subject key identifier mismatchβ the current candidate issuer certificate was rejected because its subject key identifier was present and did not match the authority key identifier current certificate. This is only set if issuer check debugging is enabled; it is used for status notification and is not in itself an error.X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCHβauthority and issuer serial number mismatchβ the current candidate issuer certificate was rejected because its issuer name and serial number was present and did not match the authority key identifier of the current certificate. This is only set if issuer check debugging is enabled; it is used for status notification and is not in itself an error.X509_V_ERR_KEYUSAGE_NO_CERTSIGNβkey usage does not include certificate signingβ the current candidate issuer certificate was rejected because itskeyUsageextension does not permit certificate signing. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.X509_V_ERR_UNABLE_TO_GET_CRL_ISSUERβunable to get CRL issuer certificateβ the CRLβs issuer could not be found: there is no alternative CRL issuer set onctxand the last certificate in the chain is not self signed.X509_V_ERR_UNHANDLED_CRITICAL_EXTENSIONβunhandled critical extensionβ the certificate contains a critical extension that is unsupported by the library. The library is like βI donβt know herβ π.X509_V_ERR_KEYUSAGE_NO_CRL_SIGNβkey usage does not include CRL signingβ the CRL issuer has akeyUsageextension with unsetcRLSignbit.X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSIONβunhandled critical CRL extensionβ the CRL contains a critical extension that is unsupported by the library.X509_V_ERR_INVALID_EXTENSIONβinvalid or inconsistent certificate extensionβ a certificate extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions.X509_V_ERR_INVALID_POLICY_EXTENSIONβinvalid or inconsistent certificate policy extensionβ a certificate policies extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions. This error only occurs if policy processing is enabled.X509_V_ERR_NO_EXPLICIT_POLICYβno explicit policyβ the verification flags were set to require an explicit policy but none was present.X509_V_ERR_DIFFERENT_CRL_SCOPEβdifferent CRL scopeβ the only CRLs that could be found did not match the scope of the certificate.X509_V_ERR_UNSUPPORTED_EXTENSION_FEATUREβunsupported extension featureβ some feature of a certificate extension is not supported. Unused. πX509_V_ERR_UNNESTED_RESOURCEβRFC 3779 resource not subset of parent's resourcesβ when walking up a certificate chain, all resources specified in RFC 3779 extensions must be contained in the resources delegated in the issuerβs RFC 3779 extensions. The error indicates that this is not the case or that the trust anchor has inheritance.X509_V_ERR_PERMITTED_VIOLATIONβpermitted subtree violationβ a name constraint violation occurred in the permitted subtrees.X509_V_ERR_EXCLUDED_VIOLATIONβexcluded subtree violationβ a name constraint violation occurred in the excluded subtrees.X509_V_ERR_SUBTREE_MINMAXβname constraints minimum and maximum not supportedβ a certificate name constraints extension included a minimum or maximum field: this is not supported.X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPEβunsupported name constraint typeβ an unsupported name constraint type was encountered. OpenSSL currently only supports directory name, DNS name, email and URI types.X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAXβunsupported or invalid name constraint syntaxβ the format of the name constraint is not recognised: for example an email address format of a form not mentioned in RFC 3280. This could be caused by a garbage extension or some new feature not currently supported.X509_V_ERR_CRL_PATH_VALIDATION_ERRORβCRL path validation errorβ an error occurred when attempting to verify the CRL path. This error can only happen if extended CRL checking is enabled.X509_V_ERR_APPLICATION_VERIFICATIONβapplication verification failureβ an application specific error. This will never be returned unless explicitly set by an application.
π SEE ALSO π
Go peek at these besties when youβre done here π«Ά:
X509_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)
π HISTORY π
okay so story time, bestie, because the lore here is actually iconic π
The OG squad β 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. like, they've been serving since before most of us could read π«Ά
Then X509_STORE_CTX_get1_chain() pulled up, first appeared in OpenSSL 0.9.5, and has been available since OpenBSD 2.7. a whole era later, ngl β¨
X509_STORE_CTX_get0_current_issuer(), X509_STORE_CTX_get0_current_crl(), and X509_STORE_CTX_get0_parent_ctx() are the OpenSSL 1.0.0 baddies β first appeared there, and have been available since OpenBSD 4.9. glow-up fr πΈ
X509_STORE_CTX_get0_chain() came through in OpenSSL 1.1.0 and has been available since OpenBSD 6.3. we love a late arrival that still ate π
And the newest main characters: 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. fresh out the gate and already iconic π
and that's the whole page, bestie!! π this little masterpiece lives in the Debian edition of the manual, dated August 29, 2026 β screenshot it, cite it, put it on your fridge, whatever, it's yours now ππ¦
π¦ where this page comes from
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2009, 2016 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms