reject unencrypted stream data on all streams except stream 1

fixes #440
This commit is contained in:
Marten Seemann 2017-02-24 13:35:37 +07:00
parent f88cbd801b
commit a97faf0bea
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
2 changed files with 48 additions and 13 deletions

View file

@ -49,6 +49,11 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
frame, err = frames.ParseStreamFrame(r)
if err != nil {
err = qerr.Error(qerr.InvalidStreamData, err.Error())
} else {
streamID := frame.(*frames.StreamFrame).StreamID
if streamID != 1 && encryptionLevel <= protocol.EncryptionUnencrypted {
err = qerr.Error(qerr.UnencryptedStreamData, fmt.Sprintf("received unencrypted stream data on stream %d", streamID))
}
}
} else if typeByte&0xc0 == 0x40 {
frame, err = frames.ParseAckFrame(r, u.version)

View file

@ -71,19 +71,6 @@ var _ = Describe("Packet unpacker", func() {
Expect(packet.encryptionLevel).To(Equal(protocol.EncryptionSecure))
})
It("unpacks STREAM frames", func() {
f := &frames.StreamFrame{
StreamID: 1,
Data: []byte("foobar"),
}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{f}))
})
It("unpacks ACK frames", func() {
unpacker.version = protocol.Version34
f := &frames.AckFrame{
@ -235,4 +222,47 @@ var _ = Describe("Packet unpacker", func() {
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(e))
}
})
Context("unpacking STREAM frames", func() {
It("unpacks unencrypted STREAM frames on stream 1", func() {
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted
f := &frames.StreamFrame{
StreamID: 1,
Data: []byte("foobar"),
}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{f}))
})
It("unpacks encrypted STREAM frames on stream 1", func() {
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionSecure
f := &frames.StreamFrame{
StreamID: 1,
Data: []byte("foobar"),
}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.frames).To(Equal([]frames.Frame{f}))
})
It("does not unpack unencrypted STREAM frames on higher streams", func() {
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionUnencrypted
f := &frames.StreamFrame{
StreamID: 3,
Data: []byte("foobar"),
}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
_, err = unpacker.Unpack(hdrBin, hdr, data)
Expect(err).To(MatchError(qerr.Error(qerr.UnencryptedStreamData, "received unencrypted stream data on stream 3")))
})
})
})