From 5a1bc2db85ace95ed69840ef2bd8ae8037755369 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Fri, 28 Apr 2023 15:59:00 +0200 Subject: [PATCH] fix(core): don't send button requests when unlocking because BLE pairing is in progress [no changelog] --- core/src/apps/base.py | 6 ++++-- core/src/apps/common/request_pin.py | 14 ++++++++++++-- core/src/bluetooth.py | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/src/apps/base.py b/core/src/apps/base.py index b16e2b83e..f89cdeba6 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -319,7 +319,9 @@ def lock_device_if_unlocked() -> None: lock_device(interrupt_workflow=workflow.autolock_interrupts_workflow) -async def unlock_device(ctx: wire.GenericContext = wire.DUMMY_CONTEXT) -> None: +async def unlock_device( + ctx: wire.GenericContext = wire.DUMMY_CONTEXT, skip_button_request: bool = False +) -> None: """Ensure the device is in unlocked state. If the storage is locked, attempt to unlock it. Reset the homescreen and the wire @@ -329,7 +331,7 @@ async def unlock_device(ctx: wire.GenericContext = wire.DUMMY_CONTEXT) -> None: if not config.is_unlocked(): # verify_user_pin will raise if the PIN was invalid - await verify_user_pin(ctx) + await verify_user_pin(ctx, skip_button_request=skip_button_request) set_homescreen() diff --git a/core/src/apps/common/request_pin.py b/core/src/apps/common/request_pin.py index 66bac810c..137405ec2 100644 --- a/core/src/apps/common/request_pin.py +++ b/core/src/apps/common/request_pin.py @@ -98,6 +98,7 @@ async def verify_user_pin( allow_cancel: bool = True, retry: bool = True, cache_time_ms: int = 0, + skip_button_request: bool = False, ) -> None: # _get_last_unlock_time last_unlock = int.from_bytes( @@ -116,7 +117,11 @@ async def verify_user_pin( from trezor.ui.layouts import request_pin_on_device pin = await request_pin_on_device( - ctx, prompt, config.get_pin_rem(), allow_cancel + ctx, + prompt, + config.get_pin_rem(), + allow_cancel, + skip_button_request=skip_button_request, ) config.ensure_not_wipe_code(pin) else: @@ -131,7 +136,12 @@ async def verify_user_pin( while retry: pin = await request_pin_on_device( # type: ignore ["request_pin_on_device" is possibly unbound] - ctx, "Enter PIN", config.get_pin_rem(), allow_cancel, wrong_pin=True + ctx, + "Enter PIN", + config.get_pin_rem(), + allow_cancel, + wrong_pin=True, + skip_button_request=skip_button_request, ) if config.unlock(pin, salt): _set_last_unlock_time() diff --git a/core/src/bluetooth.py b/core/src/bluetooth.py index d44c19f26..ce09c0da5 100644 --- a/core/src/bluetooth.py +++ b/core/src/bluetooth.py @@ -59,7 +59,7 @@ def int_find_handler( return None async def wrapper(ctx: wire.Context, msg: wire.Msg) -> protobuf.MessageType: - await unlock_device(ctx) + await unlock_device(ctx, True) return await orig_handler(ctx, msg) return wrapper