pse_pr.cpp 5.7 KB

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