aesm_xegd_blob.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <stdio.h>
  32. #include "aesm_xegd_blob.h"
  33. #include "endpoint_select_info.h"
  34. #include "internal/se_memcpy.h"
  35. #include "oal/oal.h"
  36. #include "byte_order.h"
  37. #include "aesm_epid_blob.h"
  38. ae_error_t XEGDBlob::verify_xegd_by_xgid(uint32_t xgid)
  39. {
  40. extended_epid_group_blob_t blob;
  41. if (xgid == DEFAULT_EGID){//always return success for default xgid
  42. return AE_SUCCESS;
  43. }
  44. uint32_t data_size = sizeof(blob);
  45. ae_error_t ae_ret = aesm_read_data(FT_PERSISTENT_STORAGE, EXTENDED_EPID_GROUP_BLOB_INFO_FID, reinterpret_cast<uint8_t *>(&blob), &data_size, xgid);
  46. if (AE_SUCCESS != ae_ret){
  47. return ae_ret;
  48. }
  49. if (data_size != sizeof(blob)){
  50. return OAL_CONFIG_FILE_ERROR;
  51. }
  52. ae_ret = verify(blob);
  53. return ae_ret;
  54. }
  55. ae_error_t XEGDBlob::read(extended_epid_group_blob_t& blob)
  56. {
  57. ae_error_t ae_ret = AE_FAILURE;
  58. if(status == not_initialized){
  59. uint32_t data_size = sizeof(blob_cache);
  60. if ((ae_ret = aesm_read_data(FT_PERSISTENT_STORAGE, EXTENDED_EPID_GROUP_BLOB_INFO_FID, reinterpret_cast<uint8_t *>(&blob_cache), &data_size, AESMLogic::get_active_extended_epid_group_id())) != AE_SUCCESS){
  61. goto CLEANUP_READ_FILE;
  62. }
  63. if (data_size != sizeof(blob_cache)){
  64. ae_ret = OAL_CONFIG_FILE_ERROR;
  65. goto CLEANUP_READ_FILE;
  66. }
  67. ae_ret = verify(blob_cache);
  68. if (AE_SUCCESS != ae_ret){
  69. AESM_DBG_ERROR("signature error in XEGD file");
  70. goto CLEANUP_READ_FILE;
  71. }
  72. status = update_to_date;
  73. CLEANUP_READ_FILE:
  74. if (status != update_to_date){
  75. if (AESMLogic::get_active_extended_epid_group_id() == DEFAULT_EGID){
  76. memset(&blob_cache, 0, sizeof(blob_cache));//indicate other part to use default data
  77. status = update_to_date;
  78. }
  79. else{
  80. status = not_available;//xegd blob lost
  81. }
  82. }
  83. }
  84. if(status == update_to_date){
  85. if(memcpy_s(&blob, sizeof(blob), &blob_cache, sizeof(blob_cache))!=0){
  86. status = not_available; //invalid
  87. ae_ret = AE_FAILURE;
  88. }else{
  89. ae_ret = AE_SUCCESS;
  90. }
  91. }
  92. return ae_ret;
  93. }
  94. ae_error_t aesm_verify_xegb(const extended_epid_group_blob_t& signed_xegb);
  95. ae_error_t XEGDBlob::verify(const extended_epid_group_blob_t& signed_xegb)
  96. {
  97. ae_error_t aesm_result = aesm_verify_xegb(signed_xegb);
  98. if (AE_SUCCESS != aesm_result)
  99. {
  100. AESM_DBG_ERROR("Extended EPID Group Blob Signature verifcation not passed:%d", aesm_result);
  101. return aesm_result;
  102. }
  103. return aesm_result;
  104. }