forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
mcuboot: support multiple signing keys #1
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
Open
JPHutchins
wants to merge
1
commit into
main
Choose a base branch
from
mcuboot/multiple-signing-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
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,10 @@ | ||
| # Copyright (c) 2026 Intercreate, Inc. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
|
|
||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(mcuboot_multiple_keys) | ||
|
|
||
| target_sources(app PRIVATE src/main.c) |
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,36 @@ | ||
| MCUboot Multiple Signing Keys | ||
| ############################# | ||
|
|
||
| Runtime acceptance test for an MCUboot bootloader built with more than one | ||
| verification key: a single bootloader embeds two keys and boots an application | ||
| signed by *either* one, exercised entirely under QEMU. | ||
|
|
||
| :kconfig:option:`SB_CONFIG_BOOT_SIGNATURE_KEY_FILE` takes a comma-separated list | ||
| of keys. MCUboot embeds the public half of each; the application is signed with | ||
| the first. This test models a *development* bootloader that trusts both a | ||
| development and a production key, using keys shipped with MCUboot: | ||
|
|
||
| * ``key_id 0`` -- ``root-ed25519.pem``, the development key whose private half | ||
| signs the application in the default build; | ||
| * ``key_id 1`` -- ``root-ed25519-2-pub.pem``, the production key's public half | ||
| only: the bootloader trusts production-signed images without ever holding the | ||
| production private key. | ||
|
|
||
| The two scenarios differ only in how the application is signed: | ||
|
|
||
| * **key0** boots the application as built -- signed with the development key. | ||
| * **key1** re-signs the built application with the production private key | ||
| (``root-ed25519-2.pem``) *after* the build and boots that, modelling a | ||
| production custodian who signs the release binary out-of-band. The re-sign | ||
| reuses the build's own imgtool invocation; see ``pytest/test_multiple_keys.py``. | ||
|
|
||
| How the QEMU Test Works | ||
| ******************************* | ||
|
|
||
| A ``harness: pytest`` test (``pytest/test_multiple_keys.py``) starts QEMU with | ||
| two ``-device loader`` entries -- MCUboot's hex and the signed application | ||
| preloaded into slot0 -- and reads the console. With | ||
| :kconfig:option:`CONFIG_MCUBOOT_LOG_LEVEL_DBG` MCUboot prints | ||
| ``bootutil_verify_sig: ED25519 key_id N``, the runtime proof of which embedded | ||
| key validated the image; the test asserts the expected ``key_id`` and that the | ||
| application banner then prints from the primary slot. |
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,12 @@ | ||
| # Copyright (c) 2026 Intercreate, Inc. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| CONFIG_FLASH=y | ||
| CONFIG_FLASH_SIMULATOR=y | ||
|
|
||
| CONFIG_RETAINED_MEM=y | ||
| CONFIG_RETENTION=y | ||
| CONFIG_RETAINED_MEM_ZEPHYR_RAM=y | ||
| CONFIG_RETENTION_BOOTLOADER_INFO=y | ||
| CONFIG_RETENTION_BOOTLOADER_INFO_TYPE_MCUBOOT=y |
106 changes: 106 additions & 0 deletions
106
tests/boot/mcuboot_multiple_keys/boards/mps2_an385.overlay
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,106 @@ | ||
| /* | ||
| * Copyright (c) 2026 Intercreate, Inc. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * mps2/an385 memory map for the MCUboot RAM_LOAD fixture, and the single | ||
| * source of the flash-simulator layout: sysbuild/mcuboot.overlay includes | ||
| * this file so both images agree on the partition table. | ||
| * | ||
| * This is the application image. MCUboot copies slot0 into the sram0 exec | ||
| * region defined here and jumps to it. sram0 is declared before the FlashSim | ||
| * and RetainedMem regions (also mmio-sram) so it stays mmio-sram instance 0. | ||
| * The image slots use zephyr,mapped-partition, so flash_sim0's inherited | ||
| * fixed-partitions node is deleted first. | ||
| * | ||
| * Adapted from github.com/intercreate/smp-server-fixtures | ||
| */ | ||
|
|
||
| /delete-node/ &sram0; | ||
| /delete-node/ &{/sim_flash_controller/flash_sim@0/partitions}; | ||
|
|
||
| / { | ||
| chosen { | ||
| zephyr,flash = &flash0; | ||
| zephyr,console = &uart0; | ||
| zephyr,bootloader-info = &boot_info0; | ||
|
|
||
| /delete-property/ zephyr,code-partition; | ||
| }; | ||
|
|
||
| sram0: memory@20240000 { | ||
| compatible = "mmio-sram"; | ||
| reg = <0x20240000 0x001bf000>; | ||
| }; | ||
|
|
||
| flash_sim_region: memory@20040000 { | ||
| compatible = "zephyr,memory-region", "mmio-sram"; | ||
| reg = <0x20040000 0x00200000>; /* 2 MB sim-flash backing store */ | ||
| ranges = <0x0 0x20040000 0x00200000>; | ||
| zephyr,memory-region = "FlashSim"; | ||
| status = "okay"; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
| }; | ||
|
|
||
| sram_retained: memory@203ffc00 { | ||
| compatible = "zephyr,memory-region", "mmio-sram"; | ||
| reg = <0x203ffc00 0x00000400>; | ||
| ranges = <0x0 0x203ffc00 0x00000400>; | ||
| zephyr,memory-region = "RetainedMem"; | ||
| status = "okay"; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
|
|
||
| retainedmem { | ||
| compatible = "zephyr,retained-ram"; | ||
| status = "okay"; | ||
| ranges; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
|
|
||
| boot_info0: boot_info@0 { | ||
| compatible = "zephyr,retention"; | ||
| status = "okay"; | ||
| reg = <0x0 0x100>; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| &sim_flash_controller { | ||
| memory-region = <&flash_sim_region>; | ||
| }; | ||
|
|
||
| &flash_sim0 { | ||
| reg = <0x00000000 0x00200000>; | ||
| erase-block-size = <4096>; | ||
| write-block-size = <4>; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
| ranges = <0x0 0x0 0x00200000>; | ||
|
|
||
| partitions { | ||
| ranges; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
|
|
||
| boot_partition: partition@0 { | ||
| compatible = "zephyr,mapped-partition"; | ||
| label = "mcuboot"; | ||
| reg = <0x00000000 0x00010000>; | ||
| }; | ||
|
|
||
| slot0_partition: partition@10000 { | ||
| compatible = "zephyr,mapped-partition"; | ||
| label = "image-0"; | ||
| reg = <0x00010000 0x00080000>; | ||
| }; | ||
|
|
||
| slot1_partition: partition@90000 { | ||
| compatible = "zephyr,mapped-partition"; | ||
| label = "image-1"; | ||
| reg = <0x00090000 0x00080000>; | ||
| }; | ||
| }; | ||
| }; |
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 @@ | ||
| # nothing here |
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,39 @@ | ||
| # Copyright (c) 2026 Intercreate, Inc. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
| # Add the directory to PYTHONPATH | ||
| zephyr_base = os.getenv("ZEPHYR_BASE") | ||
| if zephyr_base: | ||
| sys.path.insert( | ||
| 0, os.path.join(zephyr_base, "scripts", "pylib", "pytest-twister-harness", "src") | ||
| ) | ||
| else: | ||
| raise OSError("ZEPHYR_BASE environment variable is not set") | ||
|
|
||
| pytest_plugins = [ | ||
| "twister_harness.plugin", | ||
| ] | ||
|
|
||
|
|
||
| def pytest_addoption(parser: pytest.Parser) -> None: | ||
| parser.addoption( | ||
| "--expected-key-id", | ||
| type=int, | ||
| required=True, | ||
| help="key_id MCUboot is expected to validate the application against", | ||
| ) | ||
|
JPHutchins marked this conversation as resolved.
|
||
| parser.addoption( | ||
| "--resign-key", | ||
| default="", | ||
| help=( | ||
| "filename of a key (resolved against the build's signing-key " | ||
| "directory) to re-sign the application with before loading it, " | ||
| "modelling a production custodian signing the release binary" | ||
| ), | ||
| ) | ||
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.