esys-pp-commands.int.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "test-esys.h"
  12. #include "esys_iutil.h"
  13. #define LOGMODULE test
  14. #include "util/log.h"
  15. #include "util/aux_util.h"
  16. /** Test the ESYS function Esys_PP_Commands.
  17. *
  18. * If the test requires physical presence, the test is skipped.
  19. *
  20. *\b Note: platform authorization needed.
  21. *
  22. * Tested ESYS commands:
  23. * - Esys_PP_Commands() (O)
  24. *
  25. * @param[in,out] esys_context The ESYS_CONTEXT.
  26. * @retval EXIT_FAILURE
  27. * @retval EXIT_SKIP
  28. * @retval EXIT_SUCCESS
  29. */
  30. int
  31. test_esys_pp_commands(ESYS_CONTEXT * esys_context)
  32. {
  33. TSS2_RC r;
  34. int failure_return = EXIT_FAILURE;
  35. ESYS_TR auth_handle = ESYS_TR_RH_PLATFORM;
  36. TPML_CC setList = {
  37. .count = 1,
  38. .commandCodes = { TPM2_CC_PP_Commands }
  39. };
  40. TPML_CC clearList = {0};
  41. r = Esys_PP_Commands(esys_context, auth_handle,
  42. ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
  43. &setList, &clearList);
  44. if ((r == TPM2_RC_COMMAND_CODE) ||
  45. (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_RC_LAYER)) ||
  46. (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_TPM_RC_LAYER))) {
  47. LOG_WARNING("Command TPM2_PP_Commands not supported by TPM.");
  48. failure_return = EXIT_SKIP;
  49. }
  50. if (r == (TPM2_RC_WARN | TPM2_RC_PP)) {
  51. LOG_INFO("Command TPM2_PP_Commands requires physical presence.");
  52. return EXIT_SUCCESS;
  53. }
  54. if (number_rc(r) == TPM2_RC_BAD_AUTH) {
  55. /* Platform authorization not possible test will be skipped */
  56. LOG_WARNING("Platform authorization not possible.");
  57. failure_return = EXIT_SKIP;
  58. }
  59. goto_if_error(r, "Error: PP_Commands", error);
  60. return EXIT_SUCCESS;
  61. error:
  62. return failure_return;
  63. }
  64. int
  65. test_invoke_esys(ESYS_CONTEXT * esys_context) {
  66. return test_esys_pp_commands(esys_context);
  67. }