1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-31 18:40:56 +00:00

fix(core): increase minimum auto-lock delay to 1 minute

This commit is contained in:
Martin Milata 2020-11-18 18:59:24 +01:00 committed by Pavol Rusnak
parent 65a9636bb5
commit 93d45f1aba

View File

@ -48,7 +48,11 @@ if False:
# fmt: on
HOMESCREEN_MAXSIZE = 16384
AUTOLOCK_DELAY_MINIMUM = 10 * 1000 # 10 seconds
if __debug__:
AUTOLOCK_DELAY_MINIMUM = 10 * 1000 # 10 seconds
else:
AUTOLOCK_DELAY_MINIMUM = 60 * 1000 # 1 minute
AUTOLOCK_DELAY_DEFAULT = 10 * 60 * 1000 # 10 minutes
# autolock intervals larger than AUTOLOCK_DELAY_MAXIMUM cause issues in the scheduler
AUTOLOCK_DELAY_MAXIMUM = 0x2000_0000 # ~6 days
@ -217,17 +221,22 @@ def set_flags(flags: int) -> None:
common.set(_NAMESPACE, _FLAGS, flags.to_bytes(4, "big"))
def _normalize_autolock_delay(delay_ms: int) -> int:
delay_ms = max(delay_ms, AUTOLOCK_DELAY_MINIMUM)
delay_ms = min(delay_ms, AUTOLOCK_DELAY_MAXIMUM)
return delay_ms
def get_autolock_delay_ms() -> int:
b = common.get(_NAMESPACE, _AUTOLOCK_DELAY_MS)
if b is None:
return AUTOLOCK_DELAY_DEFAULT
else:
return int.from_bytes(b, "big")
return _normalize_autolock_delay(int.from_bytes(b, "big"))
def set_autolock_delay_ms(delay_ms: int) -> None:
delay_ms = max(delay_ms, AUTOLOCK_DELAY_MINIMUM)
delay_ms = min(delay_ms, AUTOLOCK_DELAY_MAXIMUM)
delay_ms = _normalize_autolock_delay(delay_ms)
common.set(_NAMESPACE, _AUTOLOCK_DELAY_MS, delay_ms.to_bytes(4, "big"))