Skip to content

Commit c687921

Browse files
author
vlad
committed
on-chain machine-id WIP(1)
1 parent c3f8e4b commit c687921

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

cosmwasm/enclaves/execute/src/registration/attestation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use core::{mem, slice};
22

33
use base64ct::Encoding;
44
use enclave_crypto::dcap::verify_quote_any;
5+
use log::*;
6+
use rsa::signature::Verifier;
57
use serde_json::Value;
68
use sha2::{Digest, Sha256};
79
use std::collections::{HashMap, HashSet};
810
use std::convert::TryFrom;
911
use std::io::Write;
12+
use std::sync::SgxMutex;
1013
use std::untrusted::fs::File;
1114
use std::vec::Vec;
1215

13-
use log::*;
14-
use rsa::signature::Verifier;
15-
1616
#[cfg(feature = "SGX_MODE_HW")]
1717
use sgx_tse::rsgx_create_report;
1818

@@ -142,7 +142,7 @@ lazy_static::lazy_static! {
142142
keys
143143
};
144144

145-
static ref PPID_WHITELIST: HashSet<[u8; 20]> = {
145+
pub static ref PPID_WHITELIST: SgxMutex<HashSet<[u8; 20]>> = {
146146
let mut set: HashSet<[u8; 20]> = HashSet::new();
147147

148148
set.insert([0x01,0x50,0x7c,0x95,0x77,0x89,0xb7,0xc1,0xaf,0xde,0x97,0x2d,0x67,0xf1,0xfd,0xd5,0x3a,0xf1,0xa8,0xda]);
@@ -257,7 +257,7 @@ lazy_static::lazy_static! {
257257
set.insert([0xfe,0xc9,0x34,0x2e,0x9e,0xe4,0x18,0x64,0x53,0xf8,0xa7,0xe0,0x27,0xfa,0xc8,0xc2,0x4e,0x7c,0x0c,0x60]);
258258

259259

260-
set
260+
SgxMutex::new(set)
261261
};
262262

263263
static ref FMSPC_EOL: HashSet<&'static str> = HashSet::from([
@@ -661,7 +661,7 @@ pub fn verify_quote_sgx(
661661
Some(ppid) => {
662662
let ppid_addr = crate::registration::offchain::calculate_truncated_hash(&ppid);
663663

664-
let wl = &PPID_WHITELIST;
664+
let wl = PPID_WHITELIST.lock().unwrap();
665665
if wl.contains(&ppid_addr) {
666666
true
667667
} else {

cosmwasm/enclaves/execute/src/registration/offchain.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,30 @@ pub unsafe extern "C" fn ecall_onchain_approve_machine_id(
730730
validate_const_ptr!(p_id, n_id as usize, sgx_status_t::SGX_ERROR_UNEXPECTED);
731731
validate_mut_ptr!(p_proof, 32, sgx_status_t::SGX_ERROR_UNEXPECTED);
732732

733-
// TODO: ensure message was in the signed block
734-
let proof = calculate_machine_id_evidence(slice::from_raw_parts(p_id, n_id as usize));
733+
if n_id != 20 {
734+
println!("machine_id wrong len");
735+
return sgx_types::sgx_status_t::SGX_ERROR_UNEXPECTED;
736+
}
737+
738+
let machine_id = slice::from_raw_parts(p_id, n_id as usize);
739+
let proof = calculate_machine_id_evidence(machine_id);
740+
741+
if is_on_chain {
742+
// TODO: ensure message was in the signed block
743+
slice::from_raw_parts_mut(p_proof, HASH_SIZE).copy_from_slice(&proof);
744+
} else {
745+
// compare
746+
if proof != slice::from_raw_parts(p_proof, HASH_SIZE) {
747+
return sgx_types::sgx_status_t::SGX_ERROR_UNEXPECTED;
748+
}
749+
}
735750

736-
slice::from_raw_parts_mut(p_proof, HASH_SIZE).copy_from_slice(&proof);
751+
{
752+
let mut set = crate::registration::attestation::PPID_WHITELIST
753+
.lock()
754+
.unwrap();
755+
set.insert(machine_id.try_into().unwrap());
756+
}
737757

738758
sgx_types::sgx_status_t::SGX_SUCCESS
739759
}

0 commit comments

Comments
 (0)