mac-zhou / midea-msmart

This is a library to allow communicating to a Midea AC via the Local area network.
MIT License
147 stars 39 forks source link

ERROR:msmart.security:authentication failed - no working token/key received #105

Closed Yetangitu closed 1 year ago

Yetangitu commented 1 year ago

This is the same issue as reported in a project derived from this one - midea-beautiful-air, https://github.com/nbogojevic/midea-beautiful-air/issues/21 - so what is stated there is valid here as well. A short recap:

I'm trying to get a heat pump with an EU-OSK103 dongle connected - it works in the app but I don't see why Xi needs to have control over my equipment - but have thus far not been able to do so due to token/key errors. The thing does retrieve token/key combinations but these do not seem to work. These errors occur both in this application as well as similar ones, e.g. the openHAB MideaAC binding. While I normally have all IoT devices living on their own network which is unable to reach out to the 'net I temporarily gave the OSK103 full access to see whether that made any difference but it did not work either. I also tested this on a newly created container with a single network interface on the IoT network and access to the 'net, the result was the same.

The layout is as follows:

$ midea-discover -d -a 'mideaair-f@unternet.org' -p 'l0n0 v00r midea' -i 192.168.4.103
INFO:msmart.cli:Debug mode active
INFO:msmart.cli:msmart version: 0.2.5 Currently only supports ac devices, only support MSmartHome and 美的美居 APP.
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:msmart.scanner:Message sent
DEBUG:msmart.scanner:Midea Local Data 192.168.4.103 
...
...
...

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mp-prod.appsmb.com:443
DEBUG:urllib3.connectionpool:https://mp-prod.appsmb.com:443 "POST /mas/v5/app/proxy?alias=/mj/user/login HTTP/1.1" 200 866
DEBUG:msmart.cloud:Response: {"code":0,"msg":"成功","data":{"randomData":"41e40b63996418fd670356e5d363265231d1bfb6eb874dcaea5153c4ee55a2ea","uid":"***********************","accountId":"**********","nickname":"**************","mdata":{"tokenPwdInfo":{"tokenPwd":"*****************************","expiredDate":1675863252451,"createDate":1673271252451},"userInfo":{"sourceId":"mj_12345","empId":"***********************","address":"","gender":"0","mobile":"******************************","userDeptInfoList":null,"extras":null,"nameEn":null,"employeeNumber":null,"headPhoto":null,"uid":"*************************","name":"******************","email":null},"doDeviceBind":null,"accessToken":"********************","signUnlockEnabled":null},"accessToken":"*******************************************","userId":"*********************","email":"************************"}}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mp-prod.appsmb.com:443
DEBUG:urllib3.connectionpool:https://mp-prod.appsmb.com:443 "POST /mas/v5/app/proxy?alias=/v1/iot/secure/getToken HTTP/1.1" 200 303
DEBUG:msmart.cloud:Response: {"code":"0","msg":"ok","data":{"tokenlist":[{"udpId":"FIRST_UDP_ID_VARIANT","key":"*************************************b634a85ed849bfa0308469347c847a","token":"********************************************74985A11973715121C5E3DBB006156A98EB4797B983E8E8493385FBB273061E1CA35516187686"}]}}
DEBUG:msmart.lan:Attempting new connection to 192.168.4.103:6444
DEBUG:msmart.lan:Socket 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.0 tcp_key: None
DEBUG:msmart.lan:Sending 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.0 message: ********************************************LONG MESSAGE ****************************************
DEBUG:msmart.lan:Recv 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.19 Response: 83700005200f00004552524f52 <<<<<<<<<<<< DONGLE REPORTS ERROR <<<<<<<<<<<<<<<<<<
ERROR:msmart.security:authentication failed <<<<<<<< FIRST FAILURE <<<<<<<<<<<<<<<<
ERROR:msmart.lan:Authentication failed for 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.19 
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): mp-prod.appsmb.com:443
DEBUG:urllib3.connectionpool:https://mp-prod.appsmb.com:443 "POST /mas/v5/app/proxy?alias=/v1/iot/secure/getToken HTTP/1.1" 200 303
DEBUG:msmart.cloud:Response: {"code":"0","msg":"ok","data":{"tokenlist":[{"udpId":"SECOND_UDP_ID_VARIANT","key":"**********************************4d1e968fbdd998c80d76","token":"**************************************************30F4A7E763736CE9FC38668D575E54DE8FAE7E3469003EC970D4B174CD0A1EB9ABCF5EF78A193E"}]}}
DEBUG:msmart.lan:Socket 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.61 tcp_key: None
DEBUG:msmart.lan:Sending 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.61 message: ***************************************** LONG MESSAGE ***************************************
DEBUG:msmart.lan:Recv 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.61 Response: 83700005200f00004552524f52 <<<<<<<<<< DONGLE REPORTS ERROR <<<<<<<<<<<<<<<<<
ERROR:msmart.security:authentication failed <<<<<<<<<<<<<<<< SECOND FAILURE <<<<<<<<<<<<<
ERROR:msmart.lan:Authentication failed for 192.168.4.200:55344 -> 192.168.4.103:6444 retries: 0 time: 0.61 
...
...
...

As shown it tried to get a token/ke twice using both variants of the udpid encoding but neither combination works. The device does work with the MSmartHome (or whatever it is called now) app but I 'm not foolish enough to allow that kind of access to my own network to 'cloudy' service providers, see also my rant at the end of https://github.com/nbogojevic/midea-beautiful-air/issues/21 .

Given that things work with the app I feel like it should be possible to make it work here as well. The problem seems (?) to lie in the token/key combination which for some reason does not work.

mac-zhou commented 1 year ago

You must give the device Internet permission. The v3 device needs to access the midea cloud to exchange keys.

Yetangitu commented 1 year ago

Both devices - host and AC dongle - have internet connectivity so that is not the problem.

Something else is amiss though as the device only seems to work directly after it has been connected to the app. Once power to the device has been cut and reinstated it no longer works in the app either, this without any changes in the network configuration. I tested this MSmartHome and NetHome Plus with the same result. The dongle comes online as usual and its address is pingable but it is shown as "offline" in the apps.

There are a few things which may confound the issue: