def _set_wipe_code(client, wipe_code): # Set/change wipe code. ret = client.call_raw(messages.ChangeWipeCode()) assert isinstance(ret, messages.ButtonRequest) # Confirm intent to set/change wipe code. client.debug.press_yes() ret = client.call_raw(messages.ButtonAck()) if client.features.pin_protection: # Send current PIN. assert isinstance(ret, messages.PinMatrixRequest) pin_encoded = client.debug.read_pin_encoded() ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) # Send the new wipe code for the first time. assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = client.debug.encode_pin(wipe_code) ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded)) # Send the new wipe code for the second time. assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = client.debug.encode_pin(wipe_code) ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded)) # Now we're done. assert isinstance(ret, messages.Success)
def test_set_failed_2(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is True # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN assert isinstance(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 assert isinstance(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 assert isinstance(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 assert isinstance(ret, proto.Failure) # Check that there's still old PIN protection features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is True assert self.client.debug.read_pin()[0] == self.pin4
def _check_wipe_code(client, wipe_code): # Try to change the PIN to the current wipe code value. The operation should fail. ret = client.call_raw(messages.ChangePin()) assert isinstance(ret, messages.ButtonRequest) # Confirm intent to change PIN. client.debug.press_yes() ret = client.call_raw(messages.ButtonAck()) # Send current PIN. assert isinstance(ret, messages.PinMatrixRequest) pin_encoded = client.debug.read_pin_encoded() ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) # Send the new wipe code for the first time. assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = client.debug.encode_pin(wipe_code) ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded)) # Send the new wipe code for the second time. assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = client.debug.encode_pin(wipe_code) ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded)) # Expect failure. assert isinstance(ret, messages.Failure)
def test_set_pin(self, client): features = client.call_raw(proto.Initialize()) assert features.pin_protection is False # Check that there's no PIN protection ret = client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.Success) # Let's set new PIN ret = client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) # Send the PIN for first time assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(self.pin6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(self.pin6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done assert isinstance(ret, proto.Success) # Check that there's PIN protection now features = client.call_raw(proto.Initialize()) assert features.pin_protection is True # Check that the PIN is correct self.check_pin(client, self.pin6)
def test_failed_pin(self): # external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = self.client.call_raw( proto.ResetDevice( display_random=True, strength=strength, passphrase_protection=True, pin_protection=True, language="english", label="test", ) ) assert isinstance(ret, proto.ButtonRequest) self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.ButtonRequest) self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin(self.pin4) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.Failure)
def test_pin_passphrase(self, client): mnemonic = MNEMONIC12.split(" ") ret = client.call_raw( proto.RecoveryDevice( word_count=12, passphrase_protection=True, pin_protection=True, label="label", language="en-US", enforce_wordlist=True, )) # click through confirmation assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) fakes = 0 for _ in range(int(12 * 2)): assert isinstance(ret, proto.WordRequest) (word, pos) = client.debug.read_recovery_word() if pos != 0: ret = client.call_raw(proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) # Workflow succesfully ended assert isinstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used assert fakes == 12 assert mnemonic == [None] * 12 # Mnemonic is the same client.init_device() assert client.debug.read_mnemonic_secret() == MNEMONIC12.encode() assert client.features.pin_protection is True assert client.features.passphrase_protection is True # Do passphrase-protected action, PassphraseRequest should be raised resp = client.call_raw(proto.GetAddress()) assert isinstance(resp, proto.PassphraseRequest) client.call_raw(proto.Cancel())
def test_set_pin_to_wipe_code(client): # Set wipe code. _set_wipe_code(client, WIPE_CODE4) # Try to set the PIN to the current wipe code value. ret = client.call_raw(messages.ChangePin()) assert isinstance(ret, messages.ButtonRequest) # Confirm intent to set PIN. client.debug.press_yes() ret = client.call_raw(messages.ButtonAck()) # Send the new PIN for the first time. assert isinstance(ret, messages.PinMatrixRequest) pin_encoded = client.debug.encode_pin(WIPE_CODE4) ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) # Send the new PIN for the second time. assert isinstance(ret, messages.PinMatrixRequest) pin_encoded = client.debug.encode_pin(WIPE_CODE4) ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) # The operation should fail, because the PIN must be different from the wipe code. assert isinstance(ret, messages.Failure) assert ret.code == messages.FailureType.ProcessError # Check that there is no PIN protection. client.init_device() assert client.features.pin_protection is False ret = client.call_raw(messages.Ping(pin_protection=True)) assert isinstance(ret, messages.Success)
def test_set_mismatch(self, client): features = client.call_raw(proto.Initialize()) assert features.pin_protection is False # Check that there's no PIN protection ret = client.call_raw(proto.GetAddress()) assert isinstance(ret, proto.Address) # Let's set new PIN ret = client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) # Send the PIN for first time assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time, but with typo assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(PIN4) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now it should fail, because pins are different assert isinstance(ret, proto.Failure) # Check that there's still no PIN protection now features = client.call_raw(proto.Initialize()) assert features.pin_protection is False ret = client.call_raw(proto.GetAddress()) assert isinstance(ret, proto.Address)
def test_set_wipe_code_mismatch(client): # Check that there is no wipe code protection. assert client.features.wipe_code_protection is False # Let's set a new wipe code. ret = client.call_raw(messages.ChangeWipeCode()) assert isinstance(ret, messages.ButtonRequest) # Confirm intent to set wipe code. client.debug.press_yes() ret = client.call_raw(messages.ButtonAck()) # Send the new wipe code for the first time. assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = client.debug.encode_pin(WIPE_CODE4) ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded)) # Send the new wipe code for the second time, but different. assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = client.debug.encode_pin(WIPE_CODE6) ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded)) # The operation should fail, because the wipe codes are different. assert isinstance(ret, messages.Failure) assert ret.code == messages.FailureType.WipeCodeMismatch # Check that there is no wipe code protection. client.init_device() assert client.features.wipe_code_protection is False
def test_set_wipe_code_to_pin(client): # Check that wipe code protection status is not revealed in locked state. assert client.features.wipe_code_protection is None # Let's try setting the wipe code to the curent PIN value. ret = client.call_raw(messages.ChangeWipeCode()) assert isinstance(ret, messages.ButtonRequest) # Confirm intent to set wipe code. client.debug.press_yes() ret = client.call_raw(messages.ButtonAck()) # Send current PIN. assert isinstance(ret, messages.PinMatrixRequest) pin_encoded = client.debug.read_pin_encoded() ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) # Send the new wipe code. assert isinstance(ret, messages.PinMatrixRequest) pin_encoded = client.debug.read_pin_encoded() ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) # The operation should fail, because the wipe code must be different from the PIN. assert isinstance(ret, messages.Failure) assert ret.code == messages.FailureType.ProcessError # Check that there is no wipe code protection. client.init_device() assert client.features.wipe_code_protection is False
def test_set_failed(self): self.setup_mnemonic_nopin_nopassphrase() features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is False # Check that there's no PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.Success) # Let's set new PIN ret = self.client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send the PIN for first time assert isinstance(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 assert isinstance(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 assert isinstance(ret, proto.Failure) # Check that there's still no PIN protection now features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is False ret = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.Success)
def test_change_mismatch(self, client): features = client.call_raw(proto.Initialize()) assert features.pin_protection is True # Let's set new PIN ret = client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) # Send current PIN assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.read_pin_encoded() ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for first time assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time, but with typo assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(PIN6 + "3") ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now it should fail, because pins are different assert isinstance(ret, proto.Failure) # Check that there's still old PIN protection features = client.call_raw(proto.Initialize()) assert features.pin_protection is True self.check_pin(client, PIN4)
def test_pin_fail(self, client): ret = client.call_raw( proto.RecoveryDevice( word_count=12, passphrase_protection=True, pin_protection=True, label="label", language="en-US", enforce_wordlist=True, )) # click through confirmation assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = client.debug.encode_pin(PIN4) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time, but different one pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Failure should be raised assert isinstance(ret, proto.Failure)
def test_pin_passphrase(self): mnemonic = self.mnemonic12.split(' ') ret = self.client.call_raw( proto.RecoveryDevice(word_count=12, passphrase_protection=True, pin_protection=True, label='label', language='english', enforce_wordlist=True)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) fakes = 0 for _ in range(int(12 * 2)): assert isinstance(ret, proto.WordRequest) (word, pos) = self.client.debug.read_recovery_word() if pos != 0: ret = self.client.call_raw( proto.WordAck(word=mnemonic[pos - 1])) mnemonic[pos - 1] = None else: ret = self.client.call_raw(proto.WordAck(word=word)) fakes += 1 print(mnemonic) # Workflow succesfully ended assert isinstance(ret, proto.Success) # 12 expected fake words and all words of mnemonic are used assert fakes == 12 assert mnemonic == [None] * 12 # Mnemonic is the same self.client.init_device() assert self.client.debug.read_mnemonic() == self.mnemonic12 assert self.client.features.pin_protection is True assert self.client.features.passphrase_protection is True # Do passphrase-protected action, PassphraseRequest should be raised resp = self.client.call_raw(proto.Ping(passphrase_protection=True)) assert isinstance(resp, proto.PassphraseRequest) self.client.call_raw(proto.Cancel()) # Do PIN-protected action, PinRequest should be raised resp = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(resp, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel())
def test_change_pin(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is True # Check that there's PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check current PIN value assert self.client.debug.read_pin()[0] == self.pin4 # Let's change PIN ret = self.client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN assert isinstance(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 assert isinstance(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 assert isinstance(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 assert isinstance(ret, proto.Success) # Check that there's still PIN protection now features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is True ret = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Check that the PIN is correct assert self.client.debug.read_pin()[0] == self.pin6
def test_wipe_code_activate_legacy(): with EmulatorWrapper("legacy") as emu: # set up device setup_device_legacy(emu.client, PIN, WIPE_CODE) emu.client.init_device() device_id = emu.client.features.device_id # Initiate Change pin process ret = emu.client.call_raw(messages.ChangePin(remove=False)) assert isinstance(ret, messages.ButtonRequest) emu.client.debug.press_yes() ret = emu.client.call_raw(messages.ButtonAck()) # Enter the wipe code instead of the current PIN assert isinstance(ret, messages.PinMatrixRequest) wipe_code_encoded = emu.client.debug.encode_pin(WIPE_CODE) emu.client._raw_write(messages.PinMatrixAck(pin=wipe_code_encoded)) # wait 30 seconds for emulator to shut down # this will raise a TimeoutError if the emulator doesn't die. emu.wait(30) emu.start() assert emu.client.features.initialized is False assert emu.client.features.pin_protection is False assert emu.client.features.wipe_code_protection is False assert emu.client.features.device_id != device_id
def check_pin(self, client, pin): client.clear_session() ret = client.call_raw(proto.GetAddress()) assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(pin) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.Address)
def check_pin(self, client, pin): client.clear_session() ret = client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(pin) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.Success)
def test_remove_pin(self): self.setup_mnemonic_pin_passphrase() features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is True # Check that there's PIN protection ret = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.PinMatrixRequest) self.client.call_raw(proto.Cancel()) # Let's remove PIN ret = self.client.call_raw(proto.ChangePin(remove=True)) assert isinstance(ret, proto.ButtonRequest) # Press button self.client.debug.press_yes() ret = self.client.call_raw(proto.ButtonAck()) # Send current PIN assert isinstance(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 assert isinstance(ret, proto.Success) # Check that there's no PIN protection now features = self.client.call_raw(proto.Initialize()) assert features.pin_protection is False ret = self.client.call_raw(proto.Ping(pin_protection=True)) assert isinstance(ret, proto.Success)
def test_change_pin(self, client): features = client.call_raw(proto.Initialize()) assert features.pin_protection is True # Check that there's PIN protection ret = client.call_raw(proto.GetAddress()) assert isinstance(ret, proto.PinMatrixRequest) client.call_raw(proto.Cancel()) # Check current PIN value self.check_pin(client, PIN4) # Let's change PIN ret = client.call_raw(proto.ChangePin()) assert isinstance(ret, proto.ButtonRequest) # Press button client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) # Send current PIN assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.read_pin_encoded() ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send new PIN for first time assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Send the PIN for second time assert isinstance(ret, proto.PinMatrixRequest) pin_encoded = client.debug.encode_pin(PIN6) ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Now we're done assert isinstance(ret, proto.Success) # Check that there's still PIN protection now features = client.call_raw(proto.Initialize()) assert features.pin_protection is True # Check that the PIN is correct self.check_pin(client, PIN6)
def test_failed_pin(self, client): # external_entropy = b'zlutoucky kun upel divoke ody' * 2 strength = 128 ret = client.call_raw( proto.ResetDevice( display_random=True, strength=strength, passphrase_protection=True, pin_protection=True, language="en-US", label="test", )) # Do you want ... ? assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) # Entropy screen #1 assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) # Entropy screen #2 assert isinstance(ret, proto.ButtonRequest) client.debug.press_yes() ret = client.call_raw(proto.ButtonAck()) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = client.debug.encode_pin("1234") ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time pin_encoded = client.debug.encode_pin("6789") ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.Failure)
def test_enter_invalid(client, invalid_pin): assert client.features.pin_protection is True # use an invalid PIN ret = client.call_raw(messages.GetAddress()) # Send a PIN containing an invalid digit assert isinstance(ret, messages.PinMatrixRequest) ret = client.call_raw(messages.PinMatrixAck(pin=invalid_pin)) # Ensure the invalid PIN is detected assert isinstance(ret, messages.Failure)
def test_pin(self, client): resp = client.call_raw( messages.Ping(message="test", pin_protection=True)) assert isinstance(resp, messages.PinMatrixRequest) pin, matrix = client.debug.read_pin() assert pin == "1234" assert matrix != "" pin_encoded = client.debug.read_pin_encoded() resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) assert isinstance(resp, messages.Success)
def callback_PinMatrixRequest(self, msg): if msg.type == 1: desc = 'Enter current PIN' elif msg.type == 2: desc = 'Enter new PIN' elif msg.type == 3: desc = 'Enter new PIN again' else: desc = 'Enter PIN' pin = self.ask_for_pin_fun(desc) if not pin: raise HardwareWalletCancelException('Cancelled') return trezor_proto.PinMatrixAck(pin=pin)
def test_pin_fail(self): ret = self.client.call_raw( proto.RecoveryDevice(word_count=12, passphrase_protection=True, pin_protection=True, label='label', language='english', enforce_wordlist=True)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for first time pin_encoded = self.client.debug.encode_pin(self.pin4) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(ret, proto.PinMatrixRequest) # Enter PIN for second time, but different one pin_encoded = self.client.debug.encode_pin(self.pin6) ret = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) # Failure should be raised assert isinstance(ret, proto.Failure)
def test_pin(self, client): resp = client.call_raw(messages.GetAddress()) assert isinstance(resp, messages.PinMatrixRequest) state = client.debug.state() assert state.pin == "1234" assert state.matrix != "" pin_encoded = client.debug.encode_pin("1234") resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) assert isinstance(resp, messages.PassphraseRequest) resp = client.call_raw(messages.PassphraseAck(passphrase="")) assert isinstance(resp, messages.Address)
def test_pin(self, client): resp = client.call_raw(messages.GetAddress()) assert isinstance(resp, messages.PinMatrixRequest) pin, matrix = client.debug.read_pin() assert pin == "1234" assert matrix != "" pin_encoded = client.debug.read_pin_encoded() resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded)) assert isinstance(resp, messages.PassphraseRequest) resp = client.call_raw(messages.PassphraseAck(passphrase="")) assert isinstance(resp, messages.Address)
def test_pin(self): self.setup_mnemonic_pin_passphrase() # Manually trigger PinMatrixRequest resp = self.client.call_raw( proto.Ping(message='test', pin_protection=True)) assert isinstance(resp, proto.PinMatrixRequest) pin = self.client.debug.read_pin() assert pin[0] == '1234' assert pin[1] != '' pin_encoded = self.client.debug.read_pin_encoded() resp = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(resp, proto.Success)
def test_pin(self): self.setup_mnemonic_pin_passphrase() # Manually trigger PinMatrixRequest resp = self.client.call_raw( proto.Ping(message="test", pin_protection=True)) assert isinstance(resp, proto.PinMatrixRequest) pin, matrix = self.client.debug.read_pin() assert pin == "1234" assert matrix != "" pin_encoded = self.client.debug.read_pin_encoded() resp = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded)) assert isinstance(resp, proto.Success)
def matrix_process(cls, text, calling_window): response = cls.call_raw(proto.PinMatrixAck(pin=text)) if response.__class__.__name__ is 'EthereumAddress': cls.address = response.address #calling_window._scene.remove_effect( cls.matrix_window) calling_window._scene.add_effect( MessageDialog(calling_window._screen, "Trezor is unlocked now.", destroy_window=calling_window)) elif response.__class__.__name__ == 'PassphraseRequest': cls.passphrase_request_window() else: calling_window._scene.add_effect( MessageDialog(calling_window._screen, "Trezor is unlocked now.", destroy_window=calling_window))