From da067913c2b1177898588ad87acbd08a727a2386 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 9 Jun 2016 18:11:19 +0200 Subject: [PATCH] show app icons in u2f dialog --- firmware/layout2.c | 7 +++++-- firmware/layout2.h | 2 +- firmware/u2f.c | 30 ++++++++++++++++++++---------- firmware/u2f_knownapps.h | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/firmware/layout2.c b/firmware/layout2.c index 16b867441a..4c0a3a3cae 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -336,6 +336,9 @@ void layoutSignIdentity(const IdentityType *identity, const char *challenge) NULL); } -void layoutU2FDialog(const char *verb, const char *appid) { - layoutDialog(&bmp_icon_question, NULL, verb, NULL, verb, "U2F security key?", "", appid, "", NULL); +void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appicon) { + if (!appicon) { + appicon = &bmp_icon_question; + } + layoutDialog(appicon, NULL, verb, NULL, verb, "U2F security key?", "", appname, "", NULL); } diff --git a/firmware/layout2.h b/firmware/layout2.h index d17ec7faaf..975d530bc2 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -41,6 +41,6 @@ void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address) void layoutAddress(const char *address, const char *desc); void layoutPublicKey(const uint8_t *pubkey); void layoutSignIdentity(const IdentityType *identity, const char *challenge); -void layoutU2FDialog(const char *verb, const char *appid); +void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appicon); #endif diff --git a/firmware/u2f.c b/firmware/u2f.c index c910ae5a48..cb05370c70 100644 --- a/firmware/u2f.c +++ b/firmware/u2f.c @@ -441,19 +441,23 @@ void u2f_version(const APDU *a) send_u2f_msg(version_response, sizeof(version_response)); } -static const char *getReadableAppId(const uint8_t appid[U2F_APPID_SIZE]) { +void getReadableAppId(const uint8_t appid[U2F_APPID_SIZE], const char **appname, const BITMAP **appicon) { unsigned int i; - static char buf[6+2+6+1]; + static char buf[8+2+8+1]; for (i = 0; i < sizeof(u2f_well_known)/sizeof(U2FWellKnown); i++) { - if (memcmp(appid, u2f_well_known[i].appid, U2F_APPID_SIZE) == 0) - return u2f_well_known[i].appname; + if (memcmp(appid, u2f_well_known[i].appid, U2F_APPID_SIZE) == 0) { + *appname = u2f_well_known[i].appname; + *appicon = u2f_well_known[i].appicon; + return; + } } - data2hex(appid, 3, &buf[0]); - buf[6] = buf[7] = '.'; - data2hex(appid + (U2F_APPID_SIZE - 3), 3, &buf[8]); - return buf; + data2hex(appid, 4, &buf[0]); + buf[8] = buf[9] = '.'; + data2hex(appid + (U2F_APPID_SIZE - 4), 4, &buf[10]); + *appname = buf; + *appicon = NULL; } const HDNode *getDerivedNode(uint32_t *address_n, size_t address_n_count) @@ -555,7 +559,10 @@ void u2f_register(const APDU *a) getDerivedNode(NULL, 0); // error: testof-user-presence is required buttonUpdate(); // Clear button state - layoutU2FDialog("Register", getReadableAppId(req->appId)); + const char *appname; + const BITMAP *appicon; + getReadableAppId(req->appId, &appname, &appicon); + layoutU2FDialog("Register", appname, appicon); last_req_state = REG; } @@ -679,7 +686,10 @@ void u2f_authenticate(const APDU *a) if (last_req_state == INIT) { // error: testof-user-presence is required buttonUpdate(); // Clear button state - layoutU2FDialog("Authenticate", getReadableAppId(req->appId)); + const char *appname; + const BITMAP *appicon; + getReadableAppId(req->appId, &appname, &appicon); + layoutU2FDialog("Authenticate", appname, appicon); last_req_state = AUTH; } diff --git a/firmware/u2f_knownapps.h b/firmware/u2f_knownapps.h index 32386c73b1..947594012c 100644 --- a/firmware/u2f_knownapps.h +++ b/firmware/u2f_knownapps.h @@ -27,7 +27,7 @@ typedef struct { const uint8_t appid[U2F_APPID_SIZE]; const char *appname; - const BITMAP *icon; + const BITMAP *appicon; } U2FWellKnown; static const U2FWellKnown u2f_well_known[4] = {