summaryrefslogtreecommitdiff
path: root/src/libimcv/tcg/tcg_attr.c
blob: 79492913beb6a5ceeaaf0f772c465fd8ca23a1a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 * Copyright (C) 2011-2014 Andreas Steffen
 * HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "tcg_attr.h"
#include "tcg/pts/tcg_pts_attr_proto_caps.h"
#include "tcg/pts/tcg_pts_attr_dh_nonce_params_req.h"
#include "tcg/pts/tcg_pts_attr_dh_nonce_params_resp.h"
#include "tcg/pts/tcg_pts_attr_dh_nonce_finish.h"
#include "tcg/pts/tcg_pts_attr_meas_algo.h"
#include "tcg/pts/tcg_pts_attr_get_tpm_version_info.h"
#include "tcg/pts/tcg_pts_attr_tpm_version_info.h"
#include "tcg/pts/tcg_pts_attr_get_aik.h"
#include "tcg/pts/tcg_pts_attr_aik.h"
#include "tcg/pts/tcg_pts_attr_req_func_comp_evid.h"
#include "tcg/pts/tcg_pts_attr_gen_attest_evid.h"
#include "tcg/pts/tcg_pts_attr_simple_comp_evid.h"
#include "tcg/pts/tcg_pts_attr_simple_evid_final.h"
#include "tcg/pts/tcg_pts_attr_req_file_meas.h"
#include "tcg/pts/tcg_pts_attr_file_meas.h"
#include "tcg/pts/tcg_pts_attr_req_file_meta.h"
#include "tcg/pts/tcg_pts_attr_unix_file_meta.h"
#include "tcg/swid/tcg_swid_attr_req.h"
#include "tcg/swid/tcg_swid_attr_tag_id_inv.h"
#include "tcg/swid/tcg_swid_attr_tag_inv.h"
#include "tcg/seg/tcg_seg_attr_max_size.h"
#include "tcg/seg/tcg_seg_attr_seg_env.h"
#include "tcg/seg/tcg_seg_attr_next_seg.h"

ENUM_BEGIN(tcg_attr_names,	TCG_SCAP_REFERENCES,
							TCG_SCAP_SUMMARY_RESULTS,
	"SCAP References",
	"SCAP Capabilities and Inventory",
	"SCAP Content",
	"SCAP Assessment",
	"SCAP Results",
	"SCAP Summary Results");
ENUM_NEXT(tcg_attr_names,	TCG_SWID_REQUEST,
							TCG_SWID_TAG_EVENTS,
							TCG_SCAP_SUMMARY_RESULTS,
	"SWID Request",
	"SWID Tag Identifier Inventory",
	"SWID Tag Identifier Events",
	"SWID Tag Inventory",
	"SWID Tag Events");
