1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-27 01:48:17 +00:00

really query for internal entropy before sending external one

use strength to compute number of words
This commit is contained in:
Pavol Rusnak 2014-03-03 19:30:43 +01:00
parent 3cd07c4dea
commit 1e148a7b7b

View File

@ -50,16 +50,17 @@ class TestDeviceReset(common.TrezorTest):
self.client.debug.press_yes() self.client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = self.client.call_raw(proto.ButtonAck())
# Provide entropy
self.assertIsInstance(ret, proto.EntropyRequest) self.assertIsInstance(ret, proto.EntropyRequest)
internal_entropy = self.client.debug.read_entropy()
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
# Read internal entropy and generate mnemonic locally # Generate mnemonic locally
internal_entropy = self.client.debug.read_entropy()
entropy = generate_entropy(strength, internal_entropy, external_entropy) entropy = generate_entropy(strength, internal_entropy, external_entropy)
expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy)
mnemonic = [] mnemonic = []
for _ in range(12): for _ in range(strength/32*3):
self.assertIsInstance(ret, proto.ButtonRequest) self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0]) mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes() self.client.debug.press_yes()
@ -71,7 +72,7 @@ class TestDeviceReset(common.TrezorTest):
self.assertEqual(mnemonic, expected_mnemonic) self.assertEqual(mnemonic, expected_mnemonic)
mnemonic = [] mnemonic = []
for _ in range(12): for _ in range(strength/32*3):
self.assertIsInstance(ret, proto.ButtonRequest) self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0]) mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes() self.client.debug.press_yes()
@ -112,9 +113,6 @@ class TestDeviceReset(common.TrezorTest):
self.client.debug.press_yes() self.client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = self.client.call_raw(proto.ButtonAck())
self.assertIsInstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
self.assertIsInstance(ret, proto.PinMatrixRequest) self.assertIsInstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time # Enter PIN for first time
@ -126,13 +124,17 @@ class TestDeviceReset(common.TrezorTest):
pin_encoded = self.client.debug.encode_pin('654') pin_encoded = self.client.debug.encode_pin('654')
ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
# Read internal entropy and generate mnemonic locally # Provide entropy
self.assertIsInstance(ret, proto.EntropyRequest)
internal_entropy = self.client.debug.read_entropy() internal_entropy = self.client.debug.read_entropy()
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
# Generate mnemonic locally
entropy = generate_entropy(strength, internal_entropy, external_entropy) entropy = generate_entropy(strength, internal_entropy, external_entropy)
expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy)
mnemonic = [] mnemonic = []
for _ in range(12): for _ in range(strength/32*3):
self.assertIsInstance(ret, proto.ButtonRequest) self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0]) mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes() self.client.debug.press_yes()
@ -144,7 +146,7 @@ class TestDeviceReset(common.TrezorTest):
self.assertEqual(mnemonic, expected_mnemonic) self.assertEqual(mnemonic, expected_mnemonic)
mnemonic = [] mnemonic = []
for _ in range(12): for _ in range(strength/32*3):
self.assertIsInstance(ret, proto.ButtonRequest) self.assertIsInstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_word()[0]) mnemonic.append(self.client.debug.read_word()[0])
self.client.debug.press_yes() self.client.debug.press_yes()
@ -165,10 +167,12 @@ class TestDeviceReset(common.TrezorTest):
# Do passphrase-protected action, PassphraseRequest should be raised # Do passphrase-protected action, PassphraseRequest should be raised
resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) resp = self.client.call_raw(proto.Ping(passphrase_protection=True))
self.assertIsInstance(resp, proto.PassphraseRequest) self.assertIsInstance(resp, proto.PassphraseRequest)
self.client.call_raw(proto.Cancel())
# Do PIN-protected action, PinRequest should be raised # Do PIN-protected action, PinRequest should be raised
resp = self.client.call_raw(proto.Ping(pin_protection=True)) resp = self.client.call_raw(proto.Ping(pin_protection=True))
self.assertIsInstance(resp, proto.PinMatrixRequest) self.assertIsInstance(resp, proto.PinMatrixRequest)
self.client.call_raw(proto.Cancel())
def test_failed_pin(self): def test_failed_pin(self):
external_entropy = 'zlutoucky kun upel divoke ody' * 2 external_entropy = 'zlutoucky kun upel divoke ody' * 2
@ -185,9 +189,6 @@ class TestDeviceReset(common.TrezorTest):
self.client.debug.press_yes() self.client.debug.press_yes()
ret = self.client.call_raw(proto.ButtonAck()) ret = self.client.call_raw(proto.ButtonAck())
self.assertIsInstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy))
self.assertIsInstance(ret, proto.PinMatrixRequest) self.assertIsInstance(ret, proto.PinMatrixRequest)
# Enter PIN for first time # Enter PIN for first time