AEReportAttestationRequest.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #include <AEReportAttestationRequest.h>
  32. #include <AEReportAttestationResponse.h>
  33. #include <IAESMLogic.h>
  34. #include <string.h>
  35. #include <stdlib.h>
  36. #include <limits.h>
  37. #include <IAEMessage.h>
  38. AEReportAttestationRequest::AEReportAttestationRequest(const aesm::message::Request::ReportAttestationErrorRequest& request) :
  39. m_request(NULL)
  40. {
  41. m_request = new aesm::message::Request::ReportAttestationErrorRequest();
  42. m_request->CopyFrom(request);
  43. }
  44. AEReportAttestationRequest::AEReportAttestationRequest(uint32_t platformInfoLength, const uint8_t* platformInfo, uint32_t attestation_error_code, uint32_t updateInfoLength, uint32_t timeout)
  45. :m_request(NULL)
  46. {
  47. m_request = new aesm::message::Request::ReportAttestationErrorRequest();
  48. if (platformInfoLength !=0 && platformInfo != NULL)
  49. {
  50. m_request->set_platform_info(platformInfo, platformInfoLength);
  51. }
  52. m_request->set_attestation_error_code(attestation_error_code);
  53. m_request->set_update_info_size(updateInfoLength);
  54. m_request->set_timeout(timeout);
  55. }
  56. AEReportAttestationRequest::AEReportAttestationRequest(const AEReportAttestationRequest& other)
  57. : m_request(NULL)
  58. {
  59. if (other.m_request != NULL)
  60. m_request = new aesm::message::Request::ReportAttestationErrorRequest(*other.m_request);
  61. }
  62. AEReportAttestationRequest::~AEReportAttestationRequest()
  63. {
  64. if (m_request != NULL)
  65. delete m_request;
  66. }
  67. AEMessage* AEReportAttestationRequest::serialize()
  68. {
  69. AEMessage *ae_msg = NULL;
  70. aesm::message::Request msg;
  71. if (check())
  72. {
  73. aesm::message::Request::ReportAttestationErrorRequest* mutableReq = msg.mutable_reporterrreq();
  74. mutableReq->CopyFrom(*m_request);
  75. if (msg.ByteSize() <= INT_MAX) {
  76. ae_msg = new AEMessage;
  77. ae_msg->size = (unsigned int)msg.ByteSize();
  78. ae_msg->data = new char[ae_msg->size];
  79. msg.SerializeToArray(ae_msg->data, ae_msg->size);
  80. }
  81. }
  82. return ae_msg;
  83. }
  84. AEReportAttestationRequest& AEReportAttestationRequest::operator=(const AEReportAttestationRequest& other)
  85. {
  86. if (this == &other)
  87. return *this;
  88. if (m_request != NULL)
  89. {
  90. delete m_request;
  91. m_request = NULL;
  92. }
  93. if (other.m_request != NULL)
  94. m_request = new aesm::message::Request::ReportAttestationErrorRequest(*other.m_request);
  95. return *this;
  96. }
  97. bool AEReportAttestationRequest::check()
  98. {
  99. if (m_request == NULL)
  100. return false;
  101. return m_request->IsInitialized();
  102. }
  103. IAERequest::RequestClass AEReportAttestationRequest::getRequestClass()
  104. {
  105. return QUOTING_CLASS;
  106. }
  107. IAEResponse* AEReportAttestationRequest::execute(IAESMLogic* aesmLogic)
  108. {
  109. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  110. uint8_t* update_info = NULL;
  111. uint32_t update_info_size = 0;
  112. if (check())
  113. {
  114. uint32_t platform_info_length = 0;
  115. uint8_t* platform_info = NULL;
  116. if (m_request->has_platform_info())
  117. {
  118. platform_info_length = (unsigned int)m_request->platform_info().size();
  119. platform_info = (uint8_t*)const_cast<char *>(m_request->platform_info().data());
  120. }
  121. uint32_t errorCode = m_request->attestation_error_code();
  122. update_info_size = m_request->update_info_size();
  123. result = aesmLogic->reportAttestationStatus(platform_info, platform_info_length,
  124. errorCode,
  125. &update_info, update_info_size);
  126. }
  127. IAEResponse* response = new AEReportAttestationResponse(result, update_info_size, update_info);
  128. if (update_info)
  129. delete[]update_info;
  130. return response;
  131. }