-
-
Notifications
You must be signed in to change notification settings - Fork 440
Portenta H7 tutorial: Secure Boot [PC-894] #129
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
507b700
add secure boot for portenta h7
umbynos 2a220eb
other portent boards are not yet supported
umbynos 0c81eb4
Apply suggestions from code review
umbynos aa7fbee
Better explain where to find imgtool on different OS
umbynos efcc9a5
Apply suggestions from code review
umbynos c0da15d
Apply suggestions from code review
umbynos 49c15cf
Add symlinks on the compatible boards
marqdevx af3d86d
Apply suggestions from code review
umbynos 589863c
Apply suggestions from code review
umbynos d21590e
add a paragraph in the Intro explaining what secure boot is
umbynos 567a4b4
followup of https://github.com/arduino/arduino-cli/pull/1716
umbynos 559cb89
Swap keys
sebromero 4bb3917
Rephrase security keys statement
sebromero 7db071b
Fix typo
sebromero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
content/hardware/04.pro/boards/portenta-h7-lite-connected/tutorials/secureboot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../portenta-h7/tutorials/secure-boot |
1 change: 1 addition & 0 deletions
1
content/hardware/04.pro/boards/portenta-h7-lite/tutorials/secureboot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../portenta-h7/tutorials/secure-boot |
78 changes: 78 additions & 0 deletions
78
content/hardware/04.pro/boards/portenta-h7/tutorials/secure-boot/secure-boot.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: 'Secure Boot on Portenta H7' | ||
description: 'Learn how to use secure boot on the Arduino Portenta H7.' | ||
tags: | ||
- Secure Boot | ||
author: 'Umberto Baldi' | ||
hardware: | ||
- hardware/04.pro/boards/portenta-h7 | ||
|
||
software: | ||
- ide-v1 | ||
- ide-v2 | ||
- cli | ||
--- | ||
## Introduction | ||
This short tutorial will guide the user through enabling the secure boot on the Portenta H7, generating custom security keys, and using them with the MCUboot bootloader. | ||
|
||
Secure boot is the process where compiled sketch is authenticated against the hardware before it is authorized to be used in the boot process. The hardware is pre-configured to authenticate code using trusted security credentials. | ||
|
||
In other words, secure boot ensures that the boot technology and operating system software are the legitimate manufacturer version and have not been altered or tampered with by any malicious actor or process. | ||
|
||
## Hardware & Software Required | ||
jhansson-ard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [Portenta H7](https://store.arduino.cc/portenta-h7) | ||
- Arduino IDE 1.8.19+ or Arduino IDE 2.0.0-rc5+ (https://www.arduino.cc/en/software) | ||
- [Arduino Core for mbed enabled devices](https://github.com/arduino/ArduinoCore-mbed) version 3.0.0+ | ||
- [imgtool](https://github.com/arduino/imgtool-packing/releases/latest) (optional) | ||
|
||
## Instructions | ||
|
||
### Flashing the Latest Bootloader | ||
In order to have secure boot enabled you must update the bootloader on your Portenta H7 and use [MCUboot](https://www.mcuboot.com/). You can find more info on how to perform the update in [this other tutorial](https://docs.arduino.cc/tutorials/portenta-h7/updating-the-bootloader). | ||
|
||
### Use Default Security Keys | ||
Once The bootloader has been updated to MCUboot, it's possible to use [secure boot](https://www.keyfactor.com/blog/what-is-secure-boot-its-where-iot-security-starts/) to have an additional layer of security. From that point on it is required to upload a compiled sketch with the Custom Board Option **"Security settings"** set to **"Signature + Encryption"** (the option can be found under **Tools > Security settings** in the IDE when selecting Portenta H7 as board, or you can use `--board-options security=sien` if using the Arduino CLI). Failing to provide such option will cause the bootloader not to run the compiled sketch because it is not trusted. | ||
|
||
If the security keys are not overridden, the default ones are used. | ||
Two keys are embedded in the example sketch `STM32H747_updateBootloader` which can be found in **Files > Examples > STM32H747_System > STM32H747_updateBootloader** and used by the bootloader. | ||
A private 256bit [ECDSA](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm) key is used to extract the encryption key and decrypt the binary update (`ecdsa-p256-encrypt-priv-key.h`), while a public key is used for image verification (`ecdsa-p256-signing-pub-key.h`). | ||
|
||
As counterpart, when building the image update, imgtool uses this private [key](https://github.com/arduino/ArduinoCore-mbed/pull/447/files#diff-f43e4850d60c61854678f6f80c6ddc4b59e3e68ca7e71b02e5ed15288c9aadb4) to sign the image and this public [key](https://github.com/arduino/ArduinoCore-mbed/pull/447/files#diff-95bb7b27de14276896a2bec099dc5a498d5332616458c04263efc8d24810e6a6) for image encryption with elliptic curve integrated encryption scheme. | ||
|
||
### 1. Generate Custom Security Keys | ||
The default keys provided with the mbed platform are obviously only intended for development purposes. In a production environment it is strongly recommended to generate a new key pair (public and private key). | ||
This can be done with **imgtool**. You can download and install it directly from the [release section](https://github.com/arduino/imgtool-packing/releases/latest). | ||
|
||
***`imgtool` is already installed by the mbed platform and can be found in the `%LOCALAPPDATA%\Arduino15\packages\arduino\tools\imgtool` directory on Windows, in `~/.arduino15/packages/arduino/tools/imgtool` on Linux and in `~/Library/Arduino15/packages/arduino/tools/imgtool` on macOS.*** | ||
|
||
To generate the new keys you can use this command line: | ||
``` | ||
imgtool keygen --key my-sign-keyfile.pem -t ecdsa-p256 | ||
imgtool keygen --key my-encrypt-keyfile.pem -t ecdsa-p256 | ||
``` | ||
This command line will generate two private PEM encoded security keys and save them in the current directory with `my-sign-keyfile.pem` and `my-encrypt-keyfile.pem` names. The algorithm used to generate the keys is ECDSA 256bit. | ||
|
||
Remember to **save the keys and keep them in a secure location** and not to lose them. | ||
|
||
### 2. Upload the Custom Keys to the Board | ||
Once the keys have been generated they have to be uploaded to the Portenta H7. This procedure has to be done only once, because it's persistent. To extract the public\private key and encode it in to a "C" byte array inside a `.h` header file you can use: | ||
``` | ||
imgtool getpriv -k my-encrypt-keyfile.pem > ecsda-p256-encrypt-priv-key.h | ||
imgtool getpub -k my-sign-keyfile.pem > ecsda-p256-signing-pub-key.h | ||
``` | ||
|
||
Now you have to replace the keys inside the Sketch to update the bootloader(**STM32H747_updateBootloader**). | ||
To do so just save the sketch to another location and replace the `ecsda-p256-encrypt-priv-key.h` and `ecsda-p256-signing-pub-key.h` files with the newly generated ones and then [update the bootloader](https://docs.arduino.cc/tutorials/portenta-h7/updating-the-bootloader) again. | ||
|
||
***NOTE: In case the keys are compromised, this process can be performed again with a new set of keys, but any firmware signed with the previous pair will no longer work.*** | ||
|
||
### 3. Use the Custom Keys when Compiling | ||
Since the default keys have been changed in favour of custom generated ones, the new ones have to be used when compiling and uploading a sketch, because the compiled sketch is signed and encrypted using such keys. | ||
|
||
To override the security keys used during the compile you have to use the Arduino CLI and specify the keys with: | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
arduino-cli compile -b arduino:mbed_portenta:envie_m7 --board-options security=sien --keys-keychain <path-to-your-keys> --sign-key ecdsa-p256-signing-priv-key.pem --encrypt-key ecdsa-p256-encrypt-pub-key.pem /home/user/Arduino/MySketch | ||
``` | ||
|
||
## Learn More | ||
If you want to implement secure boot for your platform have a look at [this article] (https://arduino.github.io/arduino-cli/latest/guides/secure-boot/). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.