SSL_CTX_SET_...ION_TICKET_CB(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… NAME ✨

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 β€” literally the whole squad that manages session ticket application data 🎟️ (this is OpenSSL, section 3ossl, bestie β€” buckle up).


πŸ¦‹ 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() is the plug that slots in your app callbacks, gen_cb and dec_cb β€” a server uses them to set and get the application data stored with a session, the stuff that gets yeeted into a session ticket. Either callback can be NULL, no drama. Whatever you pass in arg gets handed to the callbacks, iykyk.

gen_cb is your callback, and it fires when a session ticket is about to be created. This is your moment β€” call SSL_SESSION_set1_ticket_appdata() right there to add your application data into the session ticket. The arg you get is literally the same arg you gave to SSL_CTX_set_session_ticket_cb(). The gen_cb callback has type SSL_CTX_generate_session_ticket_fn.

dec_cb is also your callback, invoked after session ticket decryption has been attempted and any session ticket application data is available. If decryption worked, the ss argument holds the session data. keyname and keyname_len identify the key that was used to decrypt the session ticket. status is the result of the ticket decryption β€” peep the NOTES section below for the full tea. The arg is the same arg from 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 you give it via data and len into ss, which then gets placed into any generated session tickets. You can call it any time before a session ticket is created to update the data that goes into the session ticket. But heads up: sessions and tickets are created by the handshake, so that's exactly why gen_cb exists β€” to ping you that a session ticket is about to be generated πŸ‘‘

SSL_SESSION_get0_ticket_appdata() assigns data to the session ticket application data and assigns len to the length of that application data, pulled from ss. That application data can be set via SSL_SESSION_set1_ticket_appdata() or by a session ticket. If there's no session ticket application data at all? NULL gets assigned to data and 0 gets assigned to len. No vibes, no data. You can call SSL_SESSION_get0_ticket_appdata() any time after a session has been created β€” and dec_cb is your notification 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. status tells you how ticket decryption went. And bestie, your callback must check the status value before doing literally anything β€” because it gets called even when ticket decryption fails. πŸ’€

The keyname and keyname_len arguments to dec_cb can 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 β€” an empty ticket is 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. Note that in TLSv1.3 a client may send more than one ticket in a single handshake. So just because one ticket is unacceptable, that 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 doesn't 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 doesn't 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 doesn't 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

SSL_CTX_set_session_ticket_cb(), SSL_SESSION_set1_ticket_appdata() and SSL_SESSION_get0_ticket_appdata() all return 1 on success and 0 on failure. Slay.

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.


🌈 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. OG behaviour ✨


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>.


okay that's the whole thing, bestie β€” go forth and encrypt πŸ’–

mwah πŸ’‹ this was OpenSSL 3.5.0, dated 2026-09-2, and it ate, no crumbs πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from