Skip to content

Commit

Permalink
Depend only on one library for crypto
Browse files Browse the repository at this point in the history
* Drops pycrypto dependence
* Supersedes PR #122
  • Loading branch information
rytilahti committed Nov 18, 2017
1 parent 5f4e8b1 commit 88bd3c9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
10 changes: 7 additions & 3 deletions miio/extract_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import click
import tempfile
import sqlite3
from Crypto.Cipher import AES
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from pprint import pformat as pf
import attr
from android_backup import AndroidBackup
Expand Down Expand Up @@ -50,8 +51,11 @@ def decrypt_ztoken(ztoken):

keystring = '00000000000000000000000000000000'
key = bytes.fromhex(keystring)
cipher = AES.new(key, AES.MODE_ECB)
token = cipher.decrypt(bytes.fromhex(ztoken[:64]))
cipher = Cipher(algorithms.AES(key), modes.ECB(),
backend=default_backend())
decryptor = cipher.decryptor()
token = decryptor.update(bytes.fromhex(ztoken[:64])) \
+ decryptor.finalize()

return token.decode()

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cryptography
pretty_cron
construct
zeroconf
pycrypto # for miio-extract-tokens
attrs
typing # for py3.4 support
pytz # for tz offset in vacuum
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
'pretty_cron',
'typing; python_version < "3.5"',
'zeroconf',
'pycrypto',
'attrs',
'android_backup',
'pytz'],
Expand Down

0 comments on commit 88bd3c9

Please sign in to comment.