Skip to content

Commit

Permalink
audit: Adds support for HSM initialization entry (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo authored Jul 13, 2023
1 parent ba37eda commit 406bde9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/audit/commands/get_log_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Response for LogEntries {
}

/// Entry in the log response
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct LogEntry {
/// Entry number
pub item: u16,
Expand Down Expand Up @@ -73,7 +73,7 @@ pub struct LogEntry {
pub const LOG_DIGEST_SIZE: usize = 16;

/// Truncated SHA-256 digest of a log entry and the previous log digest
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, PartialEq, Eq)]
pub struct LogDigest(pub [u8; LOG_DIGEST_SIZE]);

impl AsRef<[u8]> for LogDigest {
Expand All @@ -92,3 +92,36 @@ impl Debug for LogDigest {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::serialization::deserialize;

static SAMPLE_ENTRY: &[u8] = &[
0, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 237, 217, 180,
224, 195, 140, 79, 126, 197, 15, 5, 112, 145, 241, 47, 206,
];

#[test]
fn test_get_log_entry() {
let entry: LogEntry = deserialize(SAMPLE_ENTRY).expect("Parse log entry");
assert_eq!(
entry,
LogEntry {
item: 1,
cmd: command::Code::HsmInitialization,
length: 65535,
session_key: 65535,
target_key: 65535,
second_key: 65535,
result: response::Code::Success(command::Code::Error),
tick: 4294967295,
digest: LogDigest([
0xed, 0xd9, 0xb4, 0xe0, 0xc3, 0x8c, 0x4f, 0x7e, 0xc5, 0x0f, 0x05, 0x70, 0x91,
0xf1, 0x2f, 0xce
])
}
)
}
}
2 changes: 2 additions & 0 deletions src/command/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub enum Code {
BlinkDevice = 0x6b,
ChangeAuthenticationKey = 0x6c,
Error = 0x7f,
HsmInitialization = 0xff,
}

impl Code {
Expand Down Expand Up @@ -124,6 +125,7 @@ impl Code {
0x6b => Code::BlinkDevice,
0x6c => Code::ChangeAuthenticationKey,
0x7f => Code::Error,
0xff => Code::HsmInitialization,
_ => fail!(ErrorKind::CodeInvalid, "invalid command type: {}", byte),
})
}
Expand Down

0 comments on commit 406bde9

Please sign in to comment.