123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #ifndef __GNUC__
- #include "StdAfx.h"
- #include <intrin.h>
- #endif
- #include <assert.h>
- #include "PCEClass.h"
- #include "QEClass.h"
- #include "PVEClass.h"
- #include "util.h"
- #include "prof_fun.h"
- #include "sgx_report.h"
- #include "sgx_tseal.h"
- #include "epid_pve_type.h"
- #include "pce_u.h"
- #include "pce_u.c"
- void CPCEClass::before_enclave_load() {
-
- CQEClass::instance().unload_enclave();
- CPVEClass::instance().unload_enclave();
- }
- uint32_t CPCEClass::get_pce_target(
- sgx_target_info_t *p_pce_target)
- {
- token_t *p_token =
- reinterpret_cast<token_t *>(&m_launch_token);
-
- assert(m_enclave_id);
- memset(p_pce_target, 0, sizeof(sgx_target_info_t));
- memcpy_s(&p_pce_target->attributes, sizeof(p_pce_target->attributes),
- &m_attributes.secs_attr, sizeof(m_attributes.secs_attr));
- memcpy_s(&p_pce_target->misc_select, sizeof(p_pce_target->misc_select),
- &m_attributes.misc_select, sizeof(m_attributes.misc_select));
- memcpy_s(&p_pce_target->mr_enclave, sizeof(p_pce_target->mr_enclave),
- &p_token->body.mr_enclave,
- sizeof(p_token->body.mr_enclave));
- return AE_SUCCESS;
- }
- uint32_t CPCEClass::get_pce_info(const sgx_report_t& report, const signed_pek_t& pek, uint16_t& pce_id, uint16_t& isv_svn, uint8_t encrypted_ppid[PEK_MOD_SIZE])
- {
- sgx_status_t status = SGX_SUCCESS;
- uint32_t ret_val = 0;
- uint32_t ret_size = PEK_MOD_SIZE;
- int retry = 0;
- pce_info_t pce_info;
- uint8_t signature_scheme;
- AESM_PROFILE_FUN;
- if (m_enclave_id == 0){
- AESM_DBG_ERROR("call get_pc_info without loading PCE");
- return AE_FAILURE;
- }
- status = ::get_pc_info(m_enclave_id, &ret_val, &report, (uint8_t*)&pek, static_cast<uint32_t>(PEK_MOD_SIZE + sizeof(pek.e)), ALG_RSA_OAEP_3072, encrypted_ppid, PEK_MOD_SIZE, &ret_size, &pce_info, &signature_scheme);
- for(; status == SGX_ERROR_ENCLAVE_LOST && retry < AESM_RETRY_COUNT; retry++)
- {
- unload_enclave();
- if(AE_SUCCESS != load_enclave())
- return AE_FAILURE;
- status = ::get_pc_info(m_enclave_id, &ret_val, &report, (uint8_t*)&pek, static_cast<uint32_t>(PEK_MOD_SIZE + sizeof(pek.e)), ALG_RSA_OAEP_3072, encrypted_ppid, PEK_MOD_SIZE, &ret_size, &pce_info, &signature_scheme);
- }
- if(status != SGX_SUCCESS)
- return AE_FAILURE;
- if (ret_val != AE_SUCCESS)
- return ret_val;
- if(signature_scheme != NIST_P256_ECDSA_SHA256){
- return AE_FAILURE;
- }
- if(ret_size != PEK_MOD_SIZE){
- return AE_FAILURE;
- }
- pce_id = pce_info.pce_id;
- isv_svn = pce_info.pce_isvn;
- return AE_SUCCESS;
- }
- uint32_t CPCEClass::sign_report(const psvn_t& cert_psvn, const sgx_report_t& report, uint8_t signed_sign[2*SE_ECDSA_SIGN_SIZE])
- {
- sgx_status_t status = SGX_SUCCESS;
- uint32_t ret_val = 0;
- uint32_t ret_size = 2*SE_ECDSA_SIGN_SIZE;
- int retry = 0;
- AESM_PROFILE_FUN;
- if (m_enclave_id == 0){
- AESM_DBG_ERROR("call certify_enclave without loading PCE");
- return AE_FAILURE;
- }
- status = ::certify_enclave(m_enclave_id, &ret_val, &cert_psvn, &report, signed_sign, 2*SE_ECDSA_SIGN_SIZE, &ret_size);
- for(; status == SGX_ERROR_ENCLAVE_LOST && retry < AESM_RETRY_COUNT; retry++)
- {
- unload_enclave();
- if(AE_SUCCESS != load_enclave())
- return AE_FAILURE;
- status = ::certify_enclave(m_enclave_id, &ret_val, &cert_psvn, &report, signed_sign, 2*SE_ECDSA_SIGN_SIZE, &ret_size);
- }
- if(status != SGX_SUCCESS)
- return AE_FAILURE;
- if(ret_val != AE_SUCCESS){
- return ret_val;
- }
- if(ret_size != 2*SE_ECDSA_SIGN_SIZE)
- return AE_FAILURE;
- return AE_SUCCESS;
- }
|