Skip to content

Commit

Permalink
Add verification library code.
Browse files Browse the repository at this point in the history
A golang library and test suite has been added to start testing DPE
end to end. There will need to be a layer added to abstract the
transport layer and allow testing with devices as well as the simulator.
Currently the simulator is the only working option.
  • Loading branch information
zhalvorsen authored and jhand2 committed Mar 6, 2023
1 parent cf23277 commit 14e5f70
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 21 deletions.
19 changes: 18 additions & 1 deletion dpe/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ impl TryFrom<&[u8]> for CommandHdr {
cmd_id: u32::from_le_bytes(raw[4..8].try_into().unwrap()),
profile: u32::from_le_bytes(raw[8..12].try_into().unwrap()),
};
if header.magic != Self::DPE_COMMAND_MAGIC || header.profile != DPE_PROFILE as u32 {
if header.magic != Self::DPE_COMMAND_MAGIC {
return Err(DpeErrorCode::InvalidCommand);
}
// The client doesn't know what profile is implemented when calling the `GetProfile`
// command. But, all other commands should be directed towards the correct profile.
if header.cmd_id != Command::GET_PROFILE && header.profile != DPE_PROFILE as u32 {
return Err(DpeErrorCode::InvalidCommand);
}
Ok(header)
Expand Down Expand Up @@ -257,17 +262,29 @@ mod tests {
#[cfg(feature = "dpe_profile_p384_sha384")]
let wrong_profile = DpeProfile::P256Sha256 as u32;

// All commands should check the profile except GetProfile.
assert_eq!(
invalid_command,
CommandHdr::try_from(
Vec::<u8>::from(CommandHdr {
profile: wrong_profile,
cmd_id: Command::INITIALIZE_CONTEXT,
..DEFAULT_COMMAND
})
.as_slice()
)
);

// Make sure GetProfile doesn't care.
assert!(CommandHdr::try_from(
Vec::<u8>::from(CommandHdr {
profile: wrong_profile,
..DEFAULT_COMMAND
})
.as_slice()
)
.is_ok());

// Test correct command. Using random command ID to check endianness and consistency.
const GOOD_HEADER: CommandHdr = CommandHdr {
cmd_id: 0x8765_4321,
Expand Down
10 changes: 5 additions & 5 deletions dpe/src/dpe_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ impl Default for TciMeasurement {

#[derive(Default)]
pub struct Support {
simulation: bool,
extend_tci: bool,
auto_init: bool,
tagging: bool,
rotate_context: bool,
pub simulation: bool,
pub extend_tci: bool,
pub auto_init: bool,
pub tagging: bool,
pub rotate_context: bool,
}

impl Support {
Expand Down
195 changes: 195 additions & 0 deletions simulator/Cargo.lock

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

1 change: 1 addition & 0 deletions simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
ctrlc = { version = "3.0", features = ["termination"] }
openssl = "0.10"
clap = { version = "4.1.8", features = ["derive"] }
dpe = { path = "../dpe" }
Loading

0 comments on commit 14e5f70

Please sign in to comment.