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

Unable to extract token from Android backup #138

Closed
outlying opened this issue Dec 10, 2017 · 9 comments
Closed

Unable to extract token from Android backup #138

outlying opened this issue Dec 10, 2017 · 9 comments
Labels

Comments

@outlying
Copy link

mirobo 0.3.2
Android 8.1 (Nexus 5X)
Mi Home 5.0.10
adb 1.0.39

I'm trying to extract token on OS X High Sierra (version 10.13).

Not much to describe, I start with downloading backup and I set password to 1 on my device

$ adb backup -noapk com.xiaomi.smarthome -f backup.ab
Now unlock your device and confirm the backup operation...
$

Then I'm trying to extract the token

$ miio-extract-tokens --password 1 backup.ab 
Saving database to /var/folders/f0/n_2l3ndj337_nfsyzlgy09gc0000gn/T/tmp13bony6u
INFO:miio.extract_tokens:Reading database from /var/folders/f0/n_2l3ndj337_nfsyzlgy09gc0000gn/T/tmp13bony6u
ERROR:miio.extract_tokens:Error, unknown database type!

I would add some debug output but I think miio-extract-tokens doesn't have one.

@rytilahti
Copy link
Owner

Could you take a look how does the database look like? Passing --write-to-disk test.db will save it to test.db for inspection.

@ralph089
Copy link

ralph089 commented Dec 30, 2017

Had the same issue. Also MacOS High Sierra, but I've got Android 6 installed on my phone. Maybe a permission issue? But same error with sudo. Solved it with the following steps:

  1. Create the Backup: adb backup -noapk com.xiaomi.smarthome -f backup.ab
  2. Create the db file from the ab-file: miio-extract-tokens --write-to-disk backup.db backup.ab
  3. Read the token: miio-extract-tokens backup.db

@outlying
Copy link
Author

outlying commented Jan 2, 2018

@rytilahti sure, only 3 tables, I will post schemas below

devicerecord

CREATE TABLE `devicerecord` (`bssid` VARCHAR , `canAuth` INTEGER , `canUseNotBind` INTEGER , `desc` VARCHAR , `descNew` VARCHAR , `descTimeJString` VARCHAR , `did` VARCHAR , `eventInfo` VARCHAR , `extraInfo` VARCHAR , `index` INTEGER PRIMARY KEY AUTOINCREMENT , `isOnline` INTEGER , `latitude` DOUBLE PRECISION , `localIP` VARCHAR , `location` INTEGER , `longitude` DOUBLE PRECISION , `mac` VARCHAR , `methodInfo` VARCHAR , `model` VARCHAR , `name` VARCHAR , `ownerId` VARCHAR , `ownerName` VARCHAR , `parentId` VARCHAR , `parentModel` VARCHAR , `permitLevel` INTEGER , `pid` INTEGER , `propInfo` VARCHAR , `resetFlag` INTEGER , `rssi` INTEGER , `showMode` INTEGER , `ssid` VARCHAR , `token` VARCHAR , `userId` VARCHAR , `version` VARCHAR )

android_metadata

CREATE TABLE android_metadata (locale TEXT)

sqlite_sequence

CREATE TABLE sqlite_sequence(name,seq)

I was able to extract token manually, it happens to be the same token I already have extracted previously. Unluckily this is not solving my issue, I'm not able to use this token to remote control the device.

Still, I think this issue is valid since automatic extraction is not working as intended

@ralph-hm your solution is not working in my case, first of all on higher version of Android backup is password protected, second, it just not working, I guess Xiomi has may have different app version for newer systems

@rytilahti
Copy link
Owner

@outlying the script (miio/extract_tokens.py) checks if there is a table devicerecord (for android) or ZDEVICE (for apple) by querying sqlite_master table (which is sqlite's internal way to keep track of available tables).

I'm not sure why it isn't working for you, but you could try to modify the "if is_android" check to test for True to see if it can extract the information.

Are you sure the tokens are encrypted for newer android versions? The script supports decrypting only passwords from iOS backups..

@rytilahti rytilahti added the bug label Jan 6, 2018
@outlying
Copy link
Author

outlying commented Jan 16, 2018

Token wasn't encrypted (I got the same token as I did with device auto discover mirobo discover --handshake 1), only the whole backup file, if you want I can send my Android backup file to you with password, I use my Mi app only for Air Purifier 2

@rytilahti
Copy link
Owner

@outlying please send it to me via e-mail and I'll take a look at it at some point later. tpr at iki dot fi is my address.

@fergardi
Copy link

I'm in this step to extract tokens but unable to execute the "miio-extract-tokens" command. What am I missing? I'm not a python expert, but I installed the "python-miio" package without problems, just cannot get the command to run. I'm on OSX. What command should I execute exactly?

@fergardi
Copy link

Nevermind, achieved and works as expected with the Xiaomi Yeelight Color Bulb. Thanks!

@rytilahti
Copy link
Owner

Closing for inactivity, please reopen if this is still an issue. The newer versions of mi home do not store the token in the database anymore, see #185.

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

No branches or pull requests

4 participants