]>
Commit | Line | Data |
---|---|---|
b38d9d5a | 1 | /* |
e77df5a1 AS |
2 | * Copyright (C) 2011-2012 Sansar Choinyambuu |
3 | * Copyright (C) 2011-2014 Andreas Steffen | |
19ef2aec TB |
4 | * |
5 | * Copyright (C) secunet Security Networks AG | |
b38d9d5a AS |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | * for more details. | |
16 | */ | |
17 | ||
18 | #include "tcg_pts_attr_req_func_comp_evid.h" | |
19 | ||
20 | #include <pa_tnc/pa_tnc_msg.h> | |
21 | #include <bio/bio_writer.h> | |
22 | #include <bio/bio_reader.h> | |
23 | #include <collections/linked_list.h> | |
24 | #include <utils/debug.h> | |
25 | ||
26 | typedef struct private_tcg_pts_attr_req_func_comp_evid_t private_tcg_pts_attr_req_func_comp_evid_t; | |
27 | ||
28 | /** | |
29 | * Request Functional Component Evidence | |
30 | * see section 3.14.1 of PTS Protocol: Binding to TNC IF-M Specification | |
31 | * | |
32 | * 1 2 3 | |
33 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
34 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
35 | * | Flags | Sub-component Depth (for Component #1) | | |
36 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
37 | * | Component Functional Name #1 | | |
38 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
39 | * | Component Functional Name #1 | | |
40 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
41 | * | ........ | | |
42 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
43 | * | Flags | Sub-component Depth (for Component #N) | | |
44 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
45 | * | Component Functional Name #N | | |
46 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
47 | * | Component Functional Name #N | | |
48 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
49 | */ | |
50 | ||
51 | /** | |
52 | * Component Functional Name Structure | |
53 | * (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification) | |
54 | * | |
55 | * 1 2 3 | |
56 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
57 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
58 | * | Component Functional Name Vendor ID |Fam| Qualifier | | |
59 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
60 | * | Component Functional Name | | |
61 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
62 | */ | |
63 | ||
64 | #define PTS_REQ_FUNC_COMP_EVID_SIZE 12 | |
65 | #define PTS_REQ_FUNC_COMP_FAMILY_MASK 0xC0 | |
66 | ||
67 | /** | |
68 | * Private data of an tcg_pts_attr_req_func_comp_evid_t object. | |
69 | */ | |
70 | struct private_tcg_pts_attr_req_func_comp_evid_t { | |
71 | ||
72 | /** | |
73 | * Public members of tcg_pts_attr_req_func_comp_evid_t | |
74 | */ | |
75 | tcg_pts_attr_req_func_comp_evid_t public; | |
76 | ||
77 | /** | |
78 | * Vendor-specific attribute type | |
79 | */ | |
80 | pen_type_t type; | |
81 | ||
82 | /** | |
e77df5a1 AS |
83 | * Length of attribute value |
84 | */ | |
85 | size_t length; | |
86 | ||
87 | /** | |
88 | * Attribute value or segment | |
b38d9d5a AS |
89 | */ |
90 | chunk_t value; | |
91 | ||
92 | /** | |
93 | * Noskip flag | |
94 | */ | |
95 | bool noskip_flag; | |
96 | ||
97 | /** | |
98 | * List of Functional Components | |
99 | */ | |
100 | linked_list_t *list; | |
101 | ||
102 | /** | |
103 | * Reference count | |
104 | */ | |
105 | refcount_t ref; | |
106 | }; | |
107 | ||
108 | typedef struct entry_t entry_t; | |
109 | ||
110 | /** | |
111 | * Functional component entry | |
112 | */ | |
113 | struct entry_t { | |
b12c53ce AS |
114 | uint8_t flags; |
115 | uint32_t depth; | |
b38d9d5a AS |
116 | pts_comp_func_name_t *name; |
117 | }; | |
118 | ||
525cc46c TB |
119 | CALLBACK(entry_filter, bool, |
120 | void *null, enumerator_t *orig, va_list args) | |
b38d9d5a | 121 | { |
525cc46c TB |
122 | entry_t *entry; |
123 | pts_comp_func_name_t **name; | |
124 | uint32_t *depth; | |
125 | uint8_t *flags; | |
b38d9d5a | 126 | |
525cc46c TB |
127 | VA_ARGS_VGET(args, flags, depth, name); |
128 | ||
129 | if (orig->enumerate(orig, &entry)) | |
130 | { | |
131 | *flags = entry->flags; | |
132 | *depth = entry->depth; | |
133 | *name = entry->name; | |
134 | return TRUE; | |
135 | } | |
136 | return FALSE; | |
b38d9d5a AS |
137 | } |
138 | ||
139 | /** | |
140 | * Free an entry_t object | |
141 | */ | |
142 | static void free_entry(entry_t *this) | |
143 | { | |
144 | if (this) | |
145 | { | |
146 | this->name->destroy(this->name); | |
147 | free(this); | |
148 | } | |
149 | } | |
150 | ||
151 | METHOD(pa_tnc_attr_t, get_type, pen_type_t, | |
152 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
153 | { | |
154 | return this->type; | |
155 | } | |
156 | ||
157 | METHOD(pa_tnc_attr_t, get_value, chunk_t, | |
158 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
159 | { | |
160 | return this->value; | |
161 | } | |
162 | ||
163 | METHOD(pa_tnc_attr_t, get_noskip_flag, bool, | |
164 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
165 | { | |
166 | return this->noskip_flag; | |
167 | } | |
168 | ||
169 | METHOD(pa_tnc_attr_t, set_noskip_flag,void, | |
170 | private_tcg_pts_attr_req_func_comp_evid_t *this, bool noskip) | |
171 | { | |
172 | this->noskip_flag = noskip; | |
173 | } | |
174 | ||
175 | METHOD(pa_tnc_attr_t, build, void, | |
176 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
177 | { | |
178 | bio_writer_t *writer; | |
179 | enumerator_t *enumerator; | |
180 | entry_t *entry; | |
181 | ||
182 | if (this->value.ptr) | |
183 | { | |
184 | return; | |
185 | } | |
186 | writer = bio_writer_create(PTS_REQ_FUNC_COMP_EVID_SIZE); | |
187 | ||
188 | enumerator = this->list->create_enumerator(this->list); | |
189 | while (enumerator->enumerate(enumerator, &entry)) | |
190 | { | |
191 | writer->write_uint8 (writer, entry->flags); | |
192 | writer->write_uint24(writer, entry->depth); | |
193 | writer->write_uint24(writer, entry->name->get_vendor_id(entry->name)); | |
194 | writer->write_uint8 (writer, entry->name->get_qualifier(entry->name)); | |
195 | writer->write_uint32(writer, entry->name->get_name(entry->name)); | |
196 | } | |
197 | enumerator->destroy(enumerator); | |
198 | ||
199 | this->value = writer->extract_buf(writer); | |
e77df5a1 | 200 | this->length = this->value.len; |
b38d9d5a AS |
201 | writer->destroy(writer); |
202 | } | |
203 | ||
204 | METHOD(pa_tnc_attr_t, process, status_t, | |
b12c53ce | 205 | private_tcg_pts_attr_req_func_comp_evid_t *this, uint32_t *offset) |
b38d9d5a AS |
206 | { |
207 | bio_reader_t *reader; | |
b12c53ce AS |
208 | uint32_t depth, vendor_id, name; |
209 | uint8_t flags, fam_and_qualifier, qualifier; | |
b38d9d5a AS |
210 | status_t status = FAILED; |
211 | entry_t *entry = NULL; | |
212 | ||
e77df5a1 AS |
213 | *offset = 0; |
214 | ||
215 | if (this->value.len < this->length) | |
216 | { | |
217 | return NEED_MORE; | |
218 | } | |
b38d9d5a AS |
219 | if (this->value.len < PTS_REQ_FUNC_COMP_EVID_SIZE) |
220 | { | |
221 | DBG1(DBG_TNC, "insufficient data for Request Functional " | |
222 | "Component Evidence"); | |
b38d9d5a AS |
223 | return FAILED; |
224 | } | |
225 | reader = bio_reader_create(this->value); | |
226 | ||
227 | while (reader->remaining(reader)) | |
228 | { | |
229 | if (!reader->read_uint8(reader, &flags)) | |
230 | { | |
231 | DBG1(DBG_TNC, "insufficient data for PTS Request Functional " | |
232 | "Component Evidence Flags"); | |
233 | goto end; | |
234 | } | |
235 | if (!reader->read_uint24(reader, &depth)) | |
236 | { | |
237 | DBG1(DBG_TNC, "insufficient data for PTS Request Functional " | |
238 | "Component Evidence Sub Component Depth"); | |
239 | goto end; | |
240 | } | |
241 | if (!reader->read_uint24(reader, &vendor_id)) | |
242 | { | |
243 | DBG1(DBG_TNC, "insufficient data for PTS Request Functional " | |
244 | "Component Evidence Component Name Vendor ID"); | |
245 | goto end; | |
246 | } | |
247 | if (!reader->read_uint8(reader, &fam_and_qualifier)) | |
248 | { | |
249 | DBG1(DBG_TNC, "insufficient data for PTS Request Functional " | |
250 | "Component Evidence Family and Qualifier"); | |
251 | goto end; | |
252 | } | |
253 | if (fam_and_qualifier & PTS_REQ_FUNC_COMP_FAMILY_MASK) | |
254 | { | |
255 | DBG1(DBG_TNC, "the Functional Name Encoding Family " | |
256 | "is not Binary Enumeration"); | |
257 | goto end; | |
258 | } | |
259 | if (!reader->read_uint32(reader, &name)) | |
260 | { | |
261 | DBG1(DBG_TNC, "insufficient data for PTS Request Functional " | |
262 | "Component Evidence Component Functional Name"); | |
263 | goto end; | |
264 | } | |
265 | qualifier = fam_and_qualifier & ~PTS_REQ_FUNC_COMP_FAMILY_MASK; | |
266 | ||
267 | entry = malloc_thing(entry_t); | |
268 | entry->flags = flags; | |
269 | entry->depth = depth; | |
270 | entry->name = pts_comp_func_name_create(vendor_id, name, qualifier); | |
271 | ||
272 | this->list->insert_last(this->list, entry); | |
273 | } | |
274 | status = SUCCESS; | |
275 | ||
276 | end: | |
277 | reader->destroy(reader); | |
278 | return status; | |
279 | } | |
280 | ||
1bea0065 AS |
281 | METHOD(pa_tnc_attr_t, add_segment, void, |
282 | private_tcg_pts_attr_req_func_comp_evid_t *this, chunk_t segment) | |
283 | { | |
284 | this->value = chunk_cat("mc", this->value, segment); | |
285 | } | |
286 | ||
b38d9d5a AS |
287 | METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, |
288 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
289 | { | |
290 | ref_get(&this->ref); | |
291 | return &this->public.pa_tnc_attribute; | |
292 | } | |
293 | ||
294 | METHOD(pa_tnc_attr_t, destroy, void, | |
295 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
296 | { | |
297 | if (ref_put(&this->ref)) | |
298 | { | |
299 | this->list->destroy_function(this->list, (void *)free_entry); | |
300 | free(this->value.ptr); | |
301 | free(this); | |
302 | } | |
303 | } | |
304 | ||
305 | METHOD(tcg_pts_attr_req_func_comp_evid_t, add_component, void, | |
b12c53ce AS |
306 | private_tcg_pts_attr_req_func_comp_evid_t *this, uint8_t flags, |
307 | uint32_t depth, pts_comp_func_name_t *name) | |
b38d9d5a AS |
308 | { |
309 | entry_t *entry; | |
310 | ||
311 | entry = malloc_thing(entry_t); | |
312 | entry->flags = flags; | |
313 | entry->depth = depth; | |
fbddf52c | 314 | entry->name = name->clone(name); |
b38d9d5a AS |
315 | this->list->insert_last(this->list, entry); |
316 | } | |
317 | ||
318 | METHOD(tcg_pts_attr_req_func_comp_evid_t, get_count, int, | |
319 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
320 | { | |
321 | return this->list->get_count(this->list); | |
322 | } | |
323 | ||
324 | METHOD(tcg_pts_attr_req_func_comp_evid_t, create_enumerator, enumerator_t*, | |
325 | private_tcg_pts_attr_req_func_comp_evid_t *this) | |
326 | { | |
327 | return enumerator_create_filter(this->list->create_enumerator(this->list), | |
525cc46c | 328 | entry_filter, NULL, NULL); |
b38d9d5a AS |
329 | } |
330 | ||
331 | /** | |
332 | * Described in header. | |
333 | */ | |
334 | pa_tnc_attr_t *tcg_pts_attr_req_func_comp_evid_create(void) | |
335 | { | |
336 | private_tcg_pts_attr_req_func_comp_evid_t *this; | |
337 | ||
338 | INIT(this, | |
339 | .public = { | |
340 | .pa_tnc_attribute = { | |
341 | .get_type = _get_type, | |
342 | .get_value = _get_value, | |
343 | .get_noskip_flag = _get_noskip_flag, | |
344 | .set_noskip_flag = _set_noskip_flag, | |
345 | .build = _build, | |
346 | .process = _process, | |
1bea0065 | 347 | .add_segment = _add_segment, |
b38d9d5a AS |
348 | .get_ref = _get_ref, |
349 | .destroy = _destroy, | |
350 | }, | |
351 | .add_component = _add_component, | |
352 | .get_count = _get_count, | |
353 | .create_enumerator = _create_enumerator, | |
354 | }, | |
355 | .type = { PEN_TCG, TCG_PTS_REQ_FUNC_COMP_EVID }, | |
356 | .list = linked_list_create(), | |
357 | .ref = 1, | |
358 | ); | |
359 | ||
360 | return &this->public.pa_tnc_attribute; | |
361 | } | |
362 | ||
363 | /** | |
364 | * Described in header. | |
365 | */ | |
e77df5a1 AS |
366 | pa_tnc_attr_t *tcg_pts_attr_req_func_comp_evid_create_from_data(size_t length, |
367 | chunk_t data) | |
b38d9d5a AS |
368 | { |
369 | private_tcg_pts_attr_req_func_comp_evid_t *this; | |
370 | ||
371 | INIT(this, | |
372 | .public = { | |
373 | .pa_tnc_attribute = { | |
374 | .get_type = _get_type, | |
375 | .get_value = _get_value, | |
376 | .get_noskip_flag = _get_noskip_flag, | |
377 | .set_noskip_flag = _set_noskip_flag, | |
378 | .build = _build, | |
379 | .process = _process, | |
1bea0065 | 380 | .add_segment = _add_segment, |
b38d9d5a AS |
381 | .get_ref = _get_ref, |
382 | .destroy = _destroy, | |
383 | }, | |
384 | .add_component = _add_component, | |
385 | .get_count = _get_count, | |
386 | .create_enumerator = _create_enumerator, | |
387 | }, | |
388 | .type = { PEN_TCG, TCG_PTS_REQ_FUNC_COMP_EVID }, | |
e77df5a1 | 389 | .length = length, |
b38d9d5a AS |
390 | .list = linked_list_create(), |
391 | .value = chunk_clone(data), | |
392 | .ref = 1, | |
393 | ); | |
394 | ||
395 | return &this->public.pa_tnc_attribute; | |
396 | } |