From 04c34fb4b064c1248fefb477e2f26898ab0565fa Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 28 Nov 2019 14:00:13 +0100 Subject: [PATCH] common: add support for FIDO data to template rendering --- common/tools/coin_info.py | 18 +++++++++++++----- common/tools/cointool.py | 20 ++++++++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/common/tools/coin_info.py b/common/tools/coin_info.py index 7af79198ca..8fade47b44 100755 --- a/common/tools/coin_info.py +++ b/common/tools/coin_info.py @@ -262,12 +262,20 @@ def _load_misc(): def _load_fido_apps(): """Load btc-like coins from `coins/*.json`""" apps = [] - for filename in glob.glob(os.path.join(DEFS_DIR, "webauthn", "apps", "*.json")): - app_name = os.path.basename(filename)[:-5] + for filename in sorted( + glob.glob(os.path.join(DEFS_DIR, "webauthn", "apps", "*.json")) + ): + app_name = os.path.basename(filename)[:-5].lower() app = load_json(filename) - app.update( - key=app_name, - ) + app.setdefault("use_sign_count", None) + app.setdefault("u2f", []) + app.setdefault("webauthn", []) + + icon_path = os.path.join(DEFS_DIR, "webauthn", "apps", app_name + ".png") + if not os.path.exists(icon_path): + icon_path = None + + app.update(key=app_name, icon=icon_path) apps.append(app) return apps diff --git a/common/tools/cointool.py b/common/tools/cointool.py index 15408ef600..f50a2b2c6c 100755 --- a/common/tools/cointool.py +++ b/common/tools/cointool.py @@ -477,7 +477,7 @@ def check_segwit(coins): FIDO_KNOWN_KEYS = frozenset( - ("key", "u2f", "webauthn", "label", "use_sign_count", "demo") + ("key", "u2f", "webauthn", "label", "use_sign_count", "demo", "icon") ) @@ -510,20 +510,23 @@ def check_fido(apps): unknown_keys = set(app.keys()) - FIDO_KNOWN_KEYS if unknown_keys: print_log(logging.ERROR, app["key"], ": unrecognized keys:", unknown_keys) + check_passed = False # check icons - icon_file = app["key"].lower() + ".png" - try: - icon = Image.open( - os.path.join(coin_info.DEFS_DIR, "webauthn", "apps", icon_file) - ) - except Exception: + if app["icon"] is None: if app.get("demo"): log_level = logging.WARNING else: log_level = logging.ERROR check_passed = False - print_log(log_level, app["key"], ": failed to open icon file", icon_file) + print_log(log_level, app["key"], ": missing icon") + continue + + try: + icon = Image.open(app["icon"]) + except Exception: + print_log(log_level, app["key"], ": failed to open icon file", app["icon"]) + check_passed = False continue if icon.size != (128, 128) or icon.mode != "RGBA": @@ -887,6 +890,7 @@ def render(paths, outfile, verbose, bitcoin_only): # prepare defs defs = coin_info.coin_info() + defs["fido"] = coin_info.fido_info() support_info = coin_info.support_info(defs) if bitcoin_only: