forked from OpenPRoT/spdm-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
(GET_)MEASUREMENTS #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+918
−228
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c527017
Refactor measurements command
embediver 53a61d4
Implement GET_MEASUREMENTS request generation
embediver 8dfb988
Add MEASUREMENTS response handler stub, add doc
embediver 0e10400
Implement MEASUREMENTS response parsing
embediver b2cbe5f
Reset M1/M2 transcript when a GET_MEASUREMENTS request is generated
embediver 3de4b6d
Add functionality to parse and iterate measurements from response
embediver 9199897
Fix L1/L2 transcript generation, check L1/L2 signature in example
embediver 8fcfe52
Only parse MEASUREMENTS requester context when conn. ver. is > v1.2
embediver 355ab39
Fix bug: Correctly resize buffer for transcript signature exclusion
embediver 37b12f8
Fix some linter warnings
embediver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| // Copyright 2025 | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! GET_MEASUREMENTS and MEASURMENTS command types and logic | ||
|
|
||
| /// Requester logic for GET_MEASUREMENTS and MEASURMENTS | ||
| pub mod request; | ||
| /// Responder logic for GET_MEASUREMENTS and MEASURMENTS | ||
| pub mod response; | ||
|
|
||
| use crate::protocol::*; | ||
| use crate::{codec::CommonCodec, error::CommandError}; | ||
| use bitfield::bitfield; | ||
| use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned}; | ||
|
|
||
| const RESPONSE_FIXED_FIELDS_SIZE: usize = 8; | ||
| const MAX_RESPONSE_VARIABLE_FIELDS_SIZE: usize = | ||
| NONCE_LEN + size_of::<u32>() + size_of::<RequesterContext>(); | ||
|
|
||
| #[derive(FromBytes, IntoBytes, Immutable)] | ||
| #[repr(C)] | ||
| struct GetMeasurementsReqCommon { | ||
| req_attr: GetMeasurementsReqAttr, | ||
| meas_op: u8, | ||
| } | ||
| impl CommonCodec for GetMeasurementsReqCommon {} | ||
|
|
||
| #[derive(FromBytes, IntoBytes, Immutable)] | ||
| #[repr(C)] | ||
| struct GetMeasurementsReqSignature { | ||
| requester_nonce: [u8; NONCE_LEN], | ||
| slot_id: u8, | ||
| } | ||
| impl CommonCodec for GetMeasurementsReqSignature {} | ||
|
|
||
| bitfield! { | ||
| #[derive(FromBytes, IntoBytes, Immutable)] | ||
| #[repr(C)] | ||
| struct GetMeasurementsReqAttr(u8); | ||
| impl Debug; | ||
| u8; | ||
| pub signature_requested, set_signature_requested: 0, 0; | ||
| pub raw_bitstream_requested, set_raw_bitstream_requested: 1, 1; | ||
| pub new_measurement_requested, set_new_measurement_requested: 2, 2; | ||
| reserved, _: 7, 3; | ||
| } | ||
|
|
||
| bitfield! { | ||
| #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)] | ||
| #[repr(C)] | ||
| struct MeasurementsRspFixed([u8]); | ||
| impl Debug; | ||
| u8; | ||
| pub spdm_version, set_spdm_version: 7, 0; | ||
| pub req_resp_code, set_req_resp_code: 15, 8; | ||
| pub total_measurement_indices, set_total_measurement_indices: 23, 16; | ||
| pub slot_id, set_slot_id: 27, 24; | ||
| pub content_changed, set_content_changed: 29, 28; | ||
| reserved, _: 31, 30; | ||
| pub num_blocks, set_num_blocks: 39, 32; | ||
| pub measurement_record_len_byte0, set_measurement_record_len_byte0: 47, 40; | ||
| pub measurement_record_len_byte1, set_measurement_record_len_byte1: 55, 48; | ||
| pub measurement_record_len_byte2, set_measurement_record_len_byte2: 63, 56; | ||
| } | ||
|
|
||
| impl MeasurementsRspFixed<[u8; RESPONSE_FIXED_FIELDS_SIZE]> { | ||
| pub fn set_measurement_record_len(&mut self, len: u32) { | ||
| self.set_measurement_record_len_byte0((len & 0xFF) as u8); | ||
| self.set_measurement_record_len_byte1(((len >> 8) & 0xFF) as u8); | ||
| self.set_measurement_record_len_byte2(((len >> 16) & 0xFF) as u8); | ||
| } | ||
| } | ||
|
|
||
| impl Default for MeasurementsRspFixed<[u8; RESPONSE_FIXED_FIELDS_SIZE]> { | ||
| fn default() -> Self { | ||
| Self([0; RESPONSE_FIXED_FIELDS_SIZE]) | ||
| } | ||
| } | ||
|
|
||
| impl CommonCodec for MeasurementsRspFixed<[u8; RESPONSE_FIXED_FIELDS_SIZE]> {} | ||
|
|
||
| /// Measurement Operation request field | ||
| pub enum MeasurementOperation { | ||
| /// Query the Responder for the total number of measurement blocks available | ||
| ReportMeasBlockCount, | ||
| /// Request the measurement block at a specific index | ||
| /// | ||
| /// Index has to be between `0x01` and `0xFE`, inclusively. | ||
| RequestSingleMeasBlock(u8), | ||
| /// Request all measurement blocks | ||
| RequestAllMeasBlocks, | ||
| } | ||
|
|
||
| impl TryInto<u8> for MeasurementOperation { | ||
| type Error = CommandError; | ||
|
|
||
| fn try_into(self) -> Result<u8, Self::Error> { | ||
| match self { | ||
| MeasurementOperation::ReportMeasBlockCount => Ok(0x01), | ||
| MeasurementOperation::RequestSingleMeasBlock(x) => { | ||
| if matches!(x, 0x00 | 0xFF) { | ||
| Err(CommandError::UnsupportedRequest) | ||
| } else { | ||
| Ok(x) | ||
| } | ||
| } | ||
| MeasurementOperation::RequestAllMeasBlocks => Ok(0xFF), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, FromBytes, IntoBytes, Immutable, Unaligned, KnownLayout)] | ||
| #[repr(C, packed)] | ||
| struct MeasurementBlockHeader { | ||
| index: u8, | ||
| measurement_spec: MeasurementSpecification, | ||
| measurement_size: zerocopy::little_endian::U16, | ||
| } | ||
|
|
||
| impl CommonCodec for MeasurementBlockHeader {} | ||
|
|
||
| /// Content changed indicators for MEASUREMENT responses | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub enum ContentChanged { | ||
| /// The Responder does not detect changes of MeasurementRecord fields | ||
| /// of previous MEASUREMENTS responses in the same measurement log, | ||
| /// or this message does not contain a signature. | ||
| NoDetection = 0x00, | ||
| /// The Responder detected that one or more MeasurementRecord fields | ||
| /// of previous MEASUREMENTS responses in the measurement log being | ||
| /// signed have changed. The Requester might consider issuing | ||
| /// GET_MEASUREMENTS again to acquire latest measurements. | ||
| ChangeDetected = 0x01, | ||
| /// The Responder detected no change in MeasurementRecord fields of | ||
| /// previous MEASUREMENTS responses in the measurement log being signed. | ||
| NoChangeDetected = 0x10, | ||
| Reserved = 0x11, | ||
| } | ||
|
|
||
| impl From<u8> for ContentChanged { | ||
| fn from(value: u8) -> Self { | ||
| match value { | ||
| 0b00 => Self::NoDetection, | ||
| 0b01 => Self::ChangeDetected, | ||
| 0b10 => Self::NoChangeDetected, | ||
| _ => Self::Reserved, | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.