sys-evict-ctrl.int.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /***********************************************************************
  3. * Copyright (c) 2017-2018, Intel Corporation
  4. *
  5. * All rights reserved.
  6. ***********************************************************************/
  7. #ifdef HAVE_CONFIG_H
  8. #include <config.h>
  9. #endif
  10. #include "inttypes.h"
  11. #define LOGMODULE test
  12. #include "util/log.h"
  13. #include "sys-util.h"
  14. #include "test.h"
  15. int
  16. test_invoke (TSS2_SYS_CONTEXT *sys_context)
  17. {
  18. TSS2_RC rc = TPM2_RC_SUCCESS;
  19. TPM2_HANDLE primary_handle = 0;
  20. /* session parameters */
  21. /* command session info */
  22. TSS2L_SYS_AUTH_COMMAND sessions_cmd = {
  23. .auths = {{ .sessionHandle = TPM2_RH_PW }},
  24. .count = 1
  25. };
  26. /* response session info */
  27. TSS2L_SYS_AUTH_RESPONSE sessions_rsp = {
  28. .auths = { 0 },
  29. .count = 0
  30. };
  31. rc = create_primary_rsa_2048_aes_128_cfb (sys_context, &primary_handle);
  32. if (rc != TSS2_RC_SUCCESS) {
  33. LOG_INFO("failed to create primary: 0x%" PRIx32, rc);
  34. return 99; /* fatal error */
  35. }
  36. rc = Tss2_Sys_EvictControl (sys_context,
  37. TPM2_RH_OWNER,
  38. primary_handle,
  39. &sessions_cmd,
  40. 0x81000000,
  41. &sessions_rsp);
  42. if (rc != TSS2_RC_SUCCESS) {
  43. LOG_INFO("failed to make key 0x%" PRIx32 " persistent: 0x%" PRIx32,
  44. primary_handle, rc);
  45. return 1;
  46. }
  47. rc = Tss2_Sys_EvictControl (sys_context,
  48. TPM2_RH_OWNER,
  49. 0x81000000,
  50. &sessions_cmd,
  51. 0x81000000,
  52. &sessions_rsp);
  53. if (rc != TSS2_RC_SUCCESS) {
  54. LOG_INFO("failed to make key 0x%" PRIx32 " nonpersistent: 0x%" PRIx32,
  55. primary_handle, rc);
  56. return 1;
  57. }
  58. rc = Tss2_Sys_FlushContext(sys_context, primary_handle);
  59. if (rc != TSS2_RC_SUCCESS) {
  60. LOG_ERROR("Tss2_Sys_FlushContext failed with 0x%"PRIx32, rc);
  61. return 99; /* fatal error */
  62. }
  63. return 0;
  64. }