def test_set_failed_2(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.read_pin_encoded() ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time, but with typo self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6 + '3') ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now it should fail, because pins are different self.assertIsInstance(ret, proto.Failure) # Check that there's still old PIN protection features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
def test_set_failed(self): self.setup_mnemonic_nopin_nopassphrase() features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) # Check that there's no PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success) # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send the PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time, but with typo self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin4) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now it should fail, because pins are different self.assertIsInstance(ret, proto.Failure) # Check that there's still no PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success)
def test_remove_pin(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) # Check that there's PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Let's remove PIN ret = self.client.call_raw(proto.ChangePin(remove=True)) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.read_pin_encoded() ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done self.assertIsInstance(ret, proto.Success) # Check that there's no PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertFalse(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.Success)
def test_reset_device_skip_backup_break(self): external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice( display_random=False, strength=strength, passphrase_protection=False, pin_protection=False, language='english', label='test', skip_backup=True )) # Provide entropy self.assertIsInstance(ret, proto.EntropyRequest) ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) self.assertIsInstance(ret, proto.Success) # Check if device is properly initialized resp = self.client.call_raw(proto.Initialize()) self.assertTrue(resp.initialized) self.assertTrue(resp.needs_backup) # start Backup workflow ret = self.client.call_raw(proto.BackupDevice()) # send Initialize -> break workflow ret = self.client.call_raw(proto.Initialize()) self.assertIsInstance(resp, proto.Features) # start backup again - should fail ret = self.client.call_raw(proto.BackupDevice()) self.assertIsInstance(ret, proto.Failure)
def test_change_pin(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) # Check that there's PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check current PIN value self.assertEqual(self.client.debug.read_pin()[0], self.pin4) # Let's change PIN ret = self.client.call_raw(proto.ChangePin()) self.assertIsInstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.read_pin_encoded() ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send new PIN for first time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time self.assertIsInstance(ret, proto.PinMatrixRequest) pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done self.assertIsInstance(ret, proto.Success) # Check that there's still PIN protection now features = self.client.call_raw(proto.Initialize()) self.assertTrue(features.pin_protection) ret = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check that the PIN is correct self.assertEqual(self.client.debug.read_pin()[0], self.pin6)
def test_wipe_device(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) self.assertEqual(features.initialized, True) self.assertEqual(features.pin_protection, True) self.assertEqual(features.passphrase_protection, True) device_id = features.device_id self.client.wipe_device() features = self.client.call_raw(proto.Initialize()) self.assertEqual(features.initialized, False) self.assertEqual(features.pin_protection, False) self.assertEqual(features.passphrase_protection, False) self.assertNotEqual(features.device_id, device_id)
def test_reset_device(self): # No PIN, no passphrase external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice(display_random=False, strength=strength, passphrase_protection=False, pin_protection=False, language='english', label='test')) # Provide entropy self.assertIsInstance(ret, proto.EntropyRequest) internal_entropy = self.client.debug.read_reset_entropy() ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) # Generate mnemonic locally entropy = generate_entropy(strength, internal_entropy, external_entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) mnemonic = [] for _ in range(strength//32*3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() self.client.call_raw(proto.ButtonAck()) mnemonic = ' '.join(mnemonic) # Compare that device generated proper mnemonic for given entropies self.assertEqual(mnemonic, expected_mnemonic) mnemonic = [] for _ in range(strength//32*3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() resp = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(resp, proto.Success) mnemonic = ' '.join(mnemonic) # Compare that second pass printed out the same mnemonic once again self.assertEqual(mnemonic, expected_mnemonic) # Check if device is properly initialized resp = self.client.call_raw(proto.Initialize()) self.assertFalse(resp.pin_protection) self.assertFalse(resp.passphrase_protection) # Do passphrase-protected action, PassphraseRequest should NOT be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) self.assertIsInstance(resp, proto.Success) # Do PIN-protected action, PinRequest should NOT be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) self.assertIsInstance(resp, proto.Success)
def test_reset_device_skip_backup(self): external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw(proto.ResetDevice( display_random=False, strength=strength, passphrase_protection=False, pin_protection=False, language='english', label='test', skip_backup=True )) # Provide entropy self.assertIsInstance(ret, proto.EntropyRequest) internal_entropy = self.client.debug.read_reset_entropy() ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) self.assertIsInstance(ret, proto.Success) # Check if device is properly initialized resp = self.client.call_raw(proto.Initialize()) self.assertTrue(resp.initialized) self.assertTrue(resp.needs_backup) # Generate mnemonic locally entropy = common.generate_entropy(strength, internal_entropy, external_entropy) expected_mnemonic = Mnemonic('english').to_mnemonic(entropy) # start Backup workflow ret = self.client.call_raw(proto.BackupDevice()) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() self.client.call_raw(proto.ButtonAck()) mnemonic = ' '.join(mnemonic) # Compare that device generated proper mnemonic for given entropies self.assertEqual(mnemonic, expected_mnemonic) mnemonic = [] for _ in range(strength // 32 * 3): self.assertIsInstance(ret, proto.ButtonRequest) mnemonic.append(self.client.debug.read_reset_word()) self.client.debug.press_yes() resp = self.client.call_raw(proto.ButtonAck()) self.assertIsInstance(resp, proto.Success) mnemonic = ' '.join(mnemonic) # Compare that second pass printed out the same mnemonic once again self.assertEqual(mnemonic, expected_mnemonic) # start backup again - should fail ret = self.client.call_raw(proto.BackupDevice()) self.assertIsInstance(ret, proto.Failure)
def test_features(self): features = self.client.call(messages.Initialize()) self.assertEqual(features, self.client.features)