@@ -13,6 +13,8 @@ use ring::rand::{SecureRandom, SystemRandom};
1313use tdx_tdcall:: tdx:: { tdcall_servtd_rebind_approve, tdcall_vm_write} ;
1414
1515use crate :: mig_policy:: get_init_policy;
16+ #[ cfg( feature = "spdm_attestation" ) ]
17+ use crate :: spdm;
1618use crypto:: hash:: digest_sha384;
1719
1820use crate :: {
@@ -76,6 +78,7 @@ impl RebindingToken {
7678 }
7779}
7880
81+ #[ derive( Clone ) ]
7982pub struct RebindingInfo {
8083 pub mig_request_id : u64 ,
8184 pub rebinding_src : u8 ,
@@ -326,6 +329,16 @@ pub async fn start_rebinding(
326329 remote_policy,
327330 )
328331 . await ?;
332+
333+ #[ cfg( feature = "spdm_attestation" ) ]
334+ rebinding_old_spdm (
335+ transport,
336+ info,
337+ data,
338+ #[ cfg( feature = "policy_v2" ) ]
339+ remote_policy,
340+ )
341+ . await ?;
329342 } else {
330343 let remote_policy = Box :: pin ( with_timeout (
331344 PRE_SESSION_TIMEOUT ,
@@ -356,6 +369,16 @@ pub async fn start_rebinding(
356369 remote_policy,
357370 )
358371 . await ?;
372+
373+ #[ cfg( feature = "spdm_attestation" ) ]
374+ rebinding_new_spdm (
375+ transport,
376+ info,
377+ data,
378+ #[ cfg( feature = "policy_v2" ) ]
379+ remote_policy,
380+ )
381+ . await ?;
359382 }
360383
361384 #[ cfg( feature = "vmcall-raw" ) ]
@@ -370,6 +393,87 @@ pub async fn start_rebinding(
370393 Ok ( ( ) )
371394}
372395
396+ #[ cfg( feature = "spdm_attestation" ) ]
397+ pub async fn rebinding_old_spdm (
398+ transport : TransportType ,
399+ info : & RebindingInfo ,
400+ _data : & mut Vec < u8 > ,
401+ #[ cfg( feature = "policy_v2" ) ] remote_policy : Vec < u8 > ,
402+ ) -> Result < ( ) , MigrationResult > {
403+ const SPDM_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ; // 60 seconds
404+ let mut spdm_requester = spdm:: spdm_requester ( transport) . map_err ( |_e| {
405+ log:: error!(
406+ "rebinding: Failed in spdm_requester transport. Migration ID: {}\n " ,
407+ info. mig_request_id
408+ ) ;
409+ MigrationResult :: SecureSessionError
410+ } ) ?;
411+ with_timeout (
412+ SPDM_TIMEOUT ,
413+ spdm:: spdm_requester_rebind_old (
414+ & mut spdm_requester,
415+ info,
416+ #[ cfg( feature = "policy_v2" ) ]
417+ remote_policy,
418+ ) ,
419+ )
420+ . await
421+ . map_err ( |e| {
422+ log:: error!(
423+ "rebinding: spdm_requester_rebind_old timeout error: {:?}\n " ,
424+ e
425+ ) ;
426+ e
427+ } ) ?
428+ . map_err ( |e| {
429+ log:: error!( "rebinding: spdm_requester_rebind_old error: {:?}\n " , e) ;
430+ e
431+ } ) ?;
432+ log:: info!( "Rebind completed\n " ) ;
433+ Ok ( ( ) )
434+ }
435+
436+ #[ cfg( feature = "spdm_attestation" ) ]
437+ pub async fn rebinding_new_spdm (
438+ transport : TransportType ,
439+ info : & RebindingInfo ,
440+ _data : & mut Vec < u8 > ,
441+ #[ cfg( feature = "policy_v2" ) ] remote_policy : Vec < u8 > ,
442+ ) -> Result < ( ) , MigrationResult > {
443+ const SPDM_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ; // 60 seconds
444+ let mut spdm_responder = spdm:: spdm_responder ( transport) . map_err ( |_e| {
445+ log:: error!(
446+ "rebinding: Failed in spdm_responder transport. Migration ID: {}\n " ,
447+ info. mig_request_id
448+ ) ;
449+ MigrationResult :: SecureSessionError
450+ } ) ?;
451+
452+ with_timeout (
453+ SPDM_TIMEOUT ,
454+ spdm:: spdm_responder_rebind_new (
455+ & mut spdm_responder,
456+ & info,
457+ #[ cfg( feature = "policy_v2" ) ]
458+ remote_policy,
459+ ) ,
460+ )
461+ . await
462+ . map_err ( |e| {
463+ log:: error!(
464+ "rebinding: spdm_responder_rebind_new timeout error: {:?}\n " ,
465+ e
466+ ) ;
467+ e
468+ } ) ?
469+ . map_err ( |e| {
470+ log:: error!( "rebinding: spdm_responder_rebind_new error: {:?}\n " , e) ;
471+ e
472+ } ) ?;
473+ log:: info!( "Rebind completed\n " ) ;
474+ Ok ( ( ) )
475+ }
476+
373477pub async fn rebinding_old (
374478 transport : TransportType ,
375479 info : & RebindingInfo ,
@@ -506,7 +610,7 @@ fn get_servtd_ext_from_cert(certs: &Option<Vec<&[u8]>>) -> Result<ServtdExt, Mig
506610 }
507611}
508612
509- fn create_token_list ( info : & RebindingInfo ) -> Result < Vec < RebindingToken > , MigrationResult > {
613+ pub fn create_token_list ( info : & RebindingInfo ) -> Result < Vec < RebindingToken > , MigrationResult > {
510614 let mut tokens = Vec :: new ( ) ;
511615
512616 for ( handle, uuid) in info
0 commit comments