From b5a198c09de450c14cdf9a52319ac18692068cdd Mon Sep 17 00:00:00 2001 From: "Yang, Longlong" Date: Mon, 16 Oct 2023 21:08:39 -0400 Subject: [PATCH] return content_changed in send_receive_spdm_measurement. fix #112 Signed-off-by: Yang, Longlong --- fuzz-target/random_requester/src/main.rs | 2 ++ fuzz-target/requester/measurement_req/src/main.rs | 10 ++++++++++ spdmlib/src/requester/get_measurements_req.rs | 11 +++++++++++ test/spdm-requester-emu/src/main.rs | 6 ++++++ .../src/requester_tests/get_digests_req.rs | 2 ++ .../src/requester_tests/get_measurements_req.rs | 10 ++++++++++ 6 files changed, 41 insertions(+) diff --git a/fuzz-target/random_requester/src/main.rs b/fuzz-target/random_requester/src/main.rs index ace3de2f..c1707b90 100644 --- a/fuzz-target/random_requester/src/main.rs +++ b/fuzz-target/random_requester/src/main.rs @@ -99,12 +99,14 @@ async fn run_spdm(spdm: Vec) { let mut total_number = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; if requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementRequestAll, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) diff --git a/fuzz-target/requester/measurement_req/src/main.rs b/fuzz-target/requester/measurement_req/src/main.rs index c9b25e4c..51a18253 100644 --- a/fuzz-target/requester/measurement_req/src/main.rs +++ b/fuzz-target/requester/measurement_req/src/main.rs @@ -67,12 +67,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc>) { let mut total_number = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let _ = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementRequestAll, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -120,12 +122,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc>) { let mut total_number = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let _ = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -174,12 +178,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc>) { let mut total_number = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let _ = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::RAW_BIT_STREAM_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -228,12 +234,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc>) { let mut total_number = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let _ = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::empty(), SpdmMeasurementOperation::Unknown(4), + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -310,12 +318,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc>) { requester.common.reset_runtime_info(); let mut total_number = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let _ = requester .send_receive_spdm_measurement( Some(4294836221), 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementRequestAll, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) diff --git a/spdmlib/src/requester/get_measurements_req.rs b/spdmlib/src/requester/get_measurements_req.rs index 990b1516..d6a9a0b5 100644 --- a/spdmlib/src/requester/get_measurements_req.rs +++ b/spdmlib/src/requester/get_measurements_req.rs @@ -20,6 +20,7 @@ impl RequesterContext { session_id: Option, measurement_attributes: SpdmMeasurementAttributes, measurement_operation: SpdmMeasurementOperation, + content_changed: &mut Option, spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure, slot_id: u8, ) -> SpdmResult { @@ -28,6 +29,7 @@ impl RequesterContext { session_id, measurement_attributes, measurement_operation, + content_changed, spdm_measurement_record_structure, slot_id, ) @@ -47,6 +49,7 @@ impl RequesterContext { session_id: Option, measurement_attributes: SpdmMeasurementAttributes, measurement_operation: SpdmMeasurementOperation, + content_changed: &mut Option, spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure, slot_id: u8, ) -> SpdmResult { @@ -82,6 +85,7 @@ impl RequesterContext { slot_id, measurement_attributes, measurement_operation, + content_changed, spdm_measurement_record_structure, &send_buffer[..send_used], &receive_buffer[..used], @@ -123,6 +127,7 @@ impl RequesterContext { slot_id: u8, measurement_attributes: SpdmMeasurementAttributes, measurement_operation: SpdmMeasurementOperation, + content_changed: &mut Option, spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure, send_buffer: &[u8], receive_buffer: &[u8], @@ -159,6 +164,9 @@ impl RequesterContext { if self.common.negotiate_info.spdm_version_sel >= SpdmVersion::SpdmVersion12 { self.common.runtime_info.content_changed = measurements.content_changed; + *content_changed = Some(measurements.content_changed); + } else { + *content_changed = None; } let base_asym_size = @@ -228,12 +236,14 @@ impl RequesterContext { } } + #[allow(clippy::too_many_arguments)] pub async fn send_receive_spdm_measurement( &mut self, session_id: Option, slot_id: u8, spdm_measuremente_attributes: SpdmMeasurementAttributes, measurement_operation: SpdmMeasurementOperation, + content_changed: &mut Option, // 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 @@ -243,6 +253,7 @@ impl RequesterContext { session_id, spdm_measuremente_attributes, measurement_operation, + content_changed, spdm_measurement_record_structure, slot_id, ) diff --git a/test/spdm-requester-emu/src/main.rs b/test/spdm-requester-emu/src/main.rs index 86fcf8ba..b8dac66d 100644 --- a/test/spdm-requester-emu/src/main.rs +++ b/test/spdm-requester-emu/src/main.rs @@ -268,12 +268,14 @@ async fn test_spdm( let mut total_number: u8 = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; if context .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementRequestAll, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -329,12 +331,14 @@ async fn test_spdm( panic!("send_receive_spdm_key_update failed"); } + let mut content_changed = None; if context .send_receive_spdm_measurement( Some(session_id), 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -542,12 +546,14 @@ async fn test_idekm( let mut total_number: u8 = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; if context .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, SpdmMeasurementOperation::SpdmMeasurementRequestAll, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) diff --git a/test/spdmlib-test/src/requester_tests/get_digests_req.rs b/test/spdmlib-test/src/requester_tests/get_digests_req.rs index 0ddaeab3..853635f2 100644 --- a/test/spdmlib-test/src/requester_tests/get_digests_req.rs +++ b/test/spdmlib-test/src/requester_tests/get_digests_req.rs @@ -287,12 +287,14 @@ fn issue_other_request_before_vca_negotiated() { let measurement_operation = SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber; let mut total_number: u8 = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let result = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, measurement_operation, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) diff --git a/test/spdmlib-test/src/requester_tests/get_measurements_req.rs b/test/spdmlib-test/src/requester_tests/get_measurements_req.rs index 87a7f2b9..bdba284f 100644 --- a/test/spdmlib-test/src/requester_tests/get_measurements_req.rs +++ b/test/spdmlib-test/src/requester_tests/get_measurements_req.rs @@ -120,12 +120,14 @@ fn test_case0_send_receive_spdm_measurement() { let measurement_operation = SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber; let mut total_number: u8 = 0; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); + let mut content_changed = None; let status = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, measurement_operation, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -134,12 +136,14 @@ fn test_case0_send_receive_spdm_measurement() { assert!(status); let measurement_operation = SpdmMeasurementOperation::SpdmMeasurementRequestAll; + let mut content_changed = None; let status = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, measurement_operation, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -148,12 +152,14 @@ fn test_case0_send_receive_spdm_measurement() { assert!(status); let measurement_operation = SpdmMeasurementOperation::Unknown(1); + let mut content_changed = None; let status = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, measurement_operation, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -162,12 +168,14 @@ fn test_case0_send_receive_spdm_measurement() { assert!(status); let measurement_operation = SpdmMeasurementOperation::Unknown(5); + let mut content_changed = None; let status = requester .send_receive_spdm_measurement( None, 0, SpdmMeasurementAttributes::SIGNATURE_REQUESTED, measurement_operation, + &mut content_changed, &mut total_number, &mut spdm_measurement_record_structure, ) @@ -352,11 +360,13 @@ fn test_handle_spdm_measurement_record_response() { let session_id = None; let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default(); let send_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut content_changed = None; let result = requester.handle_spdm_measurement_record_response( session_id, tc.request_slot_id, tc.attributes, tc.operation, + &mut content_changed, &mut spdm_measurement_record_structure, &send_buffer, &*tc.receive_buffer,