-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The get_report() can be used to request an attestation report to the PSP firmware. If the last parameter CertBuf is provided, the certificate chain required to verify the attestation report is saved in the CertBuf.addr provided. If get_report() fails an Err(error_code) is returned. The wrapped error_code is compliant with the Core Protocol error codes defined in the SVSM spec 0.62 (draft). The psp_rc reference provided can be used to further understand the error. Example: let buf: x86_64::addr::VirtAddr = mem::mem_allocate(0x4000).unwrap(); let mut certs: CertsBuf = CertsBuf::new(buf, 0x4000usize); let mut psp_rc: u64 = 0; let mut data: [u8; USER_DATA_SIZE] = [0u8; USER_DATA_SIZE]; data[0] = 0x31; data[1] = 0x32; data[2] = 0x33; data[4] = 0x34; // Test extended attestation report request let result: Result<psp::msg_report::SnpReportResponse, u64> = psp::request::get_report(&data, &mut psp_rc, Some(&mut certs)); if let Ok(resp) = result { prints!("INFO: Report, {} bytes, vmpl {}\n", { resp.get_report_size() }, { resp.get_report().get_vmpl() } ); prints!("INFO: report_id: {:x?}\n", { resp.get_report().get_report_id() }); prints!("INFO: report_data: {:x?}\n", { resp.get_report().get_report_data() }); let sample: *const [u8; 500] = buf.as_ptr() as *const [u8; 500]; prints!("INFO: certs sample {:x?}\n", { unsafe { *sample } }); } Signed-off-by: Claudio Carvalho <[email protected]>
- Loading branch information
Showing
4 changed files
with
226 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ | |
* Claudio Carvalho <[email protected]> | ||
*/ | ||
|
||
use crate::{getter_func, prints}; | ||
|
||
use alloc::boxed::Box; | ||
use core::slice; | ||
|
||
/// SnpReportRequest size | ||
const REQUEST_SIZE: usize = core::mem::size_of::<SnpReportRequest>(); | ||
|
||
|
@@ -20,6 +25,24 @@ pub struct SnpReportRequest { | |
rsvd: [u8; 28usize], | ||
} | ||
|
||
impl SnpReportRequest { | ||
pub fn new() -> Self { | ||
Self { | ||
user_data: [0u8; USER_DATA_SIZE], | ||
vmpl: 0u32, | ||
rsvd: [0u8; 28], | ||
} | ||
} | ||
|
||
pub fn set_user_data(&mut self, data: &[u8; USER_DATA_SIZE]) { | ||
self.user_data.copy_from_slice(data); | ||
} | ||
|
||
pub fn as_slice(&self) -> &[u8] { | ||
unsafe { slice::from_raw_parts(self as *const _ as *const u8, REQUEST_SIZE) } | ||
} | ||
} | ||
|
||
#[repr(C)] | ||
#[repr(align(2048))] | ||
#[derive(Debug, Copy, Clone)] | ||
|
@@ -30,6 +53,51 @@ pub struct SnpReportResponse { | |
report: AttestationReport, | ||
} | ||
|
||
impl SnpReportResponse { | ||
getter_func!(status, u32); | ||
getter_func!(report_size, u32); | ||
getter_func!(report, AttestationReport); | ||
|
||
pub fn is_valid(&self) -> bool { | ||
// Check status | ||
if self.status != 0 { | ||
prints!("ERR: Bad report status={}\n", { self.status }); | ||
return false; | ||
} | ||
|
||
const REPORT_SIZE: usize = core::mem::size_of::<AttestationReport>(); | ||
|
||
// Check report size | ||
if self.report_size != REPORT_SIZE as u32 { | ||
prints!( | ||
"ERR: Report size {:#x}, but should be {:#x} bytes)\n", | ||
{ self.report_size }, | ||
REPORT_SIZE | ||
); | ||
return false; | ||
} | ||
|
||
true | ||
} | ||
} | ||
|
||
impl TryFrom<Box<[u8]>> for SnpReportResponse { | ||
type Error = (); | ||
|
||
fn try_from(payload: Box<[u8]>) -> Result<Self, Self::Error> { | ||
let resp: SnpReportResponse = { | ||
let (head, body, _tail) = unsafe { payload.align_to::<SnpReportResponse>() }; | ||
if !head.is_empty() { | ||
prints!("ERR: Report response not aligned\n"); | ||
return Err(()); | ||
} | ||
body[0] | ||
}; | ||
|
||
Ok(resp) | ||
} | ||
} | ||
|
||
// Converted tcb_version from enum to | ||
// struct to make alignment simple. | ||
#[repr(C, packed)] | ||
|
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