fapi-second-provisioning.int.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_fapi.h"
  11. #include "tss2_esys.h"
  12. #include "test-fapi.h"
  13. #include "fapi_util.h"
  14. #include "fapi_int.h"
  15. #include "tss2_esys.h"
  16. #include "esys_iutil.h"
  17. #define LOGMODULE test
  18. #include "util/log.h"
  19. #include "util/aux_util.h"
  20. #include "tss2_mu.h"
  21. #include "fapi_int.h"
  22. #define PASSWORD "abc"
  23. static TSS2_RC
  24. auth_callback(
  25. char const *objectPath,
  26. char const *description,
  27. const char **auth,
  28. void *userData)
  29. {
  30. UNUSED(description);
  31. UNUSED(userData);
  32. if (!objectPath) {
  33. return_error(TSS2_FAPI_RC_BAD_VALUE, "No path.");
  34. }
  35. *auth = PASSWORD;
  36. return TSS2_RC_SUCCESS;
  37. }
  38. /** Test the FAPI provisioning with passwords already set for endorsement and
  39. * owner hierarchy.
  40. *
  41. * Tested FAPI commands:
  42. * - Fapi_Provision()
  43. * - Fapi_SetAuthCB()
  44. * - Fapi_ChangeAuth()
  45. * - Fapi_Delete()
  46. *
  47. * @param[in,out] context The FAPI_CONTEXT.
  48. * @retval EXIT_FAILURE
  49. * @retval EXIT_SUCCESS
  50. */
  51. int
  52. test_fapi_test_second_provisioning(FAPI_CONTEXT *context)
  53. {
  54. TSS2_RC r;
  55. /* We need to reset the passwords again, in order to not brick physical TPMs */
  56. r = Fapi_Provision(context, PASSWORD, PASSWORD, NULL);
  57. goto_if_error(r, "Error Fapi_Provision", error);
  58. r = pcr_reset(context, 16);
  59. goto_if_error(r, "Error pcr_reset", error);
  60. r = Fapi_SetAuthCB(context, auth_callback, NULL);
  61. goto_if_error(r, "Error SetPolicyAuthCallback", error);
  62. goto_if_error(r, "Error Fapi_NV_Undefine", error);
  63. Fapi_Finalize(&context);
  64. int rc = init_fapi("P_RSA2", &context);
  65. if (rc)
  66. goto error;
  67. /* Authentication should not work due to auth for hierarchy was set. */
  68. r = Fapi_Provision(context, NULL, NULL, NULL);
  69. if (r == TSS2_RC_SUCCESS) {
  70. goto_if_error(r, "Wrong authentication.", error);
  71. }
  72. if (r != TSS2_FAPI_RC_AUTHORIZATION_UNKNOWN) {
  73. goto_if_error(r, "Wrong check auth value.", error);
  74. }
  75. /* Correct Provisioning with auth value for hierarchy from previous
  76. provisioning. The information whether a auth value is needed
  77. will be taken from hierarchy object of first provisioning. */
  78. r = Fapi_SetAuthCB(context, auth_callback, NULL);
  79. goto_if_error(r, "Error SetPolicyAuthCallback", error);
  80. r = Fapi_Provision(context, NULL, NULL, NULL);
  81. goto_if_error(r, "Error Fapi_Provision", error);
  82. r = Fapi_Delete(context, "/");
  83. goto_if_error(r, "Error Fapi_Delete", error);
  84. Fapi_Finalize(&context);
  85. rc = init_fapi("P_RSA2", &context);
  86. if (rc)
  87. goto error;
  88. /* Correct Provisioning with auth value for hierarchy from previous
  89. provisioning. Non information whether auth value is needed is
  90. available. */
  91. r = Fapi_SetAuthCB(context, auth_callback, NULL);
  92. goto_if_error(r, "Error SetPolicyAuthCallback", error);
  93. r = Fapi_Provision(context, NULL, NULL, NULL);
  94. goto_if_error(r, "Error Fapi_Provision", error);
  95. /* We need to reset the passwords again, in order to not brick physical TPMs */
  96. r = Fapi_ChangeAuth(context, "/HS", NULL);
  97. goto_if_error(r, "Error Fapi_ChangeAuth", error);
  98. r = Fapi_ChangeAuth(context, "/HE", NULL);
  99. goto_if_error(r, "Error Fapi_ChangeAuth", error);
  100. r = Fapi_Delete(context, "/");
  101. goto_if_error(r, "Error Fapi_Delete", error);
  102. Fapi_Finalize(&context);
  103. rc = init_fapi("P_ECC_sh_eh_policy", &context);
  104. if (rc)
  105. goto error;
  106. /* A policy will be assigned to owner and endorsement hierarchy. */
  107. r = Fapi_Provision(context, NULL, NULL, NULL);
  108. goto_if_error(r, "Error Fapi_Provision", error);
  109. Fapi_Finalize(&context);
  110. rc = init_fapi("P_ECC", &context);
  111. if (rc)
  112. goto error;
  113. /* Owner and endorsement hierarchy will be authorized via policy and
  114. policy will be reset. */
  115. r = Fapi_Provision(context, NULL, NULL, NULL);
  116. goto_if_error(r, "Error Fapi_Provision", error);
  117. Fapi_Delete(context, "/");
  118. return EXIT_SUCCESS;
  119. error:
  120. Fapi_Delete(context, "/");
  121. return EXIT_FAILURE;
  122. }
  123. int
  124. test_invoke_fapi(FAPI_CONTEXT *fapi_context)
  125. {
  126. return test_fapi_test_second_provisioning(fapi_context);
  127. }