@@ -9,7 +9,7 @@ use dcap_types::{
99 TD10_REPORT_LEN , TDX_TEE_TYPE ,
1010} ;
1111use 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.
1515pub 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 ) ]
296296pub 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
322322impl 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+ }
0 commit comments