util_st.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2011-2017 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 _UTIL_ST_H_
  32. #define _UTIL_ST_H_
  33. #include "se_cdefs.h"
  34. #include "se_memcpy.h"
  35. #include <stdio.h>
  36. #define USAGE_STRING \
  37. "Usage: sgx_sign <commands> [options] file...\n"\
  38. "Commands:\n"\
  39. " sign Sign the enclave using the private key\n"\
  40. " gendata Generate enclave signing material to be signed\n"\
  41. " catsig Generate the signed enclave with the input signature file, the\n"\
  42. " public key and the enclave signing material\n"\
  43. "Options:\n"\
  44. " -enclave Specify the enclave file to be signed\n"\
  45. " It is a required option for the three commands\n"\
  46. " -key Specify the key file\n"\
  47. " It is a required option for \"sign\" and \"catsig\"\n"\
  48. " -config Specify the configuration for the enclave\n"\
  49. " -out Specify the output file\n"\
  50. " It is a required option for the three commands\n"\
  51. " -sig Specify the signature file for the enclave signing material\n" \
  52. " It is a required option for \"catsig\"\n"\
  53. " -unsigned Specify the enclave signing material generated by \"gendata\"\n" \
  54. " It is a required option for \"catsig\"\n" \
  55. " -ignore-rel-error By default, sgx_sign provides an error for enclaves with\n" \
  56. " text relocations. You can ignore the error and continue signing\n" \
  57. " by providing this option. But it is recommended you eliminate the\n" \
  58. " text relocations instead of bypassing the error with this option.\n"
  59. // General error message
  60. #define OVERALL_ERROR "Error happened while signing the enclave.\n"
  61. #define KEY_FORMAT_ERROR "Key file format is not correct.\n"
  62. #define XML_FORMAT_ERROR "Configure file format is not correct.\n"
  63. #define NO_MEMORY_ERROR "Out of memory.\n"
  64. #define OPEN_FILE_ERROR "Failed to open file \"%s\".\n"
  65. #define READ_FILE_ERROR "Failed to read file \"%s\".\n"
  66. #define WRITE_FILE_ERROR "Failed to write file \"%s\".\n"
  67. // error message for measure_enclave()
  68. #define OUT_OF_EPC_ERROR "The required memory is too large. Please check TCSNum/HeapMaxSize/StackMaxSize.\n"
  69. #define META_VERSION_ERROR "Metadata version is mismatched between uRTS and sgx_sign.\n"
  70. #define INVALID_ENCLAVE_ERROR "The input enclave file is not correct.\n"
  71. #define REQUIRED_ENCLAVE_SIZE "The required memory is %lluB.\n"
  72. #define TEXT_REL_ERROR "The enclave image has text relocations.\n"
  73. // error message for fill_enclave_css()
  74. #define UNSIGNED_FILE_ERROR "The unsigned file \"%s\" is not correct.\n"
  75. #define UNSIGNED_FILE_XML_MISMATCH "The unsigned file content doesn't match the configuration file.\n"
  76. // error message for create_signature()
  77. #define SIG_FILE_ERROR "The signature file \"%s\" is not correct.\n"
  78. // error message for cmdline_parse()
  79. #define LACK_PARA_ERROR "Lack of parameters.\n"
  80. #define UNREC_CMD_ERROR "Cannot recognize the command \"%s\".\nCommand \"sign/gendata/catsig\" is required.\n"
  81. #define REPEAT_OPTION_ERROR "Repeatly specified \"%s\" option.\n"
  82. #define INVALID_FILE_NAME_ERROR "The File name is not correct for \"%s\" option.\n"
  83. #define LACK_REQUIRED_OPTION_ERROR "Option \"%s\" is required for the command \"%s\".\n"
  84. #define GIVE_INVALID_OPTION_ERROR "Option \"%s\" is invalid for the command \"%s\".\n"
  85. // error message for generate_output()
  86. #define LACK_PRI_KEY_ERROR "Private key is required for the \"sign\" command.\n"
  87. #define LACK_PUB_KEY_ERROR "Public key is required for the \"catsig\" command.\n"
  88. // error message for main()
  89. #define INIT_IPP_LIBRARY_ERROR "Failed to initialize the IPP library.\n"
  90. #define ENCLAVE_ALREADY_SIGNED_ERROR "The enclave has been signed already.\n"
  91. #define SUCCESS_EXIT "Succeed.\n"
  92. // error message for traverser_parameter()
  93. #define LACK_VALUE_FOR_ELEMENT_ERROR "No value for the element \"%s\".\n"
  94. #define INVALID_VALUE_FOR_ELEMENT_ERROR "Invalid value for the element\"%s\".\n"
  95. #define UNREC_ELEMENT_ERROR "Element is not recognized - \"%s\".\n"
  96. #define REPEATED_DEFINE_ERROR "Defined \"%s\" too many times.\n"
  97. #define VALUE_OUT_OF_RANGE_ERROR "The value of \"%s\" is out of range.\n"
  98. // error message for modify_metadata()
  99. #define SET_STACK_SIZE_ERROR "Stack size setting is not correct.\n"
  100. #define SET_HEAP_SIZE_ERROR "Heap size setting is not correct.\n"
  101. #define SET_HW_LE_ERROR "Conflicting setting between the 'HW' and 'LaunchKey'.\n"
  102. // error message for compare_enclave()
  103. #define PDB_PATH_ERROR "The two enclaves' pdb path are not equal. The pdb path of \"%s\" is \"%s\", while the pdb path of \"%s\" is \"%s\".\n"
  104. #include <stdint.h>
  105. #include <iostream>
  106. #ifdef __cplusplus
  107. extern "C" {
  108. #endif
  109. size_t get_file_size(const char *filename);
  110. bool read_file_to_buf(const char *filename, uint8_t *buffer, size_t bsize);
  111. bool write_data_to_file(const char *filename, std::ios_base::openmode mode, uint8_t *buf, size_t bsize, long offset = 0);
  112. bool copy_file(const char *source_path, const char *dest_path);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif