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

keymanager: Add mock trusted signers for debug mock SGX builds #5852

Merged
merged 1 commit into from
Sep 13, 2024
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
1 change: 1 addition & 0 deletions .changelog/5852.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keymanager: Add mock trusted signers for debug mock SGX builds
34 changes: 33 additions & 1 deletion keymanager/src/policy/signers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,38 @@ pub struct TrustedSigners {
pub threshold: u64,
}

#[cfg(feature = "debug-mock-sgx")]
impl TrustedSigners {
/// An UNSAFE set of trusted signers using well-known debug keys.
pub fn unsafe_mock() -> Self {
use oasis_core_runtime::{
common::crypto::signature::PrivateKey as OasisPrivateKey, BUILD_INFO,
};

// Do a runtime check to ensure that this is only ever called in debug builds to avoid any
// use of this set in production. Note that this is implied by debug-mock-sgx feature.
assert!(!BUILD_INFO.is_secure);

Self {
signers: {
let mut set = HashSet::new();
for seed in [
"ekiden key manager test multisig key 0",
"ekiden key manager test multisig key 1",
"ekiden key manager test multisig key 2",
]
.iter()
{
let private_key = OasisPrivateKey::from_test_seed(seed.to_string());
set.insert(private_key.public_key());
}
set
},
threshold: 2,
}
}
}

impl Default for TrustedSigners {
fn default() -> Self {
Self {
Expand All @@ -29,7 +61,7 @@ impl Default for TrustedSigners {

impl TrustedSigners {
/// Verifies that signed data has valid signatures and that enough of them
// are from trusted signers.
/// are from trusted signers.
pub fn verify<'a, P>(&self, signed_data: &'a impl SignedData<P>) -> Result<&'a P> {
let data = signed_data.verify()?;
self.verify_trusted_signers(signed_data)?;
Expand Down
Loading