Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support customized nonce for get measurement request. #116

Closed
Closed
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
42 changes: 41 additions & 1 deletion spdmlib/src/requester/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl RequesterContext {
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_meas: &mut Option<ManagedBufferM>,
Expand All @@ -36,6 +37,7 @@ impl RequesterContext {
session_id,
measurement_attributes,
measurement_operation,
spdm_nonce_struct,
content_changed,
spdm_measurement_record_structure,
transcript_meas,
Expand All @@ -60,6 +62,7 @@ impl RequesterContext {
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_meas: &mut Option<ManagedBufferM>,
Expand All @@ -80,6 +83,7 @@ impl RequesterContext {
let send_used = self.encode_spdm_measurement_record(
measurement_attributes,
measurement_operation,
spdm_nonce_struct,
slot_id,
&mut send_buffer,
)?;
Expand Down Expand Up @@ -109,12 +113,18 @@ impl RequesterContext {
&mut self,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
slot_id: u8,
buf: &mut [u8],
) -> SpdmResult<usize> {
let mut writer = Writer::init(buf);
let mut nonce = [0u8; SPDM_NONCE_SIZE];
crypto::rand::get_random(&mut nonce)?;

if let Some(n) = spdm_nonce_struct {
nonce.copy_from_slice(&n.data)
} else {
crypto::rand::get_random(&mut nonce)?;
}

let request = SpdmMessage {
header: SpdmMessageHeader {
Expand Down Expand Up @@ -283,12 +293,42 @@ impl RequesterContext {
// number of blocks got measured.
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure, // out
transcript_meas: &mut Option<ManagedBufferM>, // out
) -> SpdmResult {
self.send_receive_spdm_measurement_with_nonce(
session_id,
slot_id,
spdm_measuremente_attributes,
measurement_operation,
None,
content_changed,
out_total_number,
spdm_measurement_record_structure,
transcript_meas,
)
.await
}

#[allow(clippy::too_many_arguments)]
#[maybe_async::maybe_async]
pub async fn send_receive_spdm_measurement_with_nonce(
&mut self,
session_id: Option<u32>,
slot_id: u8,
spdm_measuremente_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
content_changed: &mut Option<SpdmMeasurementContentChanged>, // out, None if spdm version < 0x12
out_total_number: &mut u8, // out, total number when measurement_operation = SpdmMeasurementQueryTotalNumber
// number of blocks got measured.
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure, // out
transcript_meas: &mut Option<ManagedBufferM>, // out
) -> SpdmResult {
*out_total_number = self
.send_receive_spdm_measurement_record(
session_id,
spdm_measuremente_attributes,
measurement_operation,
spdm_nonce_struct,
content_changed,
spdm_measurement_record_structure,
transcript_meas,
Expand Down
Loading