ENUM_NEXT(tcg_attr_names,	TCG_SEG_MAX_ATTR_SIZE_REQ,
							TCG_SEG_CANCEL_SEG_EXCH,
							TCG_SWID_TAG_EVENTS,
	"Max Attribute Size Request",
	"Max Attribute Size Response",
	"Attribute Segment Envelope",
	"Next Segment Request",
	"Cancel Segment Exchange");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_FUNC_COMP_EVID,
							TCG_PTS_REQ_FUNC_COMP_EVID,
							TCG_SEG_CANCEL_SEG_EXCH,
	"Request Functional Component Evidence");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_GEN_ATTEST_EVID,
							TCG_PTS_GEN_ATTEST_EVID,
							TCG_PTS_REQ_FUNC_COMP_EVID,
	"Generate Attestation Evidence");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_SIMPLE_COMP_EVID,
							TCG_PTS_SIMPLE_COMP_EVID,
							TCG_PTS_GEN_ATTEST_EVID,
	"Simple Component Evidence");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_SIMPLE_EVID_FINAL,
							TCG_PTS_SIMPLE_EVID_FINAL,
							TCG_PTS_SIMPLE_COMP_EVID,
	"Simple Evidence Final");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_VERIFICATION_RESULT,
							TCG_PTS_VERIFICATION_RESULT,
							TCG_PTS_SIMPLE_EVID_FINAL,
	"Verification Result");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_INTEG_REPORT,
							TCG_PTS_INTEG_REPORT,
							TCG_PTS_VERIFICATION_RESULT,
	"Integrity Report");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_FILE_META,
							TCG_PTS_REQ_FILE_META,
							TCG_PTS_INTEG_REPORT,
	"Request File Metadata");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_WIN_FILE_META,
							TCG_PTS_WIN_FILE_META,
							TCG_PTS_REQ_FILE_META,
	"Windows-Style File Metadata");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_UNIX_FILE_META,
							TCG_PTS_UNIX_FILE_META,
							TCG_PTS_WIN_FILE_META,
	"Unix-Style File Metadata");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_REGISTRY_VALUE,
							TCG_PTS_REQ_REGISTRY_VALUE,
							TCG_PTS_UNIX_FILE_META,
	"Request Registry Value");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REGISTRY_VALUE,
							TCG_PTS_REGISTRY_VALUE,
							TCG_PTS_REQ_REGISTRY_VALUE,
	"Registry Value");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_FILE_MEAS,
							TCG_PTS_REQ_FILE_MEAS,
							TCG_PTS_REGISTRY_VALUE,
	"Request File Measurement");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_FILE_MEAS,
							TCG_PTS_FILE_MEAS,
							TCG_PTS_REQ_FILE_MEAS,
	"File Measurement");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_INTEG_MEAS_LOG,
							TCG_PTS_REQ_INTEG_MEAS_LOG,
							TCG_PTS_FILE_MEAS,
	"Request Integrity Measurement Log");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_INTEG_MEAS_LOG,
							TCG_PTS_INTEG_MEAS_LOG,
							TCG_PTS_REQ_INTEG_MEAS_LOG,
	"Integrity Measurement Log");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_PROTO_CAPS,
							TCG_PTS_REQ_PROTO_CAPS,
							TCG_PTS_INTEG_MEAS_LOG,
	"Request PTS Protocol Capabilities");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_PROTO_CAPS,
							TCG_PTS_PROTO_CAPS,
							TCG_PTS_REQ_PROTO_CAPS,
	"PTS Protocol Capabilities");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_DH_NONCE_PARAMS_REQ,
							TCG_PTS_DH_NONCE_PARAMS_REQ,
							TCG_PTS_PROTO_CAPS,
	"DH Nonce Parameters Request");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_DH_NONCE_PARAMS_RESP,
							TCG_PTS_DH_NONCE_PARAMS_RESP,
							TCG_PTS_DH_NONCE_PARAMS_REQ,
	"DH Nonce Parameters Response");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_DH_NONCE_FINISH,
							TCG_PTS_DH_NONCE_FINISH,
							TCG_PTS_DH_NONCE_PARAMS_RESP,
	"DH Nonce Finish");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_MEAS_ALGO,
							TCG_PTS_MEAS_ALGO,
							TCG_PTS_DH_NONCE_FINISH,
	"PTS Measurement Algorithm Request");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_MEAS_ALGO_SELECTION,
							TCG_PTS_MEAS_ALGO_SELECTION,
							TCG_PTS_MEAS_ALGO,
	"PTS Measurement Algorithm");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_GET_TPM_VERSION_INFO,
							TCG_PTS_GET_TPM_VERSION_INFO,
							TCG_PTS_MEAS_ALGO_SELECTION,
	"Get TPM Version Information");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_TPM_VERSION_INFO,
							TCG_PTS_TPM_VERSION_INFO,
							TCG_PTS_GET_TPM_VERSION_INFO,
	"TPM Version Information");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_REQ_TEMPL_REF_MANI_SET_META,
							TCG_PTS_REQ_TEMPL_REF_MANI_SET_META,
							TCG_PTS_TPM_VERSION_INFO,
	"Request Template Reference Manifest Set Metadata");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_TEMPL_REF_MANI_SET_META,
							TCG_PTS_TEMPL_REF_MANI_SET_META,
							TCG_PTS_REQ_TEMPL_REF_MANI_SET_META,
	"Template Reference Manifest Set Metadata");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_UPDATE_TEMPL_REF_MANI,
							TCG_PTS_UPDATE_TEMPL_REF_MANI,
							TCG_PTS_TEMPL_REF_MANI_SET_META,
	"Update Template Reference Manifest");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_GET_AIK,
							TCG_PTS_GET_AIK,
							TCG_PTS_UPDATE_TEMPL_REF_MANI,
	"Get Attestation Identity Key");
ENUM_NEXT(tcg_attr_names,	TCG_PTS_AIK,
							TCG_PTS_AIK,
							TCG_PTS_GET_AIK,
	"Attestation Identity Key");
ENUM_END(tcg_attr_names,	TCG_PTS_AIK);

/**
 * See header
 */
