diff --git a/packet_unpacker.go b/packet_unpacker.go index fc4d87eb..9b913508 100644 --- a/packet_unpacker.go +++ b/packet_unpacker.go @@ -31,11 +31,16 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, r } r = bytes.NewReader(plaintext) - privateFlag, err := r.ReadByte() - if err != nil { - return nil, qerr.MissingPayload + // read private flag byte, for QUIC Version < 34 + var entropyBit bool + if u.version < protocol.Version34 { + var privateFlag uint8 + privateFlag, err = r.ReadByte() + if err != nil { + return nil, qerr.MissingPayload + } + entropyBit = privateFlag&0x01 > 0 } - entropyBit := privateFlag&0x01 > 0 if r.Len() == 0 { return nil, qerr.MissingPayload diff --git a/packet_unpacker_test.go b/packet_unpacker_test.go index ee80398c..c73669cd 100644 --- a/packet_unpacker_test.go +++ b/packet_unpacker_test.go @@ -35,22 +35,38 @@ var _ = Describe("Packet unpacker", func() { }) setReader := func(data []byte) { - r = bytes.NewReader(aead.Seal(0, hdrBin, append([]byte{0x01}, data...))) + if unpacker.version < protocol.Version34 { // add private flag + data = append([]byte{0x01}, data...) + } + r = bytes.NewReader(aead.Seal(0, hdrBin, data)) } - It("returns an error for empty packets that don't have a private flag", func() { + It("returns an error for empty packets that don't have a private flag, for QUIC Version < 34", func() { // don't use setReader here, since it adds a private flag + unpacker.version = protocol.Version33 r = bytes.NewReader(aead.Seal(0, hdrBin, []byte{})) _, err := unpacker.Unpack(hdrBin, hdr, r) Expect(err).To(MatchError(qerr.MissingPayload)) }) - It("returns an error for empty packets that have a private flag", func() { + It("returns an error for empty packets that have a private flag, for QUIC Version < 34", func() { + unpacker.version = protocol.Version33 setReader(nil) _, err := unpacker.Unpack(hdrBin, hdr, r) Expect(err).To(MatchError(qerr.MissingPayload)) }) + It("does not read read a private flag for QUIC Version >= 34", func() { + unpacker.version = protocol.Version34 + f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"} + err := f.Write(buf, 0) + Expect(err).ToNot(HaveOccurred()) + setReader(buf.Bytes()) + packet, err := unpacker.Unpack(hdrBin, hdr, r) + Expect(err).ToNot(HaveOccurred()) + Expect(packet.frames).To(Equal([]frames.Frame{f})) + }) + It("unpacks stream frames", func() { f := &frames.StreamFrame{ StreamID: 1, diff --git a/protocol/version.go b/protocol/version.go index f13be7cf..bf646c2c 100644 --- a/protocol/version.go +++ b/protocol/version.go @@ -15,6 +15,7 @@ const ( Version31 Version32 Version33 + Version34 ) // SupportedVersions lists the versions that the server supports