PVEClass.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #include <assert.h>
  32. #include "PVEClass.h"
  33. #include "QEClass.h"
  34. #include "util.h"
  35. #include "prof_fun.h"
  36. #include "sgx_report.h"
  37. #include "sgx_tseal.h"
  38. #include "epid_pve_type.h"
  39. #include "provision_enclave_u.h"
  40. #include "provision_enclave_u.c"
  41. void CPVEClass::before_enclave_load() {
  42. // always unload qe enclave before loading pve enclave
  43. CQEClass::instance().unload_enclave();
  44. }
  45. uint32_t CPVEClass::gen_prov_msg1_data(
  46. const psvn_t* psvn,
  47. const signed_pek_t *pek,
  48. bool performance_rekey_used,
  49. prov_msg1_output_t* output)
  50. {
  51. uint32_t ret = AE_SUCCESS;
  52. sgx_status_t status = SGX_SUCCESS;
  53. AESM_PROFILE_FUN;
  54. if(m_enclave_id==0){
  55. AESM_DBG_ERROR("call gen_prov_msg1_data without loading PvE");
  56. return AE_FAILURE;
  57. }
  58. status = gen_prov_msg1_data_wrapper(
  59. m_enclave_id, &ret,
  60. psvn,
  61. pek,
  62. performance_rekey_used?1:0,
  63. output);
  64. if(status == SGX_ERROR_ENCLAVE_LOST)
  65. ret = AE_ENCLAVE_LOST;
  66. else if(status != SGX_SUCCESS)
  67. ret = AE_FAILURE;
  68. return ret;
  69. }
  70. uint32_t CPVEClass::get_ek2(
  71. const prov_get_ek2_input_t* input,
  72. prov_get_ek2_output_t* ek2)
  73. {
  74. uint32_t ret = AE_SUCCESS;
  75. sgx_status_t status = SGX_SUCCESS;
  76. AESM_PROFILE_FUN;
  77. if(m_enclave_id==0){
  78. AESM_DBG_ERROR("call get_ek2 without loading PvE");
  79. return AE_FAILURE;
  80. }
  81. status = get_ek2_wrapper(
  82. m_enclave_id, &ret,
  83. input,
  84. ek2);
  85. if(status == SGX_ERROR_ENCLAVE_LOST)
  86. ret = AE_ENCLAVE_LOST;
  87. else if(status != SGX_SUCCESS)
  88. ret = AE_FAILURE;
  89. return ret;
  90. }
  91. uint32_t CPVEClass::proc_prov_msg2_data(
  92. const proc_prov_msg2_blob_input_t* input,
  93. const uint8_t* sigrl,
  94. uint32_t sigrl_size,
  95. gen_prov_msg3_output_t* msg3_fixed_output,
  96. uint8_t* epid_sig,
  97. uint32_t epid_sig_buffer_size)
  98. {
  99. uint32_t ret = AE_SUCCESS;
  100. sgx_status_t status = SGX_SUCCESS;
  101. AESM_PROFILE_FUN;
  102. if(m_enclave_id==0){
  103. AESM_DBG_ERROR("call proc_prov_msg2_data without loading PvE");
  104. return AE_FAILURE;
  105. }
  106. status = proc_prov_msg2_data_wrapper(
  107. m_enclave_id, &ret,
  108. input,
  109. sigrl, sigrl_size,
  110. msg3_fixed_output,
  111. epid_sig, epid_sig_buffer_size);
  112. if(status == SGX_ERROR_ENCLAVE_LOST)
  113. ret = AE_ENCLAVE_LOST;
  114. else if(status != SGX_SUCCESS)
  115. ret = AE_FAILURE;
  116. return ret;
  117. }
  118. uint32_t CPVEClass::proc_prov_msg4_data(
  119. const proc_prov_msg4_input_t* msg4_input,
  120. proc_prov_msg4_output_t* data_blob)
  121. {
  122. uint32_t ret = AE_SUCCESS;
  123. sgx_status_t status = SGX_SUCCESS;
  124. AESM_PROFILE_FUN;
  125. if(m_enclave_id==0){
  126. AESM_DBG_ERROR("call proc_prov_msg4_data without loading PvE");
  127. return AE_FAILURE;
  128. }
  129. status = proc_prov_msg4_data_wrapper(
  130. m_enclave_id, &ret,
  131. msg4_input,
  132. data_blob);
  133. if(status == SGX_ERROR_ENCLAVE_LOST)
  134. ret = AE_ENCLAVE_LOST;
  135. else if(status != SGX_SUCCESS)
  136. ret = AE_FAILURE;
  137. return ret;
  138. }
  139. uint32_t CPVEClass::gen_es_msg1_data(
  140. gen_endpoint_selection_output_t* es_output)
  141. {
  142. uint32_t ret = AE_SUCCESS;
  143. sgx_status_t status = SGX_SUCCESS;
  144. AESM_PROFILE_FUN;
  145. if(m_enclave_id==0){
  146. AESM_DBG_ERROR("call gen_es_msg1_data without loading PvE");
  147. return AE_FAILURE;
  148. }
  149. status = gen_es_msg1_data_wrapper(
  150. m_enclave_id, &ret,
  151. es_output);
  152. if(status == SGX_ERROR_ENCLAVE_LOST)
  153. ret = AE_ENCLAVE_LOST;
  154. else if(status != SGX_SUCCESS)
  155. ret = AE_FAILURE;
  156. return ret;
  157. }