DaveGut / HubitatActive

Hubitat Environment Developments
64 stars 87 forks source link

#29: KasaDevices - Fix issue with auth failure #30

Closed TonyFleisher closed 1 year ago

TonyFleisher commented 1 year ago

Hubitat escapes input that has certain special characters. This needs to be reversed before sending passwords. (This may not be exactly correct and there maybe other characters needed for this as well, but this patch resolved the issue I encountered.)

DaveGut commented 1 year ago

can you try the following instead on line 447. It would be preferable. In groovy, the triple quotes usually pass the enclosed data as-is (without escaping any characters).

cloudPassword: """${userPassword}""",

TonyFleisher commented 1 year ago

I don't think that does the same thing... the issue is that the value in the app settings itself is escaped (e.g. userPassword = "abc&lt;123" instead of "abc<123") by the hubitat security wrapping on input.

DaveGut commented 1 year ago

What country are you in? It looks like your character set is not the same as used in US and that is the issue. Below is a log sequence of a test on my live system entering "abc<123" into the password field. Basically can not duplicate in the Community version. I will add your code - but I really do not know why it is occurring to begin with.

[uri:https://wap.tplinkcloud.com, requestContentType:application/json, contentType:application/json, headers:[Accept:application/json; version=1, */*; q=0.01], body:{"method":"login","params":{"appType":"Kasa_Android","cloudUserName":"dutheinz@outlook.com","cloudPassword":"abc<123","terminalUUID":"4834df24-aaa-494c-abf1-5cbbaaaaaaa"}}]
[app:4903](http://192.168.50.197/logs#)2022-10-17 06:50:08.220[warn](http://192.168.50.197/logs#)[method:login, params:[appType:Kasa_Android, cloudUserName:dunz@outlook.com, cloudPassword:abc<123, terminalUUID:4834df24-aaa-494c-abf1-5cbbaaaaaaa]]
[app:4903](http://192.168.50.197/logs#)2022-10-17 06:50:08.206[warn](http://192.168.50.197/logs#)abc<123
TonyFleisher commented 1 year ago

Sorry it was not clear. I will try to provide some more details in the Issue. The root-cause here is not with the comunictaion with tp-link cloud, it is with how Hubitat stores the password when you enter it in the Kasa Integration app.

TonyFleisher commented 1 year ago

https://github.com/DaveGut/HubitatActive/issues/29#issuecomment-1281309489

TonyFleisher commented 1 year ago

I suppose an alternative to translating on send might be to do the translation in updated() and rewrite the app settings when the password is entered.

DaveGut commented 1 year ago

I plan to do your update (next release). However, the logs I showed you were on the Hubiat system and the password was processed by that system. Then, when recalled, there were not escape characters. I am curious as to why so we can write a problem report for Hubitat (who should fix the password storing function).

TonyFleisher commented 1 year ago

oh. maybe because the log screen itself interprets the html? You can try changing your password to one that has the less-than character, or just add this to the top of getToken() to show each character separately.

logDebug("Password chars: ${userPassword.split("(?!^)").join('::')}")

Password chars: 1::2::3::&::l::t::;::>::a::b::c

Result looks like this: [app:348](http://192.168.1.123/logs#)2022-10-17 14:04:56.826[info](http://192.168.1.123/logs#)[KasaInt: 6.7.1]: getTokenFromStart: Result = [[updateFailed: [error_code:-20601, msg:Incorrect email or password]]] [app:348](http://192.168.1.123/logs#)2022-10-17 14:04:56.782[warn](http://192.168.1.123/logs#)[KasaInt: 6.7.1]: getToken: [[updateFailed: [error_code:-20601, msg:Incorrect email or password]]]] [app:348](http://192.168.1.123/logs#)2022-10-17 14:04:56.206[debug](http://192.168.1.123/logs#)[KasaInt: 6.7.1]: Password chars: 1::2::3::&::l::t::;::>::a::b::c

DaveGut commented 1 year ago

Close with release of version 6.7.2.