pse_pr.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. /**
  32. * File: platform_service_enclave.cpp
  33. * Description: Definition for interfaces provided by platform service enclave..
  34. *
  35. * Definition for interfaces provided by platform service enclave.
  36. */
  37. #include <cstddef>
  38. #include "pse_pr_t.c"
  39. #include "pse_pr_inc.h"
  40. #include "t_certificate_provisioning.h"
  41. #include "t_long_term_pairing.h"
  42. #include "le2be_macros.h"
  43. #include "pse_pr_common.h"
  44. #include "Epid11_rl.h"
  45. static TEpidSigma11Verifier* s_pVerifier = NULL;
  46. //length to copy into enclave
  47. size_t get_sigRL_size(const EPID11_SIG_RL* pSigRL)
  48. {
  49. uint32_t nEntries = 0;
  50. uint32_t nSize = 0;
  51. if (TEpidSigma11Verifier::get_sigRL_info(pSigRL, nEntries, nSize))
  52. return nSize;
  53. else
  54. //invalid sigRL
  55. return sizeof(EPID11_SIG_RL);
  56. }
  57. //length to copy into enclave
  58. size_t get_privRL_size(const EPID11_PRIV_RL* pPrivRL)
  59. {
  60. uint32_t nEntries = 0;
  61. uint32_t nSize = 0;
  62. if (TEpidSigma11Verifier::get_privRL_info(pPrivRL, nEntries, nSize))
  63. return nSize;
  64. else
  65. //invalid privRL
  66. return sizeof(EPID11_PRIV_RL);
  67. }
  68. ae_error_t ecall_tPrepareForCertificateProvisioning
  69. (
  70. /*in */ UINT64 nonce64,
  71. /*in */ const sgx_target_info_t* pTargetInfo,
  72. /*in */ UINT16 nMaxLen_CSR_pse,
  73. /*out*/ UINT8* pCSR_pse,
  74. /*out*/ UINT16* pnTotalLen_CSR_pse,
  75. /*out*/ sgx_report_t* pREPORT,
  76. /*i/o*/ pairing_blob_t* pPairingBlob
  77. )
  78. {
  79. ae_error_t status = AE_FAILURE;
  80. status = prepare_for_certificate_provisioning( nonce64, pTargetInfo,
  81. nMaxLen_CSR_pse, pCSR_pse, pnTotalLen_CSR_pse,
  82. pREPORT, pPairingBlob);
  83. return status;
  84. }
  85. ae_error_t ecall_tGenM7
  86. (
  87. /*in */ const SIGMA_S1_MESSAGE* pS1,
  88. /*in */ const EPID11_SIG_RL* pSigRL,
  89. /*in */ const uint8_t* pOcspResp,
  90. /*in */ uint32_t nLen_OcspResp,
  91. /*in */ const uint8_t* pVerifierCert,
  92. /*in */ uint32_t nLen_VerifierCert,
  93. /*in */ const pairing_blob_t* pPairingBlob,
  94. /*in */ uint32_t nMax_S2,
  95. /*out*/ SIGMA_S2_MESSAGE* pS2,
  96. /*out*/ uint32_t* pnLen_S2
  97. )
  98. {
  99. ae_error_t status = AE_FAILURE;
  100. PSE_PR_SAFE_DELETE(s_pVerifier);
  101. do
  102. {
  103. s_pVerifier = new (std::nothrow) TEpidSigma11Verifier;
  104. BREAK_IF_TRUE((NULL == s_pVerifier), status, PSE_PR_INSUFFICIENT_MEMORY_ERROR);
  105. status = s_pVerifier->GenM7(
  106. pS1,
  107. pSigRL,
  108. pOcspResp, nLen_OcspResp,
  109. pVerifierCert, nLen_VerifierCert,
  110. pPairingBlob,
  111. nMax_S2, pS2, pnLen_S2);
  112. BREAK_IF_FAILED(status);
  113. } while (0);
  114. if (AE_FAILED(status))
  115. PSE_PR_SAFE_DELETE(s_pVerifier);
  116. return status;
  117. }
  118. ae_error_t ecall_tVerifyM8
  119. (
  120. /*in */ const SIGMA_S3_MESSAGE* pS3,
  121. /*in */ uint32_t nLen_S3,
  122. /*in */ const EPID11_PRIV_RL* pPrivRL,
  123. /*out*/ pairing_blob_t* pPairingBlob,
  124. /*out*/ uint8_t* puNewPairing
  125. )
  126. {
  127. ae_error_t status = AE_FAILURE;
  128. do
  129. {
  130. BREAK_IF_TRUE((NULL == s_pVerifier), status, PSE_PR_CALL_ORDER_ERROR);
  131. status = s_pVerifier->VerifyM8(
  132. pS3, nLen_S3,
  133. pPrivRL, pPairingBlob,
  134. (bool*)puNewPairing);
  135. BREAK_IF_FAILED(status);
  136. } while (0);
  137. PSE_PR_SAFE_DELETE(s_pVerifier);
  138. return status;
  139. }
  140. #if 0
  141. #include <stdio.h>
  142. #include <stdarg.h>
  143. // EDL for this function
  144. // untrusted
  145. // {
  146. // void ocall_OutputOctets
  147. // (
  148. // [in, sizefunc=strlen_with_null] const char* pMsg,
  149. // [in, size=nData] const void* pData,
  150. // size_t nData
  151. // );
  152. // };
  153. void OutputOctets(const char* pMsg, const void* pData, size_t nData)
  154. {
  155. ocall_OutputOctets(pMsg, (const uint8_t*)pData, nData);
  156. }
  157. // EDL for this function
  158. // untrusted
  159. // {
  160. // void ocall_OutputString
  161. // (
  162. // [in, sizefunc=strlen_with_null] const char* pMsg,
  163. // );
  164. // };
  165. void OutputString(const char* format, ...)
  166. {
  167. char buffer[1024];
  168. va_list args;
  169. va_start (args, format);
  170. vsnprintf (buffer, sizeof(buffer), format, args);
  171. va_end (args);
  172. ocall_OutputString(buffer);
  173. }
  174. size_t strlen_with_null(const char* pMsg)
  175. {
  176. size_t len = 0;
  177. if (pMsg)
  178. len = strlen(pMsg) + 1;
  179. return len;
  180. }
  181. #endif