Skip to content

Commit 125ede1

Browse files
committed
policy: add crl evaluation for v2
Signed-off-by: Jiaqi Gao <[email protected]>
1 parent 9a01c98 commit 125ede1

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

config/templates/policy_v2.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

config/templates/policy_v2_signed.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/migtd/src/mig_policy.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod v2 {
5858
use alloc::{string::String, string::ToString, vec::Vec};
5959
use attestation::verify_quote_with_collaterals;
6060
use chrono::DateTime;
61-
use crypto::pem_cert_to_der;
61+
use crypto::{crl::get_crl_number, pem_cert_to_der};
6262
use lazy_static::lazy_static;
6363
use policy::*;
6464
use spin::Once;
@@ -272,6 +272,10 @@ mod v2 {
272272
.get_engine_svn_by_report(&report_value);
273273

274274
let migtd_tcb = migtd_svn.and_then(|svn| policy.servtd_identity.get_tcb_level_by_svn(svn));
275+
let pck_crl_num = get_crl_number(collaterals.pck_crl.as_bytes())
276+
.map_err(|_| PolicyError::InvalidCollateral)?;
277+
let root_ca_crl_num = get_crl_number(collaterals.root_ca_crl.as_bytes())
278+
.map_err(|_| PolicyError::InvalidCollateral)?;
275279

276280
Ok(PolicyEvaluationInfo {
277281
tcb_date: Some(tcb_date.to_string()),
@@ -281,6 +285,8 @@ mod v2 {
281285
migtd_isvsvn: migtd_svn,
282286
migtd_tcb_date: migtd_tcb.map(|tcb| tcb.tcb_date.clone()),
283287
migtd_tcb_status: migtd_tcb.map(|tcb| tcb.tcb_status.clone()),
288+
pck_crl_num: Some(pck_crl_num),
289+
root_ca_crl_num: Some(root_ca_crl_num),
284290
})
285291
}
286292

src/policy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum PolicyError {
4444
InvalidQuote,
4545
SvnMismatch,
4646
TcbEvaluation,
47+
CrlEvaluation,
4748
HashCalculation,
4849
QuoteVerification,
4950
QuoteGeneration,

src/policy/src/v2/policy.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ pub struct PolicyEvaluationInfo {
9797

9898
/// The date of the MigTD TCB in ISO-8601 format, e.g. "2023-06-19T00:00:00Z"
9999
pub migtd_tcb_date: Option<String>,
100+
101+
/// The minimal crl_num of pck_crl
102+
pub pck_crl_num: Option<u32>,
103+
104+
/// The minimal crl_num of root_ca_crl
105+
pub root_ca_crl_num: Option<u32>,
100106
}
101107

102108
pub struct VerifiedPolicy<'a> {
@@ -295,6 +301,7 @@ enum PolicyTypes {
295301
struct GlobalPolicy {
296302
tcb: Option<TcbPolicy>,
297303
platform: Option<PlatformPolicy>,
304+
crl: Option<CrlPolicy>,
298305
}
299306

300307
impl GlobalPolicy {
@@ -311,6 +318,10 @@ impl GlobalPolicy {
311318
platform_policy.evaluate(value, relative_reference)?;
312319
}
313320

321+
if let Some(crl_policy) = &self.crl {
322+
crl_policy.evaluate(value, relative_reference)?;
323+
}
324+
314325
Ok(())
315326
}
316327
}
@@ -399,6 +410,37 @@ impl PlatformPolicy {
399410
}
400411
}
401412

413+
#[derive(Debug, Serialize, Deserialize)]
414+
#[serde(rename_all = "camelCase")]
415+
struct CrlPolicy {
416+
pck_crl_num: Option<PolicyProperty>,
417+
root_ca_crl_num: Option<PolicyProperty>,
418+
}
419+
420+
impl CrlPolicy {
421+
fn evaluate(
422+
&self,
423+
value: &PolicyEvaluationInfo,
424+
relative_reference: &PolicyEvaluationInfo,
425+
) -> Result<(), PolicyError> {
426+
if let Some(property) = &self.pck_crl_num {
427+
let pck_crl_num = value.pck_crl_num.ok_or(PolicyError::CrlEvaluation)?;
428+
if !property.evaluate_integer(pck_crl_num, relative_reference.pck_crl_num)? {
429+
return Err(PolicyError::CrlEvaluation);
430+
}
431+
}
432+
433+
if let Some(property) = &self.root_ca_crl_num {
434+
let root_ca_crl_num = value.root_ca_crl_num.ok_or(PolicyError::CrlEvaluation)?;
435+
if !property.evaluate_integer(root_ca_crl_num, relative_reference.root_ca_crl_num)? {
436+
return Err(PolicyError::CrlEvaluation);
437+
}
438+
}
439+
440+
Ok(())
441+
}
442+
}
443+
402444
#[derive(Debug, Serialize, Deserialize)]
403445
#[serde(rename_all = "camelCase")]
404446
struct ServtdPolicy {
@@ -691,6 +733,8 @@ mod test {
691733
migtd_tcb_status: None,
692734
migtd_tcb_date: None,
693735
migtd_isvsvn: None,
736+
pck_crl_num: None,
737+
root_ca_crl_num: None,
694738
};
695739
let relative_ref = PolicyEvaluationInfo::default();
696740
assert!(global_policy.evaluate(&value, &relative_ref).is_ok());

0 commit comments

Comments
 (0)