@@ -15,6 +15,8 @@ use tdx_tdcall::tdx::{tdcall_servtd_rebind_approve, tdcall_vm_write};
1515
1616use crate :: migration:: servtd_ext:: read_servtd_ext;
1717use crate :: { event_log, migration:: transport:: * } ;
18+ #[ cfg( feature = "spdm_attestation" ) ]
19+ use crate :: spdm;
1820use crypto:: hash:: digest_sha384;
1921
2022use crate :: {
@@ -392,6 +394,16 @@ pub async fn start_rebinding(
392394 MIGTD_REBIND_OP_FINALIZE => rebinding_old_finalize ( info, data) . await ?,
393395 _ => return Err ( MigrationResult :: InvalidParameter ) ,
394396 }
397+
398+ #[ cfg( feature = "spdm_attestation" ) ]
399+ rebinding_old_spdm (
400+ transport,
401+ info,
402+ data,
403+ #[ cfg( feature = "policy_v2" ) ]
404+ remote_policy,
405+ )
406+ . await ?;
395407 } else {
396408 let pre_session_data = Box :: pin ( with_timeout (
397409 PRE_SESSION_TIMEOUT ,
@@ -421,6 +433,16 @@ pub async fn start_rebinding(
421433 MIGTD_REBIND_OP_FINALIZE => rebinding_new_finalize ( info, data) . await ?,
422434 _ => return Err ( MigrationResult :: InvalidParameter ) ,
423435 }
436+
437+ #[ cfg( feature = "spdm_attestation" ) ]
438+ rebinding_new_spdm (
439+ transport,
440+ info,
441+ data,
442+ #[ cfg( feature = "policy_v2" ) ]
443+ remote_policy,
444+ )
445+ . await ?;
424446 }
425447
426448 #[ cfg( feature = "vmcall-raw" ) ]
@@ -437,6 +459,87 @@ pub async fn start_rebinding(
437459 Ok ( ( ) )
438460}
439461
462+ #[ cfg( feature = "spdm_attestation" ) ]
463+ pub async fn rebinding_old_spdm (
464+ transport : TransportType ,
465+ info : & RebindingInfo ,
466+ _data : & mut Vec < u8 > ,
467+ #[ cfg( feature = "policy_v2" ) ] remote_policy : Vec < u8 > ,
468+ ) -> Result < ( ) , MigrationResult > {
469+ const SPDM_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ; // 60 seconds
470+ let mut spdm_requester = spdm:: spdm_requester ( transport) . map_err ( |_e| {
471+ log:: error!(
472+ "rebinding: Failed in spdm_requester transport. Migration ID: {}\n " ,
473+ info. mig_request_id
474+ ) ;
475+ MigrationResult :: SecureSessionError
476+ } ) ?;
477+ with_timeout (
478+ SPDM_TIMEOUT ,
479+ spdm:: spdm_requester_rebind_old (
480+ & mut spdm_requester,
481+ info,
482+ #[ cfg( feature = "policy_v2" ) ]
483+ remote_policy,
484+ ) ,
485+ )
486+ . await
487+ . map_err ( |e| {
488+ log:: error!(
489+ "rebinding: spdm_requester_rebind_old timeout error: {:?}\n " ,
490+ e
491+ ) ;
492+ e
493+ } ) ?
494+ . map_err ( |e| {
495+ log:: error!( "rebinding: spdm_requester_rebind_old error: {:?}\n " , e) ;
496+ e
497+ } ) ?;
498+ log:: info!( "Rebind completed\n " ) ;
499+ Ok ( ( ) )
500+ }
501+
502+ #[ cfg( feature = "spdm_attestation" ) ]
503+ pub async fn rebinding_new_spdm (
504+ transport : TransportType ,
505+ info : & RebindingInfo ,
506+ _data : & mut Vec < u8 > ,
507+ #[ cfg( feature = "policy_v2" ) ] remote_policy : Vec < u8 > ,
508+ ) -> Result < ( ) , MigrationResult > {
509+ const SPDM_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ; // 60 seconds
510+ let mut spdm_responder = spdm:: spdm_responder ( transport) . map_err ( |_e| {
511+ log:: error!(
512+ "rebinding: Failed in spdm_responder transport. Migration ID: {}\n " ,
513+ info. mig_request_id
514+ ) ;
515+ MigrationResult :: SecureSessionError
516+ } ) ?;
517+
518+ with_timeout (
519+ SPDM_TIMEOUT ,
520+ spdm:: spdm_responder_rebind_new (
521+ & mut spdm_responder,
522+ & info,
523+ #[ cfg( feature = "policy_v2" ) ]
524+ remote_policy,
525+ ) ,
526+ )
527+ . await
528+ . map_err ( |e| {
529+ log:: error!(
530+ "rebinding: spdm_responder_rebind_new timeout error: {:?}\n " ,
531+ e
532+ ) ;
533+ e
534+ } ) ?
535+ . map_err ( |e| {
536+ log:: error!( "rebinding: spdm_responder_rebind_new error: {:?}\n " , e) ;
537+ e
538+ } ) ?;
539+ log:: info!( "Rebind completed\n " ) ;
540+ Ok ( ( ) )
541+ }
542+
440543pub async fn rebinding_old_prepare (
441544 transport : TransportType ,
442545 info : & RebindingInfo < ' _ > ,
0 commit comments