tae_service_sim.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /*
  2. * Copyright (C) 2011-2018 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. //tae_service_sim.cpp : Defines the exported functions
  32. //
  33. #include "sgx_tae_service.h"
  34. #include "tae_service_internal.h"
  35. #include "se_memcpy.h"
  36. #include "pse_types.h"
  37. #include "stdlib.h"
  38. #include "string.h"
  39. #include "sgx_spinlock.h"
  40. #include "sgx_tae_service_t.h"
  41. #define RETRY_TIMES 2
  42. #define DEFAULT_VMC_ATTRIBUTE_MASK 0xFFFFFFFFFFFFFFCB
  43. #define DEFAULT_VMC_XFRM_MASK 0x0
  44. #ifdef _DEBUG
  45. //wait for 10min at most for debug
  46. #define DEFAULT_AESM_TIMEOUT 600000
  47. #else
  48. //wait for 10sec at most
  49. #define DEFAULT_AESM_TIMEOUT 10000
  50. #endif
  51. static sgx_spinlock_t g_spin_lock;
  52. static bool g_b_session_established = false;
  53. sgx_status_t sgx_create_pse_session()
  54. {
  55. sgx_spin_lock(&g_spin_lock);
  56. if(!g_b_session_established)
  57. g_b_session_established = true;
  58. sgx_spin_unlock(&g_spin_lock);
  59. return SGX_SUCCESS;
  60. }
  61. sgx_status_t sgx_close_pse_session()
  62. {
  63. sgx_spin_lock(&g_spin_lock);
  64. if(g_b_session_established)
  65. g_b_session_established = false;
  66. sgx_spin_unlock(&g_spin_lock);
  67. return SGX_SUCCESS;
  68. }
  69. sgx_status_t sgx_get_ps_sec_prop(sgx_ps_sec_prop_desc_t *p_security_property)
  70. {
  71. sgx_status_t ret = SGX_SUCCESS;
  72. if(!p_security_property)
  73. return SGX_ERROR_INVALID_PARAMETER;
  74. if (!g_b_session_established){
  75. return SGX_ERROR_AE_SESSION_INVALID;
  76. }
  77. else
  78. {
  79. se_ps_sec_prop_desc_internal_t *p_security_property_internal = (se_ps_sec_prop_desc_internal_t*)p_security_property;
  80. p_security_property_internal->desc_type = 0;
  81. p_security_property_internal->pse_miscselect = 0;
  82. p_security_property_internal->reserved1 = 0;
  83. memset(p_security_property_internal->reserved2, 0, sizeof(p_security_property_internal->reserved2));
  84. p_security_property_internal->pse_prod_id = 2;
  85. p_security_property_internal->pse_isvsvn = 1;
  86. p_security_property_internal->pse_attributes.flags = SGX_FLAGS_INITTED;
  87. p_security_property_internal->pse_attributes.xfrm = SGX_XFRM_LEGACY;
  88. memset(&(p_security_property_internal->pse_mr_signer), 0xEE,
  89. sizeof(p_security_property_internal->pse_mr_signer));
  90. p_security_property_internal->cse_sec_prop.gid_cse = 0;
  91. p_security_property_internal->cse_sec_prop.prvrl_version = 1;
  92. p_security_property_internal->cse_sec_prop.sigrl_version = 1;
  93. p_security_property_internal->cse_sec_prop.sec_info_type = 0;
  94. memset(&p_security_property_internal->cse_sec_prop.ca_id_cse, 0, sizeof(p_security_property_internal->cse_sec_prop.ca_id_cse));
  95. memset(&p_security_property_internal->cse_sec_prop.sec_info, 0, sizeof(p_security_property_internal->cse_sec_prop.sec_info));
  96. }
  97. return ret;
  98. }
  99. sgx_status_t sgx_get_ps_sec_prop_ex(sgx_ps_sec_prop_desc_ex_t* ps_security_property_ex)
  100. {
  101. sgx_status_t ret;
  102. if (!ps_security_property_ex)
  103. return SGX_ERROR_INVALID_PARAMETER;
  104. ret = sgx_get_ps_sec_prop(&ps_security_property_ex->ps_sec_prop_desc);
  105. if (ret != SGX_SUCCESS)
  106. {
  107. return ret;
  108. }
  109. se_ps_sec_prop_desc_internal_t* desc_internal =
  110. (se_ps_sec_prop_desc_internal_t*)&ps_security_property_ex->ps_sec_prop_desc;
  111. memcpy_s(&ps_security_property_ex->pse_mrsigner, sizeof(ps_security_property_ex->pse_mrsigner),
  112. &desc_internal->pse_mr_signer, sizeof(sgx_measurement_t));
  113. memcpy_s(&ps_security_property_ex->pse_prod_id, sizeof(ps_security_property_ex->pse_prod_id),
  114. &desc_internal->pse_prod_id, sizeof(sgx_prod_id_t));
  115. memcpy_s(&ps_security_property_ex->pse_isv_svn, sizeof(ps_security_property_ex->pse_isv_svn),
  116. &desc_internal->pse_isvsvn, sizeof(sgx_isv_svn_t));
  117. return ret;
  118. }
  119. sgx_status_t sgx_get_trusted_time
  120. (
  121. sgx_time_t *p_current_time,
  122. sgx_time_source_nonce_t *p_time_source_nonce)
  123. {
  124. if(!p_current_time || !p_time_source_nonce)
  125. return SGX_ERROR_INVALID_PARAMETER;
  126. if (!g_b_session_established){
  127. return SGX_ERROR_AE_SESSION_INVALID;
  128. }
  129. pse_message_t *p_req_msg =
  130. (pse_message_t *)malloc(PSE_TIMER_READ_REQ_SIZE);
  131. if(!p_req_msg){
  132. return SGX_ERROR_OUT_OF_MEMORY;
  133. }
  134. pse_message_t *p_resp_msg =
  135. (pse_message_t *)malloc(PSE_TIMER_READ_RESP_SIZE);
  136. if(!p_resp_msg){
  137. free(p_req_msg);
  138. return SGX_ERROR_OUT_OF_MEMORY;
  139. }
  140. p_req_msg->exp_resp_size = sizeof(pse_timer_read_resp_t);
  141. p_req_msg->payload_size = sizeof(pse_timer_read_req_t);
  142. pse_timer_read_req_t *p_timer_req
  143. = (pse_timer_read_req_t *)p_req_msg->payload;
  144. p_timer_req->req_hdr.service_id = PSE_TRUSTED_TIME_SERVICE;
  145. p_timer_req->req_hdr.service_cmd = PSE_TIMER_READ;
  146. pse_timer_read_resp_t *p_timer_resp
  147. = (pse_timer_read_resp_t *)p_resp_msg->payload;
  148. sgx_status_t status = SGX_SUCCESS;
  149. sgx_status_t ret = SGX_SUCCESS;
  150. int retry = RETRY_TIMES;
  151. do {
  152. status = invoke_service_ocall(&ret,
  153. (uint8_t *)p_req_msg,
  154. PSE_TIMER_READ_REQ_SIZE,
  155. (uint8_t *)p_resp_msg,
  156. PSE_TIMER_READ_RESP_SIZE,
  157. DEFAULT_AESM_TIMEOUT);
  158. if(status != SGX_SUCCESS || ret != SGX_SUCCESS){
  159. status = SGX_ERROR_UNEXPECTED;
  160. continue;
  161. }
  162. if(p_timer_resp->resp_hdr.service_id != PSE_TRUSTED_TIME_SERVICE
  163. || p_timer_resp->resp_hdr.service_cmd != PSE_TIMER_READ
  164. || p_timer_resp->resp_hdr.status != PSE_SUCCESS){
  165. status = SGX_ERROR_UNEXPECTED;
  166. } else {
  167. memcpy_s(p_current_time, sizeof(*p_current_time), &p_timer_resp->timestamp, sizeof(sgx_time_t));
  168. memcpy_s(p_time_source_nonce, sizeof(*p_time_source_nonce), p_timer_resp->time_source_nonce,
  169. sizeof(sgx_time_source_nonce_t));
  170. status = SGX_SUCCESS;
  171. break;
  172. }
  173. } while(retry--);
  174. free(p_req_msg);
  175. free(p_resp_msg);
  176. return status;
  177. }
  178. sgx_status_t sgx_create_monotonic_counter_ex(
  179. uint16_t owner_policy,
  180. const sgx_attributes_t* owner_attribute_mask,
  181. sgx_mc_uuid_t *p_counter_uuid,
  182. uint32_t *p_counter_value)
  183. {
  184. if(!p_counter_value || !p_counter_uuid || !owner_attribute_mask){
  185. return SGX_ERROR_INVALID_PARAMETER;
  186. }
  187. if (0!= (~(MC_POLICY_SIGNER | MC_POLICY_ENCLAVE) & owner_policy)
  188. || 0 == ((MC_POLICY_SIGNER | MC_POLICY_ENCLAVE)& owner_policy))
  189. {
  190. return SGX_ERROR_INVALID_PARAMETER;
  191. }
  192. if (!g_b_session_established){
  193. return SGX_ERROR_AE_SESSION_INVALID;
  194. }
  195. pse_message_t *p_req_msg = (pse_message_t *)malloc(PSE_CREATE_MC_REQ_SIZE);
  196. if(!p_req_msg){
  197. return SGX_ERROR_OUT_OF_MEMORY;
  198. }
  199. pse_message_t *p_resp_msg = (pse_message_t *)malloc(PSE_CREATE_MC_RESP_SIZE);
  200. if(!p_resp_msg){
  201. free(p_req_msg);
  202. return SGX_ERROR_OUT_OF_MEMORY;
  203. }
  204. p_req_msg->exp_resp_size = sizeof(pse_mc_create_resp_t);
  205. p_req_msg->payload_size = sizeof(pse_mc_create_req_t);
  206. pse_mc_create_req_t *p_mc_req
  207. = (pse_mc_create_req_t *)p_req_msg->payload;
  208. p_mc_req->req_hdr.service_id = PSE_MC_SERVICE;
  209. p_mc_req->req_hdr.service_cmd = PSE_MC_CREATE;
  210. p_mc_req->policy = owner_policy;
  211. memcpy_s(&p_mc_req->attr_mask, sizeof(p_mc_req->attr_mask), owner_attribute_mask, sizeof(*owner_attribute_mask));
  212. pse_mc_create_resp_t *p_mc_resp
  213. = (pse_mc_create_resp_t *)p_resp_msg->payload;
  214. sgx_status_t status = SGX_SUCCESS;
  215. sgx_status_t ret = SGX_SUCCESS;
  216. int retry = RETRY_TIMES;
  217. do {
  218. sgx_spin_lock(&g_spin_lock);
  219. status = invoke_service_ocall(&ret,
  220. (uint8_t *)p_req_msg,
  221. PSE_CREATE_MC_REQ_SIZE,
  222. (uint8_t *)p_resp_msg,
  223. PSE_CREATE_MC_RESP_SIZE,
  224. DEFAULT_AESM_TIMEOUT);
  225. sgx_spin_unlock(&g_spin_lock);
  226. if(status != SGX_SUCCESS || ret != SGX_SUCCESS){
  227. status = SGX_ERROR_UNEXPECTED;
  228. continue;
  229. }
  230. if(p_mc_resp->resp_hdr.service_id != PSE_MC_SERVICE
  231. || p_mc_resp->resp_hdr.service_cmd != PSE_MC_CREATE
  232. || p_mc_resp->resp_hdr.status != PSE_SUCCESS){
  233. status = SGX_ERROR_UNEXPECTED;
  234. } else {
  235. memcpy_s(&p_counter_uuid->counter_id, sizeof(p_counter_uuid->counter_id),
  236. &p_mc_resp->counter_id, sizeof(p_mc_resp->counter_id));
  237. memcpy_s(&p_counter_uuid->nonce, sizeof(p_counter_uuid->nonce),
  238. &p_mc_resp->nonce, sizeof(p_mc_resp->nonce));
  239. *p_counter_value = 0;
  240. status = SGX_SUCCESS;
  241. break;
  242. }
  243. } while(retry--);
  244. free(p_req_msg);
  245. free(p_resp_msg);
  246. return status;
  247. }
  248. sgx_status_t sgx_increment_monotonic_counter(
  249. const sgx_mc_uuid_t *p_counter_uuid,
  250. uint32_t *p_counter_value)
  251. {
  252. if(!p_counter_value || !p_counter_uuid ){
  253. return SGX_ERROR_INVALID_PARAMETER;
  254. }
  255. if (!g_b_session_established){
  256. return SGX_ERROR_AE_SESSION_INVALID;
  257. }
  258. pse_message_t *p_req_msg = (pse_message_t *)malloc(PSE_INC_MC_REQ_SIZE);
  259. if(!p_req_msg){
  260. return SGX_ERROR_OUT_OF_MEMORY;
  261. }
  262. pse_message_t *p_resp_msg = (pse_message_t *)malloc(PSE_INC_MC_RESP_SIZE);
  263. if(!p_resp_msg){
  264. free(p_req_msg);
  265. return SGX_ERROR_OUT_OF_MEMORY;
  266. }
  267. p_req_msg->exp_resp_size = sizeof(pse_mc_inc_resp_t);
  268. p_req_msg->payload_size = sizeof(pse_mc_inc_req_t);
  269. pse_mc_inc_req_t *p_mc_req
  270. = (pse_mc_inc_req_t *)p_req_msg->payload;
  271. memcpy_s(&p_mc_req->counter_id, sizeof(p_mc_req->counter_id),
  272. &p_counter_uuid->counter_id, sizeof(p_counter_uuid->counter_id));
  273. memcpy_s(&p_mc_req->nonce, sizeof(p_mc_req->nonce),
  274. &p_counter_uuid->nonce, sizeof(p_counter_uuid->nonce));
  275. p_mc_req->req_hdr.service_id = PSE_MC_SERVICE;
  276. p_mc_req->req_hdr.service_cmd = PSE_MC_INC;
  277. pse_mc_inc_resp_t *p_mc_resp
  278. = (pse_mc_inc_resp_t *)p_resp_msg->payload;
  279. sgx_status_t status = SGX_SUCCESS;
  280. sgx_status_t ret = SGX_SUCCESS;
  281. int retry = RETRY_TIMES;
  282. do {
  283. sgx_spin_lock(&g_spin_lock);
  284. status = invoke_service_ocall(&ret,
  285. (uint8_t *)p_req_msg,
  286. PSE_INC_MC_REQ_SIZE,
  287. (uint8_t *)p_resp_msg,
  288. PSE_INC_MC_RESP_SIZE,
  289. DEFAULT_AESM_TIMEOUT);
  290. sgx_spin_unlock(&g_spin_lock);
  291. if(status != SGX_SUCCESS || ret != SGX_SUCCESS){
  292. if(SGX_ERROR_MC_NOT_FOUND != ret)
  293. status = SGX_ERROR_UNEXPECTED;
  294. else
  295. status = SGX_ERROR_MC_NOT_FOUND;
  296. continue;
  297. }
  298. if(p_mc_resp->resp_hdr.service_id != PSE_MC_SERVICE
  299. || p_mc_resp->resp_hdr.service_cmd != PSE_MC_INC
  300. || p_mc_resp->resp_hdr.status != PSE_SUCCESS){
  301. if(PSE_ERROR_MC_NOT_FOUND == p_mc_resp->resp_hdr.status)
  302. status = SGX_ERROR_MC_NOT_FOUND;
  303. else
  304. status = SGX_ERROR_UNEXPECTED;
  305. } else
  306. {
  307. *p_counter_value = p_mc_resp->counter_value;
  308. status = SGX_SUCCESS;
  309. break;
  310. }
  311. } while(retry--);
  312. free(p_req_msg);
  313. free(p_resp_msg);
  314. return status;
  315. }
  316. sgx_status_t sgx_read_monotonic_counter(
  317. const sgx_mc_uuid_t *p_counter_uuid,
  318. uint32_t *p_counter_value)
  319. {
  320. if(!p_counter_value || !p_counter_uuid){
  321. return SGX_ERROR_INVALID_PARAMETER;
  322. }
  323. if (!g_b_session_established){
  324. return SGX_ERROR_AE_SESSION_INVALID;
  325. }
  326. pse_message_t *p_req_msg = (pse_message_t *)malloc(PSE_READ_MC_REQ_SIZE);
  327. if(!p_req_msg){
  328. return SGX_ERROR_OUT_OF_MEMORY;
  329. }
  330. pse_message_t *p_resp_msg = (pse_message_t *)malloc(PSE_READ_MC_RESP_SIZE);
  331. if(!p_resp_msg){
  332. free(p_req_msg);
  333. return SGX_ERROR_OUT_OF_MEMORY;
  334. }
  335. p_req_msg->exp_resp_size = sizeof(pse_mc_read_resp_t);
  336. p_req_msg->payload_size = sizeof(pse_mc_read_req_t);
  337. pse_mc_read_req_t *p_mc_req
  338. = (pse_mc_read_req_t *)p_req_msg->payload;
  339. memcpy_s(&p_mc_req->counter_id, sizeof(p_mc_req->counter_id),
  340. &p_counter_uuid->counter_id, sizeof(p_counter_uuid->counter_id));
  341. memcpy_s(&p_mc_req->nonce, sizeof(p_mc_req->nonce),
  342. &p_counter_uuid->nonce, sizeof(p_counter_uuid->nonce));
  343. p_mc_req->req_hdr.service_id = PSE_MC_SERVICE;
  344. p_mc_req->req_hdr.service_cmd = PSE_MC_READ;
  345. pse_mc_read_resp_t *p_mc_resp
  346. = (pse_mc_read_resp_t *)p_resp_msg->payload;
  347. sgx_status_t status = SGX_SUCCESS;
  348. sgx_status_t ret = SGX_SUCCESS;
  349. int retry = RETRY_TIMES;
  350. do {
  351. sgx_spin_lock(&g_spin_lock);
  352. status = invoke_service_ocall(&ret,
  353. (uint8_t *)p_req_msg,
  354. PSE_READ_MC_REQ_SIZE,
  355. (uint8_t *)p_resp_msg,
  356. PSE_READ_MC_RESP_SIZE,
  357. DEFAULT_AESM_TIMEOUT);
  358. sgx_spin_unlock(&g_spin_lock);
  359. if(status != SGX_SUCCESS || ret != SGX_SUCCESS){
  360. if(SGX_ERROR_MC_NOT_FOUND != ret)
  361. status = SGX_ERROR_UNEXPECTED;
  362. else
  363. status = SGX_ERROR_MC_NOT_FOUND;
  364. continue;
  365. }
  366. if(p_mc_resp->resp_hdr.service_id != PSE_MC_SERVICE
  367. || p_mc_resp->resp_hdr.service_cmd != PSE_MC_READ
  368. || p_mc_resp->resp_hdr.status != PSE_SUCCESS){
  369. if(PSE_ERROR_MC_NOT_FOUND == p_mc_resp->resp_hdr.status)
  370. status = SGX_ERROR_MC_NOT_FOUND;
  371. else
  372. status = SGX_ERROR_UNEXPECTED;
  373. } else {
  374. *p_counter_value = p_mc_resp->counter_value;
  375. status = SGX_SUCCESS;
  376. break;
  377. }
  378. } while(retry--);
  379. free(p_req_msg);
  380. free(p_resp_msg);
  381. return status;
  382. }
  383. sgx_status_t sgx_create_monotonic_counter(
  384. sgx_mc_uuid_t *p_counter_uuid,
  385. uint32_t *p_counter_value)
  386. {
  387. //Default attribute mask
  388. sgx_attributes_t attr_mask;
  389. attr_mask.flags = DEFAULT_VMC_ATTRIBUTE_MASK;
  390. attr_mask.xfrm = DEFAULT_VMC_XFRM_MASK;
  391. return sgx_create_monotonic_counter_ex(MC_POLICY_SIGNER,
  392. &attr_mask,
  393. p_counter_uuid,
  394. p_counter_value);
  395. }
  396. sgx_status_t sgx_destroy_monotonic_counter(const sgx_mc_uuid_t *p_counter_uuid)
  397. {
  398. if(!p_counter_uuid){
  399. return SGX_ERROR_INVALID_PARAMETER;
  400. }
  401. if (!g_b_session_established){
  402. return SGX_ERROR_AE_SESSION_INVALID;
  403. }
  404. pse_message_t *p_req_msg = (pse_message_t *)malloc(PSE_DEL_MC_REQ_SIZE);
  405. if(!p_req_msg){
  406. return SGX_ERROR_OUT_OF_MEMORY;
  407. }
  408. pse_message_t *p_resp_msg = (pse_message_t *)malloc(PSE_DEL_MC_RESP_SIZE);
  409. if(!p_resp_msg){
  410. free(p_req_msg);
  411. return SGX_ERROR_OUT_OF_MEMORY;
  412. }
  413. p_req_msg->exp_resp_size = sizeof(pse_mc_del_resp_t);
  414. p_req_msg->payload_size = sizeof(pse_mc_del_req_t);
  415. pse_mc_del_req_t *p_mc_req
  416. = (pse_mc_del_req_t *)p_req_msg->payload;
  417. memcpy_s(&p_mc_req->counter_id, sizeof(p_mc_req->counter_id),
  418. &p_counter_uuid->counter_id, sizeof(p_counter_uuid->counter_id));
  419. memcpy_s(&p_mc_req->nonce, sizeof(p_mc_req->nonce),
  420. &p_counter_uuid->nonce, sizeof(p_counter_uuid->nonce));
  421. p_mc_req->req_hdr.service_id = PSE_MC_SERVICE;
  422. p_mc_req->req_hdr.service_cmd = PSE_MC_DEL;
  423. pse_mc_del_resp_t *p_mc_resp
  424. = (pse_mc_del_resp_t *)p_resp_msg->payload;
  425. sgx_status_t status = SGX_SUCCESS;
  426. sgx_status_t ret = SGX_SUCCESS;
  427. int retry = RETRY_TIMES;
  428. do {
  429. status = invoke_service_ocall(&ret,
  430. (uint8_t *)p_req_msg,
  431. PSE_DEL_MC_REQ_SIZE,
  432. (uint8_t *)p_resp_msg,
  433. PSE_DEL_MC_RESP_SIZE,
  434. DEFAULT_AESM_TIMEOUT);
  435. if(status != SGX_SUCCESS || ret != SGX_SUCCESS){
  436. if(SGX_ERROR_MC_NOT_FOUND != ret)
  437. status = SGX_ERROR_UNEXPECTED;
  438. else
  439. status = SGX_ERROR_MC_NOT_FOUND;
  440. continue;
  441. }
  442. if(p_mc_resp->resp_hdr.service_id != PSE_MC_SERVICE
  443. || p_mc_resp->resp_hdr.service_cmd != PSE_MC_DEL
  444. || p_mc_resp->resp_hdr.status != PSE_SUCCESS){
  445. if(PSE_ERROR_MC_NOT_FOUND == p_mc_resp->resp_hdr.status)
  446. status = SGX_ERROR_MC_NOT_FOUND;
  447. else
  448. status = SGX_ERROR_UNEXPECTED;
  449. } else {
  450. status = SGX_SUCCESS;
  451. break;
  452. }
  453. } while(retry--);
  454. free(p_req_msg);
  455. free(p_resp_msg);
  456. return status;
  457. }