aesm_logic.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #ifndef _AESM_LOGIC_H_
  32. #define _AESM_LOGIC_H_
  33. #include "sgx_urts.h"
  34. #include "aesm_error.h"
  35. #include "arch.h"
  36. #include "aeerror.h"
  37. #include "tlv_common.h"
  38. #include "se_thread.h"
  39. #include "internal/se_stdio.h"
  40. #include "internal/se_memcpy.h"
  41. #include "internal/uncopyable.h"
  42. #include "oal/oal.h"
  43. #include <time.h>
  44. #include <string.h>
  45. #include "se_wrapper.h"
  46. #include "upse/platform_info_blob.h"
  47. #include "default_url_info.hh"
  48. /*File to declare AESMLogic Class and facility class(Mutex/Lock) for it*/
  49. const uint32_t THREAD_TIMEOUT = 5000;
  50. class AESMLogicMutex{
  51. CLASS_UNCOPYABLE(AESMLogicMutex)
  52. public:
  53. AESMLogicMutex() {se_mutex_init(&mutex);}
  54. ~AESMLogicMutex() { se_mutex_destroy(&mutex);}
  55. void lock() { se_mutex_lock(&mutex); }
  56. void unlock() { se_mutex_unlock(&mutex); }
  57. private:
  58. se_mutex_t mutex;
  59. };
  60. class AESMLogicLock {
  61. CLASS_UNCOPYABLE(AESMLogicLock)
  62. public:
  63. explicit AESMLogicLock(AESMLogicMutex& cs) :_cs(cs) { _cs.lock(); }
  64. ~AESMLogicLock() { _cs.unlock(); }
  65. private:
  66. AESMLogicMutex& _cs;
  67. };
  68. #define QE_PROD_ID 1
  69. #define PSE_PROD_ID 2
  70. typedef struct _endpoint_selection_infos_t endpoint_selection_infos_t;
  71. class AESMLogic{
  72. public:
  73. static AESMLogicMutex _qe_pve_mutex, _pse_mutex, _le_mutex; /*mutex to lock external interface*/
  74. private:
  75. static aesm_thread_t qe_thread, pse_thread;
  76. static psvn_t _qe_psvn, _pse_psvn, _pce_psvn; /*different cpu svn used although they're same. We should only access _qe_psvn/_pce_svn when qe_pve_mutex is acquired and only access _pse_psvn when pse_mutext is acquired*/
  77. static bool _is_qe_psvn_set, _is_pse_psvn_set, _is_pce_psvn_set;
  78. static uint32_t active_extended_epid_group_id;
  79. static ae_error_t set_psvn(uint16_t prod_id, uint16_t isv_svn, sgx_cpu_svn_t cpu_svn, uint32_t mrsigner_index);
  80. static ae_error_t save_unverified_white_list(const uint8_t *white_list_cert, uint32_t white_list_cert_size);
  81. static ae_error_t get_white_list_size_without_lock(uint32_t *white_list_cert_size);
  82. public:
  83. static ae_error_t get_qe_isv_svn(uint16_t& isv_svn); /*This function should only be called when _qe_pve_mutex is acquired*/
  84. static ae_error_t get_qe_cpu_svn(sgx_cpu_svn_t& cpu_svn);/*This function should only be called when _qe_pve_mutex is acquired*/
  85. static ae_error_t get_pse_isv_svn(uint16_t& isv_svn); /*This function should only be called when _pse_mutex is acquired*/
  86. static ae_error_t get_pse_cpu_svn(sgx_cpu_svn_t& cpu_svn);/*This function should only be called when _pse_mutex is acquired*/
  87. static ae_error_t get_pce_isv_svn(uint16_t& isv_svn);
  88. static uint32_t get_active_extended_epid_group_id(void);
  89. static ae_error_t service_start();
  90. static void service_stop();
  91. static bool is_service_running();
  92. static sgx_status_t get_launch_token(const enclave_css_t* signature,
  93. const sgx_attributes_t* attribute,
  94. sgx_launch_token_t* launch_token);
  95. static aesm_error_t get_launch_token(
  96. const uint8_t *mrenclave, uint32_t mrenclave_size,
  97. const uint8_t *public_key, uint32_t public_key_size,
  98. const uint8_t *se_attributes, uint32_t se_attributes_size,
  99. uint8_t * lictoken, uint32_t lictoken_size);
  100. static aesm_error_t init_quote(uint8_t *target_info, uint32_t target_info_size,
  101. uint8_t *gid, uint32_t gid_size);
  102. static aesm_error_t get_quote(const uint8_t *report, uint32_t report_size,
  103. uint32_t quote_type,
  104. const uint8_t *spid, uint32_t spid_size,
  105. const uint8_t *nonce, uint32_t nonce_size,
  106. const uint8_t *sigrl, uint32_t sigrl_size,
  107. uint8_t *qe_report, uint32_t qe_report_size,
  108. uint8_t *quote, uint32_t buf_size);
  109. static aesm_error_t create_session(
  110. uint32_t* session_id,
  111. uint8_t* se_dh_msg1, uint32_t se_dh_msg1_size);
  112. static aesm_error_t exchange_report(
  113. uint32_t session_id,
  114. const uint8_t* se_dh_msg2, uint32_t se_dh_msg2_size,
  115. uint8_t* se_dh_msg3, uint32_t se_dh_msg3_size);
  116. static aesm_error_t close_session(
  117. uint32_t session_id);
  118. static aesm_error_t invoke_service(
  119. const uint8_t* pse_message_req, uint32_t pse_message_req_size,
  120. uint8_t* pse_message_resp, uint32_t pse_message_resp_size);
  121. static aesm_error_t get_ps_cap(
  122. uint64_t* ps_cap);
  123. static uint32_t endpoint_selection(endpoint_selection_infos_t& es_info);
  124. enum {GIDMT_UNMATCHED, GIDMT_NOT_AVAILABLE, GIDMT_MATCHED,GIDMT_UNEXPECTED_ERROR};
  125. static uint32_t is_gid_matching_result_in_epid_blob(const GroupId& gid);
  126. static aesm_error_t report_attestation_status(
  127. uint8_t* platform_info, uint32_t platform_info_size,
  128. uint32_t attestation_status,
  129. uint8_t* update_info, uint32_t update_info_size);
  130. static aesm_error_t white_list_register(
  131. const uint8_t *white_list_cert, uint32_t white_list_cert_size);
  132. static aesm_error_t get_white_list_size(
  133. uint32_t* white_list_cert_size);
  134. static aesm_error_t get_white_list(
  135. uint8_t *white_list_cert, uint32_t buf_size);
  136. static aesm_error_t get_extended_epid_group_id(
  137. uint32_t* extended_epid_group_id);
  138. static aesm_error_t switch_extended_epid_group(
  139. uint32_t extended_epid_group_id );
  140. };
  141. #endif