• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 
5 #include <stdbool.h>
6 #include <stdlib.h>
7 #include <inttypes.h>
8 
9 #include "tss2_sys.h"
10 
11 #define LOGMODULE test
12 #include "util/log.h"
13 #include "test-options.h"
14 #include "context-util.h"
15 
16 #define TAB_SIZE(x) (sizeof(x)/sizeof(x[0]))
17 
18 int
main(int argc,char * argv[])19 main (int argc, char *argv[])
20 {
21     TSS2_RC rc;
22     TSS2_SYS_CONTEXT *sapi_context;
23 
24     test_opts_t opts = {
25         .tcti_type      = TCTI_DEFAULT,
26         .device_file    = DEVICE_PATH_DEFAULT,
27         .socket_address = HOSTNAME_DEFAULT,
28         .socket_port    = PORT_DEFAULT,
29     };
30 
31     get_test_opts_from_env (&opts);
32     if (sanity_check_test_opts (&opts) != 0)
33         exit (1);
34 
35     sapi_context = sapi_init_from_opts (&opts);
36     if (sapi_context == NULL)
37         exit (1);
38 
39     TPMS_CAPABILITY_DATA caps;
40 
41     rc = Tss2_Sys_GetCapability(sapi_context, NULL, TPM2_CAP_HANDLES,
42                                 TPM2_HR_TRANSIENT,
43                                 TAB_SIZE(caps.data.handles.handle), NULL,
44                                 &caps, NULL);
45     if (rc != TSS2_RC_SUCCESS) {
46         LOG_ERROR("TPM GetCapabilities FAILED! Response Code : 0x%"PRIx32, rc);
47         exit(1);
48     }
49 
50 
51     sapi_teardown_full (sapi_context);
52 
53     if (caps.data.handles.count) {
54         LOG_ERROR("TPM contains transient entries");
55         for (UINT32 i = 0; i < caps.data.handles.count; i++)
56             LOG_ERROR("Handle %"PRIx32, caps.data.handles.handle[i]);
57         return 1;
58     }
59 
60     return 0;
61 }
62