From 1bb09e6b1e6cbe43c5034c99133d866b60ea81fa Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Thu, 15 Jun 2023 09:52:00 -0700 Subject: [PATCH] quic: pass the connection ID length into 1-RTT packet parsing 1-RTT packets contain a variable-length connection ID field, but no indication of the length of the connection ID. The recipient of the packet has chosen the connection ID, and is expected to either choose a consistent length or encode the length in the connection ID. Change the parse1RTTPacket function to take the connection ID length as an input, rather than assuming that all 1-RTT packets contain our hardcoded connection ID length. This permits using parse1RTTPacket in tests which may create and parse packets using other lengths. For golang/go#58547 Change-Id: I9d09e4a0041051be1604c9146f6db9ca959ad696 Reviewed-on: https://go-review.googlesource.com/c/net/+/504856 Run-TryBot: Damien Neil Reviewed-by: Jonathan Amsterdam TryBot-Result: Gopher Robot --- internal/quic/packet_codec_test.go | 2 +- internal/quic/packet_parser.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/quic/packet_codec_test.go b/internal/quic/packet_codec_test.go index 499ec4dea..3503d2431 100644 --- a/internal/quic/packet_codec_test.go +++ b/internal/quic/packet_codec_test.go @@ -185,7 +185,7 @@ func TestRoundtripEncodeShortPacket(t *testing.T) { w.b = append(w.b, test.payload...) w.finish1RTTPacket(test.num, 0, connID, test.k) pkt := w.datagram() - p, n := parse1RTTPacket(pkt, test.k, 0) + p, n := parse1RTTPacket(pkt, test.k, connIDLen, 0) if n != len(pkt) { t.Errorf("parse1RTTPacket: n=%v, want %v", n, len(pkt)) } diff --git a/internal/quic/packet_parser.go b/internal/quic/packet_parser.go index e910e0eb7..908a82ed9 100644 --- a/internal/quic/packet_parser.go +++ b/internal/quic/packet_parser.go @@ -146,9 +146,9 @@ func skipLongHeaderPacket(pkt []byte) int { // // On input, pkt contains a short header packet, k the decryption keys for the packet, // and pnumMax the largest packet number seen in the number space of this packet. -func parse1RTTPacket(pkt []byte, k keys, pnumMax packetNumber) (p shortPacket, n int) { +func parse1RTTPacket(pkt []byte, k keys, dstConnIDLen int, pnumMax packetNumber) (p shortPacket, n int) { var err error - p.payload, p.num, err = k.unprotect(pkt, 1+connIDLen, pnumMax) + p.payload, p.num, err = k.unprotect(pkt, 1+dstConnIDLen, pnumMax) if err != nil { return shortPacket{}, -1 }