LIBRESSL-SSL_CTX_SET_TLSEXT_SERVERNAME_CALLBACK(3)
π
SSL_CTX_SET_TLSEXT_SERVE(3) β the SNI glow-up
okay so bestie, welcome to the LibreSSL girlies' corner of the manual (yes, that's the libssl / libcrypto library functions manual, and yes we're doing this). This one's all about server name indication, aka SNI, aka the thing that lets one server hold a million vibes at once. β¨
πΈ NAME πΈ
SSL_CTX_set_tlsext_servername_callback, SSL_CTX_set_tlsext_servername_arg, SSL_get_servername_type, SSL_get_servername, SSL_set_tlsext_host_name β handling server name indication (SNI). no cap, that's the whole squad. π«Ά
π SYNOPSIS π
library βlibsslβ libcrypto #include <openssl/ssl.h>
long
SSL_CTX_set_tlsext_servername_callback(SSL_CTX *ctx,
int (*cb)(SSL *ssl, int *alert, void *arg));
long
SSL_CTX_set_tlsext_servername_arg(SSL_CTX *ctx, void *arg);
const char *
SSL_get_servername(const SSL *ssl, const int type);
int
SSL_get_servername_type(const SSL *ssl);
int
SSL_set_tlsext_host_name(SSL *ssl, const char *name);
β¨ DESCRIPTION β¨
π¦ the callback situation
SSL_CTX_set_tlsext_servername_callback() sets the application callback cb β this is the little function a server uses to do any actions or config it needs based on the servername extension it got in the incoming connection. like, oh, you're asking for that hostname? bet, let me reconfigure real quick. π
It's giving the same energy as the ALPN callback: it is executed during Client Hello processing. And the details matter β when cb is NULL, SNI is not used. periodt.
π what your callback should return
The servername callback should return one of these, bestie:
SSL_TLSEXT_ERR_OKβ used to indicate the servername the client asked for has been accepted. Typically a server will callSSL_set_SSL_CTX(3)inside the callback to set up a different configuration for the selected servername in this case. main character server energy, honestly. πSSL_TLSEXT_ERR_ALERT_FATALβ the servername requested by the client is not accepted and the handshake gets aborted. the alert value to use should be stored in the location pointed to by thealertparameter to the callback. by default this value is initialised toSSL_AD_UNRECOGNIZED_NAME. it's giving "sorry, we don't know her." πSSL_TLSEXT_ERR_ALERT_WARNINGβ if you return this, the servername is not accepted by the server, but the handshake continues and sends a warning alert instead. store the alert value in the location pointed to by thealertparameter exactly like withSSL_TLSEXT_ERR_ALERT_FATALabove. > β οΈ but heads up β TLSv1.3 does not support warning alerts, so if TLSv1.3 has been negotiated then this return value is treated the same way asSSL_TLSEXT_ERR_NOACK. lowkey rude of TLSv1.3 but okay.SSL_TLSEXT_ERR_NOACKβ indicates the servername is not accepted by the server. no alerts are sent and the server will not acknowledge the requested servername. silent treatment, but make it protocol. π
π the arg, the getters, and the setter
SSL_CTX_set_tlsext_servername_arg() sets a context-specific argument to be passed into the callback via the arg parameter for ctx. little carry-on luggage for your callback, love that for you. π
SSL_set_tlsext_host_name() sets the server name indication ClientHello extension to contain the value name, or clears it if name is NULL. the type of server name indication extension is set to TLSEXT_NAMETYPE_host_name as defined in RFC 3546. iconic spec behaviour.
π‘ plot twist: all three of those functions are implemented as macros. not functions. macros. don't come for me, that's just what the page says.
π RETURN VALUES π
SSL_CTX_set_tlsext_servername_callback()andSSL_CTX_set_tlsext_servername_arg()β always return1, indicating success. always slaying, never failing. πSSL_get_servername()β returns a servername extension value of the specified type if provided in the Client Hello, orNULLotherwise.SSL_get_servername_type()β returns the servername type, or-1if no servername is present. currently the only supported type (defined in RFC 3546) isTLSEXT_NAMETYPE_host_name. iykyk.SSL_set_tlsext_host_name()β returns1on success or0in case of an error. simple. clean. no notes. β¨
π§ SEE ALSO π§
ssl(3), SSL_CTX_callback_ctrl(3), SSL_CTX_set_alpn_select_cb(3) β go read these next, bestie, they're literally in the same friend group. π¦
β HISTORY β
These functions first appeared in OpenSSL 0.9.8f and have been available since OpenBSD 4.5. vintage, but make it functional. π₯
okay that's the whole page, you ate that read π
β this little love letter is from the Debian build of the LibreSSL manual, dated June, and it's the SSL_CTX_SET_TLSEXT_SERVERNAME_CALLBACK(3) page, so go forth and SNI responsibly. mwah! πβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2017, 2019 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