feat(klaptransport): auto-detect KLAP v2 for IOT devices#1625
feat(klaptransport): auto-detect KLAP v2 for IOT devices#1625adamjacobmuller wants to merge 1 commit intopython-kasa:masterfrom
Conversation
Some IOT devices (e.g., HS300 with newer firmware) use KLAP v2 authentication (sha256/sha1 hashing) despite being classified as IOT devices. This modifies KlapTransport to try v2 hashing as a fallback when v1 doesn't match.
|
@adamjacobmuller Appreciate the great work here. The newer firmwares have a new flag in the device discovery process called new_klap. I created a PR already that uses this flag to determine the correct transport to use during the discovery process instead of modifying the transports themselves, PR#1580. Your method, while it works, mixes the authentication process between the two different KLAP transports and it doesn't keep a clean line of separation between them. I just finished it recently, had to handle some issues with the CLI and making sure that all of the other devices and tests worked correctly. Just waiting on merging and a new version to get it going. |
Confirmed Working ✅Just tested this PR on two HS300 power strips that were previously failing with the "Device response did not match our challenge" error. Environment:
Before this PR: Authentication failed with KLAP v1 (md5) Test Results: The auto-detection of KLAP v2 worked seamlessly. Really appreciate this fix - these strips have been unusable with Home Assistant since the October firmware update. Hope this helps get the PR merged! 🎉 |
|
HS300 was exactly what I built this for (nice little gadget). Hoping it gets merged too, but, it works fine for me either way :) |
Summary
Some IOT devices (e.g., HS300 with newer firmware) use KLAP v2 authentication (sha256/sha1 hashing) despite being classified as IOT devices. Previously,
IOT.KLAPwas hardcoded to useKlapTransportwhich only supports v1 (md5) hashing, causing authentication failures with the error:Changes
This PR modifies
KlapTransport.perform_handshake1()to try v2 hashing (sha256/sha1) as a fallback when v1 (md5) doesn't match the server hash. If v2 succeeds, the transport remembers this via_uses_v2_hashingflag and uses v2 hashing forhandshake2as well.The v2 fallback tries:
Affected devices
Testing
Tested on HS300 that was previously failing authentication. After this change, the device authenticates successfully using KLAP v2 while still being correctly classified as an IOT device.