Skip to content

Commit 1bb09e6

Browse files
committed
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 <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 952fc9c commit 1bb09e6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

internal/quic/packet_codec_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestRoundtripEncodeShortPacket(t *testing.T) {
185185
w.b = append(w.b, test.payload...)
186186
w.finish1RTTPacket(test.num, 0, connID, test.k)
187187
pkt := w.datagram()
188-
p, n := parse1RTTPacket(pkt, test.k, 0)
188+
p, n := parse1RTTPacket(pkt, test.k, connIDLen, 0)
189189
if n != len(pkt) {
190190
t.Errorf("parse1RTTPacket: n=%v, want %v", n, len(pkt))
191191
}

internal/quic/packet_parser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func skipLongHeaderPacket(pkt []byte) int {
146146
//
147147
// On input, pkt contains a short header packet, k the decryption keys for the packet,
148148
// and pnumMax the largest packet number seen in the number space of this packet.
149-
func parse1RTTPacket(pkt []byte, k keys, pnumMax packetNumber) (p shortPacket, n int) {
149+
func parse1RTTPacket(pkt []byte, k keys, dstConnIDLen int, pnumMax packetNumber) (p shortPacket, n int) {
150150
var err error
151-
p.payload, p.num, err = k.unprotect(pkt, 1+connIDLen, pnumMax)
151+
p.payload, p.num, err = k.unprotect(pkt, 1+dstConnIDLen, pnumMax)
152152
if err != nil {
153153
return shortPacket{}, -1
154154
}

0 commit comments

Comments
 (0)