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

Commit

Permalink
support both async and sync style.
Browse files Browse the repository at this point in the history
fix #163

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang authored and jyao1 committed Dec 8, 2023
1 parent 0189b3c commit 41fe503
Show file tree
Hide file tree
Showing 56 changed files with 242 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ jobs:
"spdm-ring,hashed-transcript-data,async-executor",
"spdm-mbedtls,async-executor",
"spdm-mbedtls,hashed-transcript-data,async-executor",
"spdm-ring,hashed-transcript-data,is_sync",
"spdm-ring,is_sync",
]
run_responder_features:
[
"spdm-ring,async-executor",
"spdm-ring,hashed-transcript-data,async-executor",
"spdm-mbedtls,async-executor",
"spdm-mbedtls,hashed-transcript-data,async-executor",
"spdm-ring,hashed-transcript-data,is_sync",
"spdm-ring,is_sync",
]
include:
- runs-on: windows-latest
Expand Down
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion idekm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ codec = { path = "../codec" }
zeroize = { version = "1.5.0", features = ["zeroize_derive"]}
spdmlib = { path = "../spdmlib", default-features = false, features = ["spdm-ring"]}
conquer-once = { version = "0.3.2", default-features = false }

maybe-async = "0.2.7"

[features]
is_sync = ["spdmlib/is_sync", "maybe-async/is_sync"]
1 change: 1 addition & 0 deletions idekm/src/pci_ide_km_requester/pci_ide_km_req_key_prog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::IdekmReqContext;

