mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
store the encryption level in the unpacked packet
This commit is contained in:
parent
a972c7a21e
commit
f88cbd801b
3 changed files with 24 additions and 6 deletions
|
@ -23,7 +23,7 @@ type packetUnpacker struct {
|
||||||
func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, data []byte) (*unpackedPacket, error) {
|
func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, data []byte) (*unpackedPacket, error) {
|
||||||
buf := getPacketBuffer()
|
buf := getPacketBuffer()
|
||||||
defer putPacketBuffer(buf)
|
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 {
|
if err != nil {
|
||||||
// Wrap err in quicError so that public reset is sent by session
|
// Wrap err in quicError so that public reset is sent by session
|
||||||
return nil, qerr.Error(qerr.DecryptionFailure, err.Error())
|
return nil, qerr.Error(qerr.DecryptionFailure, err.Error())
|
||||||
|
@ -104,6 +104,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
|
||||||
}
|
}
|
||||||
|
|
||||||
return &unpackedPacket{
|
return &unpackedPacket{
|
||||||
frames: fs,
|
encryptionLevel: encryptionLevel,
|
||||||
|
frames: fs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,13 @@ import (
|
||||||
. "github.com/onsi/gomega"
|
. "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) {
|
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)
|
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 {
|
func (m *mockAEAD) Seal(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) []byte {
|
||||||
return (&crypto.NullAEAD{}).Seal(dst, src, packetNumber, associatedData)
|
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}))
|
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() {
|
It("unpacks STREAM frames", func() {
|
||||||
f := &frames.StreamFrame{
|
f := &frames.StreamFrame{
|
||||||
StreamID: 1,
|
StreamID: 1,
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package quic
|
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 {
|
type unpackedPacket struct {
|
||||||
frames []frames.Frame
|
encryptionLevel protocol.EncryptionLevel
|
||||||
|
frames []frames.Frame
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *unpackedPacket) IsRetransmittable() bool {
|
func (u *unpackedPacket) IsRetransmittable() bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue