1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 12:32:02 +00:00

bootloader: guard signatures_ok calls with firmware_present (or !brand_new_firmware)

This commit is contained in:
Pavol Rusnak 2018-03-15 04:15:41 +01:00
parent 816b4e0f72
commit dbe444029a
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 5 additions and 2 deletions

View File

@ -40,6 +40,8 @@ static const uint8_t * const pubkey[PUBKEYS] = {
int signatures_ok(uint8_t *store_hash)
{
if (!firmware_present()) return SIG_FAIL; // no firmware present
const uint32_t codelen = *((const uint32_t *)FLASH_META_CODELEN);
const uint8_t sigindex1 = *((const uint8_t *)FLASH_META_SIGINDEX1);
const uint8_t sigindex2 = *((const uint8_t *)FLASH_META_SIGINDEX2);

View File

@ -476,7 +476,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
}
if (brand_new_firmware || button.YesUp) {
// check whether current firmware is signed
if (SIG_OK == signatures_ok(NULL)) {
if (!brand_new_firmware && SIG_OK == signatures_ok(NULL)) {
old_was_unsigned = false;
// backup metadata
backup_metadata(meta_backup);
@ -632,10 +632,11 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
layoutProgress("INSTALLING ... Please wait", 1000);
uint8_t flags = *((uint8_t *)FLASH_META_FLAGS);
// wipe storage if:
// 0) there was no firmware
// 1) old firmware was unsigned
// 2) firmware restore flag isn't set
// 3) signatures are not ok
if (old_was_unsigned || (flags & 0x01) == 0 || SIG_OK != signatures_ok(NULL)) {
if (brand_new_firmware || old_was_unsigned || (flags & 0x01) == 0 || SIG_OK != signatures_ok(NULL)) {
memzero(meta_backup, sizeof(meta_backup));
}
// copy new firmware header