mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add backup of keyboard layout and language
This commit is contained in:
parent
fded17221f
commit
13e11b83ae
5 changed files with 119 additions and 4 deletions
|
|
@ -49,6 +49,7 @@ tts-frontend = {path="../tts"}
|
|||
aes-gcm-siv = {git="https://github.com/RustCrypto/AEADs.git", branch="master"}
|
||||
subtle = {version = "2.4.1", default-features = false}
|
||||
usb-device-xous = {path="../usb-device-xous"}
|
||||
keyboard = {path="../keyboard"}
|
||||
|
||||
# private keys
|
||||
#sha2 = {version = "0.9.5", default-features = false, features = []}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,12 @@
|
|||
"zh": "备份密钥不匹配。\n\n这是您的备份密钥,再次:",
|
||||
"en-tts": "Backup key did not match. This is your backup key, again:"
|
||||
},
|
||||
"rootkeys.backup_prepwait": {
|
||||
"en": "Preparing backup state...",
|
||||
"ja": "バックアップの準備中...",
|
||||
"zh": "正在准备备份...",
|
||||
"en-tts": "Preparing backup state..."
|
||||
},
|
||||
"rootkeys.backup_staged": {
|
||||
"en": "Backup data is prepared.\nConnect to a host computer by USB, and download the backup data bundle.\nScan the QR code for instructions:",
|
||||
"ja": "バックアップデータを用意します。 これで、ホストコンピューターに接続して、バックアップデータバンドルをダウンロードできます。",
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ pub enum RootkeyResult {
|
|||
|
||||
/// AES operation definitions
|
||||
pub use cipher::{BlockCipher, consts::U16};
|
||||
use keyboard::KeyMap;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
/// 128-bit AES block
|
||||
|
|
@ -265,6 +266,95 @@ pub enum BackupOp {
|
|||
Restore = 2,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub enum BackupLanguage {
|
||||
En = 0,
|
||||
EnTts = 1,
|
||||
Ja = 2,
|
||||
Zh = 3,
|
||||
}
|
||||
impl Default for BackupLanguage {
|
||||
fn default() -> Self {
|
||||
match xous::LANG {
|
||||
"en" => BackupLanguage::En,
|
||||
"en-tts" => BackupLanguage::EnTts,
|
||||
"ja" => BackupLanguage::Ja,
|
||||
"zh" => BackupLanguage::Zh,
|
||||
_ => BackupLanguage::En,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From::<BackupLanguage> for [u8; 4] {
|
||||
fn from(l: BackupLanguage) -> [u8; 4] {
|
||||
(l as u32).to_le_bytes()
|
||||
}
|
||||
}
|
||||
#[repr(u32)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
#[allow(dead_code)]
|
||||
/// We keep a separate version of this for serialization/deserialization because
|
||||
/// we need to handle "unknown/undefined" layouts in a different way from the keyboard
|
||||
/// crate. Plus this helps avoid a dependency on the keyboard crate as well.
|
||||
pub enum BackupKeyboardLayout {
|
||||
Qwerty = 0,
|
||||
Dvorak = 1,
|
||||
Qwertz = 2,
|
||||
Azerty = 3,
|
||||
Braille = 4,
|
||||
Hangul = 5,
|
||||
// codes above 16384 are reserved for user layouts
|
||||
}
|
||||
impl From::<KeyMap> for BackupKeyboardLayout {
|
||||
fn from(map: KeyMap) -> BackupKeyboardLayout {
|
||||
match map {
|
||||
KeyMap::Qwerty => BackupKeyboardLayout::Qwerty,
|
||||
KeyMap::Azerty => BackupKeyboardLayout::Azerty,
|
||||
KeyMap::Dvorak => BackupKeyboardLayout::Dvorak,
|
||||
KeyMap::Qwertz => BackupKeyboardLayout::Qwertz,
|
||||
KeyMap::Braille => BackupKeyboardLayout::Braille,
|
||||
KeyMap::Undefined => BackupKeyboardLayout::Qwerty,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Into::<KeyMap> for BackupKeyboardLayout {
|
||||
fn into(self) -> KeyMap {
|
||||
match self {
|
||||
BackupKeyboardLayout::Qwerty => KeyMap::Qwerty,
|
||||
BackupKeyboardLayout::Braille => KeyMap::Braille,
|
||||
BackupKeyboardLayout::Dvorak => KeyMap::Dvorak,
|
||||
BackupKeyboardLayout::Qwertz => KeyMap::Qwertz,
|
||||
BackupKeyboardLayout::Azerty => KeyMap::Azerty,
|
||||
BackupKeyboardLayout::Hangul => KeyMap::Undefined,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for BackupKeyboardLayout {
|
||||
fn default() -> Self {
|
||||
BackupKeyboardLayout::Qwerty
|
||||
}
|
||||
}
|
||||
impl From::<BackupKeyboardLayout> for [u8; 4] {
|
||||
fn from(l: BackupKeyboardLayout) -> [u8; 4] {
|
||||
(l as u32).to_le_bytes()
|
||||
}
|
||||
}
|
||||
impl From::<[u8; 4]> for BackupKeyboardLayout {
|
||||
fn from(b: [u8; 4]) -> BackupKeyboardLayout {
|
||||
let code = u32::from_le_bytes(b);
|
||||
match code {
|
||||
0 => BackupKeyboardLayout::Qwerty,
|
||||
1 => BackupKeyboardLayout::Dvorak,
|
||||
2 => BackupKeyboardLayout::Qwertz,
|
||||
3 => BackupKeyboardLayout::Azerty,
|
||||
4 => BackupKeyboardLayout::Braille,
|
||||
5 => BackupKeyboardLayout::Hangul,
|
||||
_ => BackupKeyboardLayout::Qwerty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C, align(8))]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct BackupHeader {
|
||||
|
|
@ -275,7 +365,9 @@ pub struct BackupHeader {
|
|||
pub ec_ver: [u8; 16],
|
||||
pub wf200_ver: [u8; 16],
|
||||
pub timestamp: u64,
|
||||
pub _reserved: [u8; 64],
|
||||
pub language: [u8; 4],
|
||||
pub kbd_layout: [u8; 4],
|
||||
pub _reserved: [u8; 56],
|
||||
pub op: BackupOp,
|
||||
}
|
||||
impl Default for BackupHeader {
|
||||
|
|
@ -287,7 +379,9 @@ impl Default for BackupHeader {
|
|||
ec_ver: [0u8; 16],
|
||||
wf200_ver: [0u8; 16],
|
||||
timestamp: 0,
|
||||
_reserved: [0u8; 64],
|
||||
language: BackupLanguage::default().into(), // this is "correct by default"
|
||||
kbd_layout: BackupKeyboardLayout::default().into(), // this has to be adjusted
|
||||
_reserved: [0u8; 56],
|
||||
op: BackupOp::Archive,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,6 +162,12 @@ pub(crate) fn create_backup(
|
|||
}
|
||||
).expect("couldn't encrypt data");
|
||||
|
||||
log::debug!("commit_nonce: {:?}", &kcom_nonce);
|
||||
log::debug!("commit_nonce: {:x?}", &kcom_nonce);
|
||||
log::debug!("commit_key: {:?}", &kcom.0);
|
||||
log::debug!("commit_key: {:x?}", &kcom.0);
|
||||
log::debug!("header {}, ptlen {}, ctlen {}", size_of::<BackupHeader>(), size_of::<BackupDataPt>(), size_of::<BackupDataCt>());
|
||||
|
||||
// copy to a ciphertext record
|
||||
let mut backup_ct = BackupDataCt::default();
|
||||
backup_ct.nonce.copy_from_slice(&nonce);
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ fn main() -> ! {
|
|||
use crate::implementation::RootKeys;
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::set_max_level(log::LevelFilter::Debug);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
@ -947,7 +947,11 @@ fn main() -> ! {
|
|||
|
||||
match result {
|
||||
Ok(_) => {
|
||||
modals.show_notification(t!("rootkeys.gwup.finished", xous::LANG), None).expect("modals error");
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
// just do the reboot now.
|
||||
// modals.show_notification(t!("rootkeys.gwup.finished", xous::LANG), None).expect("modals error");
|
||||
}
|
||||
Err(RootkeyResult::AlignmentError) => {
|
||||
modals.show_notification(t!("rootkeys.init.fail_alignment", xous::LANG), None).expect("modals error");
|
||||
|
|
@ -1381,9 +1385,13 @@ fn main() -> ! {
|
|||
// this final statement has a take/unwrap to set backup_header back to None
|
||||
match keys.write_backup(backup_header.take().unwrap(), backup_ct) {
|
||||
Ok(_) => {
|
||||
// this switchover takes a couple seconds, give some user feedback
|
||||
modals.dynamic_notification(Some(t!("rootkeys.backup_prepwait", xous::LANG)), None).ok();
|
||||
let usbd = usb_device_xous::UsbHid::new();
|
||||
usbd.switch_to_core(usb_device_xous::UsbDeviceType::Debug).unwrap();
|
||||
usbd.debug_usb(Some(false)).unwrap();
|
||||
modals.dynamic_notification_close().ok();
|
||||
// there will be a bit of a pause while the QR text renders, but we'll have to fix that with other optimizations...
|
||||
modals.show_notification(t!("rootkeys.backup_staged", xous::LANG), Some("https://github.com/betrusted-io/betrusted-wiki/wiki/Backups")).ok();
|
||||
}
|
||||
Err(_) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue