I have a very specific question, the company where I work is finishing a project and going to mass production.
The production is in China (and we are from another country), so the first firmware for the ESP32 will be pass in a factory on China by a test jig. After the first boot (yet at the factory) the calibration parameters will be recorded in the flash (by NVS).
And for security purposes we need to encrypt the flash and disable "UART Bootloader Encryption/Decryption", as described here: Flash Encryption Initialisation
Ok, this works fine, but now comes the question, how can I ensure that the Flash Encryption Key stored in the eFUSE (Block 1) was randomly generated (by the inner firmware)?
Why this questions?
Well, "assuming a situation where the manufacturer may have bad intentions" (we don't expect this, but is always good to be 100% safe), they can use the follow commands:
Code: Select all
python $IDF_PATH/components/esptool_py/esptool/espsecure.py generate_flash_encryption_key flash_encryption_key.bin
python $IDF_PATH/components/esptool_py/esptool/espefuse.py burn_key flash_encryption flash_encryption_key.bin
So, digging inside the esp-idf and flash encryption I found this lib: bootloader_utility.c
And in this lib (that makes part of the bootloader) I found the part that checks the flash encryption:
Code: Select all
#ifdef CONFIG_FLASH_ENCRYPTION_ENABLED
/* encrypt flash */
ESP_LOGI(TAG, "Checking flash encryption...");
bool flash_encryption_enabled = esp_flash_encryption_enabled();
err = esp_flash_encrypt_check_and_update();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Flash encryption check failed (%d).", err);
return;
}
if (!flash_encryption_enabled && esp_flash_encryption_enabled()) {
/* Flash encryption was just enabled for the first time,
so issue a system reset to ensure flash encryption
cache resets properly */
ESP_LOGI(TAG, "Resetting with flash encryption enabled...");
bootloader_reset();
}
#endif
flash_encrypt.c
esp_flash_encrypt.h
So I'm forgetting something? Have another way or a eFuse that can help me with this question?
I hope that I have been able to explain the entire situation!