Skip to content

Commit

Permalink
dep/verifier: fix eventlog with extra blank chars
Browse files Browse the repository at this point in the history
Due to definition of AAEL, a ' ' is allowed as part of content field.
Thus we now parse the original eventlog string using ' ' as separator to
distinguish domain, operation and content only twice, and the things
left are treated as the content of the eventlog, including extra ' 's.

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Jul 17, 2024
1 parent d8858be commit 08c6168
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions deps/verifier/src/eventlog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hash::HashAlgorithm;
use serde_json::{Map, Value};
use sha2::{digest::FixedOutput, Digest, Sha256, Sha384, Sha512};

#[derive(Clone)]
#[derive(Clone, PartialEq, Debug)]
pub struct AAEvent {
pub domain: String,
pub operation: String,
Expand All @@ -24,10 +24,7 @@ impl FromStr for AAEvent {

fn from_str(input: &str) -> Result<Self> {
let input_trimed = input.trim_end();
let sections: Vec<&str> = input_trimed.split(' ').collect();
if sections.len() != 3 {
bail!("Illegal AA event entry format. Should be `<domain> <operation> <content>`");
}
let sections: Vec<&str> = input_trimed.splitn(3, ' ').collect();
Ok(Self {
domain: sections[0].into(),
operation: sections[1].into(),
Expand Down Expand Up @@ -168,10 +165,12 @@ impl AAEventlog {

#[cfg(test)]
mod tests {
use std::fs;
use std::{fs, str::FromStr};

use rstest::rstest;

use super::AAEvent;

#[rstest]
#[case("./test_data/aael/AAEL_data_1", b"71563a23b430b8637970b866169052815ef9434056516dc9f78c1b3bfb745cee18a2ca92aa53c8122be5cbe59a100764")]
#[case("./test_data/aael/AAEL_data_2", b"31fa17881137923029b1da5b368e92d8b22b14bbb4deaa360da61fce7aa530bd2f4c59ac7bd27021ef64104ff4dd04f9")]
Expand All @@ -186,4 +185,15 @@ mod tests {
let sum = hex::decode(sum).unwrap();
aael.integrity_check(&sum).unwrap();
}

#[rstest]
#[case("domain operation con tent", AAEvent { domain: "domain".into(), operation: "operation".into(), content: "con tent".into() })]
#[case("domain operation content", AAEvent { domain: "domain".into(), operation: "operation".into(), content: "content".into() })]
#[case("dom ain operation content", AAEvent { domain: "dom".into(), operation: "ain".into(), content: "operation content".into() })]
#[case(r#"github.com/confidential-containers EventWithJSONParams { "key1":"value1\tmore values and 'quotes'\n", "key2": [ "value2", 2, true, null ] }"#, AAEvent { domain: "github.com/confidential-containers".into(), operation: "EventWithJSONParams".into(), content: r#"{ "key1":"value1\tmore values and 'quotes'\n", "key2": [ "value2", 2, true, null ] }"#.into() })]

fn test_parse_log_entry(#[case] entry: &str, #[case] expect: AAEvent) {
let entry = AAEvent::from_str(entry).unwrap();
assert_eq!(entry, expect);
}
}

0 comments on commit 08c6168

Please sign in to comment.