From dbc304dfe7422210e4d74904487117ed188f54c9 Mon Sep 17 00:00:00 2001 From: HarvsG <11440490+HarvsG@users.noreply.github.com> Date: Sun, 14 Sep 2025 16:11:34 +0100 Subject: [PATCH 1/5] support different hash methods for final hash. Should help with: https://github.com/HarvsG/ha-glinet4-integration/issues/40 --- gli4py/glinet.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gli4py/glinet.py b/gli4py/glinet.py index e09b42d..accaf4c 100644 --- a/gli4py/glinet.py +++ b/gli4py/glinet.py @@ -93,6 +93,7 @@ async def login(self, username: str, password: str) -> None: alg = res["alg"] salt = res["salt"] nonce = res["nonce"] + hash_method = res.get("hash-method", "md5") # Step2: Generate cipher text using openssl algorithm if alg == 1: # MD5 @@ -106,9 +107,17 @@ async def login(self, username: str, password: str) -> None: password ) else: - raise ValueError("Router requested unsupported hashing algorithm") + raise ValueError("Router requested unsupported hashing algorithm for cipher password") # Step3: Generate hash values for login + if hash_method == "md5": # MD5 + hsh = hashlib.md5(data.encode()).hexdigest() + elif hash_method == "sha256": # SHA-256 + hash = hashlib.sha256(data.encode()).hexdigest() + elif hash_method == "sha256": # SHA-512 + hash = hashlib.sha512(data.encode()).hexdigest() + else: + raise ValueError("Router requested unsupported hashing algorithm for cipher password") data = f"{username}:{cipher_password}:{nonce}" hsh = hashlib.md5(data.encode()).hexdigest() @@ -435,3 +444,4 @@ async def tailscale_stop(self, depth: int = 0) -> True: def logged_in(self) -> bool: """Returns whether the client is logged in.""" return self._logged_in + From 6d310c80ff3072c7b60bccbdc367529b2c2ec1a2 Mon Sep 17 00:00:00 2001 From: HarvsG <11440490+HarvsG@users.noreply.github.com> Date: Sun, 14 Sep 2025 16:13:40 +0100 Subject: [PATCH 2/5] Update glinet.py --- gli4py/glinet.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gli4py/glinet.py b/gli4py/glinet.py index accaf4c..2283eba 100644 --- a/gli4py/glinet.py +++ b/gli4py/glinet.py @@ -110,17 +110,16 @@ async def login(self, username: str, password: str) -> None: raise ValueError("Router requested unsupported hashing algorithm for cipher password") # Step3: Generate hash values for login + data = f"{username}:{cipher_password}:{nonce}" if hash_method == "md5": # MD5 hsh = hashlib.md5(data.encode()).hexdigest() elif hash_method == "sha256": # SHA-256 - hash = hashlib.sha256(data.encode()).hexdigest() + hsh = hashlib.sha256(data.encode()).hexdigest() elif hash_method == "sha256": # SHA-512 - hash = hashlib.sha512(data.encode()).hexdigest() + hsh = hashlib.sha512(data.encode()).hexdigest() else: raise ValueError("Router requested unsupported hashing algorithm for cipher password") - data = f"{username}:{cipher_password}:{nonce}" - hsh = hashlib.md5(data.encode()).hexdigest() - + # Step4: Get sid by login res = await self._get_sid(username, hsh) if "sid" in res: @@ -445,3 +444,4 @@ def logged_in(self) -> bool: """Returns whether the client is logged in.""" return self._logged_in + From 93fb80aba89053ffdbec08417e2031cb3570a8fa Mon Sep 17 00:00:00 2001 From: HarvsG <11440490+HarvsG@users.noreply.github.com> Date: Sun, 14 Sep 2025 16:15:05 +0100 Subject: [PATCH 3/5] Update glinet.py --- gli4py/glinet.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gli4py/glinet.py b/gli4py/glinet.py index 2283eba..4d1345f 100644 --- a/gli4py/glinet.py +++ b/gli4py/glinet.py @@ -119,7 +119,7 @@ async def login(self, username: str, password: str) -> None: hsh = hashlib.sha512(data.encode()).hexdigest() else: raise ValueError("Router requested unsupported hashing algorithm for cipher password") - + # Step4: Get sid by login res = await self._get_sid(username, hsh) if "sid" in res: @@ -443,5 +443,3 @@ async def tailscale_stop(self, depth: int = 0) -> True: def logged_in(self) -> bool: """Returns whether the client is logged in.""" return self._logged_in - - From f8782cf49ed74338e80187b9a5d330b2cfdbf5c1 Mon Sep 17 00:00:00 2001 From: HarvsG <11440490+HarvsG@users.noreply.github.com> Date: Sun, 14 Sep 2025 16:17:10 +0100 Subject: [PATCH 4/5] Update glinet.py --- gli4py/glinet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gli4py/glinet.py b/gli4py/glinet.py index 4d1345f..706eea8 100644 --- a/gli4py/glinet.py +++ b/gli4py/glinet.py @@ -118,7 +118,7 @@ async def login(self, username: str, password: str) -> None: elif hash_method == "sha256": # SHA-512 hsh = hashlib.sha512(data.encode()).hexdigest() else: - raise ValueError("Router requested unsupported hashing algorithm for cipher password") + raise ValueError("Router requested unsupported hashing algorithm for hash") # Step4: Get sid by login res = await self._get_sid(username, hsh) @@ -443,3 +443,4 @@ async def tailscale_stop(self, depth: int = 0) -> True: def logged_in(self) -> bool: """Returns whether the client is logged in.""" return self._logged_in + From da21cfa97463fc5b618320ed22fa5a404ef14041 Mon Sep 17 00:00:00 2001 From: HarvsG <11440490+HarvsG@users.noreply.github.com> Date: Sun, 14 Sep 2025 16:53:04 +0100 Subject: [PATCH 5/5] Update glinet.py --- gli4py/glinet.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gli4py/glinet.py b/gli4py/glinet.py index 706eea8..0477edc 100644 --- a/gli4py/glinet.py +++ b/gli4py/glinet.py @@ -443,4 +443,3 @@ async def tailscale_stop(self, depth: int = 0) -> True: def logged_in(self) -> bool: """Returns whether the client is logged in.""" return self._logged_in -