def setup_device_core(client, pin, wipe_code): device.wipe(client) debuglink.load_device(client, MNEMONIC12, pin, passphrase_protection=False, label="WIPECODE") def input_flow(): yield # do you want to set/change the wipe_code? client.debug.press_yes() if pin is not None: yield # enter current pin client.debug.input(pin) yield # enter new wipe code client.debug.input(wipe_code) yield # enter new wipe code again client.debug.input(wipe_code) yield # success client.debug.press_yes() with client: client.set_expected_responses( [messages.ButtonRequest()] * 5 + [messages.Success(), messages.Features()]) client.set_input_flow(input_flow) device.change_wipe_code(client)
def load_device(): debuglink.load_device( client, mnemonic=MNEMONIC12, pin="1234", passphrase_protection=False, label="test", )
def test_load_device_slip39_advanced(self, client): debuglink.load_device( client, mnemonic=MNEMONIC_SLIP39_ADVANCED_20, pin="", passphrase_protection=False, label="test", ) assert client.features.backup_type == BackupType.Slip39_Advanced
def test_load_device_slip39_basic(self, client): debuglink.load_device( client, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, pin="", passphrase_protection=False, label="test", ) assert client.features.backup_type == BackupType.Slip39_Basic
def setup_device_legacy(client, pin, wipe_code): device.wipe(client) debuglink.load_device( client, MNEMONIC12, pin, passphrase_protection=False, label="WIPECODE" ) with client: client.use_pin_sequence([PIN, WIPE_CODE, WIPE_CODE]) device.change_wipe_code(client)
def test_load_device_1(self, client): debuglink.load_device( client, mnemonic=MNEMONIC12, pin="", passphrase_protection=False, label="test", ) state = client.debug.state() assert state.mnemonic_secret == MNEMONIC12.encode() assert state.pin is None assert state.passphrase_protection is False address = btc.get_address(client, "Bitcoin", []) assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK"
def test_load_device_1(client: Client): debuglink.load_device( client, mnemonic=MNEMONIC12, pin="", passphrase_protection=False, label="test", ) state = client.debug.state() assert state.mnemonic_secret == MNEMONIC12.encode() assert state.pin is None assert state.passphrase_protection is False address = get_test_address(client) assert address == "mkqRFzxmkCGX9jxgpqqFHcxRUmLJcLDBer"
def test_safety_checks_level_after_reboot(emulator, set_level, after_level): device.wipe(emulator.client) debuglink.load_device( emulator.client, mnemonic=MNEMONIC12, pin="", passphrase_protection=False, label="SAFETYLEVEL", ) device.apply_settings(emulator.client, safety_checks=set_level) assert emulator.client.features.safety_checks == set_level emulator.restart() assert emulator.client.features.safety_checks == after_level
def setup_device(mnemonic, pin, passphrase_protection, label, needs_backup=None): # TODO: # - check if device is acquired otherwise throws "wrong previous session" from bridge client = TrezorClientDebugLink(get_device()) client.open() debuglink.load_device(client, mnemonic, pin, passphrase_protection, label, needs_backup=bool(needs_backup)) client.close()
def test_load_device_2(self, client): debuglink.load_device( client, mnemonic=MNEMONIC12, pin="1234", passphrase_protection=True, label="test", ) client.use_passphrase("passphrase") state = client.debug.state() assert state.mnemonic_secret == MNEMONIC12.encode() if client.features.model == "1": # we do not send PIN in DebugLinkState in Core assert state.pin == "1234" assert state.passphrase_protection is True address = btc.get_address(client, "Bitcoin", []) assert address == "15fiTDFwZd2kauHYYseifGi9daH2wniDHH"
def test_load_device_2(client: Client): debuglink.load_device( client, mnemonic=MNEMONIC12, pin="1234", passphrase_protection=True, label="test", ) client.use_passphrase("passphrase") state = client.debug.state() assert state.mnemonic_secret == MNEMONIC12.encode() if client.features.model == "1": # we do not send PIN in DebugLinkState in Core assert state.pin == "1234" assert state.passphrase_protection is True address = get_test_address(client) assert address == "mx77VZjTVixVsU7nCtAKHnGFdsyNCnsWWw"
def setup_device( mnemonic: str, pin: str, passphrase_protection: bool, label: str, needs_backup: bool = False, ) -> None: # TODO: check if device is acquired, otherwise throws # "wrong previous session" from bridge client = TrezorClientDebugLink(get_device()) client.open() time.sleep(SLEEP) debuglink.load_device( client, mnemonic, pin, passphrase_protection, label, needs_backup=needs_backup, ) client.close()
def test_wipe(client): # Enable SD protection device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Wipe device (this wipes internal storage) device.wipe(client) assert client.features.sd_protection is False # Restore device to working status debuglink.load_device(client, mnemonic=MNEMONIC12, pin=None, passphrase_protection=False, label="test") assert client.features.sd_protection is False # Enable SD protection device.sd_protect(client, Op.ENABLE) assert client.features.sd_protection is True # Refresh SD protection device.sd_protect(client, Op.REFRESH)
def test_load_device_utf(self, client): words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfkc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" words_nfd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" passphrase_nfkd = ( u"Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko" ) passphrase_nfc = ( u"Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko") passphrase_nfkc = ( u"Neuv\u011b\u0159iteln\u011b bezpe\u010dn\xe9 hesl\xed\u010dko") passphrase_nfd = ( u"Neuve\u030cr\u030citelne\u030c bezpec\u030cne\u0301 hesli\u0301c\u030cko" ) debuglink.load_device( client, mnemonic=words_nfkd, pin="", passphrase_protection=True, label="test", language="en-US", skip_checksum=True, ) client.use_passphrase(passphrase_nfkd) address_nfkd = btc.get_address(client, "Bitcoin", []) device.wipe(client) debuglink.load_device( client, mnemonic=words_nfc, pin="", passphrase_protection=True, label="test", language="en-US", skip_checksum=True, ) client.use_passphrase(passphrase_nfc) address_nfc = btc.get_address(client, "Bitcoin", []) device.wipe(client) debuglink.load_device( client, mnemonic=words_nfkc, pin="", passphrase_protection=True, label="test", language="en-US", skip_checksum=True, ) client.use_passphrase(passphrase_nfkc) address_nfkc = btc.get_address(client, "Bitcoin", []) device.wipe(client) debuglink.load_device( client, mnemonic=words_nfd, pin="", passphrase_protection=True, label="test", language="en-US", skip_checksum=True, ) client.use_passphrase(passphrase_nfd) address_nfd = btc.get_address(client, "Bitcoin", []) assert address_nfkd == address_nfc assert address_nfkd == address_nfkc assert address_nfkd == address_nfd
def client(request): """Client fixture. Every test function that requires a client instance will get it from here. If we can't connect to a debuggable device, the test will fail. If 'skip_t2' is used and TT is connected, the test is skipped. Vice versa with T1 and 'skip_t1'. The client instance is wiped and preconfigured with "all all all..." mnemonic, no password and no pin. It is possible to customize this with the `setup_client` marker. To specify a custom mnemonic and/or custom pin and/or enable passphrase: @pytest.mark.setup_client(mnemonic=MY_MNEMONIC, pin="9999", passphrase=True) To receive a client instance that was not initialized: @pytest.mark.setup_client(uninitialized=True) """ try: client = get_device() except RuntimeError: pytest.fail("No debuggable Trezor is available") if request.node.get_closest_marker( "skip_t2") and client.features.model == "T": pytest.skip("Test excluded on Trezor T") if request.node.get_closest_marker( "skip_t1") and client.features.model == "1": pytest.skip("Test excluded on Trezor 1") if (request.node.get_closest_marker("sd_card") and not client.features.sd_card_present): raise RuntimeError("This test requires SD card.\n" "To skip all such tests, run:\n" " pytest -m 'not sd_card' <test path>") test_ui = request.config.getoption("ui") if test_ui not in ("", "record", "test"): raise ValueError("Invalid ui option.") run_ui_tests = not request.node.get_closest_marker("skip_ui") and test_ui client.open() if run_ui_tests: # we need to reseed before the wipe client.debug.reseed(0) wipe_device(client) setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), pin=None, passphrase=False, needs_backup=False, no_backup=False, ) marker = request.node.get_closest_marker("setup_client") if marker: setup_params.update(marker.kwargs) if not setup_params["uninitialized"]: if setup_params["pin"] is True: setup_params["pin"] = "1234" debuglink.load_device( client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], passphrase_protection=setup_params["passphrase"], label="test", language="en-US", needs_backup=setup_params["needs_backup"], no_backup=setup_params["no_backup"], ) if setup_params["passphrase"] and client.features.model != "1": apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST) if setup_params["pin"]: # ClearSession locks the device. We only do that if the PIN is set. client.clear_session() if run_ui_tests: with ui_tests.screen_recording(client, request): yield client else: yield client client.close()
def client(request, _raw_client): """Client fixture. Every test function that requires a client instance will get it from here. If we can't connect to a debuggable device, the test will fail. If 'skip_t2' is used and TT is connected, the test is skipped. Vice versa with T1 and 'skip_t1'. The client instance is wiped and preconfigured with "all all all..." mnemonic, no password and no pin. It is possible to customize this with the `setup_client` marker. To specify a custom mnemonic and/or custom pin and/or enable passphrase: @pytest.mark.setup_client(mnemonic=MY_MNEMONIC, pin="9999", passphrase=True) To receive a client instance that was not initialized: @pytest.mark.setup_client(uninitialized=True) """ if request.node.get_closest_marker( "skip_t2") and _raw_client.features.model == "T": pytest.skip("Test excluded on Trezor T") if request.node.get_closest_marker( "skip_t1") and _raw_client.features.model == "1": pytest.skip("Test excluded on Trezor 1") sd_marker = request.node.get_closest_marker("sd_card") if sd_marker and not _raw_client.features.sd_card_present: raise RuntimeError("This test requires SD card.\n" "To skip all such tests, run:\n" " pytest -m 'not sd_card' <test path>") test_ui = request.config.getoption("ui") run_ui_tests = not request.node.get_closest_marker("skip_ui") and test_ui _raw_client.reset_debug_features() _raw_client.open() try: _raw_client.init_device() except Exception: request.session.shouldstop = "Failed to communicate with Trezor" pytest.fail("Failed to communicate with Trezor") if run_ui_tests: # we need to reseed before the wipe _raw_client.debug.reseed(0) if sd_marker: should_format = sd_marker.kwargs.get("formatted", True) _raw_client.debug.erase_sd_card(format=should_format) wipe_device(_raw_client) setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), pin=None, passphrase=False, needs_backup=False, no_backup=False, ) marker = request.node.get_closest_marker("setup_client") if marker: setup_params.update(marker.kwargs) use_passphrase = setup_params["passphrase"] is True or isinstance( setup_params["passphrase"], str) if not setup_params["uninitialized"]: debuglink.load_device( _raw_client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], passphrase_protection=use_passphrase, label="test", language="en-US", needs_backup=setup_params["needs_backup"], no_backup=setup_params["no_backup"], ) if _raw_client.features.model == "T": apply_settings(_raw_client, experimental_features=True) if use_passphrase and isinstance(setup_params["passphrase"], str): _raw_client.use_passphrase(setup_params["passphrase"]) _raw_client.clear_session() if run_ui_tests: with ui_tests.screen_recording(_raw_client, request): yield _raw_client else: yield _raw_client _raw_client.close()