-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
Support secure boot and flash encryption #305
Comments
I am also interested in this function! |
I am casting my vote for this feature as well. (+1) |
+1 here too - would be great to have it added. In the meantime though it's possible (although a bit fiddly) to get it to work by creating a bootloader in a ESP-IDF project and flashing it to your ESP32. Then you can compile your PIO project, sign the firmware.bin using espsecure.py and flash it using esptool.py. I've only tried it with WITHOUT hardware secure boot but can't see a reason why that couldn't be made to work too. Obviously you need to make sure you don't use the PIO upload as this will overwrite to bootloader. If there is interest, and proper implementation in PIO is a way off I could probably write up some instructions. |
@robertpoll Did you also try to flash a ota sketch? In that case it could be possible to flash it again via arduino ide? |
I did use the same partition table in PIO and esp-idf although I suspect that they may not have to be the same as the partition table gets flashed to the ESP32 when you download the firmware. I'll run a test though as it's an interesting question. This is the partition table I used:
The partitions are set up for OTA as you can see although I've only tested serial flashing at the moment. My interest is OTA from an HTTP server for production updates rather than for development - I don't use Arduino IDE but will test that too if that's what you're interested in..? |
Just run a quick test with the ArduinoOTA library and it seems to work (I used the OTAWebUpdater example but with the Arduino IDE 1.8.12) and a bootloader built with the partition table above (which is different form the Arduino one). @Nexus1212 is this what you're aiming to do? |
Hello robertpoll,
The reaseon is the new data, created by ota update in the partition "app1", are not encrypted. That means, ota via arduino ide or plattfomIO wirte the data in planetext in the flash... Did you uptade the esp via OTA with a preencypted app over your OTAWEbUpdater? Btw.: I found allready out it is possible to flash ota with PIO. Arduino ide is no needed....
We can try to flash with plattformIO a sketch with supported OTA update and the changed bootloader. After flashing the esp32 chip should encrypt and sign the bootloader and applikation. Updates are possible over ota. What do you think?
|
Just a minor point, it's signed and not encrypted. I haven't looked at the flash encryption option at this point but presumably that's possible too.
I think this should work well where you want to push firmware updates infrequently. If you're trying to use as part of a development process it might be a bit cumbersome....? |
If I choose the firmware in the "serverIndex"-Page and push the "update" Button I get the errormeassage on serial monitor:
The firmware is in plaintext, created by PIO (E:\Eigene Dateien\Documents\PlatformIO\Projects\OTA Web Update.pio\build\esp32dev). Is there a hint? I created with "esptool.py --port COM7 -b 921600 read_flash" a dump of the flash and checked with a Hex-Editor it. The data on app0 are encrypted, the data on app1 are in planetext. I think it is required to pre-encrypt the firmware for ota flasching. But if I try it, it does not work :(
I used this command for the pre-encryption: Could please anyone help me?
|
Hello robertpoll, Please have a look on my steps and tell me if there is anything wrong:
The only different what I see is, you use ardnino ide. But I think that is not the reason? |
Hi @Nexus1212 My example that was working was for signed firmware/OTA without flash encryption - apologies for the confusion. I've just tried ArduinoOTA on a flash encrypted ESP and it also doesn't work. The docs seem to indicate that the default is that you don't encrypt the firmware before sending via OTA - remember that the encryption key is created on the ESP the first time you flash it (in eFuse BLK1), so you won't know it. The firmware gets encrypted by the ESP once it gets there. The docs say:
Seems like there are the following options:
Let me know what you think - I should be able to test option 3 today. |
Thank you for your replay :)
|
Just one other thing though, depending on your security requirements, the OTAUpdater as is uses http not https so the unencrypted firmware goes across the wire so it's only protected once it gets to your device. |
Hi,
I was about to submit a pull request to see if they are willing to incorporate the changes - there's an argument that it's an incomplete solution so that may not happen but worth having the discussion. I notice though that there's another PR in to do the same thing, although it looks to me as if it has a problem with the re-writing of the magic byte. Anyway, in the meantime you're welcome to use the version below - Caveat Emptor but if you do then please let me know how it goes, and if you have any problems. |
Hello robertpoll, I have a lot of new ESP32. Please tell me what exact should I test? I encypted allready a ESP32, burned a key and flashed the ota example. I tested with your new update-lib the ota example again and it works now :) Now it is poosible to flash a new firmware in planetext on a encrypted esp via ota! Thats great! I hope they accapt your pull request. Could you send me the link to the pull request? I want to track the status :) I tested also to flash a encrypted firmware. That does not work, because the wrong magic byte is detected. Do you mean it makes sense, to deactivate the check for the first byte bevor flashing? Best regards :) |
Hold off on the testing - you're right about the issue with the magic byte checking for flashing pre-encrypted firmware. Turning it off won't work with my changes as it will get re-encrypted. It's not possible for Updater.cpp to automatically tell whether it's dealing with encrypted firmware so maybe an option to turn off the checking and save directly even if the partition is marked as encrypted. It means changing ArduinoOTA to add the option. Great that the change is working for you - I'll look at the above before submitting the PR, but will let you know when I do. |
I found another problem: Spiff does not work right. The problem is in the "wifiClient.cpp"
If encryption is active, "available = stream.available();" becomes never "0" and ends in an endless loop. I think the reason is a problem in the encryption? I am not sure how the "Stream-available" Function work: |
I've just tested basic SPIFFS here with the new Updater.cpp and it seems OK. Are you running an encrypted SPIFFS partition? Also are you updating your SPIFFS OTA or have you just flashed it over serial? |
No, the Spiff partition is not entcrypted. It is possible to use spiff, but only the stream function does not work... |
I think all SPIFFS file access is via streams - could you put together a little example for me that I can test. Also let me know what versions of Arduino and ESP-IDF you're using. Presumably this isn't related to the Updater changes - so it doesn't work with the unmodified libraries either? |
Short exampel:
index.html (put the file in "data"):
Case 1: Case 2: I am using the newest PIO version:
ESP-IDF: |
Just tested this and it's working for me on the ESP with encrypted boot. Is your PIO project using the same partition table that you used for the esp-idf project that you used to create/flash the encrypted bootloader? I'm using the same PIO version as you, and the latest esp-idf. |
The partition table was not the same! I used in esp-idf your table and in PIO the default.csv... I forget to change it... Sorry! OK, now Spiff works! Thank you! I tested both ota sketches with firmware in plainetext. Both are working (spiff, encrypted preferences, wifi, webserver, websocket and many other libs... ). All works great AND not more slowlier... The last nice feature is a possibility to flash pre-encrypted firmware via OTA ^^ Do you see a solution for it? :) |
Taking a step back - if the objective is to protect the firmware on its way to the ESP then probably using HTTPS is a better option. There's a HTTTPS web server here that is probably worth a look. |
Yes, it depends on the location in flash. A solution could to provide always two ota firmware-updates (one for each ota partition) and the esp pick the right one in dependence which patition on the esp is currently active :) |
It would be great to see flash encryption as a feature in PlatformIO! Other things like encrypting the NVS also rely on this feature. The fact that encryption can be circumvented (with considerable effort by a pro) should not discourage developers from using it, since it's still better to have some level of security as opposed to none. |
Any updates on this? |
any update? |
Another 👍 vote |
any update? |
I also needed to do OTA updates with flash encryption and updater.cpp would corrupt the update. I downloaded robertpoll's updater.cpp above and it solved the problem. It would be nice to see flash encryption as a PIO update........any news on this? |
Another 👍 vote |
one more ! we really need a tutorial for this 👍 |
As I stated above, I am able to use Robert Poll's updater.cpp to load firmware over OTA. One thing that caught me is I forgot to enable flash encryption on boot, and in this case the updater can't even get started. So make sure to enable it in menuconfig. This would not be secure if the download is over an unencrypted http server. So, I connect with https using WiFiClientSecure, defining it as |
What's the latest on secure boot from PIO's espidf framework? |
Looking forward for updates in this topic! |
Years later, I still looking this feature in PI for some project base on Arduino. |
just hopefully nudging this |
Happy new year folks! Its been half a decade so far! It was a pleasure to participate on this topic with you all! See you guys on 2030! |
Yea, we will send humans to Mars before this feature get released, you bet! |
There will probably no new feature to espressif stuff added. See #1225 |
Now only ESP-IDF support secure boot and flash encryption: https://esp32.com/viewtopic.php?t=10029
Please add support for it in platformio
The text was updated successfully, but these errors were encountered: