1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

make flake8 happy (#225)

This commit is contained in:
matejcik 2018-03-02 16:47:29 +01:00 committed by Pavol Rusnak
parent b24550c72f
commit 55641dd8b5
3 changed files with 15 additions and 7 deletions

View File

@ -18,10 +18,12 @@ except:
from trezorlib.client import TrezorClient from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport from trezorlib.transport_hid import HidTransport
# Return path by BIP-32 # Return path by BIP-32
def getPath(client): def getPath(client):
return client.expand_path("10016'/0") return client.expand_path("10016'/0")
# Deriving master key # Deriving master key
def getMasterKey(client): def getMasterKey(client):
bip32_path = getPath(client) bip32_path = getPath(client)
@ -36,14 +38,16 @@ def getMasterKey(client):
)) ))
return key return key
# Deriving file name and encryption key # Deriving file name and encryption key
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(filekey, FILENAME_MESS, hashlib.sha256).hexdigest()
filename = digest + '.pswd' filename = digest + '.pswd'
return [filename, filekey, enckey] return [filename, filekey, enckey]
# File level decryption and file reading # File level decryption and file reading
def decryptStorage(path, key): def decryptStorage(path, key):
cipherkey = unhexlify(key) cipherkey = unhexlify(key)
@ -64,6 +68,7 @@ def decryptStorage(path, key):
data = data + decryptor.finalize().decode() data = data + decryptor.finalize().decode()
return json.loads(data) return json.loads(data)
def decryptEntryValue(nonce, val): def decryptEntryValue(nonce, val):
cipherkey = unhexlify(nonce) cipherkey = unhexlify(nonce)
iv = val[:12] iv = val[:12]
@ -83,6 +88,7 @@ def decryptEntryValue(nonce, val):
data = data + decryptor.finalize().decode() data = data + decryptor.finalize().decode()
return json.loads(data) return json.loads(data)
# Decrypt give entry nonce # Decrypt give entry nonce
def getDecryptedNonce(client, entry): def getDecryptedNonce(client, entry):
print() print()
@ -99,7 +105,7 @@ 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 = hexlify(client.decrypt_keyvalue( decrypted_nonce = hexlify(client.decrypt_keyvalue(
getPath(client), getPath(client),
ENC_KEY, ENC_KEY,
unhexlify(ENC_VALUE), unhexlify(ENC_VALUE),
@ -108,6 +114,7 @@ def getDecryptedNonce(client, entry):
)) ))
return decrypted_nonce return decrypted_nonce
# Pretty print of list # Pretty print of list
def printEntries(entries): def printEntries(entries):
print('Password entries') print('Password entries')
@ -117,7 +124,8 @@ def printEntries(entries):
print('Entry id: #%s' % k) print('Entry id: #%s' % k)
print('-------------') print('-------------')
for kk, vv in v.items(): 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('*', kk, ': ', vv)
print() print()
return return
@ -160,14 +168,15 @@ def main():
plain_nonce = getDecryptedNonce(client, entries[entry_id]) plain_nonce = getDecryptedNonce(client, entries[entry_id])
pwdArr = entries[entry_id]['password']['data'] 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))) print('password: ', decryptEntryValue(plain_nonce, unhexlify(pwdHex)))
safeNoteArr = entries[entry_id]['safe_note']['data'] 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))) print('safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex)))
return return
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -425,7 +425,7 @@ class DebugLinkMixin(object):
continue continue
if getattr(msg, field) != value: if getattr(msg, field) != value:
raise AssertionException(proto.FailureType.UnexpectedMessage, 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): def callback_ButtonRequest(self, msg):
log("ButtonRequest code: " + get_buttonrequest_value(msg.code)) log("ButtonRequest code: " + get_buttonrequest_value(msg.code))

View File

@ -187,7 +187,6 @@ class TestMsgSigntxBch(TrezorTest):
else: else:
assert False # exception expected assert False # exception expected
def test_attack_change_input(self): def test_attack_change_input(self):
self.setup_mnemonic_allallall() self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiBcash) self.client.set_tx_api(TxApiBcash)