Skip to content

Commit 398c5fa

Browse files
committed
secure boot tutorial
1 parent 4bae8f0 commit 398c5fa

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed
Loading
Loading
Loading

content/hardware/04.pro/boards/portenta-h7/tutorials/secure-boot/secure-boot.md

+43-16
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,63 @@ software:
1414
- cli
1515
---
1616
## Introduction
17-
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.
17+
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.
1818

1919
Secure boot is the process where a 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.
2020

2121
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.
2222

2323
## Hardware & Software Required
24-
- [Portenta H7](https://store.arduino.cc/portenta-h7)
25-
- Arduino IDE 1.8.19+ or Arduino IDE 2.0-rc5+ (https://www.arduino.cc/en/software)
26-
- [Arduino Core for mbed enabled devices](https://github.com/arduino/ArduinoCore-mbed) version 3.1.0+
27-
- [imgtool](https://github.com/arduino/imgtool-packing/releases/latest) (optional)
24+
25+
- [Portenta H7](https://store.arduino.cc/portenta-h7)
26+
- [Arduino IDE 2.0+](https://www.arduino.cc/en/software)
27+
- [Arduino Core for mbed enabled devices](https://github.com/arduino/ArduinoCore-mbed) version 3.1.0+
28+
- [imgtool](https://github.com/arduino/imgtool-packing/releases/latest) (optional)
2829

2930
## Instructions
3031

3132
### Flashing the Latest Bootloader
32-
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).
33+
34+
In order to enable the secure boot, you must **update** the bootloader on your Portenta H7. 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).
35+
36+
Once the bootloader has been updated, it is 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.
3337

3438
### Use Default Security Keys
35-
Once the bootloader has been updated to MCUboot, it is 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.
3639

37-
If the security keys are not overridden, the default ones are used.
38-
Two keys are embedded in the example sketch `STM32H747_manageBootloader`, which can be found in **Files > Examples > STM32H747_System > STM32H747_manageBootloader** and used by the bootloader.
39-
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`).
40+
Upload the `enableSecurity` example sketch that can be found under **File > Examples > MCUboot** in the IDE upper menu.
41+
42+
![enableSecurity sketch](assets/sketch.png)
43+
44+
Two keys are embedded in the example sketch:
45+
46+
- 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-key.h`).
47+
- A public key is used for image verification (`ecdsa-p256-signing-key.h`).
48+
49+
***If the security keys are not overridden, the default ones are used. The default keys are in `C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\<x.x.x>\libraries\MCUboot\default_keys.`***
50+
51+
In the *Serial Monitor* you will be asked for confirmation to load the default keys. Enter `Y` to confirm, `n` to abort.
4052

41-
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.
53+
![Confirmation to load default keys](assets/load.png)
54+
55+
Finally, wait for the keys to be loaded. In the *Serial Monitor* you will see a message saying: *Security features enabled. It's now safe to reboot or disconnect your board.*
56+
57+
From that point on, you must configure your future sketches **Security setting** to **Signature + Encryption** (the option can be found under **Tools > Security settings** in the IDE when selecting *Portenta H7* as board, or use `--board-options security=sien` if working with the Arduino CLI).
58+
59+
![Security setting on Portenta H7](assets/setting.png)
60+
61+
***Not configuring this setting will cause the bootloader not to run the compiled sketch because it is not trusted.***
4262

4363
### 1. Generate Custom Security Keys
4464
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).
4565
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).
4666

47-
***`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.***
67+
***`imgtool` is already installed by the mbed platform.***
68+
69+
The tool can be found in:
70+
71+
- `%LOCALAPPDATA%\Arduino15\packages\arduino\tools\imgtool` on Windows.
72+
- `~/.arduino15/packages/arduino/tools/imgtool` on Linux.
73+
- `~/Library/Arduino15/packages/arduino/tools/imgtool` on macOS.
4874

4975
To generate the new keys you can use this command line:
5076

@@ -64,18 +90,19 @@ imgtool getpriv -k my-encrypt-keyfile.pem > ecsda-p256-encrypt-priv-key.h
6490
imgtool getpub -k my-sign-keyfile.pem > ecsda-p256-signing-pub-key.h
6591
```
6692

67-
Now you have to replace the keys inside the Sketch to update the bootloader(**STM32H747_manageBootloader**).
68-
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.
93+
Now you have to replace the keys inside the `enableSecurity` sketch found under **File > Examples > MCUboot** in the IDE upper menu.
94+
95+
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 upload the sketch again.
6996

7097
***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.***
7198

7299
### 3. Use the Custom Keys when Compiling
73100
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.
74101

75-
To override the security keys used during the compile, you have to use the Arduino CLI and specify the keys with:
102+
To override the security keys used during the compilation, you have to use the Arduino CLI and specify the keys with:
76103

77104
```bash
78-
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
105+
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 <directory-of-sketch-to-compile>
79106
```
80107

81108
## Learn More

0 commit comments

Comments
 (0)