forked from kinvolk/azure-cvm-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle variable report_data index sizes
fixes kinvolk#61 A caller of `get_report_with_report_data()` might provide report_data of varying sizes. We need to verify the size of the allocated nv index that holds the report data and recreate it if necessary. Integration tests have been added to test this on CVM hardware. Signed-off-by: Magnus Kulke <[email protected]>
- Loading branch information
Showing
9 changed files
with
212 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use az_snp_vtpm::{hcl, report, vtpm}; | ||
use serde::Deserialize; | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn get_report_with_varying_report_data_len() { | ||
let mut report_data = "test".as_bytes(); | ||
vtpm::get_report_with_report_data(report_data).unwrap(); | ||
report_data = "test_test".as_bytes(); | ||
vtpm::get_report_with_report_data(report_data).unwrap(); | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
struct VarDataUserData { | ||
#[serde(rename = "user-data")] | ||
user_data: String, | ||
} | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn get_report_with_report_data() { | ||
let mut report_data: [u8; 64] = [0; 64]; | ||
report_data[42] = 42; | ||
let bytes = vtpm::get_report_with_report_data(&report_data).unwrap(); | ||
let hcl_report = hcl::HclReport::new(bytes).unwrap(); | ||
let var_data = hcl_report.var_data(); | ||
let VarDataUserData { user_data } = serde_json::from_slice(var_data).unwrap(); | ||
assert_eq!(user_data.to_lowercase(), hex::encode(report_data)); | ||
|
||
let var_data_hash = hcl_report.var_data_sha256(); | ||
let snp_report: report::AttestationReport = hcl_report.try_into().unwrap(); | ||
assert_eq!(var_data_hash, snp_report.report_data[..32]); | ||
} | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn get_report() { | ||
let bytes = vtpm::get_report().unwrap(); | ||
let hcl_report = hcl::HclReport::new(bytes).unwrap(); | ||
|
||
let var_data_hash = hcl_report.var_data_sha256(); | ||
let snp_report: report::AttestationReport = hcl_report.try_into().unwrap(); | ||
assert_eq!(var_data_hash, snp_report.report_data[..32]); | ||
} | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn ak_pub() { | ||
let _ = vtpm::get_ak_pub().unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use az_tdx_vtpm::{hcl, tdx, vtpm}; | ||
use serde::Deserialize; | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn get_report_with_varying_report_data_len() { | ||
let mut report_data = "test".as_bytes(); | ||
vtpm::get_report_with_report_data(report_data).unwrap(); | ||
report_data = "test_test".as_bytes(); | ||
vtpm::get_report_with_report_data(report_data).unwrap(); | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
struct VarDataUserData { | ||
#[serde(rename = "user-data")] | ||
user_data: String, | ||
} | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn get_report_with_report_data() { | ||
let mut report_data: [u8; 64] = [0; 64]; | ||
report_data[42] = 42; | ||
let bytes = vtpm::get_report_with_report_data(&report_data).unwrap(); | ||
let hcl_report = hcl::HclReport::new(bytes).unwrap(); | ||
let var_data = hcl_report.var_data(); | ||
let VarDataUserData { user_data } = serde_json::from_slice(var_data).unwrap(); | ||
assert_eq!(user_data.to_lowercase(), hex::encode(report_data)); | ||
|
||
let var_data_hash = hcl_report.var_data_sha256(); | ||
let td_report: tdx::TdReport = hcl_report.try_into().unwrap(); | ||
assert_eq!(var_data_hash, td_report.report_mac.reportdata[..32]); | ||
} | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn get_report() { | ||
let bytes = vtpm::get_report().unwrap(); | ||
let hcl_report = hcl::HclReport::new(bytes).unwrap(); | ||
|
||
let var_data_hash = hcl_report.var_data_sha256(); | ||
let td_report: tdx::TdReport = hcl_report.try_into().unwrap(); | ||
assert_eq!(var_data_hash, td_report.report_mac.reportdata[..32]); | ||
} | ||
|
||
#[cfg(feature = "integration_test")] | ||
#[test] | ||
fn ak_pub() { | ||
let _ = vtpm::get_ak_pub().unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters