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

add support to export the full transcript (VCA + message_m) #109

Merged
merged 1 commit into from
Oct 23, 2023
Merged
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
7 changes: 6 additions & 1 deletion fuzz-target/pass_context/src/pass_requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ pub async fn fuzz_total_requesters() {
req_provision_info,
);

if requester.init_connection().await.is_err() {
let mut transcript_vca = None;
if requester
.init_connection(&mut transcript_vca)
.await
.is_err()
{
return;
}

Expand Down
3 changes: 3 additions & 0 deletions fuzz-target/random_requester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ async fn run_spdm(spdm: Vec<i32>) {
let mut spdm_measurement_record_structure =
SpdmMeasurementRecordStructure::default();
let mut content_changed = None;
let mut transcript_meas = None;

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

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -77,6 +79,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -123,6 +126,8 @@ 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 mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -132,6 +137,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -179,6 +185,8 @@ 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 mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -188,6 +196,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -235,6 +244,8 @@ 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 mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -244,6 +255,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await;
}
Expand Down Expand Up @@ -319,6 +331,8 @@ 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 mut transcript_meas = None;

let _ = requester
.send_receive_spdm_measurement(
Some(4294836221),
Expand All @@ -328,6 +342,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await;
}
Expand Down
12 changes: 9 additions & 3 deletions spdmlib/src/requester/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: Apache-2.0

use crate::common::ST1;
use crate::common::{self, SpdmDeviceIo, SpdmTransportEncap};
use crate::common::{ManagedBufferA, ST1};
use crate::config;
use crate::error::{SpdmResult, SPDM_STATUS_RECEIVE_FAIL, SPDM_STATUS_SEND_FAIL};
use crate::protocol::*;
Expand Down Expand Up @@ -34,10 +34,16 @@ impl RequesterContext {
}
}

pub async fn init_connection(&mut self) -> SpdmResult {
pub async fn init_connection(
&mut self,
transcript_vca: &mut Option<ManagedBufferA>,
) -> SpdmResult {
*transcript_vca = None;
self.send_receive_spdm_version().await?;
self.send_receive_spdm_capability().await?;
self.send_receive_spdm_algorithm().await
self.send_receive_spdm_algorithm().await?;
*transcript_vca = Some(self.common.runtime_info.message_a.clone());
Ok(())
}

pub async fn start_session(
Expand Down
34 changes: 34 additions & 0 deletions spdmlib/src/requester/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,52 @@ 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,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_meas: &mut Option<ManagedBufferM>,
Copy link
Contributor

@jyao1 jyao1 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the caller needs to invoke send_receive_spdm_measurement_record() multiple times, then transcript_vca will be copied multiple times.

That is not efficient.

Can we do that in init_connection()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the caller needs to invoke send_receive_spdm_measurement_record() multiple times, then transcript_vca will be copied multiple times.

That is not efficient.

Can we do that in init_connection()?

Sure, updated.

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,
content_changed,
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_meas = None;
}
}

result
}

#[allow(clippy::too_many_arguments)]
async fn delegate_send_receive_spdm_measurement_record(
&mut self,
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
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 @@ -89,6 +99,7 @@ impl RequesterContext {
spdm_measurement_record_structure,
&send_buffer[..send_used],
&receive_buffer[..used],
transcript_meas,
)
}

Expand Down Expand Up @@ -131,6 +142,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 @@ -181,6 +193,26 @@ 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)?;

if measurement_attributes
.contains(SpdmMeasurementAttributes::SIGNATURE_REQUESTED)
{
if measurements.signature.as_ref().is_empty() {
return Err(SPDM_STATUS_INVALID_MSG_FIELD);
} else {
ret_message_m
.append_message(measurements.signature.as_ref())
.ok_or(SPDM_STATUS_BUFFER_FULL)?;
}
}
}

// verify signature
if measurement_attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need append signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need append signature

updated.

Expand Down Expand Up @@ -247,6 +279,7 @@ 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_meas: &mut Option<ManagedBufferM>, // out
) -> SpdmResult {
*out_total_number = self
.send_receive_spdm_measurement_record(
Expand All @@ -255,6 +288,7 @@ impl RequesterContext {
measurement_operation,
content_changed,
spdm_measurement_record_structure,
transcript_meas,
slot_id,
)
.await?;
Expand Down
23 changes: 21 additions & 2 deletions test/spdm-requester-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ async fn test_spdm(
provision_info,
);

if context.init_connection().await.is_err() {
let mut transcript_vca = None;
if context.init_connection(&mut transcript_vca).await.is_err() {
panic!("init_connection failed!");
}

Expand Down Expand Up @@ -269,6 +270,8 @@ async fn test_spdm(
let mut total_number: u8 = 0;
let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default();
let mut content_changed = None;
let mut transcript_meas = None;

if context
.send_receive_spdm_measurement(
None,
Expand All @@ -278,13 +281,18 @@ async fn test_spdm(
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await
.is_err()
{
panic!("send_receive_spdm_measurement failed!");
}

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

let result = context
.start_session(
false,
Expand Down Expand Up @@ -332,6 +340,8 @@ async fn test_spdm(
}

let mut content_changed = None;
let mut transcript_meas = None;

if context
.send_receive_spdm_measurement(
Some(session_id),
Expand All @@ -341,13 +351,18 @@ async fn test_spdm(
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&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 Expand Up @@ -517,7 +532,8 @@ async fn test_idekm(
provision_info,
);

if context.init_connection().await.is_err() {
let mut transcript_vca = None;
if context.init_connection(&mut transcript_vca).await.is_err() {
panic!("init_connection failed!");
}

Expand Down Expand Up @@ -547,6 +563,8 @@ async fn test_idekm(
let mut total_number: u8 = 0;
let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default();
let mut content_changed = None;
let mut transcript_meas = None;

if context
.send_receive_spdm_measurement(
None,
Expand All @@ -556,6 +574,7 @@ async fn test_idekm(
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await
.is_err()
Expand Down
6 changes: 4 additions & 2 deletions test/spdmlib-test/src/requester_tests/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ fn test_case0_start_session() {
req_provision_info,
);

let status = requester.init_connection().await.is_ok();
let mut transcript_vca = None;
let status = requester.init_connection(&mut transcript_vca).await.is_ok();
assert!(status);

let status = requester.send_receive_spdm_digest(None).await.is_ok();
Expand Down Expand Up @@ -142,7 +143,8 @@ fn test_case0_get_next_half_session() {
req_provision_info,
);

let status = requester.init_connection().await.is_ok();
let mut transcript_vca = None;
let status = requester.init_connection(&mut transcript_vca).await.is_ok();
assert!(status);

let status = requester.send_receive_spdm_digest(None).await.is_ok();
Expand Down
3 changes: 3 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 @@ -288,6 +288,8 @@ fn issue_other_request_before_vca_negotiated() {
let mut total_number: u8 = 0;
let mut spdm_measurement_record_structure = SpdmMeasurementRecordStructure::default();
let mut content_changed = None;
let mut transcript_meas = None;

let result = requester
.send_receive_spdm_measurement(
None,
Expand All @@ -297,6 +299,7 @@ fn issue_other_request_before_vca_negotiated() {
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
&mut transcript_meas,
)
.await;
assert!(
Expand Down
Loading
Loading