]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix TLS session resumption via IDs when Mutual TLS is used
authorArtem Boldariev <artem@boldariev.com>
Fri, 9 Dec 2022 16:44:01 +0000 (18:44 +0200)
committerArtem Boldariev <artem@boldariev.com>
Wed, 14 Dec 2022 16:06:20 +0000 (18:06 +0200)
This commit fixes TLS session resumption via session IDs when
client certificates are used. To do so it makes sure that session ID
contexts are set within server TLS contexts. See OpenSSL documentation
for 'SSL_CTX_set_session_id_context()', the "Warnings" section.

lib/isc/include/isc/tls.h
lib/isc/tls.c
lib/ns/listenlist.c

index 26c684d6a2aacbc9b3b46156c4644500f7e0b729..24577ec13d7bd1a956649ac0783024a3e8297d79 100644 (file)
@@ -563,6 +563,26 @@ isc_tlsctx_cache_find(
  *             relation between stores and contexts.
  */
 
+void
+isc_tlsctx_set_random_session_id_context(isc_tlsctx_t *ctx);
+/*%<
+ * Set context within which session can be reused to a randomly
+ * generated value. This one is used for TLS session resumption using
+ * session IDs. See OpenSSL documentation for
+ * 'SSL_CTX_set_session_id_context()'.
+ *
+ * It might be worth noting that usually session ID contexts are kept
+ * static for an application and particular certificate
+ * combination. However, for the cases when exporting server side TLS
+ * session cache to/loading from external memory is not required, we
+ * might use random IDs just fine. See,
+ * e.g. 'ngx_ssl_session_id_context()' in NGINX for an example of how
+ * a session ID might be obtained.
+ *
+ * Requires:
+ *\li   'ctx' - a valid non-NULL pointer;
+ */
+
 void
 isc__tls_initialize(void);
 
index c027ed91e04899306aa804bb7fe64e2aad44bcfe..a7d9a933327e1cef382f6783e6c85f1de00dd465 100644 (file)
@@ -1728,3 +1728,16 @@ isc_tlsctx_client_session_cache_getctx(
        REQUIRE(VALID_TLSCTX_CLIENT_SESSION_CACHE(cache));
        return (cache->ctx);
 }
+
+void
+isc_tlsctx_set_random_session_id_context(isc_tlsctx_t *ctx) {
+       uint8_t session_id_ctx[SSL_MAX_SID_CTX_LENGTH] = { 0 };
+       const size_t len = ISC_MIN(20, sizeof(session_id_ctx));
+
+       REQUIRE(ctx != NULL);
+
+       RUNTIME_CHECK(RAND_bytes(session_id_ctx, len) == 1);
+
+       RUNTIME_CHECK(
+               SSL_CTX_set_session_id_context(ctx, session_id_ctx, len) == 1);
+}
index df9719f5e14fb0127815e1d7f8e3c2949d104e21..d864ca97f17b949d6819dc8a430b4cd2f3796560 100644 (file)
@@ -64,6 +64,17 @@ listenelt_create(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
                                goto tls_error;
                        }
 
+                       /*
+                        * We need to initialise session ID context to make TLS
+                        * session resumption work correctly - in particular in
+                        * the case when client certificates are used (Mutual
+                        * TLS) - otherwise resumption attempts will lead to
+                        * handshake failures. See OpenSSL documentation for
+                        * 'SSL_CTX_set_session_id_context()', the "Warnings"
+                        * section.
+                        */
+                       isc_tlsctx_set_random_session_id_context(sslctx);
+
                        /*
                         * If CA-bundle file is specified - enable client
                         * certificates validation.