SSL_CTX_SET_...IFY_CALLBACK(3ossl)
π
SSL_CTX_SET_...IFY_CALLBACK β the 3ossl manual, bestie edition β¨
okay so this is the 3ossl page for SSL_CTX_set_cert_verify_callback, and it's genuinely one of those "small function, big consequences" situations. buckle up π
πΈ NAME πΈ
SSL_CTX_set_cert_verify_callback β set the peer certificate verification procedure. that's the whole vibe. π₯
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
int (*callback)(X509_STORE_CTX *, void *),
void *arg);
π DESCRIPTION π
SSL_CTX_set_cert_verify_callback() sets the verification callback function for ctx. and here's the inheritance moment: SSL objects created from ctx inherit whatever setting was valid at the time SSL_new(3) got called. no cap, that's how it works π«Ά
π¦ NOTES π¦
so when a peer certificate has been received during an SSL/TLS handshake, a verification function gets called regardless of the verification mode. like, always. main character energy π
if the application doesn't explicitly specify a verification callback function, the built-in verification function is used. and if a verification callback is specified via SSL_CTX_set_cert_verify_callback(), the supplied callback function is called instead, with the arguments:
callback(X509_STORE_CTX *x509_store_ctx, void *arg)
the arg argument is specified by the application when setting callback. and by setting callback to NULL, the default behaviour is restored. we love a reset button π
callback should return 1 to indicate verification success and 0 to indicate verification failure. in server mode, a return value of 0 leads to handshake failure. in client mode, the behaviour goes like this:
- All values, including
0, are ignored if the verification mode isSSL_VERIFY_NONE. - Otherwise, when the return value is less than or equal to
0, the handshake will fail.
okay now for the spicy part πΆοΈ in client mode, callback may also call the SSL_set_retry_verify(3) function on the SSL object set in the x509_store_ctx ex data (see SSL_get_ex_data_X509_STORE_CTX_idx(3)) and return 1. this would typically be done in case the certificate verification was not yet able to succeed. it makes the handshake suspend and return control to the calling application with SSL_ERROR_WANT_RETRY_VERIFY. the app can, for instance, fetch further certificates or cert status information needed for the verification. calling SSL_connect(3) again resumes the connection attempt by retrying the server certificate verification step. and this process may even be repeated if need be β it's giving "we'll get there when we get there" π
in any case, a viable verification result value must be reflected in the error member of x509_store_ctx, which can be done using X509_STORE_CTX_set_error(3). this is particularly important in case the callback allows the connection to continue (by returning 1). and note this, because it's lowkey huge: the verification status in the store context is a possibly durable indication of the chain's validity! π it gets recorded in the SSL session (and thus also in session tickets) and the validity of the originally presented chain is then visible on resumption, even though no chain is presented in that case. moreover, the calling application will be informed about the detailed result of the verification procedure and may elect to base further decisions on it. so likeβ¦ yeah, this matters fr fr π
within x509_store_ctx, callback has access to the verify_callback function set using SSL_CTX_set_verify(3).
β RETURN VALUES β
SSL_CTX_set_cert_verify_callback() does not return a value. that's it. nothing. void. iconic behaviour honestly π€·ββοΈ
π WARNINGS π
do not mix the verification callback described in this function with theverify_callbackfunction called during the verification process. the latter is set using theSSL_CTX_set_verify(3)family of functions. two different callbacks, two different jobs, do not confuse them bestie π
also: providing a complete verification procedure including certificate purpose settings etc is a complex task. the built-in procedure is quite powerful and in most cases it should be sufficient to modify its behaviour using the verify_callback function. like, don't rebuild the whole thing when you can just tweak it, yk? πΈ
π BUGS π
SSL_CTX_set_cert_verify_callback() does not provide diagnostic information. so when something goes wrongβ¦ it's giving silence π no details, no crumbs.
π SEE ALSO π
ssl(7)SSL_CTX_set_verify(3)X509_STORE_CTX_set_error(3)SSL_get_verify_result(3)SSL_set_retry_verify(3)SSL_CTX_load_verify_locations(3)
π COPYRIGHT π
Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the page!! π«Ά brought to you by OpenSSL 3.5.0, dated 2026-09-25 β mwah, go verify some certs responsibly bestie πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms