Skip to content

Commit 1a3f09e

Browse files
OuyangHang33jyao1
authored andcommitted
replace spdm-rs url and upgrading spdm
Signed-off-by: OuyangHang33 <[email protected]>
1 parent 133813f commit 1a3f09e

19 files changed

+205
-91
lines changed

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[submodule "deps/td-shim"]
22
path = deps/td-shim
33
url = https://github.com/confidential-containers/td-shim
4-
[submodule "deps/rust-spdm"]
5-
path = deps/rust-spdm
6-
url = https://github.com/intel/rust-spdm
74
[submodule "deps/rust-tpm-20-ref/ms-tpm-20-ref"]
85
path = deps/rust-tpm-20-ref/ms-tpm-20-ref
96
url = https://github.com/microsoft/ms-tpm-20-ref.git
@@ -16,3 +13,6 @@
1613
[submodule "deps/linux-sgx"]
1714
path = deps/linux-sgx
1815
url = https://github.com/intel/linux-sgx.git
16+
[submodule "deps/spdm-rs"]
17+
path = deps/spdm-rs
18+
url = https://github.com/ccc-spdm-tools/spdm-rs.git

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ members = [
1818

1919
exclude = [
2020
"deps/td-shim",
21-
"deps/rust-spdm",
21+
"deps/spdm-rs",
2222
"deps/ring",
2323
"deps/webpki",
2424
]
@@ -33,5 +33,5 @@ panic = "abort" # disable stack unwinding on panic
3333
lto = true # Link-time optimization
3434

3535
[patch.crates-io]
36-
ring = { path = "deps/rust-spdm/external/ring" }
37-
webpki = { path = "deps/rust-spdm/external/webpki" }
36+
ring = { path = "deps/spdm-rs/external/ring" }
37+
webpki = { path = "deps/spdm-rs/external/webpki" }

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rust-vtpm-td depends on below projects
4040
|[ms-tpm-20-ref](https://github.com/microsoft/ms-tpm-20-ref/tree/d638536d0fe01acd5e39ffa1bd100b3da82d92c7)|[deps/rust-tpm-20-ref/ms-tpm-20-ref](./deps/rust-tpm-20-ref/ms-tpm-20-ref/)|An official TCG reference implementation of the TPM 2.0 Specification|
4141
|[musl](https://git.musl-libc.org/cgit/musl)|[deps/rust-tpm-20-ref/smallc/musl](./deps/rust-tpm-20-ref/smallc/musl/)|An Implementation of the C standard library|
4242
|[openssl](https://github.com/openssl/openssl/tree/2cf4e90eaaf7402bf038b158dbdacd0a15561fb7)|[deps/rust-tpm-20-ref/openssl](./deps/rust-tpm-20-ref/openssl/)|A full-strength general cryptographic library|
43-
|[rust-spdm](https://github.com/intel/rust-spdm/tree/4b100862a050a79e9cdacbfbc7ef16b0b0662aca)|[deps/rust-spdm](./deps/rust-spdm/)|A rust version SPDM implementation|
43+
|[spdm-rs](https://github.com/ccc-spdm-tools/spdm-rs/tree/f42eaf4680da0b0684ec1b9d64b7e417f8ff8160)|[deps/spdm-rs](./deps/spdm-rs/)|A rust version SPDM implementation|
4444
|[td-shim](https://github.com/confidential-containers/td-shim/tree/abc721e6796bbc723da2aa2c1bdacd3bb2e0f661)|[deps/td-shim](./deps/td-shim/)|A simplified TDX virtual firmware for the simplified kernel for TD container|
4545

4646
### Prepare source code

deps/rust-spdm

-1
This file was deleted.

deps/spdm-rs

Submodule spdm-rs added at f42eaf4

sh_script/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function clean() {
2828
cargo clean
2929
popd
3030

31-
pushd deps/rust-spdm
31+
pushd deps/spdm-rs
3232
cargo clean
3333
popd
3434

sh_script/pre-build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function patch_tdshim() {
1111
}
1212

1313
function patch_rustspdm() {
14-
pushd deps/rust-spdm
14+
pushd deps/spdm-rs
1515
sh_script/pre-build.sh
1616
popd
1717
}

src/crypto/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bytes = { version="1", default-features=false }
1010
der = {version = "0.5.1", features = ["oid", "alloc", "derive"]}
1111
global = { path = "../global" }
1212
log = "0.4.13"
13-
ring = { version = "0.16.20" }
14-
spdmlib = { path = "../../deps/rust-spdm/spdmlib", default-features = false, features = ["spdm-ring", "mut-auth"]}
13+
ring = { version = "0.17.6" }
14+
spdmlib = { path = "../../deps/spdm-rs/spdmlib", default-features = false, features = ["spdm-ring", "mut-auth", "is_sync"]}
1515
tdx-tdcall = { path = "../../deps/td-shim/tdx-tdcall" }
1616
zerocopy = { version = "0.7.31", features = ["derive"] }

src/crypto/fuzz/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ der = {version = "0.5.1", features = ["oid", "alloc", "derive"]}
1919
path = ".."
2020

2121
[patch.crates-io]
22-
ring = { path = "../../../deps/rust-spdm/external/ring" }
23-
webpki = { path = "../../../deps/rust-spdm/external/webpki" }
22+
ring = { path = "../../../deps/spdm-rs/external/ring" }
23+
webpki = { path = "../../../deps/spdm-rs/external/webpki" }
2424

2525
# Prevent this from interfering with workspaces
2626
[workspace]

src/spdm/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ global = { path = "../global" }
1010
log = "0.4.13"
1111
paste = "1.0"
1212

13-
ring = { version = "0.16.20" }
13+
ring = { version = "0.17.6" }
1414
spin = "0.9.2"
1515
x86 = "0.47.0"
1616
x86_64 = "0.14.9"
1717

18-
codec = { path = "../../deps/rust-spdm/codec" }
18+
codec = { path = "../../deps/spdm-rs/codec" }
1919
protocol = { path = "../protocol" }
2020
tdtunnel = { path = "../tdtunnel" }
21-
spdmlib = { path = "../../deps/rust-spdm/spdmlib", default-features = false, features = ["spdm-ring", "mut-auth"]}
21+
spdmlib = { path = "../../deps/spdm-rs/spdmlib", default-features = false, features = ["spdm-ring", "mut-auth", "is_sync"]}
2222
td-exception = { path = "../../deps/td-shim/td-exception", features = ["tdx"]}
2323
tdx-tdcall = { path = "../../deps/td-shim/tdx-tdcall" }
24-
td-payload = { path = "../../deps/td-shim/td-payload", features = ["tdx"] }
24+
td-payload = { path = "../../deps/td-shim/td-payload", features = ["tdx"] }
25+
maybe-async = {version = "0.2.7", features = ["is_sync"] }

src/spdm/src/crypto_callback.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ fn sign_ecdsa_asym_algo(
3838
let binding = GLOBAL_SPDM_DATA.lock();
3939
let mut pkcs8 = binding.pkcs8()?;
4040

41-
let key_pair = ring::signature::EcdsaKeyPair::from_pkcs8(algorithm, pkcs8);
41+
let rng = ring::rand::SystemRandom::new();
42+
let key_pair = ring::signature::EcdsaKeyPair::from_pkcs8(algorithm, pkcs8, &rng);
4243
if key_pair.is_err() {
4344
return None;
4445
}

src/spdm/src/vtpm_io_transport.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
use core::convert::TryFrom;
6+
use core::ops::DerefMut;
7+
8+
extern crate alloc;
9+
use alloc::sync::Arc;
10+
use spin::Mutex;
611

712
use global::{TdVtpmOperation, GLOBAL_SPDM_DATA};
813
use spdmlib::common::SpdmDeviceIo;
@@ -25,23 +30,29 @@ impl VtpmIoTransport {
2530
}
2631
}
2732

33+
#[maybe_async::maybe_async]
2834
impl SpdmDeviceIo for VtpmIoTransport {
2935
/// Send the payload out.
3036
/// The payload follows the format in Table 5-14/15/16
31-
fn send(&mut self, buffer: &[u8]) -> SpdmResult {
32-
let res =
33-
self.tunnel
34-
.report_status(buffer, self.vtpm_id, TdVtpmOperation::Communicate as u8, 0);
37+
fn send(&mut self, buffer: Arc<&[u8]>) -> SpdmResult {
38+
let res = self.tunnel.report_status(
39+
&buffer.clone(),
40+
self.vtpm_id,
41+
TdVtpmOperation::Communicate as u8,
42+
0,
43+
);
3544
if res.is_err() {
3645
Err(SPDM_STATUS_SEND_FAIL)
3746
} else {
3847
Ok(())
3948
}
4049
}
4150

42-
fn receive(&mut self, buffer: &mut [u8], _timeout: usize) -> Result<usize, usize> {
51+
fn receive(&mut self, buffer: Arc<Mutex<&mut [u8]>>, _timeout: usize) -> Result<usize, usize> {
4352
let mut tmp_buf: [u8; 0x1000] = [0; 0x1000];
4453

54+
let mut buffer = buffer.lock();
55+
let buffer = buffer.deref_mut();
4556
GLOBAL_SPDM_DATA.lock().clear_data();
4657
let res = self.tunnel.wait_for_request(buffer, self.vtpm_id);
4758
if res.is_err() {
@@ -127,7 +138,8 @@ mod test {
127138
fn test_vtpmio_transport_send() {
128139
let mut vtpmio = VtpmIoTransport::new(101);
129140
let buffer = [1u8; 100];
130-
let res = vtpmio.send(&buffer);
141+
let buffer = Arc::new(&buffer[..]);
142+
let res = vtpmio.send(buffer);
131143
assert!(res.is_err());
132144
}
133145

@@ -136,7 +148,8 @@ mod test {
136148
fn test_vtpmio_transport_recive() {
137149
let mut vtpmio = VtpmIoTransport::new(101);
138150
let mut buffer = [1u8; 100];
139-
let res = vtpmio.receive(&mut buffer, 0);
151+
let buffer = Arc::new(Mutex::new(&mut buffer[..]));
152+
let res = vtpmio.receive(buffer, 0);
140153
assert!(res.is_err());
141154
}
142155

0 commit comments

Comments
 (0)