common: add support for FIDO data to template rendering

pull/748/head
matejcik 5 years ago committed by matejcik
parent 6a3910b8ff
commit 04c34fb4b0

@ -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

@ -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:

Loading…
Cancel
Save