SSL_CTX_SET_..._GENERATE_CB(3ossl)
π NAME π
okay bestie, welcome to SSL_CTX_SET_..._GENERATE_CB from the 3ossl manual β yes the title is doing the most with those ellipses, she's mysterious like that. π
This page is all about these four icons right here:
SSL_CTX_set_stateless_cookie_generate_cbSSL_CTX_set_stateless_cookie_verify_cbSSL_CTX_set_cookie_generate_cbSSL_CTX_set_cookie_verify_cb
and they're literally just callback functions for stateless TLS1.3 cookies. cookies!! not the edible kind unfortunately π but still slay.
β¨ 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 look at those function pointer signatures. she's giving function pointer realness. π«Ά
πΈ DESCRIPTION πΈ
okay so let's break these four down one by one, no skipping, we're doing the whole set π
π the stateless ones (TLS1.3 girlies)
SSL_CTX_set_stateless_cookie_generate_cb() sets the callback that SSL_stateless(3) uses to generate the application-controlled portion of the cookie handed to clients in the HelloRetryRequest. And when does that get sent? As a response to a ClientHello that showed up with a missing or invalid cookie. rude of them honestly. π
gen_stateless_cookie_cb() has rules, and she follows them:
- it must write at most
SSL_COOKIE_LENGTHbytes intocookie - it must write the number of bytes written to
cookie_len - and if a cookie just cannot be generated? a zero return value can be used to abort the handshake. dramatic but valid. π
SSL_CTX_set_stateless_cookie_verify_cb() sets the callback that 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 its length is cookie_len. a nonzero return value from verify_stateless_cookie_cb() is how you say "yes bestie, this cookie is valid." β
ngl the best part: the integrity of the entire cookie β including the application-controlled portion β is automatically verified by HMAC before verify_stateless_cookie_cb() is even called. so OpenSSL already did the vibe check for you. π
π¦ the DTLS ones
SSL_CTX_set_cookie_generate_cb() sets the callback used by DTLSv1_listen(3) to generate the cookie given to clients in the HelloVerifyRequest β transmitted as a response to a ClientHello with a missing or invalid cookie, same energy as above.
app_gen_cookie_cb() must:
- write at most
DTLS1_COOKIE_LENGTHbytes intocookie - write the number of bytes written to
cookie_len - and if a cookie can't be generated, a zero return value can be used to abort the handshake
SSL_CTX_set_cookie_verify_cb() sets the callback used by DTLSv1_listen(3) to determine whether the cookie in a ClientHello is valid. the cookie data is pointed to by cookie and is of length cookie_len. a nonzero return value from app_verify_cookie_cb() communicates that the cookie is valid. β
π¨ okay important one, do not skip this: the integrity of the cookie is NOT verified by OpenSSL here. that's an application responsibility. meaning it's on you, bestie. the stateless one had HMAC doing the work, this one does not. keep that energy in mind. π€
π RETURN VALUES π
neither function returns a value. that's it, that's the whole section. no notes. π
β SEE ALSO β
go read those, they're the supporting cast and they ate. π₯
π HISTORY π
SSL_CTX_set_stateless_cookie_generate_cb() and SSL_CTX_set_stateless_cookie_verify_cb() were added in OpenSSL 1.1.1. so they've been around, they're established, they're veterans. π
π 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>.
okay and that's the whole page bestie, you understood it, you slayed it, you're literally the main character of TLS handshakes now π¦β¨ this was OpenSSL 3.5.9, dated 2026-09-29, and yes she's iconic, mwah ππ§ββοΈ
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms