improve logging of undecryptable packets

This commit is contained in:
Marten Seemann 2019-11-25 14:06:44 +07:00
parent dde21d2f72
commit 78029adfb2
3 changed files with 16 additions and 3 deletions

View file

@ -247,3 +247,11 @@ func (h *Header) ParseExtended(b *bytes.Reader, ver protocol.VersionNumber) (*Ex
func (h *Header) toExtendedHeader() *ExtendedHeader { func (h *Header) toExtendedHeader() *ExtendedHeader {
return &ExtendedHeader{Header: *h} return &ExtendedHeader{Header: *h}
} }
// PacketType is the type of the packet, for logging purposes
func (h *Header) PacketType() string {
if h.IsLongHeader {
return h.Type.String()
}
return "1-RTT"
}

View file

@ -558,4 +558,9 @@ var _ = Describe("Header Parsing", func() {
} }
}) })
}) })
It("tells its packet type for logging", func() {
Expect((&Header{IsLongHeader: true, Type: protocol.PacketTypeHandshake}).PacketType()).To(Equal("Handshake"))
Expect((&Header{}).PacketType()).To(Equal("1-RTT"))
})
}) })

View file

@ -665,7 +665,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool /
// After this, all packets with a different source connection have to be ignored. // After this, all packets with a different source connection have to be ignored.
destConnID := s.connIDManager.Get() destConnID := s.connIDManager.Get()
if s.receivedFirstPacket && hdr.IsLongHeader && !hdr.SrcConnectionID.Equal(destConnID) { if s.receivedFirstPacket && hdr.IsLongHeader && !hdr.SrcConnectionID.Equal(destConnID) {
s.logger.Debugf("Dropping packet with unexpected source connection ID: %s (expected %s)", hdr.SrcConnectionID, destConnID) s.logger.Debugf("Dropping %s packet with unexpected source connection ID: %s (expected %s)", hdr.PacketType(), hdr.SrcConnectionID, destConnID)
return false return false
} }
// drop 0-RTT packets // drop 0-RTT packets
@ -677,7 +677,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool /
if err != nil { if err != nil {
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 %s packet because we already dropped the keys.", hdr.PacketType())
case handshake.ErrKeysNotYetAvailable: 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.
@ -688,7 +688,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool /
default: default:
// This might be a packet injected by an attacker. // This might be a packet injected by an attacker.
// Drop it. // Drop it.
s.logger.Debugf("Dropping packet that could not be unpacked. Error: %s", err) s.logger.Debugf("Dropping %s packet that could not be unpacked. Error: %s", hdr.PacketType(), err)
} }
return false return false
} }