1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Get audit logs from the `YubiHSM2` device
//!
//! <https://developers.yubico.com/YubiHSM2/Commands/Get_Log_Entries.html>
use std::fmt::{self, Debug};
use crate::command::{Command, CommandCode};
use crate::object::ObjectId;
use crate::response::{Response, ResponseCode};
/// Request parameters for `command::get_log_entries`
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GetLogEntriesCommand {}
impl Command for GetLogEntriesCommand {
type ResponseType = LogEntries;
}
/// Response from `command::get_log_entries`
#[derive(Serialize, Deserialize, Debug)]
pub struct LogEntries {
/// Number of boot events which weren't logged (if buffer is full and audit enforce is set)
pub unlogged_boot_events: u16,
/// Number of unlogged authentication events (if buffer is full and audit enforce is set)
pub unlogged_auth_events: u16,
/// Number of entries in the response
pub num_entries: u8,
/// Entries in the log
pub entries: Vec<LogEntry>,
}
impl Response for LogEntries {
const COMMAND_CODE: CommandCode = CommandCode::GetLogEntries;
}
/// Entry in the log response
#[derive(Serialize, Deserialize, Debug)]
pub struct LogEntry {
/// Entry number
pub item: u16,
/// Command type
pub cmd: CommandCode,
/// Command length
pub length: u16,
/// Session key ID
pub session_key: ObjectId,
/// Target key ID
pub target_key: ObjectId,
/// Second key affected
pub second_key: ObjectId,
/// Result of the operation
pub result: ResponseCode,
/// Tick count of the HSM's internal clock
pub tick: u32,
/// 16-byte truncated SHA-256 digest of this log entry and the digest of the previous entry
pub digest: LogDigest,
}
/// Size of a truncated digest in the log
pub const LOG_DIGEST_SIZE: usize = 16;
/// Truncated SHA-256 digest of a log entry and the previous log digest
#[derive(Serialize, Deserialize)]
pub struct LogDigest(pub [u8; LOG_DIGEST_SIZE]);
impl AsRef<[u8]> for LogDigest {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl Debug for LogDigest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "LogDigest(")?;
for (i, byte) in self.0.iter().enumerate() {
write!(f, "{:02x}", byte)?;
write!(f, "{}", if i == LOG_DIGEST_SIZE - 1 { ")" } else { ":" })?;
}
Ok(())
}
}