SSL_CTX_SET_...DING_CALLBACK(3SSL)
πΈ SSL_CTX_SET_...DING_CALLBACK β¨
okay bestie, sit DOWN, because this one is from the OpenSSL 3SSL manual and it's all about installing a callback to specify TLS 1.3 record padding π like. we're customizing how many lil extra bytes get tacked onto your records before encryption. so cute. so powerful. let's go π«Ά
The star-studded cast, in alphabetical-ish order (yes, all of them, I would never leave one out, that's not the vibe):
SSL_CTX_set_record_padding_callbackSSL_set_record_padding_callbackSSL_CTX_set_record_padding_callback_argSSL_set_record_padding_callback_argSSL_CTX_get_record_padding_callback_argSSL_get_record_padding_callback_argSSL_CTX_set_block_paddingSSL_CTX_set_block_padding_exSSL_set_block_paddingSSL_set_block_padding_ex
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx, size_t (*cb)(SSL *s, int type, size_t len, void *arg));
int SSL_set_record_padding_callback(SSL *ssl, size_t (*cb)(SSL *s, int type, size_t len, void *arg));
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);
int SSL_set_block_padding(SSL *ssl, size_t block_size);
int SSL_CTX_set_block_padding_ex(SSL_CTX *ctx, size_t app_block_size, size_t hs_block_size);
int SSL_set_block_padding_ex(SSL *ssl, size_t app_block_size, size_t hs_block_size);
like look at those signatures bestie, gorgeous, immaculate, no notes π
π¦ DESCRIPTION π¦
so SSL_CTX_set_record_padding_callback() and SSL_set_record_padding_callback() are how you hand over a callback function cb that decides the padding for TLS 1.3 records. the value you set in ctx? it gets copied into a brand-new SSL by SSL_new(). π
β οΈ okay important: Kernel TLS is not possible if the record padding callback is set, and the callback function cannot be set if Kernel TLS is already configured for the current SSL object. it's giving "pick one, babe" π
Then SSL_CTX_set_record_padding_callback_arg() and SSL_set_record_padding_callback_arg() assign a value arg that gets passed straight to the callback whenever it's invoked. and yep β the value set in ctx is copied to a new SSL by SSL_new(). β¨
SSL_CTX_get_record_padding_callback_arg() and SSL_get_record_padding_callback_arg() fetch back that arg value you handed to the callback. retrieval arc π
Now for the block padding girlies:
SSL_CTX_set_block_padding()andSSL_set_block_padding()pad the record out to a multiple of theblock_size. ablock_sizeof0or1disables block padding (yes really). and the limit ofblock_sizeisSSL3_RT_MAX_PLAIN_LENGTH. πSSL_CTX_set_block_padding_ex()andSSL_set_block_padding_ex()do basically the same thing but let you separately specify the padding block size that gets applied to handshake vs application data messages. main character energy, honestly π
π« the callback, deconstructed π«
the callback fires for every record before encryption. here's the tea on its parameters:
typeβ the TLS record type being processed. it may be one ofSSL3_RT_APPLICATION_DATA,SSL3_RT_HANDSHAKE, orSSL3_RT_ALERT.lenβ the current plaintext length of the record before encryption.argβ the value you set viaSSL_CTX_set_record_padding_callback_arg()orSSL_set_record_padding_callback_arg().
π« QUIC girlies, this is not for you π«
These functions cannot be used with QUIC SSL objects. and to be extra clear: SSL_set_record_padding_callback() and SSL_set_block_padding() fail if called on a QUIC SSL object. sorry babe π
π RETURN VALUES π
SSL_CTX_get_record_padding_callback_arg()andSSL_get_record_padding_callback_arg()return theargvalue you assigned in the corresponding set functions. periodt.SSL_CTX_set_block_padding()andSSL_set_block_padding()return1on success, or0ifblock_sizeis too large. (too much?? too much. π« )cbreturns the number of padding bytes to add to the record. a return of0means no padding will be added. and a return value that would push the record past the maximum record size (SSL3_RT_MAX_PLAIN_LENGTH)? it'll just pad out to the maximum record size instead. iconic, honestly, it self-corrects πSSL_CTX_get_record_padding_callback_arg()β okay this one's a little β¨specialβ¨ in the docs β returns1on success, or0if the callback function is not set because Kernel TLS is configured for the SSL object. yes,1. I know. I'm just telling you what the page says, bestie π
π NOTES π
- the default behavior is to add no padding to the record. chill. minimal. a little mysterious β¨
- a user-supplied padding callback function will override the behavior set by
SSL_set_block_padding()orSSL_CTX_set_block_padding(). and setting the user-supplied callback toNULLrestores the configured block padding behavior. so you can always take it back π₯° - These functions only apply to TLS 1.3 records being written. not reading. writing. only. π
- Padding bytes are not added in constant-time. π clock that, it's a real caveat
π SEE ALSO π
ssl(7), SSL_new(3) β go read those too, they're also good, I don't make the rules π«Ά
β HISTORY β
- The record padding API was added for TLS 1.3 support in OpenSSL 1.1.1.
- The return type of
SSL_CTX_set_record_padding_callback()function was changed tointin OpenSSL 3.0. - The functions
SSL_set_block_padding_ex()andSSL_CTX_set_block_padding_ex()were added in OpenSSL 3.4. fresh drops π₯
π COPYRIGHT π
Copyright 2017-2024 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!! this one's from OpenSSL version 4.0.3, dated 2026-09-29 β go forth and pad your records responsibly, ily, mwah πππ¦β¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms