Merge branch 'bunnie-dev' into main

This commit is contained in:
bunnie 2021-08-14 22:50:38 +08:00
commit 6a7e6a7504
18 changed files with 1568 additions and 367 deletions

View file

@ -8,7 +8,7 @@ CertUtil -hashfile precursors/soc_csr.bin MD5
CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/loader.bin MD5
CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/xous.img MD5
scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-xous-elf/release/xous.img target/riscv32imac-unknown-xous-elf/release/loader.bin precursors/soc_csr.bin precursors/bbram-test1.nky pi@10.0.245.90:code/precursors/
scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-xous-elf/release/xous.img target/riscv32imac-unknown-xous-elf/release/loader.bin precursors/soc_csr.bin precursors/bbram1_soc_csr.bin precursors/bbram-test1.nky pi@10.0.245.90:code/precursors/
REM CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/loader.bin MD5
REM CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/xous.img MD5

View file

@ -286,73 +286,107 @@ pub fn validate_xous_img(xous_img_offset: *const u32) -> bool {
// select the public key
let mut keyrom = Keyrom::new();
let keyloc =
if !keyrom.key_is_zero(KeyLoc::SelfSignPub) { // self-signing key takes priority
if keyrom.key_is_dev(KeyLoc::SelfSignPub) {
println!("Self-signed key slot, but with developer public key.");
let mut keyloc = KeyLoc::SelfSignPub; // start from the self-sign key first, then work your way to less secure options
loop {
match keyloc {
KeyLoc::SelfSignPub => {
if !keyrom.key_is_zero(KeyLoc::SelfSignPub) { // self-signing key takes priority
if keyrom.key_is_dev(KeyLoc::SelfSignPub) {
println!("Self-signed key slot, but with developer public key.");
// mainly to protect against devs who were debugging and just stuck a dev key in the secure slot, and forgot to remove it.
gfx.msg("DEVELOPER KEY DETECTED\n\r", &mut cursor);
gfx.set_devboot();
}
} else {
keyloc = KeyLoc::ThirdPartyPub;
continue;
}
},
KeyLoc::ThirdPartyPub => {
// policy note: set the devboot flag also if we're doing a thirdparty pubkey boot
// reasoning: the purpose of the hash mark is to indicate if someone could have tampered
// with the device. Once an update is installed, it should always be self-signed, as it
// protects against the third party pubkey from being compromised and an alternate firmware
// being installed with no visible warning. Hence, even tho thirdparty pubkey boots could
// be more trusted, let's still flag it.
gfx.set_devboot();
if !keyrom.key_is_zero(KeyLoc::ThirdPartyPub) { // third party key is second in line
if keyrom.key_is_dev(KeyLoc::ThirdPartyPub) {
println!("Third party public key slot, but with developer public key.");
gfx.msg("DEVELOPER KEY DETECTED\n\r", &mut cursor);
}
} else {
keyloc = KeyLoc::DevPub;
continue;
}
},
KeyLoc::DevPub => {
if keyrom.key_is_zero(KeyLoc::DevPub) {
gfx.msg("Can't boot: No valid keys!", &mut cursor);
loop {}
}
gfx.msg("DEVELOPER KEY DETECTED\n\r", &mut cursor);
println!("Using developer public key");
gfx.set_devboot();
}
println!("Using self-signed public key");
KeyLoc::SelfSignPub
} else if !keyrom.key_is_zero(KeyLoc::ThirdPartyPub) { // third party key is second in line
if keyrom.key_is_dev(KeyLoc::ThirdPartyPub) {
println!("Third party public key slot, but with developer public key.");
gfx.msg("DEVELOPER KEY DETECTED\n\r", &mut cursor);
gfx.set_devboot();
}
println!("Using third-party public key");
KeyLoc::ThirdPartyPub
}
let pubkey = keyrom.read_ed25519(keyloc).unwrap_or_else(|e| {
gfx.msg("Unable to read key: ", &mut cursor);
gfx.msg(e, &mut cursor);
gfx.msg("\n\r", &mut cursor);
panic!("Unable to read key: {}", e)
});
println!("Public key bytes: {:x?}", pubkey.as_bytes());
if sig.version != 1 {
println!("Warning: mismatch on signature record version numbering. Ignoring and moving on...")
}
let signed_len = sig.signed_len;
let image: &[u8] = unsafe{core::slice::from_raw_parts((xous_img_offset as usize + SIGBLOCK_SIZE) as *const u8, signed_len as usize)};
let ed25519_signature = ed25519_dalek::Signature::from(sig.signature);
use ed25519_dalek::Verifier;
if pubkey.verify(image, &ed25519_signature).is_ok() {
gfx.msg("Signature check passed\n\r", &mut cursor);
println!("Signature check passed");
break;
} else {
if keyrom.key_is_zero(KeyLoc::DevPub) {
gfx.msg("Can't boot: No valid keys!", &mut cursor);
loop {}
}
gfx.msg("DEVELOPER KEY DETECTED\n\r", &mut cursor);
println!("Using developer public key");
gfx.set_devboot();
KeyLoc::DevPub
};
let pubkey = keyrom.read_ed25519(keyloc).unwrap_or_else(|e| {
gfx.msg("Unable to read key: ", &mut cursor);
gfx.msg(e, &mut cursor);
gfx.msg("\n\r", &mut cursor);
panic!("Unable to read key: {}", e)
});
// signature didn't work out, setup the next key and try it
match keyloc {
KeyLoc::SelfSignPub => {
keyloc = KeyLoc::ThirdPartyPub;
continue;
}
KeyLoc::ThirdPartyPub => {
// try another key and move on
keyloc = KeyLoc::DevPub;
continue;
}
KeyLoc::DevPub => {
// we're out of keys, display a message and try to power down
gfx.msg("Signature check failed, powering down\n\r", &mut cursor);
println!("Signature check failed");
let ticktimer = CSR::new(utra::ticktimer::HW_TICKTIMER_BASE as *mut u32);
let mut power = CSR::new(utra::power::HW_POWER_BASE as *mut u32);
let mut com = CSR::new(utra::com::HW_COM_BASE as *mut u32);
let mut start = ticktimer.rf(utra::ticktimer::TIME0_TIME);
loop {
// every 15 seconds, attempt to send a power down command
// any attempt to re-flash the system must halt the CPU before we time-out to this point!
if ticktimer.rf(utra::ticktimer::TIME0_TIME) - start > 15_000 {
println!("Powering down...");
power.rmwf(utra::power::POWER_STATE, 0);
power.rmwf(utra::power::POWER_SELF, 0);
println!("Public key bytes: {:x?}", pubkey.as_bytes());
if sig.version != 1 {
println!("Warning: mismatch on signature record version numbering. Ignoring and moving on...")
}
let signed_len = sig.signed_len;
let image: &[u8] = unsafe{core::slice::from_raw_parts((xous_img_offset as usize + SIGBLOCK_SIZE) as *const u8, signed_len as usize)};
let ed25519_signature = ed25519_dalek::Signature::from(sig.signature);
use ed25519_dalek::Verifier;
if pubkey.verify(image, &ed25519_signature).is_ok() {
gfx.msg("Signature check passed\n\r", &mut cursor);
println!("Signature check passed");
} else {
gfx.msg("Signature check failed, powering down\n\r", &mut cursor);
println!("Signature check failed");
let ticktimer = CSR::new(utra::ticktimer::HW_TICKTIMER_BASE as *mut u32);
let mut power = CSR::new(utra::power::HW_POWER_BASE as *mut u32);
let mut com = CSR::new(utra::com::HW_COM_BASE as *mut u32);
let mut start = ticktimer.rf(utra::ticktimer::TIME0_TIME);
loop {
// every 15 seconds, attempt to send a power down command
// any attempt to re-flash the system must halt the CPU before we time-out to this point!
if ticktimer.rf(utra::ticktimer::TIME0_TIME) - start > 15_000 {
println!("Powering down...");
power.rmwf(utra::power::POWER_STATE, 0);
power.rmwf(utra::power::POWER_SELF, 0);
// ship mode is the safest mode -- suitable for long-term storage (~years)
com.wfo(utra::com::TX_TX, com_rs::ComState::POWER_SHIPMODE.verb as u32);
while com.rf(utra::com::STATUS_TIP) == 1 {}
let _ = com.rf(utra::com::RX_RX); // discard the RX result
start = ticktimer.rf(utra::ticktimer::TIME0_TIME);
// ship mode is the safest mode -- suitable for long-term storage (~years)
com.wfo(utra::com::TX_TX, com_rs::ComState::POWER_SHIPMODE.verb as u32);
while com.rf(utra::com::STATUS_TIP) == 1 {}
let _ = com.rf(utra::com::RX_RX); // discard the RX result
start = ticktimer.rf(utra::ticktimer::TIME0_TIME);
}
}
}
}
}
}

View file

@ -1,128 +1,128 @@
KEYROM 0 A SLICE_X36Y50 b'ed9040309fce38f4'
KEYROM 0 B SLICE_X36Y50 b'34b83a94e4408416'
KEYROM 0 C SLICE_X36Y50 b'8f088d95d0241a29'
KEYROM 0 D SLICE_X36Y50 b'71976c7c19e9b004'
KEYROM 1 A SLICE_X37Y50 b'23147e30bff2ec9a'
KEYROM 1 B SLICE_X37Y50 b'1fd3c7d928865270'
KEYROM 1 C SLICE_X37Y50 b'69affdc0d64bce09'
KEYROM 1 D SLICE_X37Y50 b'7a5d619fdd90768c'
KEYROM 2 A SLICE_X36Y51 b'e6a75fea68b97646'
KEYROM 2 B SLICE_X36Y51 b'3bbe4fd7491feae7'
KEYROM 2 C SLICE_X36Y51 b'8f1ce05eb6df82cf'
KEYROM 2 D SLICE_X36Y51 b'27262a3adbb299bb'
KEYROM 3 A SLICE_X37Y51 b'f51fe08930b42539'
KEYROM 3 B SLICE_X37Y51 b'fe0f77932c0955be'
KEYROM 3 C SLICE_X37Y51 b'75b2d1f824733c6e'
KEYROM 3 D SLICE_X37Y51 b'd7d7ba4db2a43551'
KEYROM 4 A SLICE_X36Y52 b'01adb0f69b2445b6'
KEYROM 4 B SLICE_X36Y52 b'f9615dc2835077a9'
KEYROM 4 C SLICE_X36Y52 b'48b9726cdadf5f5c'
KEYROM 4 D SLICE_X36Y52 b'b04e43398e8a5a48'
KEYROM 5 A SLICE_X37Y52 b'ff7bd4295aabdd2d'
KEYROM 5 B SLICE_X37Y52 b'71ed1b78bf6abef1'
KEYROM 5 C SLICE_X37Y52 b'711b0d7da395db20'
KEYROM 5 D SLICE_X37Y52 b'bab4a809cb8d5749'
KEYROM 6 A SLICE_X36Y53 b'4d30fac41aa32b0f'
KEYROM 6 B SLICE_X36Y53 b'43b00f6dcac70852'
KEYROM 6 C SLICE_X36Y53 b'ad4003d496e1977f'
KEYROM 6 D SLICE_X36Y53 b'4ae9ec045604171d'
KEYROM 7 A SLICE_X37Y53 b'926d630da7b7a38f'
KEYROM 7 B SLICE_X37Y53 b'ea9dcfbcee0e3e27'
KEYROM 7 C SLICE_X37Y53 b'331310550f7be1a3'
KEYROM 7 D SLICE_X37Y53 b'86654bf903647983'
KEYROM 8 A SLICE_X36Y54 b'5faf7f97fd1adda9'
KEYROM 8 B SLICE_X36Y54 b'bd9e98995dfeb80e'
KEYROM 8 C SLICE_X36Y54 b'ccc154e624fa6d30'
KEYROM 8 D SLICE_X36Y54 b'6d4cf1460bbcc9d7'
KEYROM 9 A SLICE_X37Y54 b'61a5187dac4451d5'
KEYROM 9 B SLICE_X37Y54 b'b0ad0aeed2998bc1'
KEYROM 9 C SLICE_X37Y54 b'f21d761d350fc65c'
KEYROM 9 D SLICE_X37Y54 b'b12550f563825b1e'
KEYROM 10 A SLICE_X36Y55 b'fd44ec8a47c67607'
KEYROM 10 B SLICE_X36Y55 b'6f73609c3f474a99'
KEYROM 10 C SLICE_X36Y55 b'97f3f40b00eff415'
KEYROM 10 D SLICE_X36Y55 b'd9a8030e01d2e969'
KEYROM 11 A SLICE_X37Y55 b'b69db3f2c7383567'
KEYROM 11 B SLICE_X37Y55 b'c84e2d58eed1667f'
KEYROM 11 C SLICE_X37Y55 b'8de4bf137da8b4a5'
KEYROM 11 D SLICE_X37Y55 b'4b44f068e3b6e954'
KEYROM 12 A SLICE_X36Y56 b'9f9dfa17fd8f813b'
KEYROM 12 B SLICE_X36Y56 b'd7e2dc46e49beed5'
KEYROM 12 C SLICE_X36Y56 b'3c147b86326a0df7'
KEYROM 12 D SLICE_X36Y56 b'6de9236fe18c43bb'
KEYROM 13 A SLICE_X37Y56 b'f96f763f484a7293'
KEYROM 13 B SLICE_X37Y56 b'ea9d3dc73170641a'
KEYROM 13 C SLICE_X37Y56 b'2045bb3e568b0ef8'
KEYROM 13 D SLICE_X37Y56 b'2ce220df70dfe05d'
KEYROM 14 A SLICE_X36Y57 b'0fd2db99d978d460'
KEYROM 14 B SLICE_X36Y57 b'83ce09c09327ae22'
KEYROM 14 C SLICE_X36Y57 b'195e32c556a026fd'
KEYROM 14 D SLICE_X36Y57 b'23627d617f5baf71'
KEYROM 15 A SLICE_X37Y57 b'c7f24e5f55a9cca9'
KEYROM 15 B SLICE_X37Y57 b'7820cea9a62feef3'
KEYROM 15 C SLICE_X37Y57 b'baf6949fc5db190d'
KEYROM 15 D SLICE_X37Y57 b'c208af523a7d55ef'
KEYROM 16 A SLICE_X36Y58 b'b1445a38b8cec3ec'
KEYROM 16 B SLICE_X36Y58 b'2e694e04676b83c6'
KEYROM 16 C SLICE_X36Y58 b'33b1fbd89e0b2d53'
KEYROM 16 D SLICE_X36Y58 b'74d20b1bc8765902'
KEYROM 17 A SLICE_X37Y58 b'65bdef7af5c88f77'
KEYROM 17 B SLICE_X37Y58 b'182f425b728098e6'
KEYROM 17 C SLICE_X37Y58 b'26a6e4b72e49a038'
KEYROM 17 D SLICE_X37Y58 b'476e499924be15c0'
KEYROM 18 A SLICE_X36Y59 b'b78c1c5cc2aa57a1'
KEYROM 18 B SLICE_X36Y59 b'31384d4342a6fda5'
KEYROM 18 C SLICE_X36Y59 b'05ae9c252ac885ce'
KEYROM 18 D SLICE_X36Y59 b'c96968631e3f7f78'
KEYROM 19 A SLICE_X37Y59 b'634d2885ce6e5855'
KEYROM 19 B SLICE_X37Y59 b'a3cf9e2e72e6e792'
KEYROM 19 C SLICE_X37Y59 b'581ffd047adcc9ea'
KEYROM 19 D SLICE_X37Y59 b'2f64b2ce422d5531'
KEYROM 20 A SLICE_X36Y60 b'7e329f3ca0aaa48e'
KEYROM 20 B SLICE_X36Y60 b'aea96c4e160d7c23'
KEYROM 20 C SLICE_X36Y60 b'6ae6580d67e7ff89'
KEYROM 20 D SLICE_X36Y60 b'5474386b42cab7f1'
KEYROM 21 A SLICE_X37Y60 b'3f9bd1bd08d4aff4'
KEYROM 21 B SLICE_X37Y60 b'e56106594063c796'
KEYROM 21 C SLICE_X37Y60 b'2195de30ceb285a2'
KEYROM 21 D SLICE_X37Y60 b'6334c328f262238f'
KEYROM 22 A SLICE_X36Y61 b'c7864968fa48d4fb'
KEYROM 22 B SLICE_X36Y61 b'539340a6115a09de'
KEYROM 22 C SLICE_X36Y61 b'5a481886017ce135'
KEYROM 22 D SLICE_X36Y61 b'53ab6dd8014367e1'
KEYROM 23 A SLICE_X37Y61 b'a96ce894e8ef46bc'
KEYROM 23 B SLICE_X37Y61 b'1bb558f3736ff921'
KEYROM 23 C SLICE_X37Y61 b'5f317c906fda756e'
KEYROM 23 D SLICE_X37Y61 b'a09db3281b82fcf1'
KEYROM 24 A SLICE_X36Y62 b'916fb25b3c623029'
KEYROM 24 B SLICE_X36Y62 b'3c36f54ab0b983c3'
KEYROM 24 C SLICE_X36Y62 b'564c5c49176dccd2'
KEYROM 24 D SLICE_X36Y62 b'6b2a7d1cb3402096'
KEYROM 25 A SLICE_X37Y62 b'dfd1cc0ccc9d6375'
KEYROM 25 B SLICE_X37Y62 b'773dc64635af690c'
KEYROM 25 C SLICE_X37Y62 b'87958a06b32192f6'
KEYROM 25 D SLICE_X37Y62 b'a9f627a1e12ff5fb'
KEYROM 26 A SLICE_X36Y63 b'e848ef1676025ddb'
KEYROM 26 B SLICE_X36Y63 b'631c42f2972d8f4e'
KEYROM 26 C SLICE_X36Y63 b'e1ba5f1db6c1213e'
KEYROM 26 D SLICE_X36Y63 b'd0a6beb90ebfa1ad'
KEYROM 27 A SLICE_X37Y63 b'aa6f2108de94b9d7'
KEYROM 27 B SLICE_X37Y63 b'94fdad0d7e5e032a'
KEYROM 27 C SLICE_X37Y63 b'cb3a7ed9fa0c188c'
KEYROM 27 D SLICE_X37Y63 b'd9115aa51962339f'
KEYROM 28 A SLICE_X36Y64 b'88825ff323665a51'
KEYROM 28 B SLICE_X36Y64 b'6e49b5862e6533ac'
KEYROM 28 C SLICE_X36Y64 b'32fed356801273ab'
KEYROM 28 D SLICE_X36Y64 b'37904b87d81a652a'
KEYROM 29 A SLICE_X37Y64 b'4b5361b16868f5bd'
KEYROM 29 B SLICE_X37Y64 b'ba9596094f9e43b9'
KEYROM 29 C SLICE_X37Y64 b'ddabe807f246ff41'
KEYROM 29 D SLICE_X37Y64 b'8815407bf7b4e684'
KEYROM 30 A SLICE_X36Y65 b'0165ea750602f2be'
KEYROM 30 B SLICE_X36Y65 b'3c62683258a88ef9'
KEYROM 30 C SLICE_X36Y65 b'cc0c02f8539bf6d8'
KEYROM 30 D SLICE_X36Y65 b'a1caffc2420bc6de'
KEYROM 31 A SLICE_X37Y65 b'2a2894ffa957b03c'
KEYROM 31 B SLICE_X37Y65 b'958c5490ad6c2e9b'
KEYROM 31 C SLICE_X37Y65 b'f76c75011cdc2737'
KEYROM 31 D SLICE_X37Y65 b'a734aab8e4d7f6eb'
KEYROM 0 A SLICE_X36Y50 b'7139253efdee5437'
KEYROM 0 B SLICE_X36Y50 b'971240e7cb57d092'
KEYROM 0 C SLICE_X36Y50 b'1dd9845c5beaed5f'
KEYROM 0 D SLICE_X36Y50 b'b3b9d3cf5df61115'
KEYROM 1 A SLICE_X37Y50 b'406106417c8c7a65'
KEYROM 1 B SLICE_X37Y50 b'90c050c8b1e6af8c'
KEYROM 1 C SLICE_X37Y50 b'4894ab9eff8c8120'
KEYROM 1 D SLICE_X37Y50 b'b2eebf9478771fc9'
KEYROM 2 A SLICE_X36Y51 b'04286997eaf93401'
KEYROM 2 B SLICE_X36Y51 b'7e96f2c01e044565'
KEYROM 2 C SLICE_X36Y51 b'5a1e7c59ba4eeefb'
KEYROM 2 D SLICE_X36Y51 b'ed892258d64749ae'
KEYROM 3 A SLICE_X37Y51 b'7ea1b6851d9cb941'
KEYROM 3 B SLICE_X37Y51 b'6dfc6d5e02565f98'
KEYROM 3 C SLICE_X37Y51 b'5e3f36393b0d8d31'
KEYROM 3 D SLICE_X37Y51 b'ce2d479fa075d0f6'
KEYROM 4 A SLICE_X36Y52 b'ea97bf9e2e05b6ea'
KEYROM 4 B SLICE_X36Y52 b'a4e6631085dc8aed'
KEYROM 4 C SLICE_X36Y52 b'7eeb7b41817d34bf'
KEYROM 4 D SLICE_X36Y52 b'5912d16b8f528ecd'
KEYROM 5 A SLICE_X37Y52 b'0f1f162a35644658'
KEYROM 5 B SLICE_X37Y52 b'f984ab0d583d99ee'
KEYROM 5 C SLICE_X37Y52 b'ade3aa1429ca0183'
KEYROM 5 D SLICE_X37Y52 b'26bb13534f96d856'
KEYROM 6 A SLICE_X36Y53 b'8a6d0ef306aa6667'
KEYROM 6 B SLICE_X36Y53 b'c2bbdf7002d5be1d'
KEYROM 6 C SLICE_X36Y53 b'567dd7a83e29038d'
KEYROM 6 D SLICE_X36Y53 b'763405f2b1815c60'
KEYROM 7 A SLICE_X37Y53 b'7ceb7ca31ca9613e'
KEYROM 7 B SLICE_X37Y53 b'e075bde3985aa0c9'
KEYROM 7 C SLICE_X37Y53 b'fa698ee2b6dccd3f'
KEYROM 7 D SLICE_X37Y53 b'c5f451b0972f6ed1'
KEYROM 8 A SLICE_X36Y54 b'6f2da448148a8f49'
KEYROM 8 B SLICE_X36Y54 b'140c9ad2ae031c7b'
KEYROM 8 C SLICE_X36Y54 b'01fe3806885c92b9'
KEYROM 8 D SLICE_X36Y54 b'0fabd3bcc7b48917'
KEYROM 9 A SLICE_X37Y54 b'a325c72db086a6f6'
KEYROM 9 B SLICE_X37Y54 b'3bfd6fec12deecca'
KEYROM 9 C SLICE_X37Y54 b'3f1c20a20c7f9634'
KEYROM 9 D SLICE_X37Y54 b'67e4119d7c96a841'
KEYROM 10 A SLICE_X36Y55 b'17d01d48c0af1b80'
KEYROM 10 B SLICE_X36Y55 b'637e8ad69ee66cd3'
KEYROM 10 C SLICE_X36Y55 b'4b92d8a3bed42d84'
KEYROM 10 D SLICE_X36Y55 b'18b8ee879ba38a7e'
KEYROM 11 A SLICE_X37Y55 b'cce61555a1c8dcd6'
KEYROM 11 B SLICE_X37Y55 b'ac96df91741b0e43'
KEYROM 11 C SLICE_X37Y55 b'90ca2278f5a39578'
KEYROM 11 D SLICE_X37Y55 b'0684d8d2a065f6be'
KEYROM 12 A SLICE_X36Y56 b'808d9d0a5a7b01a4'
KEYROM 12 B SLICE_X36Y56 b'd4b3c9e452c72cb3'
KEYROM 12 C SLICE_X36Y56 b'970c458641fce1d1'
KEYROM 12 D SLICE_X36Y56 b'b4648f6136e64267'
KEYROM 13 A SLICE_X37Y56 b'29683729d8d7ee49'
KEYROM 13 B SLICE_X37Y56 b'da772edc07a0f23b'
KEYROM 13 C SLICE_X37Y56 b'8b09fdf54713dc4f'
KEYROM 13 D SLICE_X37Y56 b'84a8ffb1f1d83030'
KEYROM 14 A SLICE_X36Y57 b'7d31c2576a245640'
KEYROM 14 B SLICE_X36Y57 b'26712a039b8a397e'
KEYROM 14 C SLICE_X36Y57 b'a6f8f7be4f11002a'
KEYROM 14 D SLICE_X36Y57 b'8307e7557577111e'
KEYROM 15 A SLICE_X37Y57 b'fad7bc009408da13'
KEYROM 15 B SLICE_X37Y57 b'543fa23206dbe7b8'
KEYROM 15 C SLICE_X37Y57 b'ffcda1667acce717'
KEYROM 15 D SLICE_X37Y57 b'33cc4d7182ae9814'
KEYROM 16 A SLICE_X36Y58 b'4183a9f725df0ea1'
KEYROM 16 B SLICE_X36Y58 b'255004c9126605fd'
KEYROM 16 C SLICE_X36Y58 b'8eb282956cf6f85b'
KEYROM 16 D SLICE_X36Y58 b'32a4abd08e03f3a3'
KEYROM 17 A SLICE_X37Y58 b'5f33a858a287c5d8'
KEYROM 17 B SLICE_X37Y58 b'0197ed73c600a445'
KEYROM 17 C SLICE_X37Y58 b'6ba1e43c71757825'
KEYROM 17 D SLICE_X37Y58 b'b55b5d9ac9534337'
KEYROM 18 A SLICE_X36Y59 b'4ba57b36af113d3d'
KEYROM 18 B SLICE_X36Y59 b'c44455dec99281b1'
KEYROM 18 C SLICE_X36Y59 b'5ff51d04a2e23c93'
KEYROM 18 D SLICE_X36Y59 b'903a750c19dbbd7d'
KEYROM 19 A SLICE_X37Y59 b'de7b79327ea2009f'
KEYROM 19 B SLICE_X37Y59 b'2c83e749de6bdbab'
KEYROM 19 C SLICE_X37Y59 b'c9099a49e0a7962e'
KEYROM 19 D SLICE_X37Y59 b'4e0506ce2c222f53'
KEYROM 20 A SLICE_X36Y60 b'd3547cebff1734b2'
KEYROM 20 B SLICE_X36Y60 b'c77c0610cc2f3391'
KEYROM 20 C SLICE_X36Y60 b'a74034f532b4f128'
KEYROM 20 D SLICE_X36Y60 b'69f1ca4530332a1d'
KEYROM 21 A SLICE_X37Y60 b'50c0a9850d7d9510'
KEYROM 21 B SLICE_X37Y60 b'790e363c1fa363e0'
KEYROM 21 C SLICE_X37Y60 b'5c7ae6a5dc6e0a25'
KEYROM 21 D SLICE_X37Y60 b'a477b153a4dce16d'
KEYROM 22 A SLICE_X36Y61 b'befde63548ca8db3'
KEYROM 22 B SLICE_X36Y61 b'8dd6865f2a7d2c84'
KEYROM 22 C SLICE_X36Y61 b'a340c5dd4ee12769'
KEYROM 22 D SLICE_X36Y61 b'53c4ff8c438a27a7'
KEYROM 23 A SLICE_X37Y61 b'a71e06f0e983c86d'
KEYROM 23 B SLICE_X37Y61 b'874dfb61381f6aed'
KEYROM 23 C SLICE_X37Y61 b'92a40f86bad5a032'
KEYROM 23 D SLICE_X37Y61 b'fdd5969e64d3c1bc'
KEYROM 24 A SLICE_X36Y62 b'613906ed3d19211f'
KEYROM 24 B SLICE_X36Y62 b'800fbaba78d3d7f4'
KEYROM 24 C SLICE_X36Y62 b'f7f74840480f9d67'
KEYROM 24 D SLICE_X36Y62 b'09bac089a69da8c3'
KEYROM 25 A SLICE_X37Y62 b'882292c3377103d2'
KEYROM 25 B SLICE_X37Y62 b'aaebf2003815bf39'
KEYROM 25 C SLICE_X37Y62 b'8afaa0c9b4b61b5c'
KEYROM 25 D SLICE_X37Y62 b'42682e75cc042514'
KEYROM 26 A SLICE_X36Y63 b'aa394990a60fafdc'
KEYROM 26 B SLICE_X36Y63 b'bad8c1e3576df432'
KEYROM 26 C SLICE_X36Y63 b'11e72091a52b86dd'
KEYROM 26 D SLICE_X36Y63 b'cb67b8e302736449'
KEYROM 27 A SLICE_X37Y63 b'821a9549e8b1abe8'
KEYROM 27 B SLICE_X37Y63 b'ed911d6cf4a2911e'
KEYROM 27 C SLICE_X37Y63 b'400c3f94f9068455'
KEYROM 27 D SLICE_X37Y63 b'65f6d884b2053c8e'
KEYROM 28 A SLICE_X36Y64 b'b3f027e3ac1624c5'
KEYROM 28 B SLICE_X36Y64 b'35829056dfe53606'
KEYROM 28 C SLICE_X36Y64 b'ae55134511cb97f9'
KEYROM 28 D SLICE_X36Y64 b'4f1f9333a74027aa'
KEYROM 29 A SLICE_X37Y64 b'6efeeab089a09501'
KEYROM 29 B SLICE_X37Y64 b'7b2e802098b11a60'
KEYROM 29 C SLICE_X37Y64 b'7f63244980975d0d'
KEYROM 29 D SLICE_X37Y64 b'0eccde94c05979f7'
KEYROM 30 A SLICE_X36Y65 b'4ac3eecf185df444'
KEYROM 30 B SLICE_X36Y65 b'75e82366f18c159f'
KEYROM 30 C SLICE_X36Y65 b'aeffd4c4b8974f63'
KEYROM 30 D SLICE_X36Y65 b'64637baa3d0ff963'
KEYROM 31 A SLICE_X37Y65 b'f59b2721520d2513'
KEYROM 31 B SLICE_X37Y65 b'f004c1a5acb4a035'
KEYROM 31 C SLICE_X37Y65 b'4200431f9a9fe273'
KEYROM 31 D SLICE_X37Y65 b'9e17232480cc6907'

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2021-08-06 13:55:31]]></description>
<description><![CDATA[Litex SoC 2021-08-14 19:53:02]]></description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
@ -1238,10 +1238,10 @@ register to disable individual events.]]></description>
<register>
<name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``890b90e7``, so this value is 2299236583, which should be enough to check out
``94b0064b``, so this value is 2494563915, which should be enough to check out
the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0x890b90e7</resetValue>
<resetValue>0x94b0064b</resetValue>
<size>32</size>
<fields>
<field>
@ -1258,7 +1258,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset>
<resetValue>0x46</resetValue>
<resetValue>0x48</resetValue>
<size>32</size>
<fields>
<field>
@ -3584,7 +3584,7 @@ inject too fast.]]></description>
<name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset>
<resetValue>0x4f340196</resetValue>
<resetValue>0x356326ec</resetValue>
<size>32</size>
<fields>
<field>
@ -3599,7 +3599,7 @@ inject too fast.]]></description>
<name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset>
<resetValue>0x77c237e8</resetValue>
<resetValue>0x6d0d21ea</resetValue>
<size>32</size>
<fields>
<field>

Binary file not shown.

View file

@ -167,4 +167,4 @@ pub(crate) enum Return {
// small wart -- we have to reset the size of a modal to max size for resize computations
// reveal the max size globally, since it's a constant
pub const MODAL_Y_MAX: i16 = 450; // in absolute screen coords, not relative to top pad
pub const MODAL_Y_MAX: i16 = 350; // in absolute screen coords, not relative to top pad

View file

@ -755,6 +755,7 @@ pub struct Notification {
pub action_conn: xous::CID,
pub action_opcode: u32,
pub is_password: bool,
pub manual_dismiss: bool,
}
impl Notification {
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
@ -762,6 +763,7 @@ impl Notification {
action_conn,
action_opcode,
is_password: false,
manual_dismiss: true,
}
}
pub fn set_is_password(&mut self, setting: bool) {
@ -770,57 +772,66 @@ impl Notification {
// set because they can't achieve a high enough trust level.
self.is_password = setting;
}
pub fn set_manual_dismiss(&mut self, setting: bool) {
self.manual_dismiss = setting;
}
}
impl ActionApi for Notification {
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
glyph_height + margin * 2 + 5
if self.manual_dismiss {
glyph_height + margin * 2 + 5
} else {
margin + 5
}
}
fn redraw(&self, at_height: i16, modal: &Modal) {
// prime a textview with the correct general style parameters
let mut tv = TextView::new(
modal.canvas,
TextBounds::BoundingBox(Rectangle::new_coords(0, 0, 1, 1))
);
tv.ellipsis = true;
tv.style = modal.style;
tv.invert = self.is_password;
tv.draw_border= false;
tv.margin = Point::new(0, 0,);
tv.insertion = None;
if self.manual_dismiss {
// prime a textview with the correct general style parameters
let mut tv = TextView::new(
modal.canvas,
TextBounds::BoundingBox(Rectangle::new_coords(0, 0, 1, 1))
);
tv.ellipsis = true;
tv.style = modal.style;
tv.invert = self.is_password;
tv.draw_border= false;
tv.margin = Point::new(0, 0,);
tv.insertion = None;
tv.bounds_computed = None;
tv.bounds_hint = TextBounds::GrowableFromTl(
Point::new(modal.margin, at_height + modal.margin * 2),
(modal.canvas_width - modal.margin * 2) as u16
);
write!(tv, "{}", t!("notification.dismiss", xous::LANG)).unwrap();
modal.gam.bounds_compute_textview(&mut tv).expect("couldn't simulate text size");
let textwidth = if let Some(bounds) = tv.bounds_computed {
bounds.br.x - bounds.tl.x
} else {
modal.canvas_width - modal.margin * 2
};
let offset = (modal.canvas_width - textwidth) / 2;
tv.bounds_computed = None;
tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new(
Point::new(offset, at_height + modal.margin * 2),
Point::new(modal.canvas_width - modal.margin, at_height + modal.line_height + modal.margin * 2)
));
modal.gam.post_textview(&mut tv).expect("couldn't post tv");
tv.bounds_computed = None;
tv.bounds_hint = TextBounds::GrowableFromTl(
Point::new(modal.margin, at_height + modal.margin * 2),
(modal.canvas_width - modal.margin * 2) as u16
);
write!(tv, "{}", t!("notification.dismiss", xous::LANG)).unwrap();
modal.gam.bounds_compute_textview(&mut tv).expect("couldn't simulate text size");
let textwidth = if let Some(bounds) = tv.bounds_computed {
bounds.br.x - bounds.tl.x
} else {
modal.canvas_width - modal.margin * 2
};
let offset = (modal.canvas_width - textwidth) / 2;
tv.bounds_computed = None;
tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new(
Point::new(offset, at_height + modal.margin * 2),
Point::new(modal.canvas_width - modal.margin, at_height + modal.line_height + modal.margin * 2)
));
modal.gam.post_textview(&mut tv).expect("couldn't post tv");
// divider lines
let color = if self.is_password {
PixelColor::Light
} else {
PixelColor::Dark
};
// divider lines
let color = if self.is_password {
PixelColor::Light
} else {
PixelColor::Dark
};
modal.gam.draw_line(modal.canvas, Line::new_with_style(
Point::new(modal.margin, at_height + modal.margin),
Point::new(modal.canvas_width - modal.margin, at_height + modal.margin),
DrawStyle::new(color, color, 1))
modal.gam.draw_line(modal.canvas, Line::new_with_style(
Point::new(modal.margin, at_height + modal.margin),
Point::new(modal.canvas_width - modal.margin, at_height + modal.margin),
DrawStyle::new(color, color, 1))
).expect("couldn't draw entry line");
}
}
fn key_action(&mut self, k: char) -> (Option<xous_ipc::String::<512>>, bool) {
log::trace!("key_action: {}", k);
@ -829,8 +840,10 @@ impl ActionApi for Notification {
// ignore null messages
}
_ => {
send_message(self.action_conn, xous::Message::new_scalar(self.action_opcode as usize, 0, 0, 0, 0)).expect("couldn't pass on dismissal");
return(None, true)
if self.manual_dismiss {
send_message(self.action_conn, xous::Message::new_scalar(self.action_opcode as usize, 0, 0, 0, 0)).expect("couldn't pass on dismissal");
return(None, true)
}
}
}
(None, false)
@ -1109,7 +1122,7 @@ fn recompute_canvas(modal: &mut Modal, action: ActionType, top_text: Option<&str
if let Some(top_str) = top_text {
let mut top_tv = TextView::new(modal.canvas,
TextBounds::GrowableFromTl(
Point::new(modal.margin, total_height),
Point::new(modal.margin, modal.margin),
(modal.canvas_width - modal.margin * 2) as u16
));
top_tv.draw_border = false;
@ -1119,16 +1132,18 @@ fn recompute_canvas(modal: &mut Modal, action: ActionType, top_text: Option<&str
top_tv.invert = modal.inverted;
// specify a clip rect that's the biggest possible allowed. If we don't do this, the current canvas
// bounds are used, and the operation will fail if the text has to get bigger.
top_tv.clip_rect = Some(Rectangle::new(Point::new(0, 0), Point::new(current_bounds.x, crate::api::MODAL_Y_MAX)));
top_tv.clip_rect = Some(Rectangle::new(Point::new(0, 0), Point::new(current_bounds.x, crate::api::MODAL_Y_MAX - 2 * modal.line_height)));
write!(top_tv.text, "{}", top_str).unwrap();
log::trace!("posting top tv: {:?}", top_tv);
modal.gam.bounds_compute_textview(&mut top_tv).expect("couldn't simulate top text size");
if let Some(bounds) = top_tv.bounds_computed {
log::trace!("top_tv bounds computed {}", bounds.br.y - bounds.tl.y);
total_height += bounds.br.y - bounds.tl.y;
} else {
log::error!("couldn't compute height for modal top_text: {:?}", top_tv);
panic!("couldn't compute height for modal top_text");
log::warn!("couldn't compute height for modal top_text: {:?}", top_tv);
// probably should find a better way to deal with this.
total_height += crate::api::MODAL_Y_MAX - (modal.line_height * 2);
}
modal.top_text = Some(top_tv);
}
@ -1154,7 +1169,7 @@ fn recompute_canvas(modal: &mut Modal, action: ActionType, top_text: Option<&str
bot_tv.invert = modal.inverted;
// specify a clip rect that's the biggest possible allowed. If we don't do this, the current canvas
// bounds are used, and the operation will fail if the text has to get bigger.
bot_tv.clip_rect = Some(Rectangle::new(Point::new(0, 0), Point::new(current_bounds.x, crate::api::MODAL_Y_MAX)));
bot_tv.clip_rect = Some(Rectangle::new(Point::new(0, 0), Point::new(current_bounds.x, crate::api::MODAL_Y_MAX - 2 * modal.line_height)));
write!(bot_tv.text, "{}", bot_str).unwrap();
log::trace!("posting bot tv: {:?}", bot_tv);
@ -1289,8 +1304,19 @@ impl<'a> Modal<'a> {
if do_redraw {
self.gam.post_textview(&mut tv).expect("couldn't draw text");
if let Some(bounds) = tv.bounds_computed {
cur_height += bounds.br.y - bounds.tl.y;
self.top_memoized_height = Some(bounds.br.y - bounds.tl.y);
let y = bounds.br.y - bounds.tl.y;
let y_clip = if y > MODAL_Y_MAX - self.line_height * 3 {
log::warn!("overside text, clipping back {}", MODAL_Y_MAX - (self.line_height * 2));
MODAL_Y_MAX - (self.line_height * 2)
} else {
y
};
cur_height += y_clip;
log::trace!("top_tv height: {}", y_clip);
self.top_memoized_height = Some(y_clip);
} else {
log::warn!("text bounds didn't compute setting to max");
self.top_memoized_height = Some(MODAL_Y_MAX - (self.line_height * 2));
}
self.top_dirty = false;
} else {

View file

@ -224,7 +224,10 @@ fn xmain() -> ! {
br
));
} else {
tv.bounds_computed = None;
tv.bounds_computed = Some(Rectangle::new(
clip_rect.tl(),
br
));
}
},
TextBounds::GrowableFromTl(tl, width) => {
@ -277,8 +280,11 @@ fn xmain() -> ! {
));
log::trace!("intersects, bounds_computed: {:?}", tv.bounds_computed);
} else {
log::trace!("does not intersect, clip_rect: {:?}, br: {:?}", clip_rect, br);
tv.bounds_computed = None;
log::warn!("does not intersect, clip_rect: {:?}, br: {:?}", clip_rect, br);
tv.bounds_computed = Some(Rectangle::new(
tl,
clip_rect.br()
));
}
},
TextBounds::GrowableFromBl(bl, width) => {
@ -331,7 +337,10 @@ fn xmain() -> ! {
Point::new(bl.x + finalwidth, bl.y)
));
} else {
tv.bounds_computed = None
tv.bounds_computed = Some(Rectangle::new(
clip_rect.tl(),
Point::new(bl.x + finalwidth, bl.y)
));
}
},
}

