add edge case handling for restore to new device

Just remembered that the PDDB is *locked* to a given device.
To restore to a new device, you have to unlock all the Bases,
and re-encrypt them to the new device's DNA.

This commit adds the facilities to detect this condition, but
the actual code to do this is quite involved...let's handle that
after we've got a "simple" restore to the same device going.

Why do we lock to a device's DNA? the idea is to prevent
attacks where people are taking static blocks of crypto data
and just swapping it between devices to see if they can
get something to decrypt. It also makes it harder for
an adversary to replace the physical device -- e.g., an
evil maid prepared a replacement with implants in advance, and they
image your PDDB onto the replaced device, hoping that you don't
notice. Because the PDDB is device-locked, the "evil maid"
would have to forge the devices DNA to match yours:
possible, but would require kernel mods that patch over the
reported ID; that would trigger the line across the top of the
screen; or, somehow editing the FPGA itself to force
its device ID to report the same as yours. This last attack
vector would be successful, but afaik there is no known way
to modify an FPGA's DNA code. I'm sure there is some proprietary
secret know that Xilinx uses to set it, and if you were
a large government you may be able to coerce Xilinx into giving
you those codes plus some tool that could set the fuses
plus some unfused devices (the fuses are burn-once) but....
This commit is contained in:
bunnie 2022-07-16 02:31:18 +08:00
parent f6423381e9
commit 37154f3350
3 changed files with 32 additions and 3 deletions

View file

@ -264,6 +264,7 @@ pub enum BackupOp {
/// backup and restore can be manipulated by the OS without updating the ciphertext
Backup = 1,
Restore = 2,
RestoreDna = 3,
}
#[repr(u32)]
@ -367,7 +368,8 @@ pub struct BackupHeader {
pub timestamp: u64,
pub language: [u8; 4],
pub kbd_layout: [u8; 4],
pub _reserved: [u8; 56],
pub dna: [u8; 8],
pub _reserved: [u8; 48],
pub op: BackupOp,
}
impl Default for BackupHeader {
@ -381,7 +383,8 @@ impl Default for BackupHeader {
timestamp: 0,
language: BackupLanguage::default().into(), // this is "correct by default"
kbd_layout: BackupKeyboardLayout::default().into(), // this has to be adjusted
_reserved: [0u8; 56],
dna: [0u8; 8],
_reserved: [0u8; 48],
op: BackupOp::Archive,
}
}

View file

@ -1523,7 +1523,18 @@ fn main() -> ! {
match result {
Ok(_) => {
keys.erase_backup();
let (mut header, ct) = keys.read_backup()
.expect("Internal error: we're doing a backup, but somehow the backup record has disappeared on us!");
if u64::from_le_bytes(header.dna) == llio.soc_dna().unwrap() {
// we're restoring to the same device, we're done!
keys.erase_backup();
} else {
// one more step...have to re-encrypt the PDDB's basis to the new device's DNA.
// we'll handle this *after* the reboot, because we may need a newer SoC version, etc.
header.op = BackupOp::RestoreDna;
keys.write_backup(header, ct)
.expect("Couldn't set flag for restore with new DNA: some data loss will occur.");
}
log::info!("going to into reboot arc");
send_message(main_cid,
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)

View file

@ -395,6 +395,12 @@ fn wrapped_main() -> ! {
Ok(Some(header)) => {
match header.op {
BackupOp::Restore => {
{ /* remove this check once the restore process for this case is complete */
let backup_dna = u64::from_le_bytes(header.dna);
if backup_dna != llio.soc_dna().unwrap() {
panic!("Backups to new devices not yet supported: add DNA re-encryption flow");
}
}
keys.lock().unwrap().do_restore_backup_ux_flow();
restore_running = true;
// set the keyboard layout according to the restore record.
@ -403,6 +409,14 @@ fn wrapped_main() -> ! {
log::info!("Keyboard layout set to {:?} by restore process.", map);
kbd.set_keymap(map).ok();
}
BackupOp::RestoreDna => {
unimplemented!();
// need to call a PDDB function that does the DNA upgrade.
// this is also the 'churn' function that's been on the to-do list, btw, just called with the same DNA as before.
// once this step is done & successful, we have to erase the backup block to avoid re-doing this flow
keys.lock().unwrap().do_erase_backup();
}
BackupOp::Backup => {
// once we have unlocked the PDDB and know our timezone, we'll compare the embedded timestamp to
// our current time, and delete the backup if it's too old.
@ -989,6 +1003,7 @@ fn wrapped_main() -> ! {
metadata.wf200_ver = com.get_wf200_fw_rev().unwrap().into();
metadata.ec_ver = com.get_ec_sw_tag().unwrap().into();
metadata.op = BackupOp::Backup;
metadata.dna = llio.soc_dna().unwrap().to_le_bytes();
let map = kbd.get_keymap().expect("couldn't get key mapping");
let map_serialize: BackupKeyboardLayout = map.into();
metadata.kbd_layout = map_serialize.into();