void check_bootloader(void) { #if MEMORY_PROTECT uint8_t hash[32]; int r = memory_bootloader_hash(hash); if (!known_bootloader(r, hash)) { layoutDialog(&bmp_icon_error, NULL, NULL, NULL, _("Unknown bootloader"), _("detected."), NULL, _("Unplug your TREZOR"), _("contact our support."), NULL); shutdown(); } if (is_mode_unprivileged()) { return; } if (r == 32 && 0 == memcmp(hash, bl_hash, 32)) { // all OK -> done return; } // ENABLE THIS AT YOUR OWN RISK // ATTEMPTING TO OVERWRITE BOOTLOADER WITH UNSIGNED FIRMWARE MAY BRICK // YOUR DEVICE. layoutDialog(&bmp_icon_warning, NULL, NULL, NULL, _("Updating bootloader"), NULL, NULL, _("DO NOT UNPLUG"), _("YOUR TREZOR!"), NULL); // unlock sectors memory_write_unlock(); for (int tries = 0; tries < 10; tries++) { // replace bootloader flash_unlock(); for (int i = FLASH_BOOT_SECTOR_FIRST; i <= FLASH_BOOT_SECTOR_LAST; i++) { flash_erase_sector(i, FLASH_CR_PROGRAM_X32); } for (int i = 0; i < FLASH_BOOT_LEN / 4; i++) { const uint32_t *w = (const uint32_t *)(bl_data + i * 4); flash_program_word(FLASH_BOOT_START + i * 4, *w); } flash_lock(); // check whether the write was OK r = memory_bootloader_hash(hash); if (r == 32 && 0 == memcmp(hash, bl_hash, 32)) { // OK -> show info and halt layoutDialog(&bmp_icon_info, NULL, NULL, NULL, _("Update finished"), _("successfully."), NULL, _("Please reconnect"), _("the device."), NULL); shutdown(); return; } } // show info and halt layoutDialog(&bmp_icon_error, NULL, NULL, NULL, _("Bootloader update"), _("broken."), NULL, _("Unplug your TREZOR"), _("contact our support."), NULL); shutdown(); #endif }
void fsm_msgInitialize(Initialize *msg) { (void)msg; recovery_abort(); signing_abort(); RESP_INIT(Features); resp->has_vendor = true; strlcpy(resp->vendor, "bitcointrezor.com", sizeof(resp->vendor)); resp->has_major_version = true; resp->major_version = VERSION_MAJOR; resp->has_minor_version = true; resp->minor_version = VERSION_MINOR; resp->has_patch_version = true; resp->patch_version = VERSION_PATCH; resp->has_device_id = true; strlcpy(resp->device_id, storage_uuid_str, sizeof(resp->device_id)); resp->has_pin_protection = true; resp->pin_protection = storage.has_pin; resp->has_passphrase_protection = true; resp->passphrase_protection = storage.has_passphrase_protection && storage.passphrase_protection; #ifdef SCM_REVISION int len = sizeof(SCM_REVISION) - 1; resp->has_revision = true; memcpy(resp->revision.bytes, SCM_REVISION, len); resp->revision.size = len; #endif resp->has_bootloader_hash = true; resp->bootloader_hash.size = memory_bootloader_hash(resp->bootloader_hash.bytes); if (storage.has_language) { resp->has_language = true; strlcpy(resp->language, storage.language, sizeof(resp->language)); } if (storage.has_label) { resp->has_label = true; strlcpy(resp->label, storage.label, sizeof(resp->label)); } resp->coins_count = COINS_COUNT; memcpy(resp->coins, coins, COINS_COUNT * sizeof(CoinType)); resp->has_initialized = true; resp->initialized = storage_isInitialized(); resp->has_imported = true; resp->imported = storage.has_imported && storage.imported; msg_write(MessageType_MessageType_Features, resp); }
void fsm_msgGetFeatures(GetFeatures *msg) { (void)msg; RESP_INIT(Features); /* Vendor */ resp->has_vendor = true; strlcpy(resp->vendor, "keepkey.com", sizeof(resp->vendor)); /* Version */ resp->has_major_version = true; resp->major_version = MAJOR_VERSION; resp->has_minor_version = true; resp->minor_version = MINOR_VERSION; resp->has_patch_version = true; resp->patch_version = PATCH_VERSION; /* Device ID */ resp->has_device_id = true; strlcpy(resp->device_id, storage_get_uuid_str(), sizeof(resp->device_id)); /* Security settings */ resp->has_pin_protection = true; resp->pin_protection = storage_has_pin(); resp->has_passphrase_protection = true; resp->passphrase_protection = storage_get_passphrase_protected(); #ifdef SCM_REVISION int len = sizeof(SCM_REVISION) - 1; resp->has_revision = true; memcpy(resp->revision.bytes, SCM_REVISION, len); resp->revision.size = len; #endif /* Bootloader hash */ resp->has_bootloader_hash = true; resp->bootloader_hash.size = memory_bootloader_hash( resp->bootloader_hash.bytes); /* Settings for device */ if(storage_get_language()) { resp->has_language = true; strlcpy(resp->language, storage_get_language(), sizeof(resp->language)); } if(storage_get_label()) { resp->has_label = true; strlcpy(resp->label, storage_get_label(), sizeof(resp->label)); } /* Coin type support */ resp->coins_count = COINS_COUNT; memcpy(resp->coins, coins, COINS_COUNT * sizeof(CoinType)); /* Is device initialized? */ resp->has_initialized = true; resp->initialized = storage_is_initialized(); /* Are private keys imported */ resp->has_imported = true; resp->imported = storage_get_imported(); /* Cached pin and passphrase status */ resp->has_pin_cached = true; resp->pin_cached = session_is_pin_cached(); resp->has_passphrase_cached = true; resp->passphrase_cached = session_is_passphrase_cached(); msg_write(MessageType_MessageType_Features, resp); }