| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "SSL_CTX_SET_CLIENT_HELLO_CB 3SSL" |
| 58 |
.TH SSL_CTX_SET_CLIENT_HELLO_CB 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
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 |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 10 |
| 68 |
\& typedef int (*SSL_client_hello_cb_fn)(SSL *s, int *al, void *arg); |
| 69 |
\& void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn *f, |
| 70 |
\& void *arg); |
| 71 |
\& int SSL_client_hello_isv2(SSL *s); |
| 72 |
\& unsigned int SSL_client_hello_get0_legacy_version(SSL *s); |
| 73 |
\& size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out); |
| 74 |
\& size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out); |
| 75 |
\& size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out); |
| 76 |
\& size_t SSL_client_hello_get0_compression_methods(SSL *s, |
| 77 |
\& const unsigned char **out); |
| 78 |
\& int SSL_client_hello_get1_extensions_present(SSL *s, int **out, |
| 79 |
\& size_t *outlen); |
| 80 |
\& int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts, |
| 81 |
\& size_t *num_exts); |
| 82 |
\& int SSL_client_hello_get0_ext(SSL *s, unsigned int type, const unsigned char **out, |
| 83 |
\& size_t *outlen); |
| 84 |
.Ve |
| 85 |
.SH DESCRIPTION |
| 86 |
.IX Header "DESCRIPTION" |
| 87 |
\&\fBSSL_CTX_set_client_hello_cb()\fR sets the callback function, which is automatically |
| 88 |
called during the early stages of ClientHello processing on the server. |
| 89 |
The argument supplied when setting the callback is passed back to the |
| 90 |
callback at run time. A callback that returns failure (0) will cause the |
| 91 |
connection to terminate, and callbacks returning failure should indicate |
| 92 |
what alert value is to be sent in the \fBal\fR parameter. A callback may |
| 93 |
also return a negative value to suspend the handshake, and the handshake |
| 94 |
function will return immediately. \fBSSL_get_error\fR\|(3) will return |
| 95 |
SSL_ERROR_WANT_CLIENT_HELLO_CB to indicate that the handshake was suspended. |
| 96 |
It is the job of the ClientHello callback to store information about the state |
| 97 |
of the last call if needed to continue. On the next call into the handshake |
| 98 |
function, the ClientHello callback will be called again, and, if it returns |
| 99 |
success, normal handshake processing will continue from that point. |
| 100 |
.PP |
| 101 |
\&\fBSSL_client_hello_isv2()\fR indicates whether the ClientHello was carried in a |
| 102 |
SSLv2 record and is in the SSLv2 format. The SSLv2 format has substantial |
| 103 |
differences from the normal SSLv3 format, including using three bytes per |
| 104 |
cipher suite, and not allowing extensions. Additionally, the SSLv2 format |
| 105 |
\&'challenge' field is exposed via \fBSSL_client_hello_get0_random()\fR, padded to |
| 106 |
SSL3_RANDOM_SIZE bytes with zeros if needed. For SSLv2 format ClientHellos, |
| 107 |
\&\fBSSL_client_hello_get0_compression_methods()\fR returns a dummy list that only includes |
| 108 |
the null compression method, since the SSLv2 format does not include a |
| 109 |
mechanism by which to negotiate compression. |
| 110 |
.PP |
| 111 |
\&\fBSSL_client_hello_get0_random()\fR, \fBSSL_client_hello_get0_session_id()\fR, |
| 112 |
\&\fBSSL_client_hello_get0_ciphers()\fR, and |
| 113 |
\&\fBSSL_client_hello_get0_compression_methods()\fR provide access to the corresponding |
| 114 |
ClientHello fields, returning the field length and optionally setting an out |
| 115 |
pointer to the octets of that field. |
| 116 |
.PP |
| 117 |
Similarly, \fBSSL_client_hello_get0_ext()\fR provides access to individual extensions |
| 118 |
from the ClientHello on a per-extension basis. For the provided wire |
| 119 |
protocol extension type value, the extension value and length are returned |
| 120 |
in the output parameters (if present). |
| 121 |
.PP |
| 122 |
\&\fBSSL_client_hello_get1_extensions_present()\fR can be used prior to |
| 123 |
\&\fBSSL_client_hello_get0_ext()\fR, to determine which extensions are present in the |
| 124 |
ClientHello before querying for them. The \fBout\fR and \fBoutlen\fR parameters are |
| 125 |
both required, and on success the caller must release the storage allocated for |
| 126 |
\&\fB*out\fR using \fBOPENSSL_free()\fR. The contents of \fB*out\fR is an array of integers |
| 127 |
holding the numerical value of the TLS extension types in the order they appear |
| 128 |
in the ClientHello. \fB*outlen\fR contains the number of elements in the array. |
| 129 |
In situations when the ClientHello has no extensions, the function will return |
| 130 |
success with \fB*out\fR set to NULL and \fB*outlen\fR set to 0. |
| 131 |
Note that \fBSSL_client_hello_get1_extensions_present()\fR returns only recognised |
| 132 |
extensions; therefore, unrecognised (including GREASE) extensions will not |
| 133 |
appear in the output. |
| 134 |
.PP |
| 135 |
\&\fBSSL_client_hello_get_extension_order()\fR is similar to |
| 136 |
\&\fBSSL_client_hello_get1_extensions_present()\fR, without internal memory allocation. |
| 137 |
When called with \fBexts\fR set to NULL, returns the number of extensions |
| 138 |
(e.g., to allocate storage for a subsequent call). Otherwise, \fB*exts\fR is populated |
| 139 |
with the ExtensionType values in the order that the corresponding extensions |
| 140 |
appeared in the ClientHello. \fB*num_exts\fR is an input/output parameter, used |
| 141 |
as input to supply the size of storage allocated by the caller, and as output to |
| 142 |
indicate how many ExtensionType values were written. If the input \fB*num_exts\fR |
| 143 |
is smaller then the number of extensions in question, that is treated as an error. |
| 144 |
A subsequent call with \fBexts\fR set to NULL can retrieve the size of storage needed. |
| 145 |
A ClientHello that contained no extensions is treated as success, with \fB*num_exts\fR |
| 146 |
set to 0. |
| 147 |
.SH NOTES |
| 148 |
.IX Header "NOTES" |
| 149 |
The ClientHello callback provides a vast window of possibilities for application |
| 150 |
code to affect the TLS handshake. A primary use of the callback is to |
| 151 |
allow the server to examine the server name indication extension provided |
| 152 |
by the client in order to select an appropriate certificate to present, |
| 153 |
and make other configuration adjustments relevant to that server name |
| 154 |
and its configuration. Such configuration changes can include swapping out |
| 155 |
the associated SSL_CTX pointer, modifying the server's list of permitted TLS |
| 156 |
versions, changing the server's cipher list in response to the client's |
| 157 |
cipher list, etc. |
| 158 |
.PP |
| 159 |
It is also recommended that applications utilize a ClientHello callback and |
| 160 |
not use a servername callback, in order to avoid unexpected behavior that |
| 161 |
occurs due to the relative order of processing between things like session |
| 162 |
resumption and the historical servername callback. |
| 163 |
.PP |
| 164 |
The SSL_client_hello_* family of functions may only be called from code |
| 165 |
executing within a ClientHello callback. |
| 166 |
.PP |
| 167 |
The SSL_client_hello_get0_*() functions return raw ClientHello data, whereas |
| 168 |
\&\fBSSL_client_hello_get1_extensions_present()\fR returns only recognized extensions |
| 169 |
(so unknown/GREASE\-extensions are not included). |
| 170 |
.SH "RETURN VALUES" |
| 171 |
.IX Header "RETURN VALUES" |
| 172 |
The application's supplied ClientHello callback returns |
| 173 |
SSL_CLIENT_HELLO_SUCCESS on success, SSL_CLIENT_HELLO_ERROR on failure, and |
| 174 |
SSL_CLIENT_HELLO_RETRY to suspend processing. |
| 175 |
.PP |
| 176 |
\&\fBSSL_client_hello_isv2()\fR returns 1 for SSLv2\-format ClientHellos and 0 otherwise. |
| 177 |
.PP |
| 178 |
\&\fBSSL_client_hello_get0_random()\fR, \fBSSL_client_hello_get0_session_id()\fR, |
| 179 |
\&\fBSSL_client_hello_get0_ciphers()\fR, and |
| 180 |
\&\fBSSL_client_hello_get0_compression_methods()\fR return the length of the |
| 181 |
corresponding ClientHello fields. If zero is returned, the output pointer |
| 182 |
should not be assumed to be valid. |
| 183 |
.PP |
| 184 |
\&\fBSSL_client_hello_get0_ext()\fR returns 1 if the extension of type 'type' is present, and |
| 185 |
0 otherwise. |
| 186 |
.PP |
| 187 |
\&\fBSSL_client_hello_get1_extensions_present()\fR returns 1 on success and 0 on failure. |
| 188 |
.PP |
| 189 |
\&\fBSSL_client_hello_get_extension_order()\fR returns 1 on success and 0 on failure. |
| 190 |
.SH "SEE ALSO" |
| 191 |
.IX Header "SEE ALSO" |
| 192 |
\&\fBssl\fR\|(7), \fBSSL_CTX_set_tlsext_servername_callback\fR\|(3), |
| 193 |
\&\fBSSL_bytes_to_cipher_list\fR\|(3) |
| 194 |
.SH HISTORY |
| 195 |
.IX Header "HISTORY" |
| 196 |
The SSL ClientHello callback, \fBSSL_client_hello_isv2()\fR, |
| 197 |
\&\fBSSL_client_hello_get0_random()\fR, \fBSSL_client_hello_get0_session_id()\fR, |
| 198 |
\&\fBSSL_client_hello_get0_ciphers()\fR, \fBSSL_client_hello_get0_compression_methods()\fR, |
| 199 |
\&\fBSSL_client_hello_get0_ext()\fR, and \fBSSL_client_hello_get1_extensions_present()\fR |
| 200 |
were added in OpenSSL 1.1.1. |
| 201 |
\&\fBSSL_client_hello_get_extension_order()\fR |
| 202 |
was added in OpenSSL 3.2.0. |
| 203 |
.SH COPYRIGHT |
| 204 |
.IX Header "COPYRIGHT" |
| 205 |
Copyright 2017\-2022 The OpenSSL Project Authors. All Rights Reserved. |
| 206 |
.PP |
| 207 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 208 |
this file except in compliance with the License. You can obtain a copy |
| 209 |
in the file LICENSE in the source distribution or at |
| 210 |
<https://www.openssl.org/source/license.html>. |