@@ -10,8 +10,7 @@ use x509_parser::prelude::*;
1010
1111const PCS_URL : & str = "https://api.trustedservices.intel.com" ;
1212
13- /// Represents a CVM technology with quote generation and verification
14- pub trait AttestationPlatform : Clone + Send + ' static {
13+ pub trait QuoteGenerator : Clone + Send + ' static {
1514 /// Whether this is CVM attestation. This should always return true except for the [NoAttestation] case.
1615 ///
1716 /// When false, allows TLS client to be configured without client authentication
@@ -23,6 +22,13 @@ pub trait AttestationPlatform: Clone + Send + 'static {
2322 cert_chain : & [ CertificateDer < ' _ > ] ,
2423 exporter : [ u8 ; 32 ] ,
2524 ) -> Result < Vec < u8 > , AttestationError > ;
25+ }
26+
27+ pub trait QuoteVerifier : Clone + Send + ' static {
28+ /// Whether this is CVM attestation. This should always return true except for the [NoAttestation] case.
29+ ///
30+ /// When false, allows TLS client to be configured without client authentication
31+ fn is_cvm ( & self ) -> bool ;
2632
2733 /// Verify the given attestation payload
2834 fn verify_attestation (
@@ -33,10 +39,33 @@ pub trait AttestationPlatform: Clone + Send + 'static {
3339 ) -> impl Future < Output = Result < ( ) , AttestationError > > + Send ;
3440}
3541
42+ // /// Represents a CVM technology with quote generation and verification
43+ // pub trait AttestationPlatform: Clone + Send + 'static {
44+ // /// Whether this is CVM attestation. This should always return true except for the [NoAttestation] case.
45+ // ///
46+ // /// When false, allows TLS client to be configured without client authentication
47+ // fn is_cvm(&self) -> bool;
48+ //
49+ // /// Generate an attestation
50+ // fn create_attestation(
51+ // &self,
52+ // cert_chain: &[CertificateDer<'_>],
53+ // exporter: [u8; 32],
54+ // ) -> Result<Vec<u8>, AttestationError>;
55+ //
56+ // /// Verify the given attestation payload
57+ // fn verify_attestation(
58+ // &self,
59+ // input: Vec<u8>,
60+ // cert_chain: &[CertificateDer<'_>],
61+ // exporter: [u8; 32],
62+ // ) -> impl Future<Output = Result<(), AttestationError>> + Send;
63+ // }
64+
3665#[ derive( Clone ) ]
37- pub struct DcapTdxAttestation ;
66+ pub struct DcapTdxQuoteGenerator ;
3867
39- impl AttestationPlatform for DcapTdxAttestation {
68+ impl QuoteGenerator for DcapTdxQuoteGenerator {
4069 fn is_cvm ( & self ) -> bool {
4170 true
4271 }
@@ -50,6 +79,15 @@ impl AttestationPlatform for DcapTdxAttestation {
5079
5180 Ok ( generate_quote ( quote_input) ?)
5281 }
82+ }
83+
84+ #[ derive( Clone ) ]
85+ pub struct DcapTdxQuoteVerifier ;
86+
87+ impl QuoteVerifier for DcapTdxQuoteVerifier {
88+ fn is_cvm ( & self ) -> bool {
89+ true
90+ }
5391
5492 fn verify_attestation (
5593 & self ,
@@ -59,25 +97,29 @@ impl AttestationPlatform for DcapTdxAttestation {
5997 ) -> impl Future < Output = Result < ( ) , AttestationError > > + Send {
6098 async move {
6199 let quote_input = compute_report_input ( cert_chain, exporter) ?;
62-
63- let now = std:: time:: SystemTime :: now ( )
64- . duration_since ( std:: time:: UNIX_EPOCH )
65- . unwrap ( )
66- . as_secs ( ) ;
67- let quote = Quote :: parse ( & input) . unwrap ( ) ;
68- let ca = quote. ca ( ) . unwrap ( ) ;
69- let fmspc = hex:: encode_upper ( quote. fmspc ( ) . unwrap ( ) ) ;
70- let collateral = get_collateral_for_fmspc ( PCS_URL , fmspc, ca, false )
71- . await
72- . unwrap ( ) ;
73-
74100 // In tests we use mock quotes which will fail to verify
75101 if cfg ! ( not( test) ) {
102+ let now = std:: time:: SystemTime :: now ( )
103+ . duration_since ( std:: time:: UNIX_EPOCH )
104+ . unwrap ( )
105+ . as_secs ( ) ;
106+ let quote = Quote :: parse ( & input) . unwrap ( ) ;
107+ let ca = quote. ca ( ) . unwrap ( ) ;
108+ let fmspc = hex:: encode_upper ( quote. fmspc ( ) . unwrap ( ) ) ;
109+ let collateral = get_collateral_for_fmspc ( PCS_URL , fmspc, ca, false )
110+ . await
111+ . unwrap ( ) ;
76112 let _verified_report = dcap_qvl:: verify:: verify ( & input, & collateral, now) . unwrap ( ) ;
77- }
78- let quote = Quote :: parse ( & input) . unwrap ( ) ;
79- if get_quote_input_data ( quote. report ) != quote_input {
80- return Err ( AttestationError :: InputMismatch ) ;
113+
114+ let quote = Quote :: parse ( & input) . unwrap ( ) ;
115+ if get_quote_input_data ( quote. report ) != quote_input {
116+ return Err ( AttestationError :: InputMismatch ) ;
117+ }
118+ } else {
119+ let quote = tdx_quote:: Quote :: from_bytes ( & input) . unwrap ( ) ;
120+ if quote. report_input_data ( ) != quote_input {
121+ return Err ( AttestationError :: InputMismatch ) ;
122+ }
81123 }
82124
83125 Ok ( ( ) )
@@ -109,9 +151,9 @@ pub fn compute_report_input(
109151
110152/// For no CVM platform (eg: for one-sided remote-attested TLS)
111153#[ derive( Clone ) ]
112- pub struct NoAttestation ;
154+ pub struct NoQuoteGenerator ;
113155
114- impl AttestationPlatform for NoAttestation {
156+ impl QuoteGenerator for NoQuoteGenerator {
115157 fn is_cvm ( & self ) -> bool {
116158 false
117159 }
@@ -124,7 +166,16 @@ impl AttestationPlatform for NoAttestation {
124166 ) -> Result < Vec < u8 > , AttestationError > {
125167 Ok ( Vec :: new ( ) )
126168 }
169+ }
127170
171+ /// For no CVM platform (eg: for one-sided remote-attested TLS)
172+ #[ derive( Clone ) ]
173+ pub struct NoQuoteVerifier ;
174+
175+ impl QuoteVerifier for NoQuoteVerifier {
176+ fn is_cvm ( & self ) -> bool {
177+ false
178+ }
128179 /// Ensure that an empty attestation is given
129180 async fn verify_attestation (
130181 & self ,
0 commit comments