]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: quic: Stop hardcoding Retry packet Version field
authorFrédéric Lécaille <flecaille@haproxy.com>
Tue, 7 Jun 2022 09:39:00 +0000 (11:39 +0200)
committerFrédéric Lécaille <flecaille@haproxy.com>
Thu, 16 Jun 2022 12:56:24 +0000 (14:56 +0200)
Use the same version as the one received. This is safe because the
version is treated before anything else sending a Version packet.

Must be backported to 2.6.

src/xprt_quic.c

index 0e7949c06bb3fc1872d1e85e587a5fd35887e2b4..50d8e03960681b5f490f04e1e95294ced4fb6026 100644 (file)
@@ -4927,16 +4927,20 @@ static int quic_retry_token_check(unsigned char *token, size_t tokenlen,
        aadlen = quic_generate_retry_token_aad(aad, version, dcid, addr);
        salt = token + tokenlen - QUIC_RETRY_TOKEN_SALTLEN;
        if (!quic_tls_derive_retry_token_secret(EVP_sha256(), key, sizeof key, iv, sizeof iv,
-                                               salt, QUIC_RETRY_TOKEN_SALTLEN, sec, seclen))
+                                               salt, QUIC_RETRY_TOKEN_SALTLEN, sec, seclen)) {
+               TRACE_PROTO("Could not derive retry secret", QUIC_EV_CONN_LPKT, qc);
                return 0;
+       }
 
        if (!quic_tls_rx_ctx_init(&ctx, aead, key))
                goto err;
 
        /* Do not decrypt the QUIC_TOKEN_FMT_RETRY byte */
        if (!quic_tls_decrypt2(buf, token + 1, tokenlen - QUIC_RETRY_TOKEN_SALTLEN - 1, aad, aadlen,
-                              ctx, aead, key, iv))
+                              ctx, aead, key, iv)) {
+               TRACE_PROTO("Could not decrypt retry token", QUIC_EV_CONN_LPKT, qc);
                goto err;
+       }
 
        if (parse_retry_token(buf, buf + tokenlen - QUIC_RETRY_TOKEN_SALTLEN - 1, odcid)) {
                TRACE_PROTO("Error during Initial token parsing", QUIC_EV_CONN_LPKT, qc);
@@ -4968,10 +4972,10 @@ static int send_retry(int fd, struct sockaddr_storage *addr,
        /* long header + fixed bit + packet type 0x3 */
        buf[i++] = 0xf0;
        /* version */
-       buf[i++] = 0x00;
-       buf[i++] = 0x00;
-       buf[i++] = 0x00;
-       buf[i++] = 0x01;
+       buf[i++] = *((unsigned char *)&pkt->version + 3);
+       buf[i++] = *((unsigned char *)&pkt->version + 2);
+       buf[i++] = *((unsigned char *)&pkt->version + 1);
+       buf[i++] = *(unsigned char *)&pkt->version;
 
        /* Use the SCID from <pkt> for Retry DCID. */
        buf[i++] = pkt->scid.len;