tpm2_auth_util.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #ifndef SRC_PASSWORD_UTIL_H_
  3. #define SRC_PASSWORD_UTIL_H_
  4. #include <tss2/tss2_esys.h>
  5. #include "tpm2_session.h"
  6. /**
  7. * Convert a password argument to a valid TPM2B_AUTH structure. Passwords can
  8. * be specified in two forms: string and hex-string and are identified by a
  9. * prefix of str: and hex: respectively. No prefix assumes the str form.
  10. *
  11. * For example, a string can be specified as:
  12. * "1234"
  13. * "str:1234"
  14. *
  15. * And a hexstring via:
  16. * "hex:1234abcd"
  17. *
  18. * Strings are copied verbatim to the TPM2B_AUTH buffer without the terminating NULL byte,
  19. * Hex strings differ only from strings in that they are converted to a byte array when
  20. * storing. At the end of storing, the size field is set to the size of bytes of the
  21. * password.
  22. *
  23. * If your password starts with a hex: prefix and you need to escape it, just use the string
  24. * prefix to escape it, like so:
  25. * "str:hex:password"
  26. *
  27. * @param ctx
  28. * Enhanced System API (ESAPI) context
  29. * @param password
  30. * The optarg containing the password string.
  31. * @param dest
  32. * The TPM2B_AUTH structure to copy the string into.
  33. * @ is_restricted
  34. * True if it is restricted to only password session data.
  35. * @return
  36. * tool_rc indicating status.
  37. */
  38. tool_rc tpm2_auth_util_from_optarg(ESYS_CONTEXT *ctx, const char *password,
  39. tpm2_session **session, bool is_restricted);
  40. /**
  41. * Set up authorisation for a handle and return a session handle for use in
  42. * ESAPI calls.
  43. *
  44. * @param ectx
  45. * Enhanced System API (ESAPI) context
  46. * @param for_auth
  47. * The target handle which needs authorization setting up
  48. * @param auth
  49. * Auth command for the handle
  50. * @param session
  51. * Session for the handle
  52. * @param handle
  53. * The output handle for the session
  54. * @return
  55. * A tool_rc indicating status.
  56. */
  57. tool_rc tpm2_auth_util_get_shandle(ESYS_CONTEXT *ectx, ESYS_TR for_auth,
  58. tpm2_session *session, ESYS_TR *handle);
  59. /**
  60. * Populate a string password in a TPM2B_AUTH structure.
  61. *
  62. * @param password
  63. * The string password or auth value.
  64. * @param auth
  65. * The TPM2B_AUTH structure to populate.
  66. * @return
  67. * Boolean indicating the success of the operation.
  68. */
  69. bool handle_str_password(const char *password, TPM2B_AUTH *auth);
  70. #endif /* SRC_PASSWORD_UTIL_H_ */