Skip to content

Commit

Permalink
Use ReportData from mc-sgx-core-types (#3435)
Browse files Browse the repository at this point in the history
Previously the `ReportData` was defined in `mc-attest-core`. Now the
`ReportData` from `mc-sgx-core-types` is used.
  • Loading branch information
nick-mobilecoin authored Jul 25, 2023
1 parent a882be4 commit ee496bc
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 95 deletions.
2 changes: 1 addition & 1 deletion attest/core/data/test/quote_ok_str.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Quote: { version: 2, sign_type: Unlinkable, epid_group_id: 00000b4d, qe_svn: 8, pce_svn: 7, xeid: 0, basename: Basename(b6b3ee840b3fb5a6a2b14c54221aab6aad6bd3cd49db38f2b12d2c37b8943eda), report_body: ReportBody: { cpu_svn: CpuSecurityVersion(0808ffffff0201000000000000000000), misc_select: 0, isv_ext_prod_id: ExtendedProductId(00000000000000000000000000000000), attributes: Attributes { flags: 7, xfrm: 7 }, mr_enclave: MrEnclave(973140462e17d2f523511d798061eae3e8282b884ee078de91c99d833f559bbc), mr_signer: MrSigner(7ee5e29d74623fdbc6fbf1454be6f3bb0b86c12366b7b478ad13353e44de8411), config_id: ConfigId(00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000), isv_prod_id: 0, isv_svn: IsvSvn(0), config_svn: 0, isv_family_id: FamilyId(00000000000000000000000000000000), report_data: ReportData(e7a0dc1b25b0e14d156c9f12820f3d226819fd68f2376acbf73d401c959a55900000000000000000000000000000000000000000000000000000000000000000) }, signature_len: 680, signature: Some(146c25c134df61f2f55fbba368333e1c77b3524f483212f90b89d6432a21ab2adcfdbeaeb816bdb7a988a67b502c92e7b4a683b88df6ffc649d24e75d61dbfcf8aa09e22da5fb84b24fa1908f8d338277bbf8dc3c6e060ace551b7eaf2d3fdbbfc38905d0ed9d4cd28657f07ce4d5ba9e405a597c534484b4e38c54d5f9a7bcc602373f96a2962c51b60162b28c30d8a374d12f3f46ec5970699c39e8e7a3527443c65cd56abf0ad1153426e0ba32edf84070f2bfa3a32a7463bcdaec0c46ce9337899c1399e68b04ed36409c49bddd2db2bfc40ff7a1b281e2c4fa9607c678ffa4f7a7d93cfd4610047eeb62755861240eed273158c33dd17f539d248a1b3a197d986f9c52d43a246060a6a3bff21e971d82f1bfec654b31265f0e980a54a29e2ba8aca6bffe27668dd21a268010000d46a0dc1ffc4986b994b0b6efd610637d7b22bf21888c6296a9a538cadb8ac5d8f4156ac01db17579b90acd4e130f5865373a84d2ea131ee4f326d169d41d1b552daaa4c514c8ae1245185bccf4f4c9b6b5f3e3cec93216cd1ae023f03155fbf05ff0701b7fadd29a1f097318b9ba2a416e86d3131859c7aea45c58cda4a5a6fa833eabcf0a520d7342d514dbd5c9fa85ed89d8e85342a3b6f1bc1144c11102cd6409e9e93ee672ebffed9b17b0e766a9556ff0bc0da5baac91de39d1deacc35e4036795bd5ebfe7c2e8392921757f2355fdb5ff0c3d6885712cf399d0598a95df36ea34f10f3e4906043d913449d24e12228583d0713aed8a54c530cdc4c28acfc916fe7ba96be700ed2eccb3ba6874a1badd2a1ef80bac9169305666b33091f8ad935e31d3ed33251642787b161e0322d891e3a1fa171251783b61b3b33e5dffaba9010ee33e445840e0e493799d7281a681d86b1afd05cfd90b2eaf0584bccf7eefe5d9747a2e52a0e5c7a0a5d2ff1f1af590d7064abd) }
Quote: { version: 2, sign_type: Unlinkable, epid_group_id: 00000b4d, qe_svn: 8, pce_svn: 7, xeid: 0, basename: Basename(b6b3ee840b3fb5a6a2b14c54221aab6aad6bd3cd49db38f2b12d2c37b8943eda), report_body: ReportBody: { cpu_svn: CpuSecurityVersion(0808ffffff0201000000000000000000), misc_select: 0, isv_ext_prod_id: ExtendedProductId(00000000000000000000000000000000), attributes: Attributes { flags: 7, xfrm: 7 }, mr_enclave: MrEnclave(973140462e17d2f523511d798061eae3e8282b884ee078de91c99d833f559bbc), mr_signer: MrSigner(7ee5e29d74623fdbc6fbf1454be6f3bb0b86c12366b7b478ad13353e44de8411), config_id: ConfigId(00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000), isv_prod_id: 0, isv_svn: IsvSvn(0), config_svn: 0, isv_family_id: FamilyId(00000000000000000000000000000000), report_data: ReportData(sgx_report_data_t { d: [231, 160, 220, 27, 37, 176, 225, 77, 21, 108, 159, 18, 130, 15, 61, 34, 104, 25, 253, 104, 242, 55, 106, 203, 247, 61, 64, 28, 149, 154, 85, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }) }, signature_len: 680, signature: Some(146c25c134df61f2f55fbba368333e1c77b3524f483212f90b89d6432a21ab2adcfdbeaeb816bdb7a988a67b502c92e7b4a683b88df6ffc649d24e75d61dbfcf8aa09e22da5fb84b24fa1908f8d338277bbf8dc3c6e060ace551b7eaf2d3fdbbfc38905d0ed9d4cd28657f07ce4d5ba9e405a597c534484b4e38c54d5f9a7bcc602373f96a2962c51b60162b28c30d8a374d12f3f46ec5970699c39e8e7a3527443c65cd56abf0ad1153426e0ba32edf84070f2bfa3a32a7463bcdaec0c46ce9337899c1399e68b04ed36409c49bddd2db2bfc40ff7a1b281e2c4fa9607c678ffa4f7a7d93cfd4610047eeb62755861240eed273158c33dd17f539d248a1b3a197d986f9c52d43a246060a6a3bff21e971d82f1bfec654b31265f0e980a54a29e2ba8aca6bffe27668dd21a268010000d46a0dc1ffc4986b994b0b6efd610637d7b22bf21888c6296a9a538cadb8ac5d8f4156ac01db17579b90acd4e130f5865373a84d2ea131ee4f326d169d41d1b552daaa4c514c8ae1245185bccf4f4c9b6b5f3e3cec93216cd1ae023f03155fbf05ff0701b7fadd29a1f097318b9ba2a416e86d3131859c7aea45c58cda4a5a6fa833eabcf0a520d7342d514dbd5c9fa85ed89d8e85342a3b6f1bc1144c11102cd6409e9e93ee672ebffed9b17b0e766a9556ff0bc0da5baac91de39d1deacc35e4036795bd5ebfe7c2e8392921757f2355fdb5ff0c3d6885712cf399d0598a95df36ea34f10f3e4906043d913449d24e12228583d0713aed8a54c530cdc4c28acfc916fe7ba96be700ed2eccb3ba6874a1badd2a1ef80bac9169305666b33091f8ad935e31d3ed33251642787b161e0322d891e3a1fa171251783b61b3b33e5dffaba9010ee33e445840e0e493799d7281a681d86b1afd05cfd90b2eaf0584bccf7eefe5d9747a2e52a0e5c7a0a5d2ff1f1af590d7064abd) }
23 changes: 6 additions & 17 deletions attest/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,17 @@ pub use crate::{
seal::{IntelSealed, IntelSealingError, ParseSealedError, Sealed},
sigrl::SigRL,
types::{
attributes::Attributes,
basename::Basename,
config_id::ConfigId,
cpu_svn::CpuSecurityVersion,
epid_group_id::EpidGroupId,
ext_prod_id::ExtendedProductId,
family_id::FamilyId,
key_id::KeyId,
mac::Mac,
measurement::Measurement,
pib::PlatformInfoBlob,
report_body::ReportBody,
report_data::{ReportData, ReportDataMask},
spid::ProviderId,
update_info::*,
ConfigSecurityVersion, MiscSelect, ProductId,
attributes::Attributes, basename::Basename, config_id::ConfigId,
cpu_svn::CpuSecurityVersion, epid_group_id::EpidGroupId, ext_prod_id::ExtendedProductId,
family_id::FamilyId, key_id::KeyId, mac::Mac, measurement::Measurement,
pib::PlatformInfoBlob, report_body::ReportBody, report_data::ReportDataMask,
spid::ProviderId, update_info::*, ConfigSecurityVersion, MiscSelect, ProductId,
},
};

pub use mc_attest_verifier_types::{VerificationReport, VerificationSignature};

pub use mc_sgx_core_types::{IsvSvn, MrEnclave, MrSigner, TargetInfo};
pub use mc_sgx_core_types::{IsvSvn, MrEnclave, MrSigner, ReportData, TargetInfo};

/// The IAS version we support
pub const IAS_VERSION: f64 = 4.0;
Expand Down
2 changes: 1 addition & 1 deletion attest/core/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod test {
},
};

const TEST_REPORT_DEBUGSTR: &str = "Report: { body: ReportBody: { cpu_svn: CpuSecurityVersion(0102030405060708090a0b0c0d0e0f10), misc_select: 17, isv_ext_prod_id: ExtendedProductId(0102030405060708090a0b0c0d0e0f10), attributes: Attributes { flags: 72623859790382856, xfrm: 578437695752307201 }, mr_enclave: MrEnclave(1112131415161718191a1b1c1d1e1f202122232425262728292a2b2b2c2d2e2f), mr_signer: MrSigner(303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f), config_id: ConfigId(505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f), isv_prod_id: 144, isv_svn: IsvSvn(145), config_svn: 146, isv_family_id: FamilyId(939495969798999a9b9c9d9e9fa0a1a2), report_data: ReportData(a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2) }, key: KeyId(0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20), mac: Mac(0102030405060708090a0b0c0d0e0f10) }";
const TEST_REPORT_DEBUGSTR: &str = "Report: { body: ReportBody: { cpu_svn: CpuSecurityVersion(0102030405060708090a0b0c0d0e0f10), misc_select: 17, isv_ext_prod_id: ExtendedProductId(0102030405060708090a0b0c0d0e0f10), attributes: Attributes { flags: 72623859790382856, xfrm: 578437695752307201 }, mr_enclave: MrEnclave(1112131415161718191a1b1c1d1e1f202122232425262728292a2b2b2c2d2e2f), mr_signer: MrSigner(303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f), config_id: ConfigId(505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f), isv_prod_id: 144, isv_svn: IsvSvn(145), config_svn: 146, isv_family_id: FamilyId(939495969798999a9b9c9d9e9fa0a1a2), report_data: ReportData(sgx_report_data_t { d: [163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226] }) }, key: KeyId(0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20), mac: Mac(0102030405060708090a0b0c0d0e0f10) }";

#[test]
fn test_serde() {
Expand Down
24 changes: 9 additions & 15 deletions attest/core/src/types/report_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ use crate::{
impl_sgx_wrapper_reqs,
traits::SgxWrapperType,
types::{
attributes::Attributes,
config_id::ConfigId,
cpu_svn::CpuSecurityVersion,
ext_prod_id::ExtendedProductId,
family_id::FamilyId,
measurement::Measurement,
report_data::{ReportData, ReportDataMask},
ConfigSecurityVersion, MiscSelect, ProductId,
attributes::Attributes, config_id::ConfigId, cpu_svn::CpuSecurityVersion,
ext_prod_id::ExtendedProductId, family_id::FamilyId, measurement::Measurement,
report_data::ReportDataMask, ConfigSecurityVersion, MiscSelect, ProductId,
},
IsvSvn,
IsvSvn, ReportData,
};
use alloc::vec::Vec;
use core::{
Expand Down Expand Up @@ -62,7 +57,7 @@ const RB_RESERVED4_END: usize = RB_RESERVED4_START + 42;
const RB_ISVFAMILYID_START: usize = RB_RESERVED4_END;
const RB_ISVFAMILYID_END: usize = RB_ISVFAMILYID_START + <FamilyId as IntelLayout>::X86_64_CSIZE;
const RB_REPORTDATA_START: usize = RB_ISVFAMILYID_END;
const RB_REPORTDATA_END: usize = RB_REPORTDATA_START + <ReportData as IntelLayout>::X86_64_CSIZE;
const RB_REPORTDATA_END: usize = RB_REPORTDATA_START + ReportData::SIZE;

const REPORT_BODY_SIZE: usize = RB_REPORTDATA_END;
// const REPORT_SIZE: usize = 432; // taken from sgx_types
Expand Down Expand Up @@ -330,10 +325,7 @@ impl SgxWrapperType<sgx_report_body_t> for ReportBody {
&src.isv_family_id,
&mut dest[RB_ISVFAMILYID_START..RB_ISVFAMILYID_END],
)?;
ReportData::write_ffi_bytes(
&src.report_data,
&mut dest[RB_REPORTDATA_START..RB_REPORTDATA_END],
)?;
dest[RB_REPORTDATA_START..RB_REPORTDATA_END].copy_from_slice(&src.report_data.d);
Ok(REPORT_BODY_SIZE)
}
}
Expand Down Expand Up @@ -391,7 +383,9 @@ impl<'src> TryFrom<&'src [u8]> for ReportBody {
reserved4,
isv_family_id: FamilyId::try_from(&src[RB_ISVFAMILYID_START..RB_ISVFAMILYID_END])?
.into(),
report_data: ReportData::try_from(&src[RB_REPORTDATA_START..RB_REPORTDATA_END])?.into(),
report_data: ReportData::try_from(&src[RB_REPORTDATA_START..RB_REPORTDATA_END])
.map_err(|_| EncodingError::InvalidInputLength)?
.into(),
}))
}
}
Expand Down
60 changes: 19 additions & 41 deletions attest/core/src/types/report_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,26 @@

//! The report data structure
use crate::impl_sgx_newtype_for_bytestruct;
use mc_sgx_types::{sgx_report_data_t, SGX_REPORT_DATA_SIZE};
use mc_util_encodings::{Error as EncodingError, IntelLayout};
use serde::{Deserialize, Serialize};
use crate::ReportData;
use mc_util_encodings::Error as EncodingError;
use subtle::ConstantTimeEq;

/// A data structure used for the user data in a report.
#[derive(Clone, Copy, Default)]
#[repr(transparent)]
pub struct ReportData(sgx_report_data_t);

impl_sgx_newtype_for_bytestruct! {
ReportData, sgx_report_data_t, SGX_REPORT_DATA_SIZE, d;
}

#[derive(
Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
pub struct ReportDataMask {
data: ReportData,
mask: ReportData,
}

impl ReportDataMask {
pub fn new_with_mask(data: &[u8], mask: &[u8]) -> Result<Self, EncodingError> {
if data.len() > ReportData::X86_64_CSIZE || mask.len() > ReportData::X86_64_CSIZE {
if data.len() > ReportData::SIZE || mask.len() > ReportData::SIZE {
Err(EncodingError::InvalidInputLength)
} else {
let mut retval = ReportDataMask::default();
retval.data.0.d[..data.len()].copy_from_slice(data);
retval.mask.0.d[..mask.len()].copy_from_slice(mask);
let r_data: &mut [u8] = retval.data.as_mut();
r_data[..data.len()].copy_from_slice(data);
let r_mask: &mut [u8] = retval.mask.as_mut();
r_mask[..mask.len()].copy_from_slice(mask);
Ok(retval)
}
}
Expand All @@ -42,13 +31,15 @@ impl<'src> TryFrom<&'src [u8]> for ReportDataMask {
type Error = EncodingError;

fn try_from(src: &[u8]) -> Result<Self, EncodingError> {
if src.len() > ReportData::X86_64_CSIZE {
if src.len() > ReportData::SIZE {
Err(EncodingError::InvalidInputLength)
} else {
let mut retval = ReportDataMask::default();
retval.data.0.d[..src.len()].copy_from_slice(src);
for i in 0..src.len() {
retval.mask.0.d[i] = 0xff;
let data: &mut [u8] = retval.data.as_mut();
data[..src.len()].copy_from_slice(src);
let mask: &mut [u8] = retval.mask.as_mut();
for byte in mask.iter_mut().take(src.len()) {
*byte = 0xff;
}
Ok(retval)
}
Expand All @@ -57,22 +48,18 @@ impl<'src> TryFrom<&'src [u8]> for ReportDataMask {

impl PartialEq<ReportData> for ReportDataMask {
fn eq(&self, rhs: &ReportData) -> bool {
let mut self_data = [0u8; ReportData::X86_64_CSIZE];
let mut rhs_data = [0u8; ReportData::X86_64_CSIZE];

for i in 0..self.mask.0.d.len() {
self_data[i] = self.data.0.d[i] & self.mask.0.d[i];
rhs_data[i] = rhs.0.d[i] & self.mask.0.d[i];
}
let data = &self.data & &self.mask;
let masked_rhs = rhs & &self.mask;

self_data[..].ct_eq(&rhs_data[..]).unwrap_u8() == 1
let data_ref: &[u8] = data.as_ref();
data_ref.ct_eq(masked_rhs.as_ref()).unwrap_u8() == 1
}
}

#[cfg(test)]
mod test {
use super::*;
use mc_util_serial::{deserialize, serialize};
use mc_sgx_types::sgx_report_data_t;

const REPORT_DATA_TEST: sgx_report_data_t = sgx_report_data_t {
d: [
Expand All @@ -82,15 +69,6 @@ mod test {
],
};

#[test]
fn test_serde() {
let data: ReportData = REPORT_DATA_TEST.into();
let serialized = serialize(&data).expect("Could not serialize report_data");
let data2: ReportData =
deserialize(&serialized).expect("Could not deserialize report_data");
assert_eq!(data, data2);
}

#[test]
fn test_mask() {
let bitmask: [u8; 32] = [
Expand Down
2 changes: 1 addition & 1 deletion attest/verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl Verifier {

/// Verify the report data matches the data mask given
pub fn report_data(&mut self, report_data: &ReportDataMask) -> &mut Self {
self.report_body_verifiers.push((*report_data).into());
self.report_body_verifiers.push(report_data.clone().into());
self
}

Expand Down
2 changes: 1 addition & 1 deletion attest/verifier/src/report_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Verify<ReportBody> for DebugVerifier {

/// A [`Verify<ReportBody>`] implementation that will check if the enclave's
/// report data matches the mask given.
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DataVerifier(ReportDataMask);

impl Verify<ReportBody> for DataVerifier {
Expand Down
19 changes: 1 addition & 18 deletions sgx/types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use error::*;
use marker::ContiguousMemory;

extern crate mc_sgx_core_sys_types;
pub use self::mc_sgx_core_sys_types::sgx_target_info_t;
pub use self::mc_sgx_core_sys_types::{sgx_target_info_t, sgx_report_data_t};

//
// sgx_attributes.h
Expand Down Expand Up @@ -388,8 +388,6 @@ impl_struct_ContiguousMemory! {
pub const SGX_HASH_SIZE: ::size_t = 32;
pub const SGX_MAC_SIZE: ::size_t = 16;

pub const SGX_REPORT_DATA_SIZE: ::size_t = 64;

pub const SGX_ISVEXT_PROD_ID_SIZE: ::size_t = 16;
pub const SGX_ISV_FAMILY_ID_SIZE: ::size_t = 16;

Expand All @@ -405,21 +403,6 @@ impl_struct! {

pub type sgx_mac_t = [::uint8_t; SGX_MAC_SIZE];

impl_copy_clone! {

pub struct sgx_report_data_t {
pub d: [::uint8_t; SGX_REPORT_DATA_SIZE],
}
}

impl_struct_default! {
sgx_report_data_t, 64;
}

impl_struct_ContiguousMemory! {
sgx_report_data_t;
}

pub type sgx_prod_id_t = ::uint16_t;

pub const SGX_TARGET_INFO_RESERVED1_BYTES: ::size_t = 2;
Expand Down

0 comments on commit ee496bc

Please sign in to comment.