1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-15 01:40:57 +00:00

bootloader: show fingerprint on info click

This commit is contained in:
Pavol Rusnak 2018-01-25 14:16:21 +01:00
parent 8fc65d7f32
commit d27111472e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 77 additions and 22 deletions

View File

@ -32,6 +32,7 @@ SOURCE_MOD += [
# modtrezorui
CPPDEFINES_MOD += [
'TREZOR_FONT_MONO_ENABLE',
'TREZOR_FONT_NORMAL_ENABLE',
('TREZOR_FONT_PREFILL', '0'),
('QR_MAX_VERSION', '0'),
@ -41,6 +42,7 @@ SOURCE_MOD += [
'embed/extmod/modtrezorui/inflate.c',
'embed/extmod/modtrezorui/font_bitmap.c',
'embed/extmod/modtrezorui/font_roboto_regular_20.c',
'embed/extmod/modtrezorui/font_robotomono_regular_20.c',
'embed/extmod/modtrezorui/trezor-qrenc/qr_encode.c',
]

View File

@ -69,7 +69,7 @@ void ui_screen_boot_click(void) {
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 2, "click to continue ...", -1, FONT_NORMAL, COLOR_BL_GRAY, COLOR_BLACK, 0);
}
// info UI
// welcome UI
void ui_screen_first(void)
{
@ -89,6 +89,8 @@ void ui_screen_third(void)
display_text_center(120, 213, "Open trezor.io/start", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
}
// info UI
void ui_screen_info(secbool buttons, const vendor_header * const vhdr, const image_header * const hdr)
{
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
@ -127,6 +129,26 @@ void ui_screen_info(secbool buttons, const vendor_header * const vhdr, const ima
}
}
void ui_screen_info_fingerprint(const image_header * const hdr)
{
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, COLOR_WHITE);
display_text(16, 32, "Firmware fingerprint", -1, FONT_NORMAL, COLOR_BLACK, COLOR_WHITE, 0);
display_bar(16, 44, DISPLAY_RESX - 14 * 2, 1, COLOR_BLACK);
static const char *hexdigits = "0123456789abcdef";
char fingerprint_str[64];
for (int i = 0; i < 32; i++) {
fingerprint_str[i * 2 ] = hexdigits[(hdr->fingerprint[i] >> 4) & 0xF];
fingerprint_str[i * 2 + 1] = hexdigits[hdr->fingerprint[i] & 0xF];
}
for (int i = 0; i < 4; i++) {
display_text_center(120, 70 + i * 25, fingerprint_str + i * 16, 16, FONT_MONO, COLOR_BLACK, COLOR_WHITE, 0);
}
display_bar_radius(9, 184, 222, 50, COLOR_BL_DONE, COLOR_WHITE, 4);
display_icon(9 + (222 - 19) / 2, 184 + (50 - 16) / 2, 20, 16, toi_icon_confirm + 12, sizeof(toi_icon_confirm) - 12, COLOR_WHITE, COLOR_BL_DONE);
}
// install UI
void ui_screen_install_confirm(void)
@ -231,19 +253,27 @@ void ui_fadeout(void)
display_clear();
}
secbool ui_button_response(void)
int ui_user_input(int zones)
{
for (;;) {
uint32_t evt = touch_click();
uint16_t x = touch_get_x(evt);
uint16_t y = touch_get_y(evt);
// clicked on cancel button
if (x >= 9 && x < 9 + 108 && y > 184 && y < 184 + 50) {
return secfalse;
// clicked on Cancel button
if ((zones & INPUT_CANCEL) && x >= 9 && x < 9 + 108 && y > 184 && y < 184 + 50) {
return INPUT_CANCEL;
}
// clicked on confirm button
if (x >= 123 && x < 123 + 108 && y > 184 && y < 184 + 50) {
return sectrue;
// clicked on Confirm button
if ((zones & INPUT_CONFIRM) && x >= 123 && x < 123 + 108 && y > 184 && y < 184 + 50) {
return INPUT_CONFIRM;
}
// clicked on Long Confirm button
if ((zones & INPUT_LONG_CONFIRM) && x >= 9 && x < 9 + 222 && y > 184 && y < 184 + 50) {
return INPUT_LONG_CONFIRM;
}
// clicked on Info icon
if ((zones & INPUT_INFO) && x >= 16 && x < 16 + 32 && y > 54 && y < 54 + 32) {
return INPUT_INFO;
}
}
}

View File

@ -11,7 +11,9 @@ void ui_screen_boot_click(void);
void ui_screen_first(void);
void ui_screen_second(void);
void ui_screen_third(void);
void ui_screen_info(secbool buttons, const vendor_header * const vhdr, const image_header * const hdr);
void ui_screen_info_fingerprint(const image_header * const hdr);
void ui_screen_install_confirm(void);
void ui_screen_install(void);
@ -29,6 +31,10 @@ void ui_screen_fail(void);
void ui_fadein(void);
void ui_fadeout(void);
secbool ui_button_response(void);
#define INPUT_CANCEL 0x01 // Cancel button
#define INPUT_CONFIRM 0x02 // Confirm button
#define INPUT_LONG_CONFIRM 0x04 // Long Confirm button
#define INPUT_INFO 0x08 // Info icon
int ui_user_input(int zones);
#endif

View File

@ -119,7 +119,6 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
// invalid header -> discard
continue;
}
secbool response;
switch (msg_id) {
case 0: // Initialize
process_msg_Initialize(USB_IFACE_NUM, msg_size, buf, vhdr, hdr);
@ -131,8 +130,8 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
ui_fadeout();
ui_screen_wipe_confirm();
ui_fadein();
response = ui_button_response();
if (sectrue != response) {
int response = ui_user_input(INPUT_CONFIRM | INPUT_CANCEL);
if (INPUT_CANCEL == response) {
ui_fadeout();
ui_screen_info(secfalse, vhdr, hdr);
ui_fadein();
@ -165,8 +164,8 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
ui_fadeout();
ui_screen_install_confirm();
ui_fadein();
response = ui_button_response();
if (sectrue != response) {
int response = ui_user_input(INPUT_CONFIRM | INPUT_CANCEL);
if (INPUT_CANCEL == response) {
ui_fadeout();
ui_screen_info(secfalse, vhdr, hdr);
ui_fadein();
@ -319,16 +318,34 @@ main_start:
ui_screen_info(sectrue, &vhdr, &hdr);
ui_fadein();
secbool response = ui_button_response();
for (;;) {
int response = ui_user_input(INPUT_CONFIRM | INPUT_CANCEL | INPUT_INFO);
ui_fadeout();
ui_fadeout();
// if cancel was pressed -> restart
if (sectrue != response) {
goto main_start;
// if cancel was pressed -> restart
if (INPUT_CANCEL == response) {
goto main_start;
}
// if confirm was pressed -> jump out
if (INPUT_CONFIRM == response) {
// show firmware info without connect buttons
ui_screen_info(secfalse, &vhdr, &hdr);
ui_fadein();
break;
}
// if info icon was pressed -> show fingerprint
if (INPUT_INFO == response) {
// show fingerprint
ui_screen_info_fingerprint(&hdr);
ui_fadein();
while (INPUT_LONG_CONFIRM != ui_user_input(INPUT_LONG_CONFIRM)) { }
ui_fadeout();
ui_screen_info(sectrue, &vhdr, &hdr);
ui_fadein();
}
}
// show firmware info without connect buttons
ui_screen_info(secfalse, &vhdr, &hdr);
ui_fadein();
// and start the usb loop
if (bootloader_usb_loop(&vhdr, &hdr) != sectrue) {