mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
core/sd_salt: ensure ProcessErrors are propagated properly
This commit is contained in:
parent
8225e5d8b2
commit
dee47a06f2
@ -7,7 +7,7 @@ from trezor.ui.pin import CANCELLED, PinDialog
|
|||||||
from trezor.ui.popup import Popup
|
from trezor.ui.popup import Popup
|
||||||
from trezor.ui.text import Text
|
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:
|
if False:
|
||||||
from typing import Any, Optional, Tuple
|
from typing import Any, Optional, Tuple
|
||||||
@ -93,7 +93,10 @@ async def request_pin_and_sd_salt(
|
|||||||
async def verify_user_pin(
|
async def verify_user_pin(
|
||||||
prompt: str = "Enter your PIN", allow_cancel: bool = True, retry: bool = True
|
prompt: str = "Enter your PIN", allow_cancel: bool = True, retry: bool = True
|
||||||
) -> None:
|
) -> 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):
|
if not config.has_pin() and not config.check_pin(pin_to_int(""), salt):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
@ -9,7 +9,7 @@ if False:
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class SdProtectCancelled(Exception):
|
class SdProtectCancelled(wire.ProcessError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ async def ensure_sd_card(ctx: wire.GenericContext) -> None:
|
|||||||
sd = io.SDCard()
|
sd = io.SDCard()
|
||||||
while not sd.present():
|
while not sd.present():
|
||||||
if not await insert_card_dialog(ctx):
|
if not await insert_card_dialog(ctx):
|
||||||
raise SdProtectCancelled
|
raise SdProtectCancelled("SD card required.")
|
||||||
|
|
||||||
|
|
||||||
async def request_sd_salt(
|
async def request_sd_salt(
|
||||||
@ -67,7 +67,7 @@ async def request_sd_salt(
|
|||||||
return storage.sd_salt.load_sd_salt()
|
return storage.sd_salt.load_sd_salt()
|
||||||
except storage.sd_salt.WrongSdCard:
|
except storage.sd_salt.WrongSdCard:
|
||||||
if not await _wrong_card_dialog(ctx):
|
if not await _wrong_card_dialog(ctx):
|
||||||
raise SdProtectCancelled
|
raise SdProtectCancelled("Wrong SD card.")
|
||||||
except OSError:
|
except OSError:
|
||||||
# Either the SD card did not power on, or the filesystem could not be
|
# 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
|
# 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)
|
return storage.sd_salt.set_sd_salt(salt, salt_tag, stage)
|
||||||
except OSError:
|
except OSError:
|
||||||
if not await sd_problem_dialog(ctx):
|
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:
|
async def sd_protect(ctx: wire.Context, msg: SdProtect) -> Success:
|
||||||
|
Loading…
Reference in New Issue
Block a user