Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spdm_version: add version select support #11

Merged
merged 1 commit into from
Nov 3, 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
32 changes: 32 additions & 0 deletions src/cli_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@ pub fn parse_qemu_transport_layer(
}
}

/// # Summary
///
/// Parses the CLI argument for the SPDM version used by a responder.
///
/// # Parameter
///
/// * `spdm_ver`: String option containing the version (1.0, 1,1 ...etc)
///
/// # Returns
///
/// The corresponding libspdm value for the version, None if not found.
pub fn parse_spdm_responder_version(spdm_ver: Option<String>) -> Option<u8> {
if let Some(ver) = spdm_ver {
match ver.as_str() {
"1.0" => {
return Some(u8::try_from(libspdm::libspdm_rs::SPDM_MESSAGE_VERSION_10).unwrap())
}
"1.1" => {
return Some(u8::try_from(libspdm::libspdm_rs::SPDM_MESSAGE_VERSION_11).unwrap())
}
"1.2" => {
return Some(u8::try_from(libspdm::libspdm_rs::SPDM_MESSAGE_VERSION_12).unwrap())
}
"1.3" => {
return Some(u8::try_from(libspdm::libspdm_rs::SPDM_MESSAGE_VERSION_13).unwrap())
}
_ => return None,
}
}
None
}

/// # Summary
///
/// Parses the CLI based AEAD Cipher Suites
Expand Down
19 changes: 17 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ enum Commands {
use_psk_exchange: bool,
},
/// initiate a SPDM response
Response {},
Response {
/// The SPDM (DSP0274) version(s) (1.0, 1.1, 1.2 or 1.3) of an endpoint.
/// These are communicated through the `GET_VERSION / VERSION` messages.
#[arg(long, default_value = "1.3")]
spdm_ver: Option<String>,
},
Tests,
}

Expand Down Expand Up @@ -328,7 +333,7 @@ fn main() -> Result<(), ()> {
request::prepare_request(cntx_ptr, code, cert_slot_id, cert_path, &mut session_info)
.unwrap();
}
Commands::Response {} => {
Commands::Response { spdm_ver } => {
for slot_id in 1..8 {
let file_name = format!("certs/slot{}/immutable.der", slot_id);
let path = Path::new(&file_name);
Expand All @@ -342,15 +347,25 @@ fn main() -> Result<(), ()> {
responder::setup_capabilities(
cntx_ptr,
slot_id,
None,
SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384,
SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384,
)
.unwrap();
}
}
// Check if version was specified
let ver = cli_helpers::parse_spdm_responder_version(spdm_ver);
if ver.is_none() {
// spdm_ver has a default value set, if None was returned, it means
// the user argument was invalid.
error!("Unsupported libspdm data spdm version");
return Err(());
}
responder::setup_capabilities(
cntx_ptr,
0,
ver,
SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384,
SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384,
)
Expand Down
18 changes: 18 additions & 0 deletions src/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::Path;
///
/// * `context`: The SPDM context
/// * `slot_id`: slot id for this session
/// * `ver`: SPDM Version
/// * `asym_algo`: Asymmetric algorithm used
/// * `hash_algo`: Hashing algorithm used
///
Expand All @@ -33,6 +34,7 @@ use std::path::Path;
pub fn setup_capabilities(
context: *mut c_void,
slot_id: u8,
spdm_ver: Option<u8>,
asym_algo: u32,
hash_algo: u32,
) -> Result<(), ()> {
Expand Down Expand Up @@ -60,6 +62,22 @@ pub fn setup_capabilities(
core::mem::size_of::<u32>(),
);

if let Some(ver) = spdm_ver {
let mut data: u16 = (ver as u16)
.checked_shl(SPDM_VERSION_NUMBER_SHIFT_BIT)
.expect("SPDM version shift overflow");
let data_ptr = &mut data as *mut _ as *mut c_void;
libspdm_set_data(
context,
libspdm_data_type_t_LIBSPDM_DATA_SPDM_VERSION,
&parameter as *const libspdm_data_parameter_t,
data_ptr,
core::mem::size_of::<u16>(),
);
} else {
warn!("libspdm data SPDM version not specified");
}

let mut data: u8 = 0x00;
let data_ptr = &mut data as *mut _ as *mut c_void;
libspdm_set_data(
Expand Down