diff --git a/services/root-keys/src/api.rs b/services/root-keys/src/api.rs index 06f47a1b2..441edf72b 100644 --- a/services/root-keys/src/api.rs +++ b/services/root-keys/src/api.rs @@ -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, } } diff --git a/services/root-keys/src/main.rs b/services/root-keys/src/main.rs index 9363b1175..7aaac6b33 100644 --- a/services/root-keys/src/main.rs +++ b/services/root-keys/src/main.rs @@ -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) diff --git a/services/status/src/main.rs b/services/status/src/main.rs index d2af3ff40..d05031c16 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -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();