From 8be38960389380a89a01cd45a0f3f45eb6f4966a Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 4 Jan 2019 16:23:14 +0100 Subject: [PATCH] Convert U2F counter from private to public to take advantage of the more efficient implementation. --- src/apps/common/storage.py | 14 +++++++++++++- src/boot.py | 5 +++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index 7692d9741..894668201 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -8,7 +8,7 @@ from apps.common import cache HOMESCREEN_MAXSIZE = 16384 -_STORAGE_VERSION = b"\x01" +_STORAGE_VERSION = b"\x02" _FALSE_BYTE = b"\x00" _TRUE_BYTE = b"\x01" _COUNTER_HEAD_LEN = 4 @@ -223,3 +223,15 @@ def set_u2f_counter(cntr: int) -> None: def wipe(): config.wipe() cache.clear() + + +def init_unlocked(): + # Check for storage version upgrade. + version = config.get(_APP, _VERSION) + if version == b"\x01": + # Make the U2F counter public. + counter = config.get(_APP, _U2F_COUNTER) + if counter is not None: + _set_counter(_APP, _U2F_COUNTER, counter, True) + config.delete(_APP, _U2F_COUNTER) + config.set(_APP, _VERSION, _STORAGE_VERSION) diff --git a/src/boot.py b/src/boot.py index cec662cdb..c47b566a2 100644 --- a/src/boot.py +++ b/src/boot.py @@ -2,6 +2,7 @@ from trezor import config, log, loop, res, ui from trezor.pin import pin_to_int, show_pin_timeout from apps.common.request_pin import request_pin +from apps.common import storage async def bootscreen(): @@ -9,12 +10,14 @@ async def bootscreen(): try: if not config.has_pin(): config.unlock(pin_to_int("")) + storage.init_unlocked() return await lockscreen() label = None while True: pin = await request_pin(label, config.get_pin_rem()) if config.unlock(pin_to_int(pin)): + storage.init_unlocked() return else: label = "Wrong PIN, enter again" @@ -24,8 +27,6 @@ async def bootscreen(): async def lockscreen(): - from apps.common import storage - label = storage.get_label() image = storage.get_homescreen() if not label: