SSL_CTX_SET1...MP_PREFERENCE(3ossl)
π NAME π
okay bestie, gather round β this page is all about the certificate compression girlies. It's the manual for the SSL_CTX_SET1...MP_PREFERENCE(3ossl) page, and it covers these functions:
SSL_CTX_set1_cert_comp_preferenceSSL_set1_cert_comp_preferenceSSL_CTX_compress_certsSSL_compress_certsSSL_CTX_get1_compressed_certSSL_get1_compressed_certSSL_CTX_set1_compressed_certSSL_set1_compressed_cert
They're the certificate compression functions β¨
π¦ SYNOPSIS π¦
Like, here's the whole cast list, literally:
#include <openssl/ssl.h>
int SSL_CTX_set1_cert_comp_preference(SSL_CTX *ctx, int *algs, size_t len);
int SSL_set1_cert_comp_preference(SSL *ssl, int *algs, size_t len);
int SSL_CTX_compress_certs(SSL_CTX *ctx, int alg);
int SSL_compress_certs(SSL *ssl, int alg);
size_t SSL_CTX_get1_compressed_cert(SSL_CTX *ctx, int alg, unsigned char **data,
size_t *orig_len);
size_t SSL_get1_compressed_cert(SSL *ssl, int alg, unsigned char **data,
size_t *orig_len);
int SSL_CTX_set1_compressed_cert(SSL_CTX *ctx, int alg,
unsigned char *comp_data,
size_t comp_length, size_t orig_length);
int SSL_set1_compressed_cert(SSL *ssl, int alg, unsigned char *comp_data,
size_t comp_length, size_t orig_length);
πΈ DESCRIPTION πΈ
These functions are the control panel for the certificate compression feature. And heads up: certificate compression is only available for TLSv1.3, as defined in RFC8879. No TLSv1.2 shenanigans, periodt. π ββοΈ
SSL_CTX_set1_cert_comp_preference() and SSL_set1_cert_comp_preference() are how you say "here's my algorithm priority list, bestie". The algs argument is an array of algorithms, and length is number of elements in the algs array. Important: only those algorithms enabled in the library will be accepted in algs, and unknown algorithms in algs are just ignored. And if something errors out? The preference order is left unmodified β no half-applied mess, we love that for us. π
The following compression algorithms (the alg arguments) may be used:
TLSEXT_comp_cert_brotliTLSEXT_comp_cert_zlibTLSEXT_comp_cert_zstd
And that list right there? That's also the default preference order. So if you don't specify a preference order, the default preference order gets sent to the peer, and the peer's received preference order is what gets used when compressing a certificate. Otherwise, the configured preference order is sent to the peer and is used to filter the peer's preference order. π
SSL_CTX_compress_certs() and SSL_compress_certs() are the pre-compression girlies β they pre-compress all the configured certificates on an SSL_CTX/SSL object with algorithm alg. If alg is 0, then the certificates are compressed with the algorithms specified in the preference list. But listen: calling these functions on a client SSL_CTX/SSL object will result in an error, because only server certificates may be pre-compressed. Only servers get to do that. π«Ά
SSL_CTX_get1_compressed_cert() and SSL_get1_compressed_cert() are for grabbing the pre-compressed certificate most recently set that may be stored for later use. Same deal as above: calling these functions on a client SSL_CTX/SSL object will result in an error, because only server certificates may be pre-compressed. The data and orig_len arguments are required β you can't skip them, bestie.
The compressed certificate data may be passed to SSL_CTX_set1_compressed_cert() or SSL_set1_compressed_cert() to provide a pre-compressed version of the most recently set certificate. And this pre-compressed certificate can only be used by a server. π
β¨ NOTES β¨
Each side of the connection sends their compression algorithm preference list to their peer indicating compressed certificate support. The received preference list is filtered by the configured preference list (i.e. the intersection is saved). And because the default list includes all the enabled algorithms, not specifying a preference will allow any enabled algorithm by the peer. The filtered peer's preference order is used to determine what algorithm to use when sending a compressed certificate. It's giving matchmaking, honestly. π
Only server certificates may be pre-compressed. Calling any of these functions (except SSL_CTX_set1_cert_comp_preference()/SSL_set1_cert_comp_preference()) on a client SSL_CTX/SSL object will return an error. Client certificates are compressed on-demand, as unique context data from the server is compressed along with the certificate. π¦
For SSL_CTX_set1_cert_comp_preference() and SSL_set1_cert_comp_preference() the len argument is the size of the algs argument in bytes.
The compressed certificate returned by SSL_CTX_get1_compressed_cert() and SSL_get1_compressed_cert() is the last certificate set on the SSL_CTX/SSL object. The certificate is copied by the function and the caller must free *data via OPENSSL_free(). Do NOT forget the free. π
The compressed certificate data set by SSL_CTX_set1_compressed_cert() and SSL_set1_compressed_cert() is copied into the SSL_CTX/SSL object.
SSL_CTX_compress_certs() and SSL_compress_certs() return an error under the following conditions:
- If no certificates have been configured.
- If the specified algorithm
algis not enabled. - If
algis0and no compression algorithms are enabled.
Sending compressed certificates may be disabled on a connection via the SSL_OP_NO_TX_CERTIFICATE_COMPRESSION option. Receiving compressed certificates may be disabled on a connection via the SSL_OP_NO_RX_CERTIFICATE_COMPRESSION option. π
π RETURN VALUES π
SSL_CTX_set1_cert_comp_preference(), SSL_set1_cert_comp_preference(), SSL_CTX_compress_certs(), SSL_compress_certs(), SSL_CTX_set1_compressed_cert(), and SSL_set1_compressed_cert() return 1 for success and 0 on error. Simple as that. β¨
SSL_CTX_get1_compressed_cert() and SSL_get1_compressed_cert() return the length of the allocated memory on success and 0 on error.
π SEE ALSO π
π HISTORY π
These functions were added in OpenSSL 3.2. newish, iconic, we stan π
π COPYRIGHT π
Copyright 2022 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 page bestie, you ate π β¨ This was the OpenSSL 3.5.9 version of the page, dated 2026-09-2 β go forth and compress those server certificates, no cap π¦π
π¦ 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