AEServices.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 _AE_SERVICES_H
  32. #define _AE_SERVICES_H
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <stdint.h>
  36. #include <sgx_error.h>
  37. #include <aesm_error.h>
  38. #include <oal/uae_oal_api.h>
  39. #include <Config.h>
  40. struct PlainData
  41. {
  42. uint32_t length;
  43. uint8_t* data;
  44. uint32_t errorCode;
  45. uae_oal_status_t uaeStatus;
  46. #ifdef __cplusplus
  47. PlainData() : length(0), data(NULL), errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED) {}
  48. ~PlainData(){
  49. if (data != NULL) delete [] data;
  50. data = NULL;
  51. }
  52. bool operator==(const PlainData& other) const {
  53. if (this == &other) return true;
  54. if (this == NULL || &other == NULL) return false;
  55. if (length != other.length || errorCode != other.errorCode)
  56. return false;
  57. if (data == NULL && other.data == NULL) return true;
  58. if (data != NULL && other.data != NULL)
  59. return (memcmp(data, other.data, other.length) == 0);
  60. else
  61. return false;
  62. }
  63. void copyFields(const PlainData& other) {
  64. length = other.length;
  65. errorCode = other.errorCode;
  66. if(other.data == NULL)
  67. data = NULL;
  68. else {
  69. data = new uint8_t[length];
  70. memcpy(data, other.data, length);
  71. }
  72. }
  73. PlainData& operator=(const PlainData& other) {
  74. if (this == &other)
  75. return *this;
  76. if (data != NULL)
  77. delete [] data;
  78. copyFields(other);
  79. return *this;
  80. }
  81. PlainData(const PlainData& other):length(0), data(NULL), errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED) {
  82. copyFields(other);
  83. }
  84. #endif
  85. };
  86. typedef PlainData Quote;
  87. typedef PlainData Report;
  88. typedef PlainData TargetInfo;
  89. typedef PlainData PlatformGID;
  90. typedef PlainData SignatureRevocationList;
  91. typedef PlainData Nonce;
  92. typedef PlainData SPID;
  93. typedef PlainData LaunchToken;
  94. typedef PlainData EnclaveMeasurement;
  95. typedef PlainData Signature;
  96. typedef PlainData SEAttributes;
  97. typedef PlainData PSEMessage;
  98. typedef PlainData PlatformInfo;
  99. typedef PlainData UpdateInfo;
  100. struct AttestationInformation
  101. {
  102. uint32_t errorCode;
  103. uae_oal_status_t uaeStatus;
  104. TargetInfo* quotingTarget;
  105. PlatformGID* platformGID;
  106. AttestationInformation(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), quotingTarget(NULL),platformGID(NULL) {}
  107. ~AttestationInformation()
  108. {
  109. delete quotingTarget;
  110. delete platformGID;
  111. }
  112. bool operator==(const AttestationInformation& other) const{
  113. if (this == &other) return true;
  114. if (errorCode != other.errorCode) return false;
  115. if (*quotingTarget == *other.quotingTarget &&
  116. *platformGID == *other.platformGID)
  117. return true;
  118. return false;
  119. }
  120. private:
  121. AttestationInformation(const AttestationInformation&); // Prevent copy-construction
  122. AttestationInformation& operator=(const AttestationInformation&); // Prevent assignment
  123. };
  124. struct QuoteInfo
  125. {
  126. uint32_t errorCode;
  127. uae_oal_status_t uaeStatus;
  128. Quote* quote;
  129. Report* qeReport;
  130. QuoteInfo(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), quote(NULL), qeReport(NULL) {}
  131. ~QuoteInfo()
  132. {
  133. delete quote;
  134. delete qeReport;
  135. }
  136. bool operator==(const QuoteInfo& other) const{
  137. if (this == &other) return true;
  138. if (errorCode != other.errorCode) return false;
  139. if (*quote == *other.quote &&
  140. *qeReport == *other.qeReport)
  141. return true;
  142. return false;
  143. }
  144. private:
  145. QuoteInfo(const QuoteInfo&); // Prevent copy-construction
  146. QuoteInfo& operator=(const QuoteInfo&); // Prevent assignment
  147. };
  148. struct CreateSessionInformation
  149. {
  150. uint32_t errorCode;
  151. uae_oal_status_t uaeStatus;
  152. unsigned int sessionId;
  153. PlainData* dh_msg1;
  154. CreateSessionInformation(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), sessionId(0),dh_msg1(NULL) {}
  155. ~CreateSessionInformation()
  156. {
  157. delete dh_msg1;
  158. }
  159. bool operator==(const CreateSessionInformation& other) const
  160. {
  161. if (this == &other) return true;
  162. if (sessionId != other.sessionId || errorCode != other.errorCode)
  163. return false;
  164. return *dh_msg1 == *other.dh_msg1;
  165. }
  166. private:
  167. CreateSessionInformation(const CreateSessionInformation&); // Prevent copy-construction
  168. CreateSessionInformation& operator=(const CreateSessionInformation&); // Prevent assignment
  169. };
  170. struct PsCap
  171. {
  172. uint32_t errorCode;
  173. uae_oal_status_t uaeStatus;
  174. uint64_t ps_cap;
  175. PsCap(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), ps_cap(0){}
  176. ~PsCap()
  177. {
  178. }
  179. bool operator==(const PsCap& other) const
  180. {
  181. if (this == &other) return true;
  182. return ps_cap == other.ps_cap;
  183. }
  184. };
  185. struct AttestationStatus
  186. {
  187. uint32_t errorCode;
  188. uae_oal_status_t uaeStatus;
  189. UpdateInfo* updateInfo;
  190. AttestationStatus(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), updateInfo(NULL) {}
  191. ~AttestationStatus()
  192. {
  193. delete updateInfo;
  194. }
  195. bool operator==(const AttestationStatus& other) const{
  196. if (this == &other) return true;
  197. if (errorCode != other.errorCode) return false;
  198. if (*updateInfo == *other.updateInfo)
  199. return true;
  200. return false;
  201. }
  202. private:
  203. AttestationStatus(const AttestationStatus&); // Prevent copy-construction
  204. AttestationStatus& operator=(const AttestationStatus&); // Prevent assignment
  205. };
  206. class AEServices
  207. {
  208. public:
  209. AEServices() {}
  210. virtual ~AEServices() {}
  211. virtual AttestationInformation* InitQuote(uint32_t timeout_msec=0) = 0;
  212. virtual QuoteInfo* GetQuote(const Report* report, const uint32_t quoteType, const SPID* spid, const Nonce* nonce,
  213. const SignatureRevocationList* sig_rl, const uint32_t bufSize, const bool qe_report,
  214. uint32_t timeout_msec=0) = 0;
  215. virtual PsCap* GetPsCap(uint32_t timeout_msec=0) = 0;
  216. virtual AttestationStatus* ReportAttestationError(const PlatformInfo* platformInfo, uint32_t attestation_error_code, uint32_t updateInfoLength, uint32_t timeout_msec=0) = 0;
  217. };
  218. #endif