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 <dneil@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/internal/quic/packet_codec_test.go b/internal/quic/packet_codec_test.go index 499ec4d..3503d24 100644 --- a/internal/quic/packet_codec_test.go +++ b/internal/quic/packet_codec_test.go
@@ -185,7 +185,7 @@ 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 e910e0e..908a82e 100644 --- a/internal/quic/packet_parser.go +++ b/internal/quic/packet_parser.go
@@ -146,9 +146,9 @@ // // 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 }