Skip to content

Commit 143dfd5

Browse files
author
bneradt
committed
Gate cert compression by OpenSSL support
Fedora 44 exposes the OpenSSL certificate-compression preference API while disabling the built-in compression algorithms. Treating API presence as usable compression makes ATS report unsupported features and accept configuration that cannot run. This gates certificate-compression feature reporting and algorithm setup on the callbacks and algorithms ATS can actually use. It also keeps the metric-based AuTest behind the same feature check so older OpenSSL builds and Fedora 44 both behave consistently.
1 parent 39248cb commit 143dfd5

3 files changed

Lines changed: 66 additions & 15 deletions

File tree

src/iocore/net/TLSCertCompression.cc

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace
3131
DbgCtl dbg_ctl_ssl_cert_compress{"ssl_cert_compress"};
3232
}
3333

34-
constexpr unsigned int N_ALGORITHMS = 3;
35-
3634
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
3735
#include "TLSCertCompression_zlib.h"
3836

@@ -48,25 +46,41 @@ constexpr unsigned int N_ALGORITHMS = 3;
4846
struct alg_info {
4947
const char *name;
5048
int32_t number;
49+
bool available;
5150
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
5251
ssl_cert_compression_func_t compress_func;
5352
ssl_cert_decompression_func_t decompress_func;
5453
#endif
5554
} supported_algs[] = {
5655
{"zlib", 1,
56+
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG || !defined(OPENSSL_NO_ZLIB)
57+
true,
58+
#else
59+
false,
60+
#endif
5761
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
5862
compression_func_zlib, decompression_func_zlib
5963
#endif
6064
},
61-
#if HAVE_BROTLI_ENCODE_H
65+
#if HAVE_BROTLI_ENCODE_H || !HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
6266
{"brotli", 2,
67+
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG || !defined(OPENSSL_NO_BROTLI)
68+
true,
69+
#else
70+
false,
71+
#endif
6372
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
6473
compression_func_brotli, decompression_func_brotli
6574
#endif
6675
},
6776
#endif
68-
#if HAVE_ZSTD_H
77+
#if HAVE_ZSTD_H || !HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
6978
{"zstd", 3,
79+
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG || !defined(OPENSSL_NO_ZSTD)
80+
true,
81+
#else
82+
false,
83+
#endif
7084
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
7185
compression_func_zstd, decompression_func_zstd
7286
#endif
@@ -78,7 +92,7 @@ int
7892
register_certificate_compression_preference(SSL_CTX *ctx, const std::vector<std::string> &specified_algs)
7993
{
8094
ink_assert(ctx != nullptr);
81-
if (specified_algs.size() > N_ALGORITHMS) {
95+
if (specified_algs.size() > countof(supported_algs)) {
8296
return 0;
8397
}
8498

@@ -95,7 +109,7 @@ register_certificate_compression_preference(SSL_CTX *ctx, const std::vector<std:
95109
info = &supported_algs[i];
96110
}
97111
}
98-
if (info != nullptr) {
112+
if (info != nullptr && info->available) {
99113
if (SSL_CTX_add_cert_compression_alg(ctx, info->number, info->compress_func, info->decompress_func) == 0) {
100114
return 0;
101115
}
@@ -107,16 +121,24 @@ register_certificate_compression_preference(SSL_CTX *ctx, const std::vector<std:
107121
}
108122
return 1;
109123
#elif HAVE_SSL_CTX_SET1_CERT_COMP_PREFERENCE
110-
int algs[N_ALGORITHMS];
124+
int algs[countof(supported_algs)];
111125
int n = 0;
112126

113127
for (unsigned int i = 0; i < specified_algs.size(); ++i) {
128+
struct alg_info *info = nullptr;
129+
114130
for (unsigned int j = 0; j < countof(supported_algs); ++j) {
115131
if (strcmp(specified_algs[i].c_str(), supported_algs[j].name) == 0) {
116-
algs[n++] = supported_algs[j].number;
117-
Dbg(dbg_ctl_ssl_cert_compress, "Enabled %s", supported_algs[j].name);
132+
info = &supported_algs[j];
133+
break;
118134
}
119135
}
136+
if (info == nullptr || !info->available) {
137+
Dbg(dbg_ctl_ssl_cert_compress, "Unrecognized algorithm: %s", specified_algs[i].c_str());
138+
return 0;
139+
}
140+
algs[n++] = info->number;
141+
Dbg(dbg_ctl_ssl_cert_compress, "Enabled %s", info->name);
120142
}
121143
return SSL_CTX_set1_cert_comp_preference(ctx, algs, n);
122144
#else

src/traffic_layout/info.cc

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <fcntl.h>
2525
#include <openssl/crypto.h>
26+
#include <openssl/ssl.h>
2627
#include <swoc/BufferWriter.h>
2728
#include <swoc/bwf_base.h>
2829
#include "tscore/Layout.h"
@@ -53,6 +54,34 @@
5354
#include <zstd.h>
5455
#endif
5556

57+
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG
58+
static constexpr int ts_has_cert_compression_callbacks = 1;
59+
#else
60+
static constexpr int ts_has_cert_compression_callbacks = 0;
61+
#endif
62+
63+
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG || (HAVE_SSL_CTX_SET1_CERT_COMP_PREFERENCE && !defined(OPENSSL_NO_ZLIB))
64+
static constexpr int ts_has_cert_compression_zlib = 1;
65+
#else
66+
static constexpr int ts_has_cert_compression_zlib = 0;
67+
#endif
68+
69+
#if (HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG && HAVE_BROTLI_ENCODE_H) || \
70+
(HAVE_SSL_CTX_SET1_CERT_COMP_PREFERENCE && !defined(OPENSSL_NO_BROTLI))
71+
static constexpr int ts_has_cert_compression_brotli = 1;
72+
#else
73+
static constexpr int ts_has_cert_compression_brotli = 0;
74+
#endif
75+
76+
#if (HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG && HAVE_ZSTD_H) || (HAVE_SSL_CTX_SET1_CERT_COMP_PREFERENCE && !defined(OPENSSL_NO_ZSTD))
77+
static constexpr int ts_has_cert_compression_zstd = 1;
78+
#else
79+
static constexpr int ts_has_cert_compression_zstd = 0;
80+
#endif
81+
82+
static constexpr int ts_has_cert_compression =
83+
ts_has_cert_compression_zlib | ts_has_cert_compression_brotli | ts_has_cert_compression_zstd;
84+
5685
// Produce output about compile time features, useful for checking how things were built
5786
static void
5887
print_feature(std::string_view name, int value, bool json, bool last = false)
@@ -100,11 +129,11 @@ produce_features(bool json)
100129
#else
101130
print_feature("TS_HAS_ZSTD", 0, json);
102131
#endif
103-
#if HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG || HAVE_SSL_CTX_SET1_CERT_COMP_PREFERENCE
104-
print_feature("TS_HAS_CERT_COMPRESSION", 1, json);
105-
#else
106-
print_feature("TS_HAS_CERT_COMPRESSION", 0, json);
107-
#endif
132+
print_feature("TS_HAS_CERT_COMPRESSION", ts_has_cert_compression, json);
133+
print_feature("TS_HAS_CERT_COMPRESSION_CALLBACKS", ts_has_cert_compression_callbacks, json);
134+
print_feature("TS_HAS_CERT_COMPRESSION_ZLIB", ts_has_cert_compression_zlib, json);
135+
print_feature("TS_HAS_CERT_COMPRESSION_BROTLI", ts_has_cert_compression_brotli, json);
136+
print_feature("TS_HAS_CERT_COMPRESSION_ZSTD", ts_has_cert_compression_zstd, json);
108137
#ifdef F_GETPIPE_SZ
109138
print_feature("TS_HAS_PIPE_BUFFER_SIZE_CONFIG", 1, json);
110139
#else

tests/gold_tests/tls/tls_cert_comp.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
decompression succeed by checking the ssl cert compression metrics.
2525
'''
2626

27-
Test.SkipUnless(Condition.HasATSFeature('TS_HAS_CERT_COMPRESSION'))
27+
Test.SkipUnless(Condition.HasATSFeature('TS_HAS_CERT_COMPRESSION_CALLBACKS'))
2828

2929
REPLAY_FILE = 'replay/tls_cert_compression.replay.yaml'
3030

0 commit comments

Comments
 (0)