jlusiardi / homekit_python

A python implementation to work as both HomeKit controller and accessory.
Apache License 2.0
221 stars 41 forks source link

potential base64 encode issue on TLV8 data #200

Closed belkinhappyzj closed 4 years ago

belkinhappyzj commented 4 years ago

The issue is observed with using encoded TLV8 data in command line e.g. python -m homekit.put_characteristic -f steven.json -a RT -c 1.58 "Af8BAQUC\/wEBAQMBAwX......" The base64 encloding used here is MIME(RFC2045) which "\" is a legal letter, however the actual data sent out by controller is Af8BAQUC\\/wEBAQMBAwX...... where it automatically insert an extra "\" before "\" which seems to be due to escape character? this issue is making the PUT operation fail due to invalid data, would you please take a look and see if there could be a quick "patch" of "fix" available, thanks.

jlusiardi commented 4 years ago

Hi,

thanks for the report. I just tried to reproduce with test.py

import sys

print(sys.argv)

and calling python3 test.py "foo\/bar" in bash prints

['test.py', 'foo\\/bar']

What kind of shell do you use? https://stackoverflow.com/a/28156762/12376815 states that this behavior might differ from shell to shell (and between OSs).

I am thinking about offering an option give put_characteristic an option to read the value from a file, so we would not run into this troubles?

belkinhappyzj commented 4 years ago

Hi jlusiardi, thanks for your investigation, I am running it via CMD CLI on windows OS, maybe this is a windows specific issue? BTW, read it from a file is an great idea!, thanks.

jlusiardi commented 4 years ago

I made a new branch: fix_200 and added the load content from file feature: -c 1.9 @somefile

Install with:

pip3 install --upgrade -e git+https://github.com/jlusiardi /homekit_python.git@fix_200#egg=homekit[IP]