Skip to content

Commit 5cc698b

Browse files
committed
add expected_tcb_evaluation_data_number to zkdcap attestation command
Signed-off-by: Jun Kimura <[email protected]>
1 parent 14753f8 commit 5cc698b

File tree

5 files changed

+87
-17
lines changed

5 files changed

+87
-17
lines changed

app/src/commands/attestation.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use remote_attestation::{
1111
dcap,
1212
dcap_pcs::client::PCSClient,
1313
dcap_simulation::{DCAP_SIM_ROOT_CA_PEM, DCAP_SIM_ROOT_KEY_PKCS8},
14+
dcap_utils::ValidatedPCSClient,
1415
ias, zkdcap, IASMode,
1516
};
1617
use remote_attestation::{
@@ -251,6 +252,11 @@ pub struct SgxCollateralService {
251252
help = "Update policy (early(default) or standard)"
252253
)]
253254
pub update_policy: UpdatePolicy,
255+
#[clap(
256+
long = "expected_tcb_evaluation_data_number",
257+
help = "Expected TCB Evaluation Data Number for TCB Info and QE Identity"
258+
)]
259+
pub expected_tcb_evaluation_data_number: Option<u32>,
254260
}
255261

256262
#[derive(Clone, Debug, PartialEq)]
@@ -285,12 +291,15 @@ impl SgxCollateralService {
285291
}
286292
}
287293

288-
impl From<SgxCollateralService> for PCSClient {
294+
impl From<SgxCollateralService> for ValidatedPCSClient {
289295
fn from(service: SgxCollateralService) -> Self {
290296
Self::new(
291-
service.get_pccs_url().as_str(),
292-
service.get_certs_service_url().as_str(),
293-
service.update_policy == UpdatePolicy::Early,
297+
PCSClient::new(
298+
service.get_pccs_url().as_str(),
299+
service.get_certs_service_url().as_str(),
300+
service.update_policy == UpdatePolicy::Early,
301+
),
302+
service.expected_tcb_evaluation_data_number,
294303
)
295304
}
296305
}

modules/remote-attestation/src/dcap.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use crate::dcap_utils::DCAPRemoteAttestationResult;
1+
use crate::dcap_utils::{DCAPRemoteAttestationResult, ValidatedPCSClient};
22
use crate::errors::Error;
33
use anyhow::anyhow;
44
use attestation_report::QEType;
55
use crypto::Address;
6-
use dcap_pcs::client::PCSClient;
76
use dcap_quote_verifier::quotes::version_3::verify_quote_v3;
87
use dcap_quote_verifier::types::quotes::version_3::QuoteV3;
98
use keymanager::EnclaveKeyManager;
@@ -27,7 +26,7 @@ pub const INTEL_ROOT_CA_HASH: [u8; 32] = [
2726
pub fn run_dcap_ra(
2827
key_manager: &EnclaveKeyManager,
2928
target_enclave_key: Address,
30-
pcs_client: PCSClient,
29+
pcs_client: ValidatedPCSClient,
3130
) -> Result<(), Error> {
3231
let current_time = Time::now();
3332
let result = dcap_ra(key_manager, target_enclave_key, current_time, pcs_client)?;
@@ -44,7 +43,7 @@ pub(crate) fn dcap_ra(
4443
key_manager: &EnclaveKeyManager,
4544
target_enclave_key: Address,
4645
current_time: Time,
47-
pcs_client: PCSClient,
46+
pcs_client: ValidatedPCSClient,
4847
) -> Result<DCAPRemoteAttestationResult, Error> {
4948
let ek_info = key_manager.load(target_enclave_key).map_err(|e| {
5049
Error::key_manager(
@@ -64,7 +63,7 @@ pub(crate) fn dcap_ra(
6463
let (quote, _) = QuoteV3::from_bytes(&raw_quote).map_err(Error::dcap_quote_verifier)?;
6564

6665
let collateral = pcs_client
67-
.get_collateral(true, &quote.signature.qe_cert_data)
66+
.validate_and_get_collateral(true, &quote.signature.qe_cert_data)
6867
.map_err(|e| Error::anyhow(anyhow!("cannot get collateral data: {}", e)))?;
6968

7069
info!(
@@ -115,6 +114,7 @@ fn rsgx_qe_get_quote(app_report: &sgx_report_t) -> Result<Vec<u8>, sgx_quote3_er
115114
#[cfg(test)]
116115
mod tests {
117116
use super::*;
117+
use dcap_pcs::client::PCSClient;
118118
use dcap_quote_verifier::{crypto::keccak256sum, types::SGX_TEE_TYPE};
119119

120120
#[test]

modules/remote-attestation/src/dcap_utils.rs

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
11
use attestation_report::DCAPQuote;
2-
use dcap_quote_verifier::collateral::QvCollateral;
2+
use dcap_pcs::client::PCSClient;
33
use dcap_quote_verifier::verifier::QuoteVerificationOutput;
4+
use dcap_quote_verifier::{collateral::QvCollateral, types::quotes::CertData};
45
use lcp_types::proto::lcp::service::enclave::v1::{QvCollateral as ProtoQvCollateral, Validity};
6+
use std::ops::Deref;
7+
8+
pub struct ValidatedPCSClient {
9+
client: PCSClient,
10+
expected_tcb_evaluation_data_number: Option<u32>,
11+
}
12+
13+
impl ValidatedPCSClient {
14+
pub fn new(client: PCSClient, expected_tcb_evaluation_data_number: Option<u32>) -> Self {
15+
Self {
16+
client,
17+
expected_tcb_evaluation_data_number,
18+
}
19+
}
20+
21+
pub fn validate_and_get_collateral(
22+
&self,
23+
is_sgx: bool,
24+
qe_cert_data: &CertData,
25+
) -> Result<QvCollateral, anyhow::Error> {
26+
let collateral = self.client.get_collateral(is_sgx, qe_cert_data)?;
27+
if let Some(expected_tcb_evaluation_data_number) = self.expected_tcb_evaluation_data_number
28+
{
29+
let tcb_info_tcb_evaluation_data_number = collateral
30+
.get_tcb_info_v3()?
31+
.tcb_info
32+
.tcb_evaluation_data_number;
33+
if tcb_info_tcb_evaluation_data_number != expected_tcb_evaluation_data_number {
34+
return Err(anyhow::anyhow!(
35+
"TCBInfo: the number of TCB evaluation data is not as expected: {} != {}",
36+
tcb_info_tcb_evaluation_data_number,
37+
expected_tcb_evaluation_data_number
38+
));
39+
}
40+
let qe_identity_tcb_evaluation_data_number = collateral
41+
.get_qe_identity_v2()?
42+
.enclave_identity
43+
.tcb_evaluation_data_number;
44+
if qe_identity_tcb_evaluation_data_number != expected_tcb_evaluation_data_number {
45+
return Err(anyhow::anyhow!(
46+
"QEIdentity: the number of TCB evaluation data is not as expected: {} != {}",
47+
qe_identity_tcb_evaluation_data_number,
48+
expected_tcb_evaluation_data_number
49+
));
50+
}
51+
}
52+
Ok(collateral)
53+
}
54+
}
55+
56+
impl Deref for ValidatedPCSClient {
57+
type Target = PCSClient;
58+
59+
fn deref(&self) -> &Self::Target {
60+
&self.client
61+
}
62+
}
563

664
#[derive(Debug)]
765
pub struct DCAPRemoteAttestationResult {

modules/remote-attestation/src/zkdcap.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::{
22
dcap::dcap_ra,
33
dcap_simulation::{dcap_ra_simulation, DCAPRASimulationOpts},
4-
dcap_utils::DCAPRemoteAttestationResult,
4+
dcap_utils::{DCAPRemoteAttestationResult, ValidatedPCSClient},
55
errors::Error,
66
};
77
use anyhow::anyhow;
88
use attestation_report::{Risc0ZKVMProof, ZKDCAPQuote, ZKVMProof};
99
use crypto::Address;
10-
use dcap_pcs::client::PCSClient;
1110
use dcap_quote_verifier::{collateral::QvCollateral, verifier::QuoteVerificationOutput};
1211
use keymanager::EnclaveKeyManager;
1312
use lcp_types::Time;
@@ -34,7 +33,7 @@ pub fn run_zkdcap_ra(
3433
prover_mode: Risc0ProverMode,
3534
elf: &[u8],
3635
disable_pre_execution: bool,
37-
pcs_client: PCSClient,
36+
pcs_client: ValidatedPCSClient,
3837
) -> Result<(), Error> {
3938
let image_id = compute_image_id(elf)
4039
.map_err(|e| Error::anyhow(anyhow!("cannot compute image id: {}", e)))?;

tests/integration/src/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mod tests {
3838
use lcp_proto::protobuf::Protobuf;
3939
use lcp_types::{ClientId, Height};
4040
use log::*;
41+
use remote_attestation::dcap_utils::ValidatedPCSClient;
4142
use std::str::FromStr;
4243
use std::sync::{Arc, RwLock};
4344
use store::{host::HostStore, memory::MemStore};
@@ -250,10 +251,13 @@ mod tests {
250251
Risc0ProverMode::Dev,
251252
DCAP_QUOTE_VERIFIER_ELF,
252253
false,
253-
PCSClient::new(
254-
"https://api.trustedservices.intel.com/",
255-
"https://certificates.trustedservices.intel.com/",
256-
false,
254+
ValidatedPCSClient::new(
255+
PCSClient::new(
256+
"https://api.trustedservices.intel.com/",
257+
"https://certificates.trustedservices.intel.com/",
258+
false,
259+
),
260+
None,
257261
),
258262
);
259263
assert!(res.is_ok(), "zkDCAP Remote Attestation Failed {:?}", res);

0 commit comments

Comments
 (0)