blob: 0af2b6f160a7967f67f7c3274c637dc4a1d204db [file] [log] [blame]
Philip Triccaf8915802017-03-14 17:01:50 -07001#include <inttypes.h>
2#include <stdio.h>
3
4#include "sapi/tpm20.h"
5
6#include "log.h"
7#include "test.h"
8/*
9 * This is an incredibly simple test to create the most simple session
10 * (which ends up being a trial policy) and then just tear it down.
11 */
12int
13test_invoke (TSS2_SYS_CONTEXT *sapi_context)
14{
15 TSS2_RC rc;
16 TPM2B_NONCE nonce_caller = {
Tadeusz Struka64c33e2017-11-01 16:12:10 -070017 .size = SHA256_DIGEST_SIZE,
18 .buffer = {
Philip Triccaf8915802017-03-14 17:01:50 -070019 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
20 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
21 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
22 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef
23 }
Philip Triccaf8915802017-03-14 17:01:50 -070024 };
25 TPM2B_NONCE nonce_tpm = {
Tadeusz Struka64c33e2017-11-01 16:12:10 -070026 .size = SHA256_DIGEST_SIZE,
27 .buffer = { 0 }
Philip Triccaf8915802017-03-14 17:01:50 -070028 };
29 TPM2B_ENCRYPTED_SECRET encrypted_salt = { 0 };
30 TPMI_SH_AUTH_SESSION session_handle = 0;
31 TPMT_SYM_DEF symmetric = { .algorithm = TPM_ALG_NULL };
32
33 print_log ("StartAuthSession for TPM_SE_POLICY (policy session)");
34 rc = Tss2_Sys_StartAuthSession (sapi_context,
35 TPM_RH_NULL, /* tpmKey */
36 TPM_RH_NULL, /* bind */
37 0, /* cmdAuthsArray */
38 &nonce_caller, /* nonceCaller */
39 &encrypted_salt, /* encryptedSalt */
40 TPM_SE_POLICY, /* sessionType */
41 &symmetric, /* symmetric */
42 TPM_ALG_SHA256, /* authHash */
43 &session_handle, /* sessionHandle */
44 &nonce_tpm, /* nonceTPM */
45 0 /* rspAuthsArray */
46 );
47 if (rc != TSS2_RC_SUCCESS)
48 print_fail ("Tss2_Sys_StartAuthSession failed: 0x%" PRIx32, rc);
49 print_log ("StartAuthSession for TPM_SE_POLICY success! Session handle: "
50 "0x%" PRIx32, session_handle);
51 /*
52 * Clean out the session we've created. Would be nice if we didn't have
53 * to do this ...
54 */
55 rc = Tss2_Sys_FlushContext (sapi_context, session_handle);
56 if (rc != TSS2_RC_SUCCESS)
57 print_fail ("Tss2_Sys_FlushContext failed: 0x%" PRIx32, rc);
58 print_log ("Flushed context for session handle: 0x%" PRIx32 " success!",
59 session_handle);
60
61 return 0;
62}