SSL_CTX_SET_...ION_TICKET_CB(3ossl)

πŸ’– NAME πŸ’–

okay bestie, gather round, because this is the session-ticket-appdata saga ✨

SSL_CTX_set_session_ticket_cb, SSL_SESSION_get0_ticket_appdata, SSL_SESSION_set1_ticket_appdata, SSL_CTX_generate_session_ticket_fn, SSL_CTX_decrypt_session_ticket_fn β€” they're all about managing session ticket application data. that's the whole vibe. πŸ’…

this is the OpenSSL page, section 3ossl, and yes we're about to get into it.


✨ SYNOPSIS ✨

#include <openssl/ssl.h>

typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg);
typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss,
                                                               const unsigned char *keyname,
                                                               size_t keyname_len,
                                                               SSL_TICKET_STATUS status,
                                                               void *arg);
int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx,
                                  SSL_CTX_generate_session_ticket_fn gen_cb,
                                  SSL_CTX_decrypt_session_ticket_fn dec_cb,
                                  void *arg);
int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len);
int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len);

🌸 DESCRIPTION 🌸

SSL_CTX_set_set_session_ticket_cb() sets the application callbacks gen_cb and dec_cb that a server uses to set and get application data stored with a session, and then placed into a session ticket. either callback can be set to NULL, no pressure. the value of arg gets passed along to both callbacks. 🫢

gen_cb is the application defined callback that fires when a session ticket is about to be created. right at that moment, your app can call SSL_SESSION_set1_ticket_appdata() to add application data to the session ticket. the value of arg here is the same one you gave to SSL_CTX_set_session_ticket_cb(). and gen_cb is defined as type SSL_CTX_generate_session_ticket_fn. πŸ’«

dec_cb is the application defined callback that fires after session ticket decryption has been attempted and any session ticket application data is available. if the ticket decryption worked, then the ss argument holds the session data. the keyname and keyname_len arguments identify the key used to decrypt the session ticket. the status argument is the result of the ticket decryption β€” peep the "NOTES" section below for the full tea. the value of arg is the same as what you gave to SSL_CTX_set_session_ticket_cb(). and dec_cb is defined as type SSL_CTX_decrypt_session_ticket_fn. 🌈

SSL_SESSION_set1_ticket_appdata() sets the application data specified by data and len into ss, which then gets placed into any generated session tickets. you can call it at any time before a session ticket is created to update the data that goes into the session ticket. but okay, real talk: since sessions and tickets are created by the handshake, the gen_cb exists precisely to ping your application that a session ticket is about to be generated. iconic teamwork tbh. ✨

SSL_SESSION_get0_ticket_appdata() assigns data to the session ticket application data, and assigns len to the length of that session ticket application data from ss. the application data can be set either via SSL_SESSION_set1_ticket_appdata() or by a session ticket. NULL will be assigned to data and 0 will be assigned to len if there's no session ticket application data at all. you can call SSL_SESSION_get0_ticket_appdata() any time after a session has been created. and the dec_cb is the thing that pings your application that a session ticket has just been decrypted. πŸ¦‹


πŸŽ€ NOTES πŸŽ€

when the dec_cb callback is invoked, the SSL_SESSION ss has not yet been assigned to the SSL s. the status tells you the result of the ticket decryption. the callback must check the status value before doing literally anything, because it gets called even if ticket decryption fails. no skipping the vibe check. πŸ‘‘

the keyname and keyname_len arguments to dec_cb may be used to identify the key that was used to encrypt the session ticket. πŸ”‘

the status argument can be any of these values:

  • SSL_TICKET_EMPTY β€” empty ticket present. no ticket data will be used and a new ticket should be sent to the client. this only happens in TLSv1.2 or below. in TLSv1.3 it is not valid for a client to send an empty ticket. 🚫
  • SSL_TICKET_NO_DECRYPT β€” the ticket couldn't be decrypted. no ticket data will be used and a new ticket should be sent to the client. 😭
  • SSL_TICKET_SUCCESS β€” a ticket was successfully decrypted, so any session ticket application data should be available. a new ticket should not be sent to the client. βœ…
  • SSL_TICKET_SUCCESS_RENEW β€” same as SSL_TICKET_SUCCESS, but a new ticket should be sent to the client. πŸ”

