SSL_CTX_SET_...IFY_CALLBACK(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… 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 is SSL_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 the verify_callback function called during the verification process. the latter is set using the SSL_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 🌈

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