diff --git a/README.md b/README.md index c3d34fd..458ed6a 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ let opts = ParseOptions::default() .with_template_hash_algorithm(HashAlgorithm::Sha1); for event in EventLogParser::new(bytes.as_slice(), opts) { let event = event?; - println!("PCR {} {}", event.pcr_index, event.template_name); + println!("PCR {} {}", event.pcr_index, event.template); } ``` @@ -67,7 +67,7 @@ use ima_parser::log::parse_ascii_log; let line = "10 91f34b5c671d73504b274a919661cf80dab1e127 ima-ng sha1:1801e1be3e65ef1eaa5c16617bec8f1274eaf6b3 boot_aggregate\n"; let events = parse_ascii_log(line).unwrap(); assert_eq!(events.len(), 1); -assert_eq!(events[0].template_name, "ima-ng"); +assert_eq!(events[0].template.as_str(), "ima-ng"); ``` #### Recomputing a template hash diff --git a/examples/parse_ascii_log.rs b/examples/parse_ascii_log.rs index 9ebe641..fa7db01 100644 --- a/examples/parse_ascii_log.rs +++ b/examples/parse_ascii_log.rs @@ -96,6 +96,7 @@ fn main() -> ExitCode { } TemplateData::ImaBuf(e) => format!("{} [{}] buf={}B", e.name, e.digest, e.buf.len()), TemplateData::Unknown(fields) => format!("{} unknown-field(s)", fields.len()), + _ => "other built-in template".to_owned(), }; if args.verify { #[cfg(feature = "hash")] @@ -108,10 +109,16 @@ fn main() -> ExitCode { let ok = "no-hash-feature"; println!( "PCR={:>2} {:<8} hash-ok={} {hint}", - ev.pcr_index, ev.template_name, ok + ev.pcr_index, + ev.template.as_str(), + ok ); } else { - println!("PCR={:>2} {:<8} {hint}", ev.pcr_index, ev.template_name); + println!( + "PCR={:>2} {:<8} {hint}", + ev.pcr_index, + ev.template.as_str() + ); } } ExitCode::SUCCESS diff --git a/examples/parse_binary_log.rs b/examples/parse_binary_log.rs index bfbafc0..7a9f2a7 100644 --- a/examples/parse_binary_log.rs +++ b/examples/parse_binary_log.rs @@ -107,6 +107,7 @@ fn main() -> ExitCode { } TemplateData::ImaBuf(e) => format!("{} [{}] buf={}B", e.name, e.digest, e.buf.len()), TemplateData::Unknown(fields) => format!("{} unknown-field(s)", fields.len()), + _ => "other built-in template".to_owned(), }; if args.verify { #[cfg(feature = "hash")] @@ -119,10 +120,16 @@ fn main() -> ExitCode { let ok = "no-hash-feature"; println!( "PCR={:>2} {:<8} hash-ok={} {hint}", - ev.pcr_index, ev.template_name, ok + ev.pcr_index, + ev.template.as_str(), + ok ); } else { - println!("PCR={:>2} {:<8} {hint}", ev.pcr_index, ev.template_name); + println!( + "PCR={:>2} {:<8} {hint}", + ev.pcr_index, + ev.template.as_str() + ); } } ExitCode::SUCCESS diff --git a/src/lib.rs b/src/lib.rs index fcf3204..4a4bae0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ //! .with_template_hash_algorithm(HashAlgorithm::Sha1); //! for event in EventLogParser::new(bytes.as_slice(), opts) { //! let event = event?; -//! println!("PCR {} {}", event.pcr_index, event.template_name); +//! println!("PCR {} {}", event.pcr_index, event.template); //! } //! # Ok::<(), Box>(()) //! ``` @@ -62,7 +62,7 @@ //! let line = "10 91f34b5c671d73504b274a919661cf80dab1e127 ima-ng sha1:1801e1be3e65ef1eaa5c16617bec8f1274eaf6b3 boot_aggregate\n"; //! let events = parse_ascii_log(line).unwrap(); //! assert_eq!(events.len(), 1); -//! assert_eq!(events[0].template_name, "ima-ng"); +//! assert_eq!(events[0].template.as_str(), "ima-ng"); //! ``` //! //! ### Recomputing a template hash diff --git a/src/log.rs b/src/log.rs index a7eb505..2144df1 100644 --- a/src/log.rs +++ b/src/log.rs @@ -26,7 +26,9 @@ pub use self::ascii::{parse_ascii_line, parse_ascii_log}; pub use self::event::Event; pub use self::parser::{Endianness, EventLogParser, ParseOptions}; pub use self::template::{ - Digest, ImaBufEntry, ImaEntry, ImaNgEntry, ImaSigEntry, TemplateData, TemplateField, + Digest, DigestType, DigestV2, EvmSigEntry, ImaBufEntry, ImaEntry, ImaModsigEntry, ImaNgEntry, + ImaNgV2Entry, ImaSigEntry, ImaSigV2Entry, Template, TemplateData, TemplateField, + TemplateFieldId, }; /// Default PCR index used by IMA (`CONFIG_IMA_MEASURE_PCR_IDX`). @@ -36,12 +38,3 @@ pub const DEFAULT_IMA_PCR: u32 = 10; /// The legacy `ima` template pads the `n` field to this size plus one when /// computing the template hash. pub const IMA_EVENT_NAME_LEN_MAX: usize = 255; - -/// Template name of the legacy fixed-format template. -pub const IMA_TEMPLATE_NAME: &str = "ima"; -/// Template name of the `ima-ng` (next-generation) template. -pub const IMA_NG_TEMPLATE_NAME: &str = "ima-ng"; -/// Template name of the `ima-sig` template. -pub const IMA_SIG_TEMPLATE_NAME: &str = "ima-sig"; -/// Template name of the `ima-buf` template. -pub const IMA_BUF_TEMPLATE_NAME: &str = "ima-buf"; diff --git a/src/log/ascii.rs b/src/log/ascii.rs index 1faaf5e..b3f62d5 100644 --- a/src/log/ascii.rs +++ b/src/log/ascii.rs @@ -5,7 +5,7 @@ //! The format of `/sys/kernel/security/ima/ascii_runtime_measurements_*` is: //! //! ```text -//! +//!