supersaiyanmode / PyWebOSTV

Python API for controlling LG TVs (Web OS)
MIT License
261 stars 50 forks source link

Please add Use Secure Connection option #83

Closed ttesty closed 1 year ago

ttesty commented 1 year ago

LG-C2 recent firmware broke the default insecure WebSocket communication. Please update this library with an option to use secure communication. This feature has been recently implemented in Color Control. Otherwise, I won't be able to communicate with WebOS. I listed a simple fix below (in my comment) that you can make more robust.

https://www.softpedia.com/progChangelog/ColorControl-Changelog-266950.html January 19, 2023 LG controller: added "Use secure connection" option for devices. It is enabled by default and works around the connection problems introduced by the new 2022 series LG firmware update.

ttesty commented 1 year ago

Pretty easy change.. maybe add flags, have ws_url, wss_url: Quick hack: pywebostv/connection.py: ws_url = "ws://{}:3000/".format(host) -> ws_url = "wss://{}:3001/".format(host)

supersaiyanmode commented 1 year ago

Hi @ttesty Thanks so much informing about this breakage. I can think of 2 ways of fixing this problem (and I have corresponding questions):

1. Library automatically figures out wss:// or ws://

For this to work, we will need the discovery mechanism to automatically identify the differences between a TV that needs ws:// v/s the one that requires wss://. Since I dont have a TV with the latest firmware, can you please dump the variable resp when a C2 w/ new firmward is being discovered and that with an older TV? If the newer firmware has a version header or something, we can extract that and pass a flag from discover(..) to WebOSClient(..).

2. The library user passes a flag explicitly

This is straightforward. We can simply add a parameter to both discover(..) and WebOSClient(..).

In either case, I am a little held up and won't be able to update this library anytime soon (~2-3 weeks maybe). Would you like to open a PR and bump the version? I can definitely upload the latest to PyPI.

DoughMucker commented 1 year ago

Please ignore. I only changed ws>wss and not 3000>3001. The hack works.

Quick hack: pywebostv/connection.py: ws_url = "ws://{}:3000/".format(host) -> ws_url = "wss://{}:3001/".format(host)

Was the quick hack supposed to work without any other changes? I tried it on my C2 with the updated firmware and the connection still fails: kodi:~ # python LG_volume_up.py Traceback (most recent call last): File "/storage/LG_volume_up.py", line 7, in <module> client.connect() File "/storage/ws4py/client/__init__.py", line 217, in connect self.sock.connect(self.bind_addr) File "/usr/lib/python3.11/ssl.py", line 1379, in connect File "/usr/lib/python3.11/ssl.py", line 1370, in _real_connect File "/usr/lib/python3.11/ssl.py", line 1346, in do_handshake ConnectionResetError: [Errno 104] Connection reset by peer

ttesty commented 1 year ago

@supersaiyanmode: It's also pretty easy to check for existence of port 3001 for wss. Port 3000 on the new firmware disconnects upon connecting ("privacy change" to firmware). I can't get discovery to work - might be getting blocked on my system. Don't have an older TV (anymore). Attached a port scan of the TV with info.

Up to you if you want automatic discovery, flag. No rush. I can wait for you - my time is also tight.

@DoughMucker: quick hack works without other changes. I simply uncompressed the pywebostv egg, manually applied changes. Maybe they aren't being applied for you or you have the wrong python installation invoked. You can confirm with the latest ColorControl app as well - that was my first clue (since prior releases broke). I'm using Windows.

Can see my port scan of the TV: ports

supersaiyanmode commented 1 year ago

The PR from @usbpc (Thanks!) has been checked in. Closing this one out.

usbpc commented 1 year ago

@supersaiyanmode Could you update the package on PyPi?

supersaiyanmode commented 1 year ago

Done, uploaded the latest to PyPI