@@ -4,13 +4,10 @@ use attestation::{measurements::Measurements, AttestationError, AttestationType}
44pub use attestation:: { DcapTdxQuoteGenerator , NoQuoteGenerator , QuoteGenerator } ;
55use bytes:: Bytes ;
66use http:: HeaderValue ;
7- use http_body_util:: combinators:: BoxBody ;
8- use http_body_util:: BodyExt ;
9- use hyper:: service:: service_fn;
10- use hyper:: Response ;
7+ use http_body_util:: { combinators:: BoxBody , BodyExt } ;
8+ use hyper:: { service:: service_fn, Response } ;
119use hyper_util:: rt:: TokioIo ;
12- use parity_scale_codec:: Decode ;
13- use parity_scale_codec:: Encode ;
10+ use parity_scale_codec:: { Decode , Encode } ;
1411use thiserror:: Error ;
1512use tokio:: sync:: { mpsc, oneshot} ;
1613use tokio_rustls:: rustls:: server:: { VerifierBuilderError , WebPkiClientVerifier } ;
@@ -193,16 +190,12 @@ impl ProxyServer {
193190 let remote_cert_chain = connection. peer_certificates ( ) . map ( |c| c. to_owned ( ) ) ;
194191
195192 // If we are in a CVM, generate an attestation
196- let attestation = if local_quote_generator. attestation_type ( ) != AttestationType :: None {
197- AttesationPayload :: from_attestation_generator (
198- & cert_chain,
199- exporter,
200- local_quote_generator,
201- ) ?
202- . encode ( )
203- } else {
204- Vec :: new ( )
205- } ;
193+ let attestation = AttesationPayload :: from_attestation_generator (
194+ & cert_chain,
195+ exporter,
196+ local_quote_generator,
197+ ) ?
198+ . encode ( ) ;
206199
207200 // Write our attestation to the channel, with length prefix
208201 let attestation_length_prefix = length_prefix ( & attestation) ;
@@ -218,24 +211,20 @@ impl ProxyServer {
218211 let mut buf = vec ! [ 0 ; length] ;
219212 tls_stream. read_exact ( & mut buf) . await ?;
220213
214+ let remote_attestation_payload = AttesationPayload :: decode ( & mut & buf[ ..] ) ?;
215+ let remote_attestation_type = remote_attestation_payload. attestation_type ;
216+
221217 // If we expect an attestaion from the client, verify it and get measurements
222- let ( measurements, remote_attestation_type) = if attestation_verifier. has_remote_attestion ( )
223- {
224- let remote_attestation_payload = AttesationPayload :: decode ( & mut & buf[ ..] ) ?;
225-
226- let remote_attestation_type = remote_attestation_payload. attestation_type ;
227- (
228- attestation_verifier
229- . verify_attestation (
230- remote_attestation_payload,
231- & remote_cert_chain. ok_or ( ProxyError :: NoClientAuth ) ?,
232- exporter,
233- )
234- . await ?,
235- remote_attestation_type,
236- )
218+ let measurements = if attestation_verifier. has_remote_attestion ( ) {
219+ attestation_verifier
220+ . verify_attestation (
221+ remote_attestation_payload,
222+ & remote_cert_chain. ok_or ( ProxyError :: NoClientAuth ) ?,
223+ exporter,
224+ )
225+ . await ?
237226 } else {
238- ( None , AttestationType :: None )
227+ None
239228 } ;
240229
241230 // Setup an HTTP server
@@ -627,7 +616,7 @@ impl ProxyClient {
627616 ) ?
628617 . encode ( )
629618 } else {
630- Vec :: new ( )
619+ AttesationPayload :: without_attestation ( ) . encode ( )
631620 } ;
632621
633622 // Send our attestation (or zero bytes) prefixed with length
0 commit comments