Skip to content

Commit d7dd358

Browse files
authored
Merge pull request #1648 from scrtlabs/dcap-07
Dcap 07
2 parents aefec61 + 3f497f7 commit d7dd358

File tree

9 files changed

+411
-455
lines changed

9 files changed

+411
-455
lines changed

check-hw/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

check-hw/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ enclave-ffi-types = { path = "../cosmwasm/enclaves/ffi-types", features = [
2323
clap = "2.33"
2424
parking_lot = "0.11"
2525
lazy_static = "1.4"
26+
log = "0.4.17"

check-hw/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ fn main() {
1111
println!("cargo:rustc-link-lib=static=sgx_ukey_exchange");
1212
println!("cargo:rustc-link-lib=dylib=sgx_urts");
1313
println!("cargo:rustc-link-lib=dylib=sgx_uae_service");
14+
15+
println!("cargo:rustc-link-lib=dylib=sgx_dcap_ql");
16+
println!("cargo:rustc-link-lib=dylib=sgx_dcap_quoteverify");
1417
}

check-hw/src/enclave_api.rs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use sgx_types::{
1313
sgx_report_t, sgx_spid_t, sgx_status_t, sgx_target_info_t, sgx_update_info_bit_t,
1414
};
1515

16+
include!("../../cosmwasm/packages/sgx-vm/src/attestation_dcap.rs");
17+
1618
// ecalls
1719

1820
extern "C" {
@@ -186,53 +188,3 @@ pub extern "C" fn ocall_read_db(
186188
pub extern "C" fn ocall_allocate(_buffer: *const u8, _length: usize) -> UserSpaceBuffer {
187189
unimplemented!()
188190
}
189-
190-
#[no_mangle]
191-
pub extern "C" fn ocall_get_quote_ecdsa_params(
192-
ret_val: *mut sgx_status_t,
193-
p_qe_info: *mut sgx_target_info_t,
194-
p_quote_size: *mut u32,
195-
) -> sgx_status_t {
196-
unimplemented!()
197-
}
198-
#[no_mangle]
199-
pub extern "C" fn ocall_get_quote_ecdsa(
200-
ret_val: *mut sgx_status_t,
201-
p_report: *const sgx_report_t,
202-
p_quote: *mut u8,
203-
n_quote: u32,
204-
) -> sgx_status_t {
205-
unimplemented!()
206-
}
207-
208-
#[no_mangle]
209-
pub extern "C" fn ocall_get_quote_ecdsa_collateral(
210-
ret_val: *mut sgx_status_t,
211-
p_quote: *const u8,
212-
n_quote: u32,
213-
p_col: *mut u8,
214-
n_col: u32,
215-
p_col_out: *mut u32,
216-
) -> sgx_status_t {
217-
unimplemented!()
218-
}
219-
220-
#[no_mangle]
221-
pub extern "C" fn ocall_verify_quote_ecdsa(
222-
ret_val: *mut sgx_status_t,
223-
p_quote: *const u8,
224-
n_quote: u32,
225-
p_col: *const u8,
226-
n_col: u32,
227-
p_target_info: *const sgx_target_info_t,
228-
time_s: i64,
229-
p_qve_report_info: *mut sgx_ql_qe_report_info_t,
230-
p_supp_data: *mut u8,
231-
n_supp_data: u32,
232-
p_supp_data_size: *mut u32,
233-
p_time_s: *mut i64,
234-
p_collateral_expiration_status: *mut u32,
235-
p_qv_result: *mut sgx_ql_qv_result_t,
236-
) -> sgx_status_t {
237-
unimplemented!()
238-
}

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

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -166,46 +166,11 @@ pub fn validate_enclave_version(
166166
sgx_status_t::SGX_ERROR_UNEXPECTED
167167
})?;
168168

169-
// let timestamp = crate::registration::report::AttestationReport::from_cert(&cert_der)
170-
// .map_err(|_| sgx_status_t::SGX_ERROR_UNEXPECTED)?
171-
// .timestamp;
172-
173-
// if result.is_err() && in_grace_period(timestamp) {
174-
// let ecc_handle = SgxEccHandle::new();
175-
// let _result = ecc_handle.open();
176-
//
177-
// // use ephemeral key
178-
// let (prv_k, pub_k) = ecc_handle.create_key_pair().unwrap();
179-
//
180-
// // call create_report using the secp256k1 public key, and __not__ the P256 one
181-
// let signed_report =
182-
// match create_attestation_report(&kp.get_pubkey(), sign_type, api_key, challenge, false)
183-
// {
184-
// Ok(r) => r,
185-
// Err(e) => {
186-
// error!("Error creating attestation report");
187-
// return Err(e);
188-
// }
189-
// };
190-
//
191-
// let payload: String = serde_json::to_string(&signed_report).map_err(|_| {
192-
// error!("Error serializing report. May be malformed, or badly encoded");
193-
// sgx_status_t::SGX_ERROR_UNEXPECTED
194-
// })?;
195-
// let (_key_der, cert_der) = super::cert::gen_ecc_cert(payload, &prv_k, &pub_k, &ecc_handle)?;
196-
// let _result = ecc_handle.close();
197-
//
198-
// let verify_result = verify_ra_cert(&cert_der, None, false);
199-
// if verify_result.is_err() {
200-
// #[cfg(all(feature = "SGX_MODE_HW", feature = "production"))]
201-
// remove_all_keys();
202-
// }
203-
// } else
204-
205169
let (_key_der, cert_der) = super::cert::gen_ecc_cert(payload, &prv_k, &pub_k, &ecc_handle)?;
206170
let _result = ecc_handle.close();
171+
207172
if verify_ra_cert(&cert_der, None, true).is_err() {
208-
remove_all_keys();
173+
sgx_status_t::SGX_ERROR_UNEXPECTED
209174
}
210175

211176
Ok(())

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use crate::registration::attestation::create_attestation_report;
1414
#[cfg(feature = "SGX_MODE_HW")]
1515
use crate::registration::cert::verify_quote_status;
1616

17+
#[cfg(feature = "SGX_MODE_HW")]
18+
use crate::registration::offchain::get_attestation_report_dcap;
19+
1720
#[cfg(not(feature = "epid_whitelist_disabled"))]
1821
use crate::registration::cert::check_epid_gid_is_whitelisted;
1922

@@ -52,6 +55,12 @@ pub unsafe extern "C" fn ecall_check_patch_level(
5255
// generate temporary key for attestation
5356
let temp_key_result = enclave_crypto::KeyPair::new().unwrap();
5457

58+
let res_dcap = unsafe { get_attestation_report_dcap(&temp_key_result) };
59+
if res_dcap.is_ok() {
60+
println!("DCAP attestation ok");
61+
return NodeAuthResult::Success;
62+
}
63+
5564
let signed_report = match create_attestation_report(
5665
&temp_key_result.get_pubkey(),
5766
SIGNATURE_TYPE,

0 commit comments

Comments
 (0)