internal_log.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. #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. // PSE ERROR CASES
  325. CASE_ENUM_RET_STRING(PSE_PAIRING_BLOB_SEALING_ERROR)
  326. CASE_ENUM_RET_STRING(PSE_PAIRING_BLOB_UNSEALING_ERROR)
  327. CASE_ENUM_RET_STRING(PSE_PAIRING_BLOB_INVALID_ERROR)
  328. // PSE_OP ERROR CASES
  329. CASE_ENUM_RET_STRING(PSE_OP_PARAMETER_ERROR)
  330. CASE_ENUM_RET_STRING(PSE_OP_INTERNAL_ERROR)
  331. CASE_ENUM_RET_STRING(PSE_OP_MAX_NUM_SESSION_REACHED)
  332. CASE_ENUM_RET_STRING(PSE_OP_SESSION_INVALID)
  333. CASE_ENUM_RET_STRING(PSE_OP_SERVICE_MSG_ERROR)
  334. CASE_ENUM_RET_STRING(PSE_OP_EPHEMERAL_SESSION_INVALID)
  335. CASE_ENUM_RET_STRING(PSE_OP_ERROR_EPH_SESSION_ESTABLISHMENT_INTEGRITY_ERROR)
  336. CASE_ENUM_RET_STRING(PSE_OP_UNKNWON_REQUEST_ERROR)
  337. CASE_ENUM_RET_STRING(PSE_OP_PSDA_BUSY_ERROR)
  338. CASE_ENUM_RET_STRING(PSE_OP_LTPB_SEALING_OUT_OF_DATE)
  339. // PSDA ERROR CODES
  340. CASE_ENUM_RET_STRING(AESM_PSDA_NOT_AVAILABLE)
  341. CASE_ENUM_RET_STRING(AESM_PSDA_INTERNAL_ERROR)
  342. CASE_ENUM_RET_STRING(AESM_PSDA_NEED_REPAIRING)
  343. CASE_ENUM_RET_STRING(AESM_PSDA_LT_SESSION_INTEGRITY_ERROR)
  344. CASE_ENUM_RET_STRING(AESM_PSDA_NOT_PROVISONED_ERROR)
  345. CASE_ENUM_RET_STRING(AESM_PSDA_PROTOCOL_NOT_SUPPORTED)
  346. CASE_ENUM_RET_STRING(AESM_PSDA_PLATFORM_KEYS_REVOKED)
  347. CASE_ENUM_RET_STRING(AESM_PSDA_SESSION_LOST)
  348. CASE_ENUM_RET_STRING(AESM_PSDA_WRITE_THROTTLED)
  349. // PSE_Pr ERROR CASES
  350. CASE_ENUM_RET_STRING(PSE_PR_ERROR)
  351. CASE_ENUM_RET_STRING(PSE_PR_PARAMETER_ERROR)
  352. CASE_ENUM_RET_STRING(PSE_PR_ENCLAVE_EXCEPTION)
  353. CASE_ENUM_RET_STRING(PSE_PR_CALL_ORDER_ERROR)
  354. CASE_ENUM_RET_STRING(PSE_PR_ASN1DER_DECODING_ERROR)
  355. CASE_ENUM_RET_STRING(PSE_PR_PAIRING_BLOB_SIZE_ERROR)
  356. CASE_ENUM_RET_STRING(PSE_PR_BAD_POINTER_ERROR)
  357. CASE_ENUM_RET_STRING(PSE_PR_SIGNING_CSR_ERROR)
  358. CASE_ENUM_RET_STRING(PSE_PR_MSG_SIGNING_ERROR)
  359. CASE_ENUM_RET_STRING(PSE_PR_INSUFFICIENT_MEMORY_ERROR)
  360. CASE_ENUM_RET_STRING(PSE_PR_BUFFER_TOO_SMALL_ERROR)
  361. CASE_ENUM_RET_STRING(PSE_PR_S3_DATA_ERROR)
  362. CASE_ENUM_RET_STRING(PSE_PR_KEY_PAIR_GENERATION_ERROR)
  363. CASE_ENUM_RET_STRING(PSE_PR_DERIVE_SMK_ERROR)
  364. CASE_ENUM_RET_STRING(PSE_PR_CREATE_REPORT_ERROR)
  365. CASE_ENUM_RET_STRING(PSE_PR_HASH_CALC_ERROR)
  366. CASE_ENUM_RET_STRING(PSE_PR_HMAC_CALC_ERROR)
  367. CASE_ENUM_RET_STRING(PSE_PR_ID_CALC_ERROR)
  368. CASE_ENUM_RET_STRING(PSE_PR_HMAC_COMPARE_ERROR)
  369. CASE_ENUM_RET_STRING(PSE_PR_GA_COMPARE_ERROR)
  370. CASE_ENUM_RET_STRING(PSE_PR_TASK_INFO_ERROR)
  371. CASE_ENUM_RET_STRING(PSE_PR_MSG_COMPARE_ERROR)
  372. CASE_ENUM_RET_STRING(PSE_PR_GID_MISMATCH_ERROR)
  373. CASE_ENUM_RET_STRING(PSE_PR_PR_CALC_ERROR)
  374. CASE_ENUM_RET_STRING(PSE_PR_PARAM_CERT_SIZE_ERROR)
  375. CASE_ENUM_RET_STRING(PSE_PR_CERT_SIZE_ERROR)
  376. CASE_ENUM_RET_STRING(PSE_PR_NO_OCSP_RESPONSE_ERROR)
  377. CASE_ENUM_RET_STRING(PSE_PR_X509_PARSE_ERROR)
  378. CASE_ENUM_RET_STRING(PSE_PR_READ_RAND_ERROR)
  379. CASE_ENUM_RET_STRING(PSE_PR_INTERNAL_ERROR)
  380. CASE_ENUM_RET_STRING(PSE_PR_ENCLAVE_BRIDGE_ERROR)
  381. CASE_ENUM_RET_STRING(PSE_PR_ENCLAVE_LOST_ERROR)
  382. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_SIG_INVALID)
  383. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_SIG_REVOKED_IN_GROUPRL)
  384. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_SIG_REVOKED_IN_PRIVRL)
  385. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_SIG_REVOKED_IN_SIGRL)
  386. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_SIG_REVOKED_IN_VERIFIERRL)
  387. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_UNKNOWN_ERROR)
  388. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_NOT_IMPLEMENTED)
  389. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_BAD_ARG_ERR)
  390. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_NO_MEMORY_ERR)
  391. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_MATH_ERR)
  392. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_DIVIDED_BY_ZERO_ERR)
  393. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_UNDERFLOW_ERR)
  394. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_HASH_ALGORITHM_NOT_SUPPORTED)
  395. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_RAND_MAX_ITER_ERR)
  396. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_DUPLICATE_ERR)
  397. CASE_ENUM_RET_STRING(PSE_PR_PCH_EPID_INCONSISTENT_BASENAME_SET_ERR)
  398. // AESM PSE_Pr ERROR CASES
  399. CASE_ENUM_RET_STRING(AESM_PSE_PR_ERROR_GETTING_GROUP_ID_FROM_ME)
  400. CASE_ENUM_RET_STRING(AESM_PSE_PR_INIT_QUOTE_ERROR)
  401. CASE_ENUM_RET_STRING(AESM_PSE_PR_GET_QUOTE_ERROR)
  402. CASE_ENUM_RET_STRING(AESM_PSE_PR_INSUFFICIENT_MEMORY_ERROR)
  403. CASE_ENUM_RET_STRING(AESM_PSE_PR_BUFFER_TOO_SMALL)
  404. CASE_ENUM_RET_STRING(AESM_PSE_PR_MAX_SIGRL_ENTRIES_EXCEEDED)
  405. CASE_ENUM_RET_STRING(AESM_PSE_PR_MAX_PRIVRL_ENTRIES_EXCEEDED)
  406. CASE_ENUM_RET_STRING(AESM_PSE_PR_GET_SIGRL_ERROR)
  407. CASE_ENUM_RET_STRING(AESM_PSE_PR_GET_OCSPRESP_ERROR)
  408. CASE_ENUM_RET_STRING(AESM_PSE_PR_CERT_SAVE_ERROR)
  409. CASE_ENUM_RET_STRING(AESM_PSE_PR_CERT_LOAD_ERROR)
  410. CASE_ENUM_RET_STRING(AESM_PSE_PR_CERT_DELETE_ERROR)
  411. CASE_ENUM_RET_STRING(AESM_PSE_PR_PSDA_LOAD_ERROR)
  412. CASE_ENUM_RET_STRING(AESM_PSE_PR_PSDA_PROVISION_ERROR)
  413. CASE_ENUM_RET_STRING(AESM_PSE_PR_PSDA_NOT_PROVISIONED)
  414. CASE_ENUM_RET_STRING(AESM_PSE_PR_PSDA_GET_GROUP_ID)
  415. CASE_ENUM_RET_STRING(AESM_PSE_PR_PSDA_LTP_EXCHANGE_ERROR)
  416. CASE_ENUM_RET_STRING(AESM_PSE_PR_PSDA_LTP_S1_ERROR)
  417. CASE_ENUM_RET_STRING(AESM_PSE_PR_PERSISTENT_STORAGE_DELETE_ERROR)
  418. CASE_ENUM_RET_STRING(AESM_PSE_PR_PERSISTENT_STORAGE_OPEN_ERROR)
  419. CASE_ENUM_RET_STRING(AESM_PSE_PR_PERSISTENT_STORAGE_WRITE_ERROR)
  420. CASE_ENUM_RET_STRING(AESM_PSE_PR_PERSISTENT_STORAGE_READ_ERROR)
  421. CASE_ENUM_RET_STRING(AESM_PSE_PR_BAD_POINTER_ERROR)
  422. CASE_ENUM_RET_STRING(AESM_PSE_PR_CALL_ORDER_ERROR)
  423. CASE_ENUM_RET_STRING(AESM_PSE_PR_INTERNAL_ERROR)
  424. CASE_ENUM_RET_STRING(AESM_PRSE_HECI_INIT_ERROR)
  425. CASE_ENUM_RET_STRING(AESM_PSE_PR_LOAD_VERIFIER_CERT_ERROR)
  426. CASE_ENUM_RET_STRING(AESM_PSE_PR_EXCEPTION)
  427. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_STATUS_MALFORMEDREQUEST)
  428. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_STATUS_INTERNALERROR)
  429. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_STATUS_TRYLATER)
  430. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_STATUS_SIGREQUIRED)
  431. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_STATUS_UNAUTHORIZED)
  432. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_INTERNAL_ERROR)
  433. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_NO_NONCE_ERROR)
  434. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_NONCE_VERIFY_ERROR)
  435. CASE_ENUM_RET_STRING(AESM_PSE_PR_OCSP_RESPONSE_VERIFY_ERROR)
  436. CASE_ENUM_RET_STRING(AESP_PSE_PR_OCSP_RESPONSE_CERT_COUNT_ERROR)
  437. CASE_ENUM_RET_STRING(AESM_PSE_PR_ICLS_CLIENT_MISSING_ERROR)
  438. CASE_ENUM_RET_STRING(AESM_PSE_PR_NO_OCSP_RESPONSE_ERROR)
  439. CASE_ENUM_RET_STRING(AESM_PSE_PR_RL_RESP_HEADER_ERROR)
  440. CASE_ENUM_RET_STRING(AESM_PSE_PR_RL_SERVER_ERROR)
  441. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INVALID_GID)
  442. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_GID_REVOKED)
  443. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INVALID_QUOTE)
  444. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INVALID_REQUEST)
  445. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_UNKNOWN_PROTOCOL_RESPONSE)
  446. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_SERVER_BUSY)
  447. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INTEGRITY_CHECK_FAIL)
  448. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INCORRECT_SYNTAX)
  449. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INCOMPATIBLE_VERSION)
  450. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_TRANSACTION_STATE_LOST)
  451. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_PROTOCOL_ERROR)
  452. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INTERNAL_ERROR)
  453. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_UNKNOWN_GENERAL_RESPONSE)
  454. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG1_GENERATE)
  455. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG2_RESPONSE_HEADER_INTEGRITY)
  456. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG3_GENERATE)
  457. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG4_RESPONSE_HEADER_INTEGRITY)
  458. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG4_TLV_INTEGRITY)
  459. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG4_PLATFORM_INFO_BLOB_SIZE)
  460. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG4_LEAF_CERTIFICATE_SIZE)
  461. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_MSG4_UNEXPECTED_TLV_TYPE)
  462. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_INVALID_URL)
  463. CASE_ENUM_RET_STRING(AESM_PSE_PR_BACKEND_NOT_INITIALIZED)
  464. CASE_ENUM_RET_STRING(AESM_NLTP_NO_LTP_BLOB)
  465. CASE_ENUM_RET_STRING(AESM_NLTP_DONT_NEED_UPDATE_PAIR_LTP)
  466. CASE_ENUM_RET_STRING(AESM_NLTP_MAY_NEED_UPDATE_LTP)
  467. CASE_ENUM_RET_STRING(AESM_NLTP_OLD_EPID11_RLS)
  468. CASE_ENUM_RET_STRING(AESM_PCP_NEED_PSE_UPDATE)
  469. CASE_ENUM_RET_STRING(AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE)
  470. CASE_ENUM_RET_STRING(AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE)
  471. CASE_ENUM_RET_STRING(AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR)
  472. CASE_ENUM_RET_STRING(AESM_PCP_SIMPLE_EPID_PROVISION_ERROR)
  473. CASE_ENUM_RET_STRING(AESM_NPC_DONT_NEED_PSEP)
  474. CASE_ENUM_RET_STRING(AESM_NPC_NO_PSE_CERT)
  475. CASE_ENUM_RET_STRING(AESM_NPC_DONT_NEED_UPDATE_PSEP)
  476. CASE_ENUM_RET_STRING(AESM_NPC_MAY_NEED_UPDATE_PSEP)
  477. CASE_ENUM_RET_STRING(AESM_NEP_DONT_NEED_EPID_PROVISIONING)
  478. CASE_ENUM_RET_STRING(AESM_NEP_DONT_NEED_UPDATE_PVEQE)
  479. CASE_ENUM_RET_STRING(AESM_NEP_PERFORMANCE_REKEY)
  480. CASE_ENUM_RET_STRING(AESM_NEP_MAY_NEED_UPDATE)
  481. CASE_ENUM_RET_STRING(AESM_CP_ATTESTATION_FAILURE)
  482. CASE_ENUM_RET_STRING(AESM_LTP_PSE_CERT_REVOKED)
  483. CASE_ENUM_RET_STRING(AESM_LTP_SIMPLE_LTP_ERROR)
  484. CASE_ENUM_RET_STRING(AESM_PSE_PR_GET_PRIVRL_ERROR)
  485. CASE_ENUM_RET_STRING(AESM_NETWORK_TIMEOUT)
  486. CASE_ENUM_RET_STRING(PSW_UPDATE_REQUIRED)
  487. CASE_ENUM_RET_STRING(PSE_OP_ERROR_KDF_MISMATCH)
  488. CASE_ENUM_RET_STRING(AESM_AE_OUT_OF_EPC)
  489. CASE_ENUM_RET_STRING(PVE_PROV_ATTEST_KEY_NOT_FOUND)
  490. CASE_ENUM_RET_STRING(PVE_INVALID_REPORT)
  491. CASE_ENUM_RET_STRING(PVE_XEGDSK_SIGN_ERROR)
  492. // PCE ERROR CODES
  493. CASE_ENUM_RET_STRING(PCE_UNEXPECTED_ERROR)
  494. CASE_ENUM_RET_STRING(PCE_INVALID_PRIVILEGE)
  495. CASE_ENUM_RET_STRING(PCE_INVALID_REPORT)
  496. CASE_ENUM_RET_STRING(LE_WHITE_LIST_QUERY_BUSY)
  497. CASE_ENUM_RET_STRING(AESM_AE_NO_DEVICE)
  498. CASE_ENUM_RET_STRING(EXTENDED_GROUP_NOT_AVAILABLE)
  499. default:
  500. return "Unknown ae_error_t";
  501. }
  502. }
  503. //(aesm%d)
  504. static const char *get_aesm_error_t_string(aesm_error_t aesm_error)
  505. {
  506. switch (aesm_error){
  507. CASE_ENUM_RET_STRING(AESM_SUCCESS)
  508. CASE_ENUM_RET_STRING(AESM_UNEXPECTED_ERROR)
  509. CASE_ENUM_RET_STRING(AESM_NO_DEVICE_ERROR)
  510. CASE_ENUM_RET_STRING(AESM_PARAMETER_ERROR)
  511. CASE_ENUM_RET_STRING(AESM_EPIDBLOB_ERROR)
  512. CASE_ENUM_RET_STRING(AESM_EPID_REVOKED_ERROR)
  513. CASE_ENUM_RET_STRING(AESM_GET_LICENSETOKEN_ERROR)
  514. CASE_ENUM_RET_STRING(AESM_SESSION_INVALID)
  515. CASE_ENUM_RET_STRING(AESM_MAX_NUM_SESSION_REACHED)
  516. CASE_ENUM_RET_STRING(AESM_PSDA_UNAVAILABLE)
  517. CASE_ENUM_RET_STRING(AESM_KDF_MISMATCH)
  518. CASE_ENUM_RET_STRING(AESM_EPH_SESSION_FAILED)
  519. CASE_ENUM_RET_STRING(AESM_LONG_TERM_PAIRING_FAILED)
  520. CASE_ENUM_RET_STRING(AESM_NETWORK_ERROR)
  521. CASE_ENUM_RET_STRING(AESM_NETWORK_BUSY_ERROR)
  522. CASE_ENUM_RET_STRING(AESM_PROXY_SETTING_ASSIST)
  523. CASE_ENUM_RET_STRING(AESM_FILE_ACCESS_ERROR)
  524. CASE_ENUM_RET_STRING(AESM_SGX_PROVISION_FAILED)
  525. CASE_ENUM_RET_STRING(AESM_SERVICE_STOPPED)
  526. CASE_ENUM_RET_STRING(AESM_BUSY)
  527. CASE_ENUM_RET_STRING(AESM_BACKEND_SERVER_BUSY)
  528. CASE_ENUM_RET_STRING(AESM_UPDATE_AVAILABLE)
  529. CASE_ENUM_RET_STRING(AESM_OUT_OF_MEMORY_ERROR)
  530. CASE_ENUM_RET_STRING(AESM_MSG_ERROR)
  531. CASE_ENUM_RET_STRING(AESM_ENABLE_SGX_DEVICE_FAILED)
  532. CASE_ENUM_RET_STRING(AESM_PLATFORM_INFO_BLOB_INVALID_SIG)
  533. CASE_ENUM_RET_STRING(AESM_OUT_OF_EPC)
  534. CASE_ENUM_RET_STRING(AESM_SERVICE_UNAVAILABLE)
  535. CASE_ENUM_RET_STRING(AESM_UNRECOGNIZED_PLATFORM)
  536. default:
  537. return "Unknow aesm_error_t";
  538. }
  539. }
  540. //(sgx)
  541. static const char *get_sgx_status_t_string(sgx_status_t status)
  542. {
  543. switch (status){
  544. CASE_ENUM_RET_STRING(SGX_SUCCESS)
  545. CASE_ENUM_RET_STRING(SGX_ERROR_UNEXPECTED)
  546. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_PARAMETER)
  547. CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_MEMORY)
  548. CASE_ENUM_RET_STRING(SGX_ERROR_ENCLAVE_LOST)
  549. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_STATE)
  550. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_FUNCTION)
  551. CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_TCS)
  552. CASE_ENUM_RET_STRING(SGX_ERROR_ENCLAVE_CRASHED )
  553. CASE_ENUM_RET_STRING(SGX_ERROR_ECALL_NOT_ALLOWED)
  554. CASE_ENUM_RET_STRING(SGX_ERROR_OCALL_NOT_ALLOWED)
  555. CASE_ENUM_RET_STRING(SGX_ERROR_UNDEFINED_SYMBOL)
  556. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ENCLAVE)
  557. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ENCLAVE_ID)
  558. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_SIGNATURE)
  559. CASE_ENUM_RET_STRING(SGX_ERROR_NDEBUG_ENCLAVE)
  560. CASE_ENUM_RET_STRING(SGX_ERROR_OUT_OF_EPC)
  561. CASE_ENUM_RET_STRING(SGX_ERROR_NO_DEVICE)
  562. CASE_ENUM_RET_STRING(SGX_ERROR_MEMORY_MAP_CONFLICT)
  563. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_METADATA)
  564. CASE_ENUM_RET_STRING(SGX_ERROR_DEVICE_BUSY)
  565. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_VERSION)
  566. CASE_ENUM_RET_STRING(SGX_ERROR_MODE_INCOMPATIBLE)
  567. CASE_ENUM_RET_STRING(SGX_ERROR_ENCLAVE_FILE_ACCESS)
  568. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_MISC)
  569. CASE_ENUM_RET_STRING(SGX_ERROR_MAC_MISMATCH)
  570. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ATTRIBUTE)
  571. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_CPUSVN)
  572. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_ISVSVN)
  573. CASE_ENUM_RET_STRING(SGX_ERROR_INVALID_KEYNAME)
  574. CASE_ENUM_RET_STRING(SGX_ERROR_SERVICE_UNAVAILABLE)
  575. CASE_ENUM_RET_STRING(SGX_ERROR_SERVICE_TIMEOUT)
  576. CASE_ENUM_RET_STRING(SGX_ERROR_AE_INVALID_EPIDBLOB)
  577. CASE_ENUM_RET_STRING(SGX_ERROR_SERVICE_INVALID_PRIVILEGE)
  578. CASE_ENUM_RET_STRING(SGX_ERROR_EPID_MEMBER_REVOKED)
  579. CASE_ENUM_RET_STRING(SGX_ERROR_UPDATE_NEEDED)
  580. CASE_ENUM_RET_STRING(SGX_ERROR_NETWORK_FAILURE)
  581. CASE_ENUM_RET_STRING(SGX_ERROR_AE_SESSION_INVALID)
  582. CASE_ENUM_RET_STRING(SGX_ERROR_BUSY)
  583. CASE_ENUM_RET_STRING(SGX_ERROR_MC_NOT_FOUND)
  584. CASE_ENUM_RET_STRING(SGX_ERROR_MC_NO_ACCESS_RIGHT)
  585. CASE_ENUM_RET_STRING(SGX_ERROR_MC_USED_UP)
  586. CASE_ENUM_RET_STRING(SGX_ERROR_MC_OVER_QUOTA)
  587. CASE_ENUM_RET_STRING(SGX_ERROR_KDF_MISMATCH)
  588. default:
  589. return "Unknown sgx_status_t";
  590. }
  591. }
  592. #endif