aesm_logic.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2011-2016 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 */
  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 psvn_t _qe_psvn, _pse_psvn; /*two different cpu svn used although they're same. We should only access qe_psvn when qe_pve_mutex is acquired and only access pse_psvn when pse_mutext is acquired*/
  76. static bool _is_qe_psvn_set, _is_pse_psvn_set;
  77. static ae_error_t set_psvn(uint16_t prod_id, uint16_t isv_svn, sgx_cpu_svn_t cpu_svn);
  78. static ae_error_t save_unverified_white_list(const uint8_t *white_list_cert, uint32_t white_list_cert_size);
  79. public:
  80. static ae_error_t get_qe_isv_svn(uint16_t& isv_svn);/*This function should only be called when _qe_pve_mutex is acquired*/
  81. 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*/
  82. static ae_error_t get_pse_isv_svn(uint16_t& isv_svn); /*This function should only be called when _pse_mutex is acquired*/
  83. 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*/
  84. static ae_error_t service_start();
  85. static void service_stop();
  86. static bool is_service_running();
  87. static sgx_status_t get_launch_token(const enclave_css_t* signature,
  88. const sgx_attributes_t* attribute,
  89. sgx_launch_token_t* launch_token);
  90. static aesm_error_t get_launch_token(
  91. const uint8_t *mrenclave, uint32_t mrenclave_size,
  92. const uint8_t *public_key, uint32_t public_key_size,
  93. const uint8_t *se_attributes, uint32_t se_attributes_size,
  94. uint8_t * lictoken, uint32_t lictoken_size);
  95. static aesm_error_t init_quote(uint8_t *target_info, uint32_t target_info_size,
  96. uint8_t *gid, uint32_t gid_size);
  97. static aesm_error_t get_quote(const uint8_t *report, uint32_t report_size,
  98. uint32_t quote_type,
  99. const uint8_t *spid, uint32_t spid_size,
  100. const uint8_t *nonce, uint32_t nonce_size,
  101. const uint8_t *sigrl, uint32_t sigrl_size,
  102. uint8_t *qe_report, uint32_t qe_report_size,
  103. uint8_t *quote, uint32_t buf_size);
  104. static aesm_error_t create_session(
  105. uint32_t* session_id,
  106. uint8_t* se_dh_msg1, uint32_t se_dh_msg1_size);
  107. static aesm_error_t exchange_report(
  108. uint32_t session_id,
  109. const uint8_t* se_dh_msg2, uint32_t se_dh_msg2_size,
  110. uint8_t* se_dh_msg3, uint32_t se_dh_msg3_size);
  111. static aesm_error_t close_session(
  112. uint32_t session_id);
  113. static aesm_error_t invoke_service(
  114. const uint8_t* pse_message_req, uint32_t pse_message_req_size,
  115. uint8_t* pse_message_resp, uint32_t pse_message_resp_size);
  116. static aesm_error_t get_ps_cap(
  117. uint64_t* ps_cap);
  118. static uint32_t endpoint_selection(endpoint_selection_infos_t& es_info);
  119. static aesm_error_t report_attestation_status(
  120. uint8_t* platform_info, uint32_t platform_info_size,
  121. uint32_t attestation_status,
  122. uint8_t* update_info, uint32_t update_info_size);
  123. static aesm_error_t white_list_register(
  124. const uint8_t *white_list_cert, uint32_t white_list_cert_size);
  125. };
  126. #endif