Skip to content

Commit

Permalink
Merge pull request #522 from Nitrokey/rng-status
Browse files Browse the repository at this point in the history
And random generator failure to init status bytes
  • Loading branch information
sosthene-nitrokey committed Jul 31, 2024
2 parents 9b0d7a9 + df05112 commit c8622ca
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version = "1.7.2"
memory-regions = { path = "components/memory-regions" }

# forked
admin-app = { git = "https://github.com/Nitrokey/admin-app.git", rev = "c257432dbe2efb53424d6847d82d90ddb527c53b" }
admin-app = { git = "https://github.com/Nitrokey/admin-app.git", tag = "v0.1.0-nitrokey.13" }
cbor-smol = { git = "https://github.com/Nitrokey/cbor-smol.git", tag = "v0.4.0-nitrokey.3"}
fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", tag = "v0.1.1-nitrokey.16" }
lpc55-hal = { git = "https://github.com/Nitrokey/lpc55-hal", tag = "v0.3.0-nitrokey.2" }
Expand Down
39 changes: 32 additions & 7 deletions components/apps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,13 @@ impl From<Variant> for u8 {
bitflags! {
#[derive(Default, Clone, Copy)]
pub struct InitStatus: u8 {
const NFC_ERROR = 0b00000001;
const NFC_ERROR = 0b00000001;
const INTERNAL_FLASH_ERROR = 0b00000010;
const EXTERNAL_FLASH_ERROR = 0b00000100;
const MIGRATION_ERROR = 0b00001000;
const SE050_ERROR = 0b00010000;
const CONFIG_ERROR = 0b00100000;
const MIGRATION_ERROR = 0b00001000;
const SE050_ERROR = 0b00010000;
const CONFIG_ERROR = 0b00100000;
const RNG_ERROR = 0b01000000;
}
}

Expand Down Expand Up @@ -788,10 +789,23 @@ impl<R: Runner> AdminData<R> {
}
}

pub type AdminStatus = [u8; 5];
pub struct AdminStatus {
init_status: InitStatus,
ifs_blocks: u8,
efs_blocks: u16,
variant: Variant,
}

impl<R: Runner> AdminData<R> {
fn status(&self) -> AdminStatus {
impl admin_app::StatusBytes for AdminStatus {
type Serialized = [u8; 5];
fn set_random_error(&mut self, value: bool) {
self.init_status.set(InitStatus::RNG_ERROR, value);
}
fn get_random_error(&self) -> bool {
self.init_status.contains(InitStatus::RNG_ERROR)
}

fn serialize(&self) -> [u8; 5] {
let efs_blocks = self.efs_blocks.to_be_bytes();
[
self.init_status.bits(),
Expand All @@ -803,6 +817,17 @@ impl<R: Runner> AdminData<R> {
}
}

impl<R: Runner> AdminData<R> {
fn status(&self) -> AdminStatus {
AdminStatus {
init_status: self.init_status,
ifs_blocks: self.ifs_blocks,
efs_blocks: self.efs_blocks,
variant: self.variant,
}
}
}

const ADMIN_APP_CLIENT_ID: &str = "admin";

impl<R: Runner> App<R> for AdminApp<R> {
Expand Down

0 comments on commit c8622ca

Please sign in to comment.