Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token can not be discovered or extracted #93

Open
aholstenson opened this issue Jan 23, 2018 · 9 comments
Open

Token can not be discovered or extracted #93

aholstenson opened this issue Jan 23, 2018 · 9 comments

Comments

@aholstenson
Copy link
Owner

This issue is a collection and reminder to look over automatic token extraction and the documentation for how to get a token for things such as the vacuum cleaners and Philips Light Bulbs.

For some great information look into #40 and #80 which both contain information about alternative ways to extract tokens.

@thunderace
Copy link

A solution is to install this modified MiHome APP : http://www.kapiba.ru/2017/11/mi-home.html
Tokens are displayed in the app

@Hax2kon
Copy link

Hax2kon commented Sep 22, 2018

For anyone with android struggling with token, I wrote up this guide. In short, you emulate a rooted android and get the database from it. No need to downgrade phone app.

https://www.reddit.com/r/Xiaomi/comments/9ht0vn/the_easy_workaround_to_get_your_xiaomi_vacuum/?utm_source=reddit-android

@dazhbog
Copy link

dazhbog commented Sep 9, 2019

Newer versions of some peripherals seem to change their token on wifi change. That means that the devices stops responding once the wifi is configured with the {"method":"miIO.config_router","params":{"ssid":"XXX","passwd":"XXX"},"id":X} command.

My guess is that the device gets online once WiFi is set up and it generates/uploads a new token that the app can then access.

It would be interesting to see how the new token exchange occurs and whether the token renewal still takes place if xiaomi's servers are not reachable.

@dazhbog
Copy link

dazhbog commented Sep 13, 2019

For anyone wondering, uninstalling any other Mi Home apps, clearing their data and installing Mi Home 5.4.54 (and restarting the phone) allowed me to get the token from the app's log files.

You will need to click on the smart device in the app for the first time so that Mi Home downloads the token and write it to the log file. The token can then be extracted from the log file that is located in the "Smart home" folder in the sdcard Android directory. After that I was able to control my stuff.

Hope this helps.

@mitchins
Copy link

Newer versions of some peripherals seem to change their token on wifi change. That means that the devices stops responding once the wifi is configured with the {"method":"miIO.config_router","params":{"ssid":"XXX","passwd":"XXX"},"id":X} command.

My guess is that the device gets online once WiFi is set up and it generates/uploads a new token that the app can then access.

It would be interesting to see how the new token exchange occurs and whether the token renewal still takes place if xiaomi's servers are not reachable.

I can (and did) verify this!

Prelude: I faced the exact same issue for the first time after buying a Mi Air Purifier Pro (zhimi.airpurifier.v7)

  • Commands would all work etc etc during the unsecured hotspot from my laptop.
  • Recent iOS MiHome app pairs and everything as fine.
  • The old Android app (last version before they stopped storing tokens on device) no longer seems to be supported, I don't get an error message, but login is slow, as are most functions and session and operations seem to be patchy at best or outright timeout. This would seem deliberate as it was obvious it would eventually be deprecated to prevent access

After about two hours of trying to repair with either my laptop or the old Android app I gave up and did the following:

  1. Create a tagged VLAN (pure VLAN only) on my Unifi.
  2. Assign this VLAN to a new wifi network
  3. Have my HassIO instance join with it's integrated intel wifi (Celeron J1900)
  4. Create a DHCP controller and new subnet purely on the VNET. (config below for anyone interested, you could also just create a hotspot too if your network hardware is less sophisticated, or even use a usb network adapter and an old airport or whatever). The important thing to note here is I have not done any IP forwarding or NAT, there's no internet traffic at all from within the VLAN. Thus when the purifier fails to see the Xiaomi servers it doesn't change the token and the original one is valid. Further work on this might be possible to see if certain domains are used for activation, or if the SSL certificates can be forged by MITM proxy or anything similar, I won't do this at this stage as I'm happy not to use the mi app and just use HassIO.
  5. Use miio-cli tool to configure the freshly nuked purifier to join the wifi.
  6. Verify from either another computer on the wifi network or the master host, that the auto-token given initially still works (AND IT DOES! :D )

Test output:

miiocli airpurifier --ip 192.168.100.174 --token <XXXXXXXXXXXXXXXXX> info
Model: zhimi.airpurifier.v7
Hardware version: MW300
Firmware version: 1.4.3_19105
Network: {'localIp': '192.168.100.174', 'mask': '255.255.255.0', 'gw': '192.168.100.1', 'gw_mac': '74:44:01:FC:0F:B0'}
AP: {'rssi': -48, 'ssid': 'LookingGlass', 'bssid': 'FE:EC:DA:2F:89:8E'}

dnsmasq.conf (super slimmed down)

port=0
interface=wlp2s0b1
dhcp-range=192.168.100.3,192.168.100.255,72h

@phrogg
Copy link

phrogg commented Jan 5, 2020

How do you change the wifi? Via miio or the or pyton-miio (miiocli)? I tried this several times now and I can't get it too work. With this app I was able to extract the tokens from the yeelight app https://github.com/phrogg/GetMiTokens/, however my goal as well as yours is also to get this to work without the app at all. I used my normal network and just dc the router from the internet, was that wrong?

@cisco-devnet
Copy link

cisco-devnet commented Jan 9, 2020

Hello!

I agree with @mitchins in case of purifier pro and 2s - the behavior is exact as you described in case of stub WiFi network without internet.
But I have this issue (changing token) with Purifier 3H "fw_ver":"2.0.5","mcu_fw_ver":"0009","miio_ver":"0.0.5","hw_ver":"esp32".

@mitchins
Copy link

mitchins commented Jan 9, 2020

Hello!

I agree with @mitchins in case of purifier pro and 2s - the behavior is exact as you described in case of stub WiFi network without internet.
But I have this issue (changing token) with Purifier 3H "fw_ver":"2.0.5","mcu_fw_ver":"0009","miio_ver":"0.0.5","hw_ver":"esp32".

I strongly suspect it’s universal to most new xiaomi firmwares across many devices. Why do it for one when you can do it for all.

@ofen
Copy link

ofen commented Nov 1, 2021

Managed to get new valid token for mmgg.pet_waterer.s1 from Xiaomi cloud via https://github.com/Squachen/micloud#in-terminal after initial miIO.config_route command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants