Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trace logs for FMSPC and collateral #1332

Merged
merged 9 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,7 @@ name = "itp-enclave-api"
version = "0.9.0"
dependencies = [
"frame-support",
"hex",
"itc-parentchain",
"itp-enclave-api-ffi",
"itp-settings",
Expand Down
1 change: 1 addition & 0 deletions core-primitives/enclave-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
hex = "0.4"
log = "0.4"
serde_json = "1.0"
thiserror = "1.0.25"
Expand Down
61 changes: 61 additions & 0 deletions core-primitives/enclave-api/src/remote_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ impl RemoteAttestation for Enclave {

let mut unchecked_extrinsic: Vec<u8> = vec![0u8; EXTRINSIC_MAX_SIZE];

trace!("Generating dcap_ra_extrinsic with URL: {}", w_url);

let url = w_url.encode();

let result = unsafe {
Expand Down Expand Up @@ -202,6 +204,10 @@ impl RemoteAttestation for Enclave {
ensure!(result == sgx_status_t::SGX_SUCCESS, Error::Sgx(result));
ensure!(retval == sgx_status_t::SGX_SUCCESS, Error::Sgx(retval));

unsafe {
trace!("Generating DCAP RA Quote: {}", *dcap_quote_p);
}

Ok(dcap_quote_vec)
}

Expand All @@ -213,6 +219,8 @@ impl RemoteAttestation for Enclave {
let quote_size = self.qe_get_quote_size()?;
info!("Retrieved quote size of {:?}", quote_size);

trace!("Generating dcap_ra_extrinsic with URL: {}", w_url);

let mut unchecked_extrinsic: Vec<u8> = vec![0u8; EXTRINSIC_MAX_SIZE];

let url = w_url.encode();
Expand Down Expand Up @@ -241,6 +249,8 @@ impl RemoteAttestation for Enclave {
let mut retval = sgx_status_t::SGX_SUCCESS;
let mut unchecked_extrinsic: Vec<u8> = vec![0u8; EXTRINSIC_MAX_SIZE];

trace!("Generating register quoting enclave");

let collateral_ptr = self.get_dcap_collateral(fmspc)?;

let result = unsafe {
Expand All @@ -264,6 +274,8 @@ impl RemoteAttestation for Enclave {
let mut retval = sgx_status_t::SGX_SUCCESS;
let mut unchecked_extrinsic: Vec<u8> = vec![0u8; EXTRINSIC_MAX_SIZE];

trace!("Generating tcb_info registration");

let collateral_ptr = self.get_dcap_collateral(fmspc)?;

let result = unsafe {
Expand Down Expand Up @@ -373,6 +385,55 @@ impl RemoteAttestation for Enclave {
collateral_ptr_ptr,
)
};

trace!("FMSPC: {:?}", hex::encode(fmspc));

if collateral_ptr.is_null() {
error!("PCK quote collateral data is null, sgx_status is: {}", sgx_status);
return Err(Error::SgxQuote(sgx_status))
}

trace!("collateral:");
// SAFETY: the previous block checks for `collateral_ptr` being null.
// SAFETY: the fields should be nul terminated C strings.
unsafe {
let collateral = &*collateral_ptr;
trace!(
"version: {}\n, \
tee_type: {}\n, \
pck_crl_issuer_chain: {:?}\n, \
pck_crl_issuer_chain_size: {}\n, \
root_ca_crl: {:?}\n, \
root_ca_crl_size: {}\n, \
pck_crl: {:?}\n, \
pck_crl_size: {}\n, \
tcb_info_issuer_chain: {:?}\n, \
tcb_info_issuer_chain_size: {}\n, \
tcb_info: {:?}\n, \
tcb_info_size: {}\n, \
qe_identity_issuer_chain: {:?}\n, \
qe_identity_issuer_chain_size: {}\n, \
qe_identity: {:?}\n, \
qe_identity_size: {}\n",
collateral.version,
collateral.tee_type,
std::ffi::CStr::from_ptr(collateral.pck_crl_issuer_chain).to_str().unwrap(),
collateral.pck_crl_issuer_chain_size,
std::ffi::CStr::from_ptr(collateral.root_ca_crl).to_str().unwrap(),
collateral.root_ca_crl_size,
std::ffi::CStr::from_ptr(collateral.pck_crl).to_str().unwrap(),
collateral.pck_crl_size,
std::ffi::CStr::from_ptr(collateral.tcb_info_issuer_chain).to_str().unwrap(),
collateral.tcb_info_issuer_chain_size,
std::ffi::CStr::from_ptr(collateral.tcb_info).to_str().unwrap(),
collateral.tcb_info_size,
std::ffi::CStr::from_ptr(collateral.qe_identity_issuer_chain).to_str().unwrap(),
collateral.qe_identity_issuer_chain_size,
std::ffi::CStr::from_ptr(collateral.qe_identity).to_str().unwrap(),
collateral.qe_identity_size,
);
};

ensure!(sgx_status == sgx_quote3_error_t::SGX_QL_SUCCESS, Error::SgxQuote(sgx_status));
Ok(collateral_ptr)
}
Expand Down