• 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_HELPERS_H
7 #define IFAPI_HELPERS_H
8 
9 #include <stdint.h>
10 #include <stdarg.h>
11 #include <stdbool.h>
12 #include <sys/stat.h>
13 #include <json-c/json.h>
14 #include <json-c/json_util.h>
15 
16 #include "tss2_esys.h"
17 #include "tss2_fapi.h"
18 #include "fapi_int.h"
19 
20 TSS2_RC
21 ifapi_create_dirs(const char *supdir, const char *path);
22 
23 TSS2_RC
24 ifapi_set_key_flags(const char *type, bool policy, IFAPI_KEY_TEMPLATE *template);
25 
26 TSS2_RC
27 ifapi_set_nv_flags(const char *type, IFAPI_NV_TEMPLATE *template,
28                    const char *policy);
29 
30 bool
31 ifapi_path_type_p(const char *path, const char *type);
32 
33 ESYS_TR
34 ifapi_get_hierary_handle(const char *path);
35 
36 bool
37 ifapi_hierarchy_path_p(const char *path);
38 
39 bool
40 ifapi_TPMT_PUBLIC_cmp(TPMT_PUBLIC *in1, TPMT_PUBLIC *in2);
41 
42 void
43 ifapi_init_hierarchy_object(
44     IFAPI_OBJECT *hierarchy,
45     ESYS_TR esys_handle);
46 
47 char *
48 get_description(IFAPI_OBJECT *object);
49 
50 size_t
51 ifapi_path_length(NODE_STR_T *node);
52 
53 void
54 ifapi_free_object_list(NODE_OBJECT_T *node);
55 
56 void
57 ifapi_free_node_list(NODE_OBJECT_T *node);
58 
59 TSS2_RC
60 ifapi_path_string(char **dest, const char *supdir, NODE_STR_T *node, char *name);
61 
62 TSS2_RC
63 ifapi_path_string_n(
64     char **dest,
65     const char *supdir,
66     NODE_STR_T *node,
67     char *name,
68     size_t n);
69 
70 TSS2_RC
71 ifapi_asprintf(char **str, const char *fmt, ...);
72 
73 NODE_STR_T *
74 split_string(const char *string, char *delimiter);
75 
76 NODE_STR_T *
77 init_string_list(const char *string);
78 
79 bool
80 add_string_to_list(NODE_STR_T *str_list, char *string);
81 
82 void
83 free_string_list(NODE_STR_T *node);
84 
85 void
86 ifapi_cleanup_policy(
87     TPMS_POLICY *policy);
88 
89 TPMS_POLICY *
90 ifapi_copy_policy(
91     const TPMS_POLICY *from_policy);
92 
93 TSS2_RC
94 ifapi_get_name(
95     TPMT_PUBLIC *publicInfo,
96     TPM2B_NAME *name);
97 
98 TSS2_RC
99 ifapi_nv_get_name(
100     TPM2B_NV_PUBLIC *publicInfo,
101     TPM2B_NAME *name);
102 
103 TSS2_RC
104 ifapi_object_cmp_name(
105     IFAPI_OBJECT *object,
106     void *name,
107     bool *equal);
108 
109 TSS2_RC
110 ifapi_object_cmp_nv_public(
111     IFAPI_OBJECT *object,
112     void *nv_public,
113     bool *equal);
114 
115 TSS2_RC
116 ifapi_tpm_to_fapi_signature(
117     IFAPI_OBJECT *sig_key_object,
118     TPMT_SIGNATURE *tpm_signature,
119     uint8_t **signature,
120     size_t *signatureSize);
121 
122 TSS2_RC
123 ifapi_compute_quote_info(
124     IFAPI_OBJECT *sig_key_object,
125     TPM2B_ATTEST *tpm_quoted,
126     char **quoteInfo);
127 
128 TSS2_RC
129 ifapi_get_quote_info(
130     char const *quoteInfo,
131     TPM2B_ATTEST *tpm_quoted,
132     FAPI_QUOTE_INFO *fapi_quote_ingo);
133 
134 TSS2_RC
135 push_object_to_list(void *object, NODE_OBJECT_T **object_list);
136 
137 TSS2_RC
138 append_object_to_list(void *object, NODE_OBJECT_T **object_list);
139 
140 bool
141 object_with_auth(IFAPI_OBJECT *object);
142 
143 TSS2_RC
144 ifapi_get_nv_start_index(const char *path, TPM2_HANDLE *start_nv_index);
145 
146 TSS2_RC
147 ifapi_check_profile_pcr_selection(
148     const TPML_PCR_SELECTION *pcr_profile,
149     const TPML_PCR_SELECTION *pcr_capablity);
150 
151 TSS2_RC
152 ifapi_filter_pcr_selection_by_index(
153     TPML_PCR_SELECTION *pcr_selection,
154     const TPM2_HANDLE *pcr_index,
155     size_t pcr_count);
156 
157 TSS2_RC ifapi_calculate_pcr_digest(
158     json_object *jso_event_list,
159     const FAPI_QUOTE_INFO *quote_info,
160     TPM2B_DIGEST *pcr_digest);
161 
162 TSS2_RC
163 ifapi_compute_policy_digest(
164     TPML_PCRVALUES *pcrs,
165     TPML_PCR_SELECTION *pcr_selection,
166     TPMI_ALG_HASH hash_alg,
167     TPM2B_DIGEST *pcr_digest);
168 
169 bool
170 ifapi_cmp_public_key(
171     TPM2B_PUBLIC *key1,
172     TPM2B_PUBLIC *key2);
173 
174 int
175 ifapi_get_curl_buffer(
176     unsigned char * url,
177     unsigned char ** buffer,
178     size_t *cert_size);
179 
180 #endif /* IFAPI_HELPERS_H */
181