View file

@ -1,5 +1,8 @@
pub(crate) const SERVER_NAME_JTAG: &str = "_JTAG Server_";
#[allow(dead_code)]
pub const XCS750_IDCODE: u32 = 0x362F093;
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub struct EfuseRecord {
pub key: [u8; 32],

View file

@ -101,6 +101,10 @@ impl Jtag {
let erec = self.efuse_fetch().expect("couldn't read efuse record");
if (erec.cntl & 0x20) != 0 { Ok(true) } else { Ok(false) }
}
pub fn get_raw_control_bits(&self) -> Result<u8, xous::Error> {
let erec = self.efuse_fetch().expect("couldn't read efuse record");
Ok(erec.cntl)
}
fn mod_ctl_efuse(&self, bits_to_set: u8) -> Result<bool, xous::Error> {
let erec = self.efuse_fetch().expect("couldn't read efuse record");
let response = send_message(self.conn,

View file

@ -62,7 +62,7 @@ utralib = { path = "../../utralib"}
[features]
hazardous-debug = [] # this feature enables the printing of secret materials for debug purposes
default = []
default = ["hazardous-debug"]
[lib]
test = true

View file

@ -90,9 +90,9 @@
"en-audio": "Verification failed, aborting"
},
"rootkeys.init.fail_key": {
"en": "FPGA key is wrong,\nborting!",
"en": "FPGA key is wrong:\nPerhaps the update\npassword was entered\nincorrectly?",
"zh": "*missing*正在初始化失败,中止!",
"en-audio": "FPGA key is wrong, aborting"
"en-audio": "FPGA key is wrong, perhaps the update password was entered incorrectly?"
},
"rootkeys.init.fail_burn": {
"en": "FLASH write problem,\naborting!",
@ -109,6 +109,91 @@
"zh": "这无法撤消,要继续吗?",
"en-audio": "This cannot be undone. Continue?"
},
"rootkeys.gwup.no_update_found": {
"en": "No valid update found,\naborting!",
"zh": "未找到有效更新,正在中止!",
"en-audio": "No valid update found, aborting"
},
"rootkeys.gwup.inspecting": {
"en": "Inspecting update,\nplease wait...",
"zh": "正在检查比特流,请稍候...",
"en-audio": "Inspecting update, please wait."
},
"rootkeys.gwup.viewinfo_ss": {
"en": "Self-signed image found.\nReview details?",
"zh": "**missing**查看更新的详细信息?",
"en-audio": "Self-signed image found. Review details?"
},
"rootkeys.gwup.viewinfo_tp": {
"en": "Third party image found.\nReview details?",
"zh": "**missing**查看更新的详细信息?",
"en-audio": "Self-signed image found. Review details?"
},
"rootkeys.gwup.viewinfo_dk": {
"en": "Devkey image found.\nReview details?",
"zh": "**missing**查看更新的详细信息?",
"en-audio": "Self-signed image found. Review details?"
},
"rootkeys.gwup.details": {
"en": "All details",
"zh": "所有细节",
"en-audio": "All details"
},
"rootkeys.gwup.short": {
"en": "Short summary",
"zh": "简短的摘要",
"en-audio": "Short summary"
},
"rootkeys.gwup.none": {
"en": "Skip",
"zh": "跳过这步",
"en-audio": "Skip"
},
"rootkeys.gwup.proceed_confirm": {
"en": "Proceed with update?",
"zh": "继续更新?",
"en-audio": "Proceed with update?"
},
"rootkeys.gwup.yes": {
"en": "Yes",
"zh": "确定",
"en-audio": "Yes"
},
"rootkeys.gwup.no": {
"en": "No",
"zh": "取消",
"en-audio": "No"
},
"rootkeys.gwup_starting": {
"en": "Updating gateware.\nThis takes a few minutes.\nDo not reset or sleep!",
"zh": "现在正在初始化\n可能还要等一下\n不要重置或睡眠!\n",
"en-audio": "Updating gateware. This may take a while, don't reset or sleep the device."
},
"rootkeys.get_update_password": {
"en": "Password request\nSoftware update key\nSecurity: Critical\nWhy: Gateware update",
"zh": "输入密码\n软件更新\n安全含义:至关重要 ",
"en-audio": "Enter update password, in order to authorize a gateware update."
},
"rootkeys.gwup.finished": {
"en": "Gateware update finished.\nReboot to apply.",
"zh": "更新完成重启应用",
"en-audio": "Gateware update finished. Reboot to apply."
},
"rootkeys.get_signing_password": {
"en": "Password request\nSoftware update key\nSecurity: Critical\nWhy: Sign Xous",
"zh": "输入密码\n软件更新\n安全含义:至关重要 ",
"en-audio": "Enter update password, in order to authorize a gateware update."
},
"rootkeys.signxous.finished": {
"en": "Xous signing finished.\nReboot to apply.",
"zh": "更新完成重启应用",
"en-audio": "Xous signing finished. Reboot to apply."
},
"rootkeys.policy_request": {
"en": "Please pick a password\nretention policy:",
"zh": "请选择密码保留策略:",
"en-audio": "Please pick a passowrd retention policy."
},
"rootkeys.policy_clear": {
"en": "Clear after use",
"zh": "使用后删除",

View file

@ -11,6 +11,10 @@ pub(crate) enum Opcode {
KeysInitialized,
/// check that the digital signature on the gateware
CheckGatewareSignature,
/// check if the efuse has been locked down
IsEfuseSecured,
/// quick check to see if the JTAG can read its IDCODE
IsJtagWorking,
TestUx,
@ -20,15 +24,30 @@ pub(crate) enum Opcode {
UxConfirmation,
UxInitRequestPassword,
UxInitPasswordReturn,
/// provision a gateware update with our secret data
UxUpdateGateware,
UxUpdateGwCheckSig,
UxUpdateGwShowInfo,
UxUpdateGwShowLog,
UxUpdateGwShowStatus,
UxUpdateGwConfirm,
UxUpdateGwDecidePassword,
UxUpdateGwPasswordPolicy,
UxUpdateGwRun,
/// self-sign kernel/loader
UxSelfSignXous,
UxSignXousPasswordPolicy,
UxSignXousRun,
// General Ux calls
UxGutter, // NOP for UX calls that require a destination
UxGetPolicy,
UxPolicyReturn,
UxTryReboot,
UxDoReboot,
/// provision a gateware update with our secret data
UxUpdateGateware,
/// self-sign kernel/loader
UxSelfSignXous,
/// UX opcodes
MenuRedraw,
MenuKeys,
@ -43,7 +62,7 @@ pub(crate) enum Opcode {
Quit
}
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive, PartialEq, Eq)]
pub enum PasswordRetentionPolicy {
AlwaysKeep,
EraseOnSuspend,

File diff suppressed because it is too large Load diff

View file

@ -102,12 +102,7 @@ impl RootKeys {
}
/// this initiates an attempt to update passwords. User must unlock their device first, and can cancel out if not expected.
pub fn try_update_password(&mut self, which: PasswordType) -> Result<(), xous::Error> {
unimplemented!();
}
//// initiates a self-signing of the firmwares using the ed25519 private key stored in the enclave
pub fn self_sign(&mut self, which: ImageType) -> Result<(), xous::Error> {
pub fn try_update_password(&mut self, _which: PasswordType) -> Result<(), xous::Error> {
unimplemented!();
}
@ -131,6 +126,37 @@ impl RootKeys {
}
}
pub fn is_efuse_secured(&self) -> Result<Option<bool>, xous::Error> {
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::IsEfuseSecured.to_usize().unwrap(), 0, 0, 0, 0)
)?;
if let xous::Result::Scalar1(result) = response {
if result == 2 {
Ok(None)
} else if result == 1 {
Ok(Some(true))
} else {
Ok(Some(false))
}
} else {
Err(xous::Error::InternalError)
}
}
pub fn is_jtag_working(&self) -> Result<bool, xous::Error> {
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::IsJtagWorking.to_usize().unwrap(), 0, 0, 0, 0)
)?;
if let xous::Result::Scalar1(result) = response {
if result == 1 {
Ok(true)
} else {
Ok(false)
}
} else {
Err(xous::Error::InternalError)
}
}
pub fn test_ux(&mut self, arg: usize) {
send_message(self.conn,
Message::new_scalar(Opcode::TestUx.to_usize().unwrap(),

View file

@ -12,6 +12,8 @@ use gam::modal::*;
use gam::menu::*;
use locales::t;
use std::format;
use std::str;
#[cfg(any(target_os = "none", target_os = "xous"))]
mod implementation;
@ -21,6 +23,54 @@ use implementation::*;
#[cfg(any(target_os = "none", target_os = "xous"))]
mod bcrypt;
pub enum SignatureResult {
SelfSignOk,
ThirdPartyOk,
DevKeyOk,
Invalid,
}
#[allow(dead_code)]
pub enum GatewareRegion {
Boot,
Staging,
}
/// An "easily" parseable metadata structure in flash. There's nothing that guarantees the authenticity
/// of the metadata in and of itself, other than the digital signature that wraps the entire gateware record.
/// Thus we're relying on the person who signs the gateware to not inject false data here.
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct MetadataInFlash {
pub magic: u32, // 0x6174656d 'atem'
pub version: u32,
/// git data, but formatted as binary integers
pub git_additional: u32, // commits beyond the tag
pub git_rev: u32,
pub git_min: u32,
pub git_maj: u32,
pub git_commit: u32,
/// md5sum of the dummy-encrypted source file; not meant to be secure, just for human-ID purposes
pub bin_checksum: [u8; 16],
/// md5sum of 'betrusted_soc.py'
pub src_checksum: [u8; 16],
/// date as free-form string (for human readable purposes)
pub date_len: u32,
pub date_str: [u8; 64],
/// the host on which the image was built
pub host_len: u32,
pub host_str: [u8; 64],
/// git tag info as a free-form string
pub tag_len: u32,
pub tag_str: [u8; 64],
/// git log info of the last commit, as a free-form string.
pub log_len: u32,
pub log_str: [u8; 512],
/// status of the build tree, as a free-form string.
pub status_len: u32,
pub status_str: [u8; 1024],
}
// a stub to try to avoid breaking hosted mode for as long as possible.
#[cfg(not(any(target_os = "none", target_os = "xous")))]
mod implementation {
@ -32,12 +82,14 @@ mod implementation {
use crate::api::*;
use gam::{ActionType, ProgressBar};
use num_traits::*;
use crate::{SignatureResult, GatewareRegion, MetadataInFlash};
#[allow(dead_code)]
pub struct RootKeys {
password_type: Option<PasswordType>,
jtag: jtag::Jtag,
xns: xous_names::XousNames,
ticktimer: ticktimer_server::Ticktimer,
}
#[allow(dead_code)]
@ -50,6 +102,7 @@ mod implementation {
xns,
// must occupy tihs connection for the system to boot properly
jtag,
ticktimer: ticktimer_server::Ticktimer::new().unwrap(),
}
}
pub fn suspend(&self) {
@ -66,7 +119,7 @@ mod implementation {
pub fn set_ux_password_type(&mut self, cur_type: Option<PasswordType>) {
self.password_type = cur_type;
}
pub fn is_initialized(&self) -> bool {false}
pub fn is_initialized(&self) -> bool {true}
pub fn setup_key_init(&mut self) {}
pub fn do_key_init(&mut self, rootkeys_modal: &mut Modal, main_cid: xous::CID) -> Result<(), RootkeyResult> {
let mut progress_action = Slider::new(main_cid, Opcode::UxGutter.to_u32().unwrap(),
@ -100,6 +153,40 @@ mod implementation {
pub fn test(&mut self, rootkeys_modal: &mut Modal, main_cid: xous::CID) -> Result<(), RootkeyResult> {
Ok(())
}
pub fn is_jtag_working(&self) -> bool {false}
pub fn is_efuse_secured(&self) -> Option<bool> {None}
pub fn check_gateware_signature(&mut self, region_enum: GatewareRegion) -> SignatureResult {
log::info!("faking gateware check...");
self.ticktimer.sleep_ms(4000).unwrap();
log::info!("done");
SignatureResult::DevKeyOk
}
pub fn is_pcache_update_password_valid(&self) -> bool {
false
}
pub fn fetch_gw_metadata(&self, _region_enum: GatewareRegion) -> MetadataInFlash {
MetadataInFlash {
magic: 0x6174656d,
version: 1,
git_additional: 27,
git_rev: 2,
git_min: 8,
git_maj: 0,
git_commit: 0x12345678,
bin_checksum: [0; 16],
src_checksum: [0; 16],
date_len: 26,
date_str: [50, 48, 50, 49, 45, 48, 56, 45, 49, 50, 32, 50, 50, 58, 49, 53, 58, 53, 51, 46, 56, 49, 55, 51, 53, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
host_len: 14,
host_str: [98, 117, 110, 110, 105, 101, 45, 100, 101, 115, 107, 116, 111, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
tag_len: 19,
tag_str: [118, 48, 46, 56, 46, 50, 45, 55, 49, 45, 103, 102, 102, 98, 97, 52, 55, 102, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
log_len: 203,
log_str: [99, 111, 109, 109, 105, 116, 32, 102, 102, 98, 97, 52, 55, 102, 52, 98, 102, 55, 99, 52, 51, 50, 55, 54, 55, 50, 50, 56, 102, 101, 99, 52, 51, 53, 97, 56, 56, 48, 54, 54, 55, 53, 101, 52, 102, 49, 102, 10, 65, 117, 116, 104, 111, 114, 58, 32, 98, 117, 110, 110, 105, 101, 32, 60, 98, 117, 110, 110, 105, 101, 64, 107, 111, 115, 97, 103, 105, 46, 99, 111, 109, 62, 10, 68, 97, 116, 101, 58, 32, 32, 32, 84, 104, 117, 32, 65, 117, 103, 32, 49, 50, 32, 48, 52, 58, 52, 49, 58, 53, 49, 32, 50, 48, 50, 49, 32, 43, 48, 56, 48, 48, 10, 10, 32, 32, 32, 32, 109, 111, 100, 105, 102, 121, 32, 98, 111, 111, 116, 32, 116, 111, 32, 100, 111, 32, 102, 97, 108, 108, 98, 97, 99, 107, 32, 111, 110, 32, 115, 105, 103, 110, 97, 116, 117, 114, 101, 115, 10, 10, 77, 9, 98, 111, 111, 116, 47, 98, 101, 116, 114, 117, 115, 116, 101, 100, 45, 98, 111, 111, 116, 47, 115, 114, 99, 47, 109, 97, 105, 110, 46, 114, 115, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
status_len: 512,
status_str: [79, 110, 32, 98, 114, 97, 110, 99, 104, 32, 109, 97, 105, 110, 10, 89, 111, 117, 114, 32, 98, 114, 97, 110, 99, 104, 32, 105, 115, 32, 117, 112, 32, 116, 111, 32, 100, 97, 116, 101, 32, 119, 105, 116, 104, 32, 39, 111, 114, 105, 103, 105, 110, 47, 109, 97, 105, 110, 39, 46, 10, 10, 67, 104, 97, 110, 103, 101, 115, 32, 110, 111, 116, 32, 115, 116, 97, 103, 101, 100, 32, 102, 111, 114, 32, 99, 111, 109, 109, 105, 116, 58, 10, 32, 32, 40, 117, 115, 101, 32, 34, 103, 105, 116, 32, 97, 100, 100, 32, 60, 102, 105, 108, 101, 62, 46, 46, 46, 34, 32, 116, 111, 32, 117, 112, 100, 97, 116, 101, 32, 119, 104, 97, 116, 32, 119, 105, 108, 108, 32, 98, 101, 32, 99, 111, 109, 109, 105, 116, 116, 101, 100, 41, 10, 32, 32, 40, 117, 115, 101, 32, 34, 103, 105, 116, 32, 114, 101, 115, 116, 111, 114, 101, 32, 60, 102, 105, 108, 101, 62, 46, 46, 46, 34, 32, 116, 111, 32, 100, 105, 115, 99, 97, 114, 100, 32, 99, 104, 97, 110, 103, 101, 115, 32, 105, 110, 32, 119, 111, 114, 107, 105, 110, 103, 32, 100, 105, 114, 101, 99, 116, 111, 114, 121, 41, 10, 32, 32, 40, 99, 111, 109, 109, 105, 116, 32, 111, 114, 32, 100, 105, 115, 99, 97, 114, 100, 32, 116, 104, 101, 32, 117, 110, 116, 114, 97, 99, 107, 101, 100, 32, 111, 114, 32, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 32, 105, 110, 32, 115, 117, 98, 109, 111, 100, 117, 108, 101, 115, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 97, 112, 112, 101, 110, 100, 95, 99, 115, 114, 46, 112, 121, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 98, 101, 116, 114, 117, 115, 116, 101, 100, 95, 115, 111, 99, 46, 112, 121, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 98, 111, 111, 116, 47, 98, 101, 116, 114, 117, 115, 116, 101, 100, 45, 98, 111, 111, 116, 47, 97, 115, 115, 101, 109, 98, 108, 101, 46, 115, 104, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 98, 111, 111, 116, 95, 116, 101, 115, 116, 46, 112, 121, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 98, 117, 105, 108, 100, 45, 100, 111, 99, 115, 46, 115, 104, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 99, 104, 101, 99, 107, 45, 116, 105, 109, 105, 110, 103, 46, 115, 104, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 99, 111, 109, 112, 105, 108, 101, 114, 95, 114, 116, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 101, 110, 99, 114, 121, 112, 116, 45, 98, 105, 116, 115, 116, 114, 101, 97, 109, 45, 112, 121, 116, 104, 111, 110, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 103, 97, 116, 101, 119, 97, 114, 101, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 108, 105, 116, 101, 100, 114, 97, 109, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 108, 105, 116, 101, 115, 99, 111, 112, 101, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 108, 105, 116, 101, 120, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 109, 105, 103, 101, 110, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 111, 112, 101, 110, 116, 105, 116, 97, 110, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 112, 121, 115, 101, 114, 105, 97, 108, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 112, 121, 116, 104, 111, 110, 100, 97, 116, 97, 45, 99, 112, 117, 45, 118, 101, 120, 114, 105, 115, 99, 118, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102, 105, 101, 100, 58, 32, 32, 32, 100, 101, 112, 115, 47, 114, 111, 109, 45, 108, 111, 99, 97, 116, 101, 32, 40, 109, 111, 100, 105, 102, 105, 101, 100, 32, 99, 111, 110, 116, 101, 110, 116, 41, 10, 9, 109, 111, 100, 105, 102],
}
}
}
}
@ -165,6 +252,7 @@ fn xmain() -> ! {
Opcode::MenuRedraw.to_u32().unwrap(),
Opcode::MenuKeys.to_u32().unwrap(),
Opcode::MenuDrop.to_u32().unwrap());
let mut policy_followup_action: Option<usize> = None;
let mut password_action = TextEntry {
is_password: true,
@ -208,6 +296,24 @@ fn xmain() -> ! {
xous::return_scalar(msg.sender, 0).unwrap();
}
}),
Some(Opcode::IsEfuseSecured) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
if let Some(secured) = keys.is_efuse_secured() {
if secured {
xous::return_scalar(msg.sender, 1).unwrap();
} else {
xous::return_scalar(msg.sender, 0).unwrap();
}
} else {
xous::return_scalar(msg.sender, 2).unwrap();
}
}),
Some(Opcode::IsJtagWorking) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
if keys.is_jtag_working() {
xous::return_scalar(msg.sender, 1).unwrap();
} else {
xous::return_scalar(msg.sender, 0).unwrap();
}
}),
// UX flow opcodes
Some(Opcode::UxTryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, {
@ -236,6 +342,7 @@ fn xmain() -> ! {
// - self-signing public key
// - user root key
// - pepper
dismiss_modal_action.set_manual_dismiss(true); // because this can be side-effected from prior Ux arcs
if keys.is_initialized() {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
@ -334,6 +441,8 @@ fn xmain() -> ! {
// this routine will update the rootkeys_modal with the current Ux state
let result = keys.do_key_init(&mut rootkeys_modal, main_cid);
// the stop emoji, when sent to the slider action bar in progress mode, will cause it to close and relinquish focus
rootkeys_modal.key_event(['🛑', '\u{0000}', '\u{0000}', '\u{0000}']);
log::info!("set_ux_password result: {:?}", result);
@ -450,11 +559,350 @@ fn xmain() -> ! {
).expect("couldn't initiate dialog box");
}
Some(Opcode::UxUpdateGateware) => {
unimplemented!();
// steps:
// - check update signature "Inspecting gateware update, this will take a moment..."
// - if no signature found: "No valid update found! (ok -> exit out)"
// - inform user of signature status "Gatware signed with foo, do you want to see the metadata? (quick/all/no)"
// - option to show metadata (multiple pages)
// - proceed with update question "Proceed with update? (yes/no)"
// - do the update
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
dismiss_modal_action.set_manual_dismiss(false);
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.gwup.inspecting", xous::LANG)), false,
None, true, None);
rootkeys_modal.activate();
rootkeys_modal.redraw(); // the first raise requires a redraw to setup the memoized sizes
send_message(main_cid,
xous::Message::new_scalar(Opcode::UxUpdateGwCheckSig.to_usize().unwrap(), 0, 0, 0, 0)
).unwrap();
}
Some(Opcode::UxUpdateGwCheckSig) => {
let mut confirm_radiobox = gam::modal::RadioButtons::new(
main_cid,
Opcode::UxUpdateGwShowInfo.to_u32().unwrap()
);
confirm_radiobox.is_password = true;
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.gwup.short", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.gwup.details", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.gwup.none", xous::LANG)));
dismiss_modal_action.set_manual_dismiss(true); // this is a tricky bit of a side-effect we have to manage. could be done better...
let prompt = match keys.check_gateware_signature(GatewareRegion::Staging) {
SignatureResult::SelfSignOk => t!("rootkeys.gwup.viewinfo_ss", xous::LANG),
SignatureResult::ThirdPartyOk => t!("rootkeys.gwup.viewinfo_tp", xous::LANG),
SignatureResult::DevKeyOk => t!("rootkeys.gwup.viewinfo_dk", xous::LANG),
_ => {
rootkeys_modal.gam.relinquish_focus().unwrap();
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.gwup.no_update_found", xous::LANG)), false,
None, true, None);
rootkeys_modal.activate();
continue;
}
};
rootkeys_modal.gam.relinquish_focus().unwrap();
rootkeys_modal.modify(
Some(ActionType::RadioButtons(confirm_radiobox)),
Some(prompt), false,
None, true, None);
rootkeys_modal.activate();
},
Some(Opcode::UxUpdateGwShowInfo) => {
let gw_info = keys.fetch_gw_metadata(GatewareRegion::Staging);
let info = format!("v{}.{}.{}+{}\ncommit: g{:x}\n@{}\n{}",
gw_info.git_maj, gw_info.git_min, gw_info.git_rev, gw_info.git_additional,
gw_info.git_commit,
str::from_utf8(&gw_info.host_str[..gw_info.host_len as usize]).unwrap(),
str::from_utf8(&gw_info.date_str[..gw_info.date_len as usize]).unwrap()
);
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.gwup.short", xous::LANG) {
dismiss_modal_action.set_action_opcode(Opcode::UxUpdateGwConfirm.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(&info), false,
None, true, None);
rootkeys_modal.activate();
} else if payload.as_str() == t!("rootkeys.gwup.details", xous::LANG) {
dismiss_modal_action.set_action_opcode(Opcode::UxUpdateGwShowLog.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(&info), false,
None, true, None);
rootkeys_modal.activate();
} else {
// skip -- forward the "yes" decision directly on that would come from the "are you sure" modal
let payload = gam::RadioButtonPayload::new(t!("rootkeys.gwup.yes", xous::LANG));
let buf = Buffer::into_buf(payload).expect("couldn't convert message to payload");
buf.send(main_cid, Opcode::UxUpdateGwDecidePassword.to_u32().unwrap())
.map(|_| ()).expect("couldn't send action message");
}
}
Some(Opcode::UxUpdateGwShowLog) => {
let gw_info = keys.fetch_gw_metadata(GatewareRegion::Staging);
// truncate the message to better fit in the rendering box
let info_len = if gw_info.log_len > 256 { 256 } else {gw_info.log_len};
let info = format!("{}", str::from_utf8(&gw_info.log_str[..info_len as usize]).unwrap());
dismiss_modal_action.set_action_opcode(Opcode::UxUpdateGwShowStatus.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(&info), false,
None, true, None);
rootkeys_modal.activate();
},
Some(Opcode::UxUpdateGwShowStatus) => {
let gw_info = keys.fetch_gw_metadata(GatewareRegion::Staging);
// truncate the message to better fit in the rendering box
let status_len = if gw_info.status_len > 256 { 256 } else {gw_info.status_len};
let info = format!("{}", str::from_utf8(&gw_info.status_str[..status_len as usize]).unwrap());
dismiss_modal_action.set_action_opcode(Opcode::UxUpdateGwConfirm.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(&info), false,
None, true, None);
rootkeys_modal.activate();
},
Some(Opcode::UxUpdateGwConfirm) => {
let mut confirm_radiobox = gam::modal::RadioButtons::new(
main_cid,
Opcode::UxUpdateGwDecidePassword.to_u32().unwrap()
);
confirm_radiobox.is_password = true;
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.gwup.yes", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.gwup.no", xous::LANG)));
rootkeys_modal.modify(
Some(ActionType::RadioButtons(confirm_radiobox)),
Some(t!("rootkeys.gwup.proceed_confirm", xous::LANG)), false,
None, true, None);
rootkeys_modal.activate();
},
Some(Opcode::UxUpdateGwDecidePassword) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.gwup.yes", xous::LANG) {
if keys.is_pcache_update_password_valid() {
// indicate that there should be no change to the policy
let payload = gam::RadioButtonPayload::new("no change");
let buf = Buffer::into_buf(payload).expect("couldn't convert message to payload");
buf.send(main_cid, Opcode::UxUpdateGwRun.to_u32().unwrap())
.map(|_| ()).expect("couldn't send action message");
} else {
keys.set_ux_password_type(Some(PasswordType::Update));
password_action.set_action_opcode(Opcode::UxUpdateGwPasswordPolicy.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::TextEntry(password_action)),
Some(t!("rootkeys.get_update_password", xous::LANG)), false,
None, true, None
);
rootkeys_modal.activate();
}
} else {
continue;
}
}
Some(Opcode::UxUpdateGwPasswordPolicy)=> {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear();
let mut confirm_radiobox = gam::modal::RadioButtons::new(
main_cid,
Opcode::UxUpdateGwRun.to_u32().unwrap()
);
confirm_radiobox.is_password = true;
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.policy_clear", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.policy_suspend", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.policy_keep", xous::LANG)));
rootkeys_modal.modify(
Some(ActionType::RadioButtons(confirm_radiobox)),
Some(t!("rootkeys.policy_request", xous::LANG)), false,
None, true, None);
rootkeys_modal.activate();
}
Some(Opcode::UxUpdateGwRun) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep));
} else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
} else if payload.as_str() == "no change" {
// don't change the policy
} else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
}
keys.set_ux_password_type(None);
let result = keys.do_gateware_update(&mut rootkeys_modal, main_cid);
// the stop emoji, when sent to the slider action bar in progress mode, will cause it to close and relinquish focus
rootkeys_modal.key_event(['🛑', '\u{0000}', '\u{0000}', '\u{0000}']);
match result {
Ok(_) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.gwup.finished", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::AlignmentError) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_alignment", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::KeyError) => {
// probably a bad password, purge it, so the user can try again
keys.purge_password(PasswordType::Update);
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_key", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::IntegrityError) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_verify", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::FlashError) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_burn", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
}
}
Some(Opcode::UxSelfSignXous) => {
unimplemented!();
if keys.is_pcache_update_password_valid() {
// indicate that there should be no change to the policy
let payload = gam::RadioButtonPayload::new("no change");
let buf = Buffer::into_buf(payload).expect("couldn't convert message to payload");
buf.send(main_cid, Opcode::UxSignXousRun.to_u32().unwrap())
.map(|_| ()).expect("couldn't send action message");
} else {
keys.set_ux_password_type(Some(PasswordType::Update));
password_action.set_action_opcode(Opcode::UxSignXousPasswordPolicy.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::TextEntry(password_action)),
Some(t!("rootkeys.get_signing_password", xous::LANG)), false,
None, true, None
);
rootkeys_modal.activate();
}
},
Some(Opcode::UxSignXousPasswordPolicy) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear();
let mut confirm_radiobox = gam::modal::RadioButtons::new(
main_cid,
Opcode::UxSignXousRun.to_u32().unwrap()
);
confirm_radiobox.is_password = true;
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.policy_clear", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.policy_suspend", xous::LANG)));
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.policy_keep", xous::LANG)));
rootkeys_modal.modify(
Some(ActionType::RadioButtons(confirm_radiobox)),
Some(t!("rootkeys.policy_request", xous::LANG)), false,
None, true, None);
rootkeys_modal.activate();
},
Some(Opcode::UxSignXousRun) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep));
} else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
} else if payload.as_str() == "no change" {
// don't change the policy
} else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
}
keys.set_ux_password_type(None);
let result = keys.do_sign_xous(&mut rootkeys_modal, main_cid);
// the stop emoji, when sent to the slider action bar in progress mode, will cause it to close and relinquish focus
rootkeys_modal.key_event(['🛑', '\u{0000}', '\u{0000}', '\u{0000}']);
match result {
Ok(_) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.signxous.finished", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::AlignmentError) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_alignment", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::KeyError) => {
// probably a bad password, purge it, so the user can try again
keys.purge_password(PasswordType::Update);
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_key", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::IntegrityError) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_verify", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
Err(RootkeyResult::FlashError) => {
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::Notification(dismiss_modal_action)),
Some(t!("rootkeys.init.fail_burn", xous::LANG)), false,
None, false, None);
rootkeys_modal.activate();
xous::yield_slice();
}
}
}
Some(Opcode::CheckGatewareSignature) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
if keys.is_initialized() {
if keys.verify_gateware_self_signature() {
@ -474,6 +922,12 @@ fn xmain() -> ! {
}
Some(Opcode::UxPolicyReturn) => msg_scalar_unpack!(msg, policy_code, _, _, _, {
keys.update_policy(FromPrimitive::from_usize(policy_code));
if let Some(action) = policy_followup_action {
send_message(main_cid,
xous::Message::new_scalar(action, 0, 0, 0, 0)
).unwrap();
}
policy_followup_action = None;
}),
Some(Opcode::UxGutter) => {
// an intentional NOP for UX actions that require a destintation but need no action

View file

@ -192,6 +192,7 @@ fn xmain() -> ! {
sec_notes.lock().unwrap().insert("secnotes.no_keys".to_string(), t!("secnote.no_keys", xous::LANG).to_string());
} else {
log::info!("checking gateware signature...");
#[cfg(any(target_os = "none", target_os = "xous"))] // for now, threads don't work in hosted mode, but the result of this isn't important in hosted mode right now
thread::spawn({
let clone = Arc::clone(&sec_notes);
let keys = Arc::clone(&keys);

View file

@ -197,7 +197,7 @@ class PrecursorUsb:
)
def load_csrs(self):
LOC_CSRCSV = 0x20278000 # this address shouldn't change because it's how we figure out our version number
LOC_CSRCSV = 0x20277000 # this address shouldn't change because it's how we figure out our version number
csr_data = self.burst_read(LOC_CSRCSV, 0x8000)
hasher = hashlib.sha512()