oasis_core_runtime/common/sgx/pcs/
policy.rs1use super::{constants::*, report::TdReport, Error};
3
4#[derive(Clone, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
6pub struct QuotePolicy {
7 #[cbor(optional)]
9 pub disabled: bool,
10
11 pub tcb_validity_period: u16,
13
14 pub min_tcb_evaluation_data_number: u32,
17
18 #[cbor(optional)]
21 pub fmspc_whitelist: Vec<String>,
22
23 #[cbor(optional)]
26 pub fmspc_blacklist: Vec<String>,
27
28 #[cbor(optional)]
30 pub tdx: Option<TdxQuotePolicy>,
31}
32
33impl Default for QuotePolicy {
34 fn default() -> Self {
35 Self {
36 disabled: false,
37 tcb_validity_period: 30,
38 min_tcb_evaluation_data_number: DEFAULT_MIN_TCB_EVALUATION_DATA_NUMBER,
39 fmspc_whitelist: Vec::new(),
40 fmspc_blacklist: Vec::new(),
41 tdx: None,
42 }
43 }
44}
45
46impl QuotePolicy {
47 pub fn is_expired(&self, now: i64, ts: i64) -> bool {
49 if self.disabled {
50 return true;
51 }
52
53 now.checked_sub(ts)
54 .map(|d| d > 60 * 60 * 24 * (self.tcb_validity_period as i64))
55 .expect("quote timestamp is in the future") }
57}
58
59#[derive(Clone, Debug, Default, PartialEq, Eq, cbor::Encode, cbor::Decode)]
61pub struct TdxQuotePolicy {
62 pub allowed_tdx_modules: Vec<TdxModulePolicy>,
64}
65
66impl TdxQuotePolicy {
67 pub fn verify(&self, report: &TdReport) -> Result<(), Error> {
69 self.verify_tdx_module(report)?;
70 Ok(())
71 }
72
73 fn verify_tdx_module(&self, report: &TdReport) -> Result<(), Error> {
74 for allowed_module in &self.allowed_tdx_modules {
76 if allowed_module.matches(report) {
77 return Ok(());
78 }
79 }
80
81 if self.allowed_tdx_modules.is_empty() && report.mr_signer_seam == TDX_MRSIGNER_INTEL {
84 return Ok(());
85 }
86
87 Err(Error::TdxModuleNotAllowed)
88 }
89}
90
91#[derive(Clone, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
93#[cbor(no_default)]
94pub struct TdxModulePolicy {
95 pub mr_seam: Option<[u8; 48]>,
98
99 pub mr_signer_seam: [u8; 48],
101}
102
103impl TdxModulePolicy {
104 pub fn matches(&self, report: &TdReport) -> bool {
106 if let Some(mr_seam) = self.mr_seam {
108 if mr_seam != report.mr_seam {
109 return false;
110 }
111 }
112
113 if self.mr_signer_seam != report.mr_signer_seam {
115 return false;
116 }
117
118 true
119 }
120}