mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 06:18:07 +00:00
make flake8 happy (#225)
This commit is contained in:
parent
b24550c72f
commit
55641dd8b5
@ -18,10 +18,12 @@ except:
|
||||
from trezorlib.client import TrezorClient
|
||||
from trezorlib.transport_hid import HidTransport
|
||||
|
||||
|
||||
# Return path by BIP-32
|
||||
def getPath(client):
|
||||
return client.expand_path("10016'/0")
|
||||
|
||||
|
||||
# Deriving master key
|
||||
def getMasterKey(client):
|
||||
bip32_path = getPath(client)
|
||||
@ -36,14 +38,16 @@ def getMasterKey(client):
|
||||
))
|
||||
return key
|
||||
|
||||
|
||||
# Deriving file name and encryption 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'
|
||||
digest = hmac.new(filekey, FILENAME_MESS, hashlib.sha256).hexdigest()
|
||||
filename = digest + '.pswd'
|
||||
return [filename, filekey, enckey]
|
||||
|
||||
|
||||
# File level decryption and file reading
|
||||
def decryptStorage(path, key):
|
||||
cipherkey = unhexlify(key)
|
||||
@ -64,6 +68,7 @@ def decryptStorage(path, key):
|
||||
data = data + decryptor.finalize().decode()
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def decryptEntryValue(nonce, val):
|
||||
cipherkey = unhexlify(nonce)
|
||||
iv = val[:12]
|
||||
@ -83,6 +88,7 @@ def decryptEntryValue(nonce, val):
|
||||
data = data + decryptor.finalize().decode()
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
# Decrypt give entry nonce
|
||||
def getDecryptedNonce(client, entry):
|
||||
print()
|
||||
@ -99,7 +105,7 @@ def getDecryptedNonce(client, entry):
|
||||
|
||||
ENC_KEY = 'Unlock %s for user %s?' % (item, entry['username'])
|
||||
ENC_VALUE = entry['nonce']
|
||||
decrypted_nonce = hexlify(client.decrypt_keyvalue(
|
||||
decrypted_nonce = hexlify(client.decrypt_keyvalue(
|
||||
getPath(client),
|
||||
ENC_KEY,
|
||||
unhexlify(ENC_VALUE),
|
||||
@ -108,6 +114,7 @@ def getDecryptedNonce(client, entry):
|
||||
))
|
||||
return decrypted_nonce
|
||||
|
||||
|
||||
# Pretty print of list
|
||||
def printEntries(entries):
|
||||
print('Password entries')
|
||||
@ -117,7 +124,8 @@ def printEntries(entries):
|
||||
print('Entry id: #%s' % k)
|
||||
print('-------------')
|
||||
for kk, vv in v.items():
|
||||
if kk in ['nonce', 'safe_note', 'password']: continue # skip these fields
|
||||
if kk in ['nonce', 'safe_note', 'password']:
|
||||
continue # skip these fields
|
||||
print('*', kk, ': ', vv)
|
||||
print()
|
||||
return
|
||||
@ -160,14 +168,15 @@ def main():
|
||||
plain_nonce = getDecryptedNonce(client, entries[entry_id])
|
||||
|
||||
pwdArr = entries[entry_id]['password']['data']
|
||||
pwdHex = ''.join([ hex(x)[2:].zfill(2) for x in pwdArr ])
|
||||
pwdHex = ''.join([hex(x)[2:].zfill(2) for x in pwdArr])
|
||||
print('password: ', decryptEntryValue(plain_nonce, unhexlify(pwdHex)))
|
||||
|
||||
safeNoteArr = entries[entry_id]['safe_note']['data']
|
||||
safeNoteHex = ''.join([ hex(x)[2:].zfill(2) for x in safeNoteArr ])
|
||||
safeNoteHex = ''.join([hex(x)[2:].zfill(2) for x in safeNoteArr])
|
||||
print('safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex)))
|
||||
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -425,7 +425,7 @@ class DebugLinkMixin(object):
|
||||
continue
|
||||
if getattr(msg, field) != value:
|
||||
raise AssertionException(proto.FailureType.UnexpectedMessage,
|
||||
"Expected %s, got %s" % (pprint(expected), pprint(msg)))
|
||||
"Expected %s, got %s" % (pprint(expected), pprint(msg)))
|
||||
|
||||
def callback_ButtonRequest(self, msg):
|
||||
log("ButtonRequest code: " + get_buttonrequest_value(msg.code))
|
||||
|
@ -187,7 +187,6 @@ class TestMsgSigntxBch(TrezorTest):
|
||||
else:
|
||||
assert False # exception expected
|
||||
|
||||
|
||||
def test_attack_change_input(self):
|
||||
self.setup_mnemonic_allallall()
|
||||
self.client.set_tx_api(TxApiBcash)
|
||||
|
Loading…
Reference in New Issue
Block a user