diff --git a/fuzz-target/requester/version_req/src/main.rs b/fuzz-target/requester/version_req/src/main.rs index 813bdad5..a25f003d 100644 --- a/fuzz-target/requester/version_req/src/main.rs +++ b/fuzz-target/requester/version_req/src/main.rs @@ -53,7 +53,7 @@ async fn fuzz_send_receive_spdm_version(fuzzdata: Arc>) { { 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(); diff --git a/spdmlib/src/common/mod.rs b/spdmlib/src/common/mod.rs index 6f0e3094..a83b5122 100644 --- a/spdmlib/src/common/mod.rs +++ b/spdmlib/src/common/mod.rs @@ -1106,7 +1106,7 @@ impl SpdmContext { #[derive(Debug, Default)] pub struct SpdmConfigInfo { - pub spdm_version: [SpdmVersion; MAX_SPDM_VERSION_COUNT], + pub spdm_version: [Option; MAX_SPDM_VERSION_COUNT], pub req_capabilities: SpdmRequestCapabilityFlags, pub rsp_capabilities: SpdmResponseCapabilityFlags, pub req_ct_exponent: u8, @@ -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; MAX_SECURE_SPDM_VERSION_COUNT], // used by responder only } #[derive(Debug, Default)] diff --git a/spdmlib/src/requester/get_version_req.rs b/spdmlib/src/requester/get_version_req.rs index 7c110468..d219e21f 100644 --- a/spdmlib/src/requester/get_version_req.rs +++ b/spdmlib/src/requester/get_version_req.rs @@ -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; diff --git a/spdmlib/src/responder/key_exchange_rsp.rs b/spdmlib/src/responder/key_exchange_rsp.rs index 421d6816..96917de9 100644 --- a/spdmlib/src/responder/key_exchange_rsp.rs +++ b/spdmlib/src/responder/key_exchange_rsp.rs @@ -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 { diff --git a/spdmlib/src/responder/psk_exchange_rsp.rs b/spdmlib/src/responder/psk_exchange_rsp.rs index e1fa5c15..0105076d 100644 --- a/spdmlib/src/responder/psk_exchange_rsp.rs +++ b/spdmlib/src/responder/psk_exchange_rsp.rs @@ -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 { diff --git a/spdmlib/src/responder/version_rsp.rs b/spdmlib/src/responder/version_rsp.rs index 05c3fe8d..bce0d651 100644 --- a/spdmlib/src/responder/version_rsp.rs +++ b/spdmlib/src/responder/version_rsp.rs @@ -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, }), }; diff --git a/test/spdm-requester-emu/src/main.rs b/test/spdm-requester-emu/src/main.rs index b2956b08..ece19602 100644 --- a/test/spdm-requester-emu/src/main.rs +++ b/test/spdm-requester-emu/src/main.rs @@ -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; @@ -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; @@ -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, @@ -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() }; @@ -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, @@ -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() }; diff --git a/test/spdm-responder-emu/src/main.rs b/test/spdm-responder-emu/src/main.rs index 44307174..10ad0594 100644 --- a/test/spdm-responder-emu/src/main.rs +++ b/test/spdm-responder-emu/src/main.rs @@ -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, @@ -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() }; diff --git a/test/spdmlib-test/src/common/util.rs b/test/spdmlib-test/src/common/util.rs index ed3aae72..d846db18 100644 --- a/test/spdmlib-test/src/common/util.rs +++ b/test/spdmlib-test/src/common/util.rs @@ -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 @@ -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() }; @@ -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, @@ -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() }; @@ -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, @@ -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() }; diff --git a/test/spdmlib-test/src/responder_tests/version_rsp.rs b/test/spdmlib-test/src/responder_tests/version_rsp.rs index 7dd75707..0000a1fe 100644 --- a/test/spdmlib-test/src/responder_tests/version_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/version_rsp.rs @@ -97,6 +97,15 @@ 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, @@ -104,15 +113,8 @@ pub fn construct_version_positive() -> (TestSpdmMessage, TestSpdmMessage) { 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, };