]> git.feebdaed.xyz Git - 0xmirror/nginx.git/commitdiff
QUIC: trial packet decryption in response to invalid key update.
authorSergey Kandaurov <pluknet@nginx.com>
Wed, 14 Feb 2024 11:55:34 +0000 (15:55 +0400)
committerSergey Kandaurov <pluknet@nginx.com>
Wed, 14 Feb 2024 11:55:34 +0000 (15:55 +0400)
Inspired by RFC 9001, Section 6.3, trial packet decryption with the current
keys is now used to avoid a timing side-channel signal.  Further, this fixes
segfault while accessing missing next keys (ticket #2585).

src/event/quic/ngx_event_quic_protection.c

index 88e6954cffb1c029a31975b61ca0d0a776627e15..8223626b65fd697dd242f484d7d86b28a21e8ff3 100644 (file)
@@ -1144,8 +1144,19 @@ ngx_quic_decrypt(ngx_quic_header_t *pkt, uint64_t *largest_pn)
         key_phase = (pkt->flags & NGX_QUIC_PKT_KPHASE) != 0;
 
         if (key_phase != pkt->key_phase) {
-            secret = &pkt->keys->next_key.client;
-            pkt->key_update = 1;
+            if (pkt->keys->next_key.client.ctx != NULL) {
+                secret = &pkt->keys->next_key.client;
+                pkt->key_update = 1;
+
+            } else {
+                /*
+                 * RFC 9001,  6.3. Timing of Receive Key Generation.
+                 *
+                 * Trial decryption to avoid timing side-channel.
+                 */
+                ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
+                               "quic next key missing");
+            }
         }
     }