Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
return content_changed in send_receive_spdm_measurement.
Browse files Browse the repository at this point in the history
fix #112

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang authored and jyao1 committed Oct 17, 2023
1 parent feee628 commit 9113ffa
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fuzz-target/random_requester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ async fn run_spdm(spdm: Vec<i32>) {
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,
)
Expand Down
10 changes: 10 additions & 0 deletions fuzz-target/requester/measurement_req/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {

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,
)
Expand Down Expand Up @@ -120,12 +122,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {

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,
)
Expand Down Expand Up @@ -174,12 +178,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {

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,
)
Expand Down Expand Up @@ -228,12 +234,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {

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,
)
Expand Down Expand Up @@ -310,12 +318,14 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
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,
)
Expand Down
11 changes: 11 additions & 0 deletions spdmlib/src/requester/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl RequesterContext {
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
slot_id: u8,
) -> SpdmResult<u8> {
Expand All @@ -28,6 +29,7 @@ impl RequesterContext {
session_id,
measurement_attributes,
measurement_operation,
content_changed,
spdm_measurement_record_structure,
slot_id,
)
Expand All @@ -47,6 +49,7 @@ impl RequesterContext {
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
slot_id: u8,
) -> SpdmResult<u8> {
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -123,6 +127,7 @@ impl RequesterContext {
slot_id: u8,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
send_buffer: &[u8],
receive_buffer: &[u8],
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -228,12 +236,14 @@ impl RequesterContext {
}
}

#[allow(clippy::too_many_arguments)]
pub async fn send_receive_spdm_measurement(
&mut self,
session_id: Option<u32>,
slot_id: u8,
spdm_measuremente_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
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
Expand All @@ -243,6 +253,7 @@ impl RequesterContext {
session_id,
spdm_measuremente_attributes,
measurement_operation,
content_changed,
spdm_measurement_record_structure,
slot_id,
)
Expand Down
6 changes: 6 additions & 0 deletions test/spdm-requester-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 2 additions & 0 deletions test/spdmlib-test/src/requester_tests/get_digests_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
10 changes: 10 additions & 0 deletions test/spdmlib-test/src/requester_tests/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9113ffa

Please sign in to comment.