only change remote address after authenticating a packet

fixes #395
This commit is contained in:
Marten Seemann
2017-01-14 18:15:50 +07:00
parent 1e78104f83
commit 67657a37bf
2 changed files with 66 additions and 7 deletions

View File

@@ -272,10 +272,14 @@ func (s *Session) handlePacketImpl(p *receivedPacket) error {
utils.Debugf("<- Reading packet 0x%x (%d bytes) for connection %x @ %s", hdr.PacketNumber, len(data)+len(hdr.Raw), hdr.ConnectionID, time.Now().Format("15:04:05.000"))
}
// TODO: Only do this after authenticating
s.conn.setCurrentRemoteAddr(p.remoteAddr)
packet, err := s.unpacker.Unpack(hdr.Raw, hdr, data)
// if the decryption failed, this might be a packet sent by an attacker
// don't update the remote address
if quicErr, ok := err.(*qerr.QuicError); ok && quicErr.ErrorCode == qerr.DecryptionFailure {
return err
}
// update the remote address, even if unpacking failed for any other reason than a decryption error
s.conn.setCurrentRemoteAddr(p.remoteAddr)
if err != nil {
return err
}