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