provision_msg.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. /**
  32. * File: provision_msg.h
  33. * Description: Definition for data structure and provision protocol
  34. *
  35. * Definition for data structure and provision protocol
  36. */
  37. #ifndef _PVE_MSG_H_
  38. #define _PVE_MSG_H_
  39. #include "epid_pve_type.h"
  40. #include "sgx_tseal.h"
  41. //error code definition
  42. typedef enum _pve_status_t
  43. {
  44. PVEC_SUCCESS = 0,
  45. PVEC_PARAMETER_ERROR,
  46. PVEC_INSUFFICIENT_MEMORY_ERROR,
  47. PVEC_READ_RAND_ERROR,
  48. PVEC_SIGRL_INTEGRITY_CHECK_ERROR,
  49. PVEC_MALLOC_ERROR,
  50. PVEC_EPID_BLOB_ERROR,
  51. PVEC_SE_ERROR,
  52. PVEC_IPP_ERROR,
  53. PVEC_MSG_ERROR,
  54. PVEC_PEK_SIGN_ERROR,
  55. PVEC_INTEGER_OVERFLOW_ERROR,
  56. PVEC_SEAL_ERROR,
  57. PVEC_EPID_ERROR,
  58. PVEC_SESSION_OUT_OF_ORDER_ERROR,
  59. PVEC_REVOKED_ERROR,
  60. PVEC_UNSUPPORTED_VERSION_ERROR,
  61. PVEC_INVALID_CPU_ISV_SVN,
  62. PVEC_INVALID_EPID_KEY,
  63. PVEC_UNEXPECTED_ERROR //unknown error which should never happen, it indicates there're internal logical error in PvE's code
  64. }pve_status_t;
  65. //State inside PvE
  66. typedef enum _prov_stage_t
  67. {
  68. PVE_STAGE_IDLE, //waiting for ProvMsg1
  69. PVE_STAGE_WAIT_FOR_GET_EK2, //waiting for get ek2 after processing msg1
  70. PVE_STAGE_WAIT_FOR_MSG2_OR_MSG4, //waiting for ProvMsg2 or ProvMsg4 after getting ek2
  71. PVE_STAGE_WAIT_FOR_MSG4, //waiting for ProvMsg4 only
  72. }prov_stage_t;
  73. #define PVE_RSAOAEP_ENCRYPT_MAXLEN (PVE_RSA_KEY_BYTES - 2*SHA_SIZE_BIT/8 - 2) //190 bytes at most
  74. //macro definition for RSA-OAE algorithm
  75. //SHA-256 will be used for the hash generation
  76. #define SHA_SIZE_BIT 256
  77. #define MSG1_FIELD1_MAX_PAYLOAD_SIZE (4+PPID_SIZE+FMSP_SIZE+PSVN_SIZE+4+FLAGS_SIZE)
  78. #define HARD_CODED_EPID_BLOB_SIZE (sizeof(sgx_sealed_data_t)+sizeof(se_secret_epid_data_t)+sizeof(se_plaintext_epid_data_t))
  79. #define pointer_diff_u32(p1, p2) static_cast<uint32_t>(p1-p2)
  80. #pragma pack(1)
  81. //output information from PvE for AESM to generated ProvMsg1
  82. typedef struct _prov_msg1_output_t{
  83. uint32_t field1_data_size; //size of field1_data, it will be no more than MSG1_FIELD1_MAX_PAYLOAD_SIZE
  84. uint8_t xid[XID_SIZE]; //The random transaction id which will be generated inside Enclave
  85. uint8_t field0[PVE_RSA_KEY_BYTES]; //field0 of Msg1 generated inside PvE encrypted by RSA-OAEP, that's SK TLV:PSID TLV
  86. uint8_t field1_iv[IV_SIZE]; //The random IV used to encrypt field1 of Msg1 by aes-gcm
  87. //field1 before encryption is DeviceIDTlV[:FlagTLV]
  88. uint8_t field1_data[MSG1_FIELD1_MAX_PAYLOAD_SIZE];//The encrypted field1 of Msg1 by aes-gcm, the size in byte is indicated by field1_data
  89. uint8_t field1_mac[MAC_SIZE]; //The generated mac value of field1 of Msg1 by aes-gcm
  90. }prov_msg1_output_t;
  91. //input information to generate EK2 by PvE
  92. typedef struct _prov_get_ek2_input_t{
  93. uint8_t xid[XID_SIZE]; //The transaction Id
  94. uint8_t nonce[NONCE_SIZE]; //The nonce_r from ProvMsg2 or ProvMsg4
  95. }prov_get_ek2_input_t;
  96. //Ek2 generated by PvE
  97. typedef struct _prov_get_ek2_output_t{
  98. uint8_t ek2[SK_SIZE];
  99. }prov_get_ek2_output_t;
  100. //input information for PvE to decode data from ProvMsg2
  101. typedef struct _proc_prov_msg2_blob_input_t{
  102. signed_epid_group_cert_t group_cert; //ECDSA signed EPID Group Public Certificate from Intel decoded from ProvMsg2
  103. uint8_t challenge_nonce[CHALLENGE_NONCE_SIZE]; //The challenge nonce from ProvMsg2
  104. psvn_t equivalent_psvn; //The Equivalent PSVN which contains ISVN and Equivalent CPUSVN
  105. psvn_t previous_psvn; //an optional PSVN for Sigrl corresponding to previous EPID (if we upgrade TCB or performance rekey)
  106. fmsp_t fmsp; //fmsp passing in ProvMsg2 from Provisioning Backend server
  107. GroupID previous_gid; //optional previous_gid if previous_psvn is provided
  108. uint8_t old_epid_data_blob[HARD_CODED_EPID_BLOB_SIZE]; //optional old epid data blob corresponding to previous EPID
  109. uint8_t tcb_iv[IV_SIZE]; //The random IV to decode TIK
  110. uint8_t encrypted_tcb[SK_SIZE]; //It's TIK1, the aesm-gcm encrypted TIK by aes-gcm
  111. uint8_t tcb_mac[MAC_SIZE]; //The mac value to check the integrity of TIK1
  112. uint8_t is_previous_psvn_provided;//both previous_psvn and old_epid_data_blob should be provided if it is true and prev gid must be provided too
  113. }proc_prov_msg2_blob_input_t;
  114. #define HARD_CODED_JOIN_PROOF_WITH_ESCROW_TLV_SIZE (4+sizeof(join_proof_with_escrow_t))
  115. #define HARD_CODED_EPID_MEMBER_WITH_ESCROW_TLV_SIZE (4+sizeof(membertship_credential_with_escrow_t))
  116. //output information from PvE for AESM to generate ProvMsg3
  117. typedef struct _gen_prov_msg3_output_t{
  118. uint8_t field1_iv[IV_SIZE]; //The random generated IV for aes-gcm encryption of join proof and escrow data
  119. uint8_t field1_data[HARD_CODED_JOIN_PROOF_WITH_ESCROW_TLV_SIZE]; //The encrypted join proof and escrow data TLV by aes-gcm
  120. uint8_t field1_mac[MAC_SIZE]; //The corresponding mac value of previous encrypted data
  121. uint8_t epid_sig_iv[IV_SIZE]; //The random generated IV for aes-gcm encryption of EPIDSignature if available
  122. uint8_t epid_sig_mac[MAC_SIZE];//The corresponding mac value for encrypted EPIDSignature if available
  123. uint32_t epid_sig_output_size; //The size of EPIDSignature if available
  124. uint8_t is_join_proof_generated; //boolean value to tell whether join proof and escrow data is generated. The first three fields in this structure will be invalid if this field is false
  125. uint8_t is_epid_sig_generated; //boolean value to tell whether EpidSignature is generated
  126. //If it is false, the epid_sig_iv/mac/output_size are all invalid
  127. }gen_prov_msg3_output_t;
  128. //input information for PvE to decode data from ProvMsg4 and generate EPID Data Blob
  129. typedef struct _proc_prov_msg4_input_t{
  130. uint8_t tcb_iv[IV_SIZE]; //The random IV to decode TIK
  131. uint8_t encrypted_tcb[SK_SIZE]; //It's TIK1, the aes-gcm encrypted TIK by aes-gcm
  132. uint8_t tcb_mac[MAC_SIZE]; //The mac value to check the integrity of TIK1
  133. uint8_t member_credential_iv[IV_SIZE]; //The random IV to decode member credential and escrow data TLV
  134. uint8_t encrypted_member_credential[HARD_CODED_EPID_MEMBER_WITH_ESCROW_TLV_SIZE]; //The encrypted member credential and escrow data TLV by aes-gcm
  135. uint8_t member_credential_mac[MAC_SIZE]; //The mac value of previous field
  136. psvn_t equivalent_psvn; //An equivalent PSVN including ISVN and equivalent CPUSVN
  137. fmsp_t fmsp; //The fmsp from provisioning backend server
  138. signed_epid_group_cert_t group_cert;//ECDSA signed EPID Group Public Certificate from Intel decoded from ProvMsg4
  139. }proc_prov_msg4_input_t;
  140. //The EPID Data Blob generated by PvE in processing ProvMsg4 data
  141. typedef struct _proc_prov_msg4_output_t{
  142. uint8_t truested_epid_blob[HARD_CODED_EPID_BLOB_SIZE];
  143. }proc_prov_msg4_output_t;
  144. //output data of PvE to generate End Point Selection TLV
  145. typedef struct _gen_endpoint_selection_output_t{
  146. uint8_t xid[XID_SIZE];
  147. uint8_t selector_id;
  148. }gen_endpoint_selection_output_t;
  149. #pragma pack()
  150. #define PSVN_START_IN_DEVICE_ID sizeof(ppid_t)
  151. #define PPID_START_IN_DEVICE_ID 0
  152. #define FMSP_START_IN_DEVICE_ID (sizeof(ppid_t)+sizeof(psvn_t))
  153. #endif