Skip to content

Commit 8182c24

Browse files
committed
wip
1 parent 148712e commit 8182c24

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

boot/bootutil/src/ed25519_psa.c

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

35+
#if defined(CONFIG_BOOT_AUTO_REVOKE_KMU)
36+
static psa_key_id_t *validated_with = NULL;
37+
#define MK_PSA_KEY_HANDLE(key) PSA_KEY_HANDLE_FROM_CRACEN_KMU_SLOT(CRACEN_KMU_KEY_USAGE_SCHEME_RAW, key)
38+
#endif
39+
3540
BUILD_ASSERT(CONFIG_BOOT_SIGNATURE_KMU_SLOTS <= ARRAY_SIZE(kmu_key_ids),
3641
"Invalid number of KMU slots, up to 3 are supported on nRF54L15");
3742
#endif
@@ -114,6 +119,10 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
114119
EDDSA_SIGNAGURE_LENGTH);
115120
if (status == PSA_SUCCESS) {
116121
ret = 1;
122+
#if defined(CONFIG_BOOT_AUTO_REVOKE_KMU)
123+
BOOT_LOG_ERR("--------------- valid set to %d", i);
124+
validated_with = kmu_key_ids + i;
125+
#endif
117126
break;
118127
}
119128

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

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

boot/bootutil/src/image_validate.c

+12
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ bootutil_img_hash(struct enc_key_data *enc_state, int image_index,
245245
# define KEY_BUF_SIZE (SIG_BUF_SIZE + 24)
246246
#endif /* !MCUBOOT_HW_KEY */
247247

248+
#if defined(CONFIG_BOOT_AUTO_REVOKE_KMU)
249+
extern void revoke_prev(void);
250+
static uint8_t ready_to_revoke = 0;
251+
void bootutil_revoke_after_validation(void){
252+
ready_to_revoke=1;}
253+
#endif
254+
248255
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
249256
#if !defined(MCUBOOT_HW_KEY)
250257
static int
@@ -681,6 +688,11 @@ bootutil_img_validate(struct enc_key_data *enc_state, int image_index,
681688
#ifndef MCUBOOT_SIGN_PURE
682689
FIH_CALL(bootutil_verify_sig, valid_signature, hash, sizeof(hash),
683690
buf, len, key_id);
691+
#if defined(CONFIG_BOOT_AUTO_REVOKE_KMU)
692+
if(ready_to_revoke){
693+
revoke_prev();
694+
}
695+
#endif
684696
#else
685697
/* Directly check signature on the image, by using the mapping of
686698
* a device to memory. The pointer is beginning of image in flash,

boot/bootutil/src/loader.c

+7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct sector_buffer_t {
100100
boot_sector_t scratch[BOOT_MAX_IMG_SECTORS];
101101
#endif
102102
};
103+
#if defined(CONFIG_BOOT_AUTO_REVOKE_KMU)
104+
void bootutil_revoke_after_validation(void);
105+
#endif
103106

104107
static struct sector_buffer_t sector_buffers;
105108
#endif
@@ -2733,6 +2736,10 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
27332736
}
27342737
}
27352738

2739+
if (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_NONE) {
2740+
bootutil_revoke_after_validation();
2741+
BOOT_LOG_ERR("----------------------swap none");
2742+
}
27362743
/* Iterate over all the images. At this point all required update operations
27372744
* have finished. By the end of the loop each image in the primary slot will
27382745
* have been re-validated.

boot/zephyr/Kconfig

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ config BOOT_SIGNATURE_KMU_SLOTS
327327
Selects the number of KMU key slots (also known as generations) to use when verifying
328328
an image.
329329

330+
config BOOT_AUTO_REVOKE_KMU
331+
bool "Auto revoke previous gen key"
332+
help
333+
Automatically revoke previous generation key upon new valid key usage.
334+
330335
endif
331336

332337
if !BOOT_SIGNATURE_USING_KMU

0 commit comments

Comments
 (0)