Skip to content

Commit 852cc71

Browse files
committed
add early_update option to DCAP-RA command
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent 3ac0ac5 commit 852cc71

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

app/src/commands/attestation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ pub struct SgxCollateralService {
230230
help = "Certs Service URL (default: https://certificates.trustedservices.intel.com/)"
231231
)]
232232
pub certs_service_url: Option<String>,
233+
#[clap(long = "early_update", help = "Enable early update (default: false)")]
234+
pub is_early_update: bool,
233235
}
234236

235237
impl SgxCollateralService {
@@ -270,6 +272,7 @@ fn run_dcap_remote_attestation<E: EnclaveCommandAPI<S>, S: CommitStore>(
270272
Address::from_hex_string(&cmd.enclave_key)?,
271273
&cmd.collateral_service.get_pcss_url(),
272274
&cmd.collateral_service.get_certs_service_url(),
275+
cmd.collateral_service.is_early_update,
273276
)?;
274277
Ok(())
275278
}
@@ -365,6 +368,7 @@ fn run_zkdcap_remote_attestation<E: EnclaveCommandAPI<S>, S: CommitStore>(
365368
cmd.disable_pre_execution,
366369
&cmd.collateral_service.get_pcss_url(),
367370
&cmd.collateral_service.get_certs_service_url(),
371+
cmd.collateral_service.is_early_update,
368372
)?;
369373
Ok(())
370374
}

modules/remote-attestation/src/dcap.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn run_dcap_ra(
3131
target_enclave_key: Address,
3232
pccs_url: &str,
3333
certs_service_url: &str,
34+
is_early_update: bool,
3435
) -> Result<(), Error> {
3536
let current_time = Time::now();
3637
let result = dcap_ra(
@@ -39,6 +40,7 @@ pub fn run_dcap_ra(
3940
current_time,
4041
pccs_url,
4142
certs_service_url,
43+
is_early_update,
4244
)?;
4345

4446
key_manager
@@ -55,6 +57,7 @@ pub(crate) fn dcap_ra(
5557
current_time: Time,
5658
pccs_url: &str,
5759
certs_service_url: &str,
60+
is_early_update: bool,
5861
) -> Result<DCAPRemoteAttestationResult, Error> {
5962
let ek_info = key_manager.load(target_enclave_key).map_err(|e| {
6063
Error::key_manager(
@@ -69,7 +72,7 @@ pub(crate) fn dcap_ra(
6972

7073
let quote = QuoteV3::from_bytes(&raw_quote).map_err(Error::dcap_quote_verifier)?;
7174

72-
let collateral = get_collateral(pccs_url, certs_service_url, &quote)?;
75+
let collateral = get_collateral(pccs_url, certs_service_url, is_early_update, &quote)?;
7376
let output = verify_quote_dcapv3(&quote, &collateral, current_time.as_unix_timestamp_secs())
7477
.map_err(Error::dcap_quote_verifier)?;
7578
info!(
@@ -131,6 +134,7 @@ fn rsgx_qe_get_quote(app_report: &sgx_report_t) -> Result<Vec<u8>, sgx_quote3_er
131134
fn get_collateral(
132135
pccs_url: &str,
133136
certs_service_url: &str,
137+
is_early_update: bool,
134138
quote: &QuoteV3,
135139
) -> Result<IntelCollateral, Error> {
136140
let pccs_url = pccs_url.trim_end_matches('/');
@@ -149,6 +153,8 @@ fn get_collateral(
149153
));
150154
}
151155

156+
let update_policy = if is_early_update { "early" } else { "standard" };
157+
152158
// get the pck certificate
153159
let pck_cert = &certchain[0];
154160
let pck_cert_issuer = &certchain[1];
@@ -157,13 +163,15 @@ fn get_collateral(
157163
let sgx_extensions = extract_sgx_extensions(pck_cert);
158164
let (tcbinfo_bytes, sgx_tcb_signing_der) = {
159165
let fmspc = hex::encode_upper(sgx_extensions.fmspc);
160-
let res = http_get(format!("{base_url}/tcb?fmspc={fmspc}"))?;
166+
let res = http_get(format!(
167+
"{base_url}/tcb?fmspc={fmspc}&update={update_policy}"
168+
))?;
161169
let issuer_chain =
162170
extract_raw_certs(get_header(&res, "TCB-Info-Issuer-Chain")?.as_bytes())?;
163171
(res.bytes()?.to_vec(), issuer_chain[0].clone())
164172
};
165173

166-
let qeidentity_bytes = http_get(format!("{base_url}/qe/identity"))?
174+
let qeidentity_bytes = http_get(format!("{base_url}/qe/identity?update={update_policy}"))?
167175
.bytes()?
168176
.to_vec();
169177
let sgx_intel_root_ca_crl_der = http_get(format!("{certs_service_url}/IntelSGXRootCA.der"))?
@@ -241,6 +249,7 @@ mod tests {
241249
let collateral = get_collateral(
242250
"https://api.trustedservices.intel.com/",
243251
"https://certificates.trustedservices.intel.com/",
252+
false,
244253
&quote,
245254
)
246255
.unwrap();

modules/remote-attestation/src/zkdcap.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use zkvm::{
1212
verifier::verify_groth16_proof,
1313
};
1414

15+
#[allow(clippy::too_many_arguments)]
1516
pub fn run_zkdcap_ra(
1617
key_manager: &EnclaveKeyManager,
1718
target_enclave_key: Address,
@@ -20,6 +21,7 @@ pub fn run_zkdcap_ra(
2021
disable_pre_execution: bool,
2122
pccs_url: &str,
2223
certs_server_url: &str,
24+
is_early_update: bool,
2325
) -> Result<(), Error> {
2426
let image_id = compute_image_id(elf)
2527
.map_err(|e| Error::anyhow(anyhow!("cannot compute image id: {}", e)))?;
@@ -35,6 +37,7 @@ pub fn run_zkdcap_ra(
3537
current_time,
3638
pccs_url,
3739
certs_server_url,
40+
is_early_update,
3841
)?;
3942

4043
debug!(

0 commit comments

Comments
 (0)