sgx_uae_service.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. #include <oal/uae_oal_api.h>
  32. #include <aesm_error.h>
  33. #include "sgx_uae_service.h"
  34. #include "uae_service_internal.h"
  35. #include "config.h"
  36. #include "stdint.h"
  37. #include "se_sig_rl.h"
  38. #if !defined(ntohl)
  39. #define ntohl(u32) \
  40. ((uint32_t)(((((const unsigned char*)&(u32))[0]) << 24) \
  41. + ((((const unsigned char*)&(u32))[1]) << 16) \
  42. + ((((const unsigned char*)&(u32))[2]) << 8) \
  43. + (((const unsigned char*)&(u32))[3])))
  44. #endif
  45. #define GET_LAUNCH_TOKEN_TIMEOUT_MSEC (IPC_LATENCY)
  46. #define SE_INIT_QUOTE_TIMEOUT_MSEC (IPC_LATENCY)
  47. //add 3 millisecond per sig_rl entry
  48. #define SE_GET_QUOTE_TIMEOUT_MSEC(p_sig_rl) (IPC_LATENCY + ((p_sig_rl) ? 3*ntohl(((const se_sig_rl_t*)p_sig_rl)->sig_rl.n2) : 0))
  49. #define SE_GET_PS_CAP_TIMEOUT_MSEC (IPC_LATENCY)
  50. #define SE_REPORT_REMOTE_ATTESTATION_FAILURE_TIMEOUT_MSEC (IPC_LATENCY)
  51. #define GET_WHITE_LIST_SIZE_MSEC (IPC_LATENCY)
  52. #define GET_WHITE_LIST_MSEC (IPC_LATENCY)
  53. #define SGX_GET_EXTENDED_GROUP_ID_MSEC (IPC_LATENCY)
  54. #define SGX_SWITCH_EXTENDED_GROUP_MSEC (IPC_LATENCY)
  55. #define REG_WL_CERT_CHAIN_MSEC (IPC_LATENCY)
  56. extern "C" {
  57. sgx_status_t get_launch_token(
  58. const enclave_css_t* signature,
  59. const sgx_attributes_t* attribute,
  60. sgx_launch_token_t* launch_token)
  61. {
  62. if (signature == NULL || attribute == NULL || launch_token == NULL)
  63. return SGX_ERROR_INVALID_PARAMETER;
  64. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  65. uae_oal_status_t status = oal_get_launch_token(signature, attribute, launch_token, GET_LAUNCH_TOKEN_TIMEOUT_MSEC*1000, &result);
  66. /*common mappings */
  67. sgx_status_t mapped = oal_map_status(status);
  68. if (mapped != SGX_SUCCESS)
  69. return mapped;
  70. mapped = oal_map_result(result);
  71. if (mapped != SGX_SUCCESS)
  72. {
  73. /*operation specific mapping */
  74. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  75. {
  76. switch (result)
  77. {
  78. case AESM_NO_DEVICE_ERROR:
  79. mapped = SGX_ERROR_NO_DEVICE;
  80. break;
  81. case AESM_GET_LICENSETOKEN_ERROR:
  82. mapped = SGX_ERROR_SERVICE_INVALID_PRIVILEGE;
  83. break;
  84. case AESM_OUT_OF_EPC:
  85. mapped = SGX_ERROR_OUT_OF_EPC;
  86. break;
  87. default:
  88. mapped = SGX_ERROR_UNEXPECTED;
  89. }
  90. }
  91. }
  92. return mapped;
  93. }
  94. sgx_status_t sgx_init_quote(
  95. sgx_target_info_t *p_target_info,
  96. sgx_epid_group_id_t *p_gid)
  97. {
  98. if (p_target_info == NULL || p_gid == NULL)
  99. return SGX_ERROR_INVALID_PARAMETER;
  100. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  101. uae_oal_status_t status = oal_init_quote(p_target_info, p_gid, SE_INIT_QUOTE_TIMEOUT_MSEC*1000, &result);
  102. sgx_status_t mapped = oal_map_status(status);
  103. if (mapped != SGX_SUCCESS)
  104. return mapped;
  105. mapped = oal_map_result(result);
  106. if (mapped != SGX_SUCCESS)
  107. {
  108. /*operation specific mapping */
  109. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  110. {
  111. switch (result)
  112. {
  113. case AESM_EPIDBLOB_ERROR:
  114. mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
  115. break;
  116. case AESM_EPID_REVOKED_ERROR:
  117. mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
  118. break;
  119. case AESM_BACKEND_SERVER_BUSY:
  120. mapped = SGX_ERROR_BUSY;
  121. break;
  122. case AESM_SGX_PROVISION_FAILED:
  123. mapped = SGX_ERROR_UNEXPECTED;
  124. break;
  125. case AESM_OUT_OF_EPC:
  126. mapped = SGX_ERROR_OUT_OF_EPC;
  127. break;
  128. default:
  129. mapped = SGX_ERROR_UNEXPECTED;
  130. }
  131. }
  132. }
  133. return mapped;
  134. }
  135. sgx_status_t sgx_get_quote(
  136. const sgx_report_t *p_report,
  137. sgx_quote_sign_type_t quote_type,
  138. const sgx_spid_t *p_spid,
  139. const sgx_quote_nonce_t *p_nonce,
  140. const uint8_t *p_sig_rl,
  141. uint32_t sig_rl_size,
  142. sgx_report_t *p_qe_report,
  143. sgx_quote_t *p_quote,
  144. uint32_t quote_size)
  145. {
  146. if (p_report == NULL || p_spid == NULL || p_quote == NULL || quote_size == 0 )
  147. return SGX_ERROR_INVALID_PARAMETER;
  148. if ((p_sig_rl == NULL && sig_rl_size != 0) ||
  149. (p_sig_rl != NULL && sig_rl_size == 0) )
  150. return SGX_ERROR_INVALID_PARAMETER;
  151. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  152. uae_oal_status_t status = oal_get_quote(p_report, quote_type, p_spid, p_nonce, p_sig_rl, sig_rl_size, p_qe_report,
  153. p_quote, quote_size, SE_GET_QUOTE_TIMEOUT_MSEC(p_sig_rl)*1000, &result);
  154. sgx_status_t mapped = oal_map_status(status);
  155. if (mapped != SGX_SUCCESS)
  156. return mapped;
  157. mapped = oal_map_result(result);
  158. if (mapped != SGX_SUCCESS)
  159. {
  160. /*operation specific mapping */
  161. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  162. {
  163. switch (result)
  164. {
  165. case AESM_EPIDBLOB_ERROR:
  166. mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
  167. break;
  168. case AESM_EPID_REVOKED_ERROR:
  169. mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
  170. break;
  171. case AESM_BACKEND_SERVER_BUSY:
  172. mapped = SGX_ERROR_BUSY;
  173. break;
  174. case AESM_SGX_PROVISION_FAILED:
  175. mapped = SGX_ERROR_UNEXPECTED;
  176. break;
  177. case AESM_OUT_OF_EPC:
  178. mapped = SGX_ERROR_OUT_OF_EPC;
  179. break;
  180. default:
  181. mapped = SGX_ERROR_UNEXPECTED;
  182. }
  183. }
  184. }
  185. return mapped;
  186. }
  187. sgx_status_t sgx_get_ps_cap(sgx_ps_cap_t* p_sgx_ps_cap)
  188. {
  189. if (p_sgx_ps_cap == NULL)
  190. return SGX_ERROR_INVALID_PARAMETER;
  191. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  192. uint64_t ps_cap = 0;
  193. uae_oal_status_t status = oal_get_ps_cap(&ps_cap, SE_GET_PS_CAP_TIMEOUT_MSEC*1000, &result);
  194. p_sgx_ps_cap->ps_cap0 = (uint32_t)ps_cap;
  195. p_sgx_ps_cap->ps_cap1 = (uint32_t)(ps_cap >> 32);
  196. sgx_status_t mapped = oal_map_status(status);
  197. if (mapped != SGX_SUCCESS)
  198. return mapped;
  199. mapped = oal_map_result(result);
  200. if (mapped != SGX_SUCCESS)
  201. {
  202. /*operation specific mapping */
  203. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  204. {
  205. switch (result)
  206. {
  207. case AESM_LONG_TERM_PAIRING_FAILED:
  208. case AESM_EPH_SESSION_FAILED:
  209. case AESM_PSDA_UNAVAILABLE:
  210. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  211. break;
  212. default:
  213. mapped = SGX_ERROR_UNEXPECTED;
  214. }
  215. }
  216. }
  217. return mapped;
  218. }
  219. sgx_status_t sgx_report_attestation_status(
  220. const sgx_platform_info_t* p_platform_info,
  221. int attestation_status,
  222. sgx_update_info_bit_t* p_update_info)
  223. {
  224. if (p_platform_info == NULL || p_update_info == NULL)
  225. return SGX_ERROR_INVALID_PARAMETER;
  226. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  227. uae_oal_status_t status = oal_report_attestation_status(p_platform_info, attestation_status, p_update_info, SE_REPORT_REMOTE_ATTESTATION_FAILURE_TIMEOUT_MSEC*1000, &result);
  228. sgx_status_t mapped = oal_map_status(status);
  229. if (mapped != SGX_SUCCESS)
  230. return mapped;
  231. mapped = oal_map_result(result);
  232. if (mapped != SGX_SUCCESS)
  233. {
  234. /*operation specific mapping */
  235. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  236. {
  237. switch (result)
  238. {
  239. case AESM_BACKEND_SERVER_BUSY:
  240. mapped = SGX_ERROR_BUSY;
  241. break;
  242. case AESM_PLATFORM_INFO_BLOB_INVALID_SIG:
  243. mapped = SGX_ERROR_INVALID_PARAMETER;
  244. break;
  245. case AESM_EPIDBLOB_ERROR:
  246. mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
  247. break;
  248. case AESM_OUT_OF_EPC:
  249. mapped = SGX_ERROR_OUT_OF_EPC;
  250. break;
  251. case AESM_SGX_PROVISION_FAILED:
  252. default:
  253. mapped = SGX_ERROR_UNEXPECTED;
  254. }
  255. }
  256. }
  257. return mapped;
  258. }
  259. sgx_status_t create_session_ocall(
  260. uint32_t *session_id,
  261. uint8_t *se_dh_msg1,
  262. uint32_t dh_msg1_size,
  263. uint32_t timeout)
  264. {
  265. if(!session_id || !se_dh_msg1)
  266. return SGX_ERROR_INVALID_PARAMETER;
  267. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  268. uae_oal_status_t status = oal_create_session(session_id, se_dh_msg1, dh_msg1_size, timeout*1000, &result);
  269. sgx_status_t mapped = oal_map_status(status);
  270. if (mapped != SGX_SUCCESS)
  271. return mapped;
  272. mapped = oal_map_result(result);
  273. if (mapped != SGX_SUCCESS)
  274. {
  275. /*operation specific mapping */
  276. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  277. {
  278. switch (result)
  279. {
  280. case AESM_MAX_NUM_SESSION_REACHED:
  281. mapped = SGX_ERROR_BUSY;
  282. break;
  283. case AESM_EPH_SESSION_FAILED:
  284. case AESM_LONG_TERM_PAIRING_FAILED:
  285. case AESM_PSDA_UNAVAILABLE:
  286. case AESM_SERVICE_NOT_AVAILABLE:
  287. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  288. break;
  289. case AESM_OUT_OF_EPC:
  290. mapped = SGX_ERROR_OUT_OF_EPC;
  291. break;
  292. case AESM_MSG_ERROR:
  293. default:
  294. mapped = SGX_ERROR_UNEXPECTED;
  295. }
  296. }
  297. }
  298. return mapped;
  299. }
  300. sgx_status_t exchange_report_ocall(
  301. uint32_t session_id,
  302. const uint8_t *se_dh_msg2,
  303. uint32_t dh_msg2_size,
  304. uint8_t *se_dh_msg3,
  305. uint32_t dh_msg3_size,
  306. uint32_t timeout)
  307. {
  308. if (!se_dh_msg2 || !se_dh_msg3)
  309. return SGX_ERROR_INVALID_PARAMETER;
  310. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  311. uae_oal_status_t status = oal_exchange_report(session_id, se_dh_msg2, dh_msg2_size, se_dh_msg3, dh_msg3_size, timeout*1000, &result);
  312. sgx_status_t mapped = oal_map_status(status);
  313. if (mapped != SGX_SUCCESS)
  314. return mapped;
  315. mapped = oal_map_result(result);
  316. if (mapped != SGX_SUCCESS)
  317. {
  318. /*operation specific mapping */
  319. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  320. {
  321. switch (result)
  322. {
  323. case AESM_SESSION_INVALID:
  324. mapped = SGX_ERROR_AE_SESSION_INVALID;
  325. break;
  326. case AESM_KDF_MISMATCH:
  327. mapped = SGX_ERROR_KDF_MISMATCH;
  328. break;
  329. case AESM_EPH_SESSION_FAILED:
  330. case AESM_LONG_TERM_PAIRING_FAILED:
  331. case AESM_PSDA_UNAVAILABLE:
  332. case AESM_SERVICE_NOT_AVAILABLE:
  333. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  334. break;
  335. case AESM_OUT_OF_EPC:
  336. mapped = SGX_ERROR_OUT_OF_EPC;
  337. break;
  338. default:
  339. mapped = SGX_ERROR_UNEXPECTED;
  340. }
  341. }
  342. }
  343. return mapped;
  344. }
  345. sgx_status_t close_session_ocall(
  346. uint32_t session_id,
  347. uint32_t timeout)
  348. {
  349. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  350. uae_oal_status_t status = oal_close_session(session_id, timeout*1000, &result);
  351. sgx_status_t mapped = oal_map_status(status);
  352. if (mapped != SGX_SUCCESS)
  353. return mapped;
  354. mapped = oal_map_result(result);
  355. if (mapped != SGX_SUCCESS)
  356. {
  357. /*operation specific mapping */
  358. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  359. {
  360. switch (result)
  361. {
  362. case AESM_SESSION_INVALID:
  363. mapped = SGX_ERROR_AE_SESSION_INVALID;
  364. break;
  365. case AESM_EPH_SESSION_FAILED:
  366. case AESM_LONG_TERM_PAIRING_FAILED:
  367. case AESM_SERVICE_NOT_AVAILABLE:
  368. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  369. break;
  370. case AESM_OUT_OF_EPC:
  371. mapped = SGX_ERROR_OUT_OF_EPC;
  372. break;
  373. default:
  374. mapped = SGX_ERROR_UNEXPECTED;
  375. }
  376. }
  377. }
  378. return mapped;
  379. }
  380. sgx_status_t invoke_service_ocall(
  381. const uint8_t *pse_message_req,
  382. uint32_t pse_message_req_size,
  383. uint8_t *pse_message_resp,
  384. uint32_t pse_message_resp_size,
  385. uint32_t timeout)
  386. {
  387. if (pse_message_req == NULL || pse_message_resp == NULL)
  388. return SGX_ERROR_INVALID_PARAMETER;
  389. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  390. uae_oal_status_t status = oal_invoke_service(pse_message_req, pse_message_req_size, pse_message_resp, pse_message_resp_size, timeout*1000, &result);
  391. sgx_status_t mapped = oal_map_status(status);
  392. if (mapped != SGX_SUCCESS)
  393. return mapped;
  394. mapped = oal_map_result(result);
  395. if (mapped != SGX_SUCCESS)
  396. {
  397. /*operation specific mapping */
  398. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  399. {
  400. switch (result)
  401. {
  402. case AESM_SESSION_INVALID:
  403. mapped = SGX_ERROR_AE_SESSION_INVALID;
  404. break;
  405. case AESM_EPH_SESSION_FAILED:
  406. case AESM_LONG_TERM_PAIRING_FAILED:
  407. case AESM_PSDA_UNAVAILABLE:
  408. case AESM_SERVICE_NOT_AVAILABLE:
  409. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  410. break;
  411. case AESM_OUT_OF_EPC:
  412. mapped = SGX_ERROR_OUT_OF_EPC;
  413. break;
  414. case AESM_MSG_ERROR:
  415. default:
  416. mapped = SGX_ERROR_UNEXPECTED;
  417. }
  418. }
  419. }
  420. return mapped;
  421. }
  422. sgx_status_t sgx_get_whitelist_size(
  423. uint32_t* p_whitelist_size)
  424. {
  425. if (p_whitelist_size == NULL)
  426. return SGX_ERROR_INVALID_PARAMETER;
  427. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  428. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  429. ret = oal_get_whitelist_size(p_whitelist_size, GET_WHITE_LIST_SIZE_MSEC*1000, &result);
  430. //common mappings
  431. sgx_status_t mapped = oal_map_status(ret);
  432. if (mapped != SGX_SUCCESS)
  433. return mapped;
  434. mapped = oal_map_result(result);
  435. if (mapped != SGX_SUCCESS)
  436. {
  437. //operation specific mapping
  438. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  439. {
  440. switch (result)
  441. {
  442. default:
  443. mapped = SGX_ERROR_UNEXPECTED;
  444. }
  445. }
  446. }
  447. return mapped;
  448. }
  449. sgx_status_t sgx_get_whitelist(
  450. uint8_t* p_whitelist,
  451. uint32_t whitelist_size)
  452. {
  453. if (p_whitelist == NULL || whitelist_size == 0)
  454. return SGX_ERROR_INVALID_PARAMETER;
  455. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  456. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  457. ret = oal_get_whitelist(p_whitelist, whitelist_size, GET_WHITE_LIST_MSEC*1000, &result);
  458. //common mappings
  459. sgx_status_t mapped = oal_map_status(ret);
  460. if (mapped != SGX_SUCCESS)
  461. return mapped;
  462. mapped = oal_map_result(result);
  463. if (mapped != SGX_SUCCESS)
  464. {
  465. //operation specific mapping
  466. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  467. {
  468. switch (result)
  469. {
  470. default:
  471. mapped = SGX_ERROR_UNEXPECTED;
  472. }
  473. }
  474. }
  475. return mapped;
  476. }
  477. sgx_status_t sgx_get_extended_epid_group_id(
  478. uint32_t* p_extended_epid_group_id)
  479. {
  480. if (p_extended_epid_group_id == NULL)
  481. return SGX_ERROR_INVALID_PARAMETER;
  482. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  483. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  484. ret = oal_get_extended_epid_group_id(p_extended_epid_group_id, SGX_GET_EXTENDED_GROUP_ID_MSEC*1000, &result);
  485. //common mappings
  486. sgx_status_t mapped = oal_map_status(ret);
  487. if (mapped != SGX_SUCCESS)
  488. return mapped;
  489. mapped = oal_map_result(result);
  490. if (mapped != SGX_SUCCESS)
  491. {
  492. //operation specific mapping
  493. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  494. {
  495. switch (result)
  496. {
  497. default:
  498. mapped = SGX_ERROR_UNEXPECTED;
  499. }
  500. }
  501. }
  502. return mapped;
  503. }
  504. sgx_status_t sgx_switch_extended_epid_group(uint32_t extended_epid_group_id)
  505. {
  506. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  507. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  508. ret = oal_switch_extended_epid_group(extended_epid_group_id, SGX_SWITCH_EXTENDED_GROUP_MSEC*1000, &result);
  509. //common mappings
  510. sgx_status_t mapped = oal_map_status(ret);
  511. if (mapped != SGX_SUCCESS)
  512. return mapped;
  513. mapped = oal_map_result(result);
  514. if (mapped != SGX_SUCCESS)
  515. {
  516. //operation specific mapping
  517. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  518. {
  519. switch (result)
  520. {
  521. default:
  522. mapped = SGX_ERROR_UNEXPECTED;
  523. }
  524. }
  525. }
  526. return mapped;
  527. }
  528. typedef enum _sgx_register_type_t {SGX_REGISTER_WHITE_LIST_CERT} sgx_register_type_t;
  529. sgx_status_t sgx_register_wl_cert_chain(uint8_t* p_wl_cert_chain, uint32_t wl_cert_chain_size)
  530. {
  531. if (p_wl_cert_chain == NULL || wl_cert_chain_size == 0)
  532. return SGX_ERROR_INVALID_PARAMETER;
  533. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  534. uae_oal_status_t oal_ret = UAE_OAL_ERROR_UNEXPECTED;
  535. oal_ret = oal_register_common(p_wl_cert_chain, wl_cert_chain_size, SGX_REGISTER_WHITE_LIST_CERT,
  536. REG_WL_CERT_CHAIN_MSEC*1000, &result);
  537. //common mappings
  538. sgx_status_t mapped = oal_map_status(oal_ret);
  539. if (mapped != SGX_SUCCESS)
  540. return mapped;
  541. mapped = oal_map_result(result);
  542. if (mapped != SGX_SUCCESS)
  543. {
  544. //operation specific mapping
  545. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  546. {
  547. switch (result)
  548. {
  549. default:
  550. mapped = SGX_ERROR_UNEXPECTED;
  551. }
  552. }
  553. }
  554. return mapped;
  555. }
  556. // common mapper function for all OAL specific error codes
  557. sgx_status_t oal_map_status(uae_oal_status_t status)
  558. {
  559. sgx_status_t retVal;
  560. switch (status)
  561. {
  562. case UAE_OAL_SUCCESS:
  563. retVal = SGX_SUCCESS;
  564. break;
  565. case UAE_OAL_ERROR_UNEXPECTED:
  566. retVal = SGX_ERROR_UNEXPECTED;
  567. break;
  568. case UAE_OAL_ERROR_AESM_UNAVAILABLE:
  569. retVal = SGX_ERROR_SERVICE_UNAVAILABLE;
  570. break;
  571. case UAE_OAL_ERROR_TIMEOUT:
  572. retVal = SGX_ERROR_SERVICE_TIMEOUT;
  573. break;
  574. case UAE_OAL_ERROR_INVALID:
  575. retVal = SGX_ERROR_INVALID_PARAMETER;
  576. break;
  577. default:
  578. retVal = SGX_ERROR_UNEXPECTED;
  579. }
  580. return retVal;
  581. }
  582. sgx_status_t oal_map_result(aesm_error_t result)
  583. {
  584. sgx_status_t retVal = SGX_ERROR_UNEXPECTED;
  585. switch (result)
  586. {
  587. case AESM_SUCCESS:
  588. retVal = SGX_SUCCESS;
  589. break;
  590. case AESM_UPDATE_AVAILABLE:
  591. retVal = SGX_ERROR_UPDATE_NEEDED;
  592. break;
  593. case AESM_UNEXPECTED_ERROR:
  594. retVal = SGX_ERROR_UNEXPECTED;
  595. break;
  596. case AESM_PARAMETER_ERROR:
  597. retVal = SGX_ERROR_INVALID_PARAMETER;
  598. break;
  599. case AESM_SERVICE_STOPPED:
  600. case AESM_SERVICE_UNAVAILABLE:
  601. retVal = SGX_ERROR_SERVICE_UNAVAILABLE;
  602. break;
  603. case AESM_OUT_OF_MEMORY_ERROR:
  604. retVal = SGX_ERROR_OUT_OF_MEMORY;
  605. break;
  606. case AESM_BUSY:
  607. retVal = SGX_ERROR_BUSY;
  608. break;
  609. case AESM_UNRECOGNIZED_PLATFORM:
  610. retVal = SGX_ERROR_UNRECOGNIZED_PLATFORM;
  611. break;
  612. case AESM_NETWORK_ERROR:
  613. case AESM_NETWORK_BUSY_ERROR:
  614. case AESM_PROXY_SETTING_ASSIST:
  615. retVal = SGX_ERROR_NETWORK_FAILURE;
  616. break;
  617. case AESM_NO_DEVICE_ERROR:
  618. retVal = SGX_ERROR_NO_DEVICE;
  619. break;
  620. default:
  621. retVal = SGX_ERROR_UNEXPECTED;
  622. }
  623. return retVal;
  624. }
  625. } /* extern "C" */