tae_service_sim.cpp 18 KB

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