From 274bbced85383e831ddeb9d83a8af74c4992e7a1 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Fri, 26 Jul 2024 11:09:45 +0200 Subject: Disable all TLS session tickets OpenSSL supports two types of session tickets for TLSv1.3, stateless and stateful. The option we've used only turns off stateless tickets leaving stateful tickets active. Use the new API introduced in 1.1.1 to disable all types of tickets. Backpatch to all supported versions. Reviewed-by: Heikki Linnakangas Reported-by: Andres Freund Discussion: https://postgr.es/m/20240617173803.6alnafnxpiqvlh3g@awork3.anarazel.de Backpatch-through: v12 --- src/backend/libpq/be-secure-openssl.c | 14 +++++++++++++- src/include/pg_config.h.in | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c index 387f30cdaa8..eed7ec7ce56 100644 --- a/src/backend/libpq/be-secure-openssl.c +++ b/src/backend/libpq/be-secure-openssl.c @@ -259,8 +259,20 @@ be_tls_init(bool isServerStart) } } - /* disallow SSL session tickets */ + /* + * Disallow SSL session tickets. OpenSSL use both stateful and stateless + * tickets for TLSv1.3, and stateless ticket for TLSv1.2. SSL_OP_NO_TICKET + * is available since 0.9.8f but only turns off stateless tickets. In + * order to turn off stateful tickets we need SSL_CTX_set_num_tickets, + * which is available since OpenSSL 1.1.1. LibreSSL 3.5.4 (from OpenBSD + * 7.1) introduced this API for compatibility, but doesn't support session + * tickets at all so it's a no-op there. + */ +#ifdef HAVE_SSL_CTX_SET_NUM_TICKETS + SSL_CTX_set_num_tickets(context, 0); +#else SSL_CTX_set_options(context, SSL_OP_NO_TICKET); +#endif /* disallow SSL session caching, too */ SSL_CTX_set_session_cache_mode(context, SSL_SESS_CACHE_OFF); diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 9862739b8e8..db3fcbecc3a 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -517,6 +517,9 @@ /* Define to 1 if you have the `X509_get_signature_info' function. */ #undef HAVE_X509_GET_SIGNATURE_INFO +/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */ +#undef HAVE_SSL_CTX_SET_NUM_TICKETS + /* Define to 1 if the assembler supports X86_64's POPCNTQ instruction. */ #undef HAVE_X86_64_POPCNTQ -- cgit v1.2.3