store the encryption level in the unpacked packet

This commit is contained in:
Marten Seemann 2017-02-24 13:16:30 +07:00
parent a972c7a21e
commit f88cbd801b
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
3 changed files with 24 additions and 6 deletions

View file

@ -23,7 +23,7 @@ type packetUnpacker struct {
func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, data []byte) (*unpackedPacket, error) {
buf := getPacketBuffer()
defer putPacketBuffer(buf)
decrypted, _, err := u.aead.Open(buf, data, hdr.PacketNumber, publicHeaderBinary)
decrypted, encryptionLevel, err := u.aead.Open(buf, data, hdr.PacketNumber, publicHeaderBinary)
if err != nil {
// Wrap err in quicError so that public reset is sent by session
return nil, qerr.Error(qerr.DecryptionFailure, err.Error())
@ -104,6 +104,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
}
return &unpackedPacket{
frames: fs,
encryptionLevel: encryptionLevel,
frames: fs,
}, nil
}

View file

@ -12,11 +12,13 @@ import (
. "github.com/onsi/gomega"
)
type mockAEAD struct{}
type mockAEAD struct {
encLevelOpen protocol.EncryptionLevel
}
func (m *mockAEAD) Open(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) ([]byte, protocol.EncryptionLevel, error) {
res, err := (&crypto.NullAEAD{}).Open(dst, src, packetNumber, associatedData)
return res, protocol.EncryptionUnspecified, err
return res, m.encLevelOpen, err
}
func (m *mockAEAD) Seal(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) []byte {
return (&crypto.NullAEAD{}).Seal(dst, src, packetNumber, associatedData)
@ -58,6 +60,17 @@ var _ = Describe("Packet unpacker", func() {
Expect(packet.frames).To(Equal([]frames.Frame{f}))
})
It("saves the encryption level", func() {
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionSecure
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.encryptionLevel).To(Equal(protocol.EncryptionSecure))
})
It("unpacks STREAM frames", func() {
f := &frames.StreamFrame{
StreamID: 1,

View file

@ -1,9 +1,13 @@
package quic
import "github.com/lucas-clemente/quic-go/frames"
import (
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol"
)
type unpackedPacket struct {
frames []frames.Frame
encryptionLevel protocol.EncryptionLevel
frames []frames.Frame
}
func (u *unpackedPacket) IsRetransmittable() bool {