Skip to content

Commit d6aa4f4

Browse files
committed
fix: wrong package
1 parent 8898119 commit d6aa4f4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

roborock/broadcast_protocol.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
RawCopy,
1717
Struct,
1818
)
19-
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
19+
from Crypto.Cipher import AES
2020

21+
from roborock import RoborockException
2122
from roborock.containers import BroadcastMessage
2223
from roborock.protocol import EncryptionAdapter, Utils, _Parser
2324

@@ -40,14 +41,18 @@ def datagram_received(self, data: bytes, _):
4041
if version == b"L01":
4142
[parsed_msg], _ = L01Parser.parse(data)
4243
encrypted_payload = parsed_msg.payload
44+
if encrypted_payload is None:
45+
raise RoborockException("No encrypted payload found in broadcast message")
46+
ciphertext = encrypted_payload[:-16]
47+
tag = encrypted_payload[-16:]
4348

4449
key = hashlib.sha256(BROADCAST_TOKEN).digest()
4550
iv_digest_input = data[:9]
4651
digest = hashlib.sha256(iv_digest_input).digest()
4752
iv = digest[:12]
4853

49-
cipher = AESGCM(key)
50-
decrypted_payload_bytes = cipher.decrypt(iv, encrypted_payload, None)
54+
cipher = AES.new(key, AES.MODE_GCM, nonce=iv)
55+
decrypted_payload_bytes = cipher.decrypt_and_verify(ciphertext, tag)
5156
json_payload = json.loads(decrypted_payload_bytes)
5257
parsed_message = BroadcastMessage(duid=json_payload["duid"], ip=json_payload["ip"], version=version)
5358
_LOGGER.debug(f"Received L01 broadcast: {parsed_message}")
@@ -61,7 +66,7 @@ def datagram_received(self, data: bytes, _):
6166
_LOGGER.debug(f"Received broadcast: {parsed_message}")
6267
self.devices_found.append(parsed_message)
6368
except Exception as e:
64-
_LOGGER.warning(f"Failed to decode message: {bytes}. Error: {e}")
69+
_LOGGER.warning(f"Failed to decode message: {data!r}. Error: {e}")
6570

6671
async def discover(self) -> list[BroadcastMessage]:
6772
async with self._mutex:

0 commit comments

Comments
 (0)