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

Commit

Permalink
change list of version to list of option.
Browse files Browse the repository at this point in the history
fix #170

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Dec 12, 2023
1 parent a0b0220 commit be89212
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 55 deletions.
2 changes: 1 addition & 1 deletion fuzz-target/requester/version_req/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn fuzz_send_receive_spdm_version(fuzzdata: Arc<Vec<u8>>) {
{
let (mut req_config_info, req_provision_info) = req_create_info();
for i in 0..MAX_SPDM_VERSION_COUNT {
req_config_info.spdm_version[i] = SpdmVersion::default();
req_config_info.spdm_version[i] = Some(SpdmVersion::default());
}

let shared_buffer = SharedBuffer::new();
Expand Down
4 changes: 2 additions & 2 deletions spdmlib/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ impl SpdmContext {

#[derive(Debug, Default)]
pub struct SpdmConfigInfo {
pub spdm_version: [SpdmVersion; MAX_SPDM_VERSION_COUNT],
pub spdm_version: [Option<SpdmVersion>; MAX_SPDM_VERSION_COUNT],
pub req_capabilities: SpdmRequestCapabilityFlags,
pub rsp_capabilities: SpdmResponseCapabilityFlags,
pub req_ct_exponent: u8,
Expand All @@ -1125,7 +1125,7 @@ pub struct SpdmConfigInfo {
pub data_transfer_size: u32,
pub max_spdm_msg_size: u32,
pub heartbeat_period: u8, // used by responder only
pub secure_spdm_version: [SecuredMessageVersion; MAX_SECURE_SPDM_VERSION_COUNT], // used by responder only
pub secure_spdm_version: [Option<SecuredMessageVersion>; MAX_SECURE_SPDM_VERSION_COUNT], // used by responder only
}

#[derive(Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion spdmlib/src/requester/get_version_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl RequesterContext {
.common
.config_info
.spdm_version
.contains(&spdm_version_struct.version)
.contains(&Some(spdm_version_struct.version))
{
negotiate_version = Some(spdm_version_struct.version);
break;
Expand Down
11 changes: 9 additions & 2 deletions spdmlib/src/responder/key_exchange_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ impl ResponderContext {
);
}
for index in 0..secured_message_version_list.version_count as usize {
for local_version in self.common.config_info.secure_spdm_version {
if secured_message_version_list.versions_list[index] == local_version {
for (_, local_version) in self
.common
.config_info
.secure_spdm_version
.iter()
.flatten()
.enumerate()
{
if secured_message_version_list.versions_list[index] == *local_version {
if self.common.negotiate_info.spdm_version_sel
< SpdmVersion::SpdmVersion12
{
Expand Down
11 changes: 9 additions & 2 deletions spdmlib/src/responder/psk_exchange_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ impl ResponderContext {
);
}
for index in 0..secured_message_version_list.version_count as usize {
for local_version in self.common.config_info.secure_spdm_version {
if secured_message_version_list.versions_list[index] == local_version {
for (_, local_version) in self
.common
.config_info
.secure_spdm_version
.iter()
.flatten()
.enumerate()
{
if secured_message_version_list.versions_list[index] == *local_version {
if self.common.negotiate_info.spdm_version_sel
< SpdmVersion::SpdmVersion12
{
Expand Down
33 changes: 18 additions & 15 deletions spdmlib/src/responder/version_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,30 @@ impl ResponderContext {
}

info!("send spdm version\n");
let mut version_number_entry_count = 0;
let mut versions = gen_array_clone(SpdmVersionStruct::default(), MAX_SPDM_VERSION_COUNT);
for (_, v) in self
.common
.config_info
.spdm_version
.iter()
.flatten()
.enumerate()
{
versions[version_number_entry_count] = SpdmVersionStruct {
update: 0,
version: *v,
};
version_number_entry_count += 1;
}
let response = SpdmMessage {
header: SpdmMessageHeader {
version: SpdmVersion::SpdmVersion10,
request_response_code: SpdmRequestResponseCode::SpdmResponseVersion,
},
payload: SpdmMessagePayload::SpdmVersionResponse(SpdmVersionResponsePayload {
version_number_entry_count: 3,
versions: [
SpdmVersionStruct {
update: 0,
version: self.common.config_info.spdm_version[0],
},
SpdmVersionStruct {
update: 0,
version: self.common.config_info.spdm_version[1],
},
SpdmVersionStruct {
update: 0,
version: self.common.config_info.spdm_version[2],
},
],
version_number_entry_count: version_number_entry_count as u8,
versions,
}),
};

Expand Down
23 changes: 16 additions & 7 deletions test/spdm-requester-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use codec::Codec;
use common::SpdmDeviceIo;
use common::SpdmTransportEncap;

use core::convert::TryFrom;
use idekm::pci_ide_km_requester::IdekmReqContext;
use idekm::pci_idekm::Aes256GcmKeyBuffer;
use idekm::pci_idekm::KpAckStatus;
Expand All @@ -28,6 +28,7 @@ use spdm_emu::crypto_callback::SECRET_ASYM_IMPL_INSTANCE;
use spdm_emu::secret_impl_sample::SECRET_PSK_IMPL_INSTANCE;
use spdm_emu::EMU_STACK_SIZE;
use spdmlib::common;
use spdmlib::common::SecuredMessageVersion;
use spdmlib::common::SpdmOpaqueSupport;
use spdmlib::common::ST1;
use spdmlib::config;
Expand Down Expand Up @@ -151,9 +152,9 @@ async fn test_spdm(

let config_info = common::SpdmConfigInfo {
spdm_version: [
SpdmVersion::SpdmVersion10,
SpdmVersion::SpdmVersion11,
SpdmVersion::SpdmVersion12,
Some(SpdmVersion::SpdmVersion10),
Some(SpdmVersion::SpdmVersion11),
Some(SpdmVersion::SpdmVersion12),
],
req_capabilities,
req_ct_exponent: 0,
Expand All @@ -175,6 +176,10 @@ async fn test_spdm(
opaque_support: SpdmOpaqueSupport::OPAQUE_DATA_FMT1,
data_transfer_size: config::MAX_SPDM_MSG_SIZE as u32,
max_spdm_msg_size: config::MAX_SPDM_MSG_SIZE as u32,
secure_spdm_version: [
Some(SecuredMessageVersion::try_from(0x10u8).unwrap()),
Some(SecuredMessageVersion::try_from(0x11u8).unwrap()),
],
..Default::default()
};

Expand Down Expand Up @@ -445,9 +450,9 @@ async fn test_idekm_tdisp(

let config_info = common::SpdmConfigInfo {
spdm_version: [
SpdmVersion::SpdmVersion10,
SpdmVersion::SpdmVersion11,
SpdmVersion::SpdmVersion12,
Some(SpdmVersion::SpdmVersion10),
Some(SpdmVersion::SpdmVersion11),
Some(SpdmVersion::SpdmVersion12),
],
req_capabilities,
req_ct_exponent: 0,
Expand All @@ -469,6 +474,10 @@ async fn test_idekm_tdisp(
opaque_support: SpdmOpaqueSupport::OPAQUE_DATA_FMT1,
data_transfer_size: config::MAX_SPDM_MSG_SIZE as u32,
max_spdm_msg_size: config::MAX_SPDM_MSG_SIZE as u32,
secure_spdm_version: [
Some(SecuredMessageVersion::try_from(0x10u8).unwrap()),
Some(SecuredMessageVersion::try_from(0x11u8).unwrap()),
],
..Default::default()
};

Expand Down
10 changes: 5 additions & 5 deletions test/spdm-responder-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ async fn handle_message(

let config_info = common::SpdmConfigInfo {
spdm_version: [
SpdmVersion::SpdmVersion10,
SpdmVersion::SpdmVersion11,
SpdmVersion::SpdmVersion12,
Some(SpdmVersion::SpdmVersion10),
Some(SpdmVersion::SpdmVersion11),
Some(SpdmVersion::SpdmVersion12),
],
rsp_capabilities,
rsp_ct_exponent: 0,
Expand All @@ -288,8 +288,8 @@ async fn handle_message(
max_spdm_msg_size: config::MAX_SPDM_MSG_SIZE as u32,
heartbeat_period: config::HEARTBEAT_PERIOD,
secure_spdm_version: [
SecuredMessageVersion::try_from(0x10u8).unwrap(),
SecuredMessageVersion::try_from(0x11u8).unwrap(),
Some(SecuredMessageVersion::try_from(0x10u8).unwrap()),
Some(SecuredMessageVersion::try_from(0x11u8).unwrap()),
],
..Default::default()
};
Expand Down
30 changes: 19 additions & 11 deletions test/spdmlib-test/src/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use core::ops::DerefMut;
pub fn create_info() -> (SpdmConfigInfo, SpdmProvisionInfo) {
let config_info = SpdmConfigInfo {
spdm_version: [
SpdmVersion::SpdmVersion10,
SpdmVersion::SpdmVersion11,
SpdmVersion::SpdmVersion12,
Some(SpdmVersion::SpdmVersion10),
Some(SpdmVersion::SpdmVersion11),
Some(SpdmVersion::SpdmVersion12),
],
rsp_capabilities: SpdmResponseCapabilityFlags::CERT_CAP
| SpdmResponseCapabilityFlags::CHAL_CAP
Expand Down Expand Up @@ -74,6 +74,10 @@ pub fn create_info() -> (SpdmConfigInfo, SpdmProvisionInfo) {
opaque_support: SpdmOpaqueSupport::OPAQUE_DATA_FMT1,
data_transfer_size: 0x1200,
max_spdm_msg_size: 0x1200,
secure_spdm_version: [
Some(SecuredMessageVersion::try_from(0x10u8).unwrap()),
Some(SecuredMessageVersion::try_from(0x11u8).unwrap()),
],
..Default::default()
};

Expand Down Expand Up @@ -169,9 +173,9 @@ pub fn req_create_info() -> (SpdmConfigInfo, SpdmProvisionInfo) {
};
let config_info = SpdmConfigInfo {
spdm_version: [
SpdmVersion::SpdmVersion10,
SpdmVersion::SpdmVersion11,
SpdmVersion::SpdmVersion12,
Some(SpdmVersion::SpdmVersion10),
Some(SpdmVersion::SpdmVersion11),
Some(SpdmVersion::SpdmVersion12),
],
req_capabilities: req_capabilities,
req_ct_exponent: 0,
Expand All @@ -193,6 +197,10 @@ pub fn req_create_info() -> (SpdmConfigInfo, SpdmProvisionInfo) {
opaque_support: SpdmOpaqueSupport::OPAQUE_DATA_FMT1,
data_transfer_size: config::MAX_SPDM_MSG_SIZE as u32,
max_spdm_msg_size: config::MAX_SPDM_MSG_SIZE as u32,
secure_spdm_version: [
Some(SecuredMessageVersion::try_from(0x10u8).unwrap()),
Some(SecuredMessageVersion::try_from(0x11u8).unwrap()),
],
..Default::default()
};

Expand Down Expand Up @@ -294,9 +302,9 @@ pub fn rsp_create_info() -> (SpdmConfigInfo, SpdmProvisionInfo) {
};
let config_info = SpdmConfigInfo {
spdm_version: [
SpdmVersion::SpdmVersion10,
SpdmVersion::SpdmVersion11,
SpdmVersion::SpdmVersion12,
Some(SpdmVersion::SpdmVersion10),
Some(SpdmVersion::SpdmVersion11),
Some(SpdmVersion::SpdmVersion12),
],
rsp_capabilities: rsp_capabilities,
rsp_ct_exponent: 0,
Expand All @@ -321,8 +329,8 @@ pub fn rsp_create_info() -> (SpdmConfigInfo, SpdmProvisionInfo) {
max_spdm_msg_size: config::MAX_SPDM_MSG_SIZE as u32,
heartbeat_period: config::HEARTBEAT_PERIOD,
secure_spdm_version: [
SecuredMessageVersion::try_from(0x10u8).unwrap(),
SecuredMessageVersion::try_from(0x11u8).unwrap(),
Some(SecuredMessageVersion::try_from(0x10u8).unwrap()),
Some(SecuredMessageVersion::try_from(0x11u8).unwrap()),
],
..Default::default()
};
Expand Down
20 changes: 11 additions & 9 deletions test/spdmlib-test/src/responder_tests/version_rsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,24 @@ pub fn construct_version_positive() -> (TestSpdmMessage, TestSpdmMessage) {
secure: 0,
};
let (config_info, provision_info) = create_info();
let mut VersionNumberEntryCount = 0;
let mut VersionNumberEntry: [u16; MAX_SPDM_VERSION_COUNT] = gen_array_clone(
u8::from(SpdmVersion::default()) as u16,
MAX_SPDM_VERSION_COUNT,
);
for (_, v) in config_info.spdm_version.iter().flatten().enumerate() {
VersionNumberEntry[VersionNumberEntryCount] = (u8::from(*v) as u16) << 8;
VersionNumberEntryCount += 1;
}
let version_msg = TestSpdmMessage {
message: protocol::Message::VERSION(protocol::version::VERSION {
SPDMVersion: 0x10,
RequestResponseCode: 0x04,
Param1: 0,
Param2: 0,
Reserved: 0,
VersionNumberEntryCount: config_info.spdm_version.len() as u8,
VersionNumberEntry: {
let mut versions = Vec::new();
for v in config_info.spdm_version {
let version = (u8::from(v) as u16) << 8;
versions.push(version)
}
versions
},
VersionNumberEntryCount: VersionNumberEntryCount as u8,
VersionNumberEntry: VersionNumberEntry.to_vec(),
}),
secure: 0,
};
Expand Down

0 comments on commit be89212

Please sign in to comment.