Skip to content

Commit

Permalink
fixup! verifier-az-cvm-vtpm: Fix tests to updated library
Browse files Browse the repository at this point in the history
  • Loading branch information
surajssd committed Jan 26, 2024
1 parent 641229d commit 2227155
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
19 changes: 9 additions & 10 deletions attestation-service/verifier/src/az_snp_vtpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ mod tests {
use super::*;
use az_snp_vtpm::vtpm::VerifyError;

Check failure on line 136 in attestation-service/verifier/src/az_snp_vtpm/mod.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

unresolved import `az_snp_vtpm::vtpm::VerifyError`

const REPORT: &[u8; 3848] = include_bytes!("../../test_data/az-snp-vtpm/hcl-report.bin");
const REPORT: &[u8; 2600] = include_bytes!("../../test_data/az-snp-vtpm/hcl-report.bin");
const QUOTE: &[u8; 1362] = include_bytes!("../../test_data/az-snp-vtpm/quote.bin");
const REPORT_DATA: &[u8] = "challenge".as_bytes();

#[test]
fn test_verify_snp_report() {
let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
let snp_report = hcl_report.try_into().unwrap();
let vcek = Vcek::from_pem(include_str!("../../test_data/az-snp-vtpm/vcek.pem")).unwrap();
let vendor_certs = load_milan_cert_chain().as_ref().unwrap();
Expand All @@ -152,8 +152,8 @@ mod tests {
fn test_verify_snp_report_failure() {
let mut wrong_report = REPORT.clone();
// messing with snp report
wrong_report[0x01ae] = 0;
let hcl_report = HclReport::new(bincode::deserialize(&wrong_report).unwrap()).unwrap();
wrong_report[0x01a6] = 0;
let hcl_report = HclReport::new(wrong_report.to_vec()).unwrap();
let snp_report = hcl_report.try_into().unwrap();
let vcek = Vcek::from_pem(include_str!("../../test_data/az-snp-vtpm/vcek.pem")).unwrap();
let vendor_certs = load_milan_cert_chain().as_ref().unwrap();
Expand All @@ -168,7 +168,7 @@ mod tests {

#[test]
fn test_verify_report_data() {
let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
let var_data_hash = hcl_report.var_data_sha256();
let snp_report = hcl_report.try_into().unwrap();
verify_report_data(&var_data_hash, &snp_report).unwrap();
Expand All @@ -178,7 +178,7 @@ mod tests {
fn test_verify_report_data_failure() {
let mut wrong_report = REPORT.clone();
wrong_report[0x06e0] += 1;
let hcl_report = HclReport::new(bincode::deserialize(&wrong_report).unwrap()).unwrap();
let hcl_report = HclReport::new(wrong_report.to_vec()).unwrap();
let var_data_hash = hcl_report.var_data_sha256();
let snp_report = hcl_report.try_into().unwrap();
assert_eq!(
Expand All @@ -192,7 +192,7 @@ mod tests {
#[test]
fn test_verify_signature() {
let quote: Quote = bincode::deserialize(QUOTE).unwrap();
let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
verify_signature(&quote, &hcl_report).unwrap();
}

Expand All @@ -202,7 +202,7 @@ mod tests {
quote[0x030] = 0;
let wrong_quote: Quote = bincode::deserialize(&quote).unwrap();

let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
assert_eq!(
verify_signature(&wrong_quote, &hcl_report)
.unwrap_err()
Expand All @@ -219,8 +219,7 @@ mod tests {
let mut wrong_report = REPORT.clone();
// messing with AKpub in var data
wrong_report[0x0540] = 0;
let wrong_hcl_report =
HclReport::new(bincode::deserialize(&wrong_report).unwrap()).unwrap();
let wrong_hcl_report = HclReport::new(wrong_report.to_vec()).unwrap();
assert_eq!(
verify_signature(&quote, &wrong_hcl_report)
.unwrap_err()
Expand Down
12 changes: 6 additions & 6 deletions attestation-service/verifier/src/az_tdx_vtpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ mod tests {
use az_tdx_vtpm::vtpm::Quote;
use az_tdx_vtpm::vtpm::VerifyError;

Check failure on line 100 in attestation-service/verifier/src/az_tdx_vtpm/mod.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

unresolved import `az_tdx_vtpm::vtpm::VerifyError`

const REPORT: &[u8; 3848] = include_bytes!("../../test_data/az-tdx-vtpm/hcl-report.bin");
const REPORT: &[u8; 2600] = include_bytes!("../../test_data/az-tdx-vtpm/hcl-report.bin");
const QUOTE: &[u8; 1362] = include_bytes!("../../test_data/az-tdx-vtpm/quote.bin");
const TD_QUOTE: &[u8; 5006] = include_bytes!("../../test_data/az-tdx-vtpm/td-quote.bin");

#[test]
fn test_verify_hcl_var_data() {
let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
let td_quote = parse_tdx_quote(TD_QUOTE).unwrap();
verify_hcl_var_data(&hcl_report, &td_quote).unwrap();
}
Expand All @@ -114,20 +114,20 @@ mod tests {
fn test_verify_hcl_var_data_failure() {
let mut wrong_report = REPORT.clone();
wrong_report[0x0880] += 1;
let hcl_report = HclReport::new(bincode::deserialize(&wrong_report).unwrap()).unwrap();
let hcl_report = HclReport::new(wrong_report.to_vec()).unwrap();
let td_quote = parse_tdx_quote(TD_QUOTE).unwrap();
assert_eq!(
verify_hcl_var_data(&hcl_report, &td_quote)
.unwrap_err()
.to_string(),
"TDX Quote report data mismatch1"
"TDX Quote report data mismatch"
);
}

#[test]
fn test_verify_tpm_signature() {
let quote: Quote = bincode::deserialize(QUOTE).unwrap();
let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
verify_tpm_signature(&quote, &hcl_report).unwrap();
}

Expand All @@ -137,7 +137,7 @@ mod tests {
quote[0x020] = 0;
let wrong_quote: Quote = bincode::deserialize(&quote).unwrap();

let hcl_report = HclReport::new(bincode::deserialize(REPORT).unwrap()).unwrap();
let hcl_report = HclReport::new(REPORT.to_vec()).unwrap();
assert_eq!(
verify_tpm_signature(&wrong_quote, &hcl_report)
.unwrap_err()
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 2227155

Please sign in to comment.