Skip to content

Commit de5bf83

Browse files
authored
Merge pull request #20 from datachainlab/output-validity
Add `Validity` struct represents validity period of a QV output Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
2 parents 9616d79 + a47bc35 commit de5bf83

File tree

5 files changed

+62
-27
lines changed

5 files changed

+62
-27
lines changed

crates/quote-verifier/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ mod quote_verifier_tests {
113113
"validity intersection failed"
114114
);
115115
assert_eq!(
116-
verified_output.validity.not_before_max, 1737456351,
116+
verified_output.validity.not_before, 1737456351,
117117
"invalid `not_before_max`"
118118
);
119119
assert_eq!(
120-
verified_output.validity.not_after_min, 1740048100,
120+
verified_output.validity.not_after, 1740048100,
121121
"invalid `not_after_min`"
122122
);
123123
let bz = verified_output.to_bytes();

crates/quote-verifier/src/quotes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::enclave_identity::{get_qe_tcb_status, validate_qe_identityv2};
99
use crate::pck::validate_pck_cert;
1010
use crate::sgx_extensions::extract_sgx_extensions;
1111
use crate::tcb_info::{validate_tcb_info_v3, validate_tcb_signing_certificate};
12-
use crate::verifier::{QuoteVerificationOutput, ValidityIntersection};
12+
use crate::verifier::{QuoteVerificationOutput, Validity};
1313
use crate::Result;
1414
use anyhow::{bail, Context};
1515
use dcap_types::cert::SgxExtensions;
@@ -28,7 +28,7 @@ use x509_parser::certificate::X509Certificate;
2828
/// Verify the quote with the given collateral data and return the verification output.
2929
///
3030
/// Our verifier's verification logic is based on
31-
/// <https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/812e0fa140a284b772b2d8b08583c761e23ec3b3/Src/AttestationApp/src/AppCore/AttestationLibraryAdapter.cpp#L46>.
31+
/// <https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/812e0fa140a284b772b2d8b08583c761e23ec3b3/Src/AttestationApp/src/AppCore/AppCore.cpp#L81>.
3232
///
3333
/// However, our verifier returns an error instead of an output if the result corresponds the status is not defined in `Status`(e.g., `STATUS_TCB_NOT_SUPPORTED`).
3434
///
@@ -91,7 +91,7 @@ fn verify_quote_common(
9191
qe_cert_data: &CertData,
9292
collateral: &QvCollateral,
9393
current_time: u64,
94-
) -> Result<(QeTcb, SgxExtensions, TcbInfo, ValidityIntersection)> {
94+
) -> Result<(QeTcb, SgxExtensions, TcbInfo, Validity)> {
9595
// get the certchain embedded in the ecda quote signature data
9696
// this can be one of 5 types, and we only support type 5
9797
// https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/aa239d25a437a28f3f4de92c38f5b6809faac842/QuoteGeneration/quote_wrapper/common/inc/sgx_quote_3.h#L63C4-L63C112
@@ -193,7 +193,7 @@ fn verify_quote_common(
193193
);
194194
}
195195

196-
Ok((qe_tcb, pck_cert_sgx_extensions, tcb_info, validity))
196+
Ok((qe_tcb, pck_cert_sgx_extensions, tcb_info, validity.into()))
197197
}
198198

199199
/// Verify the QE Report and return the TCB Status and Advisory IDs

crates/quote-verifier/src/verifier.rs

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use dcap_types::{
99
TD10_REPORT_LEN, TDX_TEE_TYPE,
1010
};
1111
use serde::{Deserialize, Serialize};
12-
use x509_parser::certificate::Validity;
12+
use x509_parser::certificate::Validity as X509Validity;
1313

1414
/// The version of the output format.
1515
pub const QV_OUTPUT_VERSION: u16 = 0;
@@ -48,7 +48,7 @@ pub struct QuoteVerificationOutput {
4848
///
4949
/// This is the intersection of the validity periods of all certificates and other QV collateral.
5050
/// The verifier of the output should check this validity intersection to ensure the overall validity of the collateral.
51-
pub validity: ValidityIntersection,
51+
pub validity: Validity,
5252
/// The body of the quote that was verified.
5353
pub quote_body: QuoteBody,
5454
/// The advisory IDs that are associated with the platform or QE that generated the quote.
@@ -68,8 +68,8 @@ impl QuoteVerificationOutput {
6868
/// - min_tcb_evaluation_data_number: 4 bytes
6969
/// - fmspc: 6 bytes
7070
/// - sgx_intel_root_ca_hash: 32 bytes
71-
/// - validity.not_before_max: 8 bytes
72-
/// - validity.not_after_min: 8 bytes
71+
/// - validity.not_before: 8 bytes
72+
/// - validity.not_after: 8 bytes
7373
/// - quote_body: SGX_ENCLAVE_REPORT(384 bytes) or TD10_REPORT(584 bytes)
7474
/// - advisory_ids: variable length
7575
pub fn to_bytes(&self) -> Vec<u8> {
@@ -82,8 +82,8 @@ impl QuoteVerificationOutput {
8282
output_vec.extend_from_slice(&self.min_tcb_evaluation_data_number.to_be_bytes());
8383
output_vec.extend_from_slice(&self.fmspc);
8484
output_vec.extend_from_slice(&self.sgx_intel_root_ca_hash);
85-
output_vec.extend_from_slice(&self.validity.not_before_max.to_be_bytes());
86-
output_vec.extend_from_slice(&self.validity.not_after_min.to_be_bytes());
85+
output_vec.extend_from_slice(&self.validity.not_before.to_be_bytes());
86+
output_vec.extend_from_slice(&self.validity.not_after.to_be_bytes());
8787

8888
match self.quote_body {
8989
QuoteBody::SGXQuoteBody(body) => {
@@ -122,10 +122,10 @@ impl QuoteVerificationOutput {
122122
let mut sgx_intel_root_ca_hash = [0; 32];
123123
sgx_intel_root_ca_hash.copy_from_slice(&slice[19..51]);
124124

125-
let mut not_before_max = [0; 8];
126-
not_before_max.copy_from_slice(&slice[51..59]);
127-
let mut not_after_min = [0; 8];
128-
not_after_min.copy_from_slice(&slice[59..67]);
125+
let mut not_before = [0; 8];
126+
not_before.copy_from_slice(&slice[51..59]);
127+
let mut not_after = [0; 8];
128+
not_after.copy_from_slice(&slice[59..67]);
129129

130130
const QUOTE_BODY_OFFSET: usize = 67;
131131
let (quote_body, advisory_ids_offset) = match u32::from_be_bytes(tee_type) {
@@ -157,9 +157,9 @@ impl QuoteVerificationOutput {
157157
min_tcb_evaluation_data_number: u32::from_be_bytes(min_tcb_evaluation_data_number),
158158
fmspc,
159159
sgx_intel_root_ca_hash,
160-
validity: ValidityIntersection {
161-
not_before_max: u64::from_be_bytes(not_before_max),
162-
not_after_min: u64::from_be_bytes(not_after_min),
160+
validity: Validity {
161+
not_before: u64::from_be_bytes(not_before),
162+
not_after: u64::from_be_bytes(not_after),
163163
},
164164
quote_body,
165165
advisory_ids,
@@ -294,9 +294,9 @@ impl FromStr for Status {
294294
/// This is used to determine the overall validity period of the collaterals that are being verified.
295295
#[derive(Debug, Clone, PartialEq, Eq)]
296296
pub struct ValidityIntersection {
297-
/// The maximum not_before seconds timestamp of all certificates
297+
/// The maximum not_before seconds timestamp of all collaterals
298298
pub not_before_max: u64,
299-
/// The minimum not_after seconds timestamp of all certificates
299+
/// The minimum not_after seconds timestamp of all collaterals
300300
pub not_after_min: u64,
301301
}
302302

@@ -313,15 +313,15 @@ impl Display for ValidityIntersection {
313313
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
314314
write!(
315315
f,
316-
"(not_before: {}, not_after: {})",
316+
"(not_before_max: {}, not_after_min: {})",
317317
self.not_before_max, self.not_after_min
318318
)
319319
}
320320
}
321321

322322
impl ValidityIntersection {
323323
/// Create a new ValidityIntersection from a certificate validity.
324-
pub fn with_certificate(self, certificate_validity: &Validity) -> Result<Self> {
324+
pub fn with_certificate(self, certificate_validity: &X509Validity) -> Result<Self> {
325325
let not_before = certificate_validity.not_before.timestamp().try_into()?;
326326
let not_after = certificate_validity.not_after.timestamp().try_into()?;
327327
Ok(ValidityIntersection {
@@ -366,10 +366,10 @@ impl ValidityIntersection {
366366
}
367367
}
368368

369-
impl TryFrom<&Validity> for ValidityIntersection {
369+
impl TryFrom<&X509Validity> for ValidityIntersection {
370370
type Error = anyhow::Error;
371371

372-
fn try_from(validity: &Validity) -> Result<Self> {
372+
fn try_from(validity: &X509Validity) -> Result<Self> {
373373
let not_before = validity.not_before.timestamp().try_into()?;
374374
let not_after = validity.not_after.timestamp().try_into()?;
375375
Ok(ValidityIntersection {
@@ -378,3 +378,38 @@ impl TryFrom<&Validity> for ValidityIntersection {
378378
})
379379
}
380380
}
381+
382+
/// Validity represents the validity period of a QV output.
383+
#[derive(Debug, Clone, PartialEq, Eq)]
384+
pub struct Validity {
385+
/// The not_before unix timestamp in seconds
386+
pub not_before: u64,
387+
/// The not_after unix timestamp in seconds
388+
pub not_after: u64,
389+
}
390+
391+
impl Validity {
392+
/// Validate the validity period.
393+
pub fn validate(&self) -> bool {
394+
self.not_before < self.not_after
395+
}
396+
}
397+
398+
impl Display for Validity {
399+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
400+
write!(
401+
f,
402+
"(not_before: {}, not_after: {})",
403+
self.not_before, self.not_after
404+
)
405+
}
406+
}
407+
408+
impl From<ValidityIntersection> for Validity {
409+
fn from(v: ValidityIntersection) -> Self {
410+
Validity {
411+
not_before: v.not_before_max,
412+
not_after: v.not_after_min,
413+
}
414+
}
415+
}
3.55 KB
Binary file not shown.

zkvm/risc0/src/methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
pub const DCAP_QUOTE_VERIFIER_ID: [u32; 8] = [483828460, 459610919, 1188057978, 2178293476, 1749789425, 4194043372, 1381224536, 1377785701];
3-
pub const DCAP_QUOTE_VERIFIER_ID_STR: &str = "eca2d61c271b651b7a53d046e41ed681f1aa4b68ec05fcf958d0535265571f52";
2+
pub const DCAP_QUOTE_VERIFIER_ID: [u32; 8] = [4146062033, 2223854335, 2049230014, 885906633, 396095194, 725162435, 1474221337, 415436345];
3+
pub const DCAP_QUOTE_VERIFIER_ID_STR: &str = "d1e21ff7ff528d84bec4247ac9dccd34daee9b17c319392b19d5de57390ec318";
44
pub const DCAP_QUOTE_VERIFIER_ELF: &[u8] = include_bytes!("../artifacts/dcap-quote-verifier");

0 commit comments

Comments
 (0)