SSL_CTX_SET_CLIENT_HELLO_CB(3ossl)
π SSL_CTX_SET_CLIENT_HELLO_CB π
okay so bestie, this is an OpenSSL manual page β specifically SSL_CTX_SET_CLIENT_HELLO_CB(3ossl) β and it's literally all about callback functions for early server-side ClientHello processing. yes the title is a mouthful, no I will not be pronouncing it out loud. β¨
π NAME π
SSL_CTX_set_client_hello_cb, SSL_client_hello_cb_fn, SSL_client_hello_isv2, SSL_client_hello_get0_legacy_version, SSL_client_hello_get0_random, SSL_client_hello_get0_session_id, SSL_client_hello_get0_ciphers, SSL_client_hello_get0_compression_methods, SSL_client_hello_get1_extensions_present, SSL_client_hello_get_extension_order, SSL_client_hello_get0_ext β callback functions for early server-side ClientHello processing π
like, that's the whole vibe: it's giving "get in on the handshake early."
πΈ SYNOPSIS πΈ
typedef int (*SSL_client_hello_cb_fn)(SSL *s, int *al, void *arg);
void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn *f,
void *arg);
int SSL_client_hello_isv2(SSL *s);
unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_compression_methods(SSL *s,
const unsigned char **out);
int SSL_client_hello_get1_extensions_present(SSL *s, int **out,
size_t *outlen);
int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts,
size_t *num_exts);
int SSL_client_hello_get0_ext(SSL *s, unsigned int type, const unsigned char **out,
size_t *outlen);
copy that exactly, no cap, don't retype it from memory bestie π
π¦ DESCRIPTION π¦
the main character: setting the callback
SSL_CTX_set_client_hello_cb() sets the callback function, and this iconic little function gets automatically called during the early stages of ClientHello processing on the server. the argument you supply when setting the callback gets passed right back to the callback at run time π«Ά
now, the rules of the group chat:
- a callback that returns failure (
0) will cause the connection to terminate, and callbacks returning failure should indicate what alert value is to be sent in thealparameter β οΈ - a callback may also return a negative value to suspend the handshake, and the handshake function will return immediately.
SSL_get_error(3)will returnSSL_ERROR_WANT_CLIENT_HELLO_CBto indicate that the handshake was suspended - it is the job of the ClientHello callback to store information about the state of the last call if needed to continue π
- on the next call into the handshake function, the ClientHello callback will be called again, and, if it returns success, normal handshake processing will continue from that point β¨
SSLv2 era (yes, really)
SSL_client_hello_isv2() indicates whether the ClientHello was carried in a SSLv2 record and is in the SSLv2 format. and the SSLv2 format has substantial differences from the normal SSLv3 format, including:
- using three bytes per cipher suite
- not allowing extensions
additionally, the SSLv2 format 'challenge' field is exposed via SSL_client_hello_get0_random(), padded to SSL3_RANDOM_SIZE bytes with zeros if needed.
for SSLv2 format ClientHellos, SSL_client_hello_get0_compression_methods() returns a dummy list that only includes the null compression method, since the SSLv2 format does not include a mechanism by which to negotiate compression. lowkey tragic but ok π
the get0 accessors
SSL_client_hello_get0_random(), SSL_client_hello_get0_session_id(), SSL_client_hello_get0_ciphers(), and SSL_client_hello_get0_compression_methods() provide access to the corresponding ClientHello fields, returning the field length and optionally setting an out pointer to the octets of that field.
extensions, one at a time
similarly, SSL_client_hello_get0_ext() provides access to individual extensions from the ClientHello on a per-extension basis. for the provided wire protocol extension type value, the extension value and length are returned in the output parameters (if present). slay β¨
SSL_client_hello_get1_extensions_present()
this one can be used prior to SSL_client_hello_get0_ext(), to determine which extensions are present in the ClientHello before querying for them. so like, look before you leap, bestie.
deets:
- the
outandoutlenparameters are both required - on success the caller must release the storage allocated for
*outusingOPENSSL_free()π¨ (this is the "not me forgetting to free" moment) - the contents of
*outis an array of integers holding the numerical value of the TLS extension types in the order they appear in the ClientHello *outlencontains the number of elements in the array- in situations when the ClientHello has no extensions, the function will return success with
*outset toNULLand*outlenset to0 - note that
SSL_client_hello_get1_extensions_present()returns only recognised extensions; therefore, unrecognised (including GREASE) extensions will not appear in the output π
SSL_client_hello_get_extension_order()
similar to SSL_client_hello_get1_extensions_present(), but without internal memory allocation π so here's the flow:
- when called with
extsset toNULL, returns the number of extensions (e.g., to allocate storage for a subsequent call) - otherwise,
*extsis populated with theExtensionTypevalues in the order that the corresponding extensions appeared in the ClientHello *num_extsis an input/output parameter, used as input to supply the size of storage allocated by the caller, and as output to indicate how manyExtensionTypevalues were written- if the input
*num_extsis smaller then the number of extensions in question, that is treated as an error (yes the original says "smaller then", I'm just passing the message along verbatim, don't come for me π) - a subsequent call with
extsset toNULLcan retrieve the size of storage needed - a ClientHello that contained no extensions is treated as success, with
*num_extsset to0
β¨ NOTES β¨
the ClientHello callback provides a vast window of possibilities for application code to affect the TLS handshake. main character energy fr.
a primary use of the callback is to allow the server to examine the server name indication extension provided by the client in order to select an appropriate certificate to present, and make other configuration adjustments relevant to that server name and its configuration. such configuration changes can include:
- swapping out the associated
SSL_CTXpointer - modifying the server's list of permitted TLS versions
- changing the server's cipher list in response to the client's cipher list
- etc.
it is also recommended that applications utilize a ClientHello callback and not use a servername callback, in order to avoid unexpected behavior that occurs due to the relative order of processing between things like session resumption and the historical servername callback. like, trust. π
β οΈ the SSL_client_hello_* family of functions may only be called from code executing within a ClientHello callback. no sneaking around, bestie.
the SSL_client_hello_get0_*() functions return raw ClientHello data, whereas SSL_client_hello_get1_extensions_present() returns only recognized extensions (so unknown/GREASE-extensions are not included). iykyk π
π₯ RETURN VALUES π₯
the callback
the application's supplied ClientHello callback returns:
SSL_CLIENT_HELLO_SUCCESSon success βSSL_CLIENT_HELLO_ERRORon failure πSSL_CLIENT_HELLO_RETRYto suspend processing βΈοΈ
everything else
SSL_client_hello_isv2()returns1for SSLv2-format ClientHellos and0otherwiseSSL_client_hello_get0_random(),SSL_client_hello_get0_session_id(),SSL_client_hello_get0_ciphers(), andSSL_client_hello_get0_compression_methods()return the length of the corresponding ClientHello fields. if zero is returned, the output pointer should not be assumed to be valid π©SSL_client_hello_get0_ext()returns1if the extension of type 'type' is present, and0otherwiseSSL_client_hello_get1_extensions_present()returns1on success and0on failureSSL_client_hello_get_extension_order()returns1on success and0on failure
π SEE ALSO π
ssl(7), SSL_CTX_set_tlsext_servername_callback(3), SSL_bytes_to_cipher_list(3)
go read those next, bestie, they're all linked lore π
π HISTORY π
the SSL ClientHello callback, SSL_client_hello_isv2(), SSL_client_hello_get0_random(), SSL_client_hello_get0_session_id(), SSL_client_hello_get0_ciphers(), SSL_client_hello_get0_compression_methods(), SSL_client_hello_get0_ext(), and SSL_client_hello_get1_extensions_present() were added in OpenSSL 1.1.1.
SSL_client_hello_get_extension_order() was added in OpenSSL 3.2.0. the newbie of the squad π£
π COPYRIGHT π
Copyright 2017-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 whole page, bestie π«Ά this was version 3.5.6, dated 2026-04-07 β go forth and process those ClientHellos early, periodt πβ¨π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms