tpm2_policy.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #ifndef TPM2_POLICY_H_
  3. #define TPM2_POLICY_H_
  4. #include <stdbool.h>
  5. #include <tss2/tss2_esys.h>
  6. #include "object.h"
  7. #include "tpm2_session.h"
  8. /**
  9. * Build a PCR policy via PolicyPCR.
  10. * @param context
  11. * The Enhanced System API (ESAPI) context.
  12. * @param policy_session
  13. * A session started with tpm2_session_new().
  14. * @param raw_pcrs_file
  15. * The a file output from tpm2_pcrread -o option. Optional, can be NULL.
  16. * If NULL, the PCR values are read via the pcr_selection value.
  17. * @param pcr_selections
  18. * The pcr selections to use when building the pcr policy. It follows the PCR selection
  19. * specifications in the man page for tpm2_listpcrs. If using a raw_pcrs_file, this spec
  20. * must be the same as supplied to tpm2_listpcrs.
  21. * @return
  22. * tool_rc indicating status.
  23. */
  24. tool_rc tpm2_policy_build_pcr(ESYS_CONTEXT *context,
  25. tpm2_session *policy_session, const char *raw_pcrs_file,
  26. TPML_PCR_SELECTION *pcr_selections, TPM2B_DIGEST *raw_pcr_digest);
  27. /**
  28. * Enables a signing authority to authorize policies
  29. * @param ectx
  30. * The Enhanced system api context
  31. * @param policy_session
  32. * The policy session that has the policy digest to be authorized
  33. * @param policy_digest_path
  34. * The policy digest file that needs to be authorized by signing authority
  35. * @param policy_qualifier
  36. * The policy qualifier data that concatenates with approved policies. Can be
  37. * either a path to a file or a hex string.
  38. * @param verifying_pubkey_name_path
  39. * The name of the public key that verifies the signature of the signer
  40. * @param ticket_path
  41. * The verification ticket generated when TPM verifies the signature
  42. * @return
  43. * tool_rc indicating status.
  44. */
  45. tool_rc tpm2_policy_build_policyauthorize(ESYS_CONTEXT *ectx,
  46. tpm2_session *policy_session, const char *policy_digest_path,
  47. const char *policy_qualifier,
  48. const char *verifying_pubkey_name_path, const char *ticket_path);
  49. /**
  50. * Compounds policies in an OR fashion
  51. *
  52. * @param ectx
  53. * The Enhanced system api context
  54. * @param policy_session
  55. * The policy session into which the policy digest is extended into
  56. * @param policy_list
  57. * The list of policy policy digests
  58. *
  59. * @return
  60. * tool_rc indicating status.
  61. */
  62. tool_rc tpm2_policy_build_policyor(ESYS_CONTEXT *ectx,
  63. tpm2_session *policy_session, TPML_DIGEST *policy_list);
  64. /**
  65. * Evaluates an authorization for specific named objects.
  66. *
  67. * @param ectx
  68. * The Enhanced system api context
  69. * @param session
  70. * The policy session into which the policy digest is extended into
  71. * @param name_hash
  72. * The name hash
  73. *
  74. * @return
  75. * tool_rc indicating status.
  76. */
  77. tool_rc tpm2_policy_build_policynamehash(ESYS_CONTEXT *ectx,
  78. tpm2_session *session, const TPM2B_DIGEST *name_hash);
  79. /**
  80. * Evaluates an authorization for object's public template data digest.
  81. *
  82. * @param ectx
  83. * The Enhanced system api context
  84. * @param session
  85. * The policy session into which the policy digest is extended into
  86. * @param template_hash
  87. * The public template hash
  88. *
  89. * @return
  90. * tool_rc indicating status.
  91. */
  92. tool_rc tpm2_policy_build_policytemplate(ESYS_CONTEXT *ectx,
  93. tpm2_session *session, const TPM2B_DIGEST *template_hash);
  94. /**
  95. * Evaluates an authorization for object's command parameter digest.
  96. *
  97. * @param ectx
  98. * The Enhanced system api context
  99. * @param session
  100. * The policy session into which the policy digest is extended into
  101. * @param cphash
  102. * The command parameter hash
  103. *
  104. * @return
  105. * tool_rc indicating status.
  106. */
  107. tool_rc tpm2_policy_build_policycphash(ESYS_CONTEXT *ectx,
  108. tpm2_session *session, const TPM2B_DIGEST *cphash);
  109. /**
  110. * Enables secret (password/hmac) based authorization to a policy.
  111. *
  112. * @param ectx
  113. * The Enhanced system api (ESAPI) context
  114. * @param policy_session into which the policy digest is extended into
  115. * The policy session
  116. * @param[in] secret_session
  117. * The secret authentication data to update the policy session with.
  118. * Must be a password session.
  119. * @param[in] handle
  120. * The handle-id of the authentication object
  121. *
  122. * @return
  123. * tool_rc indicating status.
  124. */
  125. tool_rc tpm2_policy_build_policysecret(ESYS_CONTEXT *ectx,
  126. tpm2_session *policy_session, tpm2_loaded_object *auth_entity_obj,
  127. INT32 expiration, TPMT_TK_AUTH **policy_ticket,
  128. TPM2B_TIMEOUT **timeout, bool is_nonce_tpm,
  129. const char *policy_qualifier_path, TPM2B_DIGEST *cp_hash);
  130. /**
  131. * Retrieves the policy digest for a session via PolicyGetDigest.
  132. * @param context
  133. * The Enhanced System API (ESAPI) context.
  134. * @param session
  135. * The session whose digest to query.
  136. * @param policy_digest
  137. * The retrieved digest, only valid on true returns.
  138. * @return
  139. * tool_rc indicating status.
  140. */
  141. tool_rc tpm2_policy_get_digest(ESYS_CONTEXT *context, tpm2_session *session,
  142. TPM2B_DIGEST **policy_digest);
  143. /**
  144. * Enables a policy that requires the object's authentication passphrase be
  145. * provided.
  146. * @param ectx
  147. * The Enhanced system api (ESAPI_) context.
  148. * @param session
  149. * The policy session which is extended with PolicyPassword command code
  150. * @return
  151. * tool_rc indicating status.
  152. */
  153. tool_rc tpm2_policy_build_policypassword(ESYS_CONTEXT *ectx,
  154. tpm2_session *session);
  155. /**
  156. * Enables a policy that requires the object's authvalue be provided.
  157. * The authvalue can be transmitted as an HMAC
  158. * @param ectx
  159. * The Enhanced system api (ESAPI_) context.
  160. * @param session
  161. * The policy session which is extended with PolicyAuthValue command code
  162. * @return
  163. * tool_rc indicating status.
  164. */
  165. tool_rc tpm2_policy_build_policyauthvalue(ESYS_CONTEXT *ectx,
  166. tpm2_session *session);
  167. /**
  168. * Enables a policy authorization by virtue of verifying a signature on optional
  169. * TPM2 parameters data - nonceTPM, cphashA, policyRef, expiration
  170. * @param ectx
  171. * The Enhanced system api (ESAPI) context
  172. * @param session
  173. * The policy session which is extended with PolicySigned command code
  174. * @param auth_entity_obj
  175. * The loaded TPM2 key object public portion used for signature verification
  176. * @param signature
  177. * The signature of the optional TPM2 parameters
  178. */
  179. tool_rc tpm2_policy_build_policysigned(ESYS_CONTEXT *ectx,
  180. tpm2_session *policy_session, tpm2_loaded_object *auth_entity_obj,
  181. TPMT_SIGNATURE *signature, INT32 expiration, TPM2B_TIMEOUT **timeout,
  182. TPMT_TK_AUTH **policy_ticket, const char *policy_qualifier_path,
  183. bool is_nonce_tpm, const char *raw_data_path,
  184. const char *cphash_path);
  185. /**
  186. * PolicyTicket assertion enables proxy authentication for either PolicySecret
  187. * or PolicySigned once the specific policy is validated.
  188. *
  189. * @param ectx
  190. * The Enhanced system api (ESAPI) context
  191. * @param session
  192. * The policy session which is being extended
  193. * @param policy_timeout_path
  194. * The file containing the timeout data generated PolicySigned/ PolicySecret
  195. * @param qualifier_data_path
  196. * The file containing the qualifier data or policyRef
  197. * @param policy_ticket_path
  198. * The file containing the auth ticket
  199. * @param auth_name_file
  200. * The auth name file containing the name of the auth object
  201. *
  202. * @return { description_of_the_return_value }
  203. */
  204. tool_rc tpm2_policy_build_policyticket(ESYS_CONTEXT *ectx,
  205. tpm2_session *policy_session, char *policy_timeout_path,
  206. const char *qualifier_data_path, char *policy_ticket_path,
  207. const char *auth_name_file);
  208. /**
  209. * Parses the policy digest algorithm for the list of policies specified
  210. *
  211. * @param str
  212. * The string specifying the policy digest algorithm and list of policies
  213. * @param policy_list
  214. * The policy list structure that records all the policies from policy list
  215. * @return
  216. * true on success, false otherwise.
  217. */
  218. bool tpm2_policy_parse_policy_list(char *str, TPML_DIGEST *policy_list);
  219. /**
  220. * Policy to restrict tpm object authorization to specific commands
  221. *
  222. * @param ectx
  223. * The Enhanced system api (ESAPI_) context.
  224. * @param policy_session
  225. * The policy session into which the policy digest is extended into
  226. * @param command_code
  227. * The command code of the command authorized to use the object
  228. * @return
  229. * A tool_rc indicating status.
  230. */
  231. tool_rc tpm2_policy_build_policycommandcode(ESYS_CONTEXT *ectx,
  232. tpm2_session *session, uint32_t command_code);
  233. /**
  234. * Policy to restrict authorization to written state of the NV Index
  235. *
  236. * @param ectx
  237. * The Enhanced system api (ESAPI_) context.
  238. * @param policy_session
  239. * The policy session into which the policy digest is extended into
  240. * @param written_set
  241. * SET/ CLEAR TPMI_YES_NO value of the expected written state of NV index
  242. * @return
  243. * A tool_rc indicating status.
  244. */
  245. tool_rc tpm2_policy_build_policynvwritten(ESYS_CONTEXT *ectx,
  246. tpm2_session *session, TPMI_YES_NO written_set);
  247. /**
  248. * Policy to restrict tpm object authorization to specific locality
  249. *
  250. * @param ectx
  251. * The Enhanced system api (ESAPI_) context.
  252. * @param policy_session
  253. * The policy session into which the policy digest is extended into
  254. * @param locality
  255. * The locality of the command authorized to use the object
  256. * @return
  257. * A tool_rc indicating status.
  258. */
  259. tool_rc tpm2_policy_build_policylocality(ESYS_CONTEXT *ectx,
  260. tpm2_session *session, TPMA_LOCALITY locality);
  261. /**
  262. * Policy to restrict tpm object authorization to specific duplication target
  263. *
  264. * @param ectx
  265. * The Enhanced system api (ESAPI_) context.
  266. * @param policy_session
  267. * The policy session into which the policy digest is extended into
  268. * @param obj_name_path
  269. * The name of the tpm object to be duplicated
  270. * @param new_parent_name_path
  271. * The name of the new parent to which the object is duplicated
  272. * @param is_include_obj
  273. * the flag indicating whether object name is included in policyDigest
  274. * @return
  275. * A tool_rc indicating status.
  276. */
  277. tool_rc tpm2_policy_build_policyduplicationselect(ESYS_CONTEXT *ectx,
  278. tpm2_session *session, const char *obj_name_path,
  279. const char *new_parent_name_path, TPMI_YES_NO is_include_obj);
  280. /**
  281. * Policy tools need to:
  282. * - get the policy digest
  283. * - print the policy digest
  284. * - optionally save the digest to a file
  285. * This routine serves a common helper so all policy tools
  286. * behave in the same way.
  287. * @param ectx
  288. * The Enhanced system api (ESAPI_) context.
  289. * @param session
  290. * The policy session to get the digest of.
  291. * @param save_path
  292. * The path to optionally save the digest too.
  293. * @return
  294. * A tool_rc indicating status.
  295. */
  296. tool_rc tpm2_policy_tool_finish(ESYS_CONTEXT *ectx, tpm2_session *session,
  297. const char *save_path);
  298. #endif /* TPM2_POLICY_H_ */