mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Fixup sign_image to generate records with the new auth_data format
This commit is contained in:
parent
e254700cf9
commit
ea8927fc55
1 changed files with 27 additions and 17 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use bao1x_api::signatures::{FunctionCode, PADDING_LEN, Pubkey, SIGBLOCK_LEN, SealedFields, UNSIGNED_LEN};
|
use bao1x_api::signatures::{
|
||||||
|
FunctionCode, PADDING_LEN, 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;
|
||||||
|
|
@ -211,23 +213,23 @@ pub fn sign_image(
|
||||||
Some("swap") => FunctionCode::Swap,
|
Some("swap") => FunctionCode::Swap,
|
||||||
_ => FunctionCode::Developer,
|
_ => FunctionCode::Developer,
|
||||||
};
|
};
|
||||||
let mut sealed_fields = SealedFields {
|
let mut header = SignatureInFlash::default();
|
||||||
version: version as u32,
|
header.sealed_data.version = version as u32;
|
||||||
signed_len: (source.len() + SIGBLOCK_LEN - UNSIGNED_LEN) as u32,
|
header.sealed_data.signed_len = (source.len() + SIGBLOCK_LEN - UNSIGNED_LEN) as u32;
|
||||||
function_code: function_code as u32,
|
header.sealed_data.function_code = function_code as u32;
|
||||||
reserved: 0,
|
header.sealed_data.reserved = 0;
|
||||||
min_semver: minver_bytes,
|
header.sealed_data.min_semver = minver_bytes;
|
||||||
semver,
|
header.sealed_data.semver = semver;
|
||||||
pubkeys: [Pubkey::default(), Pubkey::default(), Pubkey::default(), Pubkey::default()],
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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 sealed_fields.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut protected = Vec::new();
|
let mut protected = Vec::new();
|
||||||
protected.extend_from_slice(sealed_fields.as_ref());
|
protected.extend_from_slice(header.sealed_data.as_ref());
|
||||||
protected.resize(protected.len() + PADDING_LEN, 0);
|
protected.resize(protected.len() + PADDING_LEN, 0);
|
||||||
protected.extend_from_slice(&source);
|
protected.extend_from_slice(&source);
|
||||||
|
|
||||||
|
|
@ -236,12 +238,14 @@ pub fn sign_image(
|
||||||
h.update(&protected);
|
h.update(&protected);
|
||||||
|
|
||||||
let sig = signing_key.sign_digest(h.clone()).to_bytes();
|
let sig = signing_key.sign_digest(h.clone()).to_bytes();
|
||||||
|
header._jal_instruction = generate_jal_x0(SIGBLOCK_LEN as isize)?;
|
||||||
|
header.signature.copy_from_slice(&sig);
|
||||||
|
// no AAD on this type of signature
|
||||||
|
header.aad_len = 0;
|
||||||
|
|
||||||
let jal = generate_jal_x0(length as isize)?;
|
// Write the header
|
||||||
dest_file.write_all(&jal.to_le_bytes())?;
|
dest_file.write_all(&header.as_ref()[..UNSIGNED_LEN])?;
|
||||||
|
println!("dest_file wrote {}, {}", dest_file.len(), UNSIGNED_LEN);
|
||||||
// Write the signature data
|
|
||||||
dest_file.write_all(&sig)?;
|
|
||||||
|
|
||||||
if defile {
|
if defile {
|
||||||
println!(
|
println!(
|
||||||
|
|
@ -306,6 +310,12 @@ where
|
||||||
let mut dest_file = std::fs::File::create(output)?;
|
let mut dest_file = std::fs::File::create(output)?;
|
||||||
source_file.read_to_end(&mut source)?;
|
source_file.read_to_end(&mut source)?;
|
||||||
|
|
||||||
|
// maintenance note: there is a mirror of this code in signing/fido-signer/src/main.rs
|
||||||
|
// if you're editing this, maybe consider also trying to librarify these routines?
|
||||||
|
// the key challenge is that fido-signer has to be out of workspace because it relies
|
||||||
|
// on cryptographic primitives that are pinned to versions that are not compatible
|
||||||
|
// with the baochip hardware, e.g. the FIDO2 libraries pin to an incompatible version
|
||||||
|
// with xous-core, so it's a little awkward spanning/sharing crates this way.
|
||||||
let app_start_addr = match function_code {
|
let app_start_addr = match function_code {
|
||||||
Some("boot0") => bao1x_api::BOOT0_START,
|
Some("boot0") => bao1x_api::BOOT0_START,
|
||||||
Some("boot1") => bao1x_api::BOOT1_START,
|
Some("boot1") => bao1x_api::BOOT1_START,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue