From 55641dd8b5e52fdad8235ab97ecee70dd1d6d6e3 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 2 Mar 2018 16:47:29 +0100 Subject: [PATCH] make flake8 happy (#225) --- tools/pwd_reader.py | 19 ++++++++++++++----- trezorlib/client.py | 2 +- .../device_tests/test_msg_signtx_bcash.py | 1 - 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/pwd_reader.py b/tools/pwd_reader.py index 2c6c4bd25..7fdea73fa 100755 --- a/tools/pwd_reader.py +++ b/tools/pwd_reader.py @@ -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() diff --git a/trezorlib/client.py b/trezorlib/client.py index 40643e1c9..d7356e3b7 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -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)) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index 4b219a81b..61a27c0dd 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -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)