async def bootscreen() -> None: ui.display.orientation(storage.device.get_rotation()) while True: try: if storage.sd_salt.is_enabled() or config.has_pin(): await lockscreen() salt = await request_sd_salt() if not config.has_pin(): config.unlock(pin_to_int(""), salt) storage.init_unlocked() return label = "Enter your PIN" while True: pin = await request_pin(label, config.get_pin_rem()) if config.unlock(pin_to_int(pin), salt): storage.init_unlocked() return else: label = "Wrong PIN, enter again" except (OSError, PinCancelled, SdCardUnavailable) as e: if __debug__: log.exception(__name__, e) except BaseException as e: if __debug__: log.exception(__name__, e) utils.halt(e.__class__.__name__)
async def respond_Features(ctx, msg): if msg.__qualname__ == 'Initialize': if msg.state is None or msg.state != cache.get_state(salt=msg.state[:32]): cache.clear() f = Features() f.vendor = 'trezor.io' f.major_version = symbol('VERSION_MAJOR') f.minor_version = symbol('VERSION_MINOR') f.patch_version = symbol('VERSION_PATCH') f.device_id = storage.get_device_id() f.pin_protection = config.has_pin() f.passphrase_protection = storage.has_passphrase() f.language = 'english' f.label = storage.get_label() f.coins = coins.COINS f.initialized = storage.is_initialized() f.revision = symbol('GITREV') f.pin_cached = config.has_pin() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.needs_backup() f.flags = storage.get_flags() f.model = 'T' f.state = cache.get_state() return f
async def respond_Features(ctx, msg): if msg.__qualname__ == 'Initialize': if msg.state is None or bytes( msg.state) != cache.get_state(state=bytes(msg.state)): cache.clear() f = Features() f.vendor = 'trezor.io' f.major_version = symbol('VERSION_MAJOR') f.minor_version = symbol('VERSION_MINOR') f.patch_version = symbol('VERSION_PATCH') f.device_id = storage.get_device_id() f.pin_protection = config.has_pin() f.passphrase_protection = storage.has_passphrase() f.language = 'english' f.label = storage.get_label() f.initialized = storage.is_initialized() f.revision = symbol('GITREV') f.pin_cached = config.has_pin() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.needs_backup() f.flags = storage.get_flags() if model() in ['T', 'EMU']: # emulator currently emulates model T f.model = 'T' f.unfinished_backup = storage.unfinished_backup() return f
async def verify_user_pin(prompt: str = "Enter your PIN", allow_cancel: bool = True, retry: bool = True) -> None: if config.has_pin(): pin = await request_pin(prompt, config.get_pin_rem(), allow_cancel) config.ensure_not_wipe_code(pin_to_int(pin)) else: pin = "" try: salt = await request_sd_salt() except SdCardUnavailable: raise PinCancelled if config.unlock(pin_to_int(pin), salt): return elif not config.has_pin(): raise RuntimeError while retry: pin = await request_pin("Wrong PIN, enter again", config.get_pin_rem(), allow_cancel) if config.unlock(pin_to_int(pin), salt): return raise PinInvalid
async def bootscreen() -> None: ui.display.orientation(storage_device.get_rotation()) salt_auth_key = storage_device.get_sd_salt_auth_key() while True: try: if salt_auth_key is not None or config.has_pin(): await lockscreen() if salt_auth_key is not None: salt = await request_sd_salt(None, salt_auth_key ) # type: Optional[bytearray] else: salt = None if not config.has_pin(): config.unlock(pin_to_int(""), salt) storage.init_unlocked() return label = "Enter your PIN" while True: pin = await request_pin(label, config.get_pin_rem()) if config.unlock(pin_to_int(pin), salt): storage.init_unlocked() return else: label = "Wrong PIN, enter again" except (OSError, PinCancelled, SdProtectCancelled) as e: if __debug__: log.exception(__name__, e) except BaseException as e: utils.halt(e.__class__.__name__)
def get_features() -> Features: f = Features() f.vendor = "trezor.io" f.language = "en-US" f.major_version = utils.VERSION_MAJOR f.minor_version = utils.VERSION_MINOR f.patch_version = utils.VERSION_PATCH f.revision = utils.GITREV.encode() f.model = utils.MODEL f.device_id = storage.device.get_device_id() f.label = storage.device.get_label() f.initialized = storage.is_initialized() f.pin_protection = config.has_pin() f.pin_cached = config.has_pin() f.passphrase_protection = storage.device.is_passphrase_enabled() f.needs_backup = storage.device.needs_backup() f.unfinished_backup = storage.device.unfinished_backup() f.no_backup = storage.device.no_backup() f.flags = storage.device.get_flags() f.recovery_mode = storage.recovery.is_in_progress() f.backup_type = mnemonic.get_type() if utils.BITCOIN_ONLY: f.capabilities = [ Capability.Bitcoin, Capability.Crypto, Capability.Shamir, Capability.ShamirGroups, Capability.PassphraseEntry, ] else: f.capabilities = [ Capability.Bitcoin, Capability.Bitcoin_like, Capability.Binance, Capability.Cardano, Capability.Crypto, Capability.EOS, Capability.Ethereum, Capability.Lisk, Capability.Monero, Capability.NEM, Capability.Ripple, Capability.Stellar, Capability.Tezos, Capability.U2F, Capability.Shamir, Capability.ShamirGroups, Capability.PassphraseEntry, ] f.sd_card_present = io.SDCard().present() f.sd_protection = storage.sd_salt.is_enabled() f.wipe_code_protection = config.has_wipe_code() f.session_id = cache.get_session_id() f.passphrase_always_on_device = storage.device.get_passphrase_always_on_device( ) return f
def get_features() -> Features: f = Features() f.vendor = "trezor.io" f.language = "english" f.major_version = utils.VERSION_MAJOR f.minor_version = utils.VERSION_MINOR f.patch_version = utils.VERSION_PATCH f.revision = utils.GITREV f.model = utils.MODEL f.device_id = storage.device.get_device_id() f.label = storage.device.get_label() f.initialized = storage.is_initialized() f.pin_protection = config.has_pin() f.pin_cached = config.has_pin() f.passphrase_protection = storage.device.has_passphrase() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.device.needs_backup() f.unfinished_backup = storage.device.unfinished_backup() f.no_backup = storage.device.no_backup() f.flags = storage.device.get_flags() f.recovery_mode = storage.recovery.is_in_progress() if utils.BITCOIN_ONLY: f.capabilities = [ Capability.Bitcoin, Capability.Crypto, Capability.Shamir, Capability.ShamirGroups, ] else: f.capabilities = [ Capability.Bitcoin, Capability.Bitcoin_like, Capability.Binance, Capability.Cardano, Capability.Crypto, Capability.EOS, Capability.Ethereum, Capability.Lisk, Capability.Monero, Capability.NEM, Capability.Ripple, Capability.Stellar, Capability.Tezos, Capability.U2F, Capability.Shamir, Capability.ShamirGroups, ] return f
def display_homescreen() -> None: image = None if storage.slip39.is_in_progress(): label = "Waiting for other shares" elif not storage.is_initialized(): label = "Go to trezor.io/start" else: label = storage.device.get_label() or "My Trezor" image = storage.device.get_homescreen() if not image: image = res.load("apps/homescreen/res/bg.toif") if storage.is_initialized() and storage.device.no_backup(): _err("SEEDLESS") elif storage.is_initialized() and storage.device.unfinished_backup(): _err("BACKUP FAILED!") elif storage.is_initialized() and storage.device.needs_backup(): _warn("NEEDS BACKUP!") elif storage.is_initialized() and not config.has_pin(): _warn("PIN NOT SET!") elif storage.slip39.is_in_progress(): _warn("SHAMIR IN PROGRESS!") else: ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG) ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK) ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG)
async def get_owner_key(ctx, msg): if not config.has_pin(): return Failure(message='PIN is not set') label = "Enter your PIN" while True: try: pin = await ctx.wait(request_pin(label)) if config.unlock(pin_to_int(pin)): break else: label = "Wrong PIN, enter again" except PinCancelled: raise wire.ActionCancelled("Cancelled") export_warning_msg = 'Exposing the key to a third party allows them to see your balance.' await beam_confirm_message(ctx, 'Owner key', export_warning_msg, False) wait_warning_msg = 'Please wait few seconds until exporting is done' await beam_confirm_message(ctx, 'Owner key', wait_warning_msg, False) pin = pin.encode() owner_key = generate_owner_key(pin) if msg.show_display: await beam_confirm_message(ctx, 'Owner key', owner_key, True) return BeamOwnerKey(key=owner_key)
async def sd_protect_enable(ctx: wire.Context, msg: SdProtect) -> Success: if storage.sd_salt.is_enabled(): raise wire.ProcessError("SD card protection already enabled") # Confirm that user wants to proceed with the operation. await require_confirm_sd_protect(ctx, msg) # Make sure SD card is present. await ensure_sdcard(ctx) # Get the current PIN. if config.has_pin(): pin = pin_to_int(await request_pin(ctx, "Enter PIN", config.get_pin_rem())) else: pin = pin_to_int("") # Check PIN and prepare salt file. salt, salt_auth_key, salt_tag = _make_salt() await _set_salt(ctx, salt, salt_tag) if not config.change_pin(pin, pin, None, salt): # Wrong PIN. Clean up the prepared salt file. try: storage.sd_salt.remove_sd_salt() except Exception: # The cleanup is not necessary for the correct functioning of # SD-protection. If it fails for any reason, we suppress the # exception, because primarily we need to raise wire.PinInvalid. pass await error_pin_invalid(ctx) storage.device.set_sd_salt_auth_key(salt_auth_key) await show_success(ctx, ("You have successfully", "enabled SD protection.")) return Success(message="SD card protection enabled")
def do_render(self) -> None: # warning bar on top if storage.device.is_initialized() and storage.device.no_backup(): ui.header_error("SEEDLESS") elif storage.device.is_initialized( ) and storage.device.unfinished_backup(): ui.header_error("BACKUP FAILED!") elif storage.device.is_initialized() and storage.device.needs_backup(): ui.header_warning("NEEDS BACKUP!") elif storage.device.is_initialized() and not config.has_pin(): ui.header_warning("PIN NOT SET!") elif storage.device.get_experimental_features(): ui.header_warning("EXPERIMENTAL MODE!") else: ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG) # homescreen with shifted avatar and text on bottom # Differs for each model # TODO: support homescreen avatar change for R and 1 if utils.MODEL in ("T", ): ui.display.avatar(48, 48 - 10, self.get_image(), ui.WHITE, ui.BLACK) elif utils.MODEL in ("R", ): icon = "trezor/res/homescreen_model_r.toif" # 92x92 px ui.display.icon(18, 18, ui.res.load(icon), ui.style.FG, ui.style.BG) elif utils.MODEL in ("1", ): icon = "trezor/res/homescreen_model_1.toif" # 64x36 px ui.display.icon(33, 14, ui.res.load(icon), ui.style.FG, ui.style.BG) label_heights = {"1": 60, "R": 120, "T": 220} ui.display.text_center(ui.WIDTH // 2, label_heights[utils.MODEL], self.label, ui.BOLD, ui.FG, ui.BG)
def display_homescreen(): if not storage.is_initialized(): label = 'Go to trezor.io/start' image = None else: label = storage.get_label() or 'My TREZOR' image = storage.get_homescreen() if not image: image = res.load('apps/homescreen/res/bg.toif') if storage.is_initialized() and storage.unfinished_backup(): ui.display.bar(0, 0, ui.WIDTH, 30, ui.RED) ui.display.text_center(ui.WIDTH // 2, 22, 'BACKUP FAILED!', ui.BOLD, ui.WHITE, ui.RED) ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG) elif storage.is_initialized() and storage.needs_backup(): ui.display.bar(0, 0, ui.WIDTH, 30, ui.YELLOW) ui.display.text_center(ui.WIDTH // 2, 22, 'NEEDS BACKUP!', ui.BOLD, ui.BLACK, ui.YELLOW) ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG) elif storage.is_initialized() and not config.has_pin(): ui.display.bar(0, 0, ui.WIDTH, 30, ui.YELLOW) ui.display.text_center(ui.WIDTH // 2, 22, 'PIN NOT SET!', ui.BOLD, ui.BLACK, ui.YELLOW) ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG) else: ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG) ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK) ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG)
async def recovery_device(ctx, msg): """ Recover BIP39 seed into empty device. 1. Ask for the number of words in recovered seed. 2. Let user type in the mnemonic words one by one. 3. Optionally check the seed validity. 4. Optionally ask for the PIN, with confirmation. 5. Save into storage. """ if not msg.dry_run and storage.is_initialized(): raise wire.UnexpectedMessage("Already initialized") text = Text("Device recovery", ui.ICON_RECOVERY) text.normal("Do you really want to", "recover the device?", "") await require_confirm(ctx, text, code=ProtectCall) if msg.dry_run and config.has_pin(): curpin = await request_pin_ack(ctx, "Enter PIN", config.get_pin_rem()) if not config.check_pin(pin_to_int(curpin)): raise wire.PinInvalid("PIN invalid") # ask for the number of words wordcount = await request_wordcount(ctx) # ask for mnemonic words one by one mnemonic = await request_mnemonic(ctx, wordcount) # check mnemonic validity if msg.enforce_wordlist or msg.dry_run: if not bip39.check(mnemonic): raise wire.ProcessError("Mnemonic is not valid") # ask for pin repeatedly if msg.pin_protection: newpin = await request_pin_confirm(ctx, cancellable=False) # dry run if msg.dry_run: digest_input = sha256(mnemonic).digest() digest_stored = sha256(storage.get_mnemonic()).digest() if consteq(digest_stored, digest_input): return Success( message="The seed is valid and matches the one in the device") else: raise wire.ProcessError( "The seed is valid but does not match the one in the device") # save into storage if msg.pin_protection: config.change_pin(pin_to_int(""), pin_to_int(newpin)) storage.set_u2f_counter(msg.u2f_counter) storage.load_settings(label=msg.label, use_passphrase=msg.passphrase_protection) storage.load_mnemonic(mnemonic=mnemonic, needs_backup=False, no_backup=False) return Success(message="Device recovered")
def on_render(self): if not self.repaint: return image = None if not storage.is_initialized(): label = "Go to trezor.io/start" else: label = storage.device.get_label() or "My Trezor" image = storage.device.get_homescreen() if not image: image = res.load("apps/homescreen/res/bg.toif") if storage.is_initialized() and storage.device.no_backup(): ui.header_error("SEEDLESS") elif storage.is_initialized() and storage.device.unfinished_backup(): ui.header_error("BACKUP FAILED!") elif storage.is_initialized() and storage.device.needs_backup(): ui.header_warning("NEEDS BACKUP!") elif storage.is_initialized() and not config.has_pin(): ui.header_warning("PIN NOT SET!") else: ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG) ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK) ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG) self.repaint = False
def on_render(self) -> None: if not self.repaint: return # warning bar on top if storage.device.is_initialized() and storage.device.no_backup(): ui.header_error("SEEDLESS") elif storage.device.is_initialized( ) and storage.device.unfinished_backup(): ui.header_error("BACKUP FAILED!") elif storage.device.is_initialized() and storage.device.needs_backup(): ui.header_warning("NEEDS BACKUP!") elif storage.device.is_initialized() and not config.has_pin(): ui.header_warning("PIN NOT SET!") elif storage.device.get_experimental_features(): ui.header_warning("EXPERIMENTAL MODE!") else: ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG) # homescreen with shifted avatar and text on bottom ui.display.avatar(48, 48 - 10, self.image, ui.WHITE, ui.BLACK) ui.display.text_center(ui.WIDTH // 2, 220, self.label, ui.BOLD, ui.FG, ui.BG) self.repaint = False
def require_confirm_change_pin(ctx: wire.Context, msg: ChangePin) -> None: has_pin = config.has_pin() if msg.remove and has_pin: # removing pin return confirm_action( ctx, "set_pin", "Remove PIN", description="Do you really want to", action="disable PIN protection?", reverse=True, ) if not msg.remove and has_pin: # changing pin return confirm_action( ctx, "set_pin", "Change PIN", description="Do you really want to", action="change your PIN?", reverse=True, ) if not msg.remove and not has_pin: # setting new pin return confirm_action( ctx, "set_pin", "Enable PIN", description="Do you really want to", action="enable PIN protection?", reverse=True, ) # removing non-existing PIN raise wire.ProcessError("PIN protection already disabled")
async def respond_Features(ctx, msg): from apps.common import storage, coins, cache from trezor.messages.Features import Features if msg.__qualname__ == 'Initialize': if msg.state is None or msg.state != cache.get_state(): cache.clear() f = Features() f.vendor = 'trezor.io' f.revision = '0123456789' f.bootloader_hash = '0123456789' f.major_version = 2 f.minor_version = 0 f.patch_version = 0 f.model = 'T' f.coins = coins.COINS f.device_id = storage.get_device_id() f.label = storage.get_label() f.initialized = storage.is_initialized() f.passphrase_protection = storage.has_passphrase() f.pin_protection = config.has_pin() f.language = 'english' f.state = cache.get_state() return f
async def change_pin(ctx, msg): # confirm that user wants to change the pin await require_confirm_change_pin(ctx, msg) # get current pin, return failure if invalid if config.has_pin(): curpin = await request_pin_ack(ctx, "Enter old PIN", config.get_pin_rem()) # if removing, defer check to change_pin() if not msg.remove: if not config.check_pin(pin_to_int(curpin)): raise wire.PinInvalid("PIN invalid") else: curpin = "" # get new pin if not msg.remove: newpin = await request_pin_confirm(ctx) else: newpin = "" # write into storage if not config.change_pin(pin_to_int(curpin), pin_to_int(newpin)): raise wire.PinInvalid("PIN invalid") if newpin: return Success(message="PIN changed") else: return Success(message="PIN removed")
async def change_pin(ctx, msg): # confirm that user wants to change the pin await require_confirm_change_pin(ctx, msg) # get current pin, return failure if invalid if config.has_pin(): curpin = await request_pin_ack(ctx) if not config.check_pin(pin_to_int(curpin), show_pin_timeout): raise wire.PinInvalid('PIN invalid') else: curpin = '' # get new pin if not msg.remove: newpin = await request_pin_confirm(ctx) else: newpin = '' # write into storage if not config.change_pin(pin_to_int(curpin), pin_to_int(newpin), show_pin_timeout): raise wire.PinInvalid('PIN invalid') if newpin: return Success(message='PIN changed') else: return Success(message='PIN removed')
async def verify_user_pin( ctx: wire.GenericContext = wire.DUMMY_CONTEXT, prompt: str = "Enter your PIN", allow_cancel: bool = True, retry: bool = True, cache_time_ms: int = 0, ) -> None: last_unlock = _get_last_unlock_time() if ( cache_time_ms and last_unlock and utime.ticks_ms() - last_unlock <= cache_time_ms and config.is_unlocked() ): return if config.has_pin(): from trezor.ui.layouts import request_pin_on_device pin = await request_pin_on_device( ctx, prompt, config.get_pin_rem(), allow_cancel ) config.ensure_not_wipe_code(pin) else: pin = "" try: salt = await request_sd_salt(ctx) except SdCardUnavailable: raise wire.PinCancelled("SD salt is unavailable") if config.unlock(pin, salt): _set_last_unlock_time() return elif not config.has_pin(): raise RuntimeError while retry: pin = await request_pin_on_device( ctx, "Wrong PIN, enter again", config.get_pin_rem(), allow_cancel ) if config.unlock(pin, salt): _set_last_unlock_time() return raise wire.PinInvalid
async def unlock_layout(): while True: if config.has_pin(): pin = await request_pin() else: pin = '' if config.unlock(pin_to_int(pin), show_pin_timeout): return else: await unlock_failed()
def get_features(): f = Features() f.vendor = "trezor.io" f.language = "english" f.major_version = utils.VERSION_MAJOR f.minor_version = utils.VERSION_MINOR f.patch_version = utils.VERSION_PATCH f.revision = utils.GITREV f.model = utils.MODEL f.device_id = storage.get_device_id() f.label = storage.get_label() f.initialized = storage.is_initialized() f.pin_protection = config.has_pin() f.pin_cached = config.has_pin() f.passphrase_protection = storage.has_passphrase() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.needs_backup() f.unfinished_backup = storage.unfinished_backup() f.flags = storage.get_flags() return f
async def request_pin_and_sd_salt( ctx: wire.Context, prompt: str = "Enter your PIN", allow_cancel: bool = True ) -> Tuple[str, Optional[bytearray]]: salt = await request_sd_salt(ctx) if config.has_pin(): pin = await request_pin_ack(ctx, prompt, config.get_pin_rem(), allow_cancel) else: pin = "" return pin, salt
async def request_pin_and_sd_salt( ctx: wire.Context, prompt: str = "Enter your PIN", allow_cancel: bool = True ) -> tuple[str, bytearray | None]: if config.has_pin(): pin = await request_pin(ctx, prompt, config.get_pin_rem(), allow_cancel) config.ensure_not_wipe_code(pin) else: pin = "" salt = await request_sd_salt(ctx) return pin, salt
def get_features(): f = Features() f.vendor = 'trezor.io' f.language = 'english' f.major_version = utils.symbol('VERSION_MAJOR') f.minor_version = utils.symbol('VERSION_MINOR') f.patch_version = utils.symbol('VERSION_PATCH') f.revision = utils.symbol('GITREV') f.model = utils.model() if f.model == 'EMU': f.model = 'T' # emulator currently emulates model T f.device_id = storage.get_device_id() f.label = storage.get_label() f.initialized = storage.is_initialized() f.pin_protection = config.has_pin() f.pin_cached = config.has_pin() f.passphrase_protection = storage.has_passphrase() f.passphrase_cached = cache.has_passphrase() f.needs_backup = storage.needs_backup() f.unfinished_backup = storage.unfinished_backup() f.flags = storage.get_flags() return f
async def bootscreen(): while True: try: if not config.has_pin(): config.unlock(pin_to_int(''), show_pin_timeout) return await lockscreen() while True: pin = await request_pin() if config.unlock(pin_to_int(pin), show_pin_timeout): return except: pass
async def request_pin_and_sd_salt( ctx: wire.Context, prompt: str = "Enter your PIN", allow_cancel: bool = True ) -> Tuple[str, Optional[bytearray]]: salt_auth_key = device.get_sd_salt_auth_key() if salt_auth_key is not None: salt = await request_sd_salt(ctx, salt_auth_key) # type: Optional[bytearray] else: salt = None if config.has_pin(): pin = await request_pin_ack(ctx, prompt, config.get_pin_rem(), allow_cancel) else: pin = "" return pin, salt
async def bootscreen(): while True: try: if not config.has_pin(): config.unlock(pin_to_int(''), show_pin_timeout) return await lockscreen() label = None while True: pin = await request_pin(label) if config.unlock(pin_to_int(pin), show_pin_timeout): return else: label = 'Wrong PIN, enter again' except: # noqa: E722 pass
async def recovery_device(ctx: wire.Context, msg: RecoveryDevice) -> Success: """ Recover BIP39/SLIP39 seed into empty device. Recovery is also possible with replugged Trezor. We call this process Persistance. User starts the process here using the RecoveryDevice msg and then they can unplug the device anytime and continue without a computer. """ _check_state(msg) if not msg.dry_run: title = "Recovery mode" text = Text(title, ui.ICON_RECOVERY) text.normal("Do you really want to", "recover a wallet?", "") else: title = "Seed check" text = Text(title, ui.ICON_RECOVERY) text.normal("Do you really want to", "check the recovery", "seed?") await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall) # for dry run pin needs to entered if msg.dry_run: if config.has_pin(): curpin = await request_pin_ack(ctx, "Enter PIN", config.get_pin_rem()) else: curpin = "" if not config.check_pin(pin_to_int(curpin)): raise wire.PinInvalid("PIN invalid") # set up pin if requested if msg.pin_protection: if msg.dry_run: raise wire.ProcessError("Can't setup PIN during dry_run recovery.") newpin = await request_pin_confirm(ctx, allow_cancel=False) config.change_pin(pin_to_int(""), pin_to_int(newpin)) if msg.u2f_counter: storage.device.set_u2f_counter(msg.u2f_counter) storage.device.load_settings(label=msg.label, use_passphrase=msg.passphrase_protection) storage.recovery.set_in_progress(True) if msg.dry_run: storage.recovery.set_dry_run(msg.dry_run) result = await recovery_process(ctx) return result
async def bootscreen(): while True: try: if not config.has_pin(): config.unlock(pin_to_int(""), show_pin_timeout) return await lockscreen() label = None while True: pin = await request_pin(label) if config.unlock(pin_to_int(pin), show_pin_timeout): return else: label = "Wrong PIN, enter again" except Exception as e: if __debug__: log.exception(__name__, e)