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

Cannot create a client socket with a PROTOCOL_TLS_SERVER context #49

Closed
samjones108 opened this issue Jul 22, 2023 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@samjones108
Copy link

/

Describe The Bug:
When running python3.10 hisensetv.py --authorize it errors out with cannot "ssl.SSLError: Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:801)" so I am unable to create a binding with the TV. On MQTT explorer I am able to auth with the certs that are in the /ssl/ folder in the root of the drive that is passed to the python script. This folder has read/write/execute (777) access to all users. This error happens on both --authorize and --getstatus.

To Reproduce:

[2023-07-22 21:52:24,994] [INFO    ] SSL context created with cert file (/ssl/rcm_certchain_pem.cer) and private key (/ssl/rcm_pem_privkey.pkcs8)
[2023-07-22 21:52:24,996] [INFO    ] Network interface MAC Address: c8:d3:ff:3b:XX:XX
Traceback (most recent call last):
  File "/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv.py", line 6, in <module>
    __main__.main()
  File "/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/__main__.py", line 128, in main
    with tv:
  File "/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/__init__.py", line 136, in __enter__
    self._mqtt_client.connect(self.hostname, self.port)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1083, in reconnect
    sock = self._ssl_context.wrap_socket(
  File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.10/ssl.py", line 1062, in _create
    self._sslobj = self._context._wrap_socket(
ssl.SSLError: Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:801)
homebridge@homebridge:/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin $ 

Expected behavior:

Once running the script I should be prompted to enter a pairing key in the terminal that is shown on tv to complete the pairing.
Logs:

Show the Homebridge logs here, remove any sensitive information.
''''' Loading logs using native method...
File: /var/lib/homebridge/homebridge.log

 report this to the developer!
Setup Payload:
X-HM://XXXXXXXXXXXXX
Enter this code with your HomeKit app on your iOS device to pair with Homebridge:
                       
    ┌────────────┐     
    │ XXX_XX-XXX │     
    └────────────┘     
[22/07/2023, 21:40:36] [Homebridge UI] Homebridge restart request received
[22/07/2023, 21:40:36] [Homebridge UI] UI / Bridge settings have not changed; only restarting Homebridge process
[22/07/2023, 21:40:36] [Homebridge UI] Sending SIGTERM to Homebridge
[22/07/2023, 21:40:36] Got SIGTERM, shutting down Homebridge...
[22/07/2023, 21:40:36] [Camera FFmpeg] [Marble Cam] Stopped video stream.
[22/07/2023, 21:40:36] Got SIGTERM, shutting down child bridge process...
[22/07/2023, 21:40:41] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null
[22/07/2023, 21:40:46] [HB Supervisor] Restarting Homebridge...
[22/07/2023, 21:40:46] [HB Supervisor] Starting Homebridge with extra flags: -I -P /var/lib/homebridge/node_modules --strict-plugin-resolution
[22/07/2023, 21:40:46] [HB Supervisor] Started Homebridge v1.6.1 with PID: 3918
[22/07/2023, 21:40:47] Loaded config.json with 0 accessories and 6 platforms.
[22/07/2023, 21:40:47] Loaded 8 cached accessories from cachedAccessories.
[22/07/2023, 21:40:48] ---
[22/07/2023, 21:40:48] Loaded plugin: [email protected]
[22/07/2023, 21:40:48] Registering platform 'homebridge-camera-ffmpeg.Camera-ffmpeg'
[22/07/2023, 21:40:48] ---
[22/07/2023, 21:40:48] Loaded plugin: [email protected]
[22/07/2023, 21:40:48] Registering platform 'homebridge-hisense-tv-remotenow.HiSenseTV'
[22/07/2023, 21:40:48] ---
[22/07/2023, 21:40:48] Disabled plugin: [email protected]
[22/07/2023, 21:40:48] ---
[22/07/2023, 21:40:48] Loaded plugin: [email protected]
[22/07/2023, 21:40:48] Registering platform 'homebridge-nest.Nest'
[22/07/2023, 21:40:48] ---
[22/07/2023, 21:40:49] Loaded plugin: @0x5e/[email protected]
[22/07/2023, 21:40:49] Registering platform '@0x5e/homebridge-tuya-platform.TuyaPlatform'
[22/07/2023, 21:40:49] ---
[22/07/2023, 21:40:49] Loading 6 platforms...
[22/07/2023, 21:40:49] [Tuya] Initializing TuyaPlatform platform...
[22/07/2023, 21:40:49] [Nest] Initializing Nest platform...
[22/07/2023, 21:40:49] Ignoring config for the platform "Camera-IP" in your config.json as the plugin "homebridge-ip-camera" has been disabled.
[22/07/2023, 21:40:49] [HiSenseTV] Initializing HiSenseTV platform...
[22/07/2023, 21:40:49] [HiSenseTV] Initializing child bridge 0E:55:88:7B:XX:XX
[22/07/2023, 21:40:49] [Camera FFmpeg] Initializing Camera-ffmpeg platform...
[22/07/2023, 21:40:50] [Tuya] Loading accessory from cache: Bedroom
[22/07/2023, 21:40:50] [Tuya] Loading accessory from cache: Christmas tree 🎄 
[22/07/2023, 21:40:50] [Tuya] Loading accessory from cache: Smart Plug
[22/07/2023, 21:40:50] [Tuya] Loading accessory from cache: Smart Plug 2
[22/07/2023, 21:40:50] [Tuya] Loading accessory from cache: Smart Plug 1
[22/07/2023, 21:40:50] [Camera FFmpeg] [Marble Cam] Configuring cached bridged accessory...
[22/07/2023, 21:40:50] [Tuya] Log in to Tuya Cloud.
[22/07/2023, 21:40:50] [Tuya] [TuyaOpenAPI] Login to: https://XXXXXXXXXXXXXXXXX
[22/07/2023, 21:40:50] [Nest] Fetching Nest devices.
Setup Payload:
X-HM://XXXXXXXXXXXXX
Enter this code with your HomeKit app on your iOS device to pair with Homebridge:
                       
    ┌────────────┐     
    │ XXX-XX-XXX │     
    └────────────┘     
                       
[22/07/2023, 21:40:50] Homebridge v1.6.1 (HAP v0.11.1) (Homebridge F2FE) is running on port 51527.
[22/07/2023, 21:40:50] [Tuya] Start MQTT connection.
[22/07/2023, 21:40:50] [Tuya] Fetching home list.
[22/07/2023, 21:40:51] [Tuya] Got home_id=XXXXXXXXXX, name=Home
[22/07/2023, 21:40:51] [Tuya] Fetching device list.
[22/07/2023, 21:40:51] [homebridge-hisense-tv-remotenow] Launched child bridge with PID 3943
[22/07/2023, 21:40:51] Registering platform 'homebridge-hisense-tv-remotenow.HiSenseTV'
[22/07/2023, 21:40:52] [homebridge-hisense-tv-remotenow] Loaded homebridge-hisense-tv-remotenow v2.0.0 child bridge successfully
[22/07/2023, 21:40:52] Loaded 0 cached accessories from cachedAccessories.0E55887XXXX.
[22/07/2023, 21:40:52] [homebridge-hisense-tv-remotenow] Adding new accessory: HiSense
[22/07/2023, 21:40:52] Homebridge v1.6.1 (HAP v0.11.1) (homebridge-hisense-tv-remotenow) is running on port 58717.
[22/07/2023, 21:40:52] HiSense 24C8 is running on port 33325.
[22/07/2023, 21:40:52] Please add [HiSense 24C8] manually in Home app. Setup Code: XXX-XX-XXX
[22/07/2023, 21:40:53] [Tuya] Fetching scene list.
[22/07/2023, 21:40:53] [Tuya] Got 5 device(s) and scene(s).
[22/07/2023, 21:40:53] [Tuya] Device list saved at /var/lib/homebridge/persist/TuyaDeviceList.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json
[22/07/2023, 21:40:53] [Tuya] Restoring existing accessory from cache: Bedroom
[22/07/2023, 21:40:53] [Tuya] [Bedroom] Light type: RGBCW
[22/07/2023, 21:40:53] [Tuya] [Bedroom] Adaptive Lighting disabled.
[22/07/2023, 21:40:53] [Tuya] Restoring existing accessory from cache: Smart Plug
[22/07/2023, 21:40:53] [Tuya] Restoring existing accessory from cache: Christmas tree 🎄 
[22/07/2023, 21:40:53] [Tuya] Restoring existing accessory from cache: Smart Plug 2
[22/07/2023, 21:40:53] [Tuya] Restoring existing accessory from cache: Smart Plug 1
[22/07/2023, 21:40:57] [Nest] initing thermostat (P) "Living Room Thermostat": deviceId: XXXXXXXXXXXXXXXX structureId: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[Living Room Thermostat@@Heating Threshold Temperature] characteristic was supplied illegal value: number 0 exceeded minimum of 9
[22/07/2023, 21:40:57] [Nest] initing home_away_sensor "Home Occupied": deviceId: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX structureId: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[22/07/2023, 21:41:08] [Camera FFmpeg] [Marble Cam] Starting video stream: native x native, native fps, ??? kbps
[22/07/2023, 21:41:36] [Homebridge UI] Changes to config.json saved.
[22/07/2023, 21:41:37] [Homebridge UI] Running Command: npm uninstall --save homebridge-ip-camera
[22/07/2023, 21:51:45] [Homebridge UI] Starting terminal session
[22/07/2023, 21:52:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:52:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:52:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:52:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:53:02] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:53:12] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:53:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:53:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:53:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:53:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:54:02] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:54:12] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:54:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:54:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:54:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:54:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:55:02] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:55:12] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:55:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:55:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:55:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:55:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:56:02] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:56:12] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:56:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:56:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:56:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:56:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:57:02] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:57:12] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:57:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:57:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:57:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:57:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:58:02] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:58:12] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:58:22] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:58:26] [Homebridge UI] Terminal session ended.
[22/07/2023, 21:58:32] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:58:42] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')
[22/07/2023, 21:58:52] [homebridge-hisense-tv-remotenow] An error occurred while fetching inputs: TypeError: Cannot read properties of null (reading 'join')

Plugin Config:

        {
            "ifname": "enp1s0",
            "devices": [
                {
                    "id": "HiSenseTV",
                    "name": "HiSense",
                    "ipaddress": "192.168.139.89",
                    "macaddress": "30:32:35:b4:XX:XX",
                    "sslmode": "default",
                    "sslcertificate": "/ssl/rcm_certchain_pem.cer",
                    "sslprivatekey": "/ssl/rcm_pem_privkey.pkcs8"
                }
            ],
            "_bridge": {
                "username": "0E:55:88:7B:XX:XX",
                "port": 58717
            },
            "platform": "HiSenseTV"
       }

Show your Homebridge config.json here, remove any sensitive information.

            "accessories": [],
    "bridge": {
        "port": 51527,
        "name": "Homebridge F2FE",
        "username": "XXXXXXXXXX",
        "advertiser": "bonjour-hap",
        "pin": "XXXXXXXX"
    },
    "platforms": [
        {
            "port": 8581,
            "platform": "config",
            "name": "Config"
        },
        {
            "platform": "TuyaPlatform",
            "options": {
                "projectType": "2",
                "debug": false,
                "password": "XXXXXXXXXXX",
                "countryCode": 44,
                "accessId": "XXXXXXXXXXXX",
                "deviceOverrides": [
                    {
                        "id": "global"
                    }
                ],
                "accessKey": "XXXXXXXXXXXXXX",
                "appSchema": "tuyaSmart",
                "username": "XXXXXXXXXXXXXXXXX"
            },
            "name": "Tuya"
        },
        {
            "name": "Nest",
            "platform": "Nest",
            "googleAuth": {
                "issueToken": "XXXXXXXXXXXXXXXX",
                "apiKey": "XXXXXXXXXXXXXXXXXXXXXXXX"
            }
        },
        {
            "ifname": "enp1s0",
            "devices": [
                {
                    "id": "HiSenseTV",
                    "name": "HiSense",
                    "ipaddress": "192.168.139.89",
                    "macaddress": "30:32:35:b4:XX:XX",
                    "sslmode": "default",
                    "sslcertificate": "/ssl/rcm_certchain_pem.cer",
                    "sslprivatekey": "/ssl/rcm_pem_privkey.pkcs8"
                }
            ],
            "_bridge": {
                "username": "0E:55:88:7B:XX:XX",
                "port": 58717
            },
            "platform": "HiSenseTV"
       }

Show your Homebridge config.json here, remove any sensitive information.
Screenshots:
[]
(https://github-production-user-asset-6210df.s3.amazonaws.com/39278241/255351605-f2da80fd-3f50-4f60-b20a-0a986034d389.png)

Environment:

  • Plugin Version:v1.7.0-beta.49
  • Homebridge Version: V1.6.1
  • Node.js Version: V18.17.0
  • NPM Version: 8.5.1
  • Operating System: Ubuntu Server Lite 22.04.01
  • TV model: 55A7100FTUK
  • TV firmware:V0001.01.00L.L1103
@samjones108 samjones108 added the bug Something isn't working label Jul 22, 2023
@MrAsterisco
Copy link
Owner

I just did a quick search and this seems to be a Python 3.10 change (see this issue). Would you be able to downgrade to 3.8 in the meantime?

I have no capacity to test on Python 3.10, as I don't have a testing TV anymore, but I'm happy to review a PR. The change would have to be done first on the underlying Python app and then here.

@timo8042
Copy link

timo8042 commented Nov 6, 2023

Hello, I' running the same error on Python3.10.12.
I've made PR on the Python App with the solution that I've found about this error (please be nice, I'm not developer 😅)

@ttaggorf
Copy link

ttaggorf commented Apr 3, 2024

Having the same issue here. Downgraded to Python 3.8 but how getting

sysadmin@pve-homebridge-1:/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin$ python3.8 hisensetv.py 172.16.0.13 --authorize --ifname ens18 --certfile tvcert.cer --keyfile tvkey.key

Traceback (most recent call last):
  File "hisensetv.py", line 3, in <module>
    from hisensetv import __main__
  File "/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/__init__.py", line 17, in <module>
    import netifaces

ModuleNotFoundError: No module named 'netifaces'

Any ideas much appreciated.

Thanks.

@ttaggorf
Copy link

ttaggorf commented Apr 3, 2024

Having the same issue here. Downgraded to Python 3.8 but how getting

sysadmin@pve-homebridge-1:/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin$ python3.8 hisensetv.py 172.16.0.13 --authorize --ifname ens18 --certfile tvcert.cer --keyfile tvkey.key

Traceback (most recent call last):
  File "hisensetv.py", line 3, in <module>
    from hisensetv import __main__
  File "/var/lib/homebridge/node_modules/homebridge-hisense-tv-remotenow/bin/hisensetv/__init__.py", line 17, in <module>
    import netifaces

ModuleNotFoundError: No module named 'netifaces'

Any ideas much appreciated.

Thanks.

This is resolved by running the below command and is often the result of a Python downgrade

sudo python3 -m pip install --force-reinstall --no-cache-dir netifaces

@MrAsterisco
Copy link
Owner

This is great, @ttaggorf ! Thank you for posting it. I would love to push forward the PR, but as I mentioned: I don't have an HiSenseTV anymore, so I would need somebody to test it. I left a comment in the PR but it was never answered.

@LeLunZ
Copy link
Collaborator

LeLunZ commented May 31, 2024

@samjones108 your issue got fixed in 2.0.1 if you still have the tv give it a try ;)

@LeLunZ LeLunZ closed this as completed May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants