Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 1 | #include <inttypes.h> |
| 2 | #include <stdio.h> |
Philip Tricca | 910f17c | 2018-03-15 12:38:37 -0700 | [diff] [blame] | 3 | #include <stdlib.h> |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 4 | |
Philip Tricca | 910f17c | 2018-03-15 12:38:37 -0700 | [diff] [blame] | 5 | #include "tss2_sys.h" |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 6 | |
Andreas Fuchs | 78a4958 | 2018-01-03 14:37:16 +0100 | [diff] [blame] | 7 | #define LOGMODULE test |
Philip Tricca | a7c51ce | 2018-03-10 18:28:25 -0800 | [diff] [blame] | 8 | #include "util/log.h" |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 9 | #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 | */ |
| 14 | int |
| 15 | test_invoke (TSS2_SYS_CONTEXT *sapi_context) |
| 16 | { |
| 17 | TSS2_RC rc; |
| 18 | TPM2B_NONCE nonce_caller = { |
Andreas Fuchs | be5899d | 2017-11-13 17:14:36 +0100 | [diff] [blame] | 19 | .size = TPM2_SHA256_DIGEST_SIZE, |
Tadeusz Struk | a64c33e | 2017-11-01 16:12:10 -0700 | [diff] [blame] | 20 | .buffer = { |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 21 | 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 Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 26 | }; |
| 27 | TPM2B_NONCE nonce_tpm = { |
Andreas Fuchs | be5899d | 2017-11-13 17:14:36 +0100 | [diff] [blame] | 28 | .size = TPM2_SHA256_DIGEST_SIZE, |
Tadeusz Struk | a64c33e | 2017-11-01 16:12:10 -0700 | [diff] [blame] | 29 | .buffer = { 0 } |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 30 | }; |
| 31 | TPM2B_ENCRYPTED_SECRET encrypted_salt = { 0 }; |
| 32 | TPMI_SH_AUTH_SESSION session_handle = 0; |
Andreas Fuchs | be5899d | 2017-11-13 17:14:36 +0100 | [diff] [blame] | 33 | TPMT_SYM_DEF symmetric = { .algorithm = TPM2_ALG_NULL }; |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 34 | |
Andreas Fuchs | 78a4958 | 2018-01-03 14:37:16 +0100 | [diff] [blame] | 35 | LOG_INFO("StartAuthSession for TPM2_SE_POLICY (policy session)"); |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 36 | rc = Tss2_Sys_StartAuthSession (sapi_context, |
Andreas Fuchs | be5899d | 2017-11-13 17:14:36 +0100 | [diff] [blame] | 37 | TPM2_RH_NULL, /* tpmKey */ |
| 38 | TPM2_RH_NULL, /* bind */ |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 39 | 0, /* cmdAuthsArray */ |
| 40 | &nonce_caller, /* nonceCaller */ |
| 41 | &encrypted_salt, /* encryptedSalt */ |
Andreas Fuchs | be5899d | 2017-11-13 17:14:36 +0100 | [diff] [blame] | 42 | TPM2_SE_POLICY, /* sessionType */ |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 43 | &symmetric, /* symmetric */ |
Andreas Fuchs | be5899d | 2017-11-13 17:14:36 +0100 | [diff] [blame] | 44 | TPM2_ALG_SHA256, /* authHash */ |
Philip Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 45 | &session_handle, /* sessionHandle */ |
| 46 | &nonce_tpm, /* nonceTPM */ |
| 47 | 0 /* rspAuthsArray */ |
| 48 | ); |
Andreas Fuchs | 78a4958 | 2018-01-03 14:37:16 +0100 | [diff] [blame] | 49 | 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 Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 54 | "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 Fuchs | 78a4958 | 2018-01-03 14:37:16 +0100 | [diff] [blame] | 60 | 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 Tricca | f891580 | 2017-03-14 17:01:50 -0700 | [diff] [blame] | 65 | session_handle); |
| 66 | |
| 67 | return 0; |
| 68 | } |