prd_css_util.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "arch.h"
  32. #include "launch_checker.h"
  33. #include "se_vendor.h"
  34. #include "prd_css_util.h"
  35. #include "se_memcpy.h"
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <assert.h>
  39. extern "C" int read_prd_css(const prd_css_path_t prd_css_path, enclave_css_t *css)
  40. {
  41. assert(css != NULL);
  42. enclave_css_t prd_css;
  43. memset(&prd_css, 0, sizeof(enclave_css_t));
  44. FILE * fp = NULL;
  45. fp = fopen(prd_css_path, "rb");
  46. if(fp == NULL)
  47. return SGX_ERROR_INVALID_PARAMETER;
  48. fseek(fp, 0L, SEEK_END);
  49. if(ftell(fp) != sizeof(enclave_css_t))
  50. {
  51. fclose(fp);
  52. return SGX_ERROR_INVALID_PARAMETER;
  53. }
  54. fseek(fp, 0L, SEEK_SET);
  55. if(fread(&prd_css, 1, sizeof(enclave_css_t), fp) != sizeof(enclave_css_t))
  56. {
  57. fclose(fp);
  58. return SGX_ERROR_INVALID_PARAMETER;
  59. }
  60. fclose(fp);
  61. memcpy_s(css, sizeof(enclave_css_t), &prd_css, sizeof(prd_css));
  62. return SGX_SUCCESS;
  63. }
  64. extern "C" bool is_le(SGXLaunchToken *lc, const enclave_css_t *const css)
  65. {
  66. assert(NULL != css && NULL != lc);
  67. sgx_launch_token_t token;
  68. lc->get_launch_token(&token);
  69. token_t *launch = reinterpret_cast<token_t *>(token);
  70. if(INTEL_VENDOR_ID == css->header.module_vendor
  71. && LE_PROD_ID == css->body.isv_prod_id
  72. && 0 != css->header.hw_version
  73. && 0 == launch->body.valid)
  74. return true;
  75. return false;
  76. }