AEServices.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 (length != other.length || errorCode != other.errorCode)
  55. return false;
  56. if (data == NULL && other.data == NULL) return true;
  57. if (data != NULL && other.data != NULL)
  58. return (memcmp(data, other.data, other.length) == 0);
  59. else
  60. return false;
  61. }
  62. void copyFields(const PlainData& other) {
  63. length = other.length;
  64. errorCode = other.errorCode;
  65. if(other.data == NULL)
  66. data = NULL;
  67. else {
  68. data = new uint8_t[length];
  69. memcpy(data, other.data, length);
  70. }
  71. }
  72. PlainData& operator=(const PlainData& other) {
  73. if (this == &other)
  74. return *this;
  75. if (data != NULL)
  76. delete [] data;
  77. copyFields(other);
  78. return *this;
  79. }
  80. PlainData(const PlainData& other):length(0), data(NULL), errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED) {
  81. copyFields(other);
  82. }
  83. #endif
  84. };
  85. typedef PlainData Quote;
  86. typedef PlainData Report;
  87. typedef PlainData TargetInfo;
  88. typedef PlainData PlatformGID;
  89. typedef PlainData SignatureRevocationList;
  90. typedef PlainData Nonce;
  91. typedef PlainData SPID;
  92. typedef PlainData LaunchToken;
  93. typedef PlainData EnclaveMeasurement;
  94. typedef PlainData Signature;
  95. typedef PlainData SEAttributes;
  96. typedef PlainData PSEMessage;
  97. typedef PlainData WhiteList;
  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 WhiteListSize
  186. {
  187. uint32_t errorCode;
  188. uae_oal_status_t uaeStatus;
  189. uint32_t white_list_size;
  190. WhiteListSize(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), white_list_size(0){}
  191. ~WhiteListSize()
  192. {
  193. }
  194. bool operator==(const WhiteListSize& other) const
  195. {
  196. if (this == &other) return true;
  197. return white_list_size == other.white_list_size;
  198. }
  199. };
  200. struct ExtendedEpidGroupId
  201. {
  202. uint32_t errorCode;
  203. uae_oal_status_t uaeStatus;
  204. uint32_t x_group_id;
  205. ExtendedEpidGroupId(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), x_group_id(0){}
  206. ~ExtendedEpidGroupId()
  207. {
  208. }
  209. bool operator==(const ExtendedEpidGroupId& other) const
  210. {
  211. if (this == &other) return true;
  212. return x_group_id == other.x_group_id;
  213. }
  214. };
  215. struct AttestationStatus
  216. {
  217. uint32_t errorCode;
  218. uae_oal_status_t uaeStatus;
  219. UpdateInfo* updateInfo;
  220. AttestationStatus(): errorCode(AESM_UNEXPECTED_ERROR), uaeStatus(UAE_OAL_ERROR_UNEXPECTED), updateInfo(NULL) {}
  221. ~AttestationStatus()
  222. {
  223. delete updateInfo;
  224. }
  225. bool operator==(const AttestationStatus& other) const{
  226. if (this == &other) return true;
  227. if (errorCode != other.errorCode) return false;
  228. if (*updateInfo == *other.updateInfo)
  229. return true;
  230. return false;
  231. }
  232. private:
  233. AttestationStatus(const AttestationStatus&); // Prevent copy-construction
  234. AttestationStatus& operator=(const AttestationStatus&); // Prevent assignment
  235. };
  236. class AEServices
  237. {
  238. public:
  239. AEServices() {}
  240. virtual ~AEServices() {}
  241. virtual AttestationInformation* InitQuote(uint32_t timeout_msec=0) = 0;
  242. virtual QuoteInfo* GetQuote(const Report* report, const uint32_t quoteType, const SPID* spid, const Nonce* nonce,
  243. const SignatureRevocationList* sig_rl, const uint32_t bufSize, const bool qe_report,
  244. uint32_t timeout_msec=0) = 0;
  245. virtual PsCap* GetPsCap(uint32_t timeout_msec=0) = 0;
  246. virtual AttestationStatus* ReportAttestationError(const PlatformInfo* platformInfo, uint32_t attestation_error_code, uint32_t updateInfoLength, uint32_t timeout_msec=0) = 0;
  247. virtual WhiteListSize* GetWhiteListSize(uint32_t timeout_msec=0) = 0;
  248. virtual PlainData* GetWhiteList(uint32_t white_list_size, uint32_t timeout = 0) =0;
  249. virtual ExtendedEpidGroupId* SGXGetExtendedEpidGroupId(uint32_t timeout_msec=0) =0;
  250. virtual PlainData* SGXSwitchExtendedEpidGroup(uint32_t x_group_id, uint32_t timeout = 0) =0;
  251. };
  252. #endif