Skip to content

Commit

Permalink
support customized nonce for get measurement request.
Browse files Browse the repository at this point in the history
Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang authored and jyao1 committed Aug 1, 2024
1 parent 6535548 commit 76a6813
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions fuzz-target/random_requester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async fn run_spdm(spdm: Vec<i32>) {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down
5 changes: 5 additions & 0 deletions fuzz-target/requester/measurement_req/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -134,6 +135,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -193,6 +195,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
0,
SpdmMeasurementAttributes::RAW_BIT_STREAM_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -252,6 +255,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
0,
SpdmMeasurementAttributes::empty(),
SpdmMeasurementOperation::Unknown(4),
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -339,6 +343,7 @@ async fn fuzz_send_receive_spdm_measurement(fuzzdata: Arc<Vec<u8>>) {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down
14 changes: 13 additions & 1 deletion spdmlib/src/requester/get_measurements_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl RequesterContext {
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_meas: &mut Option<ManagedBufferM>,
Expand All @@ -36,6 +37,7 @@ impl RequesterContext {
session_id,
measurement_attributes,
measurement_operation,
spdm_nonce_struct,
content_changed,
spdm_measurement_record_structure,
transcript_meas,
Expand All @@ -60,6 +62,7 @@ impl RequesterContext {
session_id: Option<u32>,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
content_changed: &mut Option<SpdmMeasurementContentChanged>,
spdm_measurement_record_structure: &mut SpdmMeasurementRecordStructure,
transcript_meas: &mut Option<ManagedBufferM>,
Expand All @@ -80,6 +83,7 @@ impl RequesterContext {
let send_used = self.encode_spdm_measurement_record(
measurement_attributes,
measurement_operation,
spdm_nonce_struct,
slot_id,
&mut send_buffer,
)?;
Expand Down Expand Up @@ -109,12 +113,18 @@ impl RequesterContext {
&mut self,
measurement_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
slot_id: u8,
buf: &mut [u8],
) -> SpdmResult<usize> {
let mut writer = Writer::init(buf);
let mut nonce = [0u8; SPDM_NONCE_SIZE];
crypto::rand::get_random(&mut nonce)?;

if let Some(n) = spdm_nonce_struct {
nonce.copy_from_slice(&n.data)
} else {
crypto::rand::get_random(&mut nonce)?;
}

let request = SpdmMessage {
header: SpdmMessageHeader {
Expand Down Expand Up @@ -278,6 +288,7 @@ impl RequesterContext {
slot_id: u8,
spdm_measuremente_attributes: SpdmMeasurementAttributes,
measurement_operation: SpdmMeasurementOperation,
spdm_nonce_struct: Option<SpdmNonceStruct>,
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.
Expand All @@ -289,6 +300,7 @@ impl RequesterContext {
session_id,
spdm_measuremente_attributes,
measurement_operation,
spdm_nonce_struct,
content_changed,
spdm_measurement_record_structure,
transcript_meas,
Expand Down
3 changes: 3 additions & 0 deletions test/spdm-requester-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ async fn test_spdm(
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -519,6 +520,7 @@ async fn test_spdm(
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementQueryTotalNumber,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -754,6 +756,7 @@ async fn test_idekm_tdisp(
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
SpdmMeasurementOperation::SpdmMeasurementRequestAll,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down
1 change: 1 addition & 0 deletions test/spdmlib-test/src/requester_tests/get_digests_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ fn issue_other_request_before_vca_negotiated() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down
8 changes: 8 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 @@ -130,6 +130,7 @@ fn test_case0_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand All @@ -149,6 +150,7 @@ fn test_case0_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand All @@ -168,6 +170,7 @@ fn test_case0_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand All @@ -187,6 +190,7 @@ fn test_case0_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -518,6 +522,7 @@ fn test_case1_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand All @@ -537,6 +542,7 @@ fn test_case1_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand Down Expand Up @@ -717,6 +723,7 @@ fn test_case3_send_receive_spdm_measurement() {
0,
SpdmMeasurementAttributes::SIGNATURE_REQUESTED,
measurement_operation,
None,
&mut content_changed,
&mut total_number,
&mut spdm_measurement_record_structure,
Expand All @@ -742,6 +749,7 @@ fn test_case3_send_receive_spdm_measurement() {
SpdmMeasurementAttributes::empty()
},
SpdmMeasurementOperation::Unknown(i),
None,
&mut content_changed,
&mut dummy_total_number,
&mut spdm_measurement_record_structure,
Expand Down

0 comments on commit 76a6813

Please sign in to comment.