Skip to content

Allow bypasing signature hash key matching #2310

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions boot/bootutil/src/image_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ bootutil_img_hash(struct boot_loader_state *state,
# define KEY_BUF_SIZE (SIG_BUF_SIZE + 24)
#endif /* !MCUBOOT_HW_KEY */

#if !defined(MCUBOOT_BYPASS_KEY_MATCH)
/* Find functions are only needed when key is checked first */
#if !defined(MCUBOOT_HW_KEY)
static int
bootutil_find_key(uint8_t *keyhash, uint8_t keyhash_len)
Expand Down Expand Up @@ -347,6 +349,18 @@ bootutil_find_key(uint8_t image_index, uint8_t *key, uint16_t key_len)
#endif /* !MCUBOOT_HW_KEY */
#endif /* !MCUBOOT_BUILTIN_KEY */
#endif /* EXPECTED_SIG_TLV */
#else /* !MCUBOOT_BYPASS_KEY_MATCH */
static inline int
bootutil_find_key(uint8_t image_index, uint8_t *key, uint16_t key_len)
{
(void)image_index;
(void)key;
(void)key_len;

/* There is only one key, so it always matches */
return 0;
}
#endif /* !MCUBOOT_BYPASS_KEY_MATCH */

/**
* Reads the value of an image's security counter.
Expand Down
13 changes: 13 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ endif

endchoice

config BOOT_BYPASS_KEY_MATCH
bool "Do not match TLV key hash against built in key"
depends on !BOOT_SIGNATURE_TYPE_NONE
depends on !BOOT_HW_KEY
help
MCUboot reads, from TLV, hash of a key that should be used to verify
a signature and uses it to find a builtin key.
This action is pointless when there is single key compiled in,
as the signature verification process will just fail if that is not
the right key.
Enabling this option turns off key matching, slightly reducing
MCUboot code and boot time.

config BOOT_SIGNATURE_KEY_FILE
string "PEM key file"
default "root-ec-p256.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256
Expand Down
9 changes: 9 additions & 0 deletions boot/zephyr/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@
#define MCUBOOT_HMAC_SHA512
#endif

/* Turn off check of public key hash against compiled in key
* before attempting signature verification. When there is only
* one key, matching is pointless, the signature may just be
* verified with the only key that there is.
*/
#ifdef CONFIG_BOOT_BYPASS_KEY_MATCH
#define MCUBOOT_BYPASS_KEY_MATCH
#endif

#ifdef CONFIG_BOOT_DECOMPRESSION
#define MCUBOOT_DECOMPRESS_IMAGES
#endif
Expand Down
Loading