1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

Fix incompatibilities with v0.11 movement of methods to misc library.

- pwd_reader.py
    - Moved encrypt/decrypt calls to misc module from client.
    - Corrected key to encode in binstr for Py3.7 hmac functions.
    - Added ui to client.

- pwd_reader.py
    - Moved entropy calls to misc module from client.
    - Added ui to client.
This commit is contained in:
brianddk 2019-02-26 21:07:32 -06:00 committed by matejcik
parent 972b47c8e1
commit 96ce34b276
2 changed files with 13 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import json
import os import os
from urllib.parse import urlparse from urllib.parse import urlparse
from trezorlib import misc, ui
from trezorlib.client import TrezorClient from trezorlib.client import TrezorClient
from trezorlib.transport import get_transport from trezorlib.transport import get_transport
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
@ -21,7 +22,8 @@ def getMasterKey(client):
bip32_path = BIP32_PATH bip32_path = BIP32_PATH
ENC_KEY = 'Activate TREZOR Password Manager?' ENC_KEY = 'Activate TREZOR Password Manager?'
ENC_VALUE = bytes.fromhex('2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee') ENC_VALUE = bytes.fromhex('2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee')
key = client.encrypt_keyvalue( key = misc.encrypt_keyvalue(
client,
bip32_path, bip32_path,
ENC_KEY, ENC_KEY,
ENC_VALUE, ENC_VALUE,
@ -35,7 +37,7 @@ def getMasterKey(client):
def getFileEncKey(key): def getFileEncKey(key):
filekey, enckey = key[:len(key) // 2], key[len(key) // 2:] filekey, enckey = key[:len(key) // 2], key[len(key) // 2:]
FILENAME_MESS = b'5f91add3fa1c3c76e90c90a3bd0999e2bd7833d06a483fe884ee60397aca277a' FILENAME_MESS = b'5f91add3fa1c3c76e90c90a3bd0999e2bd7833d06a483fe884ee60397aca277a'
digest = hmac.new(filekey, FILENAME_MESS, hashlib.sha256).hexdigest() digest = hmac.new(str.encode(filekey), FILENAME_MESS, hashlib.sha256).hexdigest()
filename = digest + '.pswd' filename = digest + '.pswd'
return [filename, filekey, enckey] return [filename, filekey, enckey]
@ -97,7 +99,8 @@ def getDecryptedNonce(client, entry):
ENC_KEY = 'Unlock %s for user %s?' % (item, entry['username']) ENC_KEY = 'Unlock %s for user %s?' % (item, entry['username'])
ENC_VALUE = entry['nonce'] ENC_VALUE = entry['nonce']
decrypted_nonce = client.decrypt_keyvalue( decrypted_nonce = misc.decrypt_keyvalue(
client,
BIP32_PATH, BIP32_PATH,
ENC_KEY, ENC_KEY,
bytes.fromhex(ENC_VALUE), bytes.fromhex(ENC_VALUE),
@ -130,7 +133,7 @@ def main():
print(e) print(e)
return return
client = TrezorClient(transport) client = TrezorClient(transport=transport, ui=ui.ClickUI())
print() print()
print('Confirm operation on TREZOR') print('Confirm operation on TREZOR')
@ -142,13 +145,14 @@ def main():
fileName = getFileEncKey(masterKey)[0] fileName = getFileEncKey(masterKey)[0]
# print('file name:', fileName) # print('file name:', fileName)
path = os.path.expanduser('~/Dropbox/Apps/TREZOR Password Manager/') home = os.path.expanduser('~')
path = os.path.join(home, 'Dropbox', 'Apps', 'TREZOR Password Manager')
# print('path to file:', path) # print('path to file:', path)
encKey = getFileEncKey(masterKey)[2] encKey = getFileEncKey(masterKey)[2]
# print('enckey:', encKey) # print('enckey:', encKey)
full_path = path + fileName full_path = os.path.join(path, fileName)
parsed_json = decryptStorage(full_path, encKey) parsed_json = decryptStorage(full_path, encKey)
# list entries # list entries

View File

@ -6,13 +6,14 @@
import io import io
import sys import sys
from trezorlib import misc, ui
from trezorlib.client import TrezorClient from trezorlib.client import TrezorClient
from trezorlib.transport import get_transport from trezorlib.transport import get_transport
def main(): def main():
try: try:
client = TrezorClient(get_transport()) client = TrezorClient(get_transport(), ui=ui.ClickUI())
except Exception as e: except Exception as e:
print(e) print(e)
return return
@ -23,7 +24,7 @@ def main():
with io.open(arg1, 'wb') as f: with io.open(arg1, 'wb') as f:
for i in range(0, arg2, step): for i in range(0, arg2, step):
entropy = client.get_entropy(step) entropy = misc.get_entropy(client, step)
f.write(entropy) f.write(entropy)
client.close() client.close()