don't read private header for QUIC Version >= 34

ref #55
This commit is contained in:
Marten Seemann 2016-06-11 10:43:31 +07:00
parent c063fb1dd3
commit 3ba8ec73d8
3 changed files with 29 additions and 7 deletions

View file

@ -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

View file

@ -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,

View file

@ -15,6 +15,7 @@ const (
Version31
Version32
Version33
Version34
)
// SupportedVersions lists the versions that the server supports