tlv_common.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. /**
  32. * File: tlv_common.h
  33. * Description: Header file to define TLV (the Type Length Value) related data or structure which may be commonly used by multiple components
  34. */
  35. #ifndef _PVE_TLV_COMMON_H
  36. #define _PVE_TLV_COMMON_H
  37. #include "se_cdefs.h"
  38. #include "se_types.h"
  39. #include "sgx_key.h"
  40. #include "byte_order.h"
  41. /*enumerate all tlv types, the value of it is not defined in spec yet*/
  42. typedef enum _tlv_enum_type_t{
  43. TLV_CIPHER_TEXT=0,
  44. TLV_BLOCK_CIPHER_TEXT,
  45. TLV_BLOCK_CIPHER_INFO,
  46. TLV_MESSAGE_AUTHENTICATION_CODE,
  47. TLV_NONCE,
  48. TLV_EPID_GID,
  49. TLV_EPID_SIG_RL,
  50. TLV_EPID_GROUP_CERT,
  51. /*SE Provisioning Protocol TLVs*/
  52. TLV_DEVICE_ID,
  53. TLV_PS_ID,
  54. TLV_EPID_JOIN_PROOF,
  55. TLV_EPID_SIG,
  56. TLV_EPID_MEMBERSHIP_CREDENTIAL,
  57. TLV_EPID_PSVN,
  58. /*PSE Provisioning Protocol TLVs*/
  59. TLV_QUOTE,
  60. TLV_X509_CERT_TLV,
  61. TLV_X509_CSR_TLV,
  62. /*End-point Selection Protocol TLVs*/
  63. TLV_ES_SELECTOR,
  64. TLV_ES_INFORMATION,
  65. /* EPID Provisioning Protocol TLVs Part 2*/
  66. TLV_FLAGS,
  67. /* PSE Quote Signature*/
  68. TLV_QUOTE_SIG,
  69. TLV_PLATFORM_INFO_BLOB,
  70. /* Generic TLVs*/
  71. TLV_SIGNATURE,
  72. /* End-point Selection Protocol TLVs*/
  73. TLV_PEK,
  74. TLV_PLATFORM_INFO,
  75. TLV_PWK2,
  76. TLV_SE_REPORT
  77. }tlv_enum_type_t;
  78. /*here comes general type and macro definition for AESM related Server URL which will be shared by code in other components*/
  79. typedef enum _aesm_network_server_enum_type_t{
  80. SE_EPID_PROVISIONING,
  81. PSE_PROVISIONING,
  82. ENDPOINT_SELECTION,
  83. REVOCATION_LIST_RETRIEVAL,
  84. PSE_OCSP,
  85. SGX_WHITE_LIST_FILE
  86. }aesm_network_server_enum_type_t;
  87. typedef enum _pve_msg_type_t
  88. {
  89. TYPE_PROV_MSG1,
  90. TYPE_PROV_MSG2,
  91. TYPE_PROV_MSG3,
  92. TYPE_PROV_MSG4
  93. }pve_msg_type_t;
  94. typedef enum _pse_msg_type_t
  95. {
  96. TYPE_PSE_MSG1,
  97. TYPE_PSE_MSG2,
  98. TYPE_PSE_MSG3,
  99. TYPE_PSE_MSG4
  100. }pse_msg_type_t;
  101. typedef enum _es_msg_type_t
  102. {
  103. TYPE_ES_MSG1,
  104. TYPE_ES_MSG2
  105. }es_msg_type_t;
  106. typedef enum _rlr_msg_type_t
  107. {
  108. TYPE_RLR_MSG1,
  109. TYPE_RLR_MSG2
  110. }rlr_msg_type_t;
  111. #include "epid_pve_type.h"
  112. typedef uint16_t general_response_status_t;
  113. enum _general_response_status_t
  114. {
  115. GRS_OK,
  116. GRS_SERVER_BUSY,
  117. GRS_INTEGRITY_CHECK_FAIL,
  118. GRS_INCORRECT_SYNTAX,
  119. GRS_INCOMPATIBLE_VERSION,
  120. GRS_TRANSACTION_STATE_LOST,
  121. GRS_PROTOCOL_ERROR,
  122. GRS_INTERNAL_ERROR
  123. };
  124. typedef uint16_t se_protocol_response_status_t;
  125. enum _se_protocol_response_status_t
  126. {
  127. SE_PRS_OK,
  128. SE_PRS_PLATFORM_REVOKED,
  129. SE_PRS_STATUS_INTEGRITY_FAILED,
  130. SE_PRS_PERFORMANCE_REKEY_NOT_SUPPORTED,
  131. SE_PRS_PROVISIONING_ERROR,
  132. SE_PRS_INVALID_REQUEST,
  133. SE_PRS_PROV_ATTEST_KEY_NOT_FOUND,
  134. SE_PRS_INVALID_REPORT
  135. };
  136. typedef uint16_t pse_protocol_response_status_t;
  137. enum _pse_protocol_response_status_t
  138. {
  139. PSE_PRS_OK,
  140. PSE_PRS_INVALID_GID,
  141. PSE_PRS_GID_REVOKED,
  142. PSE_PRS_INVALID_QUOTE,
  143. PSE_PRS_INVALID_REQUEST
  144. };
  145. #pragma pack(1)
  146. #define NET_S_OK 0
  147. typedef struct _provision_request_header_t{
  148. uint8_t protocol;
  149. uint8_t version;
  150. uint8_t xid[XID_SIZE]; /*transaction id, the unique id from ProvMsg1 to ProvMsg4*/
  151. uint8_t type;
  152. uint8_t size[4]; /*size of request body*/
  153. }provision_request_header_t;
  154. typedef struct _provision_response_header_t{
  155. uint8_t protocol;
  156. uint8_t version;
  157. uint8_t xid[XID_SIZE];
  158. uint8_t type;
  159. uint8_t gstatus[2];
  160. uint8_t pstatus[2];
  161. uint8_t size[4];
  162. }provision_response_header_t;
  163. #pragma pack()
  164. #define PROVISION_REQUEST_HEADER_SIZE sizeof(provision_request_header_t)
  165. #define PROVISION_RESPONSE_HEADER_SIZE sizeof(provision_response_header_t)
  166. #define GET_BODY_SIZE_FROM_PROVISION_REQUEST(req) lv_ntohl(((const provision_request_header_t *)(req))->size)
  167. #define GET_BODY_SIZE_FROM_PROVISION_RESPONSE(resp) lv_ntohl(((const provision_response_header_t *)(resp))->size)
  168. #define GET_SIZE_FROM_PROVISION_REQUEST(req) (GET_BODY_SIZE_FROM_PROVISION_REQUEST(req)+PROVISION_REQUEST_HEADER_SIZE)
  169. #define GET_SIZE_FROM_PROVISION_RESPONSE(resp) (GET_BODY_SIZE_FROM_PROVISION_RESPONSE(resp)+PROVISION_RESPONSE_HEADER_SIZE)
  170. #define GET_TYPE_FROM_PROVISION_REQUEST(req) (((const provision_request_header_t *)(req))->type)
  171. #define GET_TYPE_FROM_PROVISION_RESPONSE(resp) (((const provision_response_header_t *)(resp))->type)
  172. #define TLV_VERSION_1 1
  173. #define TLV_VERSION_2 2
  174. #endif