1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-13 18:18:08 +00:00
trezor-firmware/core/src/storage/__init__.py
matejcik 5c93ecd53a core: create top-level storage module
This is to avoid including app-specific functionality in storage and
avoid circular imports. The following policy is now in effect: modules
from `storage` namespace must not import from `apps` namespace.

In most files, the change only involves changing import paths.

A minor refactor was needed in case of webauthn: basic get/set/delete
functionality was left in storage.webauthn, and more advanced logic on
top of it was moved to apps.webauthn.resident_credentials.

A significant refactor was needed for sd_salt, where application (and
UI) logic was tightly coupled with the IO code. This is now separated,
and storage.sd_salt deals exclusively with the IO side, while the app/UI
logic is implemented on top of it in apps.common.sd_salt and
apps.management.sd_protect.
2019-10-31 16:21:56 +01:00

34 lines
975 B
Python

from storage import cache, common, device
from trezor import config
def set_current_version() -> None:
device.set_version(common.STORAGE_VERSION_CURRENT)
def is_initialized() -> bool:
return device.is_version_stored()
def wipe() -> None:
config.wipe()
cache.clear()
def init_unlocked() -> None:
# Check for storage version upgrade.
version = device.get_version()
if version == common.STORAGE_VERSION_01:
_migrate_from_version_01()
def _migrate_from_version_01() -> None:
# Make the U2F counter public and writable even when storage is locked.
# U2F counter wasn't public, so we are intentionally not using storage.device module.
counter = common.get(common.APP_DEVICE, device.U2F_COUNTER)
if counter is not None:
device.set_u2f_counter(int.from_bytes(counter, "big"))
# Delete the old, non-public U2F_COUNTER.
common.delete(common.APP_DEVICE, device.U2F_COUNTER)
set_current_version()