sys-start-auth-session.int.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "tss2_sys.h"
  14. #define LOGMODULE test
  15. #include "util/log.h"
  16. #include "test.h"
  17. /*
  18. * This is an incredibly simple test to create the most simple session
  19. * (which ends up being a trial policy) and then just tear it down.
  20. */
  21. int
  22. test_invoke (TSS2_SYS_CONTEXT *sys_context)
  23. {
  24. TSS2_RC rc;
  25. TPM2B_NONCE nonce_caller = {
  26. .size = TPM2_SHA256_DIGEST_SIZE,
  27. .buffer = {
  28. 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
  29. 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
  30. 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
  31. 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef
  32. }
  33. };
  34. TPM2B_NONCE nonce_tpm = {
  35. .size = TPM2_SHA256_DIGEST_SIZE,
  36. .buffer = { 0 }
  37. };
  38. TPM2B_ENCRYPTED_SECRET encrypted_salt = { 0 };
  39. TPMI_SH_AUTH_SESSION session_handle = 0;
  40. TPMT_SYM_DEF symmetric = { .algorithm = TPM2_ALG_NULL };
  41. LOG_INFO("StartAuthSession for TPM2_SE_POLICY (policy session)");
  42. rc = Tss2_Sys_StartAuthSession (sys_context,
  43. TPM2_RH_NULL, /* tpmKey */
  44. TPM2_RH_NULL, /* bind */
  45. 0, /* cmdAuthsArray */
  46. &nonce_caller, /* nonceCaller */
  47. &encrypted_salt, /* encryptedSalt */
  48. TPM2_SE_POLICY, /* sessionType */
  49. &symmetric, /* symmetric */
  50. TPM2_ALG_SHA256, /* authHash */
  51. &session_handle, /* sessionHandle */
  52. &nonce_tpm, /* nonceTPM */
  53. 0 /* rspAuthsArray */
  54. );
  55. if (rc != TSS2_RC_SUCCESS) {
  56. LOG_ERROR("Tss2_Sys_StartAuthSession failed: 0x%" PRIx32, rc);
  57. exit(1);
  58. }
  59. LOG_INFO("StartAuthSession for TPM2_SE_POLICY success! Session handle: "
  60. "0x%" PRIx32, session_handle);
  61. /*
  62. * Clean out the session we've created. Would be nice if we didn't have
  63. * to do this ...
  64. */
  65. rc = Tss2_Sys_FlushContext (sys_context, session_handle);
  66. if (rc != TSS2_RC_SUCCESS) {
  67. LOG_ERROR("Tss2_Sys_FlushContext failed: 0x%" PRIx32, rc);
  68. exit(1);
  69. }
  70. LOG_INFO("Flushed context for session handle: 0x%" PRIx32 " success!",
  71. session_handle);
  72. return 0;
  73. }