diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c index 1061394..48f3cba 100644 --- a/bootloader/bootloader.c +++ b/bootloader/bootloader.c @@ -38,7 +38,23 @@ #error Bootloader cannot be used in app mode #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); @@ -47,12 +63,22 @@ void show_unofficial_warning(void) buttonUpdate(); } while (!button.YesUp && !button.NoUp); - if (button.YesUp) { - return; // yes button was pressed -> return + if (button.NoUp) { + 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"); - system_halt(); + layoutFirmwareHash(hash); + + 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) @@ -128,8 +154,9 @@ int main(void) oledDrawBitmap(40, 0, &bmp_logo64_empty); oledRefresh(); - if (!signatures_ok(NULL)) { - show_unofficial_warning(); + uint8_t hash[32]; + if (!signatures_ok(hash)) { + show_unofficial_warning(hash); } load_app(); diff --git a/bootloader/bootloader.h b/bootloader/bootloader.h index 3546d15..3a37d60 100644 --- a/bootloader/bootloader.h +++ b/bootloader/bootloader.h @@ -22,15 +22,17 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 2 -#define VERSION_PATCH 5 +#define VERSION_PATCH 6 #define STR(X) #X #define VERSTR(X) STR(X) #define VERSION_MAJOR_CHAR "\x01" #define VERSION_MINOR_CHAR "\x02" -#define VERSION_PATCH_CHAR "\x05" +#define VERSION_PATCH_CHAR "\x06" #include "memory.h" +void layoutFirmwareHash(uint8_t *hash); + #endif diff --git a/bootloader/usb.c b/bootloader/usb.c index 9363a3d..e9355d6 100644 --- a/bootloader/usb.c +++ b/bootloader/usb.c @@ -425,15 +425,9 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep) if (msg_id != 0x001B) { // ButtonAck message (id 27) return; } - char digest[64]; - sha256_End(&ctx, digest); - char str[4][17]; - 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); - + uint8_t hash[32]; + sha256_Final(hash, &ctx); + layoutFirmwareHash(hash); do { delay(100000); buttonUpdate();