1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 23:38:09 +00:00

core: add SafetyCheckLevel to Features

This commit is contained in:
Martin Milata 2020-09-02 13:08:37 +02:00 committed by Tomas Susanka
parent 9f066e877d
commit 9d2ad96ad4
2 changed files with 8 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from trezor import config, sdcard, utils, wire, workflow
from trezor.messages import Capability, MessageType from trezor.messages import Capability, MessageType
from trezor.messages.Features import Features from trezor.messages.Features import Features
from trezor.messages.PreauthorizedRequest import PreauthorizedRequest from trezor.messages.PreauthorizedRequest import PreauthorizedRequest
from trezor.messages.SafetyCheckLevel import Prompt, Strict
from trezor.messages.Success import Success from trezor.messages.Success import Success
from apps.common import mnemonic from apps.common import mnemonic
@ -92,6 +93,7 @@ def get_features() -> Features:
f.sd_protection = storage.sd_salt.is_enabled() f.sd_protection = storage.sd_salt.is_enabled()
f.wipe_code_protection = config.has_wipe_code() f.wipe_code_protection = config.has_wipe_code()
f.passphrase_always_on_device = storage.device.get_passphrase_always_on_device() f.passphrase_always_on_device = storage.device.get_passphrase_always_on_device()
f.safety_checks = Prompt if storage.device.unsafe_prompts_allowed() else Strict
return f return f

View File

@ -161,6 +161,8 @@ class TestMsgApplysettings:
def test_safety_checks(self, client): def test_safety_checks(self, client):
BAD_ADDRESS = parse_path("m/0") BAD_ADDRESS = parse_path("m/0")
assert client.features.safety_checks == messages.SafetyCheckLevel.Strict
with pytest.raises( with pytest.raises(
exceptions.TrezorFailure, match="Forbidden key path" exceptions.TrezorFailure, match="Forbidden key path"
), client: ), client:
@ -173,6 +175,8 @@ class TestMsgApplysettings:
client, safety_checks=messages.SafetyCheckLevel.Prompt client, safety_checks=messages.SafetyCheckLevel.Prompt
) )
assert client.features.safety_checks == messages.SafetyCheckLevel.Prompt
with client: with client:
client.set_expected_responses( client.set_expected_responses(
[messages.ButtonRequest(), messages.Address()] [messages.ButtonRequest(), messages.Address()]
@ -185,6 +189,8 @@ class TestMsgApplysettings:
client, safety_checks=messages.SafetyCheckLevel.Strict client, safety_checks=messages.SafetyCheckLevel.Strict
) )
assert client.features.safety_checks == messages.SafetyCheckLevel.Strict
with pytest.raises( with pytest.raises(
exceptions.TrezorFailure, match="Forbidden key path" exceptions.TrezorFailure, match="Forbidden key path"
), client: ), client: