SSL_CTX_SET_..._GENERATE_CB(3ossl)
π SSL_CTX_SET_..._GENERATE_CB β bestie edition πͺ
okay so this is the 3ossl manual page, and it's literally all about cookie callback functions for stateless TLS1.3 πͺβ¨ (yes bestie, TLS has cookies too, iykyk)
πΈ NAME πΈ
SSL_CTX_set_stateless_cookie_generate_cbSSL_CTX_set_stateless_cookie_verify_cbSSL_CTX_set_cookie_generate_cbSSL_CTX_set_cookie_verify_cb
β¦and together they're the Callback functions for stateless TLS1.3 cookies π
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
void SSL_CTX_set_stateless_cookie_generate_cb(
SSL_CTX *ctx,
int (*gen_stateless_cookie_cb) (SSL *ssl,
unsigned char *cookie,
size_t *cookie_len));
void SSL_CTX_set_stateless_cookie_verify_cb(
SSL_CTX *ctx,
int (*verify_stateless_cookie_cb) (SSL *ssl,
const unsigned char *cookie,
size_t cookie_len));
void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
int (*app_gen_cookie_cb) (SSL *ssl,
unsigned char
*cookie,
unsigned int
*cookie_len));
void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
int (*app_verify_cookie_cb) (SSL *ssl,
const unsigned
char *cookie,
unsigned int
cookie_len));
likeβ¦ four functions, four callbacks, all vibes π
π¦ DESCRIPTION π¦
πͺ the stateless cookie generate one
SSL_CTX_set_stateless_cookie_generate_cb() sets the callback that SSL_stateless(3) uses to generate the application-controlled portion of the cookie that gets handed to clients in the HelloRetryRequest π β and that HelloRetryRequest is literally the response to a ClientHello that showed up with a missing or invalid cookie ππ
so gen_stateless_cookie_cb() has to write at most SSL_COOKIE_LENGTH bytes into cookie, and must write the number of bytes it wrote into cookie_len βοΈ no cap.
and if a cookie just cannot be generated? a zero return value can be used to abort the handshake. periodt. π
π the stateless cookie verify one
SSL_CTX_set_stateless_cookie_verify_cb() sets the callback SSL_stateless(3) uses to figure out whether the application-controlled portion of a ClientHello cookie is actually valid π
the cookie data is pointed to by cookie and is of length cookie_len π«Ά
a nonzero return value from verify_stateless_cookie_cb() tells everyone "yep bestie, this cookie is valid" β
okay and this part is lowkey iconic: the integrity of the entire cookie β including the application-controlled portion β is automatically verified by HMAC before verify_stateless_cookie_cb() even gets called πβ¨ so you're not doing that job, it's already done.
π§ the DTLS cookie generate one
SSL_CTX_set_cookie_generate_cb() sets the callback DTLSv1_listen(3) uses to generate the cookie provided to clients in the HelloVerifyRequest πΈ β transmitted in response to a ClientHello with a missing or invalid cookie, same energy as before π
app_gen_cookie_cb() must write at most DTLS1_COOKIE_LENGTH bytes into cookie, and must write the number of bytes written to cookie_len βοΈ (yes it's a different constant than the TLS one, keep up bestie π
)
again β if a cookie cannot be generated, a zero return value can be used to abort the handshake π«
π the DTLS cookie verify one
SSL_CTX_set_cookie_verify_cb() sets the callback DTLSv1_listen(3) uses to decide whether the cookie in a ClientHello is valid π
cookie data is pointed to by cookie, length cookie_len π a nonzero return value from app_verify_cookie_cb() means the cookie is valid β
BIG difference here though and pls don't miss it: the integrity of the cookie is not verified by OpenSSL. that's an application responsibility π you're the main character on this one, fr fr.
β RETURN VALUES β
neither function returns a value. like, none. zero. nothing. they're just setters doing their little setter thing π
π SEE ALSO π
π HISTORY π
SSL_CTX_set_stateless_cookie_generate_cb() and SSL_CTX_set_stateless_cookie_verify_cb() were added in OpenSSL 1.1.1 β¨ (the other two were already living their truth, iykyk)
π COPYRIGHT π
Copyright 2018 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>.
k bye bestie, this was OpenSSL 3.5.0, dated 2026-09-25 β signed, sealed, and slayed by the SSL_CTX_SET_..._GENERATE_CB(3ossl) girls π«Άπ
π¦ 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