From cf267f096c8047de2f15ccbb0fb42ad212aa1032 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 4 Feb 2026 03:07:38 +0800 Subject: [PATCH] generate actual private keys instead of using random data by doing this we make this safer by ensuring that the public keys are valid public keys, allowing us to sign these images with production keys and not accidentally signing a weak public key. --- tools/Cargo.toml | 2 +- tools/src/sign_image.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/Cargo.toml b/tools/Cargo.toml index edf5c3f59..a77214a58 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -22,7 +22,7 @@ pem = "0.8.3" svd2utra = "0.1.25" xmas-elf = "0.9.0" xous-semver = "0.1.5" -ed25519-dalek = { version = "2.1.0", features = ["digest"] } +ed25519-dalek = { version = "2.1.0", features = ["digest", "rand_core"] } sha2 = { version = "0.10.8" } pkcs8 = { version = "0.8.0", features = ["pem"] } base64 = "0.20.0" diff --git a/tools/src/sign_image.rs b/tools/src/sign_image.rs index aeb0b846c..42ea01231 100644 --- a/tools/src/sign_image.rs +++ b/tools/src/sign_image.rs @@ -242,10 +242,20 @@ pub fn sign_image( dst.populate_from(src); } } else { - // populate with fake, random data. The data changes every time. + // populate with a random key. Use actual key generation to ensure that the committed + // public key is actually a valid public key. for dst in header.sealed_data.pubkeys.iter_mut() { + use ed25519_dalek::VerifyingKey; + use rand::rngs::OsRng; + let mut fake_pk = Pubkey::default(); - rand::rngs::OsRng.fill_bytes(&mut fake_pk.pk); + // Generate a random signing (private) key + let signing_key = SigningKey::generate(&mut OsRng); + // Derive the verifying (public) key + let verifying_key: VerifyingKey = signing_key.verifying_key(); + let public_bytes = verifying_key.to_bytes(); + fake_pk.pk.copy_from_slice(&public_bytes); + rand::rngs::OsRng.fill_bytes(&mut fake_pk.tag); dst.populate_from(&fake_pk); }