platform_info_logic.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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. #include "util.h"
  32. #include "platform_info_logic.h"
  33. #include "sgx_quote.h"
  34. #include "aesm_encode.h"
  35. #include "pve_logic.h"
  36. #include "aesm_logic.h"
  37. #include "PSEClass.h"
  38. #include "PSEPRClass.h"
  39. #include "PSDAService.h"
  40. #include "upse/helper.h"
  41. #include "interface_psda.h"
  42. #include "aesm_pse_status.h"
  43. #include <assert.h>
  44. #include "sgx_profile.h"
  45. #include "aesm_long_lived_thread.h"
  46. ae_error_t PlatformInfoLogic::check_ltp_thread_func(bool& is_new_pairing)
  47. {
  48. AESM_DBG_TRACE("enter fun");
  49. ae_error_t psStatus = AE_SUCCESS;
  50. //platform_info_blob_wrapper_t platform_info_blob;
  51. is_new_pairing = false;
  52. //
  53. // if long-term pairing fails, we may run cert provisioning,
  54. // but long-term pairing may not fail when current pse is
  55. // newer than pse that was current last time provisioning ran
  56. // so check that here
  57. //
  58. // Put the PS init log in this method so it doesn't get logged multiple times in the invoking function
  59. // in the BUSY thread case
  60. AESM_LOG_INFO_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_START]);
  61. ae_error_t npcStatus = need_pse_cert_provisioning();
  62. switch (npcStatus)
  63. {
  64. default:
  65. {
  66. assert(false); break;
  67. }
  68. case AESM_NPC_DONT_NEED_PSEP:
  69. {
  70. break;
  71. }
  72. case AESM_NPC_NO_PSE_CERT:
  73. {
  74. ae_error_t pcphStatus = pse_cert_provisioning_helper(NULL);
  75. switch (pcphStatus)
  76. {
  77. case AE_SUCCESS:
  78. {
  79. AESM_DBG_INFO("pcphStatus AE_SUCCESS");
  80. break;
  81. }
  82. case OAL_NETWORK_UNAVAILABLE_ERROR:
  83. case OAL_PROXY_SETTING_ASSIST:
  84. case PSW_UPDATE_REQUIRED:
  85. case AESM_AE_OUT_OF_EPC:
  86. case AESM_PCP_NEED_PSE_UPDATE:
  87. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE:
  88. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE:
  89. case AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR:
  90. case AESM_PCP_SIMPLE_EPID_PROVISION_ERROR:
  91. case OAL_THREAD_TIMEOUT_ERROR:
  92. {
  93. #ifdef DBG_LOG
  94. ae_error_t& p = pcphStatus;
  95. AESM_DBG_ERROR("pcphStatus %s",
  96. p==AESM_PCP_NEED_PSE_UPDATE ? "AESM_PCP_NEED_PSE_UPDATE" :
  97. p==AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE ? "AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE" :
  98. p==AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE ? "AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE" :
  99. p==AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR ? "AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR" :
  100. p==AESM_PCP_SIMPLE_EPID_PROVISION_ERROR ? "AESM_PCP_SIMPLE_EPID_PROVISION_ERROR" : "OAL_THREAD_TIMEOUT_ERROR");
  101. #endif
  102. return pcphStatus;
  103. }
  104. default:
  105. {
  106. assert(false); break;
  107. }
  108. }
  109. break;
  110. }
  111. }
  112. ae_error_t nltpStatus = need_long_term_pairing(NULL);
  113. switch (nltpStatus)
  114. {
  115. case AE_SUCCESS:
  116. case AESM_NPC_NO_PSE_CERT:
  117. case AE_FAILURE:
  118. {
  119. break;
  120. }
  121. case AESM_NLTP_NO_LTP_BLOB:
  122. case AESM_NLTP_DONT_NEED_UPDATE_PAIR_LTP:
  123. case AESM_NLTP_MAY_NEED_UPDATE_LTP:
  124. //case AESM_NLTP_OLD_EPID11_RLS: // not possible since no info blob
  125. {
  126. ae_error_t ltpStatus = CPSEPRClass::instance().long_term_pairing(&is_new_pairing);
  127. //
  128. // what do we do if new pairing?
  129. //
  130. SGX_DBGPRINT_ONE_STRING_TWO_INTS_CREATE_SESSION(__FUNCTION__" ltpStatus = ", ltpStatus, __LINE__);
  131. switch(ltpStatus)
  132. {
  133. case AE_SUCCESS:
  134. {
  135. break;
  136. }
  137. case OAL_PROXY_SETTING_ASSIST:
  138. {
  139. return OAL_PROXY_SETTING_ASSIST;
  140. }
  141. case AESM_AE_OUT_OF_EPC:
  142. {
  143. return AESM_AE_OUT_OF_EPC;
  144. }
  145. case AESM_NPC_NO_PSE_CERT:
  146. case AESM_LTP_PSE_CERT_REVOKED:
  147. case PSE_PAIRING_BLOB_UNSEALING_ERROR:
  148. case PSE_PAIRING_BLOB_INVALID_ERROR:
  149. case AESM_PSDA_LT_SESSION_INTEGRITY_ERROR:
  150. {
  151. ae_error_t pcphStatus = pse_cert_provisioning_helper(NULL);
  152. switch(pcphStatus)
  153. {
  154. case OAL_NETWORK_UNAVAILABLE_ERROR:
  155. case OAL_PROXY_SETTING_ASSIST:
  156. case PSW_UPDATE_REQUIRED:
  157. case AESM_AE_OUT_OF_EPC:
  158. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE:
  159. case AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR:
  160. case AESM_PCP_SIMPLE_EPID_PROVISION_ERROR:
  161. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE:
  162. case AESM_PCP_NEED_PSE_UPDATE:
  163. {
  164. AESM_DBG_ERROR("pcphStatus: (ae%d)", pcphStatus);
  165. psStatus = pcphStatus;
  166. break;
  167. }
  168. case AE_SUCCESS:
  169. {
  170. //
  171. // retry one time
  172. //
  173. ltpStatus = CPSEPRClass::instance().long_term_pairing(&is_new_pairing);
  174. SGX_DBGPRINT_ONE_STRING_TWO_INTS_CREATE_SESSION(__FUNCTION__" ltpStatus = ", ltpStatus, __LINE__);
  175. switch (ltpStatus)
  176. {
  177. case AE_SUCCESS:
  178. {
  179. break;
  180. }
  181. case OAL_PROXY_SETTING_ASSIST:
  182. case AESM_AE_OUT_OF_EPC:
  183. case OAL_THREAD_TIMEOUT_ERROR:
  184. {
  185. AESM_DBG_ERROR("long_term_pairing Return: (ae0x%X)", ltpStatus);
  186. psStatus = ltpStatus;
  187. break;
  188. }
  189. case AESM_NPC_NO_PSE_CERT:
  190. case AESM_LTP_PSE_CERT_REVOKED:
  191. {
  192. AESM_DBG_ERROR("long_term_pairing Return: (ae0x%X)", ltpStatus);
  193. AESM_LOG_ERROR("%s",g_event_string_table[SGX_EVENT_LTP_FAILURE]);
  194. psStatus = AESM_LTP_SIMPLE_LTP_ERROR;
  195. break;
  196. }
  197. default:
  198. {
  199. psStatus = AESM_LTP_SIMPLE_LTP_ERROR;
  200. break;
  201. }
  202. }
  203. break;
  204. }
  205. default:
  206. {
  207. assert(false); break;
  208. }
  209. }
  210. break;
  211. }
  212. default:
  213. {
  214. psStatus = AESM_LTP_SIMPLE_LTP_ERROR;
  215. break;
  216. }
  217. }
  218. break;
  219. }
  220. default:
  221. {
  222. assert(false); break;
  223. }
  224. }
  225. return psStatus;
  226. }
  227. //AESM_NPC_DONT_NEED_PSEP: don't pse provisioning or long term pairing
  228. //AE_SUCCESS: pse provisioning and long term pairing success
  229. //other error code: failure
  230. static ae_error_t check_ltp(bool* is_new_pairing)
  231. {
  232. AESM_DBG_TRACE("enter fun");
  233. ae_error_t ae_ret = PlatformInfoLogic::need_pse_cert_provisioning();
  234. if(AESM_NPC_DONT_NEED_PSEP == ae_ret &&
  235. AE_SUCCESS == PlatformInfoLogic::need_long_term_pairing(NULL))
  236. {
  237. AESM_DBG_TRACE("dont need psep");
  238. *is_new_pairing = false;
  239. return AESM_NPC_DONT_NEED_PSEP;
  240. }
  241. return start_check_ltp_thread(*is_new_pairing);
  242. }
  243. //
  244. // call at beginning of create_session()
  245. //
  246. ae_error_t PlatformInfoLogic::create_session_pre_internal(void)
  247. {
  248. AESM_DBG_TRACE("enter fun");
  249. bool is_new_pairing = false;
  250. ae_error_t psStatus = check_ltp(&is_new_pairing);
  251. if (psStatus == AE_SUCCESS)
  252. {
  253. // long term pairing will load pse-pr enclave , which will unload pse-op enclave and
  254. // break ephemeral session
  255. ae_error_t ret = CPSEClass::instance().create_ephemeral_session_pse_cse(is_new_pairing, true);
  256. if (ret != AE_SUCCESS)
  257. {
  258. AESM_DBG_ERROR("Long term pairing succeeded but ephemeral session failed(ae%d)",ret);
  259. if(ret == AESM_AE_OUT_OF_EPC)
  260. {
  261. // Return AESM_AE_OUT_OF_EPC
  262. psStatus = AESM_AE_OUT_OF_EPC;
  263. }
  264. // ignore other return value
  265. }
  266. }
  267. else if (AESM_NPC_DONT_NEED_PSEP == psStatus)
  268. {
  269. psStatus = AE_SUCCESS;
  270. }
  271. else {
  272. PlatformServiceStatus::instance().set_platform_service_status(PLATFORM_SERVICE_NOT_READY);
  273. }
  274. // Log result to the Admin log
  275. switch (psStatus)
  276. {
  277. case AE_SUCCESS:
  278. case OAL_THREAD_TIMEOUT_ERROR:
  279. // no logging needed
  280. break;
  281. case OAL_PROXY_SETTING_ASSIST:
  282. // don't log an error here
  283. break;
  284. case PSW_UPDATE_REQUIRED:
  285. AESM_LOG_ERROR_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_FAIL_PSWVER]);
  286. break;
  287. case AESM_AE_OUT_OF_EPC:
  288. AESM_LOG_ERROR_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_FAIL]);
  289. break;
  290. case AESM_PCP_NEED_PSE_UPDATE:
  291. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE:
  292. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE:
  293. case AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR:
  294. case AESM_PCP_SIMPLE_EPID_PROVISION_ERROR:
  295. default:
  296. AESM_LOG_ERROR_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_FAIL_LTP]);
  297. break;
  298. }
  299. return psStatus;
  300. }
  301. ae_error_t PlatformInfoLogic::update_pse_thread_func(const platform_info_blob_wrapper_t* p_platform_info, uint32_t attestation_status)
  302. {
  303. AESM_DBG_TRACE("enter fun");
  304. ae_error_t ltpStatus = AE_SUCCESS;
  305. ae_error_t retVal = AESM_LTP_SIMPLE_LTP_ERROR;
  306. bool is_new_pairing = false;
  307. // Put the PS init log in this method so it doesn't get logged multiple times in the invoking function
  308. // in the BUSY thread case
  309. // Note: Are there cases where we call into here but don't actually reinit PS!? If so, need to conditionally log here
  310. // What about AESM_NLTP_DONT_NEED_UPDATE_PAIR_LTP?
  311. AESM_LOG_INFO_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_START]);
  312. ae_error_t pcphStatus = AE_SUCCESS;
  313. if (Helper::noLtpBlob() || Helper::noPseCert())
  314. {
  315. pcphStatus = pse_cert_provisioning_helper(p_platform_info);
  316. AESM_DBG_TRACE("pse_cert_provisioning_helper Return: (ae%d)", pcphStatus);
  317. if (AE_SUCCESS == pcphStatus)
  318. {
  319. pcphStatus = CPSEPRClass::instance().long_term_pairing(&is_new_pairing);
  320. AESM_DBG_TRACE("long_term_pairing Return: (ae%d)", pcphStatus);
  321. if(OAL_PROXY_SETTING_ASSIST == pcphStatus){
  322. return OAL_PROXY_SETTING_ASSIST;
  323. }
  324. else if (AESM_AE_OUT_OF_EPC == pcphStatus)
  325. return AESM_AE_OUT_OF_EPC;
  326. }
  327. else if (AESM_AE_OUT_OF_EPC == pcphStatus)
  328. return AESM_AE_OUT_OF_EPC;
  329. }
  330. ae_error_t nltpStatus = need_long_term_pairing(p_platform_info);
  331. AESM_DBG_TRACE("need_long_term_pairing result (ae%d)", nltpStatus);
  332. switch (nltpStatus)
  333. {
  334. case AE_SUCCESS:
  335. case AESM_NLTP_MAY_NEED_UPDATE_LTP: // get this case in create_session
  336. {
  337. retVal = AE_SUCCESS;
  338. break;
  339. }
  340. case AESM_NLTP_NO_LTP_BLOB: // maybe we should only handle this case in create_session to be consistent with epid
  341. case AESM_NLTP_DONT_NEED_UPDATE_PAIR_LTP:
  342. case AESM_NLTP_OLD_EPID11_RLS:
  343. {
  344. //
  345. // long-term pairing won't catch all cases where cert is out of date
  346. // so could check here, but we opt to only do this in create_session
  347. // only do this if app tells us its attestation failed (attestation_status != 0)
  348. //
  349. if (attestation_status || ((AESM_NLTP_NO_LTP_BLOB == nltpStatus) || (AESM_NLTP_DONT_NEED_UPDATE_PAIR_LTP == nltpStatus)))
  350. {
  351. ltpStatus = CPSEPRClass::instance().long_term_pairing(&is_new_pairing);
  352. switch(ltpStatus)
  353. {
  354. case AE_SUCCESS:
  355. {
  356. retVal = AE_SUCCESS;
  357. break;
  358. }
  359. case OAL_PROXY_SETTING_ASSIST:
  360. case PSW_UPDATE_REQUIRED:
  361. case AESM_AE_OUT_OF_EPC:
  362. {
  363. AESM_DBG_TRACE("long_term_pairing Return: (ae%d)", ltpStatus);
  364. retVal = ltpStatus;
  365. break;
  366. }
  367. case AESM_NPC_NO_PSE_CERT:
  368. case AESM_LTP_PSE_CERT_REVOKED:
  369. case PSE_PAIRING_BLOB_UNSEALING_ERROR:
  370. case PSE_PAIRING_BLOB_INVALID_ERROR:
  371. case AESM_PSDA_LT_SESSION_INTEGRITY_ERROR:
  372. {
  373. AESM_DBG_TRACE("long_term_pairing Return: (ae%d)", ltpStatus);
  374. pcphStatus = pse_cert_provisioning_helper(p_platform_info);
  375. switch(pcphStatus)
  376. {
  377. case OAL_NETWORK_UNAVAILABLE_ERROR:
  378. case OAL_PROXY_SETTING_ASSIST:
  379. case PSW_UPDATE_REQUIRED:
  380. case AESM_AE_OUT_OF_EPC:
  381. {
  382. AESM_DBG_TRACE("pse_cert_provisioning_helper Return: (ae%d)", pcphStatus);
  383. return pcphStatus;
  384. }
  385. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE:
  386. case AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR:
  387. case AESM_PCP_SIMPLE_EPID_PROVISION_ERROR:
  388. case AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE:
  389. case AESM_PCP_NEED_PSE_UPDATE:
  390. {
  391. AESM_DBG_TRACE("pse_cert_provisioning_helper Return: (ae%d)", pcphStatus);
  392. break;
  393. }
  394. case AE_SUCCESS:
  395. {
  396. //
  397. // retry one time
  398. //
  399. ltpStatus = CPSEPRClass::instance().long_term_pairing(&is_new_pairing);
  400. switch (ltpStatus)
  401. {
  402. case AE_SUCCESS:
  403. {
  404. retVal = AE_SUCCESS;
  405. break;
  406. }
  407. case OAL_PROXY_SETTING_ASSIST:
  408. return OAL_PROXY_SETTING_ASSIST;
  409. case AESM_AE_OUT_OF_EPC:
  410. return AESM_AE_OUT_OF_EPC;
  411. case AESM_NPC_NO_PSE_CERT:
  412. case AESM_LTP_PSE_CERT_REVOKED:
  413. {
  414. AESM_DBG_ERROR("long_term_pairing Return: (ae%d)", ltpStatus);
  415. AESM_LOG_ERROR("%s",g_event_string_table[SGX_EVENT_LTP_FAILURE]);
  416. break;
  417. }
  418. default:
  419. {
  420. break;
  421. }
  422. }
  423. break;
  424. }
  425. default:
  426. {
  427. break;
  428. }
  429. }
  430. break;
  431. }
  432. default:
  433. {
  434. break;
  435. }
  436. }
  437. }
  438. break;
  439. }
  440. default:
  441. {
  442. break;
  443. }
  444. }
  445. return retVal;
  446. }
  447. aesm_error_t PlatformInfoLogic::report_attestation_status(
  448. uint8_t* platform_info, uint32_t platform_info_size,
  449. uint32_t attestation_status,
  450. uint8_t* update_info, uint32_t update_info_size)
  451. {
  452. AESM_DBG_TRACE("enter fun");
  453. //
  454. // we don't do anything without platform info
  455. //
  456. if (NULL == platform_info) {
  457. return AESM_PARAMETER_ERROR;
  458. }
  459. platform_info_blob_wrapper_t pibw;
  460. //
  461. // presence of platform info is conditional, on whether we're up to date
  462. // if we're up to date, no platform info and no need for update info
  463. //
  464. if (((sizeof(pibw.platform_info_blob) > platform_info_size)) || ((NULL != update_info) && (sizeof(sgx_update_info_bit_t) > update_info_size))) {
  465. return AESM_PARAMETER_ERROR;
  466. }
  467. pibw.valid_info_blob = false;
  468. memcpy_s(&pibw.platform_info_blob, sizeof(pibw.platform_info_blob), platform_info, platform_info_size);
  469. aesm_error_t status = AESM_SUCCESS; // status only tells app to look at updateInfo
  470. //
  471. // we want to know what ias based its decision on; ie, some ltp blob
  472. // so it's important that we take a snapshot of the ltp blob before
  473. // we potentially trigger ltp and it's better, in general, to
  474. // read it asap since other threads could be triggering ltp (our
  475. // service locks help with this, but there's no harm in reading it
  476. // early especially since it's conditional).
  477. //
  478. pairing_blob_t pairing_blob;
  479. ae_error_t readLtpBlobStatus = AE_FAILURE;
  480. //
  481. // only need to read ltp blob (know what was reported to ias) if attestation
  482. // being reported on failed and we have an update info structure to fill in
  483. //
  484. if ((0 != attestation_status) && (NULL != update_info)) {
  485. readLtpBlobStatus = Helper::read_ltp_blob(pairing_blob);
  486. if (AE_FAILED(readLtpBlobStatus))
  487. {
  488. AESM_DBG_ERROR("read_ltp_blob Return: (ae%d)", readLtpBlobStatus);
  489. }
  490. }
  491. //
  492. // contents of input platform info can get stale, but not by virtue of anything we do
  493. // (the latest/current versions can change)
  494. // therefore, we'll use the same platform info the whole time
  495. //
  496. bool pibSigGood = (AE_SUCCESS == pib_verify_signature(pibw));
  497. //
  498. // invalid pib is an error whenever it's provided
  499. //
  500. if (!pibSigGood) {
  501. AESM_DBG_ERROR("pib verify signature failed");
  502. return AESM_PLATFORM_INFO_BLOB_INVALID_SIG;
  503. }
  504. if(pibw.platform_info_blob.xeid != AESMLogic::get_active_extended_epid_group_id()){
  505. return AESM_UNEXPECTED_ERROR;
  506. }
  507. uint32_t gid_mt_result = AESMLogic::is_gid_matching_result_in_epid_blob( pibw.platform_info_blob.gid);
  508. if(AESMLogic::GIDMT_UNMATCHED == gid_mt_result||
  509. AESMLogic::GIDMT_UNEXPECTED_ERROR == gid_mt_result){
  510. return AESM_UNEXPECTED_ERROR;
  511. }
  512. else if (AESMLogic::GIDMT_NOT_AVAILABLE == gid_mt_result) {
  513. return AESM_EPIDBLOB_ERROR;
  514. }
  515. ae_error_t nepStatus = need_epid_provisioning(&pibw);
  516. AESM_DBG_TRACE("need_epid_provisioning return (ae%d)",nepStatus);
  517. switch (nepStatus)
  518. {
  519. case AESM_NEP_DONT_NEED_EPID_PROVISIONING:
  520. {
  521. break;
  522. }
  523. case AESM_NEP_DONT_NEED_UPDATE_PVEQE: // sure thing
  524. {
  525. AESMLogicLock lock(AESMLogic::_qe_pve_mutex);
  526. if(!query_pve_thread_status()){//If another thread is busy on Epid Provisioning
  527. status = AESM_SUCCESS;
  528. break;
  529. }
  530. bool perfRekey = false;
  531. status = PvEAESMLogic::provision(perfRekey, THREAD_TIMEOUT);
  532. if (AESM_BUSY == status || //thread timeout
  533. AESM_PROXY_SETTING_ASSIST == status || //uae service need to set up proxy info and retry
  534. AESM_UPDATE_AVAILABLE == status || //PSW need be updated
  535. AESM_UNRECOGNIZED_PLATFORM == status || //Platform not recognized by Provisioning backend
  536. AESM_OUT_OF_EPC == status) // out of EPC
  537. {
  538. return status;//We should return to uae serivce directly
  539. }
  540. if (AESM_SUCCESS != status &&
  541. AESM_OUT_OF_MEMORY_ERROR != status &&
  542. AESM_BACKEND_SERVER_BUSY != status &&
  543. AESM_NETWORK_ERROR != status &&
  544. AESM_NETWORK_BUSY_ERROR != status)
  545. {
  546. status = AESM_SGX_PROVISION_FAILED;
  547. }
  548. break;
  549. }
  550. case AESM_NEP_PERFORMANCE_REKEY:
  551. {
  552. if (0 == attestation_status) // pr only if we succeeded (also we'll never get pr unless gid up-to-date)
  553. {
  554. bool perfRekey = true;
  555. AESMLogicLock lock(AESMLogic::_qe_pve_mutex);
  556. if(!query_pve_thread_status()){//If another thread is busy on Epid Provisioning
  557. status = AESM_SUCCESS;
  558. break;
  559. }
  560. status = PvEAESMLogic::provision(perfRekey, THREAD_TIMEOUT);
  561. if (AESM_BUSY == status ||//thread timeout
  562. AESM_PROXY_SETTING_ASSIST == status ||//uae service need to set up proxy info and retry
  563. AESM_UPDATE_AVAILABLE == status ||
  564. AESM_UNRECOGNIZED_PLATFORM == status ||
  565. AESM_OUT_OF_EPC == status)
  566. {
  567. return status;//We should return to uae serivce directly
  568. }
  569. if (AESM_SUCCESS != status &&
  570. AESM_OUT_OF_MEMORY_ERROR != status &&
  571. AESM_BACKEND_SERVER_BUSY != status &&
  572. AESM_NETWORK_ERROR != status &&
  573. AESM_NETWORK_BUSY_ERROR != status)
  574. {
  575. status = AESM_SGX_PROVISION_FAILED;
  576. }
  577. }
  578. break;
  579. }
  580. default:
  581. {
  582. status = AESM_UNEXPECTED_ERROR;
  583. break;
  584. }
  585. }
  586. // don't worry about pairing unless indication that PS being used
  587. if (ps_collectively_not_uptodate(&pibw) && pibw.platform_info_blob.xeid == AESMLogic::get_active_extended_epid_group_id())
  588. {
  589. ae_error_t ae_ret = start_update_pse_thread(&pibw, attestation_status);
  590. switch (ae_ret)
  591. {
  592. case AE_SUCCESS:
  593. break;
  594. case OAL_THREAD_TIMEOUT_ERROR:
  595. return AESM_BUSY;
  596. case PVE_PROV_ATTEST_KEY_NOT_FOUND:
  597. return AESM_UNRECOGNIZED_PLATFORM;
  598. case OAL_PROXY_SETTING_ASSIST:
  599. // don't log an error here
  600. return AESM_PROXY_SETTING_ASSIST;
  601. case PSW_UPDATE_REQUIRED:
  602. AESM_LOG_ERROR_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_FAIL_PSWVER]);
  603. return AESM_UPDATE_AVAILABLE;
  604. case AESM_AE_OUT_OF_EPC:
  605. AESM_LOG_ERROR_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_FAIL_LTP]);
  606. return AESM_OUT_OF_EPC;
  607. case AESM_LTP_SIMPLE_LTP_ERROR:
  608. default:
  609. AESM_LOG_ERROR_ADMIN("%s", g_admin_event_string_table[SGX_ADMIN_EVENT_PS_INIT_FAIL_LTP]);
  610. break;
  611. }
  612. }
  613. //
  614. // don't nag happy app about updates
  615. //
  616. if ((0 != attestation_status) && (NULL != update_info))
  617. {
  618. sgx_update_info_bit_t* p_update_info = (sgx_update_info_bit_t*)update_info;
  619. memset(p_update_info, 0, sizeof(*p_update_info));
  620. //
  621. // here, we treat values that get reported live - cpusvn, qe.isvsvn,
  622. // in normal flow, live values reported to attestation server will be the same as current values now so
  623. // we just look at out-of-date bits corresponding to these values.
  624. // the alternative would be to compare current with latest as reported by IAS. this
  625. // isn't an option for cpusvn since what we get from IAS is equivalent cpusvn.
  626. //
  627. if (cpu_svn_out_of_date(&pibw))
  628. {
  629. p_update_info->ucodeUpdate = 1;
  630. status = AESM_UPDATE_AVAILABLE;
  631. }
  632. if (qe_svn_out_of_date(&pibw) ||
  633. pce_svn_out_of_date(&pibw)
  634. ||pse_svn_out_of_date(&pibw))
  635. {
  636. p_update_info->pswUpdate = 1;
  637. status = AESM_UPDATE_AVAILABLE;
  638. }
  639. else if (psda_svn_out_of_date(&pibw)) {
  640. //
  641. // the psda svn value in quote is from ltp blob -> possibly stale
  642. // better to determine if update is required by comparing current
  643. // psda svn to latest as reported by ias in platform info
  644. //
  645. // if current is equal to latest, it means code above will have triggered ltp
  646. //
  647. if (latest_psda_svn(&pibw) != PSDAService::instance().psda_svn) {
  648. p_update_info->pswUpdate = 1;
  649. status = AESM_UPDATE_AVAILABLE;
  650. }
  651. }
  652. if (cse_gid_out_of_date(&pibw)) {
  653. pse_pr_interface_psda* pPSDA = NULL;
  654. pPSDA = new(std::nothrow) pse_pr_interface_psda();
  655. if(pPSDA == NULL){
  656. return AESM_OUT_OF_MEMORY_ERROR;
  657. }
  658. EPID_GID meGid;
  659. //
  660. // compare current CSME GID to one reported to IAS, in LTP blob
  661. // if same, need update
  662. // if different, assume subsequent attestation will succeed (basically
  663. // assume CSME GID is now up-to-date)
  664. //
  665. if ((AE_SUCCESS == pPSDA->get_csme_gid(&meGid)) && (AE_SUCCESS == readLtpBlobStatus)) {
  666. if (Helper::ltpBlobCseGid(pairing_blob) == meGid) {
  667. p_update_info->csmeFwUpdate = 1;
  668. status = AESM_UPDATE_AVAILABLE;
  669. }
  670. }
  671. else {
  672. p_update_info->csmeFwUpdate = 1;
  673. status = AESM_UPDATE_AVAILABLE;
  674. }
  675. delete pPSDA;
  676. pPSDA = NULL;
  677. }
  678. //
  679. // IAS will provide latest PSDA SVN value => avoid ambiguity like one above
  680. // we may not be able to get current PSDA SVN (and we can know that we didn't get it),
  681. // for several reasons (no applet file present, no heci, no jhi)
  682. // i don't really want to further complicate this code, but
  683. // if we can't get the value in the case here, we should return that
  684. // "Intel Platform SW" may need to be re-installed
  685. //
  686. //
  687. // what if MEI/HECI, JHI, iCLS isn't present/installed?
  688. // none of these are in our TCB, but they are necessary to
  689. // get properties of our TCB, when PS being used =>
  690. // at least need to document this dependency
  691. //
  692. }
  693. return status;
  694. }
  695. ae_error_t PlatformInfoLogic::attestation_failure_in_pse_cert_provisioning(const platform_info_blob_wrapper_t* p_platform_info_blob)
  696. {
  697. ae_error_t status = AE_SUCCESS;
  698. AESM_DBG_TRACE("enter fun");
  699. if ((NULL != p_platform_info_blob) && (p_platform_info_blob->valid_info_blob)) {
  700. status = AESM_PCP_NEED_PSE_UPDATE;
  701. ae_error_t nepStatus = need_epid_provisioning(p_platform_info_blob);
  702. AESM_DBG_TRACE("need_epid_provisioning return %d",nepStatus);
  703. switch (nepStatus)
  704. {
  705. default:
  706. {
  707. assert(false); break;
  708. }
  709. case AESM_NEP_DONT_NEED_EPID_PROVISIONING:
  710. {
  711. status = AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_NEED_EPID_UPDATE;
  712. break;
  713. }
  714. case AESM_NEP_DONT_NEED_UPDATE_PVEQE:
  715. case AESM_NEP_PERFORMANCE_REKEY:
  716. {
  717. aesm_error_t pvStatus = PvEAESMLogic::provision(nepStatus == AESM_NEP_PERFORMANCE_REKEY, AESM_THREAD_INFINITE);
  718. SGX_DBGPRINT_ONE_STRING_TWO_INTS_CREATE_SESSION("pvStatus = ", pvStatus, pvStatus);
  719. switch (pvStatus)
  720. {
  721. case AESM_BUSY:
  722. {
  723. status = OAL_THREAD_TIMEOUT_ERROR;
  724. break;
  725. }
  726. case AESM_UNRECOGNIZED_PLATFORM:
  727. {
  728. status = PVE_PROV_ATTEST_KEY_NOT_FOUND;
  729. break;
  730. }
  731. case AESM_UPDATE_AVAILABLE:
  732. {
  733. status = PSW_UPDATE_REQUIRED;
  734. break;
  735. }
  736. case AESM_OUT_OF_EPC:
  737. {
  738. status = AESM_AE_OUT_OF_EPC;
  739. break;
  740. }
  741. case AESM_SUCCESS:
  742. {
  743. //gLastEpidProvisioningTuple.blob = epidBlobEquivPsvn();
  744. //gLastEpidProvisioningTuple.current = currentPsvn();
  745. //
  746. // retry one time
  747. //
  748. AESM_DBG_INFO("attestation; redo certificate provisioning");
  749. platform_info_blob_wrapper_t new_platform_info_blob;
  750. new_platform_info_blob.valid_info_blob = false;
  751. ae_error_t cpStatus = CPSEPRClass::instance().certificate_provisioning(&new_platform_info_blob);
  752. SGX_DBGPRINT_ONE_STRING_TWO_INTS_CREATE_SESSION("cpStatus = ", cpStatus, cpStatus);
  753. switch (cpStatus)
  754. {
  755. case AE_SUCCESS:
  756. {
  757. status = AE_SUCCESS; break;
  758. }
  759. case AESM_CP_ATTESTATION_FAILURE:
  760. {
  761. status = AESM_PCP_PSE_CERT_PROVISIONING_ATTESTATION_FAILURE_MIGHT_NEED_EPID_UPDATE; break;
  762. }
  763. case PSW_UPDATE_REQUIRED:
  764. {
  765. status = PSW_UPDATE_REQUIRED; break;
  766. }
  767. case AESM_AE_OUT_OF_EPC:
  768. {
  769. status = AESM_AE_OUT_OF_EPC; break;
  770. }
  771. default:
  772. {
  773. status = AESM_PCP_SIMPLE_PSE_CERT_PROVISIONING_ERROR;
  774. break;
  775. }
  776. }
  777. break;
  778. }
  779. default:
  780. {
  781. status = AESM_PCP_SIMPLE_EPID_PROVISION_ERROR;
  782. break;
  783. }
  784. }
  785. break;
  786. }
  787. }
  788. }
  789. SGX_DBGPRINT_ONE_STRING_TWO_INTS_CREATE_SESSION(__FUNCTION__" returning ", status, status);
  790. return status;
  791. }