SSL_CTX_SET_..._GENERATE_CB(3ossl)
π SSL_CTX_SET_..._GENERATE_CB(3ossl) β the OpenSSL glow-up π
okay bestie, so this is one of those OpenSSL manual pages, the 3ossl side of the library, and it's literally all about cookie callbacks. not the yummy kind π the TLS1.3 / DTLS handshake kind. stay with me, it slaps once you get it.
β¨ NAME β¨
SSL_CTX_set_stateless_cookie_generate_cb, SSL_CTX_set_stateless_cookie_verify_cb, SSL_CTX_set_cookie_generate_cb, SSL_CTX_set_cookie_verify_cb β 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, yes, they're all void-returning setters and the actual callback signatures are the whole personality here. look at them. chef's kiss π
π DESCRIPTION π
π¦ stateless cookie generate β SSL_CTX_set_stateless_cookie_generate_cb()
This is the setter. It 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 when does that happen? when the server receives a ClientHello with a missing or invalid cookie. iconic behavior honestly.
so gen_stateless_cookie_cb() has rules, and they're not optional:
- it must write at most
SSL_COOKIE_LENGTHbytes intocookie - it must write the number of bytes written to
cookie_len - if a cookie genuinely cannot be generated, you can return a zero value to abort the handshake π
π¦ stateless cookie verify β 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 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 communicate "yep, that cookie is valid, slay" β
and here's the part that's giving main character energy: 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 did that for you. you're welcome π«Ά
π§ DTLS cookie generate β SSL_CTX_set_cookie_generate_cb()
sets the callback DTLSv1_listen(3) uses to generate the cookie handed to clients in the HelloVerifyRequest, which is transmitted as a response to a ClientHello with a missing or invalid cookie.
same energy, different constants:
app_gen_cookie_cb()must write at mostDTLS1_COOKIE_LENGTHbytes intocookie- it must write the number of bytes written to
cookie_len - if a cookie cannot be generated, a zero return value can be used to abort the handshake π
π§ DTLS cookie verify β SSL_CTX_set_cookie_verify_cb()
sets the callback DTLSv1_listen(3) uses to determine whether the cookie in a ClientHello is valid.
cookie data is pointed to by cookie, and it's cookie_len long. a nonzero return value from app_verify_cookie_cb() means "valid, bestie" β
β οΈ okay hear me on this one: the integrity of the cookie is not verified by OpenSSL here. that's an application responsibility. so likeβ¦ it's on you. no cap. π
π RETURN VALUES π
neither function returns a value. they're setters. they set. that's the whole arc. β¨
π SEE ALSO π
go read those next, iykyk π¦
β HISTORY β
SSL_CTX_set_stateless_cookie_generate_cb() and SSL_CTX_set_stateless_cookie_verify_cb() were added in OpenSSL 1.1.1. vintage. lowkey a classic π
π 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>.
π and that's the page!! this was OpenSSL 3.5.6, dated 2026-04-07, signing off β stay encrypted, stay hydrated, and please actually check those DTLS cookies yourself bestie ππ
π¦ 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