Skip to content

Commit 0569a98

Browse files
committed
wip
1 parent 148712e commit 0569a98

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

boot/bootutil/src/ed25519_psa.c

+35
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ static psa_key_id_t kmu_key_ids[3] = {
3232
MAKE_PSA_KMU_KEY_ID(230)
3333
};
3434

35+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
36+
static psa_key_id_t *validated_with = NULL;
37+
#endif
38+
3539
BUILD_ASSERT(CONFIG_BOOT_SIGNATURE_KMU_SLOTS <= ARRAY_SIZE(kmu_key_ids),
3640
"Invalid number of KMU slots, up to 3 are supported on nRF54L15");
3741
#endif
@@ -114,6 +118,10 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
114118
EDDSA_SIGNAGURE_LENGTH);
115119
if (status == PSA_SUCCESS) {
116120
ret = 1;
121+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
122+
BOOT_LOG_ERR("--------------- valid set to %d", i);
123+
validated_with = kmu_key_ids + i;
124+
#endif
117125
break;
118126
}
119127

@@ -122,4 +130,31 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
122130

123131
return ret;
124132
}
133+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
134+
void revoke_in_kmu(void)
135+
{
136+
137+
psa_status_t status = psa_crypto_init();
138+
139+
if (status != PSA_SUCCESS) {
140+
printk("PSA crypto init failed with error %d\n", status);
141+
return;
142+
}
143+
BOOT_LOG_ERR("--------------- for");
144+
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; i++) {
145+
if((kmu_key_ids + i) == validated_with){
146+
break;
147+
}
148+
BOOT_LOG_ERR("--------------- invalidating %d", i);
149+
150+
status = psa_destroy_key(kmu_key_ids[i]);
151+
if (status == PSA_SUCCESS) {
152+
printk("ok\n");
153+
} else {
154+
printk("destroy failed with: %d\n", status);
155+
}
156+
}
157+
158+
}
159+
#endif
125160
#endif

boot/bootutil/src/image_validate.c

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
6565

6666
#include "bootutil_priv.h"
6767

68+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
69+
#include "bootutil/key_revocation.h"
70+
#endif
71+
72+
6873
#ifndef MCUBOOT_SIGN_PURE
6974
/*
7075
* Compute SHA hash over the image.
@@ -681,6 +686,10 @@ bootutil_img_validate(struct enc_key_data *enc_state, int image_index,
681686
#ifndef MCUBOOT_SIGN_PURE
682687
FIH_CALL(bootutil_verify_sig, valid_signature, hash, sizeof(hash),
683688
buf, len, key_id);
689+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
690+
revoke();
691+
#endif
692+
684693
#else
685694
/* Directly check signature on the image, by using the mapping of
686695
* a device to memory. The pointer is beginning of image in flash,

boot/bootutil/src/loader.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ int pcd_version_cmp_net(const struct flash_area *fap, struct image_header *hdr);
7676

7777
#include "mcuboot_config/mcuboot_config.h"
7878

79+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
80+
#include "bootutil/key_revocation.h"
81+
#endif
82+
7983
BOOT_LOG_MODULE_DECLARE(mcuboot);
8084

8185
static struct boot_loader_state boot_data;
@@ -100,7 +104,6 @@ struct sector_buffer_t {
100104
boot_sector_t scratch[BOOT_MAX_IMG_SECTORS];
101105
#endif
102106
};
103-
104107
static struct sector_buffer_t sector_buffers;
105108
#endif
106109
#endif
@@ -2733,6 +2736,12 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
27332736
}
27342737
}
27352738

2739+
#if defined(CONFIG_BOOT_KEYS_REVOCATION)
2740+
if (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_NONE) {
2741+
allow_revoke();
2742+
BOOT_LOG_ERR("----------------------swap none");
2743+
}
2744+
#endif
27362745
/* Iterate over all the images. At this point all required update operations
27372746
* have finished. By the end of the loop each image in the primary slot will
27382747
* have been re-validated.

boot/zephyr/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ if(DEFINED CONFIG_BOOT_SHARE_BACKEND_RETENTION)
9191
)
9292
endif()
9393

94+
if(DEFINED CONFIG_BOOT_KEYS_REVOCATION)
95+
zephyr_library_sources(
96+
${BOOT_DIR}/bootutil/src/key_revocation.c
97+
)
98+
endif()
99+
94100
# Generic bootutil sources and includes.
95101
zephyr_library_include_directories(${BOOT_DIR}/bootutil/include)
96102
zephyr_library_sources(

boot/zephyr/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ config BOOT_SIGNATURE_KMU_SLOTS
329329

330330
endif
331331

332+
config BOOT_KEYS_REVOCATION
333+
bool "Auto revoke previous gen key"
334+
default y if BOOT_SIGNATURE_USING_KMU
335+
default n
336+
help
337+
Automatically revoke previous generation key upon new valid key usage.
338+
339+
332340
if !BOOT_SIGNATURE_USING_KMU
333341

334342
config BOOT_SIGNATURE_KEY_FILE

0 commit comments

Comments
 (0)