AEExchangeReportRequest.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #include <ISerializer.h>
  32. #include <AEExchangeReportRequest.h>
  33. #include <AEExchangeReportResponse.h>
  34. #include <IAESMLogic.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. AEExchangeReportRequest::AEExchangeReportRequest()
  38. :mSessionId(0), mDHMsg2Length(0), mDHMsg2(NULL), mDHMsg3Length(0)
  39. {
  40. }
  41. AEExchangeReportRequest::AEExchangeReportRequest(uint32_t sessionId, uint32_t dhMsg2Length, const uint8_t* dhMsg2, uint32_t dhMsg3Length, uint32_t timeout)
  42. :mSessionId(0), mDHMsg2Length(0), mDHMsg2(NULL), mDHMsg3Length(0)
  43. {
  44. CopyFields(sessionId, dhMsg2Length, dhMsg2, dhMsg3Length, timeout);
  45. }
  46. AEExchangeReportRequest::AEExchangeReportRequest(const AEExchangeReportRequest& other)
  47. :IAERequest(other), mSessionId(0), mDHMsg2Length(0), mDHMsg2(NULL), mDHMsg3Length(0)
  48. {
  49. CopyFields(other.mSessionId, other.mDHMsg2Length, other.mDHMsg2, other.mDHMsg3Length, other.mTimeout);
  50. }
  51. AEExchangeReportRequest::~AEExchangeReportRequest()
  52. {
  53. ReleaseMemory();
  54. }
  55. void AEExchangeReportRequest::ReleaseMemory()
  56. {
  57. if (mDHMsg2 != NULL)
  58. {
  59. if (mDHMsg2Length > 0)
  60. memset(mDHMsg2, 0, mDHMsg2Length);
  61. delete [] mDHMsg2;
  62. mDHMsg2 = NULL;
  63. }
  64. mDHMsg2Length = 0;
  65. mDHMsg3Length = 0;
  66. mSessionId = 0;
  67. mTimeout = 0;
  68. }
  69. void AEExchangeReportRequest::CopyFields(uint32_t sessionId, uint32_t dhMsg2Length, const uint8_t* dhMsg2, uint32_t dhMsg3Length, uint32_t timeout)
  70. {
  71. if(dhMsg2Length <= MAX_MEMORY_ALLOCATION && mDHMsg3Length <= MAX_MEMORY_ALLOCATION)
  72. {
  73. mValidSizeCheck = true;
  74. }
  75. else
  76. {
  77. mValidSizeCheck = false;
  78. return;
  79. }
  80. mSessionId = sessionId;
  81. mDHMsg2Length = dhMsg2Length;
  82. mDHMsg3Length = dhMsg3Length;
  83. mTimeout = timeout;
  84. if (dhMsg2 != NULL && dhMsg2Length > 0) {
  85. mDHMsg2 = new uint8_t[dhMsg2Length];
  86. memcpy(mDHMsg2, dhMsg2, dhMsg2Length);
  87. }
  88. }
  89. AEMessage* AEExchangeReportRequest::serialize(ISerializer* serializer)
  90. {
  91. return serializer->serialize(this);
  92. }
  93. void AEExchangeReportRequest::inflateValues(uint32_t sessionId, uint32_t dhMsg2Length, const uint8_t* dhMsg2, uint32_t dhMsg3Length, uint32_t timeout)
  94. {
  95. ReleaseMemory();
  96. CopyFields(sessionId, dhMsg2Length, dhMsg2, dhMsg3Length, timeout);
  97. }
  98. bool AEExchangeReportRequest::operator==(const AEExchangeReportRequest& other) const
  99. {
  100. if (this == &other)
  101. return true;
  102. if (mSessionId != other.mSessionId ||
  103. mDHMsg2Length != other.mDHMsg2Length ||
  104. mDHMsg3Length != other.mDHMsg3Length ||
  105. mTimeout != other.mTimeout)
  106. return false;
  107. if ((mDHMsg2 != other.mDHMsg2) &&
  108. (mDHMsg2 == NULL || other.mDHMsg2 == NULL))
  109. return false;
  110. if (mDHMsg2 != NULL && other.mDHMsg2 != NULL && memcmp(mDHMsg2, other.mDHMsg2, other.mDHMsg2Length) != 0)
  111. return false;
  112. return true;
  113. }
  114. AEExchangeReportRequest& AEExchangeReportRequest::operator=(const AEExchangeReportRequest& other)
  115. {
  116. if (this == &other)
  117. return *this;
  118. inflateValues(other.mSessionId, other.mDHMsg2Length, other.mDHMsg2, other.mDHMsg3Length, other.mTimeout);
  119. return *this;
  120. }
  121. bool AEExchangeReportRequest::check()
  122. {
  123. if(mValidSizeCheck == false)
  124. return false;
  125. if (mDHMsg2 == NULL)
  126. return false;
  127. return true;
  128. }
  129. IAERequest::RequestClass AEExchangeReportRequest::getRequestClass() {
  130. return PLATFORM_CLASS;
  131. }
  132. IAEResponse* AEExchangeReportRequest::execute(IAESMLogic* aesmLogic) {
  133. aesm_error_t ret = AESM_UNEXPECTED_ERROR;
  134. uint8_t* dh_msg3 = NULL;
  135. if (check() == false)
  136. {
  137. ret = AESM_PARAMETER_ERROR;
  138. }
  139. else
  140. {
  141. dh_msg3 = new uint8_t[mDHMsg3Length];
  142. ret = aesmLogic->exchangeReport(mSessionId, mDHMsg2, mDHMsg2Length, dh_msg3, mDHMsg3Length);
  143. }
  144. IAEResponse* ae_res = new AEExchangeReportResponse(ret, mDHMsg3Length, dh_msg3);
  145. if (dh_msg3)
  146. {
  147. delete [] dh_msg3;
  148. }
  149. return ae_res;
  150. }
  151. void AEExchangeReportRequest::visit(IAERequestVisitor& visitor)
  152. {
  153. visitor.visitExchangeReportRequest(*this);
  154. }