def test_passphrase_on_device(client): _init_session(client) # try to get xpub with passphrase on host: response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw( messages.PassphraseAck(passphrase="A", on_device=False)) assert isinstance(response, messages.PublicKey) assert response.xpub == XPUB_PASSPHRASES["A"] # try to get xpub again, passphrase should be cached response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PublicKey) assert response.xpub == XPUB_PASSPHRASES["A"] # make a new session _init_session(client) # try to get xpub with passphrase on device: response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw(messages.PassphraseAck(on_device=True)) assert isinstance(response, messages.ButtonRequest) client.debug.input("A") response = client.call_raw(messages.ButtonAck()) assert isinstance(response, messages.PublicKey) assert response.xpub == XPUB_PASSPHRASES["A"] # try to get xpub again, passphrase should be cached response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PublicKey) assert response.xpub == XPUB_PASSPHRASES["A"]
def callback_PassphraseRequest(self, msg): if msg.on_device is True: return trezor_proto.PassphraseAck() passphrase = self.ask_for_pass_fun(msg) if passphrase is None: raise HardwareWalletCancelException('Cancelled') else: passphrase = unicodedata.normalize('NFKD', passphrase) return trezor_proto.PassphraseAck(passphrase=passphrase)
def test_passphrase_missing(client): response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw(messages.PassphraseAck(passphrase=None)) assert isinstance(response, messages.Failure) assert response.code == FailureType.DataError response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw(messages.PassphraseAck(passphrase=None, on_device=False)) assert isinstance(response, messages.Failure) assert response.code == FailureType.DataError
def test_passphrase_ack_mismatch(client): response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw( messages.PassphraseAck(passphrase="A", on_device=True)) assert isinstance(response, messages.Failure) assert response.code == FailureType.DataError
def _get_xpub_cardano(client, passphrase): msg = messages.CardanoGetPublicKey(address_n=parse_path("44'/1815'/0'/0/0")) response = client.call_raw(msg) if passphrase is not None: assert isinstance(response, messages.PassphraseRequest) response = client.call(messages.PassphraseAck(passphrase=passphrase)) assert isinstance(response, messages.CardanoPublicKey) return response.xpub
def _get_xpub(client, passphrase=None): """Get XPUB and check that the appropriate passphrase flow has happened.""" response = client.call_raw(XPUB_REQUEST) if passphrase is not None: assert isinstance(response, messages.PassphraseRequest) response = client.call_raw( messages.PassphraseAck(passphrase=passphrase)) assert isinstance(response, messages.PublicKey) return response.xpub
def call(passphrase: str, expected_result: bool): _init_session(client) response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw(messages.PassphraseAck(passphrase)) if expected_result: assert isinstance(response, messages.PublicKey) else: assert isinstance(response, messages.Failure) assert response.code == FailureType.DataError
def call(passphrase: str, expected_result: bool): _init_session(client) response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) try: response = client.call(messages.PassphraseAck(passphrase)) assert expected_result is True, "Call should have failed" assert isinstance(response, messages.PublicKey) except exceptions.TrezorFailure as e: assert expected_result is False, "Call should have succeeded" assert e.code == FailureType.DataError
def passphrase_process(cls, text, calling_window): response = cls.call_raw(proto.PassphraseAck(passphrase=text)) if response.__class__.__name__ is 'EthereumAddress': address = '0x' + binascii.hexlify(response.address).decode('ascii') address = cls.eth_node.w3.toChecksumAddress(address) cls.address = address else: calling_window._scene.add_effect( MessageDialog(calling_window._screen, "Trezor is unlocked now.", destroy_window=calling_window))
def _get_xpub_cardano(client: Client, passphrase): msg = messages.CardanoGetPublicKey( address_n=parse_path("m/44h/1815h/0h/0/0"), derivation_type=messages.CardanoDerivationType.ICARUS, ) response = client.call_raw(msg) if passphrase is not None: assert isinstance(response, messages.PassphraseRequest) response = client.call(messages.PassphraseAck(passphrase=passphrase)) assert isinstance(response, messages.CardanoPublicKey) return response.xpub
def test_passphrase_on_device_not_possible_on_t1(client): # This setting makes no sense on T1. response = client.call_raw(messages.ApplySettings(passphrase_always_on_device=True)) assert isinstance(response, messages.Failure) assert response.code == FailureType.DataError # T1 should not accept on_device request response = client.call_raw(XPUB_REQUEST) assert isinstance(response, messages.PassphraseRequest) response = client.call_raw(messages.PassphraseAck(on_device=True)) assert isinstance(response, messages.Failure) assert response.code == FailureType.DataError
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)