Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/migtd/src/migration/rebinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ const MIGTD_REBIND_OP_FINALIZE: u8 = 1;

#[repr(C)]
pub struct RebindingToken {
pub token: [u8; 32],
pub target_td_uuid: TargetTdUuid,
token: [u8; 32],
}

impl RebindingToken {
Expand All @@ -77,6 +76,10 @@ impl RebindingToken {
})
}

pub fn token(&self) -> &[u8] {
&self.token
}

pub fn as_bytes(&self) -> &[u8] {
unsafe { core::slice::from_raw_parts(self as *const _ as *const u8, size_of::<Self>()) }
}
Expand Down Expand Up @@ -628,7 +631,7 @@ async fn rebinding_old_prepare(
MigrationResult::SecureSessionError
})?;

let rebind_token = create_rebind_token(info)?;
let rebind_token = create_rebind_token()?;
tls_send_rebind_token(&mut ratls_client, &rebind_token).await?;

approve_rebinding(info, &rebind_token)?;
Expand Down Expand Up @@ -670,9 +673,6 @@ async fn rebinding_new_prepare(

let servtd_ext = get_servtd_ext_from_cert(&ratls_server.peer_certs())?;
let rebind_token = tls_receive_rebind_token(&mut ratls_server).await?;
if rebind_token.target_td_uuid != info.target_td_uuid {
return Err(MigrationResult::InvalidParameter);
}

write_rebinding_session_token(&rebind_token.token)?;
write_servtd_rebind_attr(&servtd_ext.cur_servtd_attr)?;
Expand Down Expand Up @@ -751,16 +751,13 @@ fn get_servtd_ext_from_cert(certs: &Option<Vec<&[u8]>>) -> Result<ServtdExt, Mig
}
}

pub fn create_rebind_token(info: &RebindingInfo) -> Result<RebindingToken, MigrationResult> {
pub fn create_rebind_token() -> Result<RebindingToken, MigrationResult> {
let mut token = [0u8; 32];
let rng = SystemRandom::new();
rng.fill(&mut token)
.map_err(|_| MigrationResult::InvalidParameter)?;

Ok(RebindingToken {
token,
target_td_uuid: info.target_td_uuid,
})
Ok(RebindingToken { token })
}

async fn tls_send_rebind_token(
Expand Down
4 changes: 2 additions & 2 deletions src/migtd/src/spdm/spdm_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ pub async fn send_and_receive_sdm_rebind_info(
vendor_id[..VDM_MESSAGE_VENDOR_ID_LEN].copy_from_slice(&VDM_MESSAGE_VENDOR_ID);
let vendor_id = VendorIDStruct { len: 4, vendor_id };

let rebind_token = create_rebind_token(rebind_info)?;
let token = rebind_token.token;
let rebind_token = create_rebind_token()?;
let token = rebind_token.token();
if token.len() as u32 != VDM_MESSAGE_REBIND_SESSION_TOKEN_SIZE {
error!("Rebind token size is invalid: {}\n", token.len());
return Err(SPDM_STATUS_INVALID_STATE_LOCAL);
Expand Down
Loading