-
-
Notifications
You must be signed in to change notification settings - Fork 404
Add secure boot support for compile command. #1686
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
20 commits
Select commit
Hold shift + click to select a range
04b8d5c
add flags to allow the override of the keys used to sign and encrypt …
umbynos 3a8972f
add integration test for ReplaceSecurityKeys() function
umbynos 35294ce
fix regression introduced: target platform could be nil so using befo…
umbynos 50cc358
apply suggestions from code review
umbynos 04a41e7
rename of some flags (done to accommodate the proposed changes in pla…
umbynos e96fc18
change approach: override keys using `builderCtx.CustomBuildProperties`
umbynos 900c0e1
add check in the builder regarding the usage of "build.keys.type" pro…
umbynos 87a19ea
add secure boot to the platform specifications
umbynos dd05e7d
Apply suggestions from code review
umbynos 583dd9c
modify the check on in the builder regarding the usage of "build.keys…
umbynos 33e4c0d
remove check on the flags specifying the keys, it's the tool responsi…
umbynos 6262cfa
move content to a guides section
umbynos 2ed7002
add specifications regarding `build.keys` properties
umbynos 06f4beb
Apply suggestions from code review
umbynos c18bbca
add link to external resource to provide a quick explanation of the r…
umbynos 3510509
change `tools.imgtool.build.pattern` to `tools.imgtool.flags`
umbynos 1d2e03e
add small section explaining why is recommended to use these prop names
umbynos 47c3917
Apply suggestions from code review
umbynos d480ae5
Correct error message
umbynos c40e6cb
Apply suggestions from code review
umbynos 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
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
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
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
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,67 @@ | ||
# Secure Boot | ||
|
||
A ["secure boot"](https://www.keyfactor.com/blog/what-is-secure-boot-its-where-iot-security-starts/) capability may be | ||
offered by Arduino boards platforms. | ||
|
||
The compiled sketch is signed and encrypted by a [tool](../platform-specification.md#tools) before being flashed to the | ||
target board. The bootloader of the board is then responsible for starting the compiled sketch only if the matching keys | ||
are used. | ||
|
||
To be able to correctly carry out all the operations at the end of the build we can leverage the | ||
[post build hooks](../platform-specification.md#pre-and-post-build-hooks-since-arduino-ide-165) to sign and encrypt a | ||
binary by using `recipe.hooks.objcopy.postobjcopy.NUMBER.pattern` key in | ||
[`platform.txt`](../platform-specification.md#platformtxt). The security keys used are defined in the | ||
[`boards.txt`](../platform-specification.md#boardstxt) file, this way there could be different keys for different | ||
boards. | ||
|
||
``` | ||
[...] | ||
## Create secure image (bin file) | ||
recipe.hooks.objcopy.postobjcopy.1.pattern={build.postbuild.cmd} | ||
|
||
# | ||
# IMGTOOL | ||
# | ||
tools.imgtool.cmd=imgtool | ||
tools.imgtool.flags=sign --key "{build.keys.keychain}/{build.keys.sign_key}" --encrypt "{build.keys.keychain}/{build.keys.encrypt_key}" "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.bin" --align {build.alignment} --max-align {build.alignment} --version {build.version} --header-size {build.header_size} --pad-header --slot-size {build.slot_size} | ||
[...] | ||
|
||
``` | ||
|
||
By having only `tools.TOOL_NAME.cmd` and `tools.TOOL_NAME.flags`, we can customize the behavior with a | ||
[custom board option](../platform-specification.md#custom-board-options). Then in the | ||
[`boards.txt`](../platform-specification.md#boardstxt) we can define the new option to use a different | ||
`build.postbuild.cmd`: | ||
|
||
``` | ||
[...] | ||
menu.security=Security setting | ||
|
||
envie_m7.menu.security.none=None | ||
envie_m7.menu.security.sien=Signature + Encryption | ||
|
||
envie_m7.menu.security.sien.build.postbuild.cmd="{tools.imgtool.cmd}" {tools.imgtool.flags} | ||
envie_m7.menu.security.none.build.postbuild.cmd="{tools.imgtool.cmd}" exit | ||
|
||
envie_m7.menu.security.sien.build.keys.keychain={runtime.hardware.path}/Default_Keys | ||
envie_m7.menu.security.sien.build.keys.sign_key=default-signing-key.pem | ||
envie_m7.menu.security.sien.build.keys.encrypt_key=default-encrypt-key.pem | ||
[...] | ||
``` | ||
|
||
The security keys can be added with: | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `build.keys.keychain` indicates the path of the dir where to search for the custom keys to sign and encrypt a binary. | ||
- `build.keys.sign_key` indicates the name of the custom signing key to use to sign a binary during the compile process. | ||
- `build.keys.encrypt_key` indicates the name of the custom encryption key to use to encrypt a binary during the compile | ||
process. | ||
|
||
It's suggested to use the property names mentioned before, because they can be overridden respectively with | ||
`--keys-keychain`, `--sign-key` and `--encrypt-key` Arduino CLI [compile flags](../commands/arduino-cli_compile.md). | ||
|
||
For example, by using the following command, the sketch is compiled and the resulting binary is signed and encrypted | ||
with the specified keys located in `/home/user/Arduino/keys` directory: | ||
|
||
``` | ||
arduino-cli compile -b arduino:mbed_portenta:envie_m7:security=sien --keys-keychain /home/user/Arduino/keys --sign-key ecsdsa-p256-signing-key.pem --encrypt-key ecsdsa-p256-encrypt-key.pem /home/user/Arduino/MySketch | ||
``` |
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
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
Oops, something went wrong.
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.