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

SSL by default, failover to plain #140

Open
klattimer opened this issue Dec 4, 2023 · 6 comments
Open

SSL by default, failover to plain #140

klattimer opened this issue Dec 4, 2023 · 6 comments

Comments

@klattimer
Copy link
Owner

Some devices will support SSL, some will not, of those which do, some may support plaintext. It makes most sense for us to take the most secure option and failover to the least secure option.

@Tenzer
Copy link
Collaborator

Tenzer commented Dec 9, 2023

One slight complication with this for now, is that ws4py is using ssl.wrap_socket when SSL is enabled, which was marked as deprecated in Python 3.7 and removed in Python 3.12, so it makes lgtv fail like this:

~ % lgtv --ssl swInfo
Traceback (most recent call last):
  File "/Users/jeppe/.local/bin/lgtv", line 33, in <module>
    sys.exit(load_entry_point('LGTV', 'console_scripts', 'lgtv')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jeppe/my-git/LGWebOSRemote/LGTV/__init__.py", line 191, in main
    ws.connect()
  File "/Users/jeppe/.local/pipx/venvs/lgtv/lib/python3.12/site-packages/ws4py/client/__init__.py", line 214, in connect
    self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
                ^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'

There's a fix for ws4py in Lawouach/WebSocket-for-Python#283, but I wonder if it might otherwise be worth looking at migrating to another websocket library that is kept more up to date, as ws4py hasn't had a release since 2018?

@klattimer
Copy link
Owner Author

@Tenzer ws4py was the only one I found that I could make work - specifically, I had to exclude default headers in order to make it work back on webOS 2.x IIRC. You'll find this in the code where exclude_headers=['Origin'] IIRC, which was always being sent by ws4py (it IS part of the spec, so you can't blame them).

This is in itself a bit of a hack, and was likely due to a bug in the webOS web socket server libraries and may now have been fixed.

@Aurshur
Copy link

Aurshur commented Dec 30, 2023

Is there any workaround with this?

I tried @cmer 's suggestion of rolling back to Python 3.6 but got the following error:

% brew install [email protected]
Warning: No available formula with the name "[email protected]". Did you mean [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] or python-yq?
==> Searching for similarly named formulae and casks...
==> Formulae
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] python-yq

@Tenzer
Copy link
Collaborator

Tenzer commented Dec 30, 2023

The problem only exists with Python 3.12, so try version 3.11 for now.

@Aurshur
Copy link

Aurshur commented Jan 6, 2024

The problem only exists with Python 3.12, so try version 3.11 for now.

That worked! Thank you!

@egnappahz
Copy link

I'm sorry, but the real fix is
https://github.com/Lawouach/WebSocket-for-Python/pull/283/files/1d9ffff3beb71553c85e846a1b828ec7d890e751

Not all of us can afford to use ancient versions of python.

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

4 participants