@@ -22,7 +22,7 @@ use dstack_types::SysConfig;
2222use dstack_types:: { Platform , VmConfig } ;
2323use ez_hash:: { sha256, Hasher , Sha384 } ;
2424use or_panic:: ResultOrPanic ;
25- use scale:: { Decode , Encode , Error as ScaleError , Input , Output } ;
25+ use scale:: { Decode , Encode } ;
2626use serde:: { Deserialize , Serialize } ;
2727use serde_human_bytes as hex_bytes;
2828use sha2:: Digest as _;
@@ -53,7 +53,7 @@ fn read_vm_config() -> Result<String> {
5353}
5454
5555fn is_cbor_map_prefix ( byte : u8 ) -> bool {
56- matches ! ( byte, 0xa0 ..=0xbb | 0xbf )
56+ matches ! ( byte, 0xa0 ..=0xbf )
5757}
5858
5959impl From < Attestation > for AttestationV1 {
@@ -344,34 +344,6 @@ pub enum VersionedAttestation {
344344 } ,
345345}
346346
347- impl Encode for VersionedAttestation {
348- fn size_hint ( & self ) -> usize {
349- self . to_bytes ( ) . len ( )
350- }
351-
352- fn encode_to < T : Output + ?Sized > ( & self , dest : & mut T ) {
353- dest. write ( & self . to_bytes ( ) ) ;
354- }
355- }
356-
357- impl Decode for VersionedAttestation {
358- fn decode < I : Input > ( input : & mut I ) -> Result < Self , ScaleError > {
359- let Some ( remaining_len) = input. remaining_len ( ) ? else {
360- return Err ( ScaleError :: from (
361- "VersionedAttestation requires a bounded input to decode" ,
362- ) ) ;
363- } ;
364- let mut bytes = vec ! [ 0u8 ; remaining_len] ;
365- input. read ( & mut bytes) ?;
366- Self :: from_bytes ( & bytes) . map_err ( |err| {
367- ScaleError :: from ( std:: io:: Error :: new (
368- std:: io:: ErrorKind :: InvalidData ,
369- err. to_string ( ) ,
370- ) )
371- } )
372- }
373- }
374-
375347impl VersionedAttestation {
376348 /// Decode versioned attestation bytes.
377349 pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self > {
@@ -389,23 +361,17 @@ impl VersionedAttestation {
389361 let attestation = AttestationV1 :: from_cbor ( bytes) ?;
390362 return Ok ( Self :: V1 { attestation } ) ;
391363 }
392- if first == 0x01 && bytes. get ( 1 ) . is_some_and ( |byte| is_cbor_map_prefix ( * byte) ) {
393- let attestation = AttestationV1 :: from_cbor ( & bytes[ 1 ..] ) ?;
394- return Ok ( Self :: V1 { attestation } ) ;
395- }
396364 bail ! ( "Unknown attestation wire format" ) ;
397365 }
398366
399367 /// Encode versioned attestation bytes.
400- pub fn to_bytes ( & self ) -> Vec < u8 > {
368+ pub fn to_bytes ( & self ) -> Result < Vec < u8 > > {
401369 match self {
402- Self :: V0 { attestation } => LegacyVersionedAttestation :: V0 {
370+ Self :: V0 { attestation } => Ok ( LegacyVersionedAttestation :: V0 {
403371 attestation : attestation. clone ( ) ,
404372 }
405- . encode ( ) ,
406- Self :: V1 { attestation } => attestation
407- . to_cbor ( )
408- . or_panic ( "attestation schema should encode as CBOR" ) ,
373+ . encode ( ) ) ,
374+ Self :: V1 { attestation } => attestation. to_cbor ( ) ,
409375 }
410376 }
411377
@@ -415,7 +381,7 @@ impl VersionedAttestation {
415381 }
416382
417383 #[ doc( hidden) ]
418- pub fn to_scale ( & self ) -> Vec < u8 > {
384+ pub fn to_scale ( & self ) -> Result < Vec < u8 > > {
419385 self . to_bytes ( )
420386 }
421387
@@ -548,6 +514,15 @@ impl AttestationV1 {
548514 platform,
549515 stack,
550516 } = self ;
517+ // Verify report_data_payload binding: if present, the report_data must
518+ // be derived from the payload via the AppData content type scheme.
519+ if let Some ( payload) = stack. report_data_payload ( ) {
520+ let report_data: [ u8 ; 64 ] = stack. report_data ( ) ?;
521+ let expected = QuoteContentType :: AppData . to_report_data ( payload. as_bytes ( ) ) ;
522+ if report_data != expected {
523+ bail ! ( "report_data does not match report_data_payload" ) ;
524+ }
525+ }
551526 let ( report_data, runtime_events, config) = match stack {
552527 StackEvidence :: Dstack {
553528 report_data,
@@ -1308,7 +1283,7 @@ mod tests {
13081283 let attestation = dummy_tdx_attestation ( report_data)
13091284 . into_v1 ( )
13101285 . into_dstack_pod ( payload. clone ( ) ) ;
1311- let encoded = VersionedAttestation :: V1 { attestation } . to_bytes ( ) ;
1286+ let encoded = VersionedAttestation :: V1 { attestation } . to_bytes ( ) . unwrap ( ) ;
13121287 assert ! ( matches!( encoded. first( ) , Some ( 0xa0 ..=0xbf ) ) ) ;
13131288 let decoded = VersionedAttestation :: from_bytes ( & encoded)
13141289 . expect ( "decode attestation" )
0 commit comments