Skip to content

Commit

Permalink
Allow first encryption reset too
Browse files Browse the repository at this point in the history
  • Loading branch information
Komzpa committed Mar 30, 2024
1 parent 12a41be commit 69a1fa0
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/bthome_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ def _decrypt_bthome(
# Beware: If attacker manages to record a message with high encryption counter number they can
# DoS all of your actual measurements until encryption counter reaches even higher value
if ((new_encryption_counter < 1000 and last_encryption_counter >= 4294967195) or
(self.reset_counter == 0) or
(self.reset_counter <= 1 and self.message_since_last_reset >= 100)):
# Counter reset logic: either it's a legitimate overflow reset, or a reset is allowed per policy
self.encryption_counter = new_encryption_counter
Expand All @@ -683,8 +684,6 @@ def _decrypt_bthome(
raise ValueError
else:
self.encryption_counter = new_encryption_counter


# Reset the reset_counter if a hundred messages have been received since the last reset
if self.message_since_last_reset >= 100 and self.reset_counter >= 1:
if self.reset_counter <= 1:
Expand Down

0 comments on commit 69a1fa0

Please sign in to comment.