impl IdekmReqContext {
#[allow(clippy::too_many_arguments)]
#[maybe_async::maybe_async]
pub async fn pci_ide_km_key_prog(
&mut self,
// IN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::IdekmReqContext;

impl IdekmReqContext {
#[allow(clippy::too_many_arguments)]
#[maybe_async::maybe_async]
pub async fn pci_ide_km_key_set_go(
&mut self,
// IN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::IdekmReqContext;

impl IdekmReqContext {
#[allow(clippy::too_many_arguments)]
#[maybe_async::maybe_async]
pub async fn pci_ide_km_key_set_stop(
&mut self,
// IN
Expand Down
1 change: 1 addition & 0 deletions idekm/src/pci_ide_km_requester/pci_ide_km_req_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use super::IdekmReqContext;

impl IdekmReqContext {
#[allow(clippy::too_many_arguments)]
#[maybe_async::maybe_async]
pub async fn pci_ide_km_query(
&mut self,
// IN
Expand Down
4 changes: 4 additions & 0 deletions mctp_transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ spdmlib = { path = "../spdmlib", default-features = false}
futures = { version = "0.3", default-features = false }
async-trait = "0.1.71"
executor = { path = "../executor" }
maybe-async = "0.2.7"

[features]
is_sync = ["spdmlib/is_sync", "maybe-async/is_sync"]
3 changes: 1 addition & 2 deletions mctp_transport/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use async_trait::async_trait;
use codec::enum_builder;
use codec::{Codec, Reader, Writer};
use spdmlib::common::SpdmTransportEncap;
Expand Down Expand Up @@ -57,7 +56,7 @@ impl Codec for MctpMessageHeader {
#[derive(Debug, Copy, Clone, Default)]
pub struct MctpTransportEncap {}

#[async_trait]
#[maybe_async::maybe_async]
impl SpdmTransportEncap for MctpTransportEncap {
async fn encap(
&mut self,
Expand Down
4 changes: 4 additions & 0 deletions pcidoe_transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ spdmlib = { path = "../spdmlib", default-features = false}
futures = { version = "0.3", default-features = false }
async-trait = "0.1.71"
spin = { version = "0.9.8" }
maybe-async = "0.2.7"

[features]
is_sync = ["spdmlib/is_sync", "maybe-async/is_sync"]
3 changes: 1 addition & 2 deletions pcidoe_transport/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use async_trait::async_trait;
extern crate alloc;
use alloc::boxed::Box;
use alloc::sync::Arc;
Expand Down Expand Up @@ -89,7 +88,7 @@ impl Codec for PciDoeMessageHeader {
#[derive(Debug, Copy, Clone, Default)]
pub struct PciDoeTransportEncap {}

#[async_trait]
#[maybe_async::maybe_async]
impl SpdmTransportEncap for PciDoeTransportEncap {
async fn encap(
&mut self,
Expand Down
31 changes: 22 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,18 @@ cargo fmt
cargo build
```

### Build `no_std` spdm
### Build async `no_std` spdm
```
pushd spdmlib
cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring"
```

### Build sync `no_std` spdm
```
pushd spdmlib
cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring,is_sync"
```

## Run Rust SPDM emulator

### Run emulator with default feature
Expand All @@ -147,14 +153,15 @@ cargo run -p spdm-requester-emu --no-default-features --features "spdm-ring,hash
The following list shows the supported combinations for both spdm-requester-emu and spdm-responder-emu


| Features | CryptoLibrary | Hashed transcript data support | async runtime | notes |
|-------------------------------------------------|---------------|--------------------------------|---------------|---------------------------------------------------------------------------------------------------|
| spdm-ring,async-executor | ring | No | executor | use ring as crypto library with hashed-transcript-data disabled, use executor as async runtime |
| spdm-ring,hashed-transcript-data,async-executor | ring | Yes | executor | use ring as crypto library with hashed-transcript-data enabled, use executor as async runtime |
| spdm-ring,hashed-transcript-data,async-tokio | ring | Yes | tokio | use ring as crypto library with hashed-transcript-data enabled, use tokio as async runtime |
| spdm-mbedtls,async-executor | mbedtls | No | executor | use mbedtls as crypto library with hashed-transcript-data disabled, use executor as async runtime |
| spdm-mbedtls,hashed-transcript-data,async-executor | mbedtls | Yes | executor | use mbedtls as crypto library with hashed-transcript-data enabled, use executor as async runtime |
| spdm-mbedtls,hashed-transcript-data,async-tokio | mbedtls | Yes | tokio | use mbedtls as crypto library with hashed-transcript-data enabled, use tokio as async runtime |
| Features | CryptoLibrary | Hashed transcript data support | sync/async | notes |
|----------------------------------------------------|---------------|--------------------------------|------------------------|-----------------------------------------------------------------------------------------------------------------|
| spdm-ring,is_sync | ring | No | sync | use ring as crypto library with hashed-transcript-data disabled, sync version. |
| spdm-ring,hashed-transcript-data,is_sync | ring | Yes | sync | use ring as crypto library with hashed-transcript-data enabled, sync version. |
| spdm-ring,hashed-transcript-data,async-tokio | ring | Yes | tokio async runtime | use ring as crypto library with hashed-transcript-data enabled, async version, use tokio as async runtime |
| spdm-mbedtls,is_sync | mbedtls | No | sync | use mbedtls as crypto library with hashed-transcript-data disabled, sync version. |
| spdm-mbedtls,hashed-transcript-data,is_sync | mbedtls | Yes | sync | use mbedtls as crypto library with hashed-transcript-data enabled, sync version. |
| spdm-mbedtls,hashed-transcript-data,async-executor | mbedtls | Yes | executor async runtime | use mbedtls as crypto library with hashed-transcript-data enabled, async version, use executor as async runtime |


For example, run the emulator with spdm-ring enabled and without hashed-transcript-data enabled, and use executor as async runtime.
Open one command windows and run:
Expand All @@ -168,6 +175,12 @@ Open another command windows and run:
cargo run -p spdm-requester-emu --no-default-features --features "spdm-mbedtls,hashed-transcript-data,async-tokio"
```

run the emulator with spdm-mbedtls enabled and with hashed-transcript-data enabled, and without using async style.
Open another command windows and run:
```
cargo run -p spdm-requester-emu --no-default-features --features "spdm-mbedtls,hashed-transcript-data,is_sync"
```

NOTE: In order to run the emu without hashed-transcript-data, please change `max_cert_chain_data_size` in `spdmlib/etc/config.json` from `4096` to `3500`.

### Cross test with [spdm_emu](https://github.com/DMTF/spdm-emu)
Expand Down
21 changes: 20 additions & 1 deletion sh_script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,43 @@ build() {

echo "Building Rust-SPDM with spdm-ring feature..."
echo_command cargo build --release --no-default-features --features=spdm-ring

echo "Building Rust-SPDM with spdm-ring,is_sync feature..."
echo_command cargo build --release --no-default-features --features=spdm-ring,is_sync

echo "Building Rust-SPDM with spdm-ring,hashed-transcript-data feature..."
echo_command cargo build --release --no-default-features --features=spdm-ring,hashed-transcript-data


echo "Building Rust-SPDM with spdm-ring,hashed-transcript-data,is_sync feature..."
echo_command cargo build --release --no-default-features --features=spdm-ring,hashed-transcript-data,is_sync

echo "Building Rust-SPDM with spdm-ring,hashed-transcript-data,mut-auth feature..."
echo_command cargo build --release --no-default-features --features=spdm-ring,hashed-transcript-data,mut-auth

echo "Building Rust-SPDM with spdm-ring,hashed-transcript-data,mut-auth,is_sync feature..."
echo_command cargo build --release --no-default-features --features=spdm-ring,hashed-transcript-data,mut-auth,is_sync

if [ -z "$RUSTFLAGS" ]; then
echo "Building Rust-SPDM in no std with no-default-features..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features

echo "Building Rust-SPDM in no std with spdm-ring feature..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring"

echo "Building Rust-SPDM in no std with spdm-ring,is_sync feature..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring,is_sync"

echo "Building Rust-SPDM in no std with spdm-ring,hashed-transcript-data feature..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring,hashed-transcript-data"

echo "Building Rust-SPDM in no std with spdm-ring,hashed-transcript-data,is_sync feature..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring,hashed-transcript-data,is_sync"

echo "Building Rust-SPDM in no std with spdm-ring,hashed-transcript-data,mut-auth feature..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring,hashed-transcript-data,mut-auth"

echo "Building Rust-SPDM in no std with spdm-ring,hashed-transcript-data,mut-auth,is_sync feature..."
echo_command cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-none --release --no-default-features --features="spdm-ring,hashed-transcript-data,mut-auth,is_sync"
fi

popd
Expand Down Expand Up @@ -139,6 +157,7 @@ run_basic_test() {
echo "Running basic tests..."
echo_command cargo test -- --test-threads=1
echo_command cargo test --no-default-features --features "spdmlib/std,spdmlib/spdm-ring" -- --test-threads=1
echo_command cargo test --no-default-features --features "spdmlib/std,spdmlib/spdm-ring,spdm-emu/is_sync,spdmlib/is_sync,maybe-async/is_sync,idekm/is_sync,tdisp/is_sync,mctp_transport/is_sync,pcidoe_transport/is_sync,spdm-requester-emu/is_sync,spdm-responder-emu/is_sync" -- --test-threads=1
echo "Running basic tests finished..."

echo "Running spdmlib-test..."
Expand Down
3 changes: 2 additions & 1 deletion spdmlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ring = { version = "0.17.6", default-features = false, features = ["alloc", "les
webpki = { version = "0.22.4", default-features = false, features = ["alloc"], optional = true}
untrusted = { version = "0.9.0", optional = true }
zeroize = { version = "1.5.0", features = ["zeroize_derive"]}

maybe-async = "0.2.7"
futures = { version = "0.3", default-features = false }
async-trait = "0.1.71"
spin = "0"
Expand Down Expand Up @@ -48,3 +48,4 @@ downcast = []
hashed-transcript-data = []
mut-auth = []
mandatory-mut-auth = ["mut-auth"]
is_sync = ["maybe-async/is_sync"]
9 changes: 6 additions & 3 deletions spdmlib/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use alloc::boxed::Box;
use alloc::sync::Arc;
use core::ops::DerefMut;

use async_trait::async_trait;
pub use opaque::*;
pub use spdm_codec::SpdmCodec;

Expand Down Expand Up @@ -78,7 +77,7 @@ pub const INITIAL_SESSION_ID: u16 = 0xFFFD;
pub const INVALID_HALF_SESSION_ID: u16 = 0x0;
pub const INVALID_SESSION_ID: u32 = 0x0;

#[async_trait]
#[maybe_async::maybe_async]
pub trait SpdmDeviceIo {
async fn send(&mut self, buffer: Arc<&[u8]>) -> SpdmResult;

Expand All @@ -96,7 +95,7 @@ pub trait SpdmDeviceIo {

use core::fmt::Debug;

#[async_trait]
#[maybe_async::maybe_async]
pub trait SpdmTransportEncap {
async fn encap(
&mut self,
Expand Down Expand Up @@ -967,6 +966,7 @@ impl SpdmContext {
}
}

#[maybe_async::maybe_async]
pub async fn encap(
&mut self,
send_buffer: &[u8],
Expand All @@ -983,6 +983,7 @@ impl SpdmContext {
.await
}

#[maybe_async::maybe_async]
pub async fn encode_secured_message(
&mut self,
session_id: u32,
Expand Down Expand Up @@ -1027,6 +1028,7 @@ impl SpdmContext {
.await
}

#[maybe_async::maybe_async]
pub async fn decap(
&mut self,
transport_buffer: &[u8],
Expand All @@ -1050,6 +1052,7 @@ impl SpdmContext {
Ok(used)
}

#[maybe_async::maybe_async]
pub async fn decode_secured_message(
&mut self,
session_id: u32,
Expand Down
Loading

0 comments on commit 41fe503

Please sign in to comment.