core/sd_salt: ensure ProcessErrors are propagated properly

pull/665/head
matejcik 5 years ago
parent 8225e5d8b2
commit dee47a06f2

@ -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

@ -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

@ -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:

Loading…
Cancel
Save