esys-pcr-auth-value.int.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*******************************************************************************
  3. * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG
  4. * All rights reserved.
  5. *******************************************************************************/
  6. #ifdef HAVE_CONFIG_H
  7. #include <config.h>
  8. #endif
  9. #include <stdlib.h>
  10. #include "tss2_esys.h"
  11. #include "esys_iutil.h"
  12. #include "test-esys.h"
  13. #define LOGMODULE test
  14. #include "util/log.h"
  15. #include "util/aux_util.h"
  16. /** Test the commands Esys_PCR_SetAuthValue and Esys_PCR_SetAuthPolicy.
  17. *
  18. *\b Note: platform authorization needed.
  19. *
  20. * Tested ESYS commands:
  21. * - Esys_PCR_SetAuthPolicy() (O)
  22. * - Esys_PCR_SetAuthValue() (O)
  23. *
  24. * @param[in,out] esys_context The ESYS_CONTEXT.
  25. * @retval EXIT_FAILURE
  26. * @retval EXIT_SKIP
  27. * @retval EXIT_SUCCESS
  28. */
  29. int
  30. test_esys_pcr_auth_value(ESYS_CONTEXT * esys_context)
  31. {
  32. TSS2_RC r;
  33. int failure_return = EXIT_FAILURE;
  34. /*
  35. * PCR register 20 belongs to the policy group and the auth value group.
  36. * PCRs of these groups can be used for SetAuthValue and SetAuthPolicy.
  37. */
  38. ESYS_TR pcrHandle_handle = 20;
  39. TPM2B_DIGEST auth = {
  40. .size = 20,
  41. .buffer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  42. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
  43. };
  44. r = Esys_PCR_SetAuthValue(
  45. esys_context,
  46. pcrHandle_handle,
  47. ESYS_TR_PASSWORD,
  48. ESYS_TR_NONE,
  49. ESYS_TR_NONE,
  50. &auth
  51. );
  52. if ((r == TPM2_RC_COMMAND_CODE) ||
  53. (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_RC_LAYER)) ||
  54. (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_TPM_RC_LAYER))) {
  55. LOG_WARNING("Command TPM2_PCR_SetAuthValue not supported by TPM.");
  56. failure_return = EXIT_SKIP;
  57. goto error;
  58. }
  59. goto_if_error(r, "Error: PCR_SetAuthValue", error);
  60. TPM2B_DIGEST authPolicy = {
  61. .size = 32,
  62. .buffer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11, 12, 13, 14, 15, 16, 17,
  63. 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }
  64. };
  65. r = Esys_PCR_SetAuthPolicy(
  66. esys_context,
  67. ESYS_TR_RH_PLATFORM,
  68. ESYS_TR_PASSWORD,
  69. ESYS_TR_NONE,
  70. ESYS_TR_NONE,
  71. &authPolicy,
  72. TPM2_ALG_SHA256,
  73. pcrHandle_handle);
  74. if (number_rc(r) == TPM2_RC_BAD_AUTH) {
  75. /* Platform authorization not possible test will be skipped */
  76. LOG_WARNING("Platform authorization not possible.");
  77. failure_return = EXIT_SKIP;
  78. }
  79. goto_if_error(r, "Error: PCR_SetAuthPolicy", error);
  80. return EXIT_SUCCESS;
  81. error:
  82. return failure_return;
  83. }
  84. int
  85. test_invoke_esys(ESYS_CONTEXT * esys_context) {
  86. return test_esys_pcr_auth_value(esys_context);
  87. }