Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

Commit c05ba1c

Browse files
committed
feat(rtc_uenclave::enclaves::rtc_auth): expose the save_access_key ECALL
1 parent 80def4f commit c05ba1c

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

rtc_uenclave/src/enclaves/rtc_auth.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::borrow::Borrow;
22

3-
use crate::{AttestationError, EnclaveConfig, EnclaveReportResult, RtcEnclave};
43
use auth_sys::AuthSys;
4+
use rtc_types::enclave_messages::set_access_key;
55
use sgx_types::*;
66

7+
use crate::{AttestationError, EnclaveConfig, EnclaveReportResult, RtcEnclave};
8+
79
/// Wraps all the functionality for interacting with the auth enclave
810
pub struct RtcAuthEnclave<TCfg>(RtcEnclave<TCfg, AuthSys>)
911
where
@@ -33,6 +35,17 @@ where
3335
self.0.dcap_attestation_azure()
3436
}
3537

38+
/// Save the generated access key for some data.
39+
///
40+
/// This should be called from the data enclave with messages encrypted
41+
/// using an established protected channel.
42+
pub fn save_access_key(
43+
&self,
44+
encrypted_request: set_access_key::EncryptedRequest,
45+
) -> Result<set_access_key::SetAccessKeyResult, sgx_status_t> {
46+
ecalls::save_access_key(self.0.geteid(), encrypted_request)
47+
}
48+
3649
/// Take ownership of self and drop resources
3750
pub fn destroy(self) {
3851
// Take ownership of self and drop
@@ -48,3 +61,32 @@ where
4861
self.0.geteid()
4962
}
5063
}
64+
65+
mod ecalls {
66+
//! Rust-friendly wrappers for the Edger8r-generated untrusted ECALL bridge functions.
67+
68+
use auth_sys::ffi;
69+
use rtc_types::enclave_messages::{ffi_set_access_key, set_access_key};
70+
use sgx_types::{sgx_enclave_id_t, sgx_status_t};
71+
72+
/// Implement [`super::RtcAuthEnclave::save_access_key`].
73+
///
74+
/// This takes care of converting between the [`set_access_key`] and [`ffi_set_access_key`] types.
75+
pub(crate) fn save_access_key(
76+
eid: sgx_enclave_id_t,
77+
encrypted_request: set_access_key::EncryptedRequest,
78+
) -> Result<set_access_key::SetAccessKeyResult, sgx_status_t> {
79+
let mut retval = ffi_set_access_key::SetAccessKeyResult::default();
80+
let encrypted_request: ffi_set_access_key::SetAccessKeyEncryptedRequest =
81+
encrypted_request.into();
82+
83+
// Safety: Copies ffi_set_access_key::SetAccessKeyResult into retval,
84+
// but only valid for sgx_status_t::SGX_SUCCESS.
85+
let status = unsafe { ffi::rtc_auth_save_access_key(eid, &mut retval, encrypted_request) };
86+
87+
match status {
88+
sgx_status_t::SGX_SUCCESS => Ok(set_access_key::SetAccessKeyResult::from(retval)),
89+
err => Err(err),
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)