Flash encryption with micropython and reflashing
Posted: Thu Oct 12, 2023 11:22 pm
Hi, I'm using flash encryption in a ESP32 board and with micropython project, which is based in ESP-IDF. I'm manually setting the following efuses in the board using espsecure.py:
FLASH_CRYPT_CONFIG 0xF
FLASH_CRYPT_CNT 0X1
DISABLE_DL_ENCRYPT 1
DISABLE_DL_DECRYPT 1
DISABLE_DL_CACHE 1
JTAG_DISABLE 1
And then I build the micropython firmware with my scripts as frozen codes and encrypt it with a pregenerated key using espsecure.py. After that, I write the encrypted firmware in the ESP32 using esptool.py.
I'm not using the reflashing option (see here) of the Flash encryption Development mode, bacause the efuse FLASH_CRYPT_CNT has just 7 bits so the board could be reflashed just 4 times, is it correct?
But I have realized that the micropython firmware has many partitions apart from app partition (factory): nvs, phy-init, and vfs. The way I'm using encrypt all of these partition, but the Flash encryption docs state that only bootloader, partition table, NVS Key Partition, Otadata, “app” type partitions (factory) and partitions marked with encrypted flag should be encrypted. So, nvs, phy-init, and vfs partitions shouldn't be encrypted, and even nvs partition doesn't support encrypted flag. Could this cause some troubles? Could it affect Wifi taking into account the calibration data is stored in the nvs partition?
With this configuration, could someone still stole and decrypt the firmware?
FLASH_CRYPT_CONFIG 0xF
FLASH_CRYPT_CNT 0X1
DISABLE_DL_ENCRYPT 1
DISABLE_DL_DECRYPT 1
DISABLE_DL_CACHE 1
JTAG_DISABLE 1
And then I build the micropython firmware with my scripts as frozen codes and encrypt it with a pregenerated key using espsecure.py. After that, I write the encrypted firmware in the ESP32 using esptool.py.
I'm not using the reflashing option (see here) of the Flash encryption Development mode, bacause the efuse FLASH_CRYPT_CNT has just 7 bits so the board could be reflashed just 4 times, is it correct?
But I have realized that the micropython firmware has many partitions apart from app partition (factory): nvs, phy-init, and vfs. The way I'm using encrypt all of these partition, but the Flash encryption docs state that only bootloader, partition table, NVS Key Partition, Otadata, “app” type partitions (factory) and partitions marked with encrypted flag should be encrypted. So, nvs, phy-init, and vfs partitions shouldn't be encrypted, and even nvs partition doesn't support encrypted flag. Could this cause some troubles? Could it affect Wifi taking into account the calibration data is stored in the nvs partition?
With this configuration, could someone still stole and decrypt the firmware?