-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AA/attester: add check_init_data support for TDX and SNP
In TDX, we use tdx_attest crate to get a raw hardware tdx report to parse the MRCONFIGID field. In SNP, we use sev crate to get a hardware report to parse HOSTDATA field. The input one should be resize as the evidence field inside the TEE evidence to compare. Signed-off-by: Magnus Kulke <[email protected]> Signed-off-by: Dan Mihai <[email protected]> Signed-off-by: Xynnn007 <[email protected]>
- Loading branch information
Showing
8 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
// Copyright (c) 2024 Microsoft Corporation | ||
// Copyright (c) 2024 Alibaba Cloud | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum GetHostDataError { | ||
#[error("Open Sev guest firmware failed: {0}")] | ||
OpenSevGuestFirmware(#[from] std::io::Error), | ||
|
||
#[error("Get report failed: {0}")] | ||
GetReportError(#[from] sev::error::UserApiError), | ||
} | ||
|
||
pub fn get_snp_host_data() -> Result<[u8; 32], GetHostDataError> { | ||
let mut firmware = sev::firmware::guest::Firmware::open()?; | ||
let report_data: [u8; 64] = [0; 64]; | ||
let report = firmware.get_report(None, Some(report_data), Some(0))?; | ||
|
||
Ok(report.host_data) | ||
} |
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,99 @@ | ||
// Copyright (c) 2024 Microsoft Corporation | ||
// Copyright (c) 2024 Alibaba Cloud | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
use scroll::Pread; | ||
|
||
#[repr(C)] | ||
#[derive(Pread)] | ||
/// Type header of TDREPORT_STRUCT. | ||
pub struct TdTransportType { | ||
/// Type of the TDREPORT (0 - SGX, 81 - TDX, rest are reserved). | ||
pub type_: u8, | ||
|
||
/// Subtype of the TDREPORT (Default value is 0). | ||
pub sub_type: u8, | ||
|
||
/// TDREPORT version (Default value is 0). | ||
pub version: u8, | ||
|
||
/// Added for future extension. | ||
pub reserved: u8, | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Pread)] | ||
/// TDX guest report data, MAC and TEE hashes. | ||
pub struct ReportMac { | ||
/// TDREPORT type header. | ||
pub type_: TdTransportType, | ||
|
||
/// Reserved for future extension. | ||
pub reserved1: [u8; 12], | ||
|
||
/// CPU security version. | ||
pub cpu_svn: [u8; 16], | ||
|
||
/// SHA384 hash of TEE TCB INFO. | ||
pub tee_tcb_info_hash: [u8; 48], | ||
|
||
/// SHA384 hash of TDINFO_STRUCT. | ||
pub tee_td_info_hash: [u8; 48], | ||
|
||
/// User defined unique data passed in TDG.MR.REPORT request. | ||
pub reportdata: [u8; 64], | ||
|
||
/// Reserved for future extension. | ||
pub reserved2: [u8; 32], | ||
|
||
/// CPU MAC ID. | ||
pub mac: [u8; 32], | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Pread)] | ||
/// TDX guest measurements and configuration. | ||
pub struct TdInfo { | ||
/// TDX Guest attributes (like debug, spet_disable, etc). | ||
pub attr: [u8; 8], | ||
|
||
/// Extended features allowed mask. | ||
pub xfam: u64, | ||
|
||
/// Build time measurement register. | ||
pub mrtd: [u64; 6], | ||
|
||
/// Software-defined ID for non-owner-defined configuration of the guest - e.g., run-time or OS configuration. | ||
pub mrconfigid: [u8; 48], | ||
|
||
/// Software-defined ID for the guest owner. | ||
pub mrowner: [u64; 6], | ||
|
||
/// Software-defined ID for owner-defined configuration of the guest - e.g., specific to the workload. | ||
pub mrownerconfig: [u64; 6], | ||
|
||
/// Run time measurement registers. | ||
pub rtmr: [u64; 24], | ||
|
||
/// For future extension. | ||
pub reserved: [u64; 14], | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Pread)] | ||
/// Output of TDCALL[TDG.MR.REPORT]. | ||
pub struct TdReport { | ||
/// Mac protected header of size 256 bytes. | ||
pub report_mac: ReportMac, | ||
|
||
/// Additional attestable elements in the TCB are not reflected in the report_mac. | ||
pub tee_tcb_info: [u8; 239], | ||
|
||
/// Added for future extension. | ||
pub reserved: [u8; 17], | ||
|
||
/// Measurements and configuration data of size 512 bytes. | ||
pub tdinfo: TdInfo, | ||
} |
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,15 @@ | ||
// Copyright (c) 2024 Microsoft Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
pub fn pad<const T: usize>(input: &[u8]) -> [u8; T] { | ||
let mut output = [0; T]; | ||
let len = input.len(); | ||
if len > T { | ||
output.copy_from_slice(&input[..T]); | ||
} else { | ||
output[..len].copy_from_slice(input); | ||
} | ||
output | ||
} |