show firmware hash screen after unofficial firmware dialog

This commit is contained in:
Pavol Rusnak 2016-02-10 14:16:59 +01:00
parent 63bc16d375
commit fa0b238b45
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 41 additions and 18 deletions

View File

@ -38,7 +38,23 @@
#error Bootloader cannot be used in app mode #error Bootloader cannot be used in app mode
#endif #endif
void show_unofficial_warning(void) void layoutFirmwareHash(uint8_t *hash)
{
char str[4][17];
int i;
for (i = 0; i < 4; i++) {
data2hex(hash + i * 8, 8, str[i]);
}
layoutDialog(DIALOG_ICON_QUESTION, "Abort", "Continue", "Compare fingerprints", str[0], str[1], str[2], str[3], NULL, NULL);
}
void show_halt(void)
{
layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com");
system_halt();
}
void show_unofficial_warning(uint8_t *hash)
{ {
layoutDialog(DIALOG_ICON_WARNING, "Abort", "I'll take the risk", NULL, "WARNING!", NULL, "Unofficial firmware", "detected.", NULL, NULL); layoutDialog(DIALOG_ICON_WARNING, "Abort", "I'll take the risk", NULL, "WARNING!", NULL, "Unofficial firmware", "detected.", NULL, NULL);
@ -47,12 +63,22 @@ void show_unofficial_warning(void)
buttonUpdate(); buttonUpdate();
} while (!button.YesUp && !button.NoUp); } while (!button.YesUp && !button.NoUp);
if (button.YesUp) { if (button.NoUp) {
return; // yes button was pressed -> return show_halt(); // no button was pressed -> halt
} }
layoutDialog(DIALOG_ICON_ERROR, NULL, NULL, NULL, "Unofficial firmware", "aborted.", NULL, "Unplug your TREZOR", "and see our support", "page at mytrezor.com"); layoutFirmwareHash(hash);
system_halt();
do {
delay(100000);
buttonUpdate();
} while (!button.YesUp && !button.NoUp);
if (button.NoUp) {
show_halt(); // no button was pressed -> halt
}
// everything is OK, user pressed 2x Continue -> continue program
} }
void load_app(void) void load_app(void)
@ -128,8 +154,9 @@ int main(void)
oledDrawBitmap(40, 0, &bmp_logo64_empty); oledDrawBitmap(40, 0, &bmp_logo64_empty);
oledRefresh(); oledRefresh();
if (!signatures_ok(NULL)) { uint8_t hash[32];
show_unofficial_warning(); if (!signatures_ok(hash)) {
show_unofficial_warning(hash);
} }
load_app(); load_app();

View File

@ -22,15 +22,17 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 5 #define VERSION_PATCH 6
#define STR(X) #X #define STR(X) #X
#define VERSTR(X) STR(X) #define VERSTR(X) STR(X)
#define VERSION_MAJOR_CHAR "\x01" #define VERSION_MAJOR_CHAR "\x01"
#define VERSION_MINOR_CHAR "\x02" #define VERSION_MINOR_CHAR "\x02"
#define VERSION_PATCH_CHAR "\x05" #define VERSION_PATCH_CHAR "\x06"
#include "memory.h" #include "memory.h"
void layoutFirmwareHash(uint8_t *hash);
#endif #endif

View File

@ -425,15 +425,9 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
if (msg_id != 0x001B) { // ButtonAck message (id 27) if (msg_id != 0x001B) { // ButtonAck message (id 27)
return; return;
} }
char digest[64]; uint8_t hash[32];
sha256_End(&ctx, digest); sha256_Final(hash, &ctx);
char str[4][17]; layoutFirmwareHash(hash);
strlcpy(str[0], digest, 17);
strlcpy(str[1], digest + 16, 17);
strlcpy(str[2], digest + 32, 17);
strlcpy(str[3], digest + 48, 17);
layoutDialog(DIALOG_ICON_QUESTION, "Abort", "Continue", "Compare fingerprints", str[0], str[1], str[2], str[3], NULL, NULL);
do { do {
delay(100000); delay(100000);
buttonUpdate(); buttonUpdate();