pa_tnc_attr_t* tcg_attr_create_from_data(u_int32_t type, size_t length, chunk_t value)
{
	switch (type)
	{
		case TCG_SWID_REQUEST:
			return tcg_swid_attr_req_create_from_data(length, value);
		case TCG_SWID_TAG_ID_INVENTORY:
			return tcg_swid_attr_tag_id_inv_create_from_data(length, value);
		case TCG_SWID_TAG_INVENTORY:
			return tcg_swid_attr_tag_inv_create_from_data(length, value);
		case TCG_SEG_MAX_ATTR_SIZE_REQ:
			return tcg_seg_attr_max_size_create_from_data(length, value, TRUE);
		case TCG_SEG_MAX_ATTR_SIZE_RESP:
			return tcg_seg_attr_max_size_create_from_data(length, value, FALSE);
		case TCG_SEG_ATTR_SEG_ENV:
			return tcg_seg_attr_seg_env_create_from_data(length, value);
		case TCG_SEG_NEXT_SEG_REQ:
			return tcg_seg_attr_next_seg_create_from_data(length, value);
		case TCG_PTS_REQ_PROTO_CAPS:
			return tcg_pts_attr_proto_caps_create_from_data(length, value,
															TRUE);
		case TCG_PTS_PROTO_CAPS:
			return tcg_pts_attr_proto_caps_create_from_data(length, value,
															FALSE);
		case TCG_PTS_DH_NONCE_PARAMS_REQ:
			return tcg_pts_attr_dh_nonce_params_req_create_from_data(length,
																	 value);
		case TCG_PTS_DH_NONCE_PARAMS_RESP:
			return tcg_pts_attr_dh_nonce_params_resp_create_from_data(length,
																	  value);
		case TCG_PTS_DH_NONCE_FINISH:
			return tcg_pts_attr_dh_nonce_finish_create_from_data(length, value);
		case TCG_PTS_MEAS_ALGO:
			return tcg_pts_attr_meas_algo_create_from_data(length, value,
														   FALSE);
		case TCG_PTS_MEAS_ALGO_SELECTION:
			return tcg_pts_attr_meas_algo_create_from_data(length, value,
														   TRUE);
		case TCG_PTS_GET_TPM_VERSION_INFO:
			return tcg_pts_attr_get_tpm_version_info_create_from_data(length,
																	  value);
		case TCG_PTS_TPM_VERSION_INFO:
			return tcg_pts_attr_tpm_version_info_create_from_data(length,
																  value);
		case TCG_PTS_GET_AIK:
			return tcg_pts_attr_get_aik_create_from_data(length, value);
		case TCG_PTS_AIK:
			return tcg_pts_attr_aik_create_from_data(length, value);
		case TCG_PTS_REQ_FUNC_COMP_EVID:
			return tcg_pts_attr_req_func_comp_evid_create_from_data(length,
																	value);
		case TCG_PTS_GEN_ATTEST_EVID:
			return tcg_pts_attr_gen_attest_evid_create_from_data(length, value);
		case TCG_PTS_SIMPLE_COMP_EVID:
			return tcg_pts_attr_simple_comp_evid_create_from_data(length,
																  value);
		case TCG_PTS_SIMPLE_EVID_FINAL:
			return tcg_pts_attr_simple_evid_final_create_from_data(length,
																   value);
		case TCG_PTS_REQ_FILE_MEAS:
			return tcg_pts_attr_req_file_meas_create_from_data(length, value);
		case TCG_PTS_FILE_MEAS:
			return tcg_pts_attr_file_meas_create_from_data(length, value);
		case TCG_PTS_REQ_FILE_META:
			return tcg_pts_attr_req_file_meta_create_from_data(length, value);
		case TCG_PTS_UNIX_FILE_META:
			return tcg_pts_attr_unix_file_meta_create_from_data(length, value);
		/* unsupported TCG/SWID attributes */
		case TCG_SWID_TAG_ID_EVENTS:
		case TCG_SWID_TAG_EVENTS:
		/* unsupported TCG/PTS attributes */
		case TCG_PTS_REQ_TEMPL_REF_MANI_SET_META:
		case TCG_PTS_TEMPL_REF_MANI_SET_META:
		case TCG_PTS_UPDATE_TEMPL_REF_MANI:
		case TCG_PTS_VERIFICATION_RESULT:
		case TCG_PTS_INTEG_REPORT:
		case TCG_PTS_WIN_FILE_META:
		case TCG_PTS_REQ_REGISTRY_VALUE:
		case TCG_PTS_REGISTRY_VALUE:
		case TCG_PTS_REQ_INTEG_MEAS_LOG:
		case TCG_PTS_INTEG_MEAS_LOG:
		default:
			return NULL;
	}
}