aesm_logic.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /*
  2. * Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include "QEClass.h"
  32. #include "LEClass.h"
  33. #include "PVEClass.h"
  34. #include "arch.h"
  35. #include "sgx_report.h"
  36. #include "sgx_tseal.h"
  37. #include "epid_pve_type.h"
  38. #include "util.h"
  39. #include <assert.h>
  40. #include <time.h>
  41. #include "oal/oal.h"
  42. #include "oal/aesm_thread.h"
  43. #include "aesm_encode.h"
  44. #include "aesm_epid_blob.h"
  45. #include "aesm_logic.h"
  46. #include "pve_logic.h"
  47. #include "qe_logic.h"
  48. #include "platform_info_logic.h"
  49. #include "prov_msg_size.h"
  50. #include "se_sig_rl.h"
  51. #include "se_quote_internal.h"
  52. #include "endpoint_select_info.h"
  53. #include "se_wrapper.h"
  54. #include "ippcp.h"
  55. #include "ippcore.h"
  56. #include <time.h>
  57. #include <string>
  58. #include "ippcp.h"
  59. #include "ippcore.h"
  60. #include "prof_fun.h"
  61. #include "aesm_long_lived_thread.h"
  62. #include "sgx_profile.h"
  63. #define CHECK_SERVICE_STATUS if (!is_service_running()) return AESM_SERVICE_STOPPED;
  64. #define CHECK_SGX_STATUS if (g_sgx_device_status != SGX_ENABLED) return AESM_SGX_DEVICE_NOT_AVAILABLE;
  65. AESMLogicMutex AESMLogic::_qe_pve_mutex;
  66. AESMLogicMutex AESMLogic::_pse_mutex;
  67. AESMLogicMutex AESMLogic::_le_mutex;
  68. bool AESMLogic::_is_qe_psvn_set;
  69. bool AESMLogic::_is_pse_psvn_set;
  70. psvn_t AESMLogic::_qe_psvn;
  71. psvn_t AESMLogic::_pse_psvn;
  72. static ae_error_t thread_to_load_qe(aesm_thread_arg_type_t arg)
  73. {
  74. epid_blob_with_cur_psvn_t epid_data;
  75. ae_error_t ae_ret = AE_FAILURE;
  76. UNUSED(arg);
  77. AESM_DBG_TRACE("start to load qe");
  78. memset(&epid_data, 0, sizeof(epid_data));
  79. AESMLogicLock lock(AESMLogic::_qe_pve_mutex);
  80. if((ae_ret = EPIDBlob::instance().read(epid_data)) == AE_SUCCESS)
  81. {
  82. AESM_DBG_TRACE("EPID blob is read successfully, loading QE ...");
  83. ae_ret = CQEClass::instance().load_enclave();
  84. if(AE_SUCCESS != ae_ret)
  85. {
  86. AESM_DBG_WARN("fail to load QE: %d", ae_ret);
  87. }else{
  88. AESM_DBG_TRACE("QE loaded successfully");
  89. }
  90. }
  91. AESM_DBG_TRACE("QE Thread finished succ");
  92. return AE_SUCCESS;
  93. }
  94. // Must be called when AESM starts
  95. ae_error_t AESMLogic::service_start()
  96. {
  97. AESM_PROFILE_INIT;
  98. ae_error_t ae_ret = AE_SUCCESS;
  99. AESM_LOG_INIT();
  100. //ippInit();//no ippInit available for c version ipp
  101. AESM_DBG_INFO("aesm service is starting");
  102. ae_ret = CLEClass::instance().load_enclave();
  103. if(AE_SUCCESS != ae_ret)
  104. {
  105. AESM_DBG_INFO("fail to load LE: %d", ae_ret);
  106. AESM_LOG_FATAL("%s", g_event_string_table[SGX_EVENT_SERVICE_UNAVAILABLE]);
  107. return ae_ret;
  108. }
  109. aesm_thread_t qe_thread=NULL;
  110. ae_error_t aesm_ret1 = aesm_create_thread(thread_to_load_qe, 0,&qe_thread);
  111. if(AE_SUCCESS != aesm_ret1 ){
  112. AESM_DBG_WARN("Fail to create thread to preload QE:%d",aesm_ret1);
  113. }else{
  114. (void)aesm_free_thread(qe_thread);//release thread handle to free memory
  115. }
  116. AESM_DBG_TRACE("aesm service is started");
  117. return AE_SUCCESS;
  118. }
  119. void AESMLogic::service_stop()
  120. {
  121. CPVEClass::instance().unload_enclave();
  122. CQEClass::instance().unload_enclave();
  123. CLEClass::instance().unload_enclave();
  124. stop_all_long_lived_threads();
  125. AESM_DBG_INFO("aesm service down");
  126. AESM_LOG_FINI();
  127. AESM_PROFILE_OUTPUT;
  128. }
  129. bool AESMLogic::is_service_running()
  130. {
  131. return true;
  132. }
  133. ae_error_t AESMLogic::save_unverified_white_list(const uint8_t *white_list_cert, uint32_t white_list_cert_size)
  134. {
  135. wl_cert_chain_t old_cert;
  136. const wl_cert_chain_t *p_new_cert = reinterpret_cast<const wl_cert_chain_t *>(white_list_cert);
  137. uint32_t old_cert_size = sizeof(old_cert);
  138. memset(&old_cert, 0, sizeof(old_cert));
  139. if((aesm_read_data(FT_PERSISTENT_STORAGE, AESM_WHITE_LIST_CERT_TO_BE_VERIFY_FID, reinterpret_cast<uint8_t *>(&old_cert), &old_cert_size) == AE_SUCCESS)
  140. && (old_cert_size == sizeof(old_cert)) && (white_list_cert_size >= sizeof(wl_cert_chain_t)))
  141. {
  142. if(_ntohl(p_new_cert->wl_cert.wl_version) <= _ntohl(old_cert.wl_cert.wl_version))
  143. {
  144. AESM_DBG_WARN("White list version downgraded! current version is %d, new version is %d",
  145. _ntohl(old_cert.wl_cert.wl_version), _ntohl(p_new_cert->wl_cert.wl_version));
  146. return OAL_PARAMETER_ERROR; // OAL_PARAMETER_ERROR used here is to indicate the white list is incorrect
  147. }
  148. }
  149. return aesm_write_data(FT_PERSISTENT_STORAGE, AESM_WHITE_LIST_CERT_TO_BE_VERIFY_FID, white_list_cert, white_list_cert_size);
  150. }
  151. aesm_error_t AESMLogic::white_list_register(
  152. const uint8_t *white_list_cert, uint32_t white_list_cert_size)
  153. {
  154. AESM_DBG_INFO("enter function");
  155. CHECK_SERVICE_STATUS;
  156. AESMLogicLock lock(_le_mutex);
  157. CHECK_SERVICE_STATUS;
  158. ae_error_t ret_le = AE_SUCCESS;
  159. if (NULL == white_list_cert||0==white_list_cert_size){
  160. AESM_DBG_TRACE("Invalid parameter");
  161. return AESM_PARAMETER_ERROR;
  162. }
  163. ae_error_t ae_ret = CLEClass::instance().load_enclave();
  164. if(ae_ret == AE_SERVER_NOT_AVAILABLE)
  165. {
  166. AESM_DBG_WARN("LE not loaded due to AE_SERVER_NOT_AVAILABLE, possible SGX Env Not Ready");
  167. ret_le = save_unverified_white_list(white_list_cert, white_list_cert_size);
  168. }
  169. else if(AE_FAILED(ae_ret))
  170. {
  171. AESM_DBG_ERROR("LE not loaded:%d", ae_ret);
  172. return AESM_UNEXPECTED_ERROR;
  173. }else{
  174. ret_le = static_cast<ae_error_t>(CLEClass::instance().white_list_register(
  175. white_list_cert, white_list_cert_size));
  176. }
  177. switch (ret_le)
  178. {
  179. case AE_SUCCESS:
  180. return AESM_SUCCESS;
  181. case LE_INVALID_PARAMETER:
  182. AESM_DBG_TRACE("Invalid parameter");
  183. return AESM_PARAMETER_ERROR;
  184. case LE_INVALID_ATTRIBUTE:
  185. AESM_DBG_TRACE("Launch token error");
  186. return AESM_GET_LICENSETOKEN_ERROR;
  187. default:
  188. AESM_DBG_WARN("unexpeted error %d", ret_le);
  189. return AESM_UNEXPECTED_ERROR;
  190. }
  191. }
  192. aesm_error_t AESMLogic::get_launch_token(
  193. const uint8_t * mrenclave, uint32_t mrenclave_size,
  194. const uint8_t *public_key, uint32_t public_key_size,
  195. const uint8_t *se_attributes, uint32_t se_attributes_size,
  196. uint8_t * lictoken, uint32_t lictoken_size)
  197. {
  198. AESM_DBG_INFO("enter function");
  199. CHECK_SERVICE_STATUS;
  200. AESMLogicLock lock(_le_mutex);
  201. CHECK_SERVICE_STATUS;
  202. ae_error_t ret_le = AE_SUCCESS;
  203. if (NULL == mrenclave ||
  204. NULL == public_key ||
  205. NULL == se_attributes ||
  206. NULL == lictoken)
  207. {
  208. //sizes are checked in CLEClass::get_launch_token()
  209. AESM_DBG_TRACE("Invalid parameter");
  210. return AESM_PARAMETER_ERROR;
  211. }
  212. ae_error_t ae_ret = CLEClass::instance().load_enclave();
  213. if(ae_ret == AE_SERVER_NOT_AVAILABLE)
  214. {
  215. AESM_LOG_ERROR("%s", g_event_string_table[SGX_EVENT_SERVICE_UNAVAILABLE]);
  216. AESM_DBG_FATAL("LE not loaded due to AE_SERVER_NOT_AVAILABLE, possible SGX Env Not Ready");
  217. return AESM_NO_DEVICE_ERROR;
  218. }
  219. else if(AE_FAILED(ae_ret))
  220. {
  221. AESM_DBG_ERROR("LE not loaded:%d", ae_ret);
  222. return AESM_UNEXPECTED_ERROR;
  223. }
  224. ret_le = static_cast<ae_error_t>(CLEClass::instance().get_launch_token(
  225. const_cast<uint8_t *>(mrenclave), mrenclave_size,
  226. const_cast<uint8_t *>(public_key), public_key_size,
  227. const_cast<uint8_t *>(se_attributes), se_attributes_size,
  228. lictoken, lictoken_size));
  229. switch (ret_le)
  230. {
  231. case AE_SUCCESS:
  232. return AESM_SUCCESS;
  233. case LE_INVALID_PARAMETER:
  234. AESM_DBG_TRACE("Invalid parameter");
  235. return AESM_PARAMETER_ERROR;
  236. case LE_INVALID_ATTRIBUTE:
  237. case LE_INVALID_PRIVILEGE_ERROR:
  238. AESM_DBG_TRACE("Launch token error");
  239. return AESM_GET_LICENSETOKEN_ERROR;
  240. case LE_WHITELIST_UNINITIALIZED_ERROR:
  241. AESM_DBG_TRACE("LE whitelist uninitialized error");
  242. return AESM_UNEXPECTED_ERROR;
  243. default:
  244. AESM_DBG_WARN("unexpeted error %d", ret_le);
  245. return AESM_UNEXPECTED_ERROR;
  246. }
  247. }
  248. /* This function will be called outside aesm(from urts_internal) */
  249. extern "C" sgx_status_t get_launch_token(const enclave_css_t* signature,
  250. const sgx_attributes_t* attribute,
  251. sgx_launch_token_t* launch_token)
  252. {
  253. AESM_DBG_INFO("enter function");
  254. return AESMLogic::get_launch_token(signature, attribute, launch_token);
  255. }
  256. ae_error_t AESMLogic::get_qe_isv_svn(uint16_t& isv_svn)
  257. {
  258. if(!_is_qe_psvn_set){
  259. ae_error_t ae_err = CQEClass::instance().load_enclave();
  260. if(AE_SUCCESS != ae_err){
  261. AESM_DBG_ERROR("Fail to load QE Enclave:%d",ae_err);
  262. return ae_err;
  263. }
  264. }
  265. assert(_is_qe_psvn_set);
  266. if(0!=memcpy_s(&isv_svn, sizeof(isv_svn), &_qe_psvn.isv_svn, sizeof(_qe_psvn.isv_svn))){
  267. AESM_DBG_ERROR("memcpy failed");
  268. return AE_FAILURE;
  269. }
  270. return AE_SUCCESS;
  271. }
  272. ae_error_t AESMLogic::get_pse_isv_svn(uint16_t& isv_svn)
  273. {
  274. return AE_FAILURE;
  275. }
  276. ae_error_t AESMLogic::get_qe_cpu_svn(sgx_cpu_svn_t& cpu_svn)
  277. {
  278. if(!_is_qe_psvn_set){
  279. ae_error_t ae_err = CQEClass::instance().load_enclave();
  280. if(AE_SUCCESS != ae_err){
  281. AESM_DBG_ERROR("Fail to load QE Enclave:%d",ae_err);
  282. return ae_err;
  283. }
  284. }
  285. assert(_is_qe_psvn_set);
  286. if(0!=memcpy_s(&cpu_svn, sizeof(sgx_cpu_svn_t), &_qe_psvn.cpu_svn, sizeof(_qe_psvn.cpu_svn))){
  287. AESM_DBG_ERROR("memcpy failed");
  288. return AE_FAILURE;
  289. }
  290. return AE_SUCCESS;
  291. }
  292. ae_error_t AESMLogic::set_psvn(uint16_t prod_id, uint16_t isv_svn, sgx_cpu_svn_t cpu_svn)
  293. {
  294. if(prod_id == QE_PROD_ID){
  295. if(_is_qe_psvn_set){
  296. if(0!=memcmp(&_qe_psvn.isv_svn, &isv_svn, sizeof(isv_svn))||
  297. 0!=memcmp(&_qe_psvn.cpu_svn, &cpu_svn, sizeof(sgx_cpu_svn_t))){
  298. AESM_DBG_ERROR("PSVN unmatched for QE/PVE");
  299. return AE_PSVN_UNMATCHED_ERROR;
  300. }
  301. }else{
  302. if(0!=memcpy_s(&_qe_psvn.isv_svn, sizeof(_qe_psvn.isv_svn), &isv_svn, sizeof(isv_svn))||
  303. 0!=memcpy_s(&_qe_psvn.cpu_svn, sizeof(_qe_psvn.cpu_svn), &cpu_svn, sizeof(sgx_cpu_svn_t))){
  304. AESM_DBG_ERROR("memcpy failed");
  305. return AE_FAILURE;
  306. }
  307. AESM_DBG_TRACE("get QE or PvE isv_svn=%d",(int)isv_svn);
  308. _is_qe_psvn_set = true;
  309. return AE_SUCCESS;
  310. }
  311. }else if(prod_id == PSE_PROD_ID){
  312. if(_is_pse_psvn_set){
  313. if(0!=memcmp(&_pse_psvn.isv_svn, &isv_svn, sizeof(isv_svn))||
  314. 0!=memcmp(&_pse_psvn.cpu_svn, &cpu_svn, sizeof(sgx_cpu_svn_t))){
  315. AESM_DBG_ERROR("PSVN unmatched for PSE");
  316. return AE_PSVN_UNMATCHED_ERROR;
  317. }
  318. }else{
  319. if(0!=memcpy_s(&_pse_psvn.isv_svn, sizeof(_pse_psvn.isv_svn), &isv_svn, sizeof(isv_svn))||
  320. 0!=memcpy_s(&_pse_psvn.cpu_svn, sizeof(_pse_psvn.cpu_svn), &cpu_svn, sizeof(sgx_cpu_svn_t))){
  321. AESM_DBG_ERROR("memcpy failed");
  322. return AE_FAILURE;
  323. }
  324. AESM_DBG_TRACE("get PSE isv_svn=%d", (int)isv_svn);
  325. _is_pse_psvn_set = true;
  326. return AE_SUCCESS;
  327. }
  328. }
  329. return AE_SUCCESS;
  330. }
  331. sgx_status_t AESMLogic::get_launch_token(const enclave_css_t* signature,
  332. const sgx_attributes_t* attribute,
  333. sgx_launch_token_t* launch_token)
  334. {
  335. AESM_DBG_INFO("enter function");
  336. AESMLogicLock lock(_le_mutex);
  337. ae_error_t ret_le = AE_SUCCESS;
  338. // load LE to get launch token
  339. if((ret_le=CLEClass::instance().load_enclave()) != AE_SUCCESS)
  340. {
  341. if(ret_le == AE_SERVER_NOT_AVAILABLE)
  342. {
  343. AESM_DBG_FATAL("LE not loaded due to AE_SERVER_NOT_AVAILABLE, possible SGX Env Not Ready");
  344. return SGX_ERROR_NO_DEVICE;
  345. }
  346. AESM_DBG_FATAL("fail to load LE:%d",ret_le);
  347. return SGX_ERROR_UNEXPECTED;
  348. }
  349. ret_le = static_cast<ae_error_t>(CLEClass::instance().get_launch_token(
  350. const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(&signature->body.enclave_hash)),
  351. sizeof(sgx_measurement_t),
  352. const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(&signature->key.modulus)),
  353. sizeof(signature->key.modulus),
  354. const_cast<uint8_t*>(reinterpret_cast<const uint8_t *>(attribute)),
  355. sizeof(sgx_attributes_t),
  356. reinterpret_cast<uint8_t*>(launch_token),
  357. sizeof(token_t)));
  358. switch (ret_le)
  359. {
  360. case AE_SUCCESS:
  361. break;
  362. case LE_INVALID_PARAMETER:
  363. AESM_DBG_TRACE("Invalid parameter");
  364. return SGX_ERROR_INVALID_PARAMETER;
  365. case LE_INVALID_ATTRIBUTE:
  366. case LE_INVALID_PRIVILEGE_ERROR:
  367. AESM_DBG_TRACE("Launch token error");
  368. return SGX_ERROR_SERVICE_INVALID_PRIVILEGE;
  369. case LE_WHITELIST_UNINITIALIZED_ERROR:
  370. AESM_DBG_TRACE("LE whitelist uninitialized error");
  371. return SGX_ERROR_UNEXPECTED;
  372. default:
  373. AESM_DBG_WARN("unexpeted error %d", ret_le);
  374. return SGX_ERROR_UNEXPECTED;
  375. }
  376. token_t *lt = reinterpret_cast<token_t *>(launch_token);
  377. ret_le = set_psvn(signature->body.isv_prod_id, signature->body.isv_svn, lt->cpu_svn_le);
  378. if(AE_PSVN_UNMATCHED_ERROR == ret_le)
  379. {
  380. //QE or PSE has been changed, but AESM doesn't restart. Will not provide service.
  381. return SGX_ERROR_SERVICE_UNAVAILABLE;
  382. }else if(AE_SUCCESS != ret_le) {
  383. AESM_DBG_ERROR("fail to save psvn:%d", ret_le);
  384. return SGX_ERROR_UNEXPECTED;
  385. }
  386. return SGX_SUCCESS;
  387. }
  388. aesm_error_t AESMLogic::create_session(
  389. uint32_t* session_id,
  390. uint8_t* se_dh_msg1, uint32_t se_dh_msg1_size)
  391. {
  392. return AESM_SERVICE_NOT_AVAILABLE;
  393. }
  394. aesm_error_t AESMLogic::exchange_report(
  395. uint32_t session_id,
  396. const uint8_t* se_dh_msg2, uint32_t se_dh_msg2_size,
  397. uint8_t* se_dh_msg3, uint32_t se_dh_msg3_size)
  398. {
  399. return AESM_SERVICE_NOT_AVAILABLE;
  400. }
  401. aesm_error_t AESMLogic::close_session(
  402. uint32_t session_id)
  403. {
  404. return AESM_SERVICE_NOT_AVAILABLE;
  405. }
  406. aesm_error_t AESMLogic::invoke_service(
  407. const uint8_t* pse_message_req, uint32_t pse_message_req_size,
  408. uint8_t* pse_message_resp, uint32_t pse_message_resp_size)
  409. {
  410. return AESM_SERVICE_NOT_AVAILABLE;;
  411. }
  412. aesm_error_t AESMLogic::get_ps_cap(
  413. uint64_t* ps_cap)
  414. {
  415. return AESM_PSDA_UNAVAILABLE;
  416. }
  417. #define CHECK_EPID_PROVISIONG_STATUS \
  418. if(!query_pve_thread_status()){\
  419. return AESM_BUSY;\
  420. }
  421. aesm_error_t AESMLogic::init_quote(
  422. uint8_t *target_info, uint32_t target_info_size,
  423. uint8_t *gid, uint32_t gid_size)
  424. {
  425. ae_error_t ret = AE_SUCCESS;
  426. uint16_t qe_isv_svn = 0xFFFF;
  427. sgx_cpu_svn_t qe_cpu_svn;
  428. memset(&qe_cpu_svn, 0, sizeof(qe_cpu_svn));
  429. AESM_DBG_INFO("init_quote");
  430. if(sizeof(sgx_target_info_t) != target_info_size ||
  431. sizeof(sgx_epid_group_id_t) != gid_size)
  432. {
  433. return AESM_PARAMETER_ERROR;
  434. }
  435. AESMLogicLock lock(_qe_pve_mutex);
  436. CHECK_EPID_PROVISIONG_STATUS;
  437. ret = get_qe_cpu_svn(qe_cpu_svn);
  438. if(AE_SUCCESS != ret)
  439. {
  440. return AESM_UNEXPECTED_ERROR;
  441. }
  442. ret = get_qe_isv_svn(qe_isv_svn);
  443. if(AE_SUCCESS != ret)
  444. {
  445. return AESM_UNEXPECTED_ERROR;
  446. }
  447. return QEAESMLogic::init_quote(
  448. reinterpret_cast<sgx_target_info_t *>(target_info),
  449. gid, gid_size, qe_isv_svn, qe_cpu_svn);
  450. }
  451. aesm_error_t AESMLogic::get_quote(const uint8_t *report, uint32_t report_size,
  452. uint32_t quote_type,
  453. const uint8_t *spid, uint32_t spid_size,
  454. const uint8_t *nonce, uint32_t nonce_size,
  455. const uint8_t *sigrl, uint32_t sigrl_size,
  456. uint8_t *qe_report, uint32_t qe_report_size,
  457. uint8_t *quote, uint32_t buf_size)
  458. {
  459. AESM_DBG_INFO("get_quote");
  460. if(sizeof(sgx_report_t) != report_size ||
  461. sizeof(sgx_spid_t) != spid_size)
  462. {
  463. return AESM_PARAMETER_ERROR;
  464. }
  465. if((nonce && sizeof(sgx_quote_nonce_t) != nonce_size)
  466. || (qe_report && sizeof(sgx_report_t) != qe_report_size))
  467. {
  468. return AESM_PARAMETER_ERROR;
  469. }
  470. AESMLogicLock lock(_qe_pve_mutex);
  471. CHECK_EPID_PROVISIONG_STATUS;
  472. return QEAESMLogic::get_quote(report, quote_type, spid, nonce, sigrl,
  473. sigrl_size, qe_report, quote, buf_size);
  474. }
  475. uint32_t AESMLogic::endpoint_selection(endpoint_selection_infos_t& es_info)
  476. {
  477. AESMLogicLock lock(_qe_pve_mutex);
  478. SGX_DBGPRINT_ONE_STRING_TWO_INTS_ENDPOINT_SELECTION(__FUNCTION__" (line, 0)", __LINE__, 0);
  479. return EndpointSelectionInfo::instance().start_protocol(es_info);
  480. }
  481. aesm_error_t AESMLogic::report_attestation_status(
  482. uint8_t* platform_info, uint32_t platform_info_size,
  483. uint32_t attestation_status,
  484. uint8_t* update_info, uint32_t update_info_size)
  485. {
  486. AESM_DBG_INFO("report_attestation_status");
  487. AESMLogicLock lock(_pse_mutex);
  488. return PlatformInfoLogic::report_attestation_status(platform_info, platform_info_size, attestation_status, update_info, update_info_size);
  489. }
  490. ae_error_t sgx_error_to_ae_error(sgx_status_t status)
  491. {
  492. if(SGX_ERROR_OUT_OF_MEMORY == status)
  493. return AE_OUT_OF_MEMORY_ERROR;
  494. if(SGX_SUCCESS == status)
  495. return AE_SUCCESS;
  496. return AE_FAILURE;
  497. }