Commit 2b63c9a7 authored by Tom Niget's avatar Tom Niget Committed by Tom Niget

bug: handle and log UTF-8 decoding failures in X.509

Those usually indicate that we're decoding something we shouldn't be, or that something wrong happened during decryption.
parent 19550237
...@@ -303,7 +303,11 @@ class Peer: ...@@ -303,7 +303,11 @@ class Peer:
if self._hmac(msg[:i]) == msg[i:] and self._i < seqno: if self._hmac(msg[:i]) == msg[i:] and self._i < seqno:
self._last = None self._last = None
self._i = seqno self._i = seqno
return msg[4:i].decode() try:
return msg[4:i].decode()
except UnicodeDecodeError:
logging.error("Invalid message from %s: %r", self.prefix, msg)
raise
def encode(self, msg: str | bytes, _pack=seqno_struct.pack) -> bytes: def encode(self, msg: str | bytes, _pack=seqno_struct.pack) -> bytes:
self._j += 1 self._j += 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment