Skip to content

Commit

Permalink
Handle late encryption error
Browse files Browse the repository at this point in the history
We should not see an encryption error after
unless the data is corrupted on the wire,
apparently this can happen

fixes #1044
  • Loading branch information
bdraco committed Feb 3, 2025
1 parent ab15d7b commit 08e34ca
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion aioesphomeapi/_frame_helper/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,18 @@ def _handle_frame(self, frame: bytes) -> None:
"""Handle an incoming frame."""
if TYPE_CHECKING:
assert self._decrypt_cipher is not None, "Handshake should be complete"
msg = self._decrypt_cipher.decrypt(frame)
try:
msg = self._decrypt_cipher.decrypt(frame)
except InvalidTag:
# This shouldn't happen since we already checked the tag during handshake
# but it could happen if the server sends a bad frame see
# issue https://github.com/esphome/aioesphomeapi/issues/1044
self._handle_error_and_close(
InvalidEncryptionKeyAPIError(
f"{self._log_name}: Encryption error", self._server_name
)
)
return
# Message layout is
# 2 bytes: message type
# 2 bytes: message length
Expand Down

0 comments on commit 08e34ca

Please sign in to comment.