parse the whole Long Header, if the version is known

This commit is contained in:
Marten Seemann 2018-11-25 17:41:45 +07:00
parent b740d57c61
commit 70ce6a5814
11 changed files with 312 additions and 318 deletions

View file

@ -515,12 +515,12 @@ var _ = Describe("Client", func() {
Version: cl.version,
DestConnectionID: id,
},
extHdr: &wire.ExtendedHeader{
Header: wire.Header{IsLongHeader: true},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeRetry,
Token: []byte("foobar"),
OrigDestConnectionID: connID,
},
}},
})
})
manager.EXPECT().Add(gomock.Any(), gomock.Any())
@ -579,15 +579,13 @@ var _ = Describe("Client", func() {
DestConnectionID: id,
Version: cl.version,
},
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
Version: protocol.VersionTLS,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeRetry,
Token: []byte("foobar"),
OrigDestConnectionID: connID,
},
Version: protocol.VersionTLS,
}},
})
}).AnyTimes()
manager.EXPECT().Add(gomock.Any(), gomock.Any()).AnyTimes()

View file

@ -23,10 +23,12 @@ var _ = Describe("QUIC Proxy", func() {
makePacket := func(p protocol.PacketNumber, payload []byte) []byte {
b := &bytes.Buffer{}
hdr := wire.ExtendedHeader{
PacketNumber: p,
PacketNumberLen: protocol.PacketNumberLen4,
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0, 0, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0, 0, 0x13, 0x37},
Header: wire.Header{
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0, 0, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0, 0, 0x13, 0x37},
},
PacketNumber: p,
PacketNumberLen: protocol.PacketNumberLen4,
}
Expect(hdr.Write(b, protocol.VersionWhatever)).To(Succeed())
raw := b.Bytes()

View file

@ -4,10 +4,8 @@ import (
"bytes"
"crypto/rand"
"fmt"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/qerr"
"github.com/lucas-clemente/quic-go/internal/utils"
)
@ -17,18 +15,10 @@ type ExtendedHeader struct {
Raw []byte
OrigDestConnectionID protocol.ConnectionID // only needed in the Retry packet
PacketNumberLen protocol.PacketNumberLen
PacketNumber protocol.PacketNumber
IsVersionNegotiation bool
SupportedVersions []protocol.VersionNumber // Version Number sent in a Version Negotiation Packet by the server
Type protocol.PacketType
KeyPhase int
Length protocol.ByteCount
Token []byte
}
func (h *ExtendedHeader) parse(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) {
@ -39,55 +29,15 @@ func (h *ExtendedHeader) parse(b *bytes.Reader, v protocol.VersionNumber) (*Exte
}
func (h *ExtendedHeader) parseLongHeader(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) {
h.Type = protocol.PacketType(h.typeByte & 0x7f)
if h.Type != protocol.PacketTypeInitial && h.Type != protocol.PacketTypeRetry && h.Type != protocol.PacketType0RTT && h.Type != protocol.PacketTypeHandshake {
return nil, qerr.Error(qerr.InvalidPacketHeader, fmt.Sprintf("Received packet with invalid packet type: %d", h.Type))
}
if h.Type == protocol.PacketTypeRetry {
odcilByte, err := b.ReadByte()
if err != nil {
return nil, err
}
odcil := decodeSingleConnIDLen(odcilByte & 0xf)
h.OrigDestConnectionID, err = protocol.ReadConnectionID(b, odcil)
if err != nil {
return nil, err
}
h.Token = make([]byte, b.Len())
if _, err := io.ReadFull(b, h.Token); err != nil {
return nil, err
}
return h, nil
}
if h.Type == protocol.PacketTypeInitial {
tokenLen, err := utils.ReadVarInt(b)
if err != nil {
return nil, err
}
if tokenLen > uint64(b.Len()) {
return nil, io.EOF
}
h.Token = make([]byte, tokenLen)
if _, err := io.ReadFull(b, h.Token); err != nil {
return nil, err
}
}
pl, err := utils.ReadVarInt(b)
if err != nil {
return nil, err
}
h.Length = protocol.ByteCount(pl)
pn, pnLen, err := utils.ReadVarIntPacketNumber(b)
if err != nil {
return nil, err
}
h.PacketNumber = pn
h.PacketNumberLen = pnLen
return h, nil
}
@ -100,7 +50,6 @@ func (h *ExtendedHeader) parseShortHeader(b *bytes.Reader, v protocol.VersionNum
}
h.PacketNumber = pn
h.PacketNumberLen = pnLen
return h, nil
}
@ -112,7 +61,6 @@ func (h *ExtendedHeader) Write(b *bytes.Buffer, ver protocol.VersionNumber) erro
return h.writeShortHeader(b, ver)
}
// TODO: add support for the key phase
func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumber) error {
b.WriteByte(byte(0x80 | h.Type))
utils.BigEndian.WriteUint32(b, uint32(h.Version))
@ -148,6 +96,7 @@ func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumb
return utils.WriteVarIntPacketNumber(b, h.PacketNumber, h.PacketNumberLen)
}
// TODO: add support for the key phase
func (h *ExtendedHeader) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) error {
typeByte := byte(0x30)
typeByte |= byte(h.KeyPhase << 6)
@ -215,14 +164,3 @@ func encodeSingleConnIDLen(id protocol.ConnectionID) (byte, error) {
}
return byte(len - 3), nil
}
func decodeConnIDLen(enc byte) (int /*dest conn id len*/, int /*src conn id len*/) {
return decodeSingleConnIDLen(enc >> 4), decodeSingleConnIDLen(enc & 0xf)
}
func decodeSingleConnIDLen(enc uint8) int {
if enc == 0 {
return 0
}
return int(enc) + 3
}

View file

@ -37,9 +37,9 @@ var _ = Describe("Header", func() {
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe},
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad, 0x0, 0x0, 0x13, 0x37},
Version: 0x1020304,
Length: 0xcafe,
Type: 0x5,
},
Length: 0xcafe,
Type: 0x5,
PacketNumber: 0xdecaf,
PacketNumberLen: protocol.PacketNumberLen4,
}).Write(buf, versionIETFHeader)).To(Succeed())
@ -62,8 +62,8 @@ var _ = Describe("Header", func() {
SrcConnectionID: srcConnID,
DestConnectionID: protocol.ConnectionID{1, 2, 3}, // connection IDs must be at least 4 bytes long
Version: 0x1020304,
Type: 0x5,
},
Type: 0x5,
PacketNumber: 0xdecafbad,
PacketNumberLen: protocol.PacketNumberLen4,
}).Write(buf, versionIETFHeader)
@ -77,8 +77,8 @@ var _ = Describe("Header", func() {
SrcConnectionID: srcConnID,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, // connection IDs must be at most 18 bytes long
Version: 0x1020304,
Type: 0x5,
},
Type: 0x5,
PacketNumber: 0xdecafbad,
PacketNumberLen: protocol.PacketNumberLen4,
}).Write(buf, versionIETFHeader)
@ -92,8 +92,8 @@ var _ = Describe("Header", func() {
SrcConnectionID: srcConnID,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, // connection IDs must be at most 18 bytes long
Version: 0x1020304,
Type: 0x5,
},
Type: 0x5,
PacketNumber: 0xdecafbad,
PacketNumberLen: protocol.PacketNumberLen4,
}).Write(buf, versionIETFHeader)
@ -107,9 +107,9 @@ var _ = Describe("Header", func() {
Header: Header{
IsLongHeader: true,
Version: 0x1020304,
Type: protocol.PacketTypeInitial,
Token: token,
},
Type: protocol.PacketTypeInitial,
Token: token,
PacketNumber: 0xdecafbad,
PacketNumberLen: protocol.PacketNumberLen4,
}).Write(buf, versionIETFHeader)).To(Succeed())
@ -119,15 +119,13 @@ var _ = Describe("Header", func() {
It("writes a Retry packet", func() {
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
Expect((&ExtendedHeader{
Header: Header{
IsLongHeader: true,
Version: 0x1020304,
},
Expect((&ExtendedHeader{Header: Header{
IsLongHeader: true,
Version: 0x1020304,
Type: protocol.PacketTypeRetry,
Token: token,
OrigDestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9},
}).Write(buf, versionIETFHeader)).To(Succeed())
}}).Write(buf, versionIETFHeader)).To(Succeed())
Expect(buf.Bytes()[:6]).To(Equal([]byte{
0x80 ^ uint8(protocol.PacketTypeRetry),
0x1, 0x2, 0x3, 0x4, // version number
@ -139,15 +137,13 @@ var _ = Describe("Header", func() {
})
It("refuses to write a Retry packet with an invalid Orig Destination Connection ID length", func() {
err := (&ExtendedHeader{
Header: Header{
IsLongHeader: true,
Version: 0x1020304,
},
err := (&ExtendedHeader{Header: Header{
IsLongHeader: true,
Version: 0x1020304,
Type: protocol.PacketTypeRetry,
Token: []byte("foobar"),
OrigDestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, // connection IDs must be at most 18 bytes long
}).Write(buf, versionIETFHeader)
}}).Write(buf, versionIETFHeader)
Expect(err).To(MatchError("invalid connection ID length: 19 bytes"))
})
})
@ -234,8 +230,8 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
Length: 1,
},
Length: 1,
PacketNumberLen: protocol.PacketNumberLen1,
}
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 8 /* src conn id */ + 1 /* short len */ + 1 /* packet number */
@ -250,8 +246,8 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
Length: 1500,
},
Length: 1500,
PacketNumberLen: protocol.PacketNumberLen2,
}
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 8 /* src conn id */ + 2 /* long len */ + 2 /* packet number */
@ -266,9 +262,9 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4},
Length: 1500,
Type: protocol.PacketTypeInitial,
},
Length: 1500,
Type: protocol.PacketTypeInitial,
PacketNumberLen: protocol.PacketNumberLen2,
}
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 4 /* src conn id */ + 1 /* token length */ + 2 /* long len */ + 2 /* packet number */
@ -283,11 +279,11 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4},
Type: protocol.PacketTypeInitial,
Length: 1500,
Token: []byte("foo"),
},
Type: protocol.PacketTypeInitial,
Length: 1500,
PacketNumberLen: protocol.PacketNumberLen2,
Token: []byte("foo"),
}
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 4 /* src conn id */ + 1 /* token length */ + 3 /* token */ + 2 /* long len */ + 2 /* packet number */
Expect(h.GetLength(versionIETFHeader)).To(BeEquivalentTo(expectedLen))
@ -352,12 +348,12 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad, 0x013, 0x37, 0x13, 0x37},
Type: protocol.PacketTypeHandshake,
Length: 54321,
Version: 0xfeed,
},
Type: protocol.PacketTypeHandshake,
PacketNumber: 0x1337,
PacketNumberLen: protocol.PacketNumberLen2,
Length: 54321,
}).Log(logger)
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Handshake, DestConnectionID: 0xdeadbeefcafe1337, SrcConnectionID: 0xdecafbad13371337, PacketNumber: 0x1337, PacketNumberLen: 2, Length: 54321, Version: 0xfeed}"))
})
@ -368,13 +364,13 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
Type: protocol.PacketTypeInitial,
Token: []byte{0xde, 0xad, 0xbe, 0xef},
Length: 100,
Version: 0xfeed,
},
Type: protocol.PacketTypeInitial,
Token: []byte{0xde, 0xad, 0xbe, 0xef},
PacketNumber: 0x42,
PacketNumberLen: protocol.PacketNumberLen2,
Length: 100,
}).Log(logger)
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Initial, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: 0xdeadbeef, PacketNumber: 0x42, PacketNumberLen: 2, Length: 100, Version: 0xfeed}"))
})
@ -385,12 +381,12 @@ var _ = Describe("Header", func() {
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
Type: protocol.PacketTypeInitial,
Length: 100,
Version: 0xfeed,
},
Type: protocol.PacketTypeInitial,
PacketNumber: 0x42,
PacketNumberLen: protocol.PacketNumberLen2,
Length: 100,
}).Log(logger)
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Initial, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: (empty), PacketNumber: 0x42, PacketNumberLen: 2, Length: 100, Version: 0xfeed}"))
})
@ -398,14 +394,14 @@ var _ = Describe("Header", func() {
It("logs Initial Packets with a Token", func() {
(&ExtendedHeader{
Header: Header{
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
Version: 0xfeed,
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
Type: protocol.PacketTypeRetry,
OrigDestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
Token: []byte{0x12, 0x34, 0x56},
Version: 0xfeed,
},
Type: protocol.PacketTypeRetry,
OrigDestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
Token: []byte{0x12, 0x34, 0x56},
}).Log(logger)
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Retry, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: 0x123456, OrigDestConnectionID: 0xdeadbeef, Version: 0xfeed}"))
})

View file

@ -2,6 +2,7 @@ package wire
import (
"bytes"
"fmt"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -15,14 +16,23 @@ type Header struct {
SrcConnectionID protocol.ConnectionID
DestConnectionID protocol.ConnectionID
SupportedVersions []protocol.VersionNumber // sent in a Version Negotiation Packet
IsLongHeader bool
typeByte byte
len int // how many bytes were read while parsing this header
Type protocol.PacketType
Length protocol.ByteCount
Token []byte
SupportedVersions []protocol.VersionNumber // sent in a Version Negotiation Packet
OrigDestConnectionID protocol.ConnectionID // sent in the Retry packet
typeByte byte
len int // how many bytes were read while parsing this header
}
// ParseHeader parses the version independent part of the header
// ParseHeader parses the header.
// For short header packets: up to the packet number.
// For long header packets:
// * if we understand the version: up to the packet number
// * if not, only the invariant part of the header
func ParseHeader(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error) {
startLen := b.Len()
h, err := parseHeaderImpl(b, shortHeaderConnIDLen)
@ -45,46 +55,107 @@ func parseHeaderImpl(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error)
}
if !h.IsLongHeader {
var err error
h.DestConnectionID, err = protocol.ReadConnectionID(b, shortHeaderConnIDLen)
if err != nil {
if err := h.parseShortHeader(b, shortHeaderConnIDLen); err != nil {
return nil, err
}
return h, nil
}
// Long Header
if err := h.parseLongHeader(b); err != nil {
return nil, err
}
return h, nil
}
func (h *Header) parseShortHeader(b *bytes.Reader, shortHeaderConnIDLen int) error {
var err error
h.DestConnectionID, err = protocol.ReadConnectionID(b, shortHeaderConnIDLen)
return err
}
func (h *Header) parseLongHeader(b *bytes.Reader) error {
v, err := utils.BigEndian.ReadUint32(b)
if err != nil {
return nil, err
return err
}
h.Version = protocol.VersionNumber(v)
connIDLenByte, err := b.ReadByte()
if err != nil {
return nil, err
return err
}
dcil, scil := decodeConnIDLen(connIDLenByte)
h.DestConnectionID, err = protocol.ReadConnectionID(b, dcil)
if err != nil {
return nil, err
return err
}
h.SrcConnectionID, err = protocol.ReadConnectionID(b, scil)
if err != nil {
return nil, err
return err
}
if h.Version == 0 {
if b.Len() == 0 {
return nil, qerr.Error(qerr.InvalidVersionNegotiationPacket, "empty version list")
return h.parseVersionNegotiationPacket(b)
}
// If we don't understand the version, we have no idea how to interpret the rest of the bytes
if !protocol.IsSupportedVersion(protocol.SupportedVersions, h.Version) {
return nil
}
h.Type = protocol.PacketType(h.typeByte & 0x7f)
if h.Type != protocol.PacketTypeInitial && h.Type != protocol.PacketTypeRetry && h.Type != protocol.PacketType0RTT && h.Type != protocol.PacketTypeHandshake {
return qerr.Error(qerr.InvalidPacketHeader, fmt.Sprintf("Received packet with invalid packet type: %d", h.Type))
}
if h.Type == protocol.PacketTypeRetry {
odcilByte, err := b.ReadByte()
if err != nil {
return err
}
h.SupportedVersions = make([]protocol.VersionNumber, b.Len()/4)
for i := 0; b.Len() > 0; i++ {
v, err := utils.BigEndian.ReadUint32(b)
if err != nil {
return nil, qerr.InvalidVersionNegotiationPacket
}
h.SupportedVersions[i] = protocol.VersionNumber(v)
odcil := decodeSingleConnIDLen(odcilByte & 0xf)
h.OrigDestConnectionID, err = protocol.ReadConnectionID(b, odcil)
if err != nil {
return err
}
h.Token = make([]byte, b.Len())
if _, err := io.ReadFull(b, h.Token); err != nil {
return err
}
return nil
}
if h.Type == protocol.PacketTypeInitial {
tokenLen, err := utils.ReadVarInt(b)
if err != nil {
return err
}
if tokenLen > uint64(b.Len()) {
return io.EOF
}
h.Token = make([]byte, tokenLen)
if _, err := io.ReadFull(b, h.Token); err != nil {
return err
}
}
return h, nil
pl, err := utils.ReadVarInt(b)
if err != nil {
return err
}
h.Length = protocol.ByteCount(pl)
return nil
}
func (h *Header) parseVersionNegotiationPacket(b *bytes.Reader) error {
if b.Len() == 0 {
return qerr.Error(qerr.InvalidVersionNegotiationPacket, "empty version list")
}
h.SupportedVersions = make([]protocol.VersionNumber, b.Len()/4)
for i := 0; b.Len() > 0; i++ {
v, err := utils.BigEndian.ReadUint32(b)
if err != nil {
return qerr.InvalidVersionNegotiationPacket
}
h.SupportedVersions[i] = protocol.VersionNumber(v)
}
return nil
}
// IsVersionNegotiation says if this a version negotiation packet
@ -104,3 +175,14 @@ func (h *Header) ParseExtended(b *bytes.Reader, ver protocol.VersionNumber) (*Ex
func (h *Header) toExtendedHeader() *ExtendedHeader {
return &ExtendedHeader{Header: *h}
}
func decodeConnIDLen(enc byte) (int /*dest conn id len*/, int /*src conn id len*/) {
return decodeSingleConnIDLen(enc >> 4), decodeSingleConnIDLen(enc & 0xf)
}
func decodeSingleConnIDLen(enc uint8) int {
if enc == 0 {
return 0
}
return int(enc) + 3
}

View file

@ -2,6 +2,7 @@ package wire
import (
"bytes"
"encoding/binary"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -18,6 +19,13 @@ var _ = Describe("Header Parsing", func() {
return append(data, buf.Bytes()...)
}
appendVersion := func(data []byte, v protocol.VersionNumber) []byte {
offset := len(data)
data = append(data, []byte{0, 0, 0, 0}...)
binary.BigEndian.PutUint32(data[offset:], uint32(versionIETFFrames))
return data
}
Context("Version Negotiation Packets", func() {
It("parses", func() {
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
@ -65,17 +73,14 @@ var _ = Describe("Header Parsing", func() {
It("parses a Long Header", func() {
destConnID := protocol.ConnectionID{9, 8, 7, 6, 5, 4, 3, 2, 1}
srcConnID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x61, // connection ID lengths
}
data := []byte{0x80 ^ uint8(protocol.PacketTypeInitial)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x61) // connection ID lengths
data = append(data, destConnID...)
data = append(data, srcConnID...)
data = append(data, encodeVarInt(6)...) // token length
data = append(data, []byte("foobar")...) // token
data = append(data, encodeVarInt(0x1337)...) // length
// packet number
data = appendPacketNumber(data, 0xbeef, protocol.PacketNumberLen4)
hdr, err := ParseHeader(bytes.NewReader(data), 0)
@ -84,29 +89,43 @@ var _ = Describe("Header Parsing", func() {
Expect(hdr.IsVersionNegotiation()).To(BeFalse())
Expect(hdr.DestConnectionID).To(Equal(destConnID))
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
Expect(hdr.Type).To(Equal(protocol.PacketTypeInitial))
Expect(hdr.Token).To(Equal([]byte("foobar")))
Expect(hdr.Length).To(Equal(protocol.ByteCount(0x1337)))
Expect(hdr.Version).To(Equal(versionIETFFrames))
b := bytes.NewReader(data)
extHdr, err := hdr.ParseExtended(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(extHdr.Type).To(Equal(protocol.PacketTypeInitial))
Expect(extHdr.IsLongHeader).To(BeTrue())
Expect(extHdr.DestConnectionID).To(Equal(destConnID))
Expect(extHdr.SrcConnectionID).To(Equal(srcConnID))
Expect(extHdr.Token).To(Equal([]byte("foobar")))
Expect(extHdr.Length).To(Equal(protocol.ByteCount(0x1337)))
Expect(extHdr.PacketNumber).To(Equal(protocol.PacketNumber(0xbeef)))
Expect(extHdr.PacketNumberLen).To(Equal(protocol.PacketNumberLen4))
Expect(extHdr.Version).To(Equal(protocol.VersionNumber(0x1020304)))
Expect(b.Len()).To(BeZero())
})
It("parses a Long Header without a destination connection ID", func() {
It("stops parsing when encountering an unsupported version", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x01, // connection ID lengths
0xde, 0xad, 0xbe, 0xef, // source connection ID
0xde, 0xad, 0xbe, 0xef,
0x55, // connection ID length
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1,
'f', 'o', 'o', 'b', 'a', 'r', // unspecified bytes
}
data = append(data, encodeVarInt(0x42)...) // length
b := bytes.NewReader(data)
hdr, err := ParseHeader(b, 0)
Expect(err).ToNot(HaveOccurred())
Expect(hdr.IsLongHeader).To(BeTrue())
Expect(hdr.Version).To(Equal(protocol.VersionNumber(0xdeadbeef)))
Expect(hdr.DestConnectionID).To(Equal(protocol.ConnectionID{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}))
Expect(hdr.SrcConnectionID).To(Equal(protocol.ConnectionID{0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1}))
Expect(b.Len()).To(Equal(6))
})
It("parses a Long Header without a destination connection ID", func() {
data := []byte{0x80 ^ uint8(protocol.PacketTypeHandshake)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x01) // connection ID lengths
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef}...) // source connection ID
data = append(data, encodeVarInt(0x42)...) // length
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
hdr, err := ParseHeader(bytes.NewReader(data), 0)
Expect(err).ToNot(HaveOccurred())
@ -115,13 +134,11 @@ var _ = Describe("Header Parsing", func() {
})
It("parses a Long Header without a source connection ID", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x70, // connection ID lengths
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // source connection ID
}
data = append(data, encodeVarInt(0x42)...) // length
data := []byte{0x80 ^ uint8(protocol.PacketTypeHandshake)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x70) // connection ID lengths
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
data = append(data, encodeVarInt(0x42)...) // length
data = append(data, []byte{0xde, 0xca, 0xfb, 0xad}...)
hdr, err := ParseHeader(bytes.NewReader(data), 0)
Expect(err).ToNot(HaveOccurred())
@ -130,13 +147,11 @@ var _ = Describe("Header Parsing", func() {
})
It("parses a Long Header with a 2 byte packet number", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x0, // connection ID lengths
}
data = append(data, encodeVarInt(0)...) // token length
data = append(data, encodeVarInt(0x42)...) // length
data := []byte{0x80 ^ uint8(protocol.PacketTypeInitial)}
data = appendVersion(data, versionIETFFrames) // version number
data = append(data, 0x0) // connection ID lengths
data = append(data, encodeVarInt(0)...) // token length
data = append(data, encodeVarInt(0x42)...) // length
data = appendPacketNumber(data, 0x123, protocol.PacketNumberLen2)
hdr, err := ParseHeader(bytes.NewReader(data), 0)
@ -150,23 +165,18 @@ var _ = Describe("Header Parsing", func() {
})
It("parses a Retry packet", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeRetry),
0x1, 0x2, 0x3, 0x4, // version number
0x0, // connection ID lengths
0x97, // Orig Destination Connection ID length
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // source connection ID
'f', 'o', 'o', 'b', 'a', 'r', // token
}
hdr, err := ParseHeader(bytes.NewReader(data), 0)
Expect(err).ToNot(HaveOccurred())
data := []byte{0x80 ^ uint8(protocol.PacketTypeRetry)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x0) // connection ID lengths
data = append(data, 0x97) // Orig Destination Connection ID length
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
data = append(data, []byte{'f', 'o', 'o', 'b', 'a', 'r'}...) // token
b := bytes.NewReader(data)
extHdr, err := hdr.ParseExtended(b, versionIETFFrames)
hdr, err := ParseHeader(b, 0)
Expect(err).ToNot(HaveOccurred())
Expect(extHdr.Type).To(Equal(protocol.PacketTypeRetry))
Expect(extHdr.OrigDestConnectionID).To(Equal(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}))
Expect(extHdr.Token).To(Equal([]byte("foobar")))
Expect(b.Len()).To(BeZero())
Expect(hdr.Type).To(Equal(protocol.PacketTypeRetry))
Expect(hdr.OrigDestConnectionID).To(Equal(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}))
Expect(hdr.Token).To(Equal([]byte("foobar")))
})
It("rejects packets sent with an unknown packet type", func() {
@ -175,45 +185,37 @@ var _ = Describe("Header Parsing", func() {
Expect((&ExtendedHeader{
Header: Header{
IsLongHeader: true,
Type: 42,
SrcConnectionID: srcConnID,
Version: 0x10203040,
Version: versionIETFFrames,
},
Type: 42,
PacketNumber: 1,
PacketNumberLen: protocol.PacketNumberLen1,
}).Write(buf, protocol.VersionTLS)).To(Succeed())
b := bytes.NewReader(buf.Bytes())
hdr, err := ParseHeader(b, 0)
Expect(err).ToNot(HaveOccurred())
_, err = hdr.ParseExtended(b, versionIETFFrames)
_, err := ParseHeader(b, 0)
Expect(err).To(MatchError("InvalidPacketHeader: Received packet with invalid packet type: 42"))
})
It("errors if the token length is too large", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x0, // connection ID lengths
}
data := []byte{0x80 ^ uint8(protocol.PacketTypeInitial)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x0) // connection ID lengths
data = append(data, encodeVarInt(4)...) // token length: 4 bytes (1 byte too long)
data = append(data, encodeVarInt(0x42)...) // length, 1 byte
data = appendPacketNumber(data, 0x123, protocol.PacketNumberLen2) // 2 bytes
b := bytes.NewReader(data)
hdr, err := ParseHeader(b, 0)
Expect(err).ToNot(HaveOccurred())
_, err = hdr.ParseExtended(b, versionIETFFrames)
_, err := ParseHeader(b, 0)
Expect(err).To(MatchError(io.EOF))
})
It("errors on EOF, when parsing the header", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x55, // connection ID lengths
0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37, // destination connection ID
0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37, // source connection ID
}
data := []byte{0x80 ^ uint8(protocol.PacketTypeInitial)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x55) // connection ID lengths
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}...) // destination connection ID
data = append(data, []byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}...) // source connection ID
for i := 0; i < len(data); i++ {
_, err := ParseHeader(bytes.NewReader(data[:i]), 0)
Expect(err).To(Equal(io.EOF))
@ -221,13 +223,11 @@ var _ = Describe("Header Parsing", func() {
})
It("errors on EOF, when parsing the extended header", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeInitial),
0x1, 0x2, 0x3, 0x4, // version number
0x0, // connection ID lengths
}
hdrLen := len(data)
data := []byte{0x80 ^ uint8(protocol.PacketTypeHandshake)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x0) // connection ID lengths
data = append(data, encodeVarInt(0x1337)...)
hdrLen := len(data)
data = appendPacketNumber(data, 0xdeadbeef, protocol.PacketNumberLen4)
for i := hdrLen; i < len(data); i++ {
b := bytes.NewReader(data[:i])
@ -239,16 +239,12 @@ var _ = Describe("Header Parsing", func() {
})
It("errors on EOF, for a Retry packet", func() {
data := []byte{
0x80 ^ uint8(protocol.PacketTypeRetry),
0x1, 0x2, 0x3, 0x4, // version number
0x0, // connection ID lengths
}
data := []byte{0x80 ^ uint8(protocol.PacketTypeRetry)}
data = appendVersion(data, versionIETFFrames)
data = append(data, 0x0) // connection ID lengths
data = append(data, 0x97) // Orig Destination Connection ID length
data = append(data, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}...) // source connection ID
hdrLen := len(data)
data = append(data, []byte{
0x97, // Orig Destination Connection ID length
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // source connection ID
}...)
for i := hdrLen; i < len(data); i++ {
b := bytes.NewReader(data[:i])
hdr, err := ParseHeader(b, 0)

View file

@ -24,11 +24,11 @@ var _ = Describe("Packet Handler Map", func() {
Expect((&wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeHandshake,
DestConnectionID: connID,
Version: protocol.VersionWhatever,
Length: 1,
Version: protocol.VersionTLS,
},
Length: 1,
Type: protocol.PacketTypeHandshake,
PacketNumberLen: protocol.PacketNumberLen1,
}).Write(buf, protocol.VersionWhatever)).To(Succeed())
return buf.Bytes()
@ -131,11 +131,11 @@ var _ = Describe("Packet Handler Map", func() {
hdr := &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeHandshake,
Length: 1000,
DestConnectionID: connID,
Version: protocol.VersionWhatever,
Version: protocol.VersionTLS,
},
Type: protocol.PacketTypeHandshake,
Length: 1000,
PacketNumberLen: protocol.PacketNumberLen2,
}
buf := &bytes.Buffer{}
@ -155,10 +155,10 @@ var _ = Describe("Packet Handler Map", func() {
Header: wire.Header{
IsLongHeader: true,
DestConnectionID: connID,
Version: protocol.VersionWhatever,
Type: protocol.PacketTypeHandshake,
Length: 3,
Version: protocol.VersionTLS,
},
Type: protocol.PacketTypeHandshake,
Length: 3,
PacketNumberLen: protocol.PacketNumberLen4,
}
buf := &bytes.Buffer{}
@ -179,10 +179,10 @@ var _ = Describe("Packet Handler Map", func() {
Header: wire.Header{
IsLongHeader: true,
DestConnectionID: connID,
Version: protocol.VersionWhatever,
Type: protocol.PacketTypeHandshake,
Length: 456,
Version: protocol.VersionTLS,
},
Type: protocol.PacketTypeHandshake,
Length: 456,
PacketNumberLen: protocol.PacketNumberLen1,
}
buf := &bytes.Buffer{}

View file

@ -57,7 +57,7 @@ var _ = Describe("Packet packer", func() {
BeforeEach(func() {
rand.Seed(GinkgoRandomSeed())
version := protocol.VersionWhatever
version := protocol.VersionTLS
mockSender := NewMockStreamSender(mockCtrl)
mockSender.EXPECT().onHasStreamData(gomock.Any()).AnyTimes()
initialStream = NewMockCryptoStream(mockCtrl)

View file

@ -49,14 +49,12 @@ var _ = Describe("Server Session", func() {
It("ignores packets with the wrong Long Header type", func() {
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
p := &receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
Version: protocol.VersionNumber(100),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
},
Type: protocol.PacketTypeRetry,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeRetry,
Version: protocol.VersionNumber(100),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
}},
}
err := sess.handlePacketImpl(p)
Expect(err).To(MatchError("Received unsupported packet type: Retry"))
@ -64,14 +62,12 @@ var _ = Describe("Server Session", func() {
It("passes on Handshake packets", func() {
p := &receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
Version: protocol.VersionNumber(100),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
},
Type: protocol.PacketTypeHandshake,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeHandshake,
Version: protocol.VersionNumber(100),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
}},
}
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
qsess.EXPECT().handlePacket(p)

View file

@ -98,38 +98,32 @@ var _ = Describe("Server", func() {
serv = ln.(*server)
})
parseHeader := func(data []byte) *wire.ExtendedHeader {
parseHeader := func(data []byte) *wire.Header {
hdr, err := wire.ParseHeader(bytes.NewReader(data), 0)
Expect(err).ToNot(HaveOccurred())
extHdr, err := hdr.ParseExtended(bytes.NewReader(data), protocol.VersionTLS)
Expect(err).ToNot(HaveOccurred())
return extHdr
return hdr
}
It("drops Initial packets with a too short connection ID", func() {
serv.handlePacket(&receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
Version: serv.config.Versions[0],
},
Type: protocol.PacketTypeInitial,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeInitial,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
Version: serv.config.Versions[0],
}},
})
Expect(conn.dataWritten.Len()).To(BeZero())
})
It("drops too small Initial", func() {
serv.handlePacket(&receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
Version: serv.config.Versions[0],
},
Type: protocol.PacketTypeInitial,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeInitial,
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
Version: serv.config.Versions[0],
}},
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize-100),
})
Consistently(conn.dataWritten.Len).Should(BeZero())
@ -139,11 +133,11 @@ var _ = Describe("Server", func() {
hdr := &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeInitial,
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
Version: serv.config.Versions[0],
},
Type: protocol.PacketTypeInitial,
PacketNumberLen: protocol.PacketNumberLen1,
}
serv.handlePacket(&receivedPacket{
@ -156,10 +150,10 @@ var _ = Describe("Server", func() {
It("drops non-Initial packets", func() {
serv.logger.SetLogLevel(utils.LogLevelDebug)
serv.handlePacket(&receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{Version: serv.config.Versions[0]},
Type: protocol.PacketTypeHandshake,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
Type: protocol.PacketTypeHandshake,
Version: serv.config.Versions[0],
}},
data: []byte("invalid"),
})
})
@ -180,11 +174,11 @@ var _ = Describe("Server", func() {
Expect(err).ToNot(HaveOccurred())
serv.handlePacket(&receivedPacket{
remoteAddr: raddr,
extHdr: &wire.ExtendedHeader{
Header: wire.Header{Version: serv.config.Versions[0]},
Type: protocol.PacketTypeInitial,
Token: token,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
Type: protocol.PacketTypeInitial,
Token: token,
Version: serv.config.Versions[0],
}},
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
})
Eventually(done).Should(BeClosed())
@ -204,11 +198,11 @@ var _ = Describe("Server", func() {
}
serv.handlePacket(&receivedPacket{
remoteAddr: raddr,
extHdr: &wire.ExtendedHeader{
Header: wire.Header{Version: serv.config.Versions[0]},
Type: protocol.PacketTypeInitial,
Token: []byte("foobar"),
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
Type: protocol.PacketTypeInitial,
Token: []byte("foobar"),
Version: serv.config.Versions[0],
}},
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
})
Eventually(done).Should(BeClosed())
@ -218,15 +212,13 @@ var _ = Describe("Server", func() {
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5}
destConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6}
serv.handlePacket(&receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
SrcConnectionID: srcConnID,
DestConnectionID: destConnID,
Version: 0x42,
},
Type: protocol.PacketTypeInitial,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeInitial,
SrcConnectionID: srcConnID,
DestConnectionID: destConnID,
Version: 0x42,
}},
})
Expect(conn.dataWritten.Len()).ToNot(BeZero())
hdr, err := wire.ParseHeader(bytes.NewReader(conn.dataWritten.Bytes()), 0)
@ -239,14 +231,12 @@ var _ = Describe("Server", func() {
It("replies with a Retry packet, if a Cookie is required", func() {
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return false }
hdr := &wire.ExtendedHeader{
Header: wire.Header{
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
Version: protocol.VersionTLS,
},
Type: protocol.PacketTypeInitial,
}
hdr := &wire.ExtendedHeader{Header: wire.Header{
Type: protocol.PacketTypeInitial,
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
Version: protocol.VersionTLS,
}}
serv.handleInitial(&receivedPacket{
remoteAddr: &net.UDPAddr{},
extHdr: hdr,
@ -263,14 +253,12 @@ var _ = Describe("Server", func() {
It("creates a session, if no Cookie is required", func() {
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return true }
hdr := &wire.ExtendedHeader{
Header: wire.Header{
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
Version: protocol.VersionTLS,
},
Type: protocol.PacketTypeInitial,
}
hdr := &wire.ExtendedHeader{Header: wire.Header{
Type: protocol.PacketTypeInitial,
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
Version: protocol.VersionTLS,
}}
p := &receivedPacket{
extHdr: hdr,
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),

View file

@ -1321,14 +1321,12 @@ var _ = Describe("Client Session", func() {
newConnID := protocol.ConnectionID{1, 3, 3, 7, 1, 3, 3, 7}
packer.EXPECT().ChangeDestConnectionID(newConnID)
err := sess.handlePacketImpl(&receivedPacket{
extHdr: &wire.ExtendedHeader{
Header: wire.Header{
IsLongHeader: true,
SrcConnectionID: newConnID,
DestConnectionID: sess.srcConnID,
},
Type: protocol.PacketTypeHandshake,
},
extHdr: &wire.ExtendedHeader{Header: wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeHandshake,
SrcConnectionID: newConnID,
DestConnectionID: sess.srcConnID,
}},
data: []byte{0},
})
Expect(err).ToNot(HaveOccurred())