@@ -9,6 +9,8 @@ use http_body_util::BodyExt;
99use hyper:: service:: service_fn;
1010use hyper:: Response ;
1111use hyper_util:: rt:: TokioIo ;
12+ use parity_scale_codec:: Decode ;
13+ use parity_scale_codec:: Encode ;
1214use thiserror:: Error ;
1315use tokio:: sync:: { mpsc, oneshot} ;
1416use tokio_rustls:: rustls:: server:: { VerifierBuilderError , WebPkiClientVerifier } ;
@@ -192,11 +194,12 @@ impl ProxyServer {
192194
193195 // If we are in a CVM, generate an attestation
194196 let attestation = if local_quote_generator. attestation_type ( ) != AttestationType :: None {
195- serde_json :: to_vec ( & AttesationPayload :: from_attestation_generator (
197+ AttesationPayload :: from_attestation_generator (
196198 & cert_chain,
197199 exporter,
198200 local_quote_generator,
199- ) ?) ?
201+ ) ?
202+ . encode ( )
200203 } else {
201204 Vec :: new ( )
202205 } ;
@@ -218,7 +221,7 @@ impl ProxyServer {
218221 // If we expect an attestaion from the client, verify it and get measurements
219222 let ( measurements, remote_attestation_type) = if attestation_verifier. has_remote_attestion ( )
220223 {
221- let remote_attestation_payload: AttesationPayload = serde_json :: from_slice ( & buf) ?;
224+ let remote_attestation_payload = AttesationPayload :: decode ( & mut & buf[ .. ] ) ?;
222225
223226 let remote_attestation_type = remote_attestation_payload. attestation_type ;
224227 (
@@ -607,7 +610,7 @@ impl ProxyClient {
607610 let mut buf = vec ! [ 0 ; length] ;
608611 tls_stream. read_exact ( & mut buf) . await ?;
609612
610- let remote_attestation_payload: AttesationPayload = serde_json :: from_slice ( & buf) ?;
613+ let remote_attestation_payload = AttesationPayload :: decode ( & mut & buf[ .. ] ) ?;
611614 let remote_attestation_type = remote_attestation_payload. attestation_type ;
612615
613616 // Verify the remote attestation against our accepted measurements
@@ -617,11 +620,12 @@ impl ProxyClient {
617620
618621 // If we are in a CVM, provide an attestation
619622 let attestation = if local_quote_generator. attestation_type ( ) != AttestationType :: None {
620- serde_json :: to_vec ( & AttesationPayload :: from_attestation_generator (
623+ AttesationPayload :: from_attestation_generator (
621624 & cert_chain. ok_or ( ProxyError :: NoClientAuth ) ?,
622625 exporter,
623626 local_quote_generator,
624- ) ?) ?
627+ ) ?
628+ . encode ( )
625629 } else {
626630 Vec :: new ( )
627631 } ;
@@ -705,7 +709,7 @@ async fn get_tls_cert_with_config(
705709 let mut buf = vec ! [ 0 ; length] ;
706710 tls_stream. read_exact ( & mut buf) . await ?;
707711
708- let remote_attestation_payload: AttesationPayload = serde_json :: from_slice ( & buf) ?;
712+ let remote_attestation_payload = AttesationPayload :: decode ( & mut & buf[ .. ] ) ?;
709713
710714 let _measurements = attestation_verifier
711715 . verify_attestation ( remote_attestation_payload, & remote_cert_chain, exporter)
@@ -741,6 +745,8 @@ pub enum ProxyError {
741745 OneShotRecv ( #[ from] oneshot:: error:: RecvError ) ,
742746 #[ error( "Failed to send request, connection to proxy-server dropped" ) ]
743747 MpscSend ,
748+ #[ error( "Serialization: {0}" ) ]
749+ Serialization ( #[ from] parity_scale_codec:: Error ) ,
744750}
745751
746752impl From < mpsc:: error:: SendError < RequestWithResponseSender > > for ProxyError {
0 commit comments