Skip to content

Commit

Permalink
quic: pass the connection ID length into 1-RTT packet parsing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
neild committed Jun 27, 2023
1 parent 952fc9c commit 1bb09e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/quic/packet_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/quic/packet_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1bb09e6

Please sign in to comment.