summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2024-07-26 11:09:45 +0200
committerDaniel Gustafsson <dgustafsson@postgresql.org>2024-07-26 11:09:45 +0200
commitcc606afce1fb5c931469949f9ed8b17ec04668fb (patch)
treef6eb9abed5e7fa58ebbf1e1a75c9bd2c820f904c
parent67ab6ed4182c46077cbcf6e126484fc5e786c6eb (diff)
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 <hlinnaka@iki.fi> Reported-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20240617173803.6alnafnxpiqvlh3g@awork3.anarazel.de Backpatch-through: v12
-rwxr-xr-xconfigure9
-rw-r--r--configure.ac2
-rw-r--r--meson.build1
-rw-r--r--src/backend/libpq/be-secure-openssl.c14
-rw-r--r--src/include/pg_config.h.in3
5 files changed, 23 insertions, 6 deletions
diff --git a/configure b/configure
index 68e04f41886..b08ec2aaad8 100755
--- a/configure
+++ b/configure
@@ -13009,12 +13009,13 @@ fi
done
# Function introduced in OpenSSL 1.1.1.
- for ac_func in X509_get_signature_info
+ for ac_func in X509_get_signature_info SSL_CTX_set_num_tickets
do :
- ac_fn_c_check_func "$LINENO" "X509_get_signature_info" "ac_cv_func_X509_get_signature_info"
-if test "x$ac_cv_func_X509_get_signature_info" = xyes; then :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_X509_GET_SIGNATURE_INFO 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
diff --git a/configure.ac b/configure.ac
index 350d1159c06..7bbec1a70bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1391,7 +1391,7 @@ if test "$with_ssl" = openssl ; then
# function was removed.
AC_CHECK_FUNCS([CRYPTO_lock])
# Function introduced in OpenSSL 1.1.1.
- AC_CHECK_FUNCS([X509_get_signature_info])
+ AC_CHECK_FUNCS([X509_get_signature_info SSL_CTX_set_num_tickets])
AC_DEFINE([USE_OPENSSL], 1, [Define to 1 to build with OpenSSL support. (--with-ssl=openssl)])
elif test "$with_ssl" != no ; then
AC_MSG_ERROR([--with-ssl must specify openssl])
diff --git a/meson.build b/meson.build
index c6d3c029bd6..9da1cdb9f9a 100644
--- a/meson.build
+++ b/meson.build
@@ -1369,6 +1369,7 @@ if sslopt in ['auto', 'openssl']
# Function introduced in OpenSSL 1.1.1
['X509_get_signature_info'],
+ ['SSL_CTX_set_num_tickets'],
]
are_openssl_funcs_complete = true
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 6f0ecf8bf7b..6e53a15cbde 100644
--- a/src/backend/libpq/be-secure-openssl.c
+++ b/src/backend/libpq/be-secure-openssl.c
@@ -252,8 +252,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 174544630e3..b3680e8f175 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -529,6 +529,9 @@
/* Define to 1 if you have the `X509_get_signature_nid' function. */
#undef HAVE_X509_GET_SIGNATURE_NID
+/* 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