the return value can be any of these values:

  • SSL_TICKET_RETURN_ABORT β€” the handshake should be aborted, either because of an error or because of some policy. > heads up bestie: in TLSv1.3 a client may send more than one ticket in a single handshake. so just because one ticket is unacceptable does not mean all of them are. for this reason this option should be used with caution. ⚠️
  • SSL_TICKET_RETURN_IGNORE β€” do not use a ticket (if one was available). do not send a renewed ticket to the client. πŸ™…
  • SSL_TICKET_RETURN_IGNORE_RENEW β€” do not use a ticket (if one was available). send a renewed ticket to the client. πŸ™…β€β™€οΈβœ¨
    • if the callback does not wish to change the default ticket behaviour, then it should return this value if status is SSL_TICKET_EMPTY or SSL_TICKET_NO_DECRYPT.
  • SSL_TICKET_RETURN_USE β€” use the ticket. do not send a renewed ticket to the client. it is an error for the callback to return this value if status has a value other than SSL_TICKET_SUCCESS or SSL_TICKET_SUCCESS_RENEW. βœ…
    • if the callback does not wish to change the default ticket behaviour, then it should return this value if status is SSL_TICKET_SUCCESS.
  • SSL_TICKET_RETURN_USE_RENEW β€” use the ticket. send a renewed ticket to the client. it is an error for the callback to return this value if status has a value other than SSL_TICKET_SUCCESS or SSL_TICKET_SUCCESS_RENEW. βœ…πŸ”
    • if the callback does not wish to change the default ticket behaviour, then it should return this value if status is SSL_TICKET_SUCCESS_RENEW.

if status has the value SSL_TICKET_EMPTY or SSL_TICKET_NO_DECRYPT, then no session data will be available and the callback must not use the ss argument. if status has the value SSL_TICKET_SUCCESS or SSL_TICKET_SUCCESS_RENEW, then the application can call SSL_SESSION_get0_ticket_appdata() using the session provided in the ss argument to retrieve the application data. πŸ’–

when the gen_cb callback is invoked, the SSL_get_session() function can be used to retrieve the SSL_SESSION for SSL_SESSION_set1_ticket_appdata(). πŸ”

by default, in TLSv1.2 and below, a new session ticket is not issued on a successful resumption, and therefore gen_cb will not be called. in TLSv1.3 the default behaviour is to always issue a new ticket on resumption. in both cases this behaviour can be changed if a ticket key callback is in use β€” see SSL_CTX_set_tlsext_ticket_key_cb(3). πŸ“œ


πŸ’… RETURN VALUES πŸ’…

the SSL_CTX_set_session_ticket_cb(), SSL_SESSION_set1_ticket_appdata() and SSL_SESSION_get0_ticket_appdata() functions return 1 on success and 0 on failure. simple as that.

the gen_cb callback must return 1 to continue the connection. a return of 0 will terminate the connection with an INTERNAL_ERROR alert. 😱

the dec_cb callback must return a value as described in "NOTES" above. no improvising.


πŸ‘€ SEE ALSO πŸ‘€

ssl(7), SSL_get_session(3)


πŸ•°οΈ HISTORY πŸ•°οΈ

the SSL_CTX_set_session_ticket_cb(), SSL_SESSION_set1_ticket_appdata() and SSL_SESSION_get_ticket_appdata() functions were added in OpenSSL 1.1.1. so they've been around a minute. ⭐


Copyright 2017-2020 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 whole page bestie, no cap 🫢 this was SSL_CTX_SET_...ION_TICKET_CB(3ossl) from OpenSSL 3.5.9, dated 2026-09-2, and it literally ate. go forth and ticket responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from