Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode hex no longer working in python3 #7

Open
disgustipated opened this issue Feb 2, 2021 · 5 comments
Open

encode hex no longer working in python3 #7

disgustipated opened this issue Feb 2, 2021 · 5 comments

Comments

@disgustipated
Copy link

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.

@vadimkantorov
Copy link
Owner

vadimkantorov commented Feb 2, 2021

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

@disgustipated
Copy link
Author

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.

@vadimkantorov
Copy link
Owner

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

@deftdawg
Copy link

Any example of how we would do this?

@vadimkantorov
Copy link
Owner

vadimkantorov commented Jun 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants