pse_pr.cpp 5.4 KB

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