-
-
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 2 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
70 changes: 70 additions & 0 deletions
70
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,70 @@ | ||
--- | ||
title: 'Secure Boot' | ||
description: 'Learn how to use secure boot on the Arduino Portenta H7.' | ||
sebromero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tags: | ||
- Secure Boot | ||
author: 'Umberto Baldi' | ||
hardware: | ||
- hardware/04.pro/boards/portenta-h7 | ||
|
||
software: | ||
- ide-v1 | ||
- ide-v2 | ||
- cli | ||
--- | ||
|
||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Introduction | ||
This short tutorial will teach how to enable the secure boot on the Portenta H7, how to generate custom security keys, and how you can use them with MCUBoot bootloader. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## 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 Mbed OS Portenta Boards](https://github.com/arduino/ArduinoCore-mbed) version 3.0.0+ | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [imgtool](https://github.com/arduino/imgtool-packing/releases/latest) (optional) | ||
|
||
## Instructions | ||
|
||
### Flashing the Latest Bootloader | ||
In order to have secureboot enabled you have to update the bootloader and use [MCUBoot](https://www.mcuboot.com/). You can find more info on how to perform the update in [this other tutorial](../por-ard-bl/content.md). | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 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 addition layer of security. From now on it's 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). Otherwise the board will not start the compiled sketch because is not trusted. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
If no operation is performed the default security keys are used. | ||
sebromero marked this conversation as resolved.
Show resolved
Hide resolved
sebromero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
They are embedded in the example sketch `STM32H747_updateBootloader` that can be found in **Files > Examples > STM32H747_System > STM32H747_updateBootloader**. A private 256bit [ECDSA](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm) key is used for the encryption (`ecdsa-p256-encrypt-key.h`), while a public key is used for the signing (`ecdsa-p256-signing-key.h`). These two keys are the ones the bootloader uses to verify if a sketch is valid or not, before starting it. The default private keys used after compiling a sketch to sign and encrypt it, are located in `Arduino15/packages/arduino/hardware/mbed_portenta/<version>/libraries/MCUboot/default_keys/`. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 1. Generate Custom Cecurity Keys | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The default keys that comes with the mbed platform are obviously only intended for development purposes. In a production environment it's suggested to generate a new key pair (public and private key). | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This can be done with [**imgtool**](https://github.com/arduino/imgtool-packing/releases/latest). You can download and install it directly from the release section. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
***Pro tip: imgtool is already installed by the mbed platform and can be found in the `Arduino15/packages/arduino/tools/imgtool` directory.*** | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Remember to **save the keys in a secure place** and don't loose them. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 2. Upload the Custom Keys to the Board | ||
Once the keys have been generated they have to be uploaded on the Portenta. 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: | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
imgtool getpriv -k my-encrypt-keyfile.pem > ecsda-p256-encrypt-key.h | ||
imgtool getpub -k my-sign-keyfile.pem > ecsda-p256-signing-key.h | ||
``` | ||
|
||
Now you have to replace the keys in the sketch to update the bootloader(**STM32H747_updateBootloader**). | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
To do so just save the sketch to another location and replace the `ecsda-p256-encrypt-key.h` and `ecsda-p256-signing-key.h` files with the newly generated ones and then [update the bootloader](../por-ard-bl/content.md) again. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 3. Use the Custom Keys when Compiling | ||
Since the default keys have been changed in favour of newly generated custom ones, The new ones have to be used when compiling and uploading a sketch, because the compiled sketch is signed and encrypted with them. | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 ecsdsa-p256-signing-key.pem --encrypt-key ecsdsa-p256-encrypt-key.pem /home/user/Arduino/MySketch | ||
``` | ||
|
||
## Learn More | ||
If you want to implement secure boot for your platform [this](https://arduino.github.io/arduino-cli/latest/guides/secure-boot/) should be helpful . |
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.