mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
Merge pull request #226 from gsora/fix/root-keys-invalid-image-fail
root-keys: gracefully handle cases where gateware signature is malformed, invalid public key or signature type
This commit is contained in:
commit
35584cf6bf
2 changed files with 12 additions and 4 deletions
|
|
@ -2401,8 +2401,10 @@ impl<'a> RootKeys {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sig_rec: &SignatureInFlash = unsafe{(sig_region.as_ptr() as *const SignatureInFlash).as_ref().unwrap()};
|
let sig_rec: &SignatureInFlash = unsafe{(sig_region.as_ptr() as *const SignatureInFlash).as_ref().unwrap()};
|
||||||
let sig = Signature::from_bytes(&sig_rec.signature).expect("Signature malformed");
|
let sig = match Signature::from_bytes(&sig_rec.signature) {
|
||||||
|
Ok(sig) => sig,
|
||||||
|
Err(_) => return SignatureResult::MalformedSignature,
|
||||||
|
};
|
||||||
let mut sigtype = SignatureResult::SelfSignOk;
|
let mut sigtype = SignatureResult::SelfSignOk;
|
||||||
// check against all the known signature types in detail
|
// check against all the known signature types in detail
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -2417,7 +2419,7 @@ impl<'a> RootKeys {
|
||||||
self.read_key_256(KeyRomLocs::DEVELOPER_PUBKEY)
|
self.read_key_256(KeyRomLocs::DEVELOPER_PUBKEY)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
panic!("Invalid state during check gateware signature")
|
return SignatureResult::InvalidSignatureType
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// check for uninitialized signature records
|
// check for uninitialized signature records
|
||||||
|
|
@ -2436,7 +2438,10 @@ impl<'a> RootKeys {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let pubkey = PublicKey::from_bytes(&pubkey_bytes).expect("public key was not valid");
|
let pubkey = match PublicKey::from_bytes(&pubkey_bytes) {
|
||||||
|
Ok(pubkey) => pubkey,
|
||||||
|
Err(_) => return SignatureResult::InvalidPubKey,
|
||||||
|
};
|
||||||
|
|
||||||
let region = match region_enum {
|
let region = match region_enum {
|
||||||
GatewareRegion::Boot => self.gateware(),
|
GatewareRegion::Boot => self.gateware(),
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ pub enum SignatureResult {
|
||||||
ThirdPartyOk,
|
ThirdPartyOk,
|
||||||
DevKeyOk,
|
DevKeyOk,
|
||||||
Invalid,
|
Invalid,
|
||||||
|
MalformedSignature,
|
||||||
|
InvalidSignatureType,
|
||||||
|
InvalidPubKey,
|
||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub enum GatewareRegion {
|
pub enum GatewareRegion {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue