@@ -807,17 +807,37 @@ pNs85uhOZE8z2jr8Pg==
807807 attestation : VersionedAttestation ,
808808 }
809809
810+ fn patch_report_data (
811+ attestation : & VersionedAttestation ,
812+ report_data : [ u8 ; 64 ] ,
813+ ) -> VersionedAttestation {
814+ let ra_tls:: attestation:: VersionedAttestation :: V0 { attestation } = attestation. clone ( ) ;
815+ let mut attestation = attestation;
816+ attestation. report_data = report_data;
817+ if let Some ( tdx_quote) = attestation. tdx_quote_mut ( ) {
818+ if tdx_quote. quote . len ( ) >= ra_tls:: attestation:: TDX_QUOTE_REPORT_DATA_RANGE . end {
819+ tdx_quote. quote [ ra_tls:: attestation:: TDX_QUOTE_REPORT_DATA_RANGE ]
820+ . copy_from_slice ( & report_data) ;
821+ } else {
822+ tracing:: warn!(
823+ "TDX quote too short to patch report_data ({} < {})" ,
824+ tdx_quote. quote. len( ) ,
825+ ra_tls:: attestation:: TDX_QUOTE_REPORT_DATA_RANGE . end
826+ ) ;
827+ }
828+ }
829+ ra_tls:: attestation:: VersionedAttestation :: V0 { attestation }
830+ }
831+
810832 impl PlatformBackend for TestSimulatorPlatform {
811833 fn attestation_for_info ( & self ) -> Result < ra_rpc:: Attestation > {
812834 Ok ( self . attestation . clone ( ) . into_inner ( ) )
813835 }
814836
815837 fn certificate_attestation ( & self , pubkey : & [ u8 ] ) -> Result < VersionedAttestation > {
816- let mut attestation = self . attestation . clone ( ) ;
817838 let report_data =
818839 ra_tls:: attestation:: QuoteContentType :: RaTlsCert . to_report_data ( pubkey) ;
819- attestation. set_report_data ( report_data) ;
820- Ok ( attestation)
840+ Ok ( patch_report_data ( & self . attestation , report_data) )
821841 }
822842
823843 fn quote_response (
@@ -826,13 +846,11 @@ pNs85uhOZE8z2jr8Pg==
826846 vm_config : & str ,
827847 ) -> Result < GetQuoteResponse > {
828848 let ra_tls:: attestation:: VersionedAttestation :: V0 { attestation } =
829- self . attestation . clone ( ) ;
849+ patch_report_data ( & self . attestation , report_data ) ;
830850 let mut attestation = attestation;
831851 let Some ( quote) = attestation. tdx_quote_mut ( ) else {
832852 return Err ( anyhow:: anyhow!( "Quote not found" ) ) ;
833853 } ;
834- quote. quote [ ra_tls:: attestation:: TDX_QUOTE_REPORT_DATA_RANGE ]
835- . copy_from_slice ( & report_data) ;
836854 Ok ( GetQuoteResponse {
837855 quote : quote. quote . to_vec ( ) ,
838856 event_log : serde_json:: to_string ( & quote. event_log )
@@ -842,9 +860,9 @@ pNs85uhOZE8z2jr8Pg==
842860 } )
843861 }
844862
845- fn attest_response ( & self , _report_data : [ u8 ; 64 ] ) -> Result < AttestResponse > {
863+ fn attest_response ( & self , report_data : [ u8 ; 64 ] ) -> Result < AttestResponse > {
846864 Ok ( AttestResponse {
847- attestation : self . attestation . to_scale ( ) ,
865+ attestation : patch_report_data ( & self . attestation , report_data ) . to_scale ( ) ,
848866 } )
849867 }
850868
0 commit comments