osresearch / hcpy

Python tool to talk to Home Connect appliances over the local network (no cloud required)
276 stars 32 forks source link

Encryption issue: Is the IV updated? #10

Closed Eroli closed 2 years ago

Eroli commented 2 years ago

Hi everybody,

i am currently working on a C# port of this nice project. I am working with a WAV28G40 washer from Bosch and i am facing a strange issue.

If you have any hints for me regarding this error, please let me know :-)

osresearch commented 2 years ago

Glad to hear you've made it past the login steps and are now into the command-and-control part.

You've guessed correctly about the cause -- I ran into a similar problem and didn't comment it very well in the code.

The trick is that the AES context is not reset after each message, so the "IV" for the second message is the chained cipher text from the previous message as if they were one continuous communication. The HCSocket python code uses the same self.aes_encrypt object until self.reset() is called after a reconnect, which reinitializes the encrypt/decrypt objects with the self.iv value.

Eroli commented 2 years ago

In fact, I also tried reusing the AES object for the various incoming messages before asking. Unfortunately that did not work either.

The solution was not to use the single calls AES.DecryptCbc but the variant with the CryptoStream. In addition, the CryptoStream must not be closed, which means it must be reused just like the AES object. Of course I checked this only now, before the CryptoStream was in a using block and was therefore disposed after each encryption.

Thanks again for the help, I'll clean up the implementation a bit now.

Maybe a follow-up question: Decrypting the messages sent via NOTIFY (which UID means what?) I imagine is still somewhat feasible. Do you have an idea how to find out what you would have to send, for example to start a certain program of the washing machine? So actively trigger an action instead of just waiting for the reactions?

osresearch commented 2 years ago

Are you fetching the account/details json like hc-login line 133? Once you have that struct you can fetch a series of zip'ed XML files with "api/iddf/v1/iddf/" + app_id that describe the enums and ids of different commands.

My application right now is just dashboarding, so I haven't explored sending commands to the devices, although it seems like it should be "a simple matter of programming" to use the various UIDs to make it do things.