• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*******************************************************************************
3  * Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG
4  * All rights reserved.
5  *******************************************************************************/
6 #ifndef IFAPI_EVENTLOG_H
7 #define IFAPI_EVENTLOG_H
8 
9 #include <json-c/json.h>
10 
11 #include "tss2_tpm2_types.h"
12 #include "ifapi_io.h"
13 
14 /** Type of event
15  */
16 typedef UINT32 IFAPI_EVENT_TYPE;
17 #define IFAPI_IMA_EVENT_TAG            1    /**< Tag for key resource */
18 #define IFAPI_TSS_EVENT_TAG            2    /**< Tag for key resource */
19 
20 /** TSS event information
21  */
22 typedef struct {
23     TPM2B_EVENT                                    data;    /**< The event data */
24     char                                         *event;    /**< TSS event information */
25 } IFAPI_TSS_EVENT;
26 
27 /** IMA event information
28  */
29 typedef struct {
30     TPM2B_DIGEST                              eventData;    /**< The ima event digest */
31     char                                     *eventName;    /**< IMA event information */
32 } IFAPI_IMA_EVENT;
33 
34 /** Type for representing sub types of FAPI events
35  */
36 typedef union {
37     IFAPI_TSS_EVENT                           tss_event;    /**< TSS event information */
38     IFAPI_IMA_EVENT                           ima_event;    /**< IMA event information */
39 } IFAPI_EVENT_UNION;
40 
41 /** Type for representing a FAPI event
42  */
43 typedef struct IFAPI_EVENT {
44     UINT32                                       recnum;    /**< Number of event */
45     TPM2_HANDLE                                     pcr;    /**< PCR register */
46     TPML_DIGEST_VALUES                          digests;    /**< The digest list of the event */
47     IFAPI_EVENT_TYPE                               type;    /**< Selector for object type */
48     IFAPI_EVENT_UNION                         sub_event;    /**< Additional event information */
49 } IFAPI_EVENT;
50 
51 enum IFAPI_EVENTLOG_STATE {
52     IFAPI_EVENTLOG_STATE_INIT = 0,
53     IFAPI_EVENTLOG_STATE_READING,
54     IFAPI_EVENTLOG_STATE_APPENDING,
55     IFAPI_EVENTLOG_STATE_WRITING
56 };
57 
58 typedef struct IFAPI_EVENTLOG {
59     enum IFAPI_EVENTLOG_STATE state;
60     char *log_dir;
61     struct IFAPI_EVENT event;
62     TPM2_HANDLE pcrList[TPM2_MAX_PCRS];
63     size_t pcrListSize;
64     size_t pcrListIdx;
65     json_object *log;
66 } IFAPI_EVENTLOG;
67 
68 TSS2_RC
69 ifapi_eventlog_initialize(
70     IFAPI_EVENTLOG *eventlog,
71     const char *log_dir);
72 
73 TSS2_RC
74 ifapi_eventlog_get_async(
75     IFAPI_EVENTLOG *eventlog,
76     IFAPI_IO *io,
77     const TPM2_HANDLE *pcrList,
78     size_t pcrListSize);
79 
80 TSS2_RC
81 ifapi_eventlog_get_finish(
82     IFAPI_EVENTLOG *eventlog,
83     IFAPI_IO *io,
84     char **log);
85 
86 TSS2_RC
87 ifapi_eventlog_append_async(
88     IFAPI_EVENTLOG *eventlog,
89     IFAPI_IO *io,
90     const IFAPI_EVENT *event);
91 
92 TSS2_RC
93 ifapi_eventlog_append_finish(
94     IFAPI_EVENTLOG *eventlog,
95     IFAPI_IO *io);
96 
97 void
98 ifapi_cleanup_event(
99     IFAPI_EVENT * event);
100 
101 #endif /* IFAPI_EVENTLOG_H */
102