file_parser.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*############################################################################
  2. # Copyright 2016-2017 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /*!
  17. * \file
  18. * \brief Intel(R) EPID issuer material parsing utilities.
  19. */
  20. #ifndef EPID_COMMON_FILE_PARSER_H_
  21. #define EPID_COMMON_FILE_PARSER_H_
  22. #include <stddef.h>
  23. #include "epid/common/errors.h"
  24. #include "epid/common/types.h"
  25. /// Parser for issuer material
  26. /*!
  27. \defgroup FileParser fileparser
  28. Provides an API for parsing buffers formatted according to the
  29. various IoT Intel(R) EPID binary file formats.
  30. To use this module, include the header epid/common/file_parser.h.
  31. \ingroup EpidCommon
  32. @{
  33. */
  34. /// Recognized Intel(R) EPID versions
  35. typedef enum EpidVersion {
  36. kEpid1x, ///< Intel(R) EPID version 1.x
  37. kEpid2x, ///< Intel(R) EPID version 2.x
  38. kNumEpidVersions, ///< Maximum number of versions
  39. } EpidVersion;
  40. /// Encoding of issuer material Intel(R) EPID versions
  41. extern const OctStr16 kEpidVersionCode[kNumEpidVersions];
  42. /// Recognized Intel(R) EPID file types
  43. typedef enum EpidFileType {
  44. kIssuingCaPubKeyFile, ///< IoT Issuing CA public key file
  45. kGroupPubKeyFile, ///< Group Public Key Output File Format
  46. kPrivRlFile, ///< Binary Private Key Revocation List
  47. kSigRlFile, ///< Binary Signature Revocation List
  48. kGroupRlFile, ///< Binary Group Revocation List
  49. kPrivRlRequestFile, ///< Binary Private Key Revocation Request
  50. kSigRlRequestFile, ///< Binary Signature Revocation Request
  51. kGroupRlRequestFile, ///< Binary Group Revocation Request
  52. kNumFileTypes, ///< Maximum number of file types
  53. } EpidFileType;
  54. /// Encoding of issuer material file types
  55. extern const OctStr16 kEpidFileTypeCode[kNumFileTypes];
  56. #pragma pack(1)
  57. /// Intel(R) EPID binary file header
  58. typedef struct EpidFileHeader {
  59. OctStr16 epid_version; ///< Intel(R) EPID Version
  60. OctStr16 file_type; ///< File Type
  61. } EpidFileHeader;
  62. /// IoT CA Certificate binary format
  63. typedef struct EpidCaCertificate {
  64. EpidFileHeader header; ///< Intel(R) EPID binary file header
  65. OctStr512 pubkey; ///< Public Key (Qx, Qy)
  66. OctStr256 prime; ///< Prime of GF(p)
  67. OctStr256 a; ///< Coefficient of E Curve
  68. OctStr256 b; ///< Coefficient of E Curve
  69. OctStr256 x; ///< X coordinate of Base point G
  70. OctStr256 y; ///< Y coordinate of Base point G
  71. OctStr256 r; ///< Order of base point
  72. EcdsaSignature signature; ///< ECDSA Signature on SHA-256 of above values
  73. } EpidCaCertificate;
  74. #pragma pack()
  75. /// Extracts Intel(R) EPID Binary Output File header information
  76. /*!
  77. \param[in] buf
  78. Pointer to buffer containing Intel(R) EPID Binary Output File to parse.
  79. \param[in] len
  80. The size of buf in bytes.
  81. \param[out] epid_version
  82. The extracted Intel(R) EPID version or kNumEpidVersions if Intel(R) EPID
  83. version is unknown. Pass NULL to not extract.
  84. \param[out] file_type
  85. The extracted Intel(R) EPID file type or kNumFileTypes if file type is
  86. unknown. Pass NULL to not extract.
  87. \returns ::EpidStatus
  88. */
  89. EpidStatus EpidParseFileHeader(void const* buf, size_t len,
  90. EpidVersion* epid_version,
  91. EpidFileType* file_type);
  92. /// Extracts group public key from buffer in issuer binary format
  93. /*!
  94. Extracts the first group public key from a buffer with format of
  95. Intel(R) EPID 2.0 Group Public Key Certificate Binary File. The
  96. function validates that the first public key was signed by the
  97. private key corresponding to the provided CA certificate and the
  98. size of the input buffer is correct.
  99. \warning
  100. It is the responsibility of the caller to authenticate the
  101. EpidCaCertificate.
  102. \param[in] buf
  103. Pointer to buffer containing public key to extract.
  104. \param[in] len
  105. The size of buf in bytes.
  106. \param[in] cert
  107. The issuing CA public key certificate.
  108. \param[out] pubkey
  109. The extracted group public key.
  110. \returns ::EpidStatus
  111. \retval ::kEpidSigInvalid
  112. Parsing failed due to data authentication failure.
  113. \b Examples
  114. \ref UserManual_GeneratingAnIntelEpidSignature
  115. */
  116. EpidStatus EpidParseGroupPubKeyFile(void const* buf, size_t len,
  117. EpidCaCertificate const* cert,
  118. GroupPubKey* pubkey);
  119. /// Extracts private key revocation list from buffer in issuer binary format
  120. /*!
  121. Extracts the private key revocation list from a buffer with format of
  122. Binary Private Key Revocation List File. The function
  123. validates that the revocation list was signed by the private
  124. key corresponding to the provided CA certificate and the size of the
  125. input buffer is correct.
  126. To determine the required size of the revocation list output buffer,
  127. provide a null pointer for the output buffer.
  128. \warning
  129. It is the responsibility of the caller to authenticate the
  130. EpidCaCertificate.
  131. \param[in] buf
  132. Pointer to buffer containing the revocation list to extract.
  133. \param[in] len
  134. The size of buf in bytes.
  135. \param[in] cert
  136. The issuing CA public key certificate.
  137. \param[out] rl
  138. The extracted revocation list. If Null, rl_len is filled with
  139. the required output buffer size.
  140. \param[in,out] rl_len
  141. The size of rl in bytes.
  142. \returns ::EpidStatus
  143. \retval ::kEpidSigInvalid
  144. Parsing failed due to data authentication failure.
  145. \b Example
  146. \ref UserManual_VerifyingAnIntelEpidSignature
  147. */
  148. EpidStatus EpidParsePrivRlFile(void const* buf, size_t len,
  149. EpidCaCertificate const* cert, PrivRl* rl,
  150. size_t* rl_len);
  151. /// Extracts signature revocation list from buffer in issuer binary format
  152. /*!
  153. Extracts the signature based revocation list from a buffer with
  154. format of Binary Signature Revocation List File. The function
  155. validates that the revocation list was signed by the private key
  156. corresponding to the provided CA certificate and the size of the
  157. input buffer is correct.
  158. To determine the required size of the revocation list output buffer,
  159. provide a null pointer for the output buffer.
  160. \warning
  161. It is the responsibility of the caller to authenticate the
  162. EpidCaCertificate.
  163. \param[in] buf
  164. Pointer to buffer containing the revocation list to extract.
  165. \param[in] len
  166. The size of buf in bytes.
  167. \param[in] cert
  168. The issuing CA public key certificate.
  169. \param[out] rl
  170. The extracted revocation list. If Null, rl_len is filled with
  171. the required output buffer size.
  172. \param[in,out] rl_len
  173. The size of rl in bytes.
  174. \returns ::EpidStatus
  175. \retval ::kEpidSigInvalid
  176. Parsing failed due to data authentication failure.
  177. \b Examples
  178. \ref UserManual_GeneratingAnIntelEpidSignature
  179. */
  180. EpidStatus EpidParseSigRlFile(void const* buf, size_t len,
  181. EpidCaCertificate const* cert, SigRl* rl,
  182. size_t* rl_len);
  183. /// Extracts group revocation list from buffer in issuer binary format
  184. /*!
  185. Extracts the group revocation list from a buffer with format of
  186. Binary Group Certificate Revocation List File. The function
  187. validates that the revocation list was signed by the private key
  188. corresponding to the provided CA certificate and the size of the
  189. input buffer is correct.
  190. To determine the required size of the revocation list output buffer,
  191. provide a null pointer for the output buffer.
  192. \warning
  193. It is the responsibility of the caller to authenticate the
  194. EpidCaCertificate.
  195. \param[in] buf
  196. Pointer to buffer containing the revocation list to extract.
  197. \param[in] len
  198. The size of buf in bytes.
  199. \param[in] cert
  200. The issuing CA public key certificate.
  201. \param[out] rl
  202. The extracted revocation list. If Null, rl_len is filled with
  203. the required output buffer size.
  204. \param[in,out] rl_len
  205. The size of rl in bytes.
  206. \returns ::EpidStatus
  207. \retval ::kEpidSigInvalid
  208. Parsing failed due to data authentication failure.
  209. \b Example
  210. \ref UserManual_VerifyingAnIntelEpidSignature
  211. */
  212. EpidStatus EpidParseGroupRlFile(void const* buf, size_t len,
  213. EpidCaCertificate const* cert, GroupRl* rl,
  214. size_t* rl_len);
  215. /*!
  216. @}
  217. */
  218. #endif // EPID_COMMON_FILE_PARSER_H_