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).
Browse files Browse the repository at this point in the history
fix #29

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Oct 16, 2023
1 parent feee628 commit b15c963
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 9 deletions.
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 @@ -99,6 +99,8 @@ async fn run_spdm(spdm: Vec<i32>) {
let mut total_number = 0;
let mut spdm_measurement_record_structure =
SpdmMeasurementRecordStructure::default();
let mut transcript_meas = None;

if requester
.send_receive_spdm_measurement(
None,
Expand All @@ -107,6 +109,7 @@ async fn run_spdm(spdm: Vec<i32>) {
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&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 @@ -67,6 +67,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 transcript_meas = None;

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

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

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

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

let _ = requester
.send_receive_spdm_measurement(
Some(4294836221),
Expand All @@ -318,6 +332,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&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
22 changes: 22 additions & 0 deletions spdmlib/src/requester/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@ 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_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_meas = None;
}
}

Expand All @@ -48,6 +56,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 +94,7 @@ impl RequesterContext {
spdm_measurement_record_structure,
&send_buffer[..send_used],
&receive_buffer[..used],
transcript_meas,
)
}

Expand Down Expand Up @@ -126,6 +136,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 +184,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 +247,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 +257,15 @@ 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(
session_id,
spdm_measuremente_attributes,
measurement_operation,
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 @@ -268,6 +269,8 @@ async fn test_spdm(

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

if context
.send_receive_spdm_measurement(
None,
Expand All @@ -276,13 +279,18 @@ async fn test_spdm(
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&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 @@ -329,6 +337,8 @@ async fn test_spdm(
panic!("send_receive_spdm_key_update failed");
}

let mut transcript_meas = None;

if context
.send_receive_spdm_measurement(
Some(session_id),
Expand All @@ -337,13 +347,18 @@ async fn test_spdm(
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
&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 @@ -513,7 +528,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 @@ -542,6 +558,8 @@ async fn test_idekm(

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

if context
.send_receive_spdm_measurement(
None,
Expand All @@ -550,6 +568,7 @@ async fn test_idekm(
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
&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 @@ -287,6 +287,8 @@ 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_meas = None;

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

0 comments on commit b15c963

Please sign in to comment.