blob: a62648d48df2ee063e8dd007687cd50584c11050 [file] [log] [blame]
Philip Triccaf8915802017-03-14 17:01:50 -07001#include <inttypes.h>
2#include <stdio.h>
Philip Tricca910f17c2018-03-15 12:38:37 -07003#include <stdlib.h>
Philip Triccaf8915802017-03-14 17:01:50 -07004
Philip Tricca910f17c2018-03-15 12:38:37 -07005#include "tss2_sys.h"
Philip Triccaf8915802017-03-14 17:01:50 -07006
Andreas Fuchs78a49582018-01-03 14:37:16 +01007#define LOGMODULE test
Philip Triccaa7c51ce2018-03-10 18:28:25 -08008#include "util/log.h"
Philip Triccaf8915802017-03-14 17:01:50 -07009#include "test.h"
10/*
11 * This is an incredibly simple test to create the most simple session
12 * (which ends up being a trial policy) and then just tear it down.
13 */
14int
15test_invoke (TSS2_SYS_CONTEXT *sapi_context)
16{
17 TSS2_RC rc;
18 TPM2B_NONCE nonce_caller = {
Andreas Fuchsbe5899d2017-11-13 17:14:36 +010019 .size = TPM2_SHA256_DIGEST_SIZE,
Tadeusz Struka64c33e2017-11-01 16:12:10 -070020 .buffer = {
Philip Triccaf8915802017-03-14 17:01:50 -070021 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
22 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
23 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
24 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef
25 }
Philip Triccaf8915802017-03-14 17:01:50 -070026 };
27 TPM2B_NONCE nonce_tpm = {
Andreas Fuchsbe5899d2017-11-13 17:14:36 +010028 .size = TPM2_SHA256_DIGEST_SIZE,
Tadeusz Struka64c33e2017-11-01 16:12:10 -070029 .buffer = { 0 }
Philip Triccaf8915802017-03-14 17:01:50 -070030 };
31 TPM2B_ENCRYPTED_SECRET encrypted_salt = { 0 };
32 TPMI_SH_AUTH_SESSION session_handle = 0;
Andreas Fuchsbe5899d2017-11-13 17:14:36 +010033 TPMT_SYM_DEF symmetric = { .algorithm = TPM2_ALG_NULL };
Philip Triccaf8915802017-03-14 17:01:50 -070034
Andreas Fuchs78a49582018-01-03 14:37:16 +010035 LOG_INFO("StartAuthSession for TPM2_SE_POLICY (policy session)");
Philip Triccaf8915802017-03-14 17:01:50 -070036 rc = Tss2_Sys_StartAuthSession (sapi_context,
Andreas Fuchsbe5899d2017-11-13 17:14:36 +010037 TPM2_RH_NULL, /* tpmKey */
38 TPM2_RH_NULL, /* bind */
Philip Triccaf8915802017-03-14 17:01:50 -070039 0, /* cmdAuthsArray */
40 &nonce_caller, /* nonceCaller */
41 &encrypted_salt, /* encryptedSalt */
Andreas Fuchsbe5899d2017-11-13 17:14:36 +010042 TPM2_SE_POLICY, /* sessionType */
Philip Triccaf8915802017-03-14 17:01:50 -070043 &symmetric, /* symmetric */
Andreas Fuchsbe5899d2017-11-13 17:14:36 +010044 TPM2_ALG_SHA256, /* authHash */
Philip Triccaf8915802017-03-14 17:01:50 -070045 &session_handle, /* sessionHandle */
46 &nonce_tpm, /* nonceTPM */
47 0 /* rspAuthsArray */
48 );
Andreas Fuchs78a49582018-01-03 14:37:16 +010049 if (rc != TSS2_RC_SUCCESS) {
50 LOG_ERROR("Tss2_Sys_StartAuthSession failed: 0x%" PRIx32, rc);
51 exit(1);
52 }
53 LOG_INFO("StartAuthSession for TPM2_SE_POLICY success! Session handle: "
Philip Triccaf8915802017-03-14 17:01:50 -070054 "0x%" PRIx32, session_handle);
55 /*
56 * Clean out the session we've created. Would be nice if we didn't have
57 * to do this ...
58 */
59 rc = Tss2_Sys_FlushContext (sapi_context, session_handle);
Andreas Fuchs78a49582018-01-03 14:37:16 +010060 if (rc != TSS2_RC_SUCCESS) {
61 LOG_ERROR("Tss2_Sys_FlushContext failed: 0x%" PRIx32, rc);
62 exit(1);
63 }
64 LOG_INFO("Flushed context for session handle: 0x%" PRIx32 " success!",
Philip Triccaf8915802017-03-14 17:01:50 -070065 session_handle);
66
67 return 0;
68}