-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
update NVS encryption docs to note that post flash encryption writing nvs_key with parttool.py must include --esptool-write-args encrypt flag #8196
Comments
There should not be any problem using compression before flash encryption is enabled, the bootloader, partition table, and the app partitions get flashed with compression before they are encrypted. |
I can try it again, but when I followed the steps in that link and wrote all those partitions in plaintext, the pre-encrypted NVS partition was not readable on the ESP32C3 device. And IIRC the Wi-Fi provisioning manager also could not read the default NVS partition and needed to be re-provisioned. Will try again today and reply. |
Note that Nvs partitions should not be marked as encrypted in your partition table, only nvs key partitions. |
Thanks, I do not have the NVS partition itself marked encrypted. But I tried it again, and it worked as documented. Hard to say what went wrong the first few tries... Perhaps I had not rebuilt .bin files or something. Either way, I'd still suggest that the docs are updated to note that in developer mode and post flash encyption, you can still update keys but must include If you don't include that flag the write appears to work (no errors or warnings about writing to an encrypted partition), but the data is corrupted, and the key won't decrypt a pre-generated NVS encrypted partition. I updated the title to reflect that suggestion. |
@bschick Sorry for the issue in the documentation, I'm taking a look right now and connecting a few things already. |
@bschick I'll add some note to the documentation. I could reproduce your issue almost entirely. The only difference is that I didn't see |
Hi @0xjakob $ parttool.py --esptool-write-args encrypt --port /dev/ttyUSB0 --partition-table-file=build/partition_table/partition-table.bin --partition-table-offset 0x8000 write_partition --partition-name="nvs_key" --input keys/my_nvs_key_partition_file.bin A fatal error occurred: Active security features detected, erasing flash is disabled as a safety measure. Use --force to override, please use with caution, otherwise it may brick your device! |
Hi @AxelLin!
Could you try this way? |
Above command works, thanks. It's a big surprise if copy-paste the command from document does not work. |
Environment
Problem Description
I am creating a separate encrypted NVS partition with pre-generated keys (in development flash encyption) following the directions here:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/storage/nvs_flash.html#nvs-key-partition
I had uploaded the nvs_key partition with this template:
parttool.py --port /dev/ttyUSB0 --partition-table-offset "nvs_key partition offset" write_partition --partition-name="name of nvs_key partition" --input "nvs_key partition"
Also uploaded the encrypted custom NVS partition. But after enabling flash encryption and letting the bootloader encrypt appropriate partitions and initializing the custom partition with nvs_flash_secure_init_partition, opening the partition with a call like the following always returns ESP_ERR_NVS_NOT_FOUND.
nvs_open_from_partition("customer", "id", NVS_READONLY, &nvs_handle));
After much tinkering and reading esptool.py source, I found that you cannot use compression to upload encrypted partitions. This seems to matter whether you write the partition before or after flash encryption is applied. Before flash encryption is enabled, I assume you'd need to disable compression by adding the following to the parttool.py command (I have not tested this)
--esptool-write-args no-compress
What I did test and validate is that post flash encryption you must use the --encrypt flag for esptool.py. Adding the following to parttool.py does that and allows the pre-encrypted NVS partition to be opened and read:
--esptool-write-args encrypt
Proposed Change
Edit the docs so the parttool.py "template" command for pre-generated keys includes the esptool no-compress flag when run before flash encryption is applied (I have not validated this works, but I know it fails without):
parttool.py --esptool-write-args no-compress --port /dev/ttyUSB0 --partition-table-offset "nvs_key partition offset" write_partition --partition-name="name of nvs_key partition" --input "nvs_key partition"
Also add a description to the docs about writing nvs_key in developer mode after flash encryption is applied (I have validated this works, and I know corrupts the keys without):
parttool.py --esptool-write-args encrypt --port /dev/ttyUSB0 --partition-table-offset "nvs_key partition offset" write_partition --partition-name="name of nvs_key partition" --input "nvs_key partition"
The text was updated successfully, but these errors were encountered: