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

core: use cache for Monero live refresh confirmation

This commit is contained in:
matejcik 2020-01-29 15:22:31 +01:00 committed by Pavol Rusnak
parent 7513a65f9a
commit 1f50a13edf
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 4 additions and 15 deletions

View File

@ -4,7 +4,6 @@ from trezor.messages import MessageType
from apps.common import HARDENED from apps.common import HARDENED
CURVE = "ed25519" CURVE = "ed25519"
_LIVE_REFRESH_TOKEN = None # live-refresh permission token
def boot() -> None: def boot() -> None:
@ -20,11 +19,3 @@ def boot() -> None:
if __debug__ and hasattr(MessageType, "DebugMoneroDiagRequest"): if __debug__ and hasattr(MessageType, "DebugMoneroDiagRequest"):
wire.add(MessageType.DebugMoneroDiagRequest, __name__, "diag") wire.add(MessageType.DebugMoneroDiagRequest, __name__, "diag")
def live_refresh_token(token: bytes = None) -> None:
global _LIVE_REFRESH_TOKEN
if token is None:
return _LIVE_REFRESH_TOKEN
else:
_LIVE_REFRESH_TOKEN = token

View File

@ -10,7 +10,7 @@ from trezor.messages.MoneroLiveRefreshStepAck import MoneroLiveRefreshStepAck
from trezor.messages.MoneroLiveRefreshStepRequest import MoneroLiveRefreshStepRequest from trezor.messages.MoneroLiveRefreshStepRequest import MoneroLiveRefreshStepRequest
from apps.common import paths from apps.common import paths
from apps.monero import CURVE, live_refresh_token, misc from apps.monero import CURVE, misc
from apps.monero.layout import confirms from apps.monero.layout import confirms
from apps.monero.xmr import crypto, key_image, monero from apps.monero.xmr import crypto, key_image, monero
from apps.monero.xmr.crypto import chacha_poly from apps.monero.xmr.crypto import chacha_poly
@ -49,10 +49,9 @@ async def _init_step(
ctx, misc.validate_full_path, keychain, msg.address_n, CURVE ctx, misc.validate_full_path, keychain, msg.address_n, CURVE
) )
fingerprint = storage.cache.get_session_id()[:4] if not storage.cache.get(storage.cache.APP_MONERO_LIVE_REFRESH):
if live_refresh_token() != fingerprint:
await confirms.require_confirm_live_refresh(ctx) await confirms.require_confirm_live_refresh(ctx)
live_refresh_token(fingerprint) storage.cache.set(storage.cache.APP_MONERO_LIVE_REFRESH, True)
s.creds = misc.get_creds(keychain, msg.address_n, msg.network_type) s.creds = misc.get_creds(keychain, msg.address_n, msg.network_type)

View File

@ -6,6 +6,7 @@ if False:
APP_COMMON_SEED = 0 APP_COMMON_SEED = 0
APP_COMMON_SEED_WITHOUT_PASSPHRASE = 1 APP_COMMON_SEED_WITHOUT_PASSPHRASE = 1
APP_CARDANO_ROOT = 2 APP_CARDANO_ROOT = 2
APP_MONERO_LIVE_REFRESH = 3
_cache_session_id = None # type: Optional[bytes] _cache_session_id = None # type: Optional[bytes]
_cache = {} _cache = {}
@ -22,7 +23,6 @@ def get_session_id() -> bytes:
def set(key: int, value: Any) -> None: def set(key: int, value: Any) -> None:
global _cache
_cache[key] = value _cache[key] = value
@ -32,6 +32,5 @@ def get(key: int) -> Any:
def clear() -> None: def clear() -> None:
global _cache_session_id global _cache_session_id
global _cache
_cache_session_id = None _cache_session_id = None
_cache.clear() _cache.clear()