mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
add the ability to create a fake public key block
This just populates a pubkey block with random data, simulating a third party firmware. A fake pubkey block can't boot anything else because we can't sign a firmware that matches that. But, it's also good enough to be able to test collateral key states.
This commit is contained in:
parent
a840beb98e
commit
602cc44ff8
4 changed files with 30 additions and 5 deletions
|
|
@ -163,6 +163,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
xous_tools::sign_image::Version::Bao1xV1,
|
xous_tools::sign_image::Version::Bao1xV1,
|
||||||
Some("app"),
|
Some("app"),
|
||||||
Some(anti_rollback as usize),
|
Some(anti_rollback as usize),
|
||||||
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let app_uf2 = "apps.uf2";
|
let app_uf2 = "apps.uf2";
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.help("Manually specify an anti-rollback value for the image. Overrides the system configuration file.")
|
.help("Manually specify an anti-rollback value for the image. Overrides the system configuration file.")
|
||||||
.required(false)
|
.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();
|
.get_matches();
|
||||||
|
|
||||||
let minver =
|
let minver =
|
||||||
|
|
@ -157,6 +164,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
sig_length,
|
sig_length,
|
||||||
matches.value_of("function-code"),
|
matches.value_of("function-code"),
|
||||||
arb_override.map(|x| x as usize),
|
arb_override.map(|x| x as usize),
|
||||||
|
matches.is_present("fake-pubkeys"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if matches.is_present("bao1x") {
|
if matches.is_present("bao1x") {
|
||||||
|
|
@ -199,6 +207,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
sig_length,
|
sig_length,
|
||||||
Some(matches.value_of("function-code").unwrap_or("kernel")),
|
Some(matches.value_of("function-code").unwrap_or("kernel")),
|
||||||
arb_override.map(|x| x as usize),
|
arb_override.map(|x| x as usize),
|
||||||
|
matches.is_present("fake-pubkeys"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if matches.is_present("bao1x") {
|
if matches.is_present("bao1x") {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ use std::io::{Read, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use bao1x_api::signatures::{
|
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 ed25519_dalek::{DigestSigner, SigningKey};
|
||||||
use pkcs8::PrivateKeyInfo;
|
use pkcs8::PrivateKeyInfo;
|
||||||
use pkcs8::der::Decodable;
|
use pkcs8::der::Decodable;
|
||||||
|
use rand::RngCore;
|
||||||
use ring::signature::{Ed25519KeyPair, KeyPair};
|
use ring::signature::{Ed25519KeyPair, KeyPair};
|
||||||
use sha2::{Digest, Sha512};
|
use sha2::{Digest, Sha512};
|
||||||
|
|
||||||
|
|
@ -76,6 +77,7 @@ pub fn sign_image(
|
||||||
version: Version,
|
version: Version,
|
||||||
function_code: Option<&str>,
|
function_code: Option<&str>,
|
||||||
anti_rollback_manual: Option<usize>,
|
anti_rollback_manual: Option<usize>,
|
||||||
|
fake_pubkeys: bool,
|
||||||
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||||
let mut dest_file = vec![];
|
let mut dest_file = vec![];
|
||||||
|
|
||||||
|
|
@ -237,10 +239,20 @@ pub fn sign_image(
|
||||||
header.sealed_data.semver = semver;
|
header.sealed_data.semver = semver;
|
||||||
|
|
||||||
// whack in all the public keys, defined in the bao1x-api crate
|
// whack in all the public keys, defined in the bao1x-api crate
|
||||||
for (dst, src) in
|
if !fake_pubkeys {
|
||||||
header.sealed_data.pubkeys.iter_mut().zip(bao1x_api::pubkeys::PUBKEY_HEADER.iter())
|
for (dst, src) in
|
||||||
{
|
header.sealed_data.pubkeys.iter_mut().zip(bao1x_api::pubkeys::PUBKEY_HEADER.iter())
|
||||||
dst.populate_from(src);
|
{
|
||||||
|
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();
|
let mut protected = Vec::new();
|
||||||
|
|
@ -305,6 +317,7 @@ pub fn sign_file<S, T>(
|
||||||
sector_length: usize,
|
sector_length: usize,
|
||||||
function_code: Option<&str>,
|
function_code: Option<&str>,
|
||||||
arb_override: Option<usize>,
|
arb_override: Option<usize>,
|
||||||
|
fake_pubkeys: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>>
|
) -> Result<(), Box<dyn std::error::Error>>
|
||||||
where
|
where
|
||||||
S: AsRef<Path>,
|
S: AsRef<Path>,
|
||||||
|
|
@ -326,6 +339,7 @@ where
|
||||||
version,
|
version,
|
||||||
function_code,
|
function_code,
|
||||||
arb_override,
|
arb_override,
|
||||||
|
fake_pubkeys,
|
||||||
)?;
|
)?;
|
||||||
dest_file.write_all(&result)?;
|
dest_file.write_all(&result)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ impl SwapWriter {
|
||||||
Version::Bao1xV1,
|
Version::Bao1xV1,
|
||||||
function,
|
function,
|
||||||
anti_rollback_manual,
|
anti_rollback_manual,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Can't sign swap image"))?;
|
.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Can't sign swap image"))?;
|
||||||
// write the header, less space for the signature
|
// write the header, less space for the signature
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue