mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
return the key index that passed from sigcheck
This commit is contained in:
parent
6768f87ce8
commit
63e2834e9d
2 changed files with 9 additions and 6 deletions
|
|
@ -246,7 +246,7 @@ impl Repl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"check" => match crate::sigcheck::validate_image(crate::FLASH_BASE as *const u32) {
|
"check" => match crate::sigcheck::validate_image(crate::FLASH_BASE as *const u32) {
|
||||||
Ok(_) => crate::println!("sigcheck passed"),
|
Ok(key_number) => crate::println!("sigcheck passed on key {}", key_number),
|
||||||
Err(e) => crate::println!("sigcheck failed: {}", e),
|
Err(e) => crate::println!("sigcheck failed: {}", e),
|
||||||
},
|
},
|
||||||
"reps" => {
|
"reps" => {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub const REVOCATION_OFFSET: usize = 124;
|
||||||
/// Why this matters: boot0 has to boot the chip under all modes. An external power source is needed for
|
/// Why this matters: boot0 has to boot the chip under all modes. An external power source is needed for
|
||||||
/// IDD85 > 100mA. Thus we can't boot at max speed config, as not all system configurations have the
|
/// IDD85 > 100mA. Thus we can't boot at max speed config, as not all system configurations have the
|
||||||
/// external regulator. So, we have to work at reduced VDD/frequency and make sure this constraint is met.
|
/// external regulator. So, we have to work at reduced VDD/frequency and make sure this constraint is met.
|
||||||
pub fn validate_image(img_offset: *const u32) -> Result<(), String> {
|
pub fn validate_image(img_offset: *const u32) -> Result<usize, String> {
|
||||||
// conjure the signature struct directly out of memory. super unsafe.
|
// conjure the signature struct directly out of memory. super unsafe.
|
||||||
let sig_ptr = img_offset as *const SignatureInFlash;
|
let sig_ptr = img_offset as *const SignatureInFlash;
|
||||||
let sig: &SignatureInFlash = unsafe { sig_ptr.as_ref().unwrap() };
|
let sig: &SignatureInFlash = unsafe { sig_ptr.as_ref().unwrap() };
|
||||||
|
|
@ -46,8 +46,8 @@ pub fn validate_image(img_offset: *const u32) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let one_way_counters = OneWayCounter::new();
|
let one_way_counters = OneWayCounter::new();
|
||||||
let mut valid = false;
|
|
||||||
let mut secure = false;
|
let mut secure = false;
|
||||||
|
let mut passing_key: Option<usize> = None;
|
||||||
for (i, key) in sig.sealed_data.pubkeys.iter().enumerate() {
|
for (i, key) in sig.sealed_data.pubkeys.iter().enumerate() {
|
||||||
if key.iter().all(|&x| x == 0) {
|
if key.iter().all(|&x| x == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -68,13 +68,12 @@ pub fn validate_image(img_offset: *const u32) -> Result<(), String> {
|
||||||
// the function inside the ed25519 crate.
|
// the function inside the ed25519 crate.
|
||||||
match verifying_key.verify_prehashed(h, None, &ed25519_signature) {
|
match verifying_key.verify_prehashed(h, None, &ed25519_signature) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
passing_key = Some(i);
|
||||||
if i != sig.sealed_data.pubkeys.len() - 1 {
|
if i != sig.sealed_data.pubkeys.len() - 1 {
|
||||||
valid = true;
|
|
||||||
secure = true;
|
secure = true;
|
||||||
break;
|
break;
|
||||||
} else if i == sig.sealed_data.pubkeys.len() - 1 {
|
} else if i == sig.sealed_data.pubkeys.len() - 1 {
|
||||||
// this is the developer key slot
|
// this is the developer key slot
|
||||||
valid = true;
|
|
||||||
secure = false;
|
secure = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +85,11 @@ pub fn validate_image(img_offset: *const u32) -> Result<(), String> {
|
||||||
if !secure {
|
if !secure {
|
||||||
erase_secrets();
|
erase_secrets();
|
||||||
}
|
}
|
||||||
if valid { Ok(()) } else { Err(String::from("No valid pubkeys found or signature invalid")) }
|
if let Some(valid_key) = passing_key {
|
||||||
|
Ok(valid_key)
|
||||||
|
} else {
|
||||||
|
Err(String::from("No valid pubkeys found or signature invalid"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn erase_secrets() {
|
fn erase_secrets() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue