555efc16d5dad3f6683a6909dd04ecea764f4a3f
[strongswan.git] / src / libimcv / tcg / tcg_pts_attr_simple_comp_evid.c
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "tcg_pts_attr_simple_comp_evid.h"
17
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <debug.h>
22
23 typedef struct private_tcg_pts_attr_simple_comp_evid_t private_tcg_pts_attr_simple_comp_evid_t;
24
25 /**
26 * Simple Component Evidence (see section 3.15.1 of PTS Protocol: Binding to TNC IF-M Specification)
27 *
28 * 1 2 3
29 * 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
30 *
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Flags | Sub-Component Depth |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Specific Functional Component |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | Specific Functional Component |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | Measure. Type | Extended into PCR |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | Hash Algorithm | PCR Transform | Reserved |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * | Measurement Date/Time |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | Measurement Date/Time |
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Measurement Date/Time |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Measurement Date/Time |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | Measurement Date/Time |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * | Optional Policy URI Length | Opt. Verification Policy URI ~
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * ~ Optional Verification Policy URI ~
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * | Optional PCR Length | Optional PCR Before Value ~
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * ~ Optional PCR Before Value (Variable Length) ~
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 * ~ Optional PCR After Value (Variable Length) ~
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * ~ Component Measurement (Variable Length) ~
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 */
65
66 /**
67 * Specific Functional Component -> Component Functional Name Structure
68 * (see section 5.1 of PTS Protocol: Binding to TNC IF-M Specification)
69 *
70 * 1 2 3
71 * 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
72 *
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * | Component Functional Name Vendor ID |Fam| Qualifier |
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 * | Component Functional Name |
77 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 *
79 */
80
81 /**
82 * Qualifier for Functional Component (see section 5.2 of PTS Protocol: Binding to TNC IF-M Specification)
83 *
84 *
85 * 0 1 2 3 4 5
86 * +-+-+-+-+-+-+
87 * |K|S| Type |
88 * +-+-+-+-+-+-+
89 */
90
91
92
93 #define PTS_SIMPLE_COMP_EVID_SIZE 40
94 #define PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE 20
95 #define PTS_SIMPLE_COMP_EVID_RESERVED 0x00
96 #define PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM 0x00
97
98 /**
99 * Private data of an tcg_pts_attr_simple_comp_evid_t object.
100 */
101 struct private_tcg_pts_attr_simple_comp_evid_t {
102
103 /**
104 * Public members of tcg_pts_attr_simple_comp_evid_t
105 */
106 tcg_pts_attr_simple_comp_evid_t public;
107
108 /**
109 * Attribute vendor ID
110 */
111 pen_t vendor_id;
112
113 /**
114 * Attribute type
115 */
116 u_int32_t type;
117
118 /**
119 * Attribute value
120 */
121 chunk_t value;
122
123 /**
124 * Noskip flag
125 */
126 bool noskip_flag;
127
128 /**
129 * Set of flags for Simple Component Evidence
130 */
131 pts_attr_simple_comp_evid_flag_t flags;
132
133 /**
134 * Sub-component Depth
135 */
136 u_int32_t depth;
137
138 /**
139 * Component Functional Name Vendor ID
140 */
141 u_int32_t comp_vendor_id;
142
143 /**
144 * Functional Name Encoding Family
145 */
146 u_int8_t family;
147
148 /**
149 * Functional Name Category Qualifier
150 */
151 tcg_pts_qualifier_t qualifier;
152
153 /**
154 * Component Functional Name
155 */
156 pts_attr_req_funct_comp_name_bin_enum_t name;
157
158 /**
159 * Measurement type
160 */
161 u_int8_t measurement_type;
162
163 /**
164 * Which PCR the functional component is extended into
165 */
166 u_int32_t extended_pcr;
167
168 /**
169 * Hash Algorithm
170 */
171 pts_attr_meas_algorithms_t hash_algorithm;
172
173 /**
174 * Transformation type for PCR
175 */
176 pts_attr_simple_comp_evid_pcr_transform_t transformation;
177
178 /**
179 * Measurement time
180 */
181 chunk_t measurement_time;
182
183 /**
184 * Optional Policy URI
185 */
186 chunk_t policy_uri;
187
188 /**
189 * Optional PCR before value
190 */
191 chunk_t pcr_before;
192
193 /**
194 * Optional PCR after value
195 */
196 chunk_t pcr_after;
197
198 /**
199 * Component Measurement
200 */
201 chunk_t measurement;
202
203 };
204
205 METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
206 private_tcg_pts_attr_simple_comp_evid_t *this)
207 {
208 return this->vendor_id;
209 }
210
211 METHOD(pa_tnc_attr_t, get_type, u_int32_t,
212 private_tcg_pts_attr_simple_comp_evid_t *this)
213 {
214 return this->type;
215 }
216
217 METHOD(pa_tnc_attr_t, get_value, chunk_t,
218 private_tcg_pts_attr_simple_comp_evid_t *this)
219 {
220 return this->value;
221 }
222
223 METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
224 private_tcg_pts_attr_simple_comp_evid_t *this)
225 {
226 return this->noskip_flag;
227 }
228
229 METHOD(pa_tnc_attr_t, set_noskip_flag,void,
230 private_tcg_pts_attr_simple_comp_evid_t *this, bool noskip)
231 {
232 this->noskip_flag = noskip;
233 }
234
235 METHOD(pa_tnc_attr_t, build, void,
236 private_tcg_pts_attr_simple_comp_evid_t *this)
237 {
238 bio_writer_t *writer;
239 u_int8_t flags = 0;
240 u_int8_t qualifier = 0;
241 u_int16_t algorithm = 0;
242
243 writer = bio_writer_create(PTS_SIMPLE_COMP_EVID_SIZE);
244
245 /* Determine the flags to set*/
246 if(this->flags & PTS_SIMPLE_COMP_EVID_FLAG_PCR) flags += 128;
247 if(this->flags & PTS_SIMPLE_COMP_EVID_FLAG_NO_VER) flags += 32;
248 else if(this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL) flags += 64;
249 else if(this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS) flags += 96;
250
251 writer->write_uint8(writer, flags);
252
253 writer->write_uint24 (writer, this->depth);
254 writer->write_uint24 (writer, this->comp_vendor_id);
255
256 if(this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
257 {
258 DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
259 }
260
261 qualifier += this->qualifier.type;
262 if(this->qualifier.kernel) qualifier += 16;
263 if(this->qualifier.sub_component) qualifier += 32;
264
265 /* Unknown or Wildcard should not be used for Qualification*/
266 if(!qualifier || qualifier == 63)
267 {
268 DBG1(DBG_TNC, "Unknown or Wildcard should not be used for"
269 " Functional Name Qualifier");
270 }
271
272 writer->write_uint8 (writer, qualifier);
273 writer->write_uint32 (writer, this->name);
274
275 writer->write_uint8 (writer, (this->measurement_type << 7));
276 writer->write_uint24 (writer, this->extended_pcr);
277
278 /* Determine the hash algorithm to set*/
279 if(this->hash_algorithm & PTS_MEAS_ALGO_SHA384) algorithm = 8192;
280 else if(this->hash_algorithm & PTS_MEAS_ALGO_SHA256) algorithm = 16384;
281 else if(this->hash_algorithm & PTS_MEAS_ALGO_SHA1) algorithm = 32768;
282 writer->write_uint16(writer, algorithm);
283
284 writer->write_uint8 (writer, this->transformation);
285 writer->write_data (writer, this->measurement_time);
286
287 /* Optional fields */
288 if(this->policy_uri.ptr && this->policy_uri.len > 0)
289 {
290 writer->write_uint16 (writer, this->policy_uri.len);
291 writer->write_data (writer, this->policy_uri);
292 }
293 if(this->pcr_before.ptr && this->pcr_after.ptr &&
294 this->pcr_before.len == this->pcr_after.len &&
295 this->pcr_before.len > 0 && this->pcr_after.len > 0)
296 {
297 writer->write_uint16 (writer, this->pcr_before.len);
298 writer->write_data (writer, this->pcr_before);
299 writer->write_data (writer, this->pcr_after);
300 }
301
302 writer->write_data (writer, this->measurement);
303
304 this->value = chunk_clone(writer->get_buf(writer));
305 writer->destroy(writer);
306 }
307
308 METHOD(pa_tnc_attr_t, process, status_t,
309 private_tcg_pts_attr_simple_comp_evid_t *this, u_int32_t *offset)
310 {
311 bio_reader_t *reader;
312 u_int8_t flags;
313 u_int8_t fam_and_qualifier;
314 u_int8_t measurement_type;
315 u_int16_t algorithm;
316 u_int8_t transformation;
317 u_int32_t measurement_len;
318
319 if (this->value.len < PTS_SIMPLE_COMP_EVID_SIZE)
320 {
321 DBG1(DBG_TNC, "insufficient data for Simple Component Evidence");
322 *offset = 0;
323 return FAILED;
324 }
325 reader = bio_reader_create(this->value);
326
327 reader->read_uint8(reader, &flags);
328
329 /* Determine the flags to set*/
330 if((flags >> 7) & 1) this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_PCR;
331
332 if(!((flags >> 6) & 1) && !((flags >> 5) & 1))
333 this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_NO_VALID;
334 else if(!((flags >> 6) & 1) && ((flags >> 5) & 1))
335 this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_NO_VER;
336 else if(((flags >> 6) & 1) && !((flags >> 5) & 1))
337 this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL;
338 else if(((flags >> 6) & 1) && ((flags >> 5) & 1))
339 this->flags |= PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS;
340
341 reader->read_uint24(reader, &this->depth);
342 reader->read_uint24(reader, &this->comp_vendor_id);
343 reader->read_uint8(reader, &fam_and_qualifier);
344
345 if(((fam_and_qualifier >> 6) & 1) ) this->family += 1;
346 if(((fam_and_qualifier >> 7) & 1) ) this->family += 2;
347
348 /* TODO: Generate an IF-M error attribute indicating */
349 /* TCG_PTS_INVALID_NAME_FAM */
350 //if(&this->comp_vendor_id==PEN_TCG && this->family != PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM)
351 //{
352 // DBG1(DBG_TNC, "Functional Name Encoding Family is not set to 00");
353 //}
354
355 if(((fam_and_qualifier >> 5) & 1) ) this->qualifier.kernel = true;
356 if(((fam_and_qualifier >> 4) & 1) ) this->qualifier.sub_component = true;
357 this->qualifier.type = ( fam_and_qualifier & 0xF );
358 /* TODO: Check the type is defined in pts_attr_req_funct_comp_type_t */
359
360 /* Unknown or Wildcard should not be used for Qualification*/
361 if(!(fam_and_qualifier & 0x3F) || (fam_and_qualifier & 0x3F) == 0x3F)
362 {
363 DBG1(DBG_TNC, "Unknown or Wildcard should not be used for"
364 " Functional Name Qualifier");
365 }
366
367 reader->read_uint32(reader, &this->name);
368 /* TODO: Check the name is defined in pts_attr_req_funct_comp_name_bin_enum_t */
369
370 reader->read_uint8(reader, &measurement_type);
371 this->measurement_type = (measurement_type >> 7 ) & 1;
372
373 reader->read_uint24(reader, &this->extended_pcr);
374 reader->read_uint16(reader, &algorithm);
375
376 if((algorithm >> 13) & 1) this->hash_algorithm = PTS_MEAS_ALGO_SHA384;
377 else if((algorithm >> 14) & 1) this->hash_algorithm = PTS_MEAS_ALGO_SHA256;
378 else if((algorithm >> 15) & 1) this->hash_algorithm = PTS_MEAS_ALGO_SHA1;
379
380 reader->read_uint8(reader, &transformation);
381 this->transformation = transformation;
382 /* TODO: Check the transformation is defined in pts_attr_simple_comp_evid_pcr_transform_t */
383
384 reader->read_data(reader, PTS_SIMPLE_COMP_EVID_MEASUREMENT_TIME_SIZE,
385 &this->measurement_time);
386
387 /* Optional Policy URI field is included */
388 if(this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_FAIL ||
389 this->flags & PTS_SIMPLE_COMP_EVID_FLAG_VER_PASS)
390 {
391 u_int16_t policy_uri_len;
392 reader->read_uint16(reader, &policy_uri_len);
393 reader->read_data(reader, policy_uri_len, &this->policy_uri);
394 }
395
396 /* Optional PCR value fields are included */
397 if(this->flags & PTS_SIMPLE_COMP_EVID_FLAG_PCR)
398 {
399 u_int16_t pcr_value_len;
400 reader->read_uint16(reader, &pcr_value_len);
401 reader->read_data(reader, pcr_value_len, &this->pcr_before);
402 reader->read_data(reader, pcr_value_len, &this->pcr_after);
403 }
404
405 measurement_len = reader->remaining(reader);
406 reader->read_data(reader, measurement_len, &this->measurement);
407
408 reader->destroy(reader);
409 return SUCCESS;
410 }
411
412 METHOD(pa_tnc_attr_t, destroy, void,
413 private_tcg_pts_attr_simple_comp_evid_t *this)
414 {
415 free(this->value.ptr);
416 free(this->measurement_time.ptr);
417 free(this->policy_uri.ptr);
418 free(this->pcr_before.ptr);
419 free(this->pcr_after.ptr);
420 free(this->measurement.ptr);
421 free(this);
422 }
423
424 METHOD(tcg_pts_attr_simple_comp_evid_t, get_flags, pts_attr_simple_comp_evid_flag_t,
425 private_tcg_pts_attr_simple_comp_evid_t *this)
426 {
427 return this->flags;
428 }
429
430 METHOD(tcg_pts_attr_simple_comp_evid_t, set_flags, void,
431 private_tcg_pts_attr_simple_comp_evid_t *this, pts_attr_simple_comp_evid_flag_t flags)
432 {
433 this->flags = flags;
434 }
435
436 METHOD(tcg_pts_attr_simple_comp_evid_t, get_sub_component_depth, u_int32_t,
437 private_tcg_pts_attr_simple_comp_evid_t *this)
438 {
439 return this->depth;
440 }
441
442 METHOD(tcg_pts_attr_simple_comp_evid_t, get_spec_comp_funct_name_vendor_id, u_int32_t,
443 private_tcg_pts_attr_simple_comp_evid_t *this)
444 {
445 return this->comp_vendor_id;
446 }
447
448 METHOD(tcg_pts_attr_simple_comp_evid_t, get_family, u_int8_t,
449 private_tcg_pts_attr_simple_comp_evid_t *this)
450 {
451 return this->family;
452 }
453
454 METHOD(tcg_pts_attr_simple_comp_evid_t, get_qualifier, tcg_pts_qualifier_t,
455 private_tcg_pts_attr_simple_comp_evid_t *this)
456 {
457 return this->qualifier;
458 }
459
460 METHOD(tcg_pts_attr_simple_comp_evid_t, set_qualifier, void,
461 private_tcg_pts_attr_simple_comp_evid_t *this,
462 tcg_pts_qualifier_t qualifier)
463 {
464 this->qualifier = qualifier;
465 }
466
467 METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_funct_name, pts_attr_req_funct_comp_name_bin_enum_t,
468 private_tcg_pts_attr_simple_comp_evid_t *this)
469 {
470 return this->name;
471 }
472
473 METHOD(tcg_pts_attr_simple_comp_evid_t, set_comp_funct_name, void,
474 private_tcg_pts_attr_simple_comp_evid_t *this, pts_attr_req_funct_comp_name_bin_enum_t name)
475 {
476 this->name = name;
477 }
478
479 METHOD(tcg_pts_attr_simple_comp_evid_t, get_measurement_type, u_int8_t,
480 private_tcg_pts_attr_simple_comp_evid_t *this)
481 {
482 return this->measurement_type;
483 }
484
485 METHOD(tcg_pts_attr_simple_comp_evid_t, get_extended_pcr, u_int32_t,
486 private_tcg_pts_attr_simple_comp_evid_t *this)
487 {
488 return this->extended_pcr;
489 }
490
491 METHOD(tcg_pts_attr_simple_comp_evid_t, set_extended_pcr, void,
492 private_tcg_pts_attr_simple_comp_evid_t *this, u_int32_t extended_pcr)
493 {
494 this->extended_pcr = extended_pcr;
495 }
496
497 METHOD(tcg_pts_attr_simple_comp_evid_t, get_hash_algorithm, pts_attr_meas_algorithms_t,
498 private_tcg_pts_attr_simple_comp_evid_t *this)
499 {
500 return this->hash_algorithm;
501 }
502
503 METHOD(tcg_pts_attr_simple_comp_evid_t, set_hash_algorithm, void,
504 private_tcg_pts_attr_simple_comp_evid_t *this, pts_attr_meas_algorithms_t hash_algorithm)
505 {
506 this->hash_algorithm = hash_algorithm;
507 }
508
509 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_trans, pts_attr_simple_comp_evid_pcr_transform_t,
510 private_tcg_pts_attr_simple_comp_evid_t *this)
511 {
512 return this->transformation;
513 }
514
515 METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_trans, void,
516 private_tcg_pts_attr_simple_comp_evid_t *this, pts_attr_simple_comp_evid_pcr_transform_t transformation)
517 {
518 this->transformation = transformation;
519 }
520
521 METHOD(tcg_pts_attr_simple_comp_evid_t, get_measurement_time, chunk_t,
522 private_tcg_pts_attr_simple_comp_evid_t *this)
523 {
524 return this->measurement_time;
525 }
526
527 METHOD(tcg_pts_attr_simple_comp_evid_t, set_measurement_time, void,
528 private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t measurement_time)
529 {
530 this->measurement_time = measurement_time;
531 }
532
533 METHOD(tcg_pts_attr_simple_comp_evid_t, get_policy_uri, chunk_t,
534 private_tcg_pts_attr_simple_comp_evid_t *this)
535 {
536 return this->policy_uri;
537 }
538
539 METHOD(tcg_pts_attr_simple_comp_evid_t, set_policy_uri, void,
540 private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t policy_uri)
541 {
542 this->policy_uri = policy_uri;
543 }
544
545 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_before_value, chunk_t,
546 private_tcg_pts_attr_simple_comp_evid_t *this)
547 {
548 return this->pcr_before;
549 }
550
551 METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_before_value, void,
552 private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t pcr_before)
553 {
554 this->pcr_before = pcr_before;
555 }
556
557 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_after_value, chunk_t,
558 private_tcg_pts_attr_simple_comp_evid_t *this)
559 {
560 return this->pcr_after;
561 }
562
563 METHOD(tcg_pts_attr_simple_comp_evid_t, set_pcr_after_value, void,
564 private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t pcr_after)
565 {
566 this->pcr_after = pcr_after;
567 }
568
569 METHOD(tcg_pts_attr_simple_comp_evid_t, get_pcr_len, u_int16_t,
570 private_tcg_pts_attr_simple_comp_evid_t *this)
571 {
572 if(this->pcr_before.ptr && this->pcr_after.ptr &&
573 this->pcr_before.len == this->pcr_after.len &&
574 this->pcr_before.len > 0 && this->pcr_after.len > 0)
575 return this->pcr_before.len;
576 else return 0;
577 }
578
579 METHOD(tcg_pts_attr_simple_comp_evid_t, get_comp_measurement, chunk_t,
580 private_tcg_pts_attr_simple_comp_evid_t *this)
581 {
582 return this->measurement;
583 }
584
585 METHOD(tcg_pts_attr_simple_comp_evid_t, set_comp_measurement, void,
586 private_tcg_pts_attr_simple_comp_evid_t *this, chunk_t measurement)
587 {
588 this->measurement = measurement;
589 }
590
591 /**
592 * Described in header.
593 */
594 pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create(
595 pts_attr_simple_comp_evid_flag_t flags,
596 u_int32_t depth,
597 u_int32_t vendor_id,
598 tcg_pts_qualifier_t qualifier,
599 pts_attr_req_funct_comp_name_bin_enum_t name,
600 u_int32_t extended_pcr,
601 pts_attr_meas_algorithms_t hash_algorithm,
602 pts_attr_simple_comp_evid_pcr_transform_t transformation,
603 chunk_t measurement_time,
604 chunk_t policy_uri,
605 chunk_t pcr_before,
606 chunk_t pcr_after,
607 chunk_t measurement)
608 {
609 private_tcg_pts_attr_simple_comp_evid_t *this;
610
611 INIT(this,
612 .public = {
613 .pa_tnc_attribute = {
614 .get_vendor_id = _get_vendor_id,
615 .get_type = _get_type,
616 .get_value = _get_value,
617 .get_noskip_flag = _get_noskip_flag,
618 .set_noskip_flag = _set_noskip_flag,
619 .build = _build,
620 .process = _process,
621 .destroy = _destroy,
622 },
623 .get_flags= _get_flags,
624 .set_flags= _set_flags,
625 .get_sub_component_depth = _get_sub_component_depth,
626 .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
627 .get_family = _get_family,
628 .get_qualifier = _get_qualifier,
629 .set_qualifier = _set_qualifier,
630 .get_comp_funct_name = _get_comp_funct_name,
631 .set_comp_funct_name = _set_comp_funct_name,
632 .get_measurement_type = _get_measurement_type,
633 .get_extended_pcr = _get_extended_pcr,
634 .set_extended_pcr = _set_extended_pcr,
635 .get_hash_algorithm = _get_hash_algorithm,
636 .set_hash_algorithm = _set_hash_algorithm,
637 .get_pcr_trans = _get_pcr_trans,
638 .set_pcr_trans = _set_pcr_trans,
639 .get_measurement_time = _get_measurement_time,
640 .set_measurement_time = _set_measurement_time,
641 .get_policy_uri = _get_policy_uri,
642 .set_policy_uri = _set_policy_uri,
643 .get_pcr_before_value = _get_pcr_before_value,
644 .set_pcr_before_value = _set_pcr_before_value,
645 .get_pcr_after_value = _get_pcr_after_value,
646 .set_pcr_after_value = _set_pcr_after_value,
647 .get_pcr_len = _get_pcr_len,
648 .get_comp_measurement = _get_comp_measurement,
649 .set_comp_measurement = _set_comp_measurement,
650 },
651 .vendor_id = PEN_TCG,
652 .type = TCG_PTS_SIMPLE_COMP_EVID,
653 .flags = flags,
654 .depth = depth,
655 .comp_vendor_id = vendor_id,
656 .family = PTS_REQ_FUNCT_COMP_FAM_BIN_ENUM,
657 .qualifier = qualifier,
658 .name = name,
659 .extended_pcr = extended_pcr,
660 .hash_algorithm = hash_algorithm,
661 .transformation = transformation,
662 .measurement_time = measurement_time,
663 .policy_uri = policy_uri,
664 .pcr_before = pcr_before,
665 .pcr_after = pcr_after,
666 .measurement = measurement,
667 );
668
669 return &this->public.pa_tnc_attribute;
670 }
671
672
673 /**
674 * Described in header.
675 */
676 pa_tnc_attr_t *tcg_pts_attr_simple_comp_evid_create_from_data(chunk_t data)
677 {
678 private_tcg_pts_attr_simple_comp_evid_t *this;
679
680 INIT(this,
681 .public = {
682 .pa_tnc_attribute = {
683 .get_vendor_id = _get_vendor_id,
684 .get_type = _get_type,
685 .get_value = _get_value,
686 .get_noskip_flag = _get_noskip_flag,
687 .set_noskip_flag = _set_noskip_flag,
688 .build = _build,
689 .process = _process,
690 .destroy = _destroy,
691 },
692 .get_flags= _get_flags,
693 .set_flags= _set_flags,
694 .get_sub_component_depth = _get_sub_component_depth,
695 .get_spec_comp_funct_name_vendor_id = _get_spec_comp_funct_name_vendor_id,
696 .get_family = _get_family,
697 .get_qualifier = _get_qualifier,
698 .set_qualifier = _set_qualifier,
699 .get_comp_funct_name = _get_comp_funct_name,
700 .set_comp_funct_name = _set_comp_funct_name,
701 .get_measurement_type = _get_measurement_type,
702 .get_extended_pcr = _get_extended_pcr,
703 .set_extended_pcr = _set_extended_pcr,
704 .get_hash_algorithm = _get_hash_algorithm,
705 .set_hash_algorithm = _set_hash_algorithm,
706 .get_pcr_trans = _get_pcr_trans,
707 .set_pcr_trans = _set_pcr_trans,
708 .get_measurement_time = _get_measurement_time,
709 .set_measurement_time = _set_measurement_time,
710 .get_policy_uri = _get_policy_uri,
711 .set_policy_uri = _set_policy_uri,
712 .get_pcr_before_value = _get_pcr_before_value,
713 .set_pcr_before_value = _set_pcr_before_value,
714 .get_pcr_after_value = _get_pcr_after_value,
715 .set_pcr_after_value = _set_pcr_after_value,
716 .get_pcr_len = _get_pcr_len,
717 .get_comp_measurement = _get_comp_measurement,
718 .set_comp_measurement = _set_comp_measurement,
719 },
720 .vendor_id = PEN_TCG,
721 .type = TCG_PTS_SIMPLE_COMP_EVID,
722 .value = chunk_clone(data),
723 );
724
725 return &this->public.pa_tnc_attribute;
726 }