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

Commit

Permalink
add support to export the full transcript (VCA + message_m) for GET_M…
Browse files Browse the repository at this point in the history
…EASUREMENT.

fix #29

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Oct 10, 2023
1 parent c57b91d commit bf3b975
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fuzz-target/random_requester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ async fn run_spdm(spdm: Vec<i32>) {
let mut total_number = 0;
let mut spdm_measurement_record_structure =
SpdmMeasurementRecordStructure::default();
let mut transcript_vca = None;
let mut transcript_meas = None;

if requester
.send_receive_spdm_measurement(
None,
Expand All @@ -107,6 +110,8 @@ async fn run_spdm(spdm: Vec<i32>) {
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_err()
Expand Down
25 changes: 25 additions & 0 deletions fuzz-target/requester/measurement_req/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -75,6 +78,8 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -120,6 +125,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -128,6 +136,8 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -174,6 +184,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -182,6 +195,8 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -228,6 +243,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -236,6 +254,8 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
SpdmMeasurementOperation::Unknown(4),
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -310,6 +330,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
Some(4294836221),
Expand All @@ -318,6 +341,8 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await;
}
Expand Down
28 changes: 28 additions & 0 deletions spdmlib/src/requester/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,40 @@ use crate::protocol::*;
use crate::requester::*;

impl RequesterContext {
#[allow(clippy::too_many_arguments)]
async fn send_receive_spdm_measurement_record(
&mut self,
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_vca: &mut Option<ManagedBufferA>,
transcript_meas: &mut Option<ManagedBufferM>,
slot_id: u8,
) -> SpdmResult<u8> {
if transcript_meas.is_none() {
*transcript_meas = Some(ManagedBufferM::default());
}

let result = self
.delegate_send_receive_spdm_measurement_record(
session_id,
measurement_attributes,
measurement_operation,
spdm_measurement_record_structure,
transcript_meas,
slot_id,
)
.await;

if let Err(e) = result {
if e != SPDM_STATUS_NOT_READY_PEER {
self.common.reset_message_m(session_id);
*transcript_vca = None;
*transcript_meas = None;
}
} else {
*transcript_vca = Some(self.common.runtime_info.message_a.clone());
}

result
Expand All @@ -48,6 +60,7 @@ impl RequesterContext {
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_meas: &mut Option<ManagedBufferM>,
slot_id: u8,
) -> SpdmResult<u8> {
info!("send spdm measurement\n");
Expand Down Expand Up @@ -85,6 +98,7 @@ impl RequesterContext {
spdm_measurement_record_structure,
&send_buffer[..send_used],
&receive_buffer[..used],
transcript_meas,
)
}

Expand Down Expand Up @@ -126,6 +140,7 @@ impl RequesterContext {
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
send_buffer: &[u8],
receive_buffer: &[u8],
transcript_meas: &mut Option<ManagedBufferM>,
) -> SpdmResult<u8> {
self.common.runtime_info.need_measurement_signature =
measurement_attributes.contains(SpdmMeasurementAttributes::SIGNATURE_REQUESTED);
Expand Down Expand Up @@ -173,6 +188,14 @@ impl RequesterContext {
self.common.append_message_m(session_id, send_buffer)?;
self.common
.append_message_m(session_id, &receive_buffer[..temp_used])?;
if let Some(ret_message_m) = transcript_meas {
ret_message_m
.append_message(send_buffer)
.ok_or(SPDM_STATUS_BUFFER_FULL)?;
ret_message_m
.append_message(&receive_buffer[..temp_used])
.ok_or(SPDM_STATUS_BUFFER_FULL)?;
}

// verify signature
if measurement_attributes
Expand Down Expand Up @@ -228,6 +251,7 @@ impl RequesterContext {
}
}

#[allow(clippy::too_many_arguments)]
pub async fn send_receive_spdm_measurement(
&mut self,
session_id: Option<u32>,
Expand All @@ -237,13 +261,17 @@ impl RequesterContext {
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_vca: &mut Option<ManagedBufferA>, // 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_measurement_record_structure,
transcript_vca,
transcript_meas,
slot_id,
)
.await?;
Expand Down
18 changes: 18 additions & 0 deletions test/spdm-requester-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ async fn test_spdm(

let mut total_number: u8 = 0;
let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default();
let mut transcript_vca = None;
let mut transcript_meas = None;

if context
.send_receive_spdm_measurement(
None,
Expand All @@ -265,13 +268,19 @@ async fn test_spdm(
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_err()
{
panic!("send_receive_spdm_measurement failed!");
}

if transcript_vca.is_none() || transcript_meas.is_none() {
panic!("get VCA + message_m from send_receive_spdm_measurement failed!");
}

let result = context
.start_session(
false,
Expand Down Expand Up @@ -318,6 +327,9 @@ async fn test_spdm(
panic!("send_receive_spdm_key_update failed");
}

let mut transcript_vca = None;
let mut transcript_meas = None;

if context
.send_receive_spdm_measurement(
Some(session_id),
Expand All @@ -326,13 +338,19 @@ async fn test_spdm(
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_err()
{
panic!("send_receive_spdm_measurement failed");
}

if transcript_vca.is_none() || transcript_meas.is_none() {
panic!("get VCA + message_m from send_receive_spdm_measurement failed!");
}

if context
.send_receive_spdm_digest(Some(session_id))
.await
Expand Down
5 changes: 5 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,6 +287,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let result = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -295,6 +298,8 @@ fn issue_other_request_before_vca_negotiated() {
measurement_operation,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await;
assert!(
Expand Down
22 changes: 22 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,6 +120,9 @@ 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 transcript_vca = None;
let mut transcript_meas = None;

let status = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -128,12 +131,17 @@ fn test_case0_send_receive_spdm_measurement() {
measurement_operation,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_ok();
assert!(status);

let measurement_operation = SpdmMeasurementOperation::SpdmMeasurementRequestAll;
let mut transcript_vca = None;
let mut transcript_meas = None;

let status = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -142,12 +150,17 @@ fn test_case0_send_receive_spdm_measurement() {
measurement_operation,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_ok();
assert!(status);

let measurement_operation = SpdmMeasurementOperation::Unknown(1);
let mut transcript_vca = None;
let mut transcript_meas = None;

let status = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -156,12 +169,17 @@ fn test_case0_send_receive_spdm_measurement() {
measurement_operation,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_ok();
assert!(status);

let measurement_operation = SpdmMeasurementOperation::Unknown(5);
let mut transcript_vca = None;
let mut transcript_meas = None;

let status = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -170,6 +188,8 @@ fn test_case0_send_receive_spdm_measurement() {
measurement_operation,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_vca,
&mut transcript_meas,
)
.await
.is_err();
Expand Down Expand Up @@ -352,6 +372,7 @@ 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 transcript_meas = None;
let result = requester.handle_spdm_measurement_record_response(
session_id,
tc.request_slot_id,
Expand All @@ -360,6 +381,7 @@ fn test_handle_spdm_measurement_record_response() {
&mut spdm_measurement_record_structure,
&send_buffer,
&*tc.receive_buffer,
&mut transcript_meas,
);
assert!(
result == tc.expected_result,
Expand Down

0 comments on commit bf3b975

Please sign in to comment.