Implement factory reset command

This commit is contained in:
Sosthène Guédon
2023-11-10 15:29:06 +01:00
parent b67c3647b7
commit f72eccbc3b
3 changed files with 12 additions and 2 deletions
+2
View File
@@ -25,6 +25,7 @@ embedded-hal = { version = "0.2.7", optional = true }
hex-literal = "0.4.1"
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
trussed-se050-backend = { version = "0.1.0", optional = true }
trussed-staging = { version = "0.1.0", features = ["manage"] }
[features]
default = []
@@ -44,3 +45,4 @@ apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch.git", rev
trussed-se050-backend = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", rev = "3395a5b73241a0a9f14a0715952be6fe7f1e56b0" }
iso7816 = { git = "https://github.com/sosthene-nitrokey/iso7816.git", rev = "160ca3bbd8e21ec4e4ee1e0748e1eaa53a45c97f"}
se05x = { git = "https://github.com/Nitrokey/se05x.git", rev = "0b77eb6b152d214897696aadf87767fd84ffcb0e"}
trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", rev = "10baac2608e98e25ea77ade974a4e26f778d6c8e" }
+7
View File
@@ -19,6 +19,7 @@ const STATUS: u8 = 0x80;
const TEST_SE050: u8 = 0x81;
const GET_CONFIG: u8 = 0x82;
const SET_CONFIG: u8 = 0x83;
const FACTORY_RESET: u8 = 0x84;
// For compatibility, old commands are also available directly as separate vendor commands.
const UPDATE: VendorCommand = VendorCommand::H51;
@@ -48,6 +49,7 @@ enum Command {
TestSe05X,
GetConfig,
SetConfig,
FactoryReset,
}
impl TryFrom<u8> for Command {
@@ -67,6 +69,7 @@ impl TryFrom<u8> for Command {
TEST_SE050 => Ok(Command::TestSe05X),
GET_CONFIG => Ok(Command::GetConfig),
SET_CONFIG => Ok(Command::SetConfig),
FACTORY_RESET => Ok(Command::FactoryReset),
_ => Err(Error::UnsupportedCommand),
}
}
@@ -295,6 +298,10 @@ where
};
response.push(status).ok();
}
Command::FactoryReset => {
debug_now!("Factory resetting the device");
syscall!(self.trussed.factory_reset_device());
}
}
Ok(())
}
+3 -2
View File
@@ -15,11 +15,12 @@ mod config;
pub use admin::{App, Reboot};
pub use config::{Config, ConfigError, ConfigValueMut};
use trussed_staging::manage::ManageClient;
#[cfg(not(feature = "se050"))]
pub trait Client: trussed::Client {}
pub trait Client: trussed::Client + ManageClient {}
#[cfg(not(feature = "se050"))]
impl<C: trussed::Client> Client for C {}
impl<C: trussed::Client + ManageClient> Client for C {}
#[cfg(feature = "se050")]
pub trait Client: trussed::Client + trussed_se050_backend::manage::ManageClient {}