-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flash Encryption (FLASH_CRYPT_CNT) #1387
Comments
See my instructions in #1142 |
Is it possible to set the fuses for the flash encryption in arduino or maybe with the espefuse.py script, and then compile and upload my sketch with arduino ? |
OK i have now changed the sdkconfig in the "make menuconfig". this new sdkconfig i copied into: |
Next Try: Can you help me please to get the "flash encryption on boot" running ? |
You enable encryption by running |
yes i read the documentation veeeery often :) |
Getting error 1000 seems like some progress. Follow the serial reflashing procedure from that point and see if it will encrypt on its own. |
Ok I tried it like you said but, it seems just like i broke another esp32 board ⚡️ #1 "make menuconfig" -> "sercurity options" -> "enable flash encryption on boot" #2 "make flash" (at this point, a normal ESP-IDF example got encrypted, but not the "arduino-esp32" as an esp-idf component ) #3 burned the efuse manually by using script espefuse.py #4 I got the error 1000... #5 Burn the FLASH_CRYPT_CNT efuse again with the python script #6 this time i put some code inside my arduino sketch which will figure out if hardware encyption is enabled or not... the answer is, it is not enabled. It is disabled. #7 Now, I reset the device, and the documentation says, it will re-encrypt plaintext partitions. #8 The flash is not encrypted, but the esp32 board trys to decrypt it, ending up with "Err 100" again. |
The point is, i think if In normal |
Next try: I took a new ESP32 board and tried the #1 flashed my sketch in plain text. #2 generated the key and burned it to the esp32 #3 Followed the instructions.... #4 Strange things happend: Read_disable and write_disable became set, but the flash "encryption on boot" did not work again, even with the pregenerated key. Flash encryption is still disabled. Next, I will try the "reflash pregenrated key procedure"... |
Um, Ok. Then don't do that. Just flash the esp-idf OTA example with the encryption turned on. Then you can put whatever you want on there. There may very well be something in the arduino-esp32 code that overrides the sdkconfig setting, and that is probably a reasonable security feature to keep people that don't understand the consequences from bricking their devices. |
Success ! #1 Generated the flash Encryption Key and burned it to the ESP32 board #2 check if the RD_Dis and WR_Dis have changed after BURN the key (before burn they are 0, after burn they must look like on this picture : 3# Use a NORMAL "ESP-IDF" example like #4 after openning serial monitor I had "Err 1000", so I flashed it again. Then the error was gone and my the Hello_world example was running on the board #5 Then check the FLASH_CRYPT_CNT counter it must be 1 now because the in my example i added some code to make the firmware check if the encryption is working: serial monitor shows, encryption is working: So far so good, esp-idf flash encryption worked out with our own flash encryption key, which we stored on our PC. Now lets make the #6 this time in this project I DISABLED "encryption on boot" #7 make the project. Now the will be a .bin file in the project folder like this : #8 encrypt this .bin file of the project with our own generated encryption-key by using the espsecure.py script : #9 Flash the encrypted .bin File to the ESP-32 Board by using the esptool.py script. #10 Check out the FLASH_CRYPT_CNT with #11 The 🥇 🍦 ⚡️ |
If i use Arduino-IDE to compile and upload my arduino-esp32 sketch, in which directory can i find the I am asking, because I wanna try to encrypt that file directly without using the arduino as an idf component. |
If you turn on verbose output during compilation in the preferences, you will see the location in a few places. I really think flashing a basic OTA + CONFIG_FLASH_ENCRYPTION_ENABLED firmware and then having the devices connect to a rpi/esp set up as an AP/webserver will be easier and mass repeatable. You could also get a list of mac addresses that way. |
Today I took the .bin file which was compiled by Flashed the .bin file into the esp-board with esptool.py Is it possible to use SPIFFS when the flash encryption is enabled ? |
@Buffalchill that is probably the only way that flash encryption will be available for Arduino users. Since it's not for everyone and could cause any novice an issue, it would require you to run Arduino as IDF component. SPIFFS does not run on encrypted flash ;) FATFS does |
I don't know whether the partition table has been encrypted or not, but maybe you initially uploaded a partition table without spiffs? Maybe it just needs a format (though that should give you a different error)? Here's some quick code to show the spiffs location:
|
Ibernstone i tried your code. Thank you for that! |
Well, there certainly is a partition table, just no spiffs partition. Try running |
Ya i got something but its not plain text :)
If i wanna flash the partition table only as a bin file, I guess the the adress is 0x8000 ? and Where in the project folder do i find the partition table file ? |
There are a few available at https://github.com/espressif/arduino-esp32/tree/master/tools/partitions and the doco is at http://esp-idf.readthedocs.io/en/latest/api-guides/partition-tables.html. NB at the very bottom it mentions that |
So far thank you for your help 👍 |
Bringing in another comment from gitter for reference. Buffalchill @Buffalchill lbernstone @lbernstone |
Today i tried to use the NVS ( Preferences ) ...
|
@me-no-dev are you sure that spiffs don't work when flash encryption is enabled ? |
I got the error 1000... rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) Burn the FLASH_CRYPT_CNT efuse again with the python script getting error : A fatal error occurred : Efuse FLASH_ENCRYPT_CNT failed to burn. Protected?
|
Hi Buffalchill, thanks a lot for your explanation on encryption and re-flashing, just one silly question because I don't know c and don't seem to be lucky googling for this one : what library(ies) do I have to include in order to use esp_flash_encryption_enabled() in my code and also how do I declare it so I can use it? Thanks in advance |
Assuming the bootloader is recompiled from the ELF in 2.0.6 and newer, I wonder if just uncommenting the "CONFIG_SECURE_FLASH_ENC_ENABLED" line would do the trick... |
The loader DEFINITELY DOES NOT RECOMPILATE!!! The file date does not change. I just replace the bootloader_dio_80m.elf file with the one that created the idf. |
Yeah, the ELF won't...but the output BIN will. |
If arduino wants to create a bin file every time - ok. For encryption, just replace bootloader_dio_80m.elf |
Webdust, did you make the shift memory for the encrypted bootloader? |
Huh? As detailed much further above, all I did was enable encryption in the bootloader, and then swap out the Arduino bootloader file for the encrypted one. |
Yes. That's what I was asking about. What log settings did you set? |
I believe I had to set it to "none" to make the bootloader fit. Honestly, it was 3 years ago I was digging into this stuff, so I really don't recall! And thanks to Git context nonsense of ESP-IDF, there's almost zero chance I'll be able to pull up the old settings and find out what I did. |
ONLY FOR 16MB ESP32!!! |
ONLY FOR 4MB ESP32!!! |
Unless I'm mistaken, the partition table shouldn't affect the bootloader file. |
My board didn't work until I specified the partition table in menuconfig. Perhaps the elf file contains this information. |
@PilnyTomas Also this, can be explained in FAQ and closed. |
is there anyway to debrick ecnrypted esp32? like reading the previous working encrypted firmware then manually flashing it later? |
Hi all. I was puzzled by the encryption issue in Arduino. As far as I understand, it is enough to build the bootloader with encryption support from the idf, limited by the functionality so that it fits into its partition. |
Once the flash is encrypted, all writes to the ota partitions (the firmware), will be encrypted. So, OTA becomes the only way to update in release mode. |
So yes, above I noted that the Arduino-ESP32 core's OTA routines were using the only function that didn't support encrypted FLASH--however, I believe this has been fixed for some time in the Arduino-ESP32 core. And as @lbernstone points out, OTA is the only way to update an encrypted ESP32. FYI you'll need to generate an ESP32-S2 bootloader via ESP-IDF, with encryption enabled. The bootloader binaries provided above were for the original ESP32, and I'm almost certain they won't work on the ESP32-S2 (or ESP32-S3 for that matter). |
Thank you! I researched the topic and realized that there was a problem with the standard OTA using the ESP.flash* procedures, which was fixed and now the OTA works well with an encrypted flash, when using the appropriate bootloader. |
Yes, I understand, while this is a problem, espidf does not support win7. I'll try to persuade friends on win10 to help me :) |
Make a linux vm. It'll perform better anyhow. |
Hi All, on the ESP32-S3 I enabled Flash Encryption and Secure Boot v2 by flashing the ESP-IDF generated bootloader and signing the Arduino generated binary
I get no Error if I use the ESP-IDF compiled binary |
Hello. I also want to try encryption through bootloader substitution, I have Esp32-S2 lolin mini. I can't get an encrypted bootloader, I have win7 and idf doesn't want to install. Are you unable to download the encrypted bootloader, development and release version for me? As far as I understand, there is no need to sign the binaries, a regular file is served and the bootloader already encrypts it. |
I quoted this as it is important to be aware. Issue already solved, the user was able to make it work. |
Hardware:
Board: ESP32 Dev Module
Core Installation/update date: 11/jul/2017
IDE name: Arduino IDE 1.8.3.
Flash Frequency: 40Mhz
Upload Speed: 115200
Hi,
I'm trying to enable Flash Encryption.
The ESP IDF documentation says (http://esp-idf.readthedocs.io/en/latest/security/flash-encryption.html)
how is this possible in Arduino IDE ?
The text was updated successfully, but these errors were encountered: