diff --git a/codec/src/codec.rs b/codec/src/codec.rs index 3f54e559..c3429ed9 100644 --- a/codec/src/codec.rs +++ b/codec/src/codec.rs @@ -65,6 +65,10 @@ impl<'a> Writer<'a> { } } + pub fn clear(&mut self) { + self.offs = 0; + } + pub fn extend_from_slice(&mut self, value: &[u8]) -> Option { if self.left() < value.len() { return None; diff --git a/fuzz-target/responder/algorithm_rsp/Cargo.toml b/fuzz-target/responder/algorithm_rsp/Cargo.toml index cc03fdd9..044b8e7d 100644 --- a/fuzz-target/responder/algorithm_rsp/Cargo.toml +++ b/fuzz-target/responder/algorithm_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/algorithm_rsp/src/main.rs b/fuzz-target/responder/algorithm_rsp/src/main.rs index caaacddb..be07aceb 100644 --- a/fuzz-target/responder/algorithm_rsp/src/main.rs +++ b/fuzz-target/responder/algorithm_rsp/src/main.rs @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 +use fuzzlib::config::MAX_SPDM_MSG_SIZE; use fuzzlib::{spdmlib::protocol::SpdmVersion, *}; use spdmlib::common::SpdmConnectionState; use spin::Mutex; @@ -33,7 +34,10 @@ async fn fuzz_handle_spdm_algorithm(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionAfterCapabilities); - context.handle_spdm_algorithm(&data).await.unwrap(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_algorithm(&data, &mut writer); + assert!(status.is_ok()); } #[cfg(not(feature = "use_libfuzzer"))] diff --git a/fuzz-target/responder/capability_rsp/Cargo.toml b/fuzz-target/responder/capability_rsp/Cargo.toml index d267df07..7e4ef776 100644 --- a/fuzz-target/responder/capability_rsp/Cargo.toml +++ b/fuzz-target/responder/capability_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/capability_rsp/src/main.rs b/fuzz-target/responder/capability_rsp/src/main.rs index 24765355..0c947d44 100644 --- a/fuzz-target/responder/capability_rsp/src/main.rs +++ b/fuzz-target/responder/capability_rsp/src/main.rs @@ -33,7 +33,10 @@ async fn fuzz_handle_spdm_capability(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionAfterVersion); - context.handle_spdm_capability(&data).await.unwrap(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_capability(&data, &mut writer); + assert!(status.is_ok()); } #[cfg(not(feature = "use_libfuzzer"))] diff --git a/fuzz-target/responder/certificate_rsp/Cargo.toml b/fuzz-target/responder/certificate_rsp/Cargo.toml index 6543432e..bc27fda9 100644 --- a/fuzz-target/responder/certificate_rsp/Cargo.toml +++ b/fuzz-target/responder/certificate_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/certificate_rsp/src/main.rs b/fuzz-target/responder/certificate_rsp/src/main.rs index 3e33a530..23b46a87 100644 --- a/fuzz-target/responder/certificate_rsp/src/main.rs +++ b/fuzz-target/responder/certificate_rsp/src/main.rs @@ -54,7 +54,10 @@ async fn fuzz_handle_spdm_certificate(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_certificate(&data, None).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_certificate(&data, None, &mut writer); + assert!(status.is_ok()); } // TCD: // - id: 0 @@ -103,10 +106,11 @@ async fn fuzz_handle_spdm_certificate(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context - .handle_spdm_certificate(&data, Some(4294836221)) - .await - .is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = + context.handle_spdm_certificate(&data, Some(4294836221), &mut writer); + assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/challenge_rsp/Cargo.toml b/fuzz-target/responder/challenge_rsp/Cargo.toml index 86cb64c6..07a04a8d 100644 --- a/fuzz-target/responder/challenge_rsp/Cargo.toml +++ b/fuzz-target/responder/challenge_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/challenge_rsp/src/main.rs b/fuzz-target/responder/challenge_rsp/src/main.rs index 27f30148..957a10d7 100644 --- a/fuzz-target/responder/challenge_rsp/src/main.rs +++ b/fuzz-target/responder/challenge_rsp/src/main.rs @@ -53,7 +53,10 @@ async fn fuzz_handle_spdm_challenge(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_challenge(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_challenge(&data, &mut writer); + assert!(status.is_ok()); } // TCD: // - id: 0 @@ -96,7 +99,10 @@ async fn fuzz_handle_spdm_challenge(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_challenge(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_challenge(&data, &mut writer); + assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/deliver_encapsulated_response_certificate_rsp/Cargo.toml b/fuzz-target/responder/deliver_encapsulated_response_certificate_rsp/Cargo.toml index 3516239d..e137dcf6 100644 --- a/fuzz-target/responder/deliver_encapsulated_response_certificate_rsp/Cargo.toml +++ b/fuzz-target/responder/deliver_encapsulated_response_certificate_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data", "mut-auth"] diff --git a/fuzz-target/responder/deliver_encapsulated_response_digest_rsp/Cargo.toml b/fuzz-target/responder/deliver_encapsulated_response_digest_rsp/Cargo.toml index a8c39d4b..72feb3bd 100644 --- a/fuzz-target/responder/deliver_encapsulated_response_digest_rsp/Cargo.toml +++ b/fuzz-target/responder/deliver_encapsulated_response_digest_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data", "mut-auth"] diff --git a/fuzz-target/responder/deliver_encapsulated_response_rsp/Cargo.toml b/fuzz-target/responder/deliver_encapsulated_response_rsp/Cargo.toml index abeff8df..6f247513 100644 --- a/fuzz-target/responder/deliver_encapsulated_response_rsp/Cargo.toml +++ b/fuzz-target/responder/deliver_encapsulated_response_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data", "mut-auth"] diff --git a/fuzz-target/responder/deliver_encapsulated_response_rsp/src/main.rs b/fuzz-target/responder/deliver_encapsulated_response_rsp/src/main.rs index 7e54e293..3664336b 100644 --- a/fuzz-target/responder/deliver_encapsulated_response_rsp/src/main.rs +++ b/fuzz-target/responder/deliver_encapsulated_response_rsp/src/main.rs @@ -52,10 +52,10 @@ async fn fuzz_handle_deliver_encapsulated_reponse(data: Arc>) { context.common.peer_info.peer_cert_chain_temp = Some(SpdmCertChainBuffer::default()); - let _ = context - .handle_deliver_encapsulated_reponse(4294836221, &data) - .await - .is_err(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_deliver_encapsulated_reponse(&data, &mut writer); + // assert!(status.is_ok()); } // TCD: // - id: 0 @@ -94,10 +94,10 @@ async fn fuzz_handle_deliver_encapsulated_reponse(data: Arc>) { context.common.peer_info.peer_cert_chain_temp = Some(SpdmCertChainBuffer::default()); - let _ = context - .handle_deliver_encapsulated_reponse(4294836221, &data) - .await - .is_err(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_deliver_encapsulated_reponse(&data, &mut writer); + // assert!(status.is_ok()); } // TCD: // - id: 0 @@ -134,10 +134,11 @@ async fn fuzz_handle_deliver_encapsulated_reponse(data: Arc>) { context.common.peer_info.peer_cert_chain_temp = Some(SpdmCertChainBuffer::default()); - let _ = context - .handle_deliver_encapsulated_reponse(4294836221, &data) - .await - .is_err(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_deliver_encapsulated_reponse(&data, &mut writer); + + // assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/digest_rsp/Cargo.toml b/fuzz-target/responder/digest_rsp/Cargo.toml index cb7adcc6..196c04a7 100644 --- a/fuzz-target/responder/digest_rsp/Cargo.toml +++ b/fuzz-target/responder/digest_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/digest_rsp/src/main.rs b/fuzz-target/responder/digest_rsp/src/main.rs index 56b3ded8..98874a2c 100644 --- a/fuzz-target/responder/digest_rsp/src/main.rs +++ b/fuzz-target/responder/digest_rsp/src/main.rs @@ -55,7 +55,10 @@ async fn fuzz_handle_spdm_digest(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_digest(&data, None).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_digest(&data, None, &mut writer); + assert!(status.is_ok()); } // TCD: // - id: 0 @@ -107,10 +110,11 @@ async fn fuzz_handle_spdm_digest(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context - .handle_spdm_digest(&data, Some(4294836221)) - .await - .is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = + context.handle_spdm_digest(&data, Some(4294836221), &mut writer); + assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/end_session_rsp/Cargo.toml b/fuzz-target/responder/end_session_rsp/Cargo.toml index 286cda75..f94e6eac 100644 --- a/fuzz-target/responder/end_session_rsp/Cargo.toml +++ b/fuzz-target/responder/end_session_rsp/Cargo.toml @@ -13,6 +13,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/end_session_rsp/src/main.rs b/fuzz-target/responder/end_session_rsp/src/main.rs index b4acd480..61ae73b8 100644 --- a/fuzz-target/responder/end_session_rsp/src/main.rs +++ b/fuzz-target/responder/end_session_rsp/src/main.rs @@ -42,7 +42,10 @@ async fn fuzz_handle_spdm_end_session(data: Arc>) { SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE, ); - context.handle_spdm_end_session(4294901758, &data).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_end_session(4294901758, &data, &mut writer); + assert!(status.is_ok()); } #[cfg(not(feature = "use_libfuzzer"))] diff --git a/fuzz-target/responder/finish_rsp/Cargo.toml b/fuzz-target/responder/finish_rsp/Cargo.toml index 0d589e5e..3fa4915b 100644 --- a/fuzz-target/responder/finish_rsp/Cargo.toml +++ b/fuzz-target/responder/finish_rsp/Cargo.toml @@ -13,6 +13,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/finish_rsp/src/main.rs b/fuzz-target/responder/finish_rsp/src/main.rs index 1c5a7933..b9ac58da 100644 --- a/fuzz-target/responder/finish_rsp/src/main.rs +++ b/fuzz-target/responder/finish_rsp/src/main.rs @@ -83,7 +83,11 @@ async fn fuzz_handle_spdm_finish(data: Arc>) { .common .runtime_info .set_last_session_id(Some(4294836221)); - let _ = context.handle_spdm_finish(4294836221, &data).await.is_ok(); + + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294836221, &data, &mut writer); + // assert!(status.is_ok()); } // TCD: // - id: 0 @@ -148,7 +152,11 @@ async fn fuzz_handle_spdm_finish(data: Arc>) { .common .runtime_info .set_last_session_id(Some(4294836221)); - let _ = context.handle_spdm_finish(4294836221, &data).await.is_ok(); + + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294836221, &data, &mut writer); + // assert!(status.is_ok()); } // TCD: // - id: 0 @@ -212,7 +220,11 @@ async fn fuzz_handle_spdm_finish(data: Arc>) { .common .runtime_info .set_last_session_id(Some(4294836221)); - let _ = context.handle_spdm_finish(4294836221, &data).await.is_ok(); + + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294836221, &data, &mut writer); + // assert!(status.is_ok()); } // TCD: // - id: 0 @@ -282,7 +294,11 @@ async fn fuzz_handle_spdm_finish(data: Arc>) { .common .runtime_info .set_last_session_id(Some(4294836221)); - let _ = context.handle_spdm_finish(4294836221, &data).await.is_ok(); + + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294836221, &data, &mut writer); + // assert!(status.is_ok()); } // TCD: // - id: 0 @@ -351,7 +367,11 @@ async fn fuzz_handle_spdm_finish(data: Arc>) { .common .runtime_info .set_last_session_id(Some(4294836221)); - let _ = context.handle_spdm_finish(4294836221, &data).await.is_ok(); + + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294836221, &data, &mut writer); + // assert!(status.is_ok()); } } fn main() { diff --git a/fuzz-target/responder/get_encapsulated_request_rsp/Cargo.toml b/fuzz-target/responder/get_encapsulated_request_rsp/Cargo.toml index f5d0b852..71c6abe8 100644 --- a/fuzz-target/responder/get_encapsulated_request_rsp/Cargo.toml +++ b/fuzz-target/responder/get_encapsulated_request_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data", "mut-auth"] diff --git a/fuzz-target/responder/get_encapsulated_request_rsp/src/main.rs b/fuzz-target/responder/get_encapsulated_request_rsp/src/main.rs index f4f097fc..885d0bc0 100644 --- a/fuzz-target/responder/get_encapsulated_request_rsp/src/main.rs +++ b/fuzz-target/responder/get_encapsulated_request_rsp/src/main.rs @@ -51,10 +51,10 @@ async fn fuzz_handle_get_encapsulated_request(data: Arc>) { context.common.peer_info.peer_cert_chain_temp = Some(SpdmCertChainBuffer::default()); - let _ = context - .handle_get_encapsulated_request(4294836221, &data) - .await - .is_err(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_get_encapsulated_request(&data, &mut writer); + // assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/heartbeat_rsp/Cargo.toml b/fuzz-target/responder/heartbeat_rsp/Cargo.toml index 4e0230fc..1a78bdd9 100644 --- a/fuzz-target/responder/heartbeat_rsp/Cargo.toml +++ b/fuzz-target/responder/heartbeat_rsp/Cargo.toml @@ -13,6 +13,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/heartbeat_rsp/src/main.rs b/fuzz-target/responder/heartbeat_rsp/src/main.rs index 0ab6df02..968d55ab 100644 --- a/fuzz-target/responder/heartbeat_rsp/src/main.rs +++ b/fuzz-target/responder/heartbeat_rsp/src/main.rs @@ -42,7 +42,10 @@ async fn fuzz_handle_spdm_heartbeat(data: Arc>) { SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE, ); - context.handle_spdm_heartbeat(4294901758, &data).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_heartbeat(4294901758, &data, &mut writer); + assert!(status.is_ok()); } #[cfg(not(feature = "use_libfuzzer"))] diff --git a/fuzz-target/responder/key_update_rsp/Cargo.toml b/fuzz-target/responder/key_update_rsp/Cargo.toml index 51e77d46..ddded127 100644 --- a/fuzz-target/responder/key_update_rsp/Cargo.toml +++ b/fuzz-target/responder/key_update_rsp/Cargo.toml @@ -13,6 +13,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/key_update_rsp/src/main.rs b/fuzz-target/responder/key_update_rsp/src/main.rs index 0bb3f8a6..16675a08 100644 --- a/fuzz-target/responder/key_update_rsp/src/main.rs +++ b/fuzz-target/responder/key_update_rsp/src/main.rs @@ -42,7 +42,10 @@ async fn fuzz_handle_spdm_key_update(data: Arc>) { SpdmKeyScheduleAlgo::SPDM_KEY_SCHEDULE, ); - context.handle_spdm_key_update(4294901758, &data).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_update(4294901758, &data, &mut writer); + assert!(status.is_ok()); } #[cfg(not(feature = "use_libfuzzer"))] diff --git a/fuzz-target/responder/keyexchange_rsp/Cargo.toml b/fuzz-target/responder/keyexchange_rsp/Cargo.toml index c8553798..71a684b2 100644 --- a/fuzz-target/responder/keyexchange_rsp/Cargo.toml +++ b/fuzz-target/responder/keyexchange_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/keyexchange_rsp/src/main.rs b/fuzz-target/responder/keyexchange_rsp/src/main.rs index 494a1b67..81c89988 100644 --- a/fuzz-target/responder/keyexchange_rsp/src/main.rs +++ b/fuzz-target/responder/keyexchange_rsp/src/main.rs @@ -34,7 +34,7 @@ async fn fuzz_handle_spdm_key_exchange(data: Arc>) { config_info, provision_info, ); - context.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion12; + context.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion11; context.common.negotiate_info.opaque_data_support = SpdmOpaqueSupport::OPAQUE_DATA_FMT1; context.common.negotiate_info.base_hash_sel = SpdmBaseHashAlgo::TPM_ALG_SHA_384; context.common.negotiate_info.base_asym_sel = SpdmBaseAsymAlgo::TPM_ALG_ECDSA_ECC_NIST_P384; @@ -59,7 +59,9 @@ async fn fuzz_handle_spdm_key_exchange(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_key_exchange(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_exchange(&data, &mut writer); } // TCD: // - id: 0 @@ -110,7 +112,9 @@ async fn fuzz_handle_spdm_key_exchange(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_key_exchange(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_exchange(&data, &mut writer); } // TCD: // - id: 0 @@ -132,7 +136,7 @@ async fn fuzz_handle_spdm_key_exchange(data: Arc>) { config_info, provision_info, ); - context.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion12; + context.common.negotiate_info.spdm_version_sel = SpdmVersion::SpdmVersion11; context.common.negotiate_info.opaque_data_support = SpdmOpaqueSupport::OPAQUE_DATA_FMT1; context.common.negotiate_info.base_hash_sel = SpdmBaseHashAlgo::TPM_ALG_SHA_384; context.common.negotiate_info.base_asym_sel = SpdmBaseAsymAlgo::TPM_ALG_ECDSA_ECC_NIST_P384; @@ -160,7 +164,9 @@ async fn fuzz_handle_spdm_key_exchange(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_key_exchange(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_exchange(&data, &mut writer); } } diff --git a/fuzz-target/responder/measurement_rsp/Cargo.toml b/fuzz-target/responder/measurement_rsp/Cargo.toml index 1e32f19b..04f4a0de 100644 --- a/fuzz-target/responder/measurement_rsp/Cargo.toml +++ b/fuzz-target/responder/measurement_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/measurement_rsp/src/main.rs b/fuzz-target/responder/measurement_rsp/src/main.rs index 1958fb50..9df94cd0 100644 --- a/fuzz-target/responder/measurement_rsp/src/main.rs +++ b/fuzz-target/responder/measurement_rsp/src/main.rs @@ -58,7 +58,10 @@ async fn fuzz_handle_spdm_measurement(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - context.handle_spdm_measurement(None, &data).await.unwrap(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_measurement(None, &data, &mut writer); + assert!(status.is_ok()); } // TCD: // - id: 0 @@ -111,9 +114,11 @@ async fn fuzz_handle_spdm_measurement(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - context - .handle_spdm_measurement(Some(4294836221), &data) - .await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = + context.handle_spdm_measurement(Some(4294836221), &data, &mut writer); + assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/psk_finish_rsp/Cargo.toml b/fuzz-target/responder/psk_finish_rsp/Cargo.toml index e49dea10..cd28ed13 100644 --- a/fuzz-target/responder/psk_finish_rsp/Cargo.toml +++ b/fuzz-target/responder/psk_finish_rsp/Cargo.toml @@ -13,6 +13,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/psk_finish_rsp/src/main.rs b/fuzz-target/responder/psk_finish_rsp/src/main.rs index 9eebcbde..6dee7c70 100644 --- a/fuzz-target/responder/psk_finish_rsp/src/main.rs +++ b/fuzz-target/responder/psk_finish_rsp/src/main.rs @@ -59,7 +59,10 @@ async fn fuzz_handle_spdm_psk_finish(data: Arc>) { spdmlib::crypto::hash::hash_ctx_init(SpdmBaseHashAlgo::TPM_ALG_SHA_384); } - context.handle_spdm_psk_finish(4294836221, &data).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_finish(4294836221, &data, &mut writer); + //assert!(status.is_ok()); } // TCD: // - id: 0 @@ -107,7 +110,10 @@ async fn fuzz_handle_spdm_psk_finish(data: Arc>) { spdmlib::crypto::hash::hash_ctx_init(SpdmBaseHashAlgo::TPM_ALG_SHA_384); } - context.handle_spdm_psk_finish(4294836221, &data).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_finish(4294836221, &data, &mut writer); + //assert!(status.is_ok()); } // TCD: // - id: 0 @@ -148,8 +154,10 @@ async fn fuzz_handle_spdm_psk_finish(data: Arc>) { context.common.session[0].runtime_info.digest_context_th = spdmlib::crypto::hash::hash_ctx_init(SpdmBaseHashAlgo::TPM_ALG_SHA_384); } - - context.handle_spdm_psk_finish(4294836221, &data).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_finish(4294836221, &data, &mut writer); + //assert!(status.is_ok()); } } diff --git a/fuzz-target/responder/pskexchange_rsp/Cargo.toml b/fuzz-target/responder/pskexchange_rsp/Cargo.toml index 139645a9..fdc4b5e4 100644 --- a/fuzz-target/responder/pskexchange_rsp/Cargo.toml +++ b/fuzz-target/responder/pskexchange_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/pskexchange_rsp/src/main.rs b/fuzz-target/responder/pskexchange_rsp/src/main.rs index 85085f47..779699a7 100644 --- a/fuzz-target/responder/pskexchange_rsp/src/main.rs +++ b/fuzz-target/responder/pskexchange_rsp/src/main.rs @@ -55,7 +55,9 @@ async fn fuzz_handle_spdm_psk_exchange(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_psk_exchange(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_exchange(&data, &mut writer); } // TCD: @@ -96,7 +98,9 @@ async fn fuzz_handle_spdm_psk_exchange(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_psk_exchange(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_exchange(&data, &mut writer); } // TCD: @@ -141,7 +145,10 @@ async fn fuzz_handle_spdm_psk_exchange(data: Arc>) { context.common.session[i] = SpdmSession::new(); context.common.session[i].setup(4294836221).unwrap(); } - let _ = context.handle_spdm_psk_exchange(&data).await.is_ok(); + + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_exchange(&data, &mut writer); } // TCD: // - id: 0 @@ -182,7 +189,9 @@ async fn fuzz_handle_spdm_psk_exchange(data: Arc>) { .runtime_info .set_connection_state(SpdmConnectionState::SpdmConnectionNegotiated); - let _ = context.handle_spdm_psk_exchange(&data).await.is_ok(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_exchange(&data, &mut writer); } } fn main() { diff --git a/fuzz-target/responder/vendor_rsp/Cargo.toml b/fuzz-target/responder/vendor_rsp/Cargo.toml index cb780a31..a05c5b6d 100644 --- a/fuzz-target/responder/vendor_rsp/Cargo.toml +++ b/fuzz-target/responder/vendor_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] default = ["hashed-transcript-data"] diff --git a/fuzz-target/responder/vendor_rsp/src/main.rs b/fuzz-target/responder/vendor_rsp/src/main.rs index a404b6ef..f0d45e16 100644 --- a/fuzz-target/responder/vendor_rsp/src/main.rs +++ b/fuzz-target/responder/vendor_rsp/src/main.rs @@ -70,10 +70,11 @@ async fn fuzz_handle_spdm_vendor_defined_request(data: Arc>) { vendor_defined_request_handler: vendor_defined_func, }); - context - .handle_spdm_vendor_defined_request(None, &data) - .await - .unwrap(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = + context.handle_spdm_vendor_defined_request(None, &data, &mut writer); + assert!(status.is_ok()); } #[cfg(not(feature = "use_libfuzzer"))] diff --git a/fuzz-target/responder/version_rsp/Cargo.toml b/fuzz-target/responder/version_rsp/Cargo.toml index 21c17b0a..9c26f51a 100644 --- a/fuzz-target/responder/version_rsp/Cargo.toml +++ b/fuzz-target/responder/version_rsp/Cargo.toml @@ -14,6 +14,7 @@ async-trait = "0.1.71" async-recursion = "1.0.4" spin = { version = "0.9.8" } executor = { path = "../../../executor" } +codec = {path= "../../../codec"} [features] fuzzlogfile = [] diff --git a/fuzz-target/responder/version_rsp/src/main.rs b/fuzz-target/responder/version_rsp/src/main.rs index d71b8416..2e907294 100644 --- a/fuzz-target/responder/version_rsp/src/main.rs +++ b/fuzz-target/responder/version_rsp/src/main.rs @@ -27,7 +27,16 @@ async fn fuzz_handle_spdm_version(data: Arc>) { provision_info, ); - context.handle_spdm_version(&data).await.unwrap(); + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = codec::Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_version(&data, &mut writer); + assert!(status.is_ok()); + assert!(send_buffer.is_some()); + assert!(context + .send_message(None, send_buffer.unwrap(), false) + .await + .is_ok()); + let mut req_buf = [0u8; 1024]; let mut socket_io_transport = socket_io_transport.lock(); let socket_io_transport = socket_io_transport.deref_mut(); diff --git a/spdmlib/src/responder/algorithm_rsp.rs b/spdmlib/src/responder/algorithm_rsp.rs index e4254cdc..446f97b2 100644 --- a/spdmlib/src/responder/algorithm_rsp.rs +++ b/spdmlib/src/responder/algorithm_rsp.rs @@ -10,11 +10,14 @@ use crate::protocol::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_algorithm(&mut self, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_algorithm(bytes, &mut writer); - self.send_message(None, writer.used_slice(), false).await + pub fn handle_spdm_algorithm<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_algorithm(bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_algorithm(&mut self, bytes: &[u8], writer: &mut Writer) { diff --git a/spdmlib/src/responder/app_message_handler.rs b/spdmlib/src/responder/app_message_handler.rs index 9c8310a2..967bfae4 100644 --- a/spdmlib/src/responder/app_message_handler.rs +++ b/spdmlib/src/responder/app_message_handler.rs @@ -2,22 +2,23 @@ // // SPDX-License-Identifier: Apache-2.0 +use codec::Writer; use conquer_once::spin::OnceCell; -use crate::config::MAX_SPDM_MSG_SIZE; use crate::error::SpdmResult; use crate::responder::ResponderContext; -type SpdmAppMessageCbRes = ([u8; MAX_SPDM_MSG_SIZE], usize); +type DispatchSecuredAppMessageCbType = for<'a> fn( + &mut ResponderContext, + u32, + &[u8], + &[u8], + &'a mut Writer, +) -> (SpdmResult, Option<&'a [u8]>); #[derive(Clone)] pub struct SpdmAppMessageHandler { - pub dispatch_secured_app_message_cb: fn( - ctx: &mut ResponderContext, - session_id: u32, - app_buffer: &[u8], - auxiliary_app_data: &[u8], - ) -> SpdmResult, + pub dispatch_secured_app_message_cb: DispatchSecuredAppMessageCbType, } static SPDM_APP_MESSAGE_HANDLER: OnceCell = OnceCell::uninit(); @@ -26,8 +27,9 @@ static DEFAULT: SpdmAppMessageHandler = SpdmAppMessageHandler { dispatch_secured_app_message_cb: |_ctx: &mut ResponderContext, _session_id: u32, _app_buffer: &[u8], - _auxiliary_app_data: &[u8]| - -> SpdmResult { unimplemented!() }, + _auxiliary_app_data: &[u8], + _writer: &mut Writer| + -> (SpdmResult, Option<&[u8]>) { unimplemented!() }, }; #[allow(dead_code)] @@ -35,14 +37,17 @@ pub fn register(context: SpdmAppMessageHandler) -> bool { SPDM_APP_MESSAGE_HANDLER.try_init_once(|| context).is_ok() } -pub fn dispatch_secured_app_message_cb( +pub fn dispatch_secured_app_message_cb<'a>( ctx: &mut ResponderContext, session_id: u32, app_buffer: &[u8], auxiliary_app_data: &[u8], -) -> SpdmResult { + writer: &'a mut Writer, +) -> (SpdmResult, Option<&'a [u8]>) { (SPDM_APP_MESSAGE_HANDLER .try_get_or_init(|| DEFAULT.clone()) .unwrap_or(&DEFAULT) - .dispatch_secured_app_message_cb)(ctx, session_id, app_buffer, auxiliary_app_data) + .dispatch_secured_app_message_cb)( + ctx, session_id, app_buffer, auxiliary_app_data, writer + ) } diff --git a/spdmlib/src/responder/capability_rsp.rs b/spdmlib/src/responder/capability_rsp.rs index c4aba2a2..07691df8 100644 --- a/spdmlib/src/responder/capability_rsp.rs +++ b/spdmlib/src/responder/capability_rsp.rs @@ -10,11 +10,14 @@ use crate::protocol::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_capability(&mut self, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_capability_response(bytes, &mut writer); - self.send_message(None, writer.used_slice(), false).await + pub fn handle_spdm_capability<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_capability_response(bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_capability_response(&mut self, bytes: &[u8], writer: &mut Writer) { diff --git a/spdmlib/src/responder/certificate_rsp.rs b/spdmlib/src/responder/certificate_rsp.rs index 484b28f4..77641436 100644 --- a/spdmlib/src/responder/certificate_rsp.rs +++ b/spdmlib/src/responder/certificate_rsp.rs @@ -10,17 +10,15 @@ use crate::protocol::SPDM_MAX_SLOT_NUMBER; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_certificate( + pub fn handle_spdm_certificate<'a>( &mut self, bytes: &[u8], session_id: Option, - ) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_certificate_response(session_id, bytes, &mut writer); + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_certificate_response(session_id, bytes, writer); - self.send_message(session_id, writer.used_slice(), false) - .await + (Ok(()), Some(writer.used_slice())) } fn write_spdm_certificate_response( diff --git a/spdmlib/src/responder/challenge_rsp.rs b/spdmlib/src/responder/challenge_rsp.rs index c5c7040b..6c7175b7 100644 --- a/spdmlib/src/responder/challenge_rsp.rs +++ b/spdmlib/src/responder/challenge_rsp.rs @@ -11,24 +11,26 @@ use crate::common::SpdmCodec; use crate::common::SpdmConnectionState; use crate::crypto; use crate::error::SpdmResult; -use crate::message::*; -use crate::protocol::*; -use crate::responder::*; -extern crate alloc; #[cfg(feature = "hashed-transcript-data")] use crate::error::SPDM_STATUS_INVALID_STATE_LOCAL; use crate::error::{SPDM_STATUS_BUFFER_FULL, SPDM_STATUS_CRYPTO_ERROR}; +use crate::message::*; +use crate::protocol::*; +use crate::responder::*; use crate::secret; impl ResponderContext { - pub async fn handle_spdm_challenge(&mut self, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_challenge_response(bytes, &mut writer).await; - self.send_message(None, writer.used_slice(), false).await + pub fn handle_spdm_challenge<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_challenge_response(bytes, writer); + + (Ok(()), Some(writer.used_slice())) } - pub async fn write_spdm_challenge_response(&mut self, bytes: &[u8], writer: &mut Writer<'_>) { + pub fn write_spdm_challenge_response(&mut self, bytes: &[u8], writer: &mut Writer<'_>) { if self.common.runtime_info.get_connection_state().get_u8() < SpdmConnectionState::SpdmConnectionNegotiated.get_u8() { @@ -172,8 +174,7 @@ impl ResponderContext { let signature = self.generate_challenge_auth_signature(); if signature.is_err() { - self.send_spdm_error(SpdmErrorCode::SpdmErrorUnspecified, 0) - .await; + self.write_spdm_error(SpdmErrorCode::SpdmErrorUnspecified, 0, writer); return; } let signature = signature.unwrap(); diff --git a/spdmlib/src/responder/context.rs b/spdmlib/src/responder/context.rs index cd7047a8..aba3673b 100644 --- a/spdmlib/src/responder/context.rs +++ b/spdmlib/src/responder/context.rs @@ -5,7 +5,7 @@ use super::app_message_handler::dispatch_secured_app_message_cb; use crate::common::{session::SpdmSessionState, SpdmDeviceIo, SpdmTransportEncap}; use crate::common::{SpdmConnectionState, ST1}; -use crate::config::{self, RECEIVER_BUFFER_SIZE}; +use crate::config::{self, MAX_SPDM_MSG_SIZE, RECEIVER_BUFFER_SIZE}; use crate::error::{SpdmResult, SPDM_STATUS_UNSUPPORTED_CAP}; use crate::message::*; use crate::protocol::{SpdmRequestCapabilityFlags, SpdmResponseCapabilityFlags}; @@ -148,6 +148,9 @@ impl ResponderContext { auxiliary_app_data: &[u8], raw_packet: &mut [u8; RECEIVER_BUFFER_SIZE], ) -> Result { + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + match self.receive_message(raw_packet, crypto_request).await { Ok((used, secured_message)) => { if secured_message { @@ -184,25 +187,56 @@ impl ResponderContext { Err(_) => Err(used), Ok((decode_size, is_app_message)) => { if !is_app_message { - Ok(self - .dispatch_secured_message( - session_id, - &spdm_buffer[0..decode_size], - ) - .await) + let (status, send_buffer) = self.dispatch_secured_message( + session_id, + &spdm_buffer[0..decode_size], + &mut writer, + ); + if let Some(send_buffer) = send_buffer { + if let Err(err) = self + .send_message(Some(session_id), send_buffer, false) + .await + { + Ok(Err(err)) + } else { + Ok(status) + } + } else { + Ok(status) + } } else { - Ok(self - .dispatch_secured_app_message( - session_id, - &spdm_buffer[..decode_size], - auxiliary_app_data, - ) - .await) + let (status, send_buffer) = self.dispatch_secured_app_message( + session_id, + &spdm_buffer[..decode_size], + auxiliary_app_data, + &mut writer, + ); + if let Some(send_buffer) = send_buffer { + if let Err(err) = + self.send_message(Some(session_id), send_buffer, true).await + { + Ok(Err(err)) + } else { + Ok(status) + } + } else { + Ok(status) + } } } } } else { - Ok(self.dispatch_message(&raw_packet[0..used]).await) + let (status, send_buffer) = + self.dispatch_message(&raw_packet[0..used], &mut writer); + if let Some(send_buffer) = send_buffer { + if let Err(err) = self.send_message(None, send_buffer, false).await { + Ok(Err(err)) + } else { + Ok(status) + } + } else { + Ok(status) + } } } Err(used) => Err(used), @@ -253,12 +287,17 @@ impl ResponderContext { Ok((used, secured_message)) } - async fn dispatch_secured_message(&mut self, session_id: u32, bytes: &[u8]) -> SpdmResult { + fn dispatch_secured_message<'a>( + &mut self, + session_id: u32, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { let mut reader = Reader::init(bytes); let session = self.common.get_immutable_session_via_id(session_id); if session.is_none() { - return Err(SPDM_STATUS_UNSUPPORTED_CAP); + return (Err(SPDM_STATUS_UNSUPPORTED_CAP), None); } let session = session.unwrap(); @@ -275,32 +314,29 @@ impl ResponderContext { .rsp_capabilities_sel .contains(SpdmResponseCapabilityFlags::HANDSHAKE_IN_THE_CLEAR_CAP); if in_clear_text { - return Err(SPDM_STATUS_UNSUPPORTED_CAP); + return (Err(SPDM_STATUS_UNSUPPORTED_CAP), None); } match SpdmMessageHeader::read(&mut reader) { Some(message_header) => match message_header.request_response_code { #[cfg(feature = "mut-auth")] SpdmRequestResponseCode::SpdmRequestGetEncapsulatedRequest => { - self.handle_get_encapsulated_request(session_id, bytes) - .await + self.handle_get_encapsulated_request(bytes, writer) } #[cfg(feature = "mut-auth")] SpdmRequestResponseCode::SpdmRequestDeliverEncapsulatedResponse => { - self.handle_deliver_encapsulated_reponse(session_id, bytes) - .await + self.handle_deliver_encapsulated_reponse(bytes, writer) } SpdmRequestResponseCode::SpdmRequestFinish => { - self.handle_spdm_finish(session_id, bytes).await + self.handle_spdm_finish(session_id, bytes, writer) } SpdmRequestResponseCode::SpdmRequestPskFinish => { - self.handle_spdm_psk_finish(session_id, bytes).await + self.handle_spdm_psk_finish(session_id, bytes, writer) } SpdmRequestResponseCode::SpdmRequestVendorDefinedRequest => { - self.handle_spdm_vendor_defined_request(Some(session_id), bytes) - .await + self.handle_spdm_vendor_defined_request(Some(session_id), bytes, writer) } SpdmRequestResponseCode::SpdmRequestGetVersion @@ -314,56 +350,51 @@ impl ResponderContext { | SpdmRequestResponseCode::SpdmRequestPskExchange | SpdmRequestResponseCode::SpdmRequestHeartbeat | SpdmRequestResponseCode::SpdmRequestKeyUpdate - | SpdmRequestResponseCode::SpdmRequestEndSession => { - self.handle_error_request( + | SpdmRequestResponseCode::SpdmRequestEndSession => self + .handle_error_request( SpdmErrorCode::SpdmErrorUnexpectedRequest, - Some(session_id), bytes, - ) - .await - } + writer, + ), - SpdmRequestResponseCode::SpdmRequestResponseIfReady => { - self.handle_error_request( + SpdmRequestResponseCode::SpdmRequestResponseIfReady => self + .handle_error_request( SpdmErrorCode::SpdmErrorUnsupportedRequest, - Some(session_id), bytes, - ) - .await - } + writer, + ), - _ => Err(SPDM_STATUS_UNSUPPORTED_CAP), + _ => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), }, - None => Err(SPDM_STATUS_UNSUPPORTED_CAP), + None => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), } } SpdmSessionState::SpdmSessionEstablished => { match SpdmMessageHeader::read(&mut reader) { Some(message_header) => match message_header.request_response_code { SpdmRequestResponseCode::SpdmRequestGetDigests => { - self.handle_spdm_digest(bytes, Some(session_id)).await + self.handle_spdm_digest(bytes, Some(session_id), writer) } SpdmRequestResponseCode::SpdmRequestGetCertificate => { - self.handle_spdm_certificate(bytes, Some(session_id)).await + self.handle_spdm_certificate(bytes, Some(session_id), writer) } SpdmRequestResponseCode::SpdmRequestGetMeasurements => { - self.handle_spdm_measurement(Some(session_id), bytes).await + self.handle_spdm_measurement(Some(session_id), bytes, writer) } SpdmRequestResponseCode::SpdmRequestHeartbeat => { - self.handle_spdm_heartbeat(session_id, bytes).await + self.handle_spdm_heartbeat(session_id, bytes, writer) } SpdmRequestResponseCode::SpdmRequestKeyUpdate => { - self.handle_spdm_key_update(session_id, bytes).await + self.handle_spdm_key_update(session_id, bytes, writer) } SpdmRequestResponseCode::SpdmRequestEndSession => { - self.handle_spdm_end_session(session_id, bytes).await + self.handle_spdm_end_session(session_id, bytes, writer) } SpdmRequestResponseCode::SpdmRequestVendorDefinedRequest => { - self.handle_spdm_vendor_defined_request(Some(session_id), bytes) - .await + self.handle_spdm_vendor_defined_request(Some(session_id), bytes, writer) } SpdmRequestResponseCode::SpdmRequestGetVersion @@ -373,84 +404,82 @@ impl ResponderContext { | SpdmRequestResponseCode::SpdmRequestKeyExchange | SpdmRequestResponseCode::SpdmRequestPskExchange | SpdmRequestResponseCode::SpdmRequestFinish - | SpdmRequestResponseCode::SpdmRequestPskFinish => { - self.handle_error_request( + | SpdmRequestResponseCode::SpdmRequestPskFinish => self + .handle_error_request( SpdmErrorCode::SpdmErrorUnexpectedRequest, - Some(session_id), bytes, - ) - .await - } + writer, + ), - SpdmRequestResponseCode::SpdmRequestResponseIfReady => { - self.handle_error_request( + SpdmRequestResponseCode::SpdmRequestResponseIfReady => self + .handle_error_request( SpdmErrorCode::SpdmErrorUnsupportedRequest, - Some(session_id), bytes, - ) - .await - } + writer, + ), - _ => Err(SPDM_STATUS_UNSUPPORTED_CAP), + _ => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), }, - None => Err(SPDM_STATUS_UNSUPPORTED_CAP), + None => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), } } - SpdmSessionState::SpdmSessionNotStarted => Err(SPDM_STATUS_UNSUPPORTED_CAP), - SpdmSessionState::Unknown(_) => Err(SPDM_STATUS_UNSUPPORTED_CAP), + SpdmSessionState::SpdmSessionNotStarted => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), + SpdmSessionState::Unknown(_) => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), } } - async fn dispatch_secured_app_message( + fn dispatch_secured_app_message<'a>( &mut self, session_id: u32, bytes: &[u8], auxiliary_app_data: &[u8], - ) -> SpdmResult { + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { debug!("dispatching secured app message\n"); - let (rsp_app_buffer, size) = - dispatch_secured_app_message_cb(self, session_id, bytes, auxiliary_app_data).unwrap(); - self.send_message(Some(session_id), &rsp_app_buffer[..size], true) - .await + dispatch_secured_app_message_cb(self, session_id, bytes, auxiliary_app_data, writer) } - pub async fn dispatch_message(&mut self, bytes: &[u8]) -> SpdmResult { + pub fn dispatch_message<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { let mut reader = Reader::init(bytes); match SpdmMessageHeader::read(&mut reader) { Some(message_header) => match message_header.request_response_code { SpdmRequestResponseCode::SpdmRequestGetVersion => { - self.handle_spdm_version(bytes).await + self.handle_spdm_version(bytes, writer) } SpdmRequestResponseCode::SpdmRequestGetCapabilities => { - self.handle_spdm_capability(bytes).await + self.handle_spdm_capability(bytes, writer) } SpdmRequestResponseCode::SpdmRequestNegotiateAlgorithms => { - self.handle_spdm_algorithm(bytes).await + self.handle_spdm_algorithm(bytes, writer) } SpdmRequestResponseCode::SpdmRequestGetDigests => { - self.handle_spdm_digest(bytes, None).await + self.handle_spdm_digest(bytes, None, writer) } SpdmRequestResponseCode::SpdmRequestGetCertificate => { - self.handle_spdm_certificate(bytes, None).await + self.handle_spdm_certificate(bytes, None, writer) } SpdmRequestResponseCode::SpdmRequestChallenge => { - self.handle_spdm_challenge(bytes).await + self.handle_spdm_challenge(bytes, writer) } SpdmRequestResponseCode::SpdmRequestGetMeasurements => { - self.handle_spdm_measurement(None, bytes).await + self.handle_spdm_measurement(None, bytes, writer) } SpdmRequestResponseCode::SpdmRequestKeyExchange => { - self.handle_spdm_key_exchange(bytes).await + self.handle_spdm_key_exchange(bytes, writer) } SpdmRequestResponseCode::SpdmRequestPskExchange => { - self.handle_spdm_psk_exchange(bytes).await + self.handle_spdm_psk_exchange(bytes, writer) } SpdmRequestResponseCode::SpdmRequestVendorDefinedRequest => { - self.handle_spdm_vendor_defined_request(None, bytes).await + self.handle_spdm_vendor_defined_request(None, bytes, writer) } SpdmRequestResponseCode::SpdmRequestFinish => { @@ -472,7 +501,7 @@ impl ResponderContext { if session.get_session_state() == SpdmSessionState::SpdmSessionHandshaking { - return self.handle_spdm_finish(session_id, bytes).await; + return self.handle_spdm_finish(session_id, bytes, writer); } } } @@ -480,36 +509,29 @@ impl ResponderContext { self.handle_error_request( SpdmErrorCode::SpdmErrorUnexpectedRequest, - None, bytes, + writer, ) - .await } SpdmRequestResponseCode::SpdmRequestPskFinish | SpdmRequestResponseCode::SpdmRequestHeartbeat | SpdmRequestResponseCode::SpdmRequestKeyUpdate - | SpdmRequestResponseCode::SpdmRequestEndSession => { - self.handle_error_request( - SpdmErrorCode::SpdmErrorUnexpectedRequest, - None, - bytes, - ) - .await - } - - SpdmRequestResponseCode::SpdmRequestResponseIfReady => { - self.handle_error_request( - SpdmErrorCode::SpdmErrorUnsupportedRequest, - None, - bytes, - ) - .await - } - - _ => Err(SPDM_STATUS_UNSUPPORTED_CAP), + | SpdmRequestResponseCode::SpdmRequestEndSession => self.handle_error_request( + SpdmErrorCode::SpdmErrorUnexpectedRequest, + bytes, + writer, + ), + + SpdmRequestResponseCode::SpdmRequestResponseIfReady => self.handle_error_request( + SpdmErrorCode::SpdmErrorUnsupportedRequest, + bytes, + writer, + ), + + _ => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), }, - None => Err(SPDM_STATUS_UNSUPPORTED_CAP), + None => (Err(SPDM_STATUS_UNSUPPORTED_CAP), None), } } } diff --git a/spdmlib/src/responder/digest_rsp.rs b/spdmlib/src/responder/digest_rsp.rs index ddaab3f8..1b261d83 100644 --- a/spdmlib/src/responder/digest_rsp.rs +++ b/spdmlib/src/responder/digest_rsp.rs @@ -14,17 +14,15 @@ use crate::protocol::gen_array_clone; use alloc::boxed::Box; impl ResponderContext { - pub async fn handle_spdm_digest( + pub fn handle_spdm_digest<'a>( &mut self, bytes: &[u8], session_id: Option, - ) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_digest_response(session_id, bytes, &mut writer); + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_digest_response(session_id, bytes, writer); - self.send_message(session_id, writer.used_slice(), false) - .await + (Ok(()), Some(writer.used_slice())) } fn write_spdm_digest_response( diff --git a/spdmlib/src/responder/encap_rsp.rs b/spdmlib/src/responder/encap_rsp.rs index 2bd31ac6..23eb3eaf 100644 --- a/spdmlib/src/responder/encap_rsp.rs +++ b/spdmlib/src/responder/encap_rsp.rs @@ -6,10 +6,10 @@ use codec::{Codec, Reader, Writer}; use crate::{ common::{SpdmCodec, SpdmConnectionState}, - config, error::{ SpdmResult, SPDM_STATUS_BUFFER_FULL, SPDM_STATUS_INVALID_MSG_FIELD, - SPDM_STATUS_INVALID_MSG_SIZE, SPDM_STATUS_NOT_READY_PEER, SPDM_STATUS_UNSUPPORTED_CAP, + SPDM_STATUS_INVALID_MSG_SIZE, SPDM_STATUS_INVALID_STATE_LOCAL, SPDM_STATUS_NOT_READY_PEER, + SPDM_STATUS_UNSUPPORTED_CAP, }, message::{ SpdmDeliverEncapsulatedResponsePayload, SpdmEncapsulatedRequestPayload, @@ -22,23 +22,20 @@ use crate::{ use super::ResponderContext; impl ResponderContext { - pub async fn handle_get_encapsulated_request( + pub fn handle_get_encapsulated_request<'a>( &mut self, - session_id: u32, bytes: &[u8], - ) -> SpdmResult { - let mut encapsulated_request = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut encapsulated_request); - - self.encap_check_version_cap_state( + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + if let Err(err) = self.encap_check_version_cap_state( SpdmRequestResponseCode::SpdmRequestGetEncapsulatedRequest.get_u8(), - &mut writer, - ) - .await; - self.write_encap_request_response(bytes, &mut writer); - - self.send_message(Some(session_id), writer.used_slice(), false) - .await + writer, + ) { + (Err(err), Some(writer.used_slice())) + } else { + self.write_encap_request_response(bytes, writer); + (Ok(()), Some(writer.used_slice())) + } } fn write_encap_request_response(&mut self, bytes: &[u8], writer: &mut Writer) { @@ -79,23 +76,20 @@ impl ResponderContext { } } - pub async fn handle_deliver_encapsulated_reponse( + pub fn handle_deliver_encapsulated_reponse<'a>( &mut self, - session_id: u32, bytes: &[u8], - ) -> SpdmResult { - let mut encap_response_ack = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut encap_response_ack); - - self.encap_check_version_cap_state( + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + if let Err(err) = self.encap_check_version_cap_state( SpdmRequestResponseCode::SpdmRequestGetEncapsulatedRequest.get_u8(), - &mut writer, - ) - .await; - self.write_encap_response_ack_response(bytes, &mut writer); - - self.send_message(Some(session_id), writer.used_slice(), false) - .await + writer, + ) { + (Err(err), Some(writer.used_slice())) + } else { + self.write_encap_response_ack_response(bytes, writer); + (Ok(()), Some(writer.used_slice())) + } } fn write_encap_response_ack_response(&mut self, bytes: &[u8], writer: &mut Writer) { @@ -127,19 +121,20 @@ impl ResponderContext { } } - async fn encap_check_version_cap_state( + fn encap_check_version_cap_state( &mut self, request_response_code: u8, writer: &mut Writer<'_>, - ) { + ) -> SpdmResult { if self.common.negotiate_info.spdm_version_sel.get_u8() < SpdmVersion::SpdmVersion11.get_u8() { - self.send_spdm_error( + self.write_spdm_error( SpdmErrorCode::SpdmErrorUnsupportedRequest, request_response_code, - ) - .await + writer, + ); + return Err(SPDM_STATUS_INVALID_STATE_LOCAL); } if !self @@ -158,14 +153,17 @@ impl ResponderContext { request_response_code, writer, ); - return; + return Err(SPDM_STATUS_UNSUPPORTED_CAP); } if self.common.runtime_info.get_connection_state().get_u8() < SpdmConnectionState::SpdmConnectionAfterCertificate.get_u8() { self.write_spdm_error(SpdmErrorCode::SpdmErrorUnexpectedRequest, 0, writer); + return Err(SPDM_STATUS_INVALID_STATE_LOCAL); } + + Ok(()) } fn process_encapsulated_response( diff --git a/spdmlib/src/responder/end_session_rsp.rs b/spdmlib/src/responder/end_session_rsp.rs index 653c8217..ed7bea96 100644 --- a/spdmlib/src/responder/end_session_rsp.rs +++ b/spdmlib/src/responder/end_session_rsp.rs @@ -8,12 +8,15 @@ use crate::message::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_end_session(&mut self, session_id: u32, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_end_session_response(session_id, bytes, &mut writer); - self.send_message(Some(session_id), writer.used_slice(), false) - .await + pub fn handle_spdm_end_session<'a>( + &mut self, + session_id: u32, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_end_session_response(session_id, bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_end_session_response( diff --git a/spdmlib/src/responder/error_rsp.rs b/spdmlib/src/responder/error_rsp.rs index 8fdb63b9..7263a9f8 100644 --- a/spdmlib/src/responder/error_rsp.rs +++ b/spdmlib/src/responder/error_rsp.rs @@ -32,31 +32,21 @@ impl ResponderContext { ), }), }; + writer.clear(); let _ = error.spdm_encode(&mut self.common, writer); } - - pub async fn send_spdm_error(&mut self, error_code: SpdmErrorCode, error_data: u8) { - info!("send spdm version\n"); - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_error(error_code, error_data, &mut writer); - let _ = self.send_message(None, writer.used_slice(), false).await; - } } impl ResponderContext { - pub async fn handle_error_request( + pub fn handle_error_request<'a>( &mut self, error_code: SpdmErrorCode, - session_id: Option, bytes: &[u8], - ) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_error_response(error_code, bytes, &mut writer); + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_error_response(error_code, bytes, writer); - self.send_message(session_id, writer.used_slice(), false) - .await + (Ok(()), Some(writer.used_slice())) } pub fn write_error_response( diff --git a/spdmlib/src/responder/finish_rsp.rs b/spdmlib/src/responder/finish_rsp.rs index 469a22af..dece24ed 100644 --- a/spdmlib/src/responder/finish_rsp.rs +++ b/spdmlib/src/responder/finish_rsp.rs @@ -17,28 +17,15 @@ extern crate alloc; use alloc::boxed::Box; impl ResponderContext { - pub async fn handle_spdm_finish(&mut self, session_id: u32, bytes: &[u8]) -> SpdmResult { - let in_clear_text = self - .common - .negotiate_info - .req_capabilities_sel - .contains(SpdmRequestCapabilityFlags::HANDSHAKE_IN_THE_CLEAR_CAP) - && self - .common - .negotiate_info - .rsp_capabilities_sel - .contains(SpdmResponseCapabilityFlags::HANDSHAKE_IN_THE_CLEAR_CAP); - info!("in_clear_text {:?}\n", in_clear_text); + pub fn handle_spdm_finish<'a>( + &mut self, + session_id: u32, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + let r = self.write_spdm_finish_response(session_id, bytes, writer); - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_finish_response(session_id, bytes, &mut writer)?; - if in_clear_text { - self.send_message(None, writer.used_slice(), false).await - } else { - self.send_message(Some(session_id), writer.used_slice(), false) - .await - } + (r, Some(writer.used_slice())) } // Return true on success, false otherwise. diff --git a/spdmlib/src/responder/heartbeat_rsp.rs b/spdmlib/src/responder/heartbeat_rsp.rs index dc5ebbf6..40fa9c83 100644 --- a/spdmlib/src/responder/heartbeat_rsp.rs +++ b/spdmlib/src/responder/heartbeat_rsp.rs @@ -8,12 +8,15 @@ use crate::message::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_heartbeat(&mut self, session_id: u32, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_heartbeat_response(session_id, bytes, &mut writer); - self.send_message(Some(session_id), writer.used_slice(), false) - .await + pub fn handle_spdm_heartbeat<'a>( + &mut self, + session_id: u32, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_heartbeat_response(session_id, bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_heartbeat_response( diff --git a/spdmlib/src/responder/key_exchange_rsp.rs b/spdmlib/src/responder/key_exchange_rsp.rs index ca99a46e..40138cbe 100644 --- a/spdmlib/src/responder/key_exchange_rsp.rs +++ b/spdmlib/src/responder/key_exchange_rsp.rs @@ -24,11 +24,14 @@ use alloc::boxed::Box; use core::ops::DerefMut; impl ResponderContext { - pub async fn handle_spdm_key_exchange(&mut self, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_key_exchange_response(bytes, &mut writer)?; - self.send_message(None, writer.used_slice(), false).await + pub fn handle_spdm_key_exchange<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + let r = self.write_spdm_key_exchange_response(bytes, writer); + + (r, Some(writer.used_slice())) } pub fn write_spdm_key_exchange_response( diff --git a/spdmlib/src/responder/key_update_rsp.rs b/spdmlib/src/responder/key_update_rsp.rs index 364cd1dc..dac872ff 100644 --- a/spdmlib/src/responder/key_update_rsp.rs +++ b/spdmlib/src/responder/key_update_rsp.rs @@ -8,12 +8,15 @@ use crate::message::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_key_update(&mut self, session_id: u32, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_key_update_response(session_id, bytes, &mut writer); - self.send_message(Some(session_id), writer.used_slice(), false) - .await + pub fn handle_spdm_key_update<'a>( + &mut self, + session_id: u32, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_key_update_response(session_id, bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_key_update_response( diff --git a/spdmlib/src/responder/measurement_rsp.rs b/spdmlib/src/responder/measurement_rsp.rs index 450c8034..eeefad4e 100644 --- a/spdmlib/src/responder/measurement_rsp.rs +++ b/spdmlib/src/responder/measurement_rsp.rs @@ -24,20 +24,18 @@ use crate::responder::*; use crate::secret; impl ResponderContext { - pub async fn handle_spdm_measurement( + pub fn handle_spdm_measurement<'a>( &mut self, session_id: Option, bytes: &[u8], - ) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_measurement_response(session_id, bytes, &mut writer) - .await; - self.send_message(session_id, writer.used_slice(), false) - .await + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_measurement_response(session_id, bytes, writer); + + (Ok(()), Some(writer.used_slice())) } - pub async fn write_spdm_measurement_response( + pub fn write_spdm_measurement_response( &mut self, session_id: Option, bytes: &[u8], @@ -233,8 +231,7 @@ impl ResponderContext { let signature = self.generate_measurement_signature(session_id); if signature.is_err() { - self.send_spdm_error(SpdmErrorCode::SpdmErrorUnspecified, 0) - .await; + self.write_spdm_error(SpdmErrorCode::SpdmErrorUnspecified, 0, writer); return; } let signature = signature.unwrap(); diff --git a/spdmlib/src/responder/psk_exchange_rsp.rs b/spdmlib/src/responder/psk_exchange_rsp.rs index 230f31d7..a84ecb08 100644 --- a/spdmlib/src/responder/psk_exchange_rsp.rs +++ b/spdmlib/src/responder/psk_exchange_rsp.rs @@ -24,11 +24,14 @@ use alloc::boxed::Box; use core::ops::DerefMut; impl ResponderContext { - pub async fn handle_spdm_psk_exchange(&mut self, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_psk_exchange_response(bytes, &mut writer)?; - self.send_message(None, writer.used_slice(), false).await + pub fn handle_spdm_psk_exchange<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + let r = self.write_spdm_psk_exchange_response(bytes, writer); + + (r, Some(writer.used_slice())) } pub fn write_spdm_psk_exchange_response( diff --git a/spdmlib/src/responder/psk_finish_rsp.rs b/spdmlib/src/responder/psk_finish_rsp.rs index 1d34b27b..171946d3 100644 --- a/spdmlib/src/responder/psk_finish_rsp.rs +++ b/spdmlib/src/responder/psk_finish_rsp.rs @@ -12,12 +12,15 @@ use crate::message::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_psk_finish(&mut self, session_id: u32, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_psk_finish_response(session_id, bytes, &mut writer)?; - self.send_message(Some(session_id), writer.used_slice(), false) - .await + pub fn handle_spdm_psk_finish<'a>( + &mut self, + session_id: u32, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + let r = self.write_spdm_psk_finish_response(session_id, bytes, writer); + + (r, Some(writer.used_slice())) } // Return true on success, false otherwise diff --git a/spdmlib/src/responder/vendor_rsp.rs b/spdmlib/src/responder/vendor_rsp.rs index 0ce2a43c..18a04cb9 100644 --- a/spdmlib/src/responder/vendor_rsp.rs +++ b/spdmlib/src/responder/vendor_rsp.rs @@ -8,16 +8,15 @@ use crate::message::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_vendor_defined_request( + pub fn handle_spdm_vendor_defined_request<'a>( &mut self, session_id: Option, bytes: &[u8], - ) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_vendor_defined_response(session_id, bytes, &mut writer); - self.send_message(session_id, writer.used_slice(), false) - .await + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_vendor_defined_response(session_id, bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_vendor_defined_response( diff --git a/spdmlib/src/responder/version_rsp.rs b/spdmlib/src/responder/version_rsp.rs index 1d58d7f4..9b737e42 100644 --- a/spdmlib/src/responder/version_rsp.rs +++ b/spdmlib/src/responder/version_rsp.rs @@ -9,11 +9,14 @@ use crate::protocol::*; use crate::responder::*; impl ResponderContext { - pub async fn handle_spdm_version(&mut self, bytes: &[u8]) -> SpdmResult { - let mut send_buffer = [0u8; config::MAX_SPDM_MSG_SIZE]; - let mut writer = Writer::init(&mut send_buffer); - self.write_spdm_version_response(bytes, &mut writer); - self.send_message(None, writer.used_slice(), false).await + pub fn handle_spdm_version<'a>( + &mut self, + bytes: &[u8], + writer: &'a mut Writer, + ) -> (SpdmResult, Option<&'a [u8]>) { + self.write_spdm_version_response(bytes, writer); + + (Ok(()), Some(writer.used_slice())) } pub fn write_spdm_version_response(&mut self, bytes: &[u8], writer: &mut Writer) { diff --git a/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs b/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs index a91f009e..0c104060 100644 --- a/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/algorithm_rsp.rs @@ -9,6 +9,7 @@ use crate::common::util::create_info; use codec::{Codec, Reader, Writer}; use log::debug; use spdmlib::common::*; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -87,7 +88,9 @@ fn test_case0_handle_spdm_algorithm() { bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&negotiate_algorithms[0..1022]); - context.handle_spdm_algorithm(bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.handle_spdm_algorithm(bytes, &mut writer); let data = context.common.runtime_info.message_a.as_ref(); let u8_slice = &mut [0u8; 2048]; diff --git a/test/spdmlib-test/src/responder_tests/capability_rsp.rs b/test/spdmlib-test/src/responder_tests/capability_rsp.rs index fe0470ed..54c92948 100644 --- a/test/spdmlib-test/src/responder_tests/capability_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/capability_rsp.rs @@ -8,6 +8,7 @@ use crate::common::transport::PciDoeTransportEncap; use crate::common::util::create_info; use codec::{Codec, Reader, Writer}; use spdmlib::common::*; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -56,7 +57,10 @@ fn test_case0_handle_spdm_capability() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&capabilities[0..1022]); - context.handle_spdm_capability(bytes).await; + + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.handle_spdm_capability(bytes, &mut writer); let rsp_capabilities = SpdmResponseCapabilityFlags::CERT_CAP | SpdmResponseCapabilityFlags::CHAL_CAP diff --git a/test/spdmlib-test/src/responder_tests/certificate_rsp.rs b/test/spdmlib-test/src/responder_tests/certificate_rsp.rs index f9d5a0ba..49e03bf7 100644 --- a/test/spdmlib-test/src/responder_tests/certificate_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/certificate_rsp.rs @@ -18,6 +18,8 @@ use alloc::sync::Arc; #[test] #[cfg(feature = "hashed-transcript-data")] fn test_case0_handle_spdm_certificate() { + use spdmlib::config::MAX_SPDM_MSG_SIZE; + let future = async { let (config_info, provision_info) = create_info(); let pcidoe_transport_encap = Arc::new(Mutex::new(PciDoeTransportEncap {})); @@ -67,7 +69,10 @@ fn test_case0_handle_spdm_certificate() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&capabilities[0..1022]); - context.handle_spdm_certificate(bytes, None).await; + + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.handle_spdm_certificate(bytes, None, &mut writer); #[cfg(not(feature = "hashed-transcript-data"))] { diff --git a/test/spdmlib-test/src/responder_tests/challenge_rsp.rs b/test/spdmlib-test/src/responder_tests/challenge_rsp.rs index 20449c8d..ac634e05 100644 --- a/test/spdmlib-test/src/responder_tests/challenge_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/challenge_rsp.rs @@ -22,6 +22,8 @@ use alloc::sync::Arc; #[test] #[cfg(feature = "hashed-transcript-data")] fn test_case0_handle_spdm_challenge() { + use spdmlib::config::MAX_SPDM_MSG_SIZE; + let future = async { let (config_info, provision_info) = create_info(); let pcidoe_transport_encap = Arc::new(Mutex::new(PciDoeTransportEncap {})); @@ -82,7 +84,10 @@ fn test_case0_handle_spdm_challenge() { let bytes = &mut [0u8; 4 + SPDM_NONCE_SIZE]; bytes[0..2].copy_from_slice(&spdm_message_header[0..]); bytes[2..4 + SPDM_NONCE_SIZE].copy_from_slice(&challenge[0..2 + SPDM_NONCE_SIZE]); - context.handle_spdm_challenge(bytes).await; + + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.handle_spdm_challenge(bytes, &mut writer); #[cfg(not(feature = "hashed-transcript-data"))] { diff --git a/test/spdmlib-test/src/responder_tests/digest_rsp.rs b/test/spdmlib-test/src/responder_tests/digest_rsp.rs index e83529a2..da5888e2 100644 --- a/test/spdmlib-test/src/responder_tests/digest_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/digest_rsp.rs @@ -17,6 +17,8 @@ use alloc::sync::Arc; #[test] #[cfg(feature = "hashed-transcript-data")] fn test_case0_handle_spdm_digest() { + use spdmlib::config::MAX_SPDM_MSG_SIZE; + let future = async { let (config_info, provision_info) = create_info(); let pcidoe_transport_encap = Arc::new(Mutex::new(PciDoeTransportEncap {})); @@ -57,7 +59,10 @@ fn test_case0_handle_spdm_digest() { assert!(value.encode(&mut writer).is_ok()); let bytes = &mut [0u8; 1024]; - context.handle_spdm_digest(bytes, None).await; + + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.handle_spdm_digest(bytes, None, &mut writer); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/encap_rsp.rs b/test/spdmlib-test/src/responder_tests/encap_rsp.rs index df46b6fe..a6d09b81 100644 --- a/test/spdmlib-test/src/responder_tests/encap_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/encap_rsp.rs @@ -56,8 +56,14 @@ fn test_handle_get_encapsulated_request() { .spdm_encode(&mut context.common, &mut writer) .is_ok()); + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_get_encapsulated_request(request, &mut writer); + assert!(status.is_ok()); + assert!(send_buffer.is_some()); + assert!(context - .handle_get_encapsulated_request(SESSION_ID, writer.used_slice()) + .send_message(Some(SESSION_ID), send_buffer.unwrap(), false) .await .is_ok()); @@ -136,8 +142,15 @@ fn test_handle_deliver_encapsulated_reponse_digest() { assert!(write_spdm_get_digest_response(&mut context, &mut writer).is_ok()); + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = + context.handle_deliver_encapsulated_reponse(request, &mut writer); + assert!(status.is_ok()); + assert!(send_buffer.is_some()); + assert!(context - .handle_deliver_encapsulated_reponse(SESSION_ID, request) + .send_message(Some(SESSION_ID), send_buffer.unwrap(), false) .await .is_ok()); @@ -221,8 +234,15 @@ fn test_handle_deliver_encapsulated_reponse_cert() { assert!(write_spdm_get_certificate_response(&mut context, &mut writer).is_ok()); + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = + context.handle_deliver_encapsulated_reponse(request, &mut writer); + assert!(status.is_ok()); + assert!(send_buffer.is_some()); + assert!(context - .handle_deliver_encapsulated_reponse(SESSION_ID, request) + .send_message(Some(SESSION_ID), send_buffer.unwrap(), false) .await .is_ok()); diff --git a/test/spdmlib-test/src/responder_tests/end_session_rsp.rs b/test/spdmlib-test/src/responder_tests/end_session_rsp.rs index 7c805ad9..fdfd90b5 100644 --- a/test/spdmlib-test/src/responder_tests/end_session_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/end_session_rsp.rs @@ -9,6 +9,7 @@ use crate::common::util::create_info; use codec::{Codec, Writer}; use spdmlib::common::session::{SpdmSession, SpdmSessionState}; use spdmlib::common::SpdmCodec; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -92,10 +93,10 @@ fn test_case0_handle_spdm_end_session() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&session_request[0..1022]); - assert!(context - .handle_spdm_end_session(session_id, bytes) - .await - .is_ok()); + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_end_session(session_id, bytes, &mut writer); + assert!(status.is_ok()); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/error_rsp.rs b/test/spdmlib-test/src/responder_tests/error_rsp.rs index 5a793d6c..6e50facb 100644 --- a/test/spdmlib-test/src/responder_tests/error_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/error_rsp.rs @@ -6,6 +6,8 @@ use crate::common::device_io::{FakeSpdmDeviceIoReceve, SharedBuffer}; use crate::common::secret_callback::*; use crate::common::transport::PciDoeTransportEncap; use crate::common::util::create_info; +use codec::Writer; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -31,9 +33,9 @@ fn test_case0_send_spdm_error() { ); context.common.negotiate_info.base_hash_sel = SpdmBaseHashAlgo::TPM_ALG_SHA_384; - context - .send_spdm_error(SpdmErrorCode::SpdmErrorInvalidRequest, 0) - .await + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.write_spdm_error(SpdmErrorCode::SpdmErrorInvalidRequest, 0, &mut writer); }; executor::block_on(future); diff --git a/test/spdmlib-test/src/responder_tests/finish_rsp.rs b/test/spdmlib-test/src/responder_tests/finish_rsp.rs index 787e2aec..2602b9d2 100644 --- a/test/spdmlib-test/src/responder_tests/finish_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/finish_rsp.rs @@ -89,13 +89,17 @@ fn test_case0_handle_spdm_finish() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&finish_slic[0..1022]); - context.handle_spdm_finish(4294901758, bytes).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294901758, bytes, &mut writer); }; executor::block_on(future); } #[test] #[cfg(feature = "hashed-transcript-data")] fn test_case1_handle_spdm_finish() { + use spdmlib::config::MAX_SPDM_MSG_SIZE; + let (config_info, provision_info) = create_info(); let pcidoe_transport_encap = Arc::new(Mutex::new(PciDoeTransportEncap {})); let shared_buffer = SharedBuffer::new(); @@ -167,5 +171,7 @@ fn test_case1_handle_spdm_finish() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&finish_slic[0..1022]); - context.handle_spdm_finish(4294901758, bytes); + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_finish(4294901758, bytes, &mut writer); } diff --git a/test/spdmlib-test/src/responder_tests/heartbeat_rsp.rs b/test/spdmlib-test/src/responder_tests/heartbeat_rsp.rs index 318e5646..61115b58 100644 --- a/test/spdmlib-test/src/responder_tests/heartbeat_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/heartbeat_rsp.rs @@ -8,6 +8,7 @@ use crate::common::transport::PciDoeTransportEncap; use crate::common::util::create_info; use codec::{Codec, Writer}; use spdmlib::common::session::{SpdmSession, SpdmSessionState}; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -79,11 +80,9 @@ fn test_case0_handle_spdm_heartbeat() { request_response_code: SpdmRequestResponseCode::SpdmRequestChallenge, }; assert!(value.encode(&mut writer).is_ok()); - - assert!(context - .handle_spdm_heartbeat(session_id, bytes) - .await - .is_ok()); + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_heartbeat(session_id, bytes, &mut writer); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/key_exchange_rsp.rs b/test/spdmlib-test/src/responder_tests/key_exchange_rsp.rs index e7675d8e..01583066 100644 --- a/test/spdmlib-test/src/responder_tests/key_exchange_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/key_exchange_rsp.rs @@ -88,7 +88,9 @@ fn test_case0_handle_spdm_key_exchange() { bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&key_exchange[0..1022]); - context.handle_spdm_key_exchange(bytes).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_exchange(bytes, &mut writer); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/key_update_rsp.rs b/test/spdmlib-test/src/responder_tests/key_update_rsp.rs index aa24b137..3a82f512 100644 --- a/test/spdmlib-test/src/responder_tests/key_update_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/key_update_rsp.rs @@ -9,6 +9,7 @@ use crate::common::util::create_info; use codec::{Codec, Writer}; use spdmlib::common::session::{SpdmSession, SpdmSessionState}; use spdmlib::common::SpdmCodec; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -85,8 +86,9 @@ fn test_case0_handle_spdm_key_update() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&key_exchange[0..1022]); - - context.handle_spdm_key_update(session_id, bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_update(session_id, bytes, &mut writer); }; executor::block_on(future); } @@ -158,8 +160,9 @@ fn test_case1_handle_spdm_key_update() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&key_exchange[0..1022]); - - context.handle_spdm_key_update(session_id, bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_key_update(session_id, bytes, &mut writer); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/measurement_rsp.rs b/test/spdmlib-test/src/responder_tests/measurement_rsp.rs index a3d26aeb..c202df8c 100644 --- a/test/spdmlib-test/src/responder_tests/measurement_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/measurement_rsp.rs @@ -9,6 +9,7 @@ use crate::common::util::create_info; use codec::{Codec, Reader, Writer}; use spdmlib::common::SpdmCodec; use spdmlib::common::SpdmConnectionState; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -70,7 +71,9 @@ fn test_case0_handle_spdm_measurement() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&measurements_struct[0..1022]); - context.handle_spdm_measurement(None, bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_measurement(None, bytes, &mut writer); #[cfg(not(feature = "hashed-transcript-data"))] { @@ -174,7 +177,9 @@ fn test_case1_handle_spdm_measurement() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&measurements_struct[0..1022]); - context.handle_spdm_measurement(None, bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_measurement(None, bytes, &mut writer); #[cfg(not(feature = "hashed-transcript-data"))] { diff --git a/test/spdmlib-test/src/responder_tests/psk_exchange_rsp.rs b/test/spdmlib-test/src/responder_tests/psk_exchange_rsp.rs index 68a27ac8..264e35fd 100644 --- a/test/spdmlib-test/src/responder_tests/psk_exchange_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/psk_exchange_rsp.rs @@ -10,7 +10,7 @@ use codec::{Codec, Writer}; use spdmlib::common::opaque; use spdmlib::common::opaque::*; use spdmlib::common::SpdmCodec; -use spdmlib::config::{MAX_SPDM_PSK_CONTEXT_SIZE, MAX_SPDM_PSK_HINT_SIZE}; +use spdmlib::config::{MAX_SPDM_MSG_SIZE, MAX_SPDM_PSK_CONTEXT_SIZE, MAX_SPDM_PSK_HINT_SIZE}; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -75,7 +75,9 @@ fn test_case0_handle_spdm_psk_exchange() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&challenge[0..1022]); - context.handle_spdm_psk_exchange(bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_exchange(bytes, &mut writer); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/psk_finish_rsp.rs b/test/spdmlib-test/src/responder_tests/psk_finish_rsp.rs index e717c737..156de0ca 100644 --- a/test/spdmlib-test/src/responder_tests/psk_finish_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/psk_finish_rsp.rs @@ -71,7 +71,9 @@ fn test_case0_handle_spdm_psk_finish() { let bytes = &mut [0u8; 1024]; bytes.copy_from_slice(&spdm_message_header[0..]); bytes[2..].copy_from_slice(&psk_finish[0..1022]); - context.handle_spdm_psk_finish(4294901758, bytes).await; + let mut response_buffer = [0u8; spdmlib::config::MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + let (status, send_buffer) = context.handle_spdm_psk_finish(4294901758, bytes, &mut writer); }; executor::block_on(future); } diff --git a/test/spdmlib-test/src/responder_tests/version_rsp.rs b/test/spdmlib-test/src/responder_tests/version_rsp.rs index 5f77fbed..60e0d242 100644 --- a/test/spdmlib-test/src/responder_tests/version_rsp.rs +++ b/test/spdmlib-test/src/responder_tests/version_rsp.rs @@ -8,6 +8,7 @@ use crate::common::transport::PciDoeTransportEncap; use crate::common::util::create_info; use codec::{Codec, Reader, Writer}; use spdmlib::common::*; +use spdmlib::config::MAX_SPDM_MSG_SIZE; use spdmlib::message::*; use spdmlib::protocol::*; use spdmlib::{responder, secret}; @@ -43,7 +44,9 @@ fn test_case0_handle_spdm_version() { }; assert!(value.encode(&mut writer).is_ok()); - context.handle_spdm_version(bytes).await; + let mut response_buffer = [0u8; MAX_SPDM_MSG_SIZE]; + let mut writer = Writer::init(&mut response_buffer); + context.handle_spdm_version(bytes, &mut writer); let data = context.common.runtime_info.message_a.as_ref(); let u8_slice = &mut [0u8; 1024];