mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 20:57:36 +03:00
use a sentinel error when a sealer is not yet available
This commit is contained in:
parent
d00828b762
commit
3db60534cf
5 changed files with 11 additions and 11 deletions
|
@ -576,7 +576,7 @@ func (h *cryptoSetup) GetHandshakeSealer() (LongHeaderSealer, error) {
|
||||||
if h.initialSealer == nil {
|
if h.initialSealer == nil {
|
||||||
return nil, ErrKeysDropped
|
return nil, ErrKeysDropped
|
||||||
}
|
}
|
||||||
return nil, errors.New("CryptoSetup: no sealer with encryption level Handshake")
|
return nil, ErrKeysNotYetAvailable
|
||||||
}
|
}
|
||||||
return h.handshakeSealer, nil
|
return h.handshakeSealer, nil
|
||||||
}
|
}
|
||||||
|
@ -586,7 +586,7 @@ func (h *cryptoSetup) Get1RTTSealer() (ShortHeaderSealer, error) {
|
||||||
defer h.mutex.Unlock()
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
if !h.has1RTTSealer {
|
if !h.has1RTTSealer {
|
||||||
return nil, errors.New("CryptoSetup: no sealer with encryption level 1-RTT")
|
return nil, ErrKeysNotYetAvailable
|
||||||
}
|
}
|
||||||
return h.aead, nil
|
return h.aead, nil
|
||||||
}
|
}
|
||||||
|
@ -607,7 +607,7 @@ func (h *cryptoSetup) GetHandshakeOpener() (LongHeaderOpener, error) {
|
||||||
|
|
||||||
if h.handshakeOpener == nil {
|
if h.handshakeOpener == nil {
|
||||||
if h.initialOpener != nil {
|
if h.initialOpener != nil {
|
||||||
return nil, ErrOpenerNotYetAvailable
|
return nil, ErrKeysNotYetAvailable
|
||||||
}
|
}
|
||||||
// if the initial opener is also not available, the keys were already dropped
|
// if the initial opener is also not available, the keys were already dropped
|
||||||
return nil, ErrKeysDropped
|
return nil, ErrKeysDropped
|
||||||
|
@ -620,7 +620,7 @@ func (h *cryptoSetup) Get1RTTOpener() (ShortHeaderOpener, error) {
|
||||||
defer h.mutex.Unlock()
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
if !h.has1RTTOpener {
|
if !h.has1RTTOpener {
|
||||||
return nil, ErrOpenerNotYetAvailable
|
return nil, ErrKeysNotYetAvailable
|
||||||
}
|
}
|
||||||
return h.aead, nil
|
return h.aead, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrOpenerNotYetAvailable is returned when an opener is requested for an encryption level,
|
// ErrKeysNotYetAvailable is returned when an opener or a sealer is requested for an encryption level,
|
||||||
// but the corresponding opener has not yet been initialized
|
// but the corresponding opener has not yet been initialized
|
||||||
// This can happen when packets arrive out of order.
|
// This can happen when packets arrive out of order.
|
||||||
ErrOpenerNotYetAvailable = errors.New("CryptoSetup: opener at this encryption level not yet available")
|
ErrKeysNotYetAvailable = errors.New("CryptoSetup: keys at this encryption level not yet available")
|
||||||
// ErrKeysDropped is returned when an opener or a sealer is requested for an encryption level,
|
// ErrKeysDropped is returned when an opener or a sealer is requested for an encryption level,
|
||||||
// but the corresponding keys have already been dropped.
|
// but the corresponding keys have already been dropped.
|
||||||
ErrKeysDropped = errors.New("CryptoSetup: keys were already dropped")
|
ErrKeysDropped = errors.New("CryptoSetup: keys were already dropped")
|
||||||
|
|
|
@ -85,9 +85,9 @@ var _ = Describe("Packet Unpacker", func() {
|
||||||
PacketNumberLen: 2,
|
PacketNumberLen: 2,
|
||||||
}
|
}
|
||||||
hdr, hdrRaw := getHeader(extHdr)
|
hdr, hdrRaw := getHeader(extHdr)
|
||||||
cs.EXPECT().Get1RTTOpener().Return(nil, handshake.ErrOpenerNotYetAvailable)
|
cs.EXPECT().Get1RTTOpener().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
_, err := unpacker.Unpack(hdr, time.Now(), append(hdrRaw, payload...))
|
_, err := unpacker.Unpack(hdr, time.Now(), append(hdrRaw, payload...))
|
||||||
Expect(err).To(MatchError(handshake.ErrOpenerNotYetAvailable))
|
Expect(err).To(MatchError(handshake.ErrKeysNotYetAvailable))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns the error when unpacking fails", func() {
|
It("returns the error when unpacking fails", func() {
|
||||||
|
|
|
@ -677,7 +677,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool /
|
||||||
switch err {
|
switch err {
|
||||||
case handshake.ErrKeysDropped:
|
case handshake.ErrKeysDropped:
|
||||||
s.logger.Debugf("Dropping packet because we already dropped the keys.")
|
s.logger.Debugf("Dropping packet because we already dropped the keys.")
|
||||||
case handshake.ErrOpenerNotYetAvailable:
|
case handshake.ErrKeysNotYetAvailable:
|
||||||
// Sealer for this encryption level not yet available.
|
// Sealer for this encryption level not yet available.
|
||||||
// Try again later.
|
// Try again later.
|
||||||
wasQueued = true
|
wasQueued = true
|
||||||
|
|
|
@ -749,7 +749,7 @@ var _ = Describe("Session", func() {
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
PacketNumber: 1,
|
PacketNumber: 1,
|
||||||
}
|
}
|
||||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrOpenerNotYetAvailable)
|
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||||
packet := getPacket(hdr, nil)
|
packet := getPacket(hdr, nil)
|
||||||
Expect(sess.handlePacketImpl(packet)).To(BeFalse())
|
Expect(sess.handlePacketImpl(packet)).To(BeFalse())
|
||||||
Expect(sess.undecryptablePackets).To(Equal([]*receivedPacket{packet}))
|
Expect(sess.undecryptablePackets).To(Equal([]*receivedPacket{packet}))
|
||||||
|
@ -832,7 +832,7 @@ var _ = Describe("Session", func() {
|
||||||
hdrLen1, packet1 := getPacketWithLength(srcConnID, 456)
|
hdrLen1, packet1 := getPacketWithLength(srcConnID, 456)
|
||||||
hdrLen2, packet2 := getPacketWithLength(srcConnID, 123)
|
hdrLen2, packet2 := getPacketWithLength(srcConnID, 123)
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrOpenerNotYetAvailable),
|
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrKeysNotYetAvailable),
|
||||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ *wire.Header, _ time.Time, data []byte) (*unpackedPacket, error) {
|
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ *wire.Header, _ time.Time, data []byte) (*unpackedPacket, error) {
|
||||||
Expect(data).To(HaveLen(hdrLen2 + 123 - 3))
|
Expect(data).To(HaveLen(hdrLen2 + 123 - 3))
|
||||||
return &unpackedPacket{
|
return &unpackedPacket{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue