wemosetup icon indicating copy to clipboard operation
wemosetup copied to clipboard

encode hex no longer working in python3

Open disgustipated opened this issue 4 years ago • 5 comments

Looks like the encode hex command in the encrypt_wifi_password is failing in python3 when trying to add a device. I tried importing codecs and changing it to codecs.encode(salt, 'hex') and codecs.encode(iv,'hex')

but it still seems to fail with it complaining about it being a string and not byte coded `` Discovered 3 networks with SSID "wifissid", using the first available..." Traceback (most recent call last): File "/usr/lib/python3.8/encodings/hex_codec.py", line 15, in hex_encode return (binascii.b2a_hex(input), len(input)) TypeError: a bytes-like object is required, not 'str'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "wemosetup.py", line 258, in cmd(**args) File "wemosetup.py", line 137, in connecthomenetwork 'password' : device.encrypt_wifi_password(password, meta_array), File "wemosetup.py", line 90, in encrypt_wifi_password stdout, stderr = subprocess.Popen(['openssl', 'enc', '-aes-128-cbc', '-md', 'md5', '-S', codecs.encode(salt, 'hex'), '-iv', codecs.encode(iv,'hex'), '-pass', 'pass:' + keydata], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate(password) TypeError: encoding with 'hex' codec failed (TypeError: a bytes-like object is required, not 'str') ``

I can poke through python a bit but not extremely versed in it so not sure what to try next.

disgustipated avatar Feb 02 '21 21:02 disgustipated

you'd have to poke yourself, yes :( you'd need to put in .encode() (or .encode("utf-8"), but i i'm not sure if anything there supports utf8) in right places to convert ascii strings to bytes

poking can be limited to that encrytpt_wifi_password function which is short

vadimkantorov avatar Feb 02 '21 21:02 vadimkantorov

Are the salt and iv values required for wemo setup? looks like you can use just '-salt' with openssl and it will generate a random salt.

disgustipated avatar Feb 03 '21 17:02 disgustipated

they are required, yes, you must use specific iv/salt that come the device metadata call

vadimkantorov avatar Feb 03 '21 17:02 vadimkantorov

Any example of how we would do this?

deftdawg avatar Jun 20 '21 08:06 deftdawg

I think the course of action should be: go over the code, check for bytes / strings arguments. If needed, find the commit before python2->python3 refactoring to see what it was supposed to be doing.

Sorry I'm not of help, but I don't have access to wemo devices anymore. But with some basic debugging and comparing to the old Python2 version, one should be able to do these fixes.

vadimkantorov avatar Jun 20 '21 19:06 vadimkantorov