From 545e93d1b48ae8d394d8f342067c3ae7c067b534 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 4 Jul 2016 17:01:34 +0200 Subject: [PATCH] add layout to u2f app --- src/apps/fido_u2f/__init__.py | 2 ++ src/apps/fido_u2f/knownapps.py | 14 ++++++++------ src/apps/fido_u2f/layout_u2f.py | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 src/apps/fido_u2f/layout_u2f.py diff --git a/src/apps/fido_u2f/__init__.py b/src/apps/fido_u2f/__init__.py index e69de29b..7a9be839 100644 --- a/src/apps/fido_u2f/__init__.py +++ b/src/apps/fido_u2f/__init__.py @@ -0,0 +1,2 @@ +def boot(): + pass diff --git a/src/apps/fido_u2f/knownapps.py b/src/apps/fido_u2f/knownapps.py index 585ac82b..d56c729b 100644 --- a/src/apps/fido_u2f/knownapps.py +++ b/src/apps/fido_u2f/knownapps.py @@ -1,8 +1,10 @@ +from trezor.crypto import hashlib + knownapps = { - b'12743b921297b77f1135e41fdedd4a846afe82e1f36932a9912f3b0d8dfb7d0e': 'Bitbucket', # https://bitbucket.org - b'c50f8a7b708e92f82e7a50e2bdc55d8fd91a22fe6b29c0cdf7805530842af581': 'Dropbox', # https://www.dropbox.com/u2f-app-id.json - b'70617dfed065863af47c15556c91798880828cc407fdf70ae85011569465a075': 'Github', # https://github.com/u2f/trusted_facets - b'e7be96a51bd0192a72840d2e5909f72ba82a2fe93faa624f03396b30e494c804': 'Gitlab', # https://gitlab.com - b'a54672b222c4cf95e151ed8d4d3c767a6cc349435943794e884f3d023a8229fd': 'Google', # https://www.gstatic.com/securitykey/origins.json - b'08b2a3d41939aa31668493cb36cdcc4f16c4d9b4c8238b73c2f672c033007197': 'Slush Pool', # https://slushpool.com/static/security/u2f.json + hashlib.sha256(b'https://bitbucket.org').digest() : 'Bitbucket', + hashlib.sha256(b'https://www.dropbox.com/u2f-app-id.json').digest() : 'Dropbox', + hashlib.sha256(b'https://github.com/u2f/trusted_facets').digest() : 'GitHub', + hashlib.sha256(b'https://gitlab.com').digest() : 'GitLab', + hashlib.sha256(b'https://www.gstatic.com/securitykey/origins.json').digest() : 'Google', + hashlib.sha256(b'https://slushpool.com/static/security/u2f.json').digest() : 'Slush Pool', } diff --git a/src/apps/fido_u2f/layout_u2f.py b/src/apps/fido_u2f/layout_u2f.py new file mode 100644 index 00000000..27792bb4 --- /dev/null +++ b/src/apps/fido_u2f/layout_u2f.py @@ -0,0 +1,34 @@ +from ubinascii import hexlify +from trezor import ui, loop, res +from trezor.utils import unimport_gen +from trezor.crypto import random +from . import knownapps + +ids = list(knownapps.knownapps.keys()) +random.shuffle(ids) + +appid = ids[0] +action = 'Register' + +@unimport_gen +def layout_u2f(): + + if appid in knownapps.knownapps: + appname = knownapps.knownapps[appid] + appicon = res.load('apps/fido_u2f/res/u2f_%s.toif' % appname.lower().replace(' ', '_')) + else: + appname = hexlify(appid[:4]) + '...' + hexlify(appid[-4:]) + appicon = res.load('apps/fido_u2f/res/u2f_unknown.toif') + + # paint background black + ui.display.bar(0, 0, 240, 240, ui.BLACK) + + # top header bar + ui.display.text(10, 28, 'U2F Login', ui.BOLD, ui.PM_BLUE, ui.BLACK) + + # content + ui.display.text_center(120, 70, '%s:' % action, ui.BOLD, ui.GREY, ui.BLACK) + ui.display.image((240 - 64) // 2, 90, appicon) + ui.display.text_center(120, 185, appname, ui.MONO, ui.WHITE, ui.BLACK) + + yield loop.Wait([])