diff --git a/test/spdmlib-test/src/requester_tests/negotiate_algorithms_req.rs b/test/spdmlib-test/src/requester_tests/negotiate_algorithms_req.rs index a069a94..a66dc03 100644 --- a/test/spdmlib-test/src/requester_tests/negotiate_algorithms_req.rs +++ b/test/spdmlib-test/src/requester_tests/negotiate_algorithms_req.rs @@ -7,6 +7,9 @@ use crate::common::secret_callback::*; use crate::common::transport::PciDoeTransportEncap; use crate::common::util::create_info; use spdmlib::common::SpdmConnectionState; +use spdmlib::protocol::{ + SpdmAlgoOtherParams, SpdmRequestCapabilityFlags, SpdmResponseCapabilityFlags, SpdmVersion, +}; use spdmlib::requester::RequesterContext; use spdmlib::{responder, secret}; use spin::Mutex; @@ -57,3 +60,155 @@ fn test_case0_send_receive_spdm_algorithm() { }; executor::block_on(future); } + +#[test] +fn test_case1_send_receive_spdm_algorithm() { + let future = async { + let (rsp_config_info, rsp_provision_info) = create_info(); + let (req_config_info, req_provision_info) = create_info(); + + let shared_buffer = SharedBuffer::new(); + let device_io_responder = Arc::new(Mutex::new(FakeSpdmDeviceIoReceve::new(Arc::new( + shared_buffer, + )))); + let pcidoe_transport_encap = Arc::new(Mutex::new(PciDoeTransportEncap {})); + + secret::asym_sign::register(SECRET_ASYM_IMPL_INSTANCE.clone()); + + let mut responder = responder::ResponderContext::new( + device_io_responder, + pcidoe_transport_encap, + rsp_config_info, + rsp_provision_info, + ); + responder + .common + .runtime_info + .set_connection_state(SpdmConnectionState::SpdmConnectionAfterCapabilities); + + responder.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion13; + responder + .common + .negotiate_info + .rsp_capabilities_sel + .insert(SpdmResponseCapabilityFlags::MULTI_KEY_CAP_ONLY); + + let pcidoe_transport_encap2 = Arc::new(Mutex::new(PciDoeTransportEncap {})); + let shared_buffer = SharedBuffer::new(); + let device_io_requester = Arc::new(Mutex::new(FakeSpdmDeviceIo::new( + Arc::new(shared_buffer), + Arc::new(Mutex::new(responder)), + ))); + + let mut requester = RequesterContext::new( + device_io_requester, + pcidoe_transport_encap2, + req_config_info, + req_provision_info, + ); + + requester.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion13; + requester + .common + .negotiate_info + .rsp_capabilities_sel + .insert(SpdmResponseCapabilityFlags::MULTI_KEY_CAP_ONLY); + + let status = requester.send_receive_spdm_algorithm().await.is_ok(); + assert!(status); + assert_eq!(requester.common.negotiate_info.multi_key_conn_req, true); + assert_eq!(requester.common.negotiate_info.multi_key_conn_rsp, true); + }; + executor::block_on(future); +} + +#[test] +fn test_case2_send_receive_spdm_algorithm() { + let future = async { + let (rsp_config_info, rsp_provision_info) = create_info(); + let (req_config_info, req_provision_info) = create_info(); + + let shared_buffer = SharedBuffer::new(); + let device_io_responder = Arc::new(Mutex::new(FakeSpdmDeviceIoReceve::new(Arc::new( + shared_buffer, + )))); + let pcidoe_transport_encap = Arc::new(Mutex::new(PciDoeTransportEncap {})); + + secret::asym_sign::register(SECRET_ASYM_IMPL_INSTANCE.clone()); + + let mut responder = responder::ResponderContext::new( + device_io_responder, + pcidoe_transport_encap, + rsp_config_info, + rsp_provision_info, + ); + responder + .common + .runtime_info + .set_connection_state(SpdmConnectionState::SpdmConnectionAfterCapabilities); + + responder.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion13; + responder + .common + .negotiate_info + .rsp_capabilities_sel + .insert(SpdmResponseCapabilityFlags::MULTI_KEY_CAP_CONN_SEL); + responder + .common + .config_info + .other_params_support + .remove(SpdmAlgoOtherParams::MULTI_KEY_CONN); + responder + .common + .config_info + .rsp_capabilities + .remove(SpdmResponseCapabilityFlags::MULTI_KEY_CAP_ONLY); + responder + .common + .config_info + .rsp_capabilities + .insert(SpdmResponseCapabilityFlags::MULTI_KEY_CAP_CONN_SEL); + + let pcidoe_transport_encap2 = Arc::new(Mutex::new(PciDoeTransportEncap {})); + let shared_buffer = SharedBuffer::new(); + let device_io_requester = Arc::new(Mutex::new(FakeSpdmDeviceIo::new( + Arc::new(shared_buffer), + Arc::new(Mutex::new(responder)), + ))); + + let mut requester = RequesterContext::new( + device_io_requester, + pcidoe_transport_encap2, + req_config_info, + req_provision_info, + ); + + requester.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion13; + requester + .common + .negotiate_info + .rsp_capabilities_sel + .insert(SpdmResponseCapabilityFlags::MULTI_KEY_CAP_CONN_SEL); + requester + .common + .config_info + .other_params_support + .remove(SpdmAlgoOtherParams::MULTI_KEY_CONN); + requester + .common + .config_info + .req_capabilities + .remove(SpdmRequestCapabilityFlags::MULTI_KEY_CAP_ONLY); + requester + .common + .config_info + .req_capabilities + .insert(SpdmRequestCapabilityFlags::MULTI_KEY_CAP_CONN_SEL); + + let status = requester.send_receive_spdm_algorithm().await.is_ok(); + assert!(status); + assert_eq!(requester.common.negotiate_info.multi_key_conn_req, false); + assert_eq!(requester.common.negotiate_info.multi_key_conn_rsp, false); + }; + executor::block_on(future); +} diff --git a/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs b/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs index 2332c3e..c3715f8 100644 --- a/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs @@ -37,7 +37,18 @@ fn test_case0_handle_spdm_algorithm() { provision_info, ); - context.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion11; + context.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion13; + context + .common + .negotiate_info + .req_capabilities_sel + .insert(SpdmRequestCapabilityFlags::MULTI_KEY_CAP_CONN_SEL); + context + .common + .config_info + .other_params_support + .remove(SpdmAlgoOtherParams::MULTI_KEY_CONN); + context .common .runtime_info @@ -46,7 +57,7 @@ fn test_case0_handle_spdm_algorithm() { let spdm_message_header = &mut [0u8; 1024]; let mut writer = Writer::init(spdm_message_header); let value = SpdmMessageHeader { - version: SpdmVersion::SpdmVersion11, + version: SpdmVersion::SpdmVersion13, request_response_code: SpdmRequestResponseCode::SpdmRequestNegotiateAlgorithms, }; assert!(value.encode(&mut writer).is_ok()); @@ -55,7 +66,8 @@ fn test_case0_handle_spdm_algorithm() { let mut writer = Writer::init(negotiate_algorithms); let value = SpdmNegotiateAlgorithmsRequestPayload { measurement_specification: SpdmMeasurementSpecification::DMTF, - other_params_support: SpdmAlgoOtherParams::empty(), + other_params_support: SpdmAlgoOtherParams::OPAQUE_DATA_FMT1 + | SpdmAlgoOtherParams::MULTI_KEY_CONN, base_asym_algo: SpdmBaseAsymAlgo::TPM_ALG_ECDSA_ECC_NIST_P384, base_hash_algo: SpdmBaseHashAlgo::TPM_ALG_SHA_384, alg_struct_count: 4, @@ -100,7 +112,7 @@ fn test_case0_handle_spdm_algorithm() { let mut reader = Reader::init(u8_slice); let spdm_message_header = SpdmMessageHeader::read(&mut reader).unwrap(); - assert_eq!(spdm_message_header.version, SpdmVersion::SpdmVersion11); + assert_eq!(spdm_message_header.version, SpdmVersion::SpdmVersion13); assert_eq!( spdm_message_header.request_response_code, SpdmRequestResponseCode::SpdmRequestNegotiateAlgorithms @@ -116,6 +128,18 @@ fn test_case0_handle_spdm_algorithm() { spdm_sturct_data.measurement_specification, SpdmMeasurementSpecification::DMTF ); + assert_eq!( + spdm_sturct_data + .other_params_support + .contains(SpdmAlgoOtherParams::MULTI_KEY_CONN), + true + ); + assert_eq!( + spdm_sturct_data + .other_params_support + .contains(SpdmAlgoOtherParams::OPAQUE_DATA_FMT1), + true + ); assert_eq!( spdm_sturct_data.base_asym_algo, SpdmBaseAsymAlgo::TPM_ALG_ECDSA_ECC_NIST_P384 @@ -164,7 +188,7 @@ fn test_case0_handle_spdm_algorithm() { let spdm_message: SpdmMessage = SpdmMessage::spdm_read(&mut context.common, &mut reader).unwrap(); - assert_eq!(spdm_message.header.version, SpdmVersion::SpdmVersion11); + assert_eq!(spdm_message.header.version, SpdmVersion::SpdmVersion13); assert_eq!( spdm_message.header.request_response_code, SpdmRequestResponseCode::SpdmResponseAlgorithms @@ -174,6 +198,20 @@ fn test_case0_handle_spdm_algorithm() { payload.measurement_specification_sel, SpdmMeasurementSpecification::DMTF ); + assert_eq!( + payload + .other_params_selection + .contains(SpdmAlgoOtherParams::MULTI_KEY_CONN), + false + ); + assert_eq!( + payload + .other_params_selection + .contains(SpdmAlgoOtherParams::OPAQUE_DATA_FMT1), + true + ); + assert_eq!(context.common.negotiate_info.multi_key_conn_req, false); + assert_eq!(context.common.negotiate_info.multi_key_conn_rsp, true); assert_eq!( payload.measurement_hash_algo, SpdmMeasurementHashAlgo::TPM_ALG_SHA_384