IAERequest.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_REQUEST_H__
  32. #define __AE_REQUEST_H__
  33. #include <string.h>
  34. #include <stdint.h>
  35. #include <sgx_error.h>
  36. #include <aeerror.h>
  37. #include <Config.h>
  38. struct AEMessage{
  39. uint32_t size;
  40. char* data;
  41. #ifdef __cplusplus
  42. AEMessage(): size(0), data(NULL) {}
  43. ~AEMessage(){
  44. if (data != NULL) delete [] data;
  45. data = NULL;
  46. }
  47. bool operator==(const AEMessage &other) const
  48. {
  49. if (this == &other) return true;
  50. if (this == NULL) return false;
  51. if (size != other.size) return false;
  52. if (memcmp(data, other.data, size) != 0) return false;
  53. return true;
  54. }
  55. void copyFields(const AEMessage& other)
  56. {
  57. size = other.size;
  58. if (other.data == NULL)
  59. data = NULL;
  60. else
  61. {
  62. data = new char[size];
  63. memcpy(data, other.data, size);
  64. }
  65. }
  66. AEMessage& operator=(const AEMessage& other)
  67. {
  68. if (this == &other)
  69. return *this;
  70. if (data != NULL)
  71. delete [] data;
  72. copyFields(other);
  73. return *this;
  74. }
  75. AEMessage(const AEMessage& other)
  76. {
  77. copyFields(other);
  78. }
  79. #endif
  80. };
  81. class ISerializer;
  82. class IAEResponse;
  83. class IAESMLogic;
  84. class AECloseSessionRequest;
  85. class AEExchangeReportRequest;
  86. class AEInvokeServiceRequest;
  87. class AECreateSessionRequest;
  88. class AEReportAttestationRequest;
  89. class AEGetLaunchTokenRequest;
  90. class AEGetQuoteRequest;
  91. class AEInitQuoteRequest;
  92. class AEGetPsCapRequest;
  93. class IAERequestVisitor
  94. {
  95. public:
  96. virtual void visitInitQuoteRequest(AEInitQuoteRequest&) = 0;
  97. virtual void visitGetQuoteRequest(AEGetQuoteRequest&) = 0;
  98. virtual void visitGetLaunchTokenRequest(AEGetLaunchTokenRequest&) = 0;
  99. virtual void visitReportAttestationRequest(AEReportAttestationRequest&) = 0;
  100. virtual void visitCreateSessionRequest(AECreateSessionRequest&) = 0;
  101. virtual void visitInvokeServiceRequest(AEInvokeServiceRequest&) = 0;
  102. virtual void visitExchangeReportRequest(AEExchangeReportRequest&) = 0;
  103. virtual void visitCloseSessionRequest(AECloseSessionRequest&) = 0;
  104. virtual void visitGetPsCapRequest(AEGetPsCapRequest&) = 0;
  105. virtual ~IAERequestVisitor() = 0;
  106. };
  107. class IAERequest{
  108. public:
  109. typedef enum {QUOTING_CLASS, LAUNCH_CLASS, PLATFORM_CLASS} RequestClass;
  110. IAERequest(uint32_t timeout = IPC_LATENCY) : mTimeout(timeout), mValidSizeCheck(false) {} //constructor with default parameter
  111. virtual ~IAERequest() {}
  112. virtual void visit(IAERequestVisitor&) = 0;
  113. virtual AEMessage* serialize(ISerializer* serializer) =0;
  114. virtual RequestClass getRequestClass() = 0;
  115. //this method is added especially for future compatibility (may be used to check thigs like the message MAC)
  116. virtual bool check() {return false;} //although only some requests will need more complex logic here, this will default to
  117. //invalid. Validity needs to be explicitly declared in children :)
  118. virtual IAEResponse* execute(IAESMLogic* aesmLogic) =0;
  119. //timeout
  120. uint32_t GetTimeout() const { return mTimeout; }
  121. protected:
  122. uint32_t mTimeout;
  123. bool mValidSizeCheck;
  124. };
  125. #endif