-
Notifications
You must be signed in to change notification settings - Fork 93
Implemented Key Sharing and Seperation Config id Feature for Singleton. #731
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,9 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import json | ||
| import time | ||
| import random | ||
| import logging | ||
|
|
||
| from ssl import SSLError | ||
|
|
@@ -23,27 +23,29 @@ | |
| import utility.hex_utils as hex_utils | ||
| import utility.file_utils as file_utils | ||
| import avalon_enclave_manager.kme.kme_enclave as enclave | ||
| from avalon_enclave_manager.base_enclave_info import BaseEnclaveInfo | ||
| import avalon_enclave_manager.base_enclave_info as enclave_info | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class KeyManagementEnclaveInfo(BaseEnclaveInfo): | ||
| class KeyManagementEnclaveInfo(enclave_info.BaseEnclaveInfo): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit message says config id feature for singleton but KME is also touched. Change commit message accordingly. |
||
| """ | ||
| KME info class to initialize enclave, signup enclave and hold | ||
| data obtained post signup. | ||
| """ | ||
|
|
||
| # ------------------------------------------------------- | ||
| def __init__(self, config, worker_id, enlcave_type): | ||
| def __init__(self, config, worker_id): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any reason why enclave_type is removed? |
||
|
|
||
| enclave._SetLogger(logger) | ||
| super().__init__(config, enlcave_type) | ||
| super().__init__(enclave.is_sgx_simulator()) | ||
|
|
||
| self._config = config | ||
| self._worker_id = worker_id | ||
| self._initialize_enclave() | ||
| enclave_info = self._create_enclave_signup_data() | ||
| try: | ||
| self.ias_nonce = enclave_info['ias_nonce'] | ||
| self.sealed_data = enclave_info['sealed_data'] | ||
| self.verifying_key = enclave_info['verifying_key'] | ||
| self.encryption_key = enclave_info['encryption_key'] | ||
|
|
@@ -66,43 +68,52 @@ def _create_enclave_signup_data(self): | |
| @returns enclave_info - A dictionary of enclave data | ||
| """ | ||
|
|
||
| ias_nonce = '{0:032X}'.format(random.getrandbits(128)) | ||
| try: | ||
| enclave_data = self._create_signup_info() | ||
| enclave_data = self._create_signup_info(ias_nonce) | ||
| except Exception as err: | ||
| raise Exception('failed to create enclave signup data; {}' | ||
| .format(str(err))) | ||
|
|
||
| enclave_info = dict() | ||
| enclave_info['ias_nonce'] = ias_nonce | ||
| enclave_info['sealed_data'] = enclave_data.sealed_signup_data | ||
| enclave_info['verifying_key'] = enclave_data.verifying_key | ||
| enclave_info['encryption_key'] = enclave_data.encryption_key | ||
| enclave_info['encryption_key_signature'] = \ | ||
| enclave_data.encryption_key_signature | ||
| enclave_info['enclave_id'] = enclave_data.verifying_key | ||
| enclave_info['proof_data'] = '' | ||
| if not self.is_sgx_simulator(): | ||
| if not enclave.is_sgx_simulator(): | ||
| enclave_info['proof_data'] = enclave_data.proof_data | ||
|
|
||
| return enclave_info | ||
|
|
||
| # ----------------------------------------------------------------- | ||
|
|
||
| def _create_signup_info(self): | ||
| def _create_signup_info(self, ias_nonce): | ||
| """ | ||
| Create enclave signup data | ||
|
|
||
| Parameters : | ||
| @param ias_nonce - Used in IAS request to verify attestation | ||
| as a distinguishing factor | ||
| Returns : | ||
| @returns signup_info_obj - Signup info data | ||
| """ | ||
|
|
||
| # Part of what is returned with the signup data is an enclave quote, we | ||
| # want to update the revocation list first. | ||
| self._update_sig_rl() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function is specific epid attestation and it is moved to epid file , usage should go that file |
||
| # Now, let the enclave create the signup data | ||
|
|
||
| signup_cpp_obj = enclave.SignupInfoKME() | ||
|
|
||
| if "wpe_mrenclave" in self._config: | ||
| self._wpe_mrenclave = self._config["wpe_mrenclave"] | ||
| else: | ||
| tcf_home = os.environ.get("TCF_HOME", '../../../') | ||
| self._wpe_mrenclave = hex_utils.mrenclave_hex_string( | ||
| tcf_home + "/" | ||
| enclave_info.TCF_HOME + "/" | ||
| + self._config["wpe_mrenclave_read_from_file"]) | ||
|
|
||
| # @TODO : Passing in_ext_data_signature as empty string "" as of now | ||
|
|
@@ -112,7 +123,7 @@ def _create_signup_info(self): | |
| return None | ||
|
|
||
| signup_info = self._get_signup_info( | ||
| signup_data, signup_cpp_obj) | ||
| signup_data, signup_cpp_obj, ias_nonce) | ||
|
|
||
| # Now we can finally serialize the signup info and create a | ||
| # corresponding signup info object. Because we don't want the | ||
|
|
@@ -167,14 +178,15 @@ def _init_enclave_with(self, signed_enclave): | |
|
|
||
| Parameters : | ||
| @param signed_enclave - The enclave binary read from filesystem | ||
| @param config - A dictionary of configurations | ||
| Returns : | ||
| @returns tcf_enclave_info - An instance of the tcf_enclave_info | ||
| """ | ||
| # Get sealed data if persisted from previous startup. | ||
| persisted_sealed_data = file_utils.read_file( | ||
| self._get_sealed_data_file_name(self._config["sealed_data_path"], | ||
| self._worker_id)) | ||
| return self._attestation.init_enclave_info( | ||
| return enclave.tcf_enclave_info( | ||
| signed_enclave, persisted_sealed_data, | ||
| int(self._config['num_of_enclaves'])) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,15 +70,21 @@ namespace tcf { | |
| // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
| void Enclave::Load( | ||
| const std::string& inEnclaveFilePath, | ||
| const Base64EncodedString& inSealedEnclaveData) { | ||
| const Base64EncodedString& inSealedEnclaveData, | ||
| const uint8_t (&kss_config_id)[SGX_CONFIGID_SIZE]) { | ||
| tcf::error::ThrowIf<tcf::error::ValueError>( | ||
| inEnclaveFilePath.empty() || | ||
| inEnclaveFilePath.length() > PATH_MAX, | ||
| "Invalid enclave path."); | ||
|
|
||
| this->Unload(); | ||
| this->enclaveFilePath = inEnclaveFilePath; | ||
| for(int i=0; i <SGX_CONFIGID_SIZE;i++ ){ | ||
| this->_kss_config[i] = kss_config_id[i]; | ||
| } | ||
|
|
||
| this->LoadEnclave(inSealedEnclaveData); | ||
|
|
||
| } // Enclave::Load | ||
|
|
||
| // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
|
|
@@ -114,6 +120,11 @@ namespace tcf { | |
| "Attestation object is not initialized" | ||
| ); | ||
| this->attestation->CreateQuoteFromReport(inEnclaveReport, outEnclaveQuote); | ||
|
|
||
| sgx_quote_t* enclaveQuote = | ||
| reinterpret_cast<sgx_quote_t *>(&outEnclaveQuote[0]); | ||
| tcf::Log(TCF_LOG_INFO,"KSS Config Id added to the EnclaveQuote : %s\n", enclaveQuote->report_body.config_id ); | ||
|
|
||
| } // Enclave::GenerateSignupData | ||
|
|
||
|
|
||
|
|
@@ -137,7 +148,6 @@ namespace tcf { | |
| if (!this->enclaveId) { | ||
| /* Enclave id, used in communicating with enclave */ | ||
| Enclave::QuerySgxStatus(); | ||
|
|
||
| sgx_launch_token_t token = { 0 }; | ||
| int flags = SGX_DEBUG_FLAG; | ||
| tcf::error::ThrowSgxError((SGX_DEBUG_FLAG == 0 ? | ||
|
|
@@ -147,7 +157,9 @@ namespace tcf { | |
|
|
||
| // First attempt to load the enclave executable | ||
| sgx_status_t ret = SGX_SUCCESS; | ||
| ret = tcf::sgx_util::CallSgx([this, flags, &token] () { | ||
| if(this->_kss_config[0] == NULL){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we checking only index 0, is that sufficient? |
||
|
|
||
| ret = tcf::sgx_util::CallSgx([this, flags, &token] () { | ||
| int updated = 0; | ||
| return sgx_create_enclave( | ||
| this->enclaveFilePath.c_str(), | ||
|
|
@@ -160,7 +172,30 @@ namespace tcf { | |
| 10, // retries | ||
| 250 // retryWaitMs | ||
| ); | ||
| tcf::error::ThrowSgxError(ret, "Unable to create enclave."); | ||
| tcf::error::ThrowSgxError(ret, "Unable to create enclave."); | ||
|
|
||
| } else { | ||
| tcf::Log(TCF_LOG_INFO, "Enclave::sgx_create_enclave_ex called" ); | ||
| void *enclave_ex_p[32] = { 0 }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use constant instead of hard coded value 32, may be sgx sdk or create one. |
||
| enclave_ex_p[SGX_CREATE_ENCLAVE_EX_KSS_BIT_IDX] = &this->_kss_config; | ||
|
|
||
| ret = tcf::sgx_util::CallSgx([this, flags, &token, enclave_ex_p] () { | ||
| int updated = 0; | ||
| return sgx_create_enclave_ex( | ||
| this->enclaveFilePath.c_str(), | ||
| flags, | ||
| &token, | ||
| &updated, | ||
| &this->enclaveId, | ||
| NULL, | ||
| SGX_CREATE_ENCLAVE_EX_KSS, | ||
| (const void** )enclave_ex_p); | ||
| }, | ||
| 10, // retries | ||
| 250 // retryWaitMs | ||
| ); | ||
| tcf::error::ThrowSgxError(ret, "Unable to create enclave with Config id"); | ||
| } | ||
| // Initialize the enclave | ||
| tcf_err_t tcfError = TCF_SUCCESS; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to display kss_config in log?