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

move send_message to process_message. #75

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions codec/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
if self.left() < value.len() {
return None;
Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/algorithm_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
6 changes: 5 additions & 1 deletion fuzz-target/responder/algorithm_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +34,10 @@ async fn fuzz_handle_spdm_algorithm(data: Arc<Vec<u8>>) {
.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"))]
Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/capability_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 4 additions & 1 deletion fuzz-target/responder/capability_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ async fn fuzz_handle_spdm_capability(data: Arc<Vec<u8>>) {
.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"))]
Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/certificate_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
14 changes: 9 additions & 5 deletions fuzz-target/responder/certificate_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ async fn fuzz_handle_spdm_certificate(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -103,10 +106,11 @@ async fn fuzz_handle_spdm_certificate(data: Arc<Vec<u8>>) {
.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());
}
}

Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/challenge_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
10 changes: 8 additions & 2 deletions fuzz-target/responder/challenge_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ async fn fuzz_handle_spdm_challenge(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -96,7 +99,10 @@ async fn fuzz_handle_spdm_challenge(data: Arc<Vec<u8>>) {
.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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
25 changes: 13 additions & 12 deletions fuzz-target/responder/deliver_encapsulated_response_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ async fn fuzz_handle_deliver_encapsulated_reponse(data: Arc<Vec<u8>>) {

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
Expand Down Expand Up @@ -94,10 +94,10 @@ async fn fuzz_handle_deliver_encapsulated_reponse(data: Arc<Vec<u8>>) {

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
Expand Down Expand Up @@ -134,10 +134,11 @@ async fn fuzz_handle_deliver_encapsulated_reponse(data: Arc<Vec<u8>>) {

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());
}
}

Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/digest_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
14 changes: 9 additions & 5 deletions fuzz-target/responder/digest_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ async fn fuzz_handle_spdm_digest(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -107,10 +110,11 @@ async fn fuzz_handle_spdm_digest(data: Arc<Vec<u8>>) {
.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());
}
}

Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/end_session_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 4 additions & 1 deletion fuzz-target/responder/end_session_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ async fn fuzz_handle_spdm_end_session(data: Arc<Vec<u8>>) {
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"))]
Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/finish_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
30 changes: 25 additions & 5 deletions fuzz-target/responder/finish_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ async fn fuzz_handle_spdm_finish(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -148,7 +152,11 @@ async fn fuzz_handle_spdm_finish(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -212,7 +220,11 @@ async fn fuzz_handle_spdm_finish(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -282,7 +294,11 @@ async fn fuzz_handle_spdm_finish(data: Arc<Vec<u8>>) {
.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
Expand Down Expand Up @@ -351,7 +367,11 @@ async fn fuzz_handle_spdm_finish(data: Arc<Vec<u8>>) {
.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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ async fn fuzz_handle_get_encapsulated_request(data: Arc<Vec<u8>>) {

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());
}
}

Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/heartbeat_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 4 additions & 1 deletion fuzz-target/responder/heartbeat_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ async fn fuzz_handle_spdm_heartbeat(data: Arc<Vec<u8>>) {
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"))]
Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/key_update_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 4 additions & 1 deletion fuzz-target/responder/key_update_rsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ async fn fuzz_handle_spdm_key_update(data: Arc<Vec<u8>>) {
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"))]
Expand Down
1 change: 1 addition & 0 deletions fuzz-target/responder/keyexchange_rsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Loading
Loading