diff --git a/tools/src/bin/xous-app-uf2.rs b/tools/src/bin/xous-app-uf2.rs index 00b239e53..bf5f5392f 100644 --- a/tools/src/bin/xous-app-uf2.rs +++ b/tools/src/bin/xous-app-uf2.rs @@ -163,6 +163,7 @@ fn main() -> Result<(), Box> { xous_tools::sign_image::Version::Bao1xV1, Some("app"), Some(anti_rollback as usize), + false, )?; let app_uf2 = "apps.uf2"; diff --git a/tools/src/bin/xous-sign-image.rs b/tools/src/bin/xous-sign-image.rs index cc6aa79b4..3cb5c494e 100644 --- a/tools/src/bin/xous-sign-image.rs +++ b/tools/src/bin/xous-sign-image.rs @@ -108,6 +108,13 @@ fn main() -> Result<(), Box> { .help("Manually specify an anti-rollback value for the image. Overrides the system configuration file.") .required(false) ) + .arg( + Arg::with_name("fake-pubkeys") + .long("fake public key block") + .takes_value(false) + .help("When specified, fills the public key block with random, fake data. Used for testing third-party boot flow policies") + .required(false) + ) .get_matches(); let minver = @@ -157,6 +164,7 @@ fn main() -> Result<(), Box> { sig_length, matches.value_of("function-code"), arb_override.map(|x| x as usize), + matches.is_present("fake-pubkeys"), )?; if matches.is_present("bao1x") { @@ -199,6 +207,7 @@ fn main() -> Result<(), Box> { sig_length, Some(matches.value_of("function-code").unwrap_or("kernel")), arb_override.map(|x| x as usize), + matches.is_present("fake-pubkeys"), )?; if matches.is_present("bao1x") { diff --git a/tools/src/sign_image.rs b/tools/src/sign_image.rs index b2c0012f3..fb7fe48c1 100644 --- a/tools/src/sign_image.rs +++ b/tools/src/sign_image.rs @@ -4,11 +4,12 @@ use std::io::{Read, Write}; use std::path::Path; use bao1x_api::signatures::{ - FunctionCode, PADDING_LEN, SIGBLOCK_LEN, SealedFields, SignatureInFlash, UNSIGNED_LEN, + FunctionCode, PADDING_LEN, Pubkey, SIGBLOCK_LEN, SealedFields, SignatureInFlash, UNSIGNED_LEN, }; use ed25519_dalek::{DigestSigner, SigningKey}; use pkcs8::PrivateKeyInfo; use pkcs8::der::Decodable; +use rand::RngCore; use ring::signature::{Ed25519KeyPair, KeyPair}; use sha2::{Digest, Sha512}; @@ -76,6 +77,7 @@ pub fn sign_image( version: Version, function_code: Option<&str>, anti_rollback_manual: Option, + fake_pubkeys: bool, ) -> Result, Box> { let mut dest_file = vec![]; @@ -237,10 +239,20 @@ pub fn sign_image( header.sealed_data.semver = semver; // whack in all the public keys, defined in the bao1x-api crate - for (dst, src) in - header.sealed_data.pubkeys.iter_mut().zip(bao1x_api::pubkeys::PUBKEY_HEADER.iter()) - { - dst.populate_from(src); + if !fake_pubkeys { + for (dst, src) in + header.sealed_data.pubkeys.iter_mut().zip(bao1x_api::pubkeys::PUBKEY_HEADER.iter()) + { + dst.populate_from(src); + } + } else { + // populate with fake, random data. The data changes every time. + for dst in header.sealed_data.pubkeys.iter_mut() { + let mut fake_pk = Pubkey::default(); + rand::rngs::OsRng.fill_bytes(&mut fake_pk.pk); + rand::rngs::OsRng.fill_bytes(&mut fake_pk.tag); + dst.populate_from(&fake_pk); + } } let mut protected = Vec::new(); @@ -305,6 +317,7 @@ pub fn sign_file( sector_length: usize, function_code: Option<&str>, arb_override: Option, + fake_pubkeys: bool, ) -> Result<(), Box> where S: AsRef, @@ -326,6 +339,7 @@ where version, function_code, arb_override, + fake_pubkeys, )?; dest_file.write_all(&result)?; Ok(()) diff --git a/tools/src/swap_writer.rs b/tools/src/swap_writer.rs index 62859ce37..ba4e643cf 100644 --- a/tools/src/swap_writer.rs +++ b/tools/src/swap_writer.rs @@ -142,6 +142,7 @@ impl SwapWriter { Version::Bao1xV1, function, anti_rollback_manual, + false, ) .map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Can't sign swap image"))?; // write the header, less space for the signature