diff --git a/core/src/apps/common/request_pin.py b/core/src/apps/common/request_pin.py index ec2a1b3c9..3c0690b1c 100644 --- a/core/src/apps/common/request_pin.py +++ b/core/src/apps/common/request_pin.py @@ -7,7 +7,7 @@ from trezor.ui.pin import CANCELLED, PinDialog from trezor.ui.popup import Popup from trezor.ui.text import Text -from apps.common.sd_salt import request_sd_salt +from apps.common.sd_salt import SdProtectCancelled, request_sd_salt if False: from typing import Any, Optional, Tuple @@ -93,7 +93,10 @@ async def request_pin_and_sd_salt( async def verify_user_pin( prompt: str = "Enter your PIN", allow_cancel: bool = True, retry: bool = True ) -> None: - salt = await request_sd_salt() + try: + salt = await request_sd_salt() + except SdProtectCancelled: + raise PinCancelled if not config.has_pin() and not config.check_pin(pin_to_int(""), salt): raise RuntimeError diff --git a/core/src/apps/common/sd_salt.py b/core/src/apps/common/sd_salt.py index 4a9843c68..2d78d7a47 100644 --- a/core/src/apps/common/sd_salt.py +++ b/core/src/apps/common/sd_salt.py @@ -9,7 +9,7 @@ if False: from typing import Optional -class SdProtectCancelled(Exception): +class SdProtectCancelled(wire.ProcessError): pass @@ -55,7 +55,7 @@ async def ensure_sd_card(ctx: wire.GenericContext) -> None: sd = io.SDCard() while not sd.present(): if not await insert_card_dialog(ctx): - raise SdProtectCancelled + raise SdProtectCancelled("SD card required.") async def request_sd_salt( @@ -67,7 +67,7 @@ async def request_sd_salt( return storage.sd_salt.load_sd_salt() except storage.sd_salt.WrongSdCard: if not await _wrong_card_dialog(ctx): - raise SdProtectCancelled + raise SdProtectCancelled("Wrong SD card.") except OSError: # Either the SD card did not power on, or the filesystem could not be # mounted (card is not formatted?), or there is a staged salt file and diff --git a/core/src/apps/management/sd_protect.py b/core/src/apps/management/sd_protect.py index f9ca6a280..cfb325e46 100644 --- a/core/src/apps/management/sd_protect.py +++ b/core/src/apps/management/sd_protect.py @@ -37,7 +37,7 @@ async def _set_salt( return storage.sd_salt.set_sd_salt(salt, salt_tag, stage) except OSError: if not await sd_problem_dialog(ctx): - raise + raise wire.ProcessError("SD card I/O error.") async def sd_protect(ctx: wire.Context, msg: SdProtect) -> Success: