home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.59k stars 29.91k forks source link

Error in ezviz component (and a dirty solution) #119409

Open tango13 opened 3 months ago

tango13 commented 3 months ago

The problem

Hello, when trying to send a command to my Ezviz BC1C battery camera (namely the activation of motion detection), I get an error saying "Error: Incorrect IV length (it must be 16 bytes long)" and the command fails.

What version of Home Assistant Core has the issue?

core-2024.6.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

EZVIZ

Link to integration documentation on our website

No response

Diagnostics information

I have made some troubleshooting and found a (dirty!) solution. The problem lies in file /usr/local/lib/python3.12/site-packages/Crypto/Cipher/_mode_cbc.py. In detail, starting from line 275, my modified file is as follows:

cipher_state = factory._create_base_cipher(kwargs)
iv = kwargs.pop("IV", None)
IV = kwargs.pop("iv", None)                                    
iv = urandom(16)             # <<<<<<======= added line                                 

if (None, None) == (iv, IV):                                    
    #iv = get_random_bytes(factory.block_size)             <<<<<<===== commented out
    iv = urandom(16)         # <<<<<<======= added line
if iv is not None:
    if IV is not None:                                           
        raise TypeError("You must either use 'iv' or 'IV', not both")
else:                                                          
    iv = IV 

At the beginning of the file I added a simple

from os import urandom

I am no python programmer nor had I time to further investigate an elegant solution, but this code works and the error doesn't show up anymore. Thanks.

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Thank you.

home-assistant[bot] commented 1 month ago

Hey there @renierm26, @baqs, mind taking a look at this issue as it has been labeled with an integration (ezviz) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `ezviz` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign ezviz` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


ezviz documentation ezviz source (message by IssueLinks)