-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Richard Zak <richard@profian.com>
- Loading branch information
Showing
14 changed files
with
781 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com> | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
use serde::de::Error; | ||
use serde::{Deserialize, Deserializer, Serialize}; | ||
use sgx::parameters::Features; | ||
|
||
#[derive(Clone, Deserialize, Debug, Default, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Config { | ||
/// Values for `mrsigner` in the report body. | ||
/// This is the list of public keys which have signed the Enarx binary. | ||
#[serde(default)] | ||
#[serde(deserialize_with = "from_hex")] | ||
pub enarx_signer: Option<Vec<Vec<u8>>>, | ||
|
||
/// Values for `features`. | ||
#[serde(default)] | ||
#[serde(deserialize_with = "from_features")] | ||
pub features: Option<u64>, | ||
|
||
/// Value allowed for `cpusvn`. | ||
pub cpu_svn: Option<Vec<u8>>, | ||
|
||
/// Value for `isv_svn`, do not allow versions below this. | ||
pub enclave_security_version: Option<u16>, | ||
|
||
/// Value for `isv_prodid`, do not allow versions below this. | ||
pub enclave_product_id: Option<u16>, | ||
} | ||
|
||
fn from_hex<'de, D>(deserializer: D) -> Result<Option<Vec<Vec<u8>>>, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let s: Vec<&str> = Deserialize::deserialize(deserializer)?; | ||
|
||
let mut outer_vec = Vec::new(); | ||
for hash_string in s { | ||
outer_vec.push(hex::decode(hash_string).map_err(|_| Error::custom("invalid hex"))?); | ||
} | ||
|
||
Ok(Some(outer_vec)) | ||
} | ||
|
||
fn from_features<'de, D>(deserializer: D) -> Result<Option<u64>, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let s: &str = Deserialize::deserialize(deserializer)?; | ||
|
||
let mut flags = Features::empty(); | ||
|
||
flags |= Features::INIT; // Must be set | ||
flags |= Features::MODE64BIT; // Isn't everything 64-bit? | ||
|
||
for flag in s.to_string().split("|") { | ||
match flag.trim() { | ||
"CET" => { | ||
flags = flags | Features::CET; | ||
} | ||
"Debug" => { | ||
flags = flags | Features::DEBUG; | ||
} | ||
"Eint_Key" => { | ||
flags = flags | Features::EINIT_KEY; | ||
} | ||
"KSS" => { | ||
flags = flags | Features::KSS; | ||
} | ||
"Provisioning_Key" => { | ||
flags = flags | Features::PROVISIONING_KEY; | ||
} | ||
_ => return Err(D::Error::custom(format!("unknown flag '{}'", flag))), | ||
} | ||
} | ||
|
||
Ok(Some(flags.bits())) | ||
} | ||
|
||
impl Into<Features> for &Config { | ||
fn into(self) -> Features { | ||
match self.features { | ||
Some(f) => Features::from_bits_truncate(f), | ||
None => Features::empty(), | ||
} | ||
} | ||
} | ||
|
||
impl Config { | ||
pub fn features(&self) -> Features { | ||
self.into() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::config::Config; | ||
|
||
#[test] | ||
fn test_empty_config() { | ||
let config_raw = r#" | ||
"#; | ||
|
||
let config_obj: Config = toml::from_str(config_raw).expect("Couldn't deserialize"); | ||
assert!(config_obj.enarx_signer.is_none()); | ||
assert!(config_obj.enclave_security_version.is_none()); | ||
assert!(config_obj.cpu_svn.is_none()); | ||
} | ||
|
||
#[test] | ||
fn test_list_of_hashes() { | ||
let config_raw = r#" | ||
enarx_signer = ["1234567890", "00112233445566778899"] | ||
"#; | ||
|
||
let config_obj: Config = toml::from_str(config_raw).expect("Couldn't deserialize"); | ||
assert!(config_obj.enarx_signer.is_some()); | ||
assert_eq!(config_obj.enarx_signer.clone().unwrap().len(), 2); | ||
assert_eq!( | ||
config_obj.enarx_signer.clone().unwrap().first().unwrap(), | ||
&hex::decode("1234567890").unwrap() | ||
); | ||
assert_eq!( | ||
config_obj.enarx_signer.unwrap().get(1).unwrap(), | ||
&hex::decode("00112233445566778899").unwrap() | ||
); | ||
assert!(config_obj.cpu_svn.is_none()); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.