Skip to content

Commit 1a2cb73

Browse files
committed
Use certificate pinning for API requests
1 parent 466ceee commit 1a2cb73

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

karcher/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from karcher.exception import KarcherHomeException
1414
from karcher.karcher import KarcherHome
15-
from karcher.consts import Region
1615

1716
try:
1817
from rich import print as echo

karcher/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ class Product(str, Enum):
116116
PROTOCOL_VERSION = 'v1'
117117
APP_VERSION_CODE = 10004
118118
APP_VERSION_NAME = '1.0.4'
119+
SSL_CERTIFICATE_THUMBPRINT = bytes.fromhex('68:A3:68:92:5D:B3:DE:51:6A:80:64:FD:70:38:A3:49:45:D8:6E:DF:11:33:08:66:2C:87:85:A4:C9:F5:4A:10'.replace(':', ''))

karcher/karcher.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: MIT
44
# -----------------------------------------------------------
55

6+
import asyncio
67
import collections
78
import json
89
import threading
@@ -14,8 +15,8 @@
1415
from .auth import Domains, Session
1516
from .countries import get_country_code, get_region_by_country
1617
from .consts import (
17-
APP_VERSION_CODE, APP_VERSION_NAME, PROJECT_TYPE,
18-
PROTOCOL_VERSION, REGION_URLS, ROBOT_PROPERTIES, TENANT_ID,
18+
APP_VERSION_CODE, APP_VERSION_NAME, PROJECT_TYPE, PROTOCOL_VERSION,
19+
REGION_URLS, ROBOT_PROPERTIES, SSL_CERTIFICATE_THUMBPRINT, TENANT_ID,
1920
Language, Region
2021
)
2122
from .device import Device, DeviceProperties
@@ -32,7 +33,11 @@ class KarcherHome:
3233
"""Main class to access Karcher Home Robots API"""
3334

3435
@classmethod
35-
async def create(cls, country: str = 'GB', language: Language = Language.EN, session: aiohttp.ClientSession = None):
36+
async def create(
37+
cls,
38+
country: str = 'GB',
39+
language: Language = Language.EN,
40+
session: aiohttp.ClientSession = None):
3641
"""Create Karcher Home Robots API instance"""
3742

3843
self = KarcherHome()
@@ -65,11 +70,13 @@ def __init__(self):
6570
self._mqtt = None
6671
self._device_props = {}
6772
self._wait_events = {}
73+
self._http = None
74+
self._http_external = False
6875

6976
def __del__(self):
7077
"""Destructor"""
7178

72-
self.close()
79+
asyncio.run(self.close())
7380

7481
async def close(self):
7582
"""Close underlying connections"""
@@ -133,8 +140,7 @@ async def _request(self, method: str, url: str, **kwargs) -> aiohttp.ClientRespo
133140
headers['nonce'] = nonce
134141

135142
kwargs['headers'] = headers
136-
# TODO: Fix SSL
137-
kwargs['verify_ssl'] = False
143+
kwargs['ssl'] = aiohttp.Fingerprint(SSL_CERTIFICATE_THUMBPRINT)
138144
return await self._http.request(method, self._base_url + url, **kwargs)
139145

140146
async def _download(self, url) -> bytes:

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ extend-exclude = [
44

55
[per-file-ignores]
66
"tests/test_*.py" = ["E501"]
7+
"karcher/consts.py" = ["E501"]

0 commit comments

Comments
 (0)