internal_log.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. #ifdef DBG_LOG
  32. #include "oal/oal.h"
  33. #include <time.h>
  34. #include <stdio.h>
  35. #include <stdarg.h>
  36. #include <assert.h>
  37. #include <ctype.h>
  38. #include <se_stdio.h>
  39. #include <se_string.h>
  40. #include "se_thread.h"
  41. #include "type_length_value.h"
  42. #include "aeerror.h"
  43. #include "aesm_error.h"
  44. #include "sgx_error.h"
  45. static int aesm_trace_level = TRACE_LOG_LEVEL;
  46. static int at_start=1;
  47. se_mutex_t cs;
  48. static ae_error_t init_log_file(void)
  49. {
  50. char filename[MAX_PATH];
  51. ae_error_t err = aesm_get_pathname(FT_PERSISTENT_STORAGE, AESM_DBG_LOG_FID, filename, MAX_PATH);
  52. if(err != AE_SUCCESS)
  53. return err;
  54. return AE_SUCCESS;
  55. }
  56. #include <string>
  57. using namespace std;
  58. static const char *get_sgx_status_t_string(sgx_status_t status);
  59. static const char *get_ae_error_t_string(ae_error_t ae_error);
  60. static const char *get_aesm_error_t_string(aesm_error_t aesm_error);
  61. static const char *get_tlv_enum_type_t_string(uint8_t type);
  62. const char *support_tags[] = {
  63. "sgx",
  64. "aesm",//matching longer tag before shorter one so aesm should be arranged before ae
  65. "ae",
  66. "tlv"
  67. };
  68. #define COUNT_TAGS (sizeof(support_tags)/sizeof(support_tags[0]))
  69. #define TAG_SGX 0
  70. #define TAG_AESM 1
  71. #define TAG_AE 2
  72. #define TAG_TLV 3
  73. #define MAX_BUF_SIZE 4096
  74. std::string internal_log_msg_trans(const std::string& s)
  75. {
  76. std::string output;
  77. size_t i;
  78. const char *p = s.c_str();
  79. for (i = 0; i < s.length(); ++i){
  80. if (p[i] == '('){//begin of tag
  81. size_t start = i + 1;
  82. while (isspace(p[start]))start++;//skip all space
  83. int j;
  84. for (j = 0; j < COUNT_TAGS; ++j){
  85. int tag_len = strlen(support_tags[j]);
  86. if (strncmp(p + start, support_tags[j], tag_len) == 0){
  87. start += tag_len;
  88. break;
  89. }
  90. }
  91. if (j < COUNT_TAGS){//found a potential tag
  92. while (isspace(p[start]))start++;//skip all space after tag
  93. if ((p[start] == '-' || p[start] == '+') && isdigit(p[start + 1]) ||
  94. isdigit(p[start])){
  95. int number = strtol(p + start,NULL, 0);
  96. switch (j){
  97. case TAG_SGX:
  98. output += "(sgx_status_t:";
  99. output += get_sgx_status_t_string((sgx_status_t)number);
  100. output += ":";
  101. break;
  102. case TAG_AESM:
  103. output += "(aesm_error_t:";
  104. output += get_aesm_error_t_string((aesm_error_t)number);
  105. output += ":";
  106. break;
  107. case TAG_AE:
  108. output += "(ae_error_t:";
  109. output += get_ae_error_t_string((ae_error_t)number);
  110. output += ":";
  111. break;
  112. case TAG_TLV:
  113. output += "(TLV:";
  114. output += get_tlv_enum_type_t_string((uint8_t)number);
  115. output += ":";
  116. break;
  117. default:
  118. output += "(Unknown type:";
  119. break;
  120. }
  121. i = start-1;
  122. }
  123. else{
  124. output += p[i];
  125. }
  126. }
  127. else{//not found, keep original flags
  128. output += p[i];
  129. }
  130. }
  131. else{
  132. output += p[i];
  133. }
  134. }
  135. return output;
  136. }
  137. #define TIME_BUF_SIZE 100
  138. void aesm_internal_log(const char *file_name, int line_no, const char *funname, int level, const char *format, ...)
  139. {
  140. if(level <= aesm_trace_level){
  141. if(at_start){
  142. at_start=0;
  143. se_mutex_init(&cs);
  144. init_log_file();
  145. }
  146. char filename[MAX_PATH];
  147. ae_error_t err = aesm_get_cpathname(FT_PERSISTENT_STORAGE, AESM_DBG_LOG_FID, filename, MAX_PATH);
  148. if(err != AE_SUCCESS)
  149. return;
  150. FILE *logfile = NULL;
  151. se_mutex_lock(&cs);
  152. logfile = fopen(filename, "a+");
  153. if(logfile == NULL){
  154. se_mutex_unlock(&cs);
  155. return;
  156. }
  157. time_t t;
  158. struct tm time_info;
  159. va_list varg;
  160. char time_buf[TIME_BUF_SIZE];
  161. time(&t);
  162. struct tm *temp_time_info;
  163. temp_time_info = localtime(&t);
  164. memcpy_s(&time_info, sizeof(time_info), temp_time_info, sizeof(*temp_time_info));
  165. if(strftime(time_buf, TIME_BUF_SIZE, "%c", &time_info)!=0){
  166. fprintf(logfile, "[%s|%d|%s|%s]",file_name, line_no, funname, time_buf);
  167. }else{
  168. fprintf(logfile, "[%s|%d|%s]",file_name, line_no, funname);
  169. }
  170. va_start(varg, format);
  171. char message_buf[MAX_BUF_SIZE];
  172. vsnprintf(message_buf, MAX_BUF_SIZE-1, format, varg);
  173. va_end(varg);
  174. std::string input_message = message_buf;
  175. std::string output_message = internal_log_msg_trans(input_message);
  176. fprintf(logfile, "%s\n", output_message.c_str());
  177. fflush(logfile);
  178. fclose(logfile);
  179. se_mutex_unlock(&cs);
  180. }
  181. }
  182. void aesm_set_log_level(int level)
  183. {
  184. aesm_trace_level = level;
  185. }
  186. static char half_byte_to_char(int x)
  187. {
  188. assert(0<=x&&x<=0xF);
  189. if(0<=x&&x<=9)return (char)('0'+x);
  190. else return (char)('A'+x-10);
  191. }
  192. void aesm_dbg_format_hex(const uint8_t *data, uint32_t data_len, char *out_buf, uint32_t buf_size)
  193. {
  194. uint32_t i;
  195. assert(buf_size>0);
  196. if(data_len==0){
  197. out_buf[0]='\0';
  198. return;
  199. }
  200. if(buf_size/3>=data_len){
  201. for(i=0;i<data_len;i++){
  202. int low=data[i]&0xF;
  203. int high=(data[i]>>4)&0xF;
  204. out_buf[i*3]=half_byte_to_char(high);
  205. out_buf[i*3+1]=half_byte_to_char(low);
  206. out_buf[i*3+2]=' ';
  207. }
  208. out_buf[data_len*3-1]='\0';
  209. }else if(buf_size>10){
  210. uint32_t tcount=buf_size/3-1;
  211. uint32_t off;
  212. uint32_t ecount=tcount/2,bcount=tcount-ecount;
  213. for(i=0;i<bcount;i++){
  214. int low=data[i]&0xF;
  215. int high=(data[i]>>4)&0xF;
  216. out_buf[i*3]=half_byte_to_char(high);
  217. out_buf[i*3+1]=half_byte_to_char(low);
  218. out_buf[i*3+2]=' ';
  219. }
  220. out_buf[i*3]=out_buf[i*3+1]=out_buf[i*3+2]='.';
  221. off=i*3+3;
  222. for(i=0;i<ecount;i++){
  223. int low=data[data_len-ecount+i]&0xF;
  224. int high=(data[data_len-ecount+i]>>4)&0xF;
  225. out_buf[off+i*3]=half_byte_to_char(high);
  226. out_buf[off+i*3+1]=half_byte_to_char(low);
  227. out_buf[off+i*3+2]=' ';
  228. }
  229. out_buf[off+i*3-1]='\0';
  230. }else{
  231. for(i=0;/*i<data_len&&*/i<(buf_size-1)/3;i++){//checking for i<data_len is redundant since first if condition in the function has filtered it
  232. int low=data[i]&0xF;
  233. int high=(data[i]>>4)&0xF;
  234. out_buf[i*3]=half_byte_to_char(high);
  235. out_buf[i*3+1]=half_byte_to_char(low);
  236. out_buf[i*3+2]=' ';
  237. }
  238. out_buf[i*3]='\0';
  239. }
  240. }
  241. #define CASE_ENUM_RET_STRING(x) case x: return #x;
  242. //(tlv%d)
  243. static const char *get_tlv_enum_type_t_string(uint8_t type)
  244. {
  245. switch (type){
  246. CASE_ENUM_RET_STRING(TLV_CIPHER_TEXT)
  247. CASE_ENUM_RET_STRING(TLV_BLOCK_CIPHER_TEXT)
  248. CASE_ENUM_RET_STRING(TLV_BLOCK_CIPHER_INFO)
  249. CASE_ENUM_RET_STRING(TLV_MESSAGE_AUTHENTICATION_CODE)
  250. CASE_ENUM_RET_STRING(TLV_NONCE)
  251. CASE_ENUM_RET_STRING(TLV_EPID_GID)
  252. CASE_ENUM_RET_STRING(TLV_EPID_SIG_RL)
  253. CASE_ENUM_RET_STRING(TLV_EPID_GROUP_CERT)
  254. CASE_ENUM_RET_STRING(TLV_DEVICE_ID)
  255. CASE_ENUM_RET_STRING(TLV_PS_ID)
  256. CASE_ENUM_RET_STRING(TLV_EPID_JOIN_PROOF)
  257. CASE_ENUM_RET_STRING(TLV_EPID_SIG)
  258. CASE_ENUM_RET_STRING(TLV_EPID_MEMBERSHIP_CREDENTIAL)
  259. CASE_ENUM_RET_STRING(TLV_EPID_PSVN)
  260. CASE_ENUM_RET_STRING(TLV_QUOTE)
  261. CASE_ENUM_RET_STRING(TLV_X509_CERT_TLV)
  262. CASE_ENUM_RET_STRING(TLV_X509_CSR_TLV)
  263. CASE_ENUM_RET_STRING(TLV_ES_SELECTOR)
  264. CASE_ENUM_RET_STRING(TLV_ES_INFORMATION)
  265. CASE_ENUM_RET_STRING(TLV_FLAGS)
  266. CASE_ENUM_RET_STRING(TLV_QUOTE_SIG)
  267. CASE_ENUM_RET_STRING(TLV_PEK)
  268. CASE_ENUM_RET_STRING(TLV_SIGNATURE)
  269. CASE_ENUM_RET_STRING(TLV_PLATFORM_INFO)
  270. CASE_ENUM_RET_STRING(TLV_PWK2)
  271. CASE_ENUM_RET_STRING(TLV_SE_REPORT)
  272. default:
  273. return "Unknown TLV";
  274. }
  275. }
  276. //(ae%d)
  277. static const char *get_ae_error_t_string(ae_error_t ae_error)
  278. {
  279. switch (ae_error){
  280. CASE_ENUM_RET_STRING(AE_SUCCESS)
  281. CASE_ENUM_RET_STRING(AE_FAILURE)
  282. CASE_ENUM_RET_STRING(AE_ENCLAVE_LOST)
  283. CASE_ENUM_RET_STRING(OAL_PARAMETER_ERROR)
  284. CASE_ENUM_RET_STRING(OAL_PATHNAME_BUFFER_OVERFLOW_ERROR)
  285. CASE_ENUM_RET_STRING(OAL_FILE_ACCESS_ERROR)
  286. CASE_ENUM_RET_STRING(OAL_CONFIG_FILE_ERROR)
  287. CASE_ENUM_RET_STRING(OAL_NETWORK_UNAVAILABLE_ERROR)
  288. CASE_ENUM_RET_STRING(OAL_NETWORK_BUSY)
  289. CASE_ENUM_RET_STRING(OAL_NETWORK_RESEND_REQUIRED)
  290. CASE_ENUM_RET_STRING(OAL_PROXY_SETTING_ASSIST)
  291. CASE_ENUM_RET_STRING(OAL_THREAD_ERROR)
  292. CASE_ENUM_RET_STRING(OAL_THREAD_TIMEOUT_ERROR)
  293. CASE_ENUM_RET_STRING(AE_PSVN_UNMATCHED_ERROR)
  294. CASE_ENUM_RET_STRING(AE_SERVER_NOT_AVAILABLE)
  295. CASE_ENUM_RET_STRING(AE_INVALID_PARAMETER)
  296. CASE_ENUM_RET_STRING(AE_READ_RAND_ERROR)
  297. CASE_ENUM_RET_STRING(AE_OUT_OF_MEMORY_ERROR)
  298. CASE_ENUM_RET_STRING(AE_INSUFFICIENT_DATA_IN_BUFFER)
  299. CASE_ENUM_RET_STRING(QE_UNEXPECTED_ERROR)
  300. CASE_ENUM_RET_STRING(QE_PARAMETER_ERROR)
  301. CASE_ENUM_RET_STRING(QE_EPIDBLOB_ERROR)
  302. CASE_ENUM_RET_STRING(QE_REVOKED_ERROR)
  303. CASE_ENUM_RET_STRING(QE_SIGRL_ERROR)
  304. CASE_ENUM_RET_STRING(PVE_UNEXPECTED_ERROR)
  305. CASE_ENUM_RET_STRING(PVE_PARAMETER_ERROR)
  306. CASE_ENUM_RET_STRING(PVE_EPIDBLOB_ERROR)
  307. CASE_ENUM_RET_STRING(PVE_INSUFFICIENT_MEMORY_ERROR)
  308. CASE_ENUM_RET_STRING(PVE_INTEGRITY_CHECK_ERROR)
  309. CASE_ENUM_RET_STRING(PVE_SIGRL_INTEGRITY_CHECK_ERROR)
  310. CASE_ENUM_RET_STRING(PVE_SERVER_REPORTED_ERROR)
  311. CASE_ENUM_RET_STRING(PVE_PEK_SIGN_ERROR)
  312. CASE_ENUM_RET_STRING(PVE_MSG_ERROR)
  313. CASE_ENUM_RET_STRING(PVE_REVOKED_ERROR)
  314. CASE_ENUM_RET_STRING(PVE_SESSION_OUT_OF_ORDER_ERROR)
  315. CASE_ENUM_RET_STRING(PVE_SERVER_BUSY_ERROR)
  316. CASE_ENUM_RET_STRING(PVE_PERFORMANCE_REKEY_NOT_SUPPORTED)
  317. CASE_ENUM_RET_STRING(LE_UNEXPECTED_ERROR)
  318. CASE_ENUM_RET_STRING(LE_INVALID_PARAMETER)
  319. CASE_ENUM_RET_STRING(LE_GET_EINITTOKEN_KEY_ERROR)
  320. CASE_ENUM_RET_STRING(LE_INVALID_ATTRIBUTE)
  321. CASE_ENUM_RET_STRING(LE_INVALID_PRIVILEGE_ERROR)
  322. CASE_ENUM_RET_STRING(LE_WHITELIST_UNINITIALIZED_ERROR)
  323. CASE_ENUM_RET_STRING(LE_CALC_LIC_TOKEN_ERROR)
  324. CASE_ENUM_RET_STRING(AESM_NLTP_NO_LTP_BLOB)
  325. CASE_ENUM_RET_STRING(AESM_NLTP_DONT_NEED_UPDATE_PAIR_LTP)
  326. CASE_ENUM_RET_STRING(AESM_NLTP_MAY_NEED_UPDATE_LTP)
  327. CASE_ENUM_RET_STRING(AESM_NLTP_OLD_EPID11_RLS)
  328. CASE_ENUM_RET_STRING(AESM_PCP_NEED_PSE_UPDATE)
  329. CASE_ENUM_RET_STRING(AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE)
  330. CASE_ENUM_RET_STRING(AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE)
  331. CASE_ENUM_RET_STRING(AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR)
  332. CASE_ENUM_RET_STRING(AESM_PCP_SIMPLE_EPID_PROVISION_ERROR)
  333. CASE_ENUM_RET_STRING(AESM_NPC_DONT_NEED_PSEP)
  334. CASE_ENUM_RET_STRING(AESM_NPC_NO_PSE_CERT)
  335. CASE_ENUM_RET_STRING(AESM_NPC_DONT_NEED_UPDATE_PSEP)
  336. CASE_ENUM_RET_STRING(AESM_NPC_MAY_NEED_UPDATE_PSEP)
  337. CASE_ENUM_RET_STRING(AESM_NEP_DONT_NEED_EPID_PROVISIONING)
  338. CASE_ENUM_RET_STRING(AESM_NEP_DONT_NEED_UPDATE_PVEQE)
  339. CASE_ENUM_RET_STRING(AESM_NEP_PERFORMANCE_REKEY)
  340. CASE_ENUM_RET_STRING(AESM_NEP_MAY_NEED_UPDATE)
  341. CASE_ENUM_RET_STRING(AESM_CP_ATTESTATION_FAILURE)
  342. CASE_ENUM_RET_STRING(AESM_LTP_PSE_CERT_REVOKED)
  343. CASE_ENUM_RET_STRING(AESM_LTP_SIMPLE_LTP_ERROR)
  344. CASE_ENUM_RET_STRING(AESM_PSE_PR_GET_PRIVRL_ERROR)
  345. CASE_ENUM_RET_STRING(AESM_NETWORK_TIMEOUT)
  346. CASE_ENUM_RET_STRING(PSW_UPDATE_REQUIRED)
  347. CASE_ENUM_RET_STRING(PSE_OP_ERROR_KDF_MISMATCH)
  348. CASE_ENUM_RET_STRING(AESM_AE_OUT_OF_EPC)
  349. CASE_ENUM_RET_STRING(PVE_PROV_ATTEST_KEY_NOT_FOUND)
  350. CASE_ENUM_RET_STRING(PVE_INVALID_REPORT)
  351. CASE_ENUM_RET_STRING(PVE_XEGDSK_SIGN_ERROR)
  352. // PCE ERROR CODES
  353. CASE_ENUM_RET_STRING(PCE_UNEXPECTED_ERROR)
  354. CASE_ENUM_RET_STRING(PCE_INVALID_PRIVILEGE)
  355. CASE_ENUM_RET_STRING(PCE_INVALID_REPORT)
  356. CASE_ENUM_RET_STRING(LE_WHITE_LIST_QUERY_BUSY)
  357. CASE_ENUM_RET_STRING(AESM_AE_NO_DEVICE)
  358. CASE_ENUM_RET_STRING(EXTENDED_GROUP_NOT_AVAILABLE)
  359. default:
  360. return "Unknown ae_error_t";
  361. }
  362. }
  363. //(aesm%d)
  364. static const char *get_aesm_error_t_string(aesm_error_t aesm_error)
  365. {
  366. switch (aesm_error){
  367. CASE_ENUM_RET_STRING(AESM_SUCCESS)
  368. CASE_ENUM_RET_STRING(AESM_UNEXPECTED_ERROR)
  369. CASE_ENUM_RET_STRING(AESM_NO_DEVICE_ERROR)
  370. CASE_ENUM_RET_STRING(AESM_PARAMETER_ERROR)
  371. CASE_ENUM_RET_STRING(AESM_EPIDBLOB_ERROR)
  372. CASE_ENUM_RET_STRING(AESM_EPID_REVOKED_ERROR)
  373. CASE_ENUM_RET_STRING(AESM_GET_LICENSETOKEN_ERROR)
  374. CASE_ENUM_RET_STRING(AESM_SESSION_INVALID)
  375. CASE_ENUM_RET_STRING(AESM_MAX_NUM_SESSION_REACHED)
  376. CASE_ENUM_RET_STRING(AESM_PSDA_UNAVAILABLE)
  377. CASE_ENUM_RET_STRING(AESM_KDF_MISMATCH)
  378. CASE_ENUM_RET_STRING(AESM_EPH_SESSION_FAILED)
  379. CASE_ENUM_RET_STRING(AESM_LONG_TERM_PAIRING_FAILED)
  380. CASE_ENUM_RET_STRING(AESM_NETWORK_ERROR)
  381. CASE_ENUM_RET_STRING(AESM_NETWORK_BUSY_ERROR)
  382. CASE_ENUM_RET_STRING(AESM_PROXY_SETTING_ASSIST)
  383. CASE_ENUM_RET_STRING(AESM_FILE_ACCESS_ERROR)
  384. CASE_ENUM_RET_STRING(AESM_SGX_PROVISION_FAILED)
  385. CASE_ENUM_RET_STRING(AESM_SERVICE_STOPPED)
  386. CASE_ENUM_RET_STRING(AESM_BUSY)
  387. CASE_ENUM_RET_STRING(AESM_BACKEND_SERVER_BUSY)
  388. CASE_ENUM_RET_STRING(AESM_UPDATE_AVAILABLE)
  389. CASE_ENUM_RET_STRING(AESM_OUT_OF_MEMORY_ERROR)
  390. CASE_ENUM_RET_STRING(AESM_MSG_ERROR)
  391. CASE_ENUM_RET_STRING(AESM_ENABLE_SGX_DEVICE_FAILED)
  392. CASE_ENUM_RET_STRING(AESM_PLATFORM_INFO_BLOB_INVALID_SIG)
  393. CASE_ENUM_RET_STRING(AESM_OUT_OF_EPC)
  394. CASE_ENUM_RET_STRING(AESM_SERVICE_UNAVAILABLE)
  395. CASE_ENUM_RET_STRING(AESM_UNRECOGNIZED_PLATFORM)
  396. default:
  397. return "Unknow aesm_error_t";
  398. }
  399. }
  400. //(sgx)
  401. static const char *get_sgx_status_t_string(sgx_status_t status)
  402. {
  403. switch (status){
  404. CASE_ENUM_RET_STRING(SGX_SUCCESS)
  405. CASE_ENUM_RET_STRING(SGX_ERROR_UNEXPECTED)
  406. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_PARAMETER)
  407. CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_MEMORY)
  408. CASE_ENUM_RET_STRING(SGX_ERROR_ENCLAVE_LOST)
  409. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_STATE)
  410. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_FUNCTION)
  411. CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_TCS)
  412. CASE_ENUM_RET_STRING(SGX_ERROR_ENCLAVE_CRASHED )
  413. CASE_ENUM_RET_STRING(SGX_ERROR_ECALL_NOT_ALLOWED)
  414. CASE_ENUM_RET_STRING(SGX_ERROR_OCALL_NOT_ALLOWED)
  415. CASE_ENUM_RET_STRING(SGX_ERROR_UNDEFINED_SYMBOL)
  416. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ENCLAVE)
  417. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ENCLAVE_ID)
  418. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_SIGNATURE)
  419. CASE_ENUM_RET_STRING(SGX_ERROR_NDEBUG_ENCLAVE)
  420. CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_EPC)
  421. CASE_ENUM_RET_STRING(SGX_ERROR_NO_DEVICE)
  422. CASE_ENUM_RET_STRING(SGX_ERROR_MEMORY_MAP_CONFLICT)
  423. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_METADATA)
  424. CASE_ENUM_RET_STRING(SGX_ERROR_DEVICE_BUSY)
  425. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_VERSION)
  426. CASE_ENUM_RET_STRING(SGX_ERROR_MODE_INCOMPATIBLE)
  427. CASE_ENUM_RET_STRING(SGX_ERROR_ENCLAVE_FILE_ACCESS)
  428. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_MISC)
  429. CASE_ENUM_RET_STRING(SGX_ERROR_MAC_MISMATCH)
  430. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ATTRIBUTE)
  431. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_CPUSVN)
  432. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ISVSVN)
  433. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_KEYNAME)
  434. CASE_ENUM_RET_STRING(SGX_ERROR_SERVICE_UNAVAILABLE)
  435. CASE_ENUM_RET_STRING(SGX_ERROR_SERVICE_TIMEOUT)
  436. CASE_ENUM_RET_STRING(SGX_ERROR_AE_INVALID_EPIDBLOB)
  437. CASE_ENUM_RET_STRING(SGX_ERROR_SERVICE_INVALID_PRIVILEGE)
  438. CASE_ENUM_RET_STRING(SGX_ERROR_EPID_MEMBER_REVOKED)
  439. CASE_ENUM_RET_STRING(SGX_ERROR_UPDATE_NEEDED)
  440. CASE_ENUM_RET_STRING(SGX_ERROR_NETWORK_FAILURE)
  441. CASE_ENUM_RET_STRING(SGX_ERROR_AE_SESSION_INVALID)
  442. CASE_ENUM_RET_STRING(SGX_ERROR_BUSY)
  443. CASE_ENUM_RET_STRING(SGX_ERROR_MC_NOT_FOUND)
  444. CASE_ENUM_RET_STRING(SGX_ERROR_MC_NO_ACCESS_RIGHT)
  445. CASE_ENUM_RET_STRING(SGX_ERROR_MC_USED_UP)
  446. CASE_ENUM_RET_STRING(SGX_ERROR_MC_OVER_QUOTA)
  447. CASE_ENUM_RET_STRING(SGX_ERROR_KDF_MISMATCH)
  448. default:
  449. return "Unknown sgx_status_t";
  450. }
  451. }
  452. #endif