Skip to content

Commit

Permalink
Merge pull request #5852 from oasisprotocol/kostko/feature/debug-mock…
Browse files Browse the repository at this point in the history
…-signers

keymanager: Add mock trusted signers for debug mock SGX builds
  • Loading branch information
kostko authored Sep 13, 2024
2 parents c3e7d2d + 28736a2 commit d6d15d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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

0 comments on commit d6d15d5

Please sign in to comment.