mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 10:58:21 +00:00
core, legacy: Don't allow change_pin if device is not initialized.
This commit is contained in:
parent
737ebeec1c
commit
ba9eee3b8f
@ -39,7 +39,7 @@ async def _get_passphrase(ctx: wire.Context) -> bytes:
|
|||||||
|
|
||||||
async def get_keychain(ctx: wire.Context) -> Keychain:
|
async def get_keychain(ctx: wire.Context) -> Keychain:
|
||||||
if not storage.is_initialized():
|
if not storage.is_initialized():
|
||||||
raise wire.ProcessError("Device is not initialized")
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
|
|
||||||
if mnemonic.is_bip39():
|
if mnemonic.is_bip39():
|
||||||
# derive the root node from mnemonic and passphrase
|
# derive the root node from mnemonic and passphrase
|
||||||
|
@ -108,7 +108,7 @@ class Keychain:
|
|||||||
|
|
||||||
async def get_keychain(ctx: wire.Context, namespaces: list) -> Keychain:
|
async def get_keychain(ctx: wire.Context, namespaces: list) -> Keychain:
|
||||||
if not storage.is_initialized():
|
if not storage.is_initialized():
|
||||||
raise wire.ProcessError("Device is not initialized")
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
seed = cache.get_seed()
|
seed = cache.get_seed()
|
||||||
if seed is None:
|
if seed is None:
|
||||||
passphrase = cache.get_passphrase()
|
passphrase = cache.get_passphrase()
|
||||||
|
@ -7,7 +7,7 @@ from apps.management.reset_device import backup_seed, layout
|
|||||||
|
|
||||||
async def backup_device(ctx, msg):
|
async def backup_device(ctx, msg):
|
||||||
if not storage.is_initialized():
|
if not storage.is_initialized():
|
||||||
raise wire.ProcessError("Device is not initialized")
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
if not storage.device.needs_backup():
|
if not storage.device.needs_backup():
|
||||||
raise wire.ProcessError("Seed already backed up")
|
raise wire.ProcessError("Seed already backed up")
|
||||||
|
|
||||||
|
@ -10,12 +10,16 @@ from apps.common.request_pin import (
|
|||||||
request_pin_confirm,
|
request_pin_confirm,
|
||||||
show_pin_invalid,
|
show_pin_invalid,
|
||||||
)
|
)
|
||||||
|
from apps.common.storage import is_initialized
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from trezor.messages.ChangePin import ChangePin
|
from trezor.messages.ChangePin import ChangePin
|
||||||
|
|
||||||
|
|
||||||
async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
|
async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
|
||||||
|
if not is_initialized():
|
||||||
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
|
|
||||||
# confirm that user wants to change the pin
|
# confirm that user wants to change the pin
|
||||||
await require_confirm_change_pin(ctx, msg)
|
await require_confirm_change_pin(ctx, msg)
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ def _check_state(msg: RecoveryDevice) -> None:
|
|||||||
if not msg.dry_run and storage.is_initialized():
|
if not msg.dry_run and storage.is_initialized():
|
||||||
raise wire.UnexpectedMessage("Already initialized")
|
raise wire.UnexpectedMessage("Already initialized")
|
||||||
if msg.dry_run and not storage.is_initialized():
|
if msg.dry_run and not storage.is_initialized():
|
||||||
raise wire.UnexpectedMessage("Device is not initialized")
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
|
|
||||||
if storage.recovery.is_in_progress():
|
if storage.recovery.is_in_progress():
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
@ -27,11 +27,11 @@ async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
|||||||
# make sure user knows they're setting up a new wallet
|
# make sure user knows they're setting up a new wallet
|
||||||
await layout.show_reset_device_warning(ctx, msg.backup_type)
|
await layout.show_reset_device_warning(ctx, msg.backup_type)
|
||||||
|
|
||||||
# request new PIN
|
# request and set new PIN
|
||||||
if msg.pin_protection:
|
if msg.pin_protection:
|
||||||
newpin = await request_pin_confirm(ctx)
|
newpin = await request_pin_confirm(ctx)
|
||||||
else:
|
if not config.change_pin(pin_to_int(""), pin_to_int(newpin), None, None):
|
||||||
newpin = ""
|
raise wire.ProcessError("Failed to set PIN")
|
||||||
|
|
||||||
# generate and display internal entropy
|
# generate and display internal entropy
|
||||||
int_entropy = random.bytes(32)
|
int_entropy = random.bytes(32)
|
||||||
@ -70,10 +70,6 @@ async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
|||||||
if perform_backup:
|
if perform_backup:
|
||||||
await backup_seed(ctx, msg.backup_type, secret)
|
await backup_seed(ctx, msg.backup_type, secret)
|
||||||
|
|
||||||
# write PIN into storage
|
|
||||||
if not config.change_pin(pin_to_int(""), pin_to_int(newpin), None, None):
|
|
||||||
raise wire.ProcessError("Could not change PIN")
|
|
||||||
|
|
||||||
# write settings and master secret into storage
|
# write settings and master secret into storage
|
||||||
storage.device.load_settings(
|
storage.device.load_settings(
|
||||||
label=msg.label, use_passphrase=msg.passphrase_protection
|
label=msg.label, use_passphrase=msg.passphrase_protection
|
||||||
|
@ -30,7 +30,7 @@ if False:
|
|||||||
|
|
||||||
async def sd_protect(ctx: wire.Context, msg: SdProtect) -> Success:
|
async def sd_protect(ctx: wire.Context, msg: SdProtect) -> Success:
|
||||||
if not is_initialized():
|
if not is_initialized():
|
||||||
raise wire.ProcessError("Device is not initialized")
|
raise wire.NotInitialized("Device is not initialized")
|
||||||
|
|
||||||
if msg.operation == SdProtectOperationType.ENABLE:
|
if msg.operation == SdProtectOperationType.ENABLE:
|
||||||
return await sd_protect_enable(ctx, msg)
|
return await sd_protect_enable(ctx, msg)
|
||||||
|
@ -136,6 +136,8 @@ void fsm_msgPing(const Ping *msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fsm_msgChangePin(const ChangePin *msg) {
|
void fsm_msgChangePin(const ChangePin *msg) {
|
||||||
|
CHECK_INITIALIZED
|
||||||
|
|
||||||
bool removal = msg->has_remove && msg->remove;
|
bool removal = msg->has_remove && msg->remove;
|
||||||
if (removal) {
|
if (removal) {
|
||||||
if (config_hasPin()) {
|
if (config_hasPin()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user