496dc885c7611af393195293521db64eb3c01783
[strongswan.git] / src / libpts / pts / pts.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 "pts.h"
17
18 #include <debug.h>
19 #include <crypto/hashers/hasher.h>
20 #include <bio/bio_writer.h>
21 #include <bio/bio_reader.h>
22
23 #include <trousers/tss.h>
24 #include <trousers/trousers.h>
25
26 #include <sys/stat.h>
27 #include <sys/utsname.h>
28 #include <errno.h>
29
30 #define PTS_BUF_SIZE 4096
31
32 typedef struct private_pts_t private_pts_t;
33
34 /**
35 * Private data of a pts_t object.
36 *
37 */
38 struct private_pts_t {
39
40 /**
41 * Public pts_t interface.
42 */
43 pts_t public;
44
45 /**
46 * PTS Protocol Capabilities
47 */
48 pts_proto_caps_flag_t proto_caps;
49
50 /**
51 * PTS Measurement Algorithm
52 */
53 pts_meas_algorithms_t algorithm;
54
55 /**
56 * DH Hash Algorithm
57 */
58 pts_meas_algorithms_t dh_hash_algorithm;
59
60 /**
61 * PTS Diffie-Hellman Secret
62 */
63 diffie_hellman_t *dh;
64
65 /**
66 * PTS Diffie-Hellman Initiator Nonce
67 */
68 chunk_t initiator_nonce;
69
70 /**
71 * PTS Diffie-Hellman Responder Nonce
72 */
73 chunk_t responder_nonce;
74
75 /**
76 * Secret assessment value to be used for TPM Quote as an external data
77 */
78 chunk_t secret;
79
80 /**
81 * Platform and OS Info
82 */
83 char *platform_info;
84
85 /**
86 * TRUE if IMC-PTS, FALSE if IMV-PTS
87 */
88 bool is_imc;
89
90 /**
91 * Do we have an activated TPM
92 */
93 bool has_tpm;
94
95 /**
96 * Contains a TPM_CAP_VERSION_INFO struct
97 */
98 chunk_t tpm_version_info;
99
100 /**
101 * Contains TSS Blob structure for AIK
102 */
103 chunk_t aik_blob;
104
105 /**
106 * Contains a Attestation Identity Key or Certificate
107 */
108 certificate_t *aik;
109
110 /**
111 * Table of extended PCRs with corresponding values
112 */
113 u_char* pcrs[PCR_MAX_NUM];
114
115 /**
116 * Length of PCR registers
117 */
118 size_t pcr_len;
119
120 /**
121 * Number of extended PCR registers
122 */
123 u_int32_t pcr_count;
124
125 /**
126 * Highest extended PCR register
127 */
128 u_int32_t pcr_max;
129
130 /**
131 * Bitmap of extended PCR registers
132 */
133 u_int8_t pcr_select[PCR_MAX_NUM / 8];
134
135 };
136
137 METHOD(pts_t, get_proto_caps, pts_proto_caps_flag_t,
138 private_pts_t *this)
139 {
140 return this->proto_caps;
141 }
142
143 METHOD(pts_t, set_proto_caps, void,
144 private_pts_t *this, pts_proto_caps_flag_t flags)
145 {
146 this->proto_caps = flags;
147 DBG2(DBG_PTS, "supported PTS protocol capabilities: %s%s%s%s%s",
148 flags & PTS_PROTO_CAPS_C ? "C" : ".",
149 flags & PTS_PROTO_CAPS_V ? "V" : ".",
150 flags & PTS_PROTO_CAPS_D ? "D" : ".",
151 flags & PTS_PROTO_CAPS_T ? "T" : ".",
152 flags & PTS_PROTO_CAPS_X ? "X" : ".");
153 }
154
155 METHOD(pts_t, get_meas_algorithm, pts_meas_algorithms_t,
156 private_pts_t *this)
157 {
158 return this->algorithm;
159 }
160
161 METHOD(pts_t, set_meas_algorithm, void,
162 private_pts_t *this, pts_meas_algorithms_t algorithm)
163 {
164 hash_algorithm_t hash_alg;
165
166 hash_alg = pts_meas_algo_to_hash(algorithm);
167 DBG2(DBG_PTS, "selected PTS measurement algorithm is %N",
168 hash_algorithm_names, hash_alg);
169 if (hash_alg != HASH_UNKNOWN)
170 {
171 this->algorithm = algorithm;
172 }
173 }
174
175 METHOD(pts_t, get_dh_hash_algorithm, pts_meas_algorithms_t,
176 private_pts_t *this)
177 {
178 return this->dh_hash_algorithm;
179 }
180
181 METHOD(pts_t, set_dh_hash_algorithm, void,
182 private_pts_t *this, pts_meas_algorithms_t algorithm)
183 {
184 hash_algorithm_t hash_alg;
185
186 hash_alg = pts_meas_algo_to_hash(algorithm);
187 DBG2(DBG_PTS, "selected DH hash algorithm is %N",
188 hash_algorithm_names, hash_alg);
189 if (hash_alg != HASH_UNKNOWN)
190 {
191 this->dh_hash_algorithm = algorithm;
192 }
193 }
194
195
196 METHOD(pts_t, create_dh_nonce, bool,
197 private_pts_t *this, pts_dh_group_t group, int nonce_len)
198 {
199 diffie_hellman_group_t dh_group;
200 chunk_t *nonce;
201 rng_t *rng;
202
203 dh_group = pts_dh_group_to_ike(group);
204 DBG2(DBG_PTS, "selected PTS DH group is %N",
205 diffie_hellman_group_names, dh_group);
206 DESTROY_IF(this->dh);
207 this->dh = lib->crypto->create_dh(lib->crypto, dh_group);
208
209 rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
210 if (!rng)
211 {
212 DBG1(DBG_PTS, "no rng available");
213 return FALSE;
214 }
215 DBG2(DBG_PTS, "nonce length is %d", nonce_len);
216 nonce = this->is_imc ? &this->responder_nonce : &this->initiator_nonce;
217 chunk_free(nonce);
218 rng->allocate_bytes(rng, nonce_len, nonce);
219 rng->destroy(rng);
220
221 return TRUE;
222 }
223
224 METHOD(pts_t, get_my_public_value, void,
225 private_pts_t *this, chunk_t *value, chunk_t *nonce)
226 {
227 this->dh->get_my_public_value(this->dh, value);
228 *nonce = this->is_imc ? this->responder_nonce : this->initiator_nonce;
229 }
230
231 METHOD(pts_t, set_peer_public_value, void,
232 private_pts_t *this, chunk_t value, chunk_t nonce)
233 {
234 this->dh->set_other_public_value(this->dh, value);
235
236 nonce = chunk_clone(nonce);
237 if (this->is_imc)
238 {
239 this->initiator_nonce = nonce;
240 }
241 else
242 {
243 this->responder_nonce = nonce;
244 }
245 }
246
247 METHOD(pts_t, calculate_secret, bool,
248 private_pts_t *this)
249 {
250 hasher_t *hasher;
251 hash_algorithm_t hash_alg;
252 chunk_t shared_secret;
253
254 /* Check presence of nonces */
255 if (!this->initiator_nonce.len || !this->responder_nonce.len)
256 {
257 DBG1(DBG_PTS, "initiator and/or responder nonce is not available");
258 return FALSE;
259 }
260 DBG3(DBG_PTS, "initiator nonce: %B", &this->initiator_nonce);
261 DBG3(DBG_PTS, "responder nonce: %B", &this->responder_nonce);
262
263 /* Calculate the DH secret */
264 if (this->dh->get_shared_secret(this->dh, &shared_secret) != SUCCESS)
265 {
266 DBG1(DBG_PTS, "shared DH secret computation failed");
267 return FALSE;
268 }
269 DBG3(DBG_PTS, "shared DH secret: %B", &shared_secret);
270
271 /* Calculate the secret assessment value */
272 hash_alg = pts_meas_algo_to_hash(this->dh_hash_algorithm);
273 hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
274
275 hasher->allocate_hash(hasher, chunk_from_chars('1'), NULL);
276 hasher->allocate_hash(hasher, this->initiator_nonce, NULL);
277 hasher->allocate_hash(hasher, this->responder_nonce, NULL);
278 hasher->allocate_hash(hasher, shared_secret, &this->secret);
279 hasher->destroy(hasher);
280
281 /* The DH secret must be destroyed */
282 chunk_clear(&shared_secret);
283
284 /*
285 * Truncate the hash to 20 bytes to fit the ExternalData
286 * argument of the TPM Quote command
287 */
288 this->secret.len = min(this->secret.len, 20);
289 DBG3(DBG_PTS, "secret assessment value: %B", &this->secret);
290 return TRUE;
291 }
292
293 /**
294 * Print TPM 1.2 Version Info
295 */
296 static void print_tpm_version_info(private_pts_t *this)
297 {
298 TPM_CAP_VERSION_INFO versionInfo;
299 UINT64 offset = 0;
300 TSS_RESULT result;
301
302 result = Trspi_UnloadBlob_CAP_VERSION_INFO(&offset,
303 this->tpm_version_info.ptr, &versionInfo);
304 if (result != TSS_SUCCESS)
305 {
306 DBG1(DBG_PTS, "could not parse tpm version info: tss error 0x%x",
307 result);
308 }
309 else
310 {
311 DBG2(DBG_PTS, "TPM 1.2 Version Info: Chip Version: %hhu.%hhu.%hhu.%hhu,"
312 " Spec Level: %hu, Errata Rev: %hhu, Vendor ID: %.4s",
313 versionInfo.version.major, versionInfo.version.minor,
314 versionInfo.version.revMajor, versionInfo.version.revMinor,
315 versionInfo.specLevel, versionInfo.errataRev,
316 versionInfo.tpmVendorID);
317 }
318 }
319
320 METHOD(pts_t, get_platform_info, char*,
321 private_pts_t *this)
322 {
323 return this->platform_info;
324 }
325
326 METHOD(pts_t, set_platform_info, void,
327 private_pts_t *this, char *info)
328 {
329 free(this->platform_info);
330 this->platform_info = strdup(info);
331 }
332
333 METHOD(pts_t, get_tpm_version_info, bool,
334 private_pts_t *this, chunk_t *info)
335 {
336 if (!this->has_tpm)
337 {
338 return FALSE;
339 }
340 *info = this->tpm_version_info;
341 print_tpm_version_info(this);
342 return TRUE;
343 }
344
345 METHOD(pts_t, set_tpm_version_info, void,
346 private_pts_t *this, chunk_t info)
347 {
348 this->tpm_version_info = chunk_clone(info);
349 print_tpm_version_info(this);
350 }
351
352 /**
353 * Load an AIK Blob (TSS_TSPATTRIB_KEYBLOB_BLOB attribute)
354 */
355 static void load_aik_blob(private_pts_t *this)
356 {
357 char *blob_path;
358 FILE *fp;
359 u_int32_t aikBlobLen;
360
361 blob_path = lib->settings->get_str(lib->settings,
362 "libimcv.plugins.imc-attestation.aik_blob", NULL);
363
364 if (blob_path)
365 {
366 /* Read aik key blob from a file */
367 if ((fp = fopen(blob_path, "r")) == NULL)
368 {
369 DBG1(DBG_PTS, "unable to open AIK Blob file: %s", blob_path);
370 return;
371 }
372
373 fseek(fp, 0, SEEK_END);
374 aikBlobLen = ftell(fp);
375 fseek(fp, 0L, SEEK_SET);
376
377 this->aik_blob = chunk_alloc(aikBlobLen);
378 if (fread(this->aik_blob.ptr, 1, aikBlobLen, fp))
379 {
380 DBG2(DBG_PTS, "loaded AIK Blob from '%s'", blob_path);
381 DBG3(DBG_PTS, "AIK Blob: %B", &this->aik_blob);
382 }
383 else
384 {
385 DBG1(DBG_PTS, "unable to read AIK Blob file '%s'", blob_path);
386 }
387 fclose(fp);
388 return;
389 }
390
391 DBG1(DBG_PTS, "AIK Blob is not available");
392 }
393
394 /**
395 * Load an AIK certificate or public key
396 * the certificate having precedence over the public key if both are present
397 */
398 static void load_aik(private_pts_t *this)
399 {
400 char *cert_path, *key_path;
401
402 cert_path = lib->settings->get_str(lib->settings,
403 "libimcv.plugins.imc-attestation.aik_cert", NULL);
404 key_path = lib->settings->get_str(lib->settings,
405 "libimcv.plugins.imc-attestation.aik_key", NULL);
406
407 if (cert_path)
408 {
409 this->aik = lib->creds->create(lib->creds, CRED_CERTIFICATE,
410 CERT_X509, BUILD_FROM_FILE,
411 cert_path, BUILD_END);
412 if (this->aik)
413 {
414 DBG2(DBG_PTS, "loaded AIK certificate from '%s'", cert_path);
415 return;
416 }
417 }
418 if (key_path)
419 {
420 this->aik = lib->creds->create(lib->creds, CRED_CERTIFICATE,
421 CERT_TRUSTED_PUBKEY, BUILD_FROM_FILE,
422 key_path, BUILD_END);
423 if (this->aik)
424 {
425 DBG2(DBG_PTS, "loaded AIK public key from '%s'", key_path);
426 return;
427 }
428 }
429
430 DBG1(DBG_PTS, "neither AIK certificate nor public key is available");
431 }
432
433 METHOD(pts_t, get_aik, certificate_t*,
434 private_pts_t *this)
435 {
436 return this->aik;
437 }
438
439 METHOD(pts_t, set_aik, void,
440 private_pts_t *this, certificate_t *aik)
441 {
442 DESTROY_IF(this->aik);
443 this->aik = aik->get_ref(aik);
444 }
445
446 METHOD(pts_t, hash_file, bool,
447 private_pts_t *this, hasher_t *hasher, char *pathname, u_char *hash)
448 {
449 u_char buffer[PTS_BUF_SIZE];
450 FILE *file;
451 int bytes_read;
452
453 file = fopen(pathname, "rb");
454 if (!file)
455 {
456 DBG1(DBG_PTS," file '%s' can not be opened, %s", pathname,
457 strerror(errno));
458 return FALSE;
459 }
460 while (TRUE)
461 {
462 bytes_read = fread(buffer, 1, sizeof(buffer), file);
463 if (bytes_read > 0)
464 {
465 hasher->get_hash(hasher, chunk_create(buffer, bytes_read), NULL);
466 }
467 else
468 {
469 hasher->get_hash(hasher, chunk_empty, hash);
470 break;
471 }
472 }
473 fclose(file);
474
475 return TRUE;
476 }
477
478 /**
479 * Get the relative filename of a fully qualified file pathname
480 */
481 static char* get_filename(char *pathname)
482 {
483 char *pos, *filename;
484
485 pos = filename = pathname;
486 while (pos && *(++pos) != '\0')
487 {
488 filename = pos;
489 pos = strchr(filename, '/');
490 }
491 return filename;
492 }
493
494 METHOD(pts_t, is_path_valid, bool,
495 private_pts_t *this, char *path, pts_error_code_t *error_code)
496 {
497 struct stat st;
498
499 *error_code = 0;
500
501 if (!stat(path, &st))
502 {
503 return TRUE;
504 }
505 else if (errno == ENOENT || errno == ENOTDIR)
506 {
507 DBG1(DBG_PTS, "file/directory does not exist %s", path);
508 *error_code = TCG_PTS_FILE_NOT_FOUND;
509 }
510 else if (errno == EFAULT)
511 {
512 DBG1(DBG_PTS, "bad address %s", path);
513 *error_code = TCG_PTS_INVALID_PATH;
514 }
515 else
516 {
517 DBG1(DBG_PTS, "error: %s occured while validating path: %s",
518 strerror(errno), path);
519 return FALSE;
520 }
521
522 return TRUE;
523 }
524
525 METHOD(pts_t, do_measurements, pts_file_meas_t*,
526 private_pts_t *this, u_int16_t request_id, char *pathname, bool is_directory)
527 {
528 hasher_t *hasher;
529 hash_algorithm_t hash_alg;
530 u_char hash[HASH_SIZE_SHA384];
531 chunk_t measurement;
532 pts_file_meas_t *measurements;
533
534 /* Create a hasher */
535 hash_alg = pts_meas_algo_to_hash(this->algorithm);
536 hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
537 if (!hasher)
538 {
539 DBG1(DBG_PTS, "hasher %N not available", hash_algorithm_names, hash_alg);
540 return NULL;
541 }
542
543 /* Create a measurement object */
544 measurements = pts_file_meas_create(request_id);
545
546 /* Link the hash to the measurement and set the measurement length */
547 measurement = chunk_create(hash, hasher->get_hash_size(hasher));
548
549 if (is_directory)
550 {
551 enumerator_t *enumerator;
552 char *rel_name, *abs_name;
553 struct stat st;
554
555 enumerator = enumerator_create_directory(pathname);
556 if (!enumerator)
557 {
558 DBG1(DBG_PTS," directory '%s' can not be opened, %s", pathname,
559 strerror(errno));
560 hasher->destroy(hasher);
561 measurements->destroy(measurements);
562 return NULL;
563 }
564 while (enumerator->enumerate(enumerator, &rel_name, &abs_name, &st))
565 {
566 /* measure regular files only */
567 if (S_ISREG(st.st_mode) && *rel_name != '.')
568 {
569 if (!hash_file(this, hasher, abs_name, hash))
570 {
571 enumerator->destroy(enumerator);
572 hasher->destroy(hasher);
573 measurements->destroy(measurements);
574 return NULL;
575 }
576 DBG2(DBG_PTS, " %#B for '%s'", &measurement, rel_name);
577 measurements->add(measurements, rel_name, measurement);
578 }
579 }
580 enumerator->destroy(enumerator);
581 }
582 else
583 {
584 char *filename;
585
586 if (!hash_file(this, hasher, pathname, hash))
587 {
588 hasher->destroy(hasher);
589 measurements->destroy(measurements);
590 return NULL;
591 }
592 filename = get_filename(pathname);
593 DBG2(DBG_PTS, " %#B for '%s'", &measurement, filename);
594 measurements->add(measurements, filename, measurement);
595 }
596 hasher->destroy(hasher);
597
598 return measurements;
599 }
600
601 /**
602 * Obtain statistical information describing a file
603 */
604 static bool file_metadata(char *pathname, pts_file_metadata_t **entry)
605 {
606 struct stat st;
607 pts_file_metadata_t *this;
608
609 this = malloc_thing(pts_file_metadata_t);
610
611 if (stat(pathname, &st))
612 {
613 DBG1(DBG_PTS, "Unable to obtain statistics about '%s'", pathname);
614 return FALSE;
615 }
616
617 if (S_ISREG(st.st_mode))
618 {
619 this->type = PTS_FILE_REGULAR;
620 }
621 else if (S_ISDIR(st.st_mode))
622 {
623 this->type = PTS_FILE_DIRECTORY;
624 }
625 else if (S_ISCHR(st.st_mode))
626 {
627 this->type = PTS_FILE_CHAR_SPEC;
628 }
629 else if (S_ISBLK(st.st_mode))
630 {
631 this->type = PTS_FILE_BLOCK_SPEC;
632 }
633 else if (S_ISFIFO(st.st_mode))
634 {
635 this->type = PTS_FILE_FIFO;
636 }
637 else if (S_ISLNK(st.st_mode))
638 {
639 this->type = PTS_FILE_SYM_LINK;
640 }
641 else if (S_ISSOCK(st.st_mode))
642 {
643 this->type = PTS_FILE_SOCKET;
644 }
645 else
646 {
647 this->type = PTS_FILE_OTHER;
648 }
649
650 this->filesize = st.st_size;
651 this->created = st.st_ctime;
652 this->modified = st.st_mtime;
653 this->accessed = st.st_atime;
654 this->owner = st.st_uid;
655 this->group = st.st_gid;
656
657 *entry = this;
658 return TRUE;
659 }
660
661 METHOD(pts_t, get_metadata, pts_file_meta_t*,
662 private_pts_t *this, char *pathname, bool is_directory)
663 {
664 pts_file_meta_t *metadata;
665 pts_file_metadata_t *entry;
666
667 /* Create a metadata object */
668 metadata = pts_file_meta_create();
669
670 if (is_directory)
671 {
672 enumerator_t *enumerator;
673 char *rel_name, *abs_name;
674 struct stat st;
675
676 enumerator = enumerator_create_directory(pathname);
677 if (!enumerator)
678 {
679 DBG1(DBG_PTS," directory '%s' can not be opened, %s", pathname,
680 strerror(errno));
681 metadata->destroy(metadata);
682 return NULL;
683 }
684 while (enumerator->enumerate(enumerator, &rel_name, &abs_name, &st))
685 {
686 /* measure regular files only */
687 if (S_ISREG(st.st_mode) && *rel_name != '.')
688 {
689 if (!file_metadata(abs_name, &entry))
690 {
691 enumerator->destroy(enumerator);
692 metadata->destroy(metadata);
693 return NULL;
694 }
695 entry->filename = strdup(rel_name);
696 metadata->add(metadata, entry);
697 }
698 }
699 enumerator->destroy(enumerator);
700 }
701 else
702 {
703 if (!file_metadata(pathname, &entry))
704 {
705 metadata->destroy(metadata);
706 return NULL;
707 }
708 entry->filename = strdup(get_filename(pathname));
709 metadata->add(metadata, entry);
710 }
711
712 return metadata;
713 }
714
715 METHOD(pts_t, read_pcr, bool,
716 private_pts_t *this, u_int32_t pcr_num, chunk_t *pcr_value)
717 {
718 TSS_HCONTEXT hContext;
719 TSS_HTPM hTPM;
720 TSS_RESULT result;
721 chunk_t rgbPcrValue;
722
723 bool success = FALSE;
724
725 result = Tspi_Context_Create(&hContext);
726 if (result != TSS_SUCCESS)
727 {
728 DBG1(DBG_PTS, "TPM context could not be created: tss error 0x%x", result);
729 return FALSE;
730 }
731
732 result = Tspi_Context_Connect(hContext, NULL);
733 if (result != TSS_SUCCESS)
734 {
735 goto err;
736 }
737 result = Tspi_Context_GetTpmObject (hContext, &hTPM);
738 if (result != TSS_SUCCESS)
739 {
740 goto err;
741 }
742 result = Tspi_TPM_PcrRead(hTPM, pcr_num, (UINT32*)&rgbPcrValue.len, &rgbPcrValue.ptr);
743 if (result != TSS_SUCCESS)
744 {
745 goto err;
746 }
747 *pcr_value = chunk_clone(rgbPcrValue);
748 DBG3(DBG_PTS, "PCR %d value:%B", pcr_num, pcr_value);
749 success = TRUE;
750
751 err:
752 if (!success)
753 {
754 DBG1(DBG_PTS, "TPM not available: tss error 0x%x", result);
755 }
756 Tspi_Context_FreeMemory(hContext, NULL);
757 Tspi_Context_Close(hContext);
758
759 return success;
760 }
761
762 METHOD(pts_t, extend_pcr, bool,
763 private_pts_t *this, u_int32_t pcr_num, chunk_t input, chunk_t *output)
764 {
765 TSS_HCONTEXT hContext;
766 TSS_HTPM hTPM;
767 TSS_RESULT result;
768 u_int32_t pcr_length;
769 chunk_t pcr_value;
770
771 result = Tspi_Context_Create(&hContext);
772 if (result != TSS_SUCCESS)
773 {
774 DBG1(DBG_PTS, "TPM context could not be created: tss error 0x%x",
775 result);
776 return FALSE;
777 }
778 result = Tspi_Context_Connect(hContext, NULL);
779 if (result != TSS_SUCCESS)
780 {
781 goto err;
782 }
783 result = Tspi_Context_GetTpmObject (hContext, &hTPM);
784 if (result != TSS_SUCCESS)
785 {
786 goto err;
787 }
788
789 pcr_value = chunk_alloc(PCR_LEN);
790 result = Tspi_TPM_PcrExtend(hTPM, pcr_num, PCR_LEN, input.ptr,
791 NULL, &pcr_length, &pcr_value.ptr);
792 if (result != TSS_SUCCESS)
793 {
794 goto err;
795 }
796
797 *output = pcr_value;
798 *output = chunk_clone(*output);
799
800 DBG3(DBG_PTS, "PCR %d extended with: %B", pcr_num, &input);
801 DBG3(DBG_PTS, "PCR %d value after extend: %B", pcr_num, output);
802
803 chunk_clear(&pcr_value);
804 Tspi_Context_FreeMemory(hContext, NULL);
805 Tspi_Context_Close(hContext);
806
807 return TRUE;
808
809 err:
810 DBG1(DBG_PTS, "TPM not available: tss error 0x%x", result);
811
812 chunk_clear(&pcr_value);
813 Tspi_Context_FreeMemory(hContext, NULL);
814 Tspi_Context_Close(hContext);
815
816 return FALSE;
817 }
818
819
820 static void clear_pcrs(private_pts_t *this)
821 {
822 int i;
823
824 for (i = 0; i <= this->pcr_max; i++)
825 {
826 free(this->pcrs[i]);
827 this->pcrs[i] = NULL;
828 }
829 this->pcr_count = 0;
830 this->pcr_max = 0;
831
832 memset(this->pcr_select, 0x00, sizeof(this->pcr_select));
833 }
834
835 METHOD(pts_t, quote_tpm, bool,
836 private_pts_t *this, bool use_quote2, chunk_t *pcr_comp, chunk_t *quote_sig)
837 {
838 TSS_HCONTEXT hContext;
839 TSS_HTPM hTPM;
840 TSS_HKEY hAIK;
841 TSS_HKEY hSRK;
842 TSS_HPOLICY srkUsagePolicy;
843 TSS_UUID SRK_UUID = TSS_UUID_SRK;
844 BYTE secret[] = TSS_WELL_KNOWN_SECRET;
845 TSS_HPCRS hPcrComposite;
846 TSS_VALIDATION valData;
847 TSS_RESULT result;
848 chunk_t quote_info;
849 BYTE* versionInfo;
850 u_int32_t versionInfoSize, pcr, i = 0, f = 1;
851 bool success = FALSE;
852
853 result = Tspi_Context_Create(&hContext);
854 if (result != TSS_SUCCESS)
855 {
856 DBG1(DBG_PTS, "TPM context could not be created: tss error 0x%x",
857 result);
858 return FALSE;
859 }
860 result = Tspi_Context_Connect(hContext, NULL);
861 if (result != TSS_SUCCESS)
862 {
863 goto err1;
864 }
865 result = Tspi_Context_GetTpmObject (hContext, &hTPM);
866 if (result != TSS_SUCCESS)
867 {
868 goto err1;
869 }
870
871 /* Retrieve SRK from TPM and set the authentication to well known secret*/
872 result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
873 SRK_UUID, &hSRK);
874 if (result != TSS_SUCCESS)
875 {
876 goto err1;
877 }
878
879 result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &srkUsagePolicy);
880 if (result != TSS_SUCCESS)
881 {
882 goto err1;
883 }
884 result = Tspi_Policy_SetSecret(srkUsagePolicy, TSS_SECRET_MODE_SHA1,
885 20, secret);
886 if (result != TSS_SUCCESS)
887 {
888 goto err1;
889 }
890
891 result = Tspi_Context_LoadKeyByBlob (hContext, hSRK, this->aik_blob.len,
892 this->aik_blob.ptr, &hAIK);
893 if (result != TSS_SUCCESS)
894 {
895 goto err1;
896 }
897
898 /* Create PCR composite object */
899 result = use_quote2 ?
900 Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_PCRS,
901 TSS_PCRS_STRUCT_INFO_SHORT, &hPcrComposite) :
902 Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_PCRS,
903 0, &hPcrComposite);
904 if (result != TSS_SUCCESS)
905 {
906 goto err2;
907 }
908
909 /* Select PCRs */
910 for (pcr = 0; pcr <= this->pcr_max ; pcr++)
911 {
912 if (f == 256)
913 {
914 i++;
915 f = 1;
916 }
917 if (this->pcr_select[i] & f)
918 {
919 DBG2(DBG_TNC, "PCR %02d selected for TPM Quote", pcr);
920 result = use_quote2 ?
921 Tspi_PcrComposite_SelectPcrIndexEx(hPcrComposite, pcr,
922 TSS_PCRS_DIRECTION_RELEASE) :
923 Tspi_PcrComposite_SelectPcrIndex(hPcrComposite, pcr);
924 if (result != TSS_SUCCESS)
925 {
926 goto err3;
927 }
928 }
929 f <<= 1;
930 }
931
932 /* Set the Validation Data */
933 valData.ulExternalDataLength = this->secret.len;
934 valData.rgbExternalData = (BYTE *)this->secret.ptr;
935
936
937 /* TPM Quote */
938 result = use_quote2 ?
939 Tspi_TPM_Quote2(hTPM, hAIK, FALSE, hPcrComposite, &valData,
940 &versionInfoSize, &versionInfo):
941 Tspi_TPM_Quote(hTPM, hAIK, hPcrComposite, &valData);
942 if (result != TSS_SUCCESS)
943 {
944 goto err4;
945 }
946
947 /* Set output chunks */
948 *pcr_comp = chunk_alloc(HASH_SIZE_SHA1);
949
950 if (use_quote2)
951 {
952 /* TPM_Composite_Hash is last 20 bytes of TPM_Quote_Info2 structure */
953 memcpy(pcr_comp->ptr, valData.rgbData + valData.ulDataLength - HASH_SIZE_SHA1,
954 HASH_SIZE_SHA1);
955 }
956 else
957 {
958 /* TPM_Composite_Hash is 8-28th bytes of TPM_Quote_Info structure */
959 memcpy(pcr_comp->ptr, valData.rgbData + 8, HASH_SIZE_SHA1);
960 }
961 DBG3(DBG_PTS, "Hash of PCR Composite: %#B", pcr_comp);
962
963 quote_info = chunk_create(valData.rgbData, valData.ulDataLength);
964 DBG3(DBG_PTS, "TPM Quote Info: %B",&quote_info);
965
966 *quote_sig = chunk_clone(chunk_create(valData.rgbValidationData,
967 valData.ulValidationDataLength));
968 DBG3(DBG_PTS, "TPM Quote Signature: %B",quote_sig);
969
970 success = TRUE;
971
972 /* Cleanup */
973 err4:
974 Tspi_Context_FreeMemory(hContext, NULL);
975
976 err3:
977 Tspi_Context_CloseObject(hContext, hPcrComposite);
978
979 err2:
980 Tspi_Context_CloseObject(hContext, hAIK);
981
982 err1:
983 Tspi_Context_Close(hContext);
984
985 if (!success)
986 {
987 DBG1(DBG_PTS, "TPM not available: tss error 0x%x", result);
988 }
989 clear_pcrs(this);
990
991 return success;
992 }
993
994 METHOD(pts_t, select_pcr, bool,
995 private_pts_t *this, u_int32_t pcr)
996 {
997 u_int32_t i, f;
998
999 if (pcr >= PCR_MAX_NUM)
1000 {
1001 DBG1(DBG_PTS, "PCR %u: number is larger than maximum of %u",
1002 pcr, PCR_MAX_NUM-1);
1003 return FALSE;
1004 }
1005
1006 /* Determine PCR selection flag */
1007 i = pcr / 8;
1008 f = 1 << (pcr - 8*i);
1009
1010 /* Has this PCR already been selected? */
1011 if (!(this->pcr_select[i] & f))
1012 {
1013 this->pcr_select[i] |= f;
1014 this->pcr_max = max(this->pcr_max, pcr);
1015 this->pcr_count++;
1016 }
1017
1018 return TRUE;
1019 }
1020
1021 METHOD(pts_t, add_pcr, bool,
1022 private_pts_t *this, u_int32_t pcr, chunk_t pcr_before, chunk_t pcr_after)
1023 {
1024 if (pcr >= PCR_MAX_NUM)
1025 {
1026 DBG1(DBG_PTS, "PCR %u: number is larger than maximum of %u",
1027 pcr, PCR_MAX_NUM-1);
1028 return FALSE;
1029 }
1030
1031 /* Is the length of the PCR registers already set? */
1032 if (this->pcr_len)
1033 {
1034 if (pcr_after.len != this->pcr_len)
1035 {
1036 DBG1(DBG_PTS, "PCR %02u: length is %d bytes but should be %d bytes",
1037 pcr_after.len, this->pcr_len);
1038 return FALSE;
1039 }
1040 }
1041 else
1042 {
1043 this->pcr_len = pcr_after.len;
1044 }
1045
1046 /* Has the value of the PCR register already been assigned? */
1047 if (this->pcrs[pcr])
1048 {
1049 if (!memeq(this->pcrs[pcr], pcr_before.ptr, this->pcr_len))
1050 {
1051 DBG1(DBG_PTS, "PCR %02u: new pcr_before value does not equal "
1052 "old pcr_after value");
1053 }
1054 /* remove the old PCR value */
1055 free(this->pcrs[pcr]);
1056 }
1057 else
1058 {
1059 /* add extended PCR Register */
1060 this->pcr_select[pcr / 8] |= 1 << (pcr % 8);
1061 this->pcr_max = max(this->pcr_max, pcr);
1062 this->pcr_count++;
1063 }
1064
1065 /* Duplicate and store current PCR value */
1066 pcr_after = chunk_clone(pcr_after);
1067 this->pcrs[pcr] = pcr_after.ptr;
1068
1069 return TRUE;
1070 }
1071
1072 METHOD(pts_t, does_pcr_value_match, bool,
1073 private_pts_t *this, chunk_t pcr_after_value)
1074 {
1075 enumerator_t *e;
1076 pcr_entry_t *entry;
1077
1078 if (!this->pcrs)
1079 {
1080 this->pcrs = linked_list_create();
1081 }
1082
1083 e = this->pcrs->create_enumerator(this->pcrs);
1084 while (e->enumerate(e, &entry))
1085 {
1086 if (entry->pcr_number == new->pcr_number)
1087 {
1088 DBG4(DBG_PTS, "updating already added PCR%d value",
1089 entry->pcr_number);
1090 this->pcrs->remove_at(this->pcrs, e);
1091 free(entry);
1092 break;
1093 }
1094 }
1095 DESTROY_IF(e);
1096 this->pcrs->insert_last(this->pcrs, new);
1097 }
1098
1099 /**
1100 * TPM_QUOTE_INFO structure:
1101 * 4 bytes of version
1102 * 4 bytes 'Q' 'U' 'O' 'T'
1103 * 20 byte SHA1 of TCPA_PCR_COMPOSITE
1104 * 20 byte nonce
1105 *
1106 * TPM_QUOTE_INFO2 structure:
1107 * 2 bytes Tag 0x0036 TPM_Tag_Quote_info2
1108 * 4 bytes 'Q' 'U' 'T' '2'
1109 * 20 bytes nonce
1110 * 26 bytes PCR_INFO_SHORT
1111 */
1112
1113 METHOD(pts_t, get_quote_info, bool,
1114 private_pts_t *this, bool use_quote2, bool use_ver_info,
1115 pts_meas_algorithms_t comp_hash_algo,
1116 chunk_t *out_pcr_comp, chunk_t *out_quote_info)
1117 {
1118 u_int8_t size_of_select;
1119 int pcr_comp_len, i;
1120 chunk_t pcr_comp, hash_pcr_comp;
1121 bio_writer_t *writer;
1122 hasher_t *hasher;
1123
1124 if (this->pcr_count == 0)
1125 {
1126 DBG1(DBG_PTS, "No extended PCR entries available, "
1127 "unable to construct TPM Quote Info");
1128 return FALSE;
1129 }
1130 if (!this->secret.ptr)
1131 {
1132 DBG1(DBG_PTS, "Secret assessment value unavailable, ",
1133 "unable to construct TPM Quote Info");
1134 return FALSE;
1135 }
1136 if (use_quote2 && use_ver_info && !this->tpm_version_info.ptr)
1137 {
1138 DBG1(DBG_PTS, "TPM Version Information unavailable, ",
1139 "unable to construct TPM Quote Info2");
1140 return FALSE;
1141 }
1142
1143 size_of_select = 1 + this->pcr_max / 8;
1144 pcr_comp_len = 2 + size_of_select + 4 + this->pcr_count * this->pcr_len;
1145
1146 writer = bio_writer_create(pcr_comp_len);
1147
1148 writer->write_uint16(writer, size_of_select);
1149 for (i = 0; i < size_of_select; i++)
1150 {
1151 writer->write_uint8(writer, this->pcr_select[i]);
1152 }
1153
1154 writer->write_uint32(writer, this->pcr_count * this->pcr_len);
1155 for (i = 0; i < 8 * size_of_select; i++)
1156 {
1157 if (this->pcrs[i])
1158 {
1159 writer->write_data(writer, chunk_create(this->pcrs[i], this->pcr_len));
1160 }
1161 }
1162 pcr_comp = chunk_clone(writer->get_buf(writer));
1163 DBG3(DBG_PTS, "constructed PCR Composite: %B", &pcr_comp);
1164
1165 writer->destroy(writer);
1166
1167 /* Output the TPM_PCR_COMPOSITE expected from IMC */
1168 if (comp_hash_algo)
1169 {
1170 hash_algorithm_t algo;
1171
1172 algo = pts_meas_algo_to_hash(comp_hash_algo);
1173 hasher = lib->crypto->create_hasher(lib->crypto, algo);
1174
1175 /* Hash the PCR Composite Structure */
1176 hasher->allocate_hash(hasher, pcr_comp, out_pcr_comp);
1177 DBG3(DBG_PTS, "constructed PCR Composite hash: %#B", out_pcr_comp);
1178 hasher->destroy(hasher);
1179 }
1180 else
1181 {
1182 *out_pcr_comp = chunk_clone(pcr_comp);
1183 }
1184
1185 /* SHA1 hash of PCR Composite to construct TPM_QUOTE_INFO */
1186 hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
1187 hasher->allocate_hash(hasher, pcr_comp, &hash_pcr_comp);
1188 hasher->destroy(hasher);
1189
1190 writer->write_data(writer, hash_pcr_composite);
1191 chunk_clear(&pcr_composite);
1192 chunk_clear(&hash_pcr_composite);
1193
1194 /* Hash the PCR Composite Structure */
1195 hasher->allocate_hash(hasher, pcr_composite, out_pcr_composite);
1196 DBG4(DBG_PTS, "Hash of calculated PCR Composite: %B", out_pcr_composite);
1197 hasher->destroy(hasher);
1198 }
1199 else
1200 {
1201 *out_pcr_composite = chunk_clone(pcr_composite);
1202 DBG3(DBG_PTS, "calculated PCR Composite: %B", out_pcr_composite);
1203 }
1204
1205 /* SHA1 hash of PCR Composite to construct TPM_QUOTE_INFO */
1206 hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
1207 hasher->allocate_hash(hasher, pcr_composite, &hash_pcr_composite);
1208 hasher->destroy(hasher);
1209
1210 /* Construct TPM_QUOTE_INFO/TPM_QUOTE_INFO2 structure */
1211 writer = bio_writer_create(TPM_QUOTE_INFO_LEN);
1212
1213 if (use_quote2)
1214 {
1215 /* TPM Structure Tag */
1216 writer->write_uint16(writer, TPM_TAG_QUOTE_INFO2);
1217
1218 /* Magic QUT2 value */
1219 writer->write_data(writer, chunk_create("QUT2", 4));
1220
1221 /* Secret assessment value 20 bytes (nonce) */
1222 writer->write_data(writer, this->secret);
1223
1224 /* Length of the PCR selection field */
1225 writer->write_uint16(writer, size_of_select);
1226
1227 /* PCR selection */
1228 for (i = 0; i < size_of_select ; i++)
1229 {
1230 writer->write_uint8(writer, this->pcr_select[i]);
1231 }
1232
1233 /* TPM Locality Selection */
1234 writer->write_uint8(writer, TPM_LOC_ZERO);
1235
1236 /* PCR Composite Hash */
1237 writer->write_data(writer, hash_pcr_comp);
1238
1239 if (use_ver_info)
1240 {
1241 /* TPM version Info */
1242 writer->write_data(writer, this->tpm_version_info);
1243 }
1244 }
1245 else
1246 {
1247 /* Version number */
1248 writer->write_data(writer, chunk_from_chars(1, 1, 0, 0));
1249
1250 /* Magic QUOT value */
1251 writer->write_data(writer, chunk_create("QUOT", 4));
1252
1253 /* PCR Composite Hash */
1254 writer->write_data(writer, hash_pcr_comp);
1255
1256 /* Secret assessment value 20 bytes (nonce) */
1257 writer->write_data(writer, this->secret);
1258 }
1259
1260 /* TPM Quote Info */
1261 *out_quote_info = chunk_clone(writer->get_buf(writer));
1262 DBG3(DBG_PTS, "constructed TPM Quote Info: %B", out_quote_info);
1263
1264 writer->destroy(writer);
1265 free(pcr_comp.ptr);
1266 free(hash_pcr_comp.ptr);
1267 clear_pcrs(this);
1268
1269 return TRUE;
1270 }
1271
1272 METHOD(pts_t, verify_quote_signature, bool,
1273 private_pts_t *this, chunk_t data, chunk_t signature)
1274 {
1275 public_key_t *aik_pub_key;
1276
1277 aik_pub_key = this->aik->get_public_key(this->aik);
1278 if (!aik_pub_key)
1279 {
1280 DBG1(DBG_PTS, "failed to get public key from AIK certificate");
1281 return FALSE;
1282 }
1283
1284 if (!aik_pub_key->verify(aik_pub_key, SIGN_RSA_EMSA_PKCS1_SHA1,
1285 data, signature))
1286 {
1287 DBG1(DBG_PTS, "signature verification failed for TPM Quote Info");
1288 DESTROY_IF(aik_pub_key);
1289 return FALSE;
1290 }
1291 */
1292
1293 if (!aik_pub_key->get_encoding(aik_pub_key,
1294 PUBKEY_SPKI_ASN1_DER, &key_encoding))
1295 {
1296 DBG1(DBG_PTS, "failed to get encoding of AIK public key");
1297 goto cleanup;
1298 }
1299
1300 aik_pub_key->destroy(aik_pub_key);
1301 return TRUE;
1302 }
1303
1304 METHOD(pts_t, destroy, void,
1305 private_pts_t *this)
1306 {
1307 clear_pcrs(this);
1308 DESTROY_IF(this->aik);
1309 DESTROY_IF(this->dh);
1310 free(this->initiator_nonce.ptr);
1311 free(this->responder_nonce.ptr);
1312 free(this->secret.ptr);
1313 free(this->platform_info);
1314 free(this->aik_blob.ptr);
1315 free(this->tpm_version_info.ptr);
1316 free(this);
1317 }
1318
1319 /**
1320 * Determine Linux distribution and hardware platform
1321 */
1322 static char* extract_platform_info(void)
1323 {
1324 FILE *file;
1325 char buf[BUF_LEN], *pos, *value = NULL;
1326 int i, len;
1327 struct utsname uninfo;
1328
1329 /* Linux/Unix distribution release info (from http://linuxmafia.com) */
1330 const char* releases[] = {
1331 "/etc/lsb-release", "/etc/debian_version",
1332 "/etc/SuSE-release", "/etc/novell-release",
1333 "/etc/sles-release", "/etc/redhat-release",
1334 "/etc/fedora-release", "/etc/gentoo-release",
1335 "/etc/slackware-version", "/etc/annvix-release",
1336 "/etc/arch-release", "/etc/arklinux-release",
1337 "/etc/aurox-release", "/etc/blackcat-release",
1338 "/etc/cobalt-release", "/etc/conectiva-release",
1339 "/etc/debian_release", "/etc/immunix-release",
1340 "/etc/lfs-release", "/etc/linuxppc-release",
1341 "/etc/mandrake-release", "/etc/mandriva-release",
1342 "/etc/mandrakelinux-release", "/etc/mklinux-release",
1343 "/etc/pld-release", "/etc/redhat_version",
1344 "/etc/slackware-release", "/etc/e-smith-release",
1345 "/etc/release", "/etc/sun-release",
1346 "/etc/tinysofa-release", "/etc/turbolinux-release",
1347 "/etc/ultrapenguin-release", "/etc/UnitedLinux-release",
1348 "/etc/va-release", "/etc/yellowdog-release"
1349 };
1350
1351 const char description[] = "DISTRIB_DESCRIPTION=\"";
1352
1353 for (i = 0; i < countof(releases); i++)
1354 {
1355 file = fopen(releases[i], "r");
1356 if (!file)
1357 {
1358 continue;
1359 }
1360 fseek(file, 0, SEEK_END);
1361 len = min(ftell(file), sizeof(buf)-1);
1362 rewind(file);
1363 buf[len] = '\0';
1364 if (fread(buf, 1, len, file) != len)
1365 {
1366 DBG1(DBG_PTS, "failed to read file '%s'", releases[i]);
1367 fclose(file);
1368 return NULL;
1369 }
1370 fclose(file);
1371
1372 if (i == 0) /* LSB release */
1373 {
1374 pos = strstr(buf, description);
1375 if (!pos)
1376 {
1377 DBG1(DBG_PTS, "failed to find begin of lsb-release "
1378 "DESCRIPTION field");
1379 return NULL;
1380 }
1381 value = pos + strlen(description);
1382 pos = strchr(value, '"');
1383 if (!pos)
1384 {
1385 DBG1(DBG_PTS, "failed to find end of lsb-release "
1386 "DESCRIPTION field");
1387 return NULL;
1388 }
1389 }
1390 else
1391 {
1392 value = buf;
1393 pos = strchr(value, '\n');
1394 if (!pos)
1395 {
1396 DBG1(DBG_PTS, "failed to find end of release string");
1397 return NULL;
1398 }
1399 }
1400 break;
1401 }
1402
1403 if (!value)
1404 {
1405 DBG1(DBG_PTS, "no distribution release file found");
1406 return NULL;
1407 }
1408
1409 if (uname(&uninfo) < 0)
1410 {
1411 DBG1(DBG_PTS, "could not retrieve machine architecture");
1412 return NULL;
1413 }
1414
1415 *pos++ = ' ';
1416 len = sizeof(buf)-1 + (pos - buf);
1417 strncpy(pos, uninfo.machine, len);
1418
1419 DBG1(DBG_PTS, "platform is '%s'", value);
1420 return strdup(value);
1421 }
1422
1423 /**
1424 * Check for a TPM by querying for TPM Version Info
1425 */
1426 static bool has_tpm(private_pts_t *this)
1427 {
1428 TSS_HCONTEXT hContext;
1429 TSS_HTPM hTPM;
1430 TSS_RESULT result;
1431 u_int32_t version_info_len;
1432
1433 result = Tspi_Context_Create(&hContext);
1434 if (result != TSS_SUCCESS)
1435 {
1436 DBG1(DBG_PTS, "TPM context could not be created: tss error 0x%x",
1437 result);
1438 return FALSE;
1439 }
1440 result = Tspi_Context_Connect(hContext, NULL);
1441 if (result != TSS_SUCCESS)
1442 {
1443 goto err;
1444 }
1445 result = Tspi_Context_GetTpmObject (hContext, &hTPM);
1446 if (result != TSS_SUCCESS)
1447 {
1448 goto err;
1449 }
1450 result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_VERSION_VAL, 0, NULL,
1451 &version_info_len,
1452 &this->tpm_version_info.ptr);
1453 this->tpm_version_info.len = version_info_len;
1454 if (result != TSS_SUCCESS)
1455 {
1456 goto err;
1457 }
1458 this->tpm_version_info = chunk_clone(this->tpm_version_info);
1459
1460 Tspi_Context_FreeMemory(hContext, NULL);
1461 Tspi_Context_Close(hContext);
1462 return TRUE;
1463
1464 err:
1465 DBG1(DBG_PTS, "TPM not available: tss error 0x%x", result);
1466 Tspi_Context_FreeMemory(hContext, NULL);
1467 Tspi_Context_Close(hContext);
1468 return FALSE;
1469 }
1470
1471 /**
1472 * See header
1473 */
1474 pts_t *pts_create(bool is_imc)
1475 {
1476 private_pts_t *this;
1477
1478 INIT(this,
1479 .public = {
1480 .get_proto_caps = _get_proto_caps,
1481 .set_proto_caps = _set_proto_caps,
1482 .get_meas_algorithm = _get_meas_algorithm,
1483 .set_meas_algorithm = _set_meas_algorithm,
1484 .get_dh_hash_algorithm = _get_dh_hash_algorithm,
1485 .set_dh_hash_algorithm = _set_dh_hash_algorithm,
1486 .create_dh_nonce = _create_dh_nonce,
1487 .get_my_public_value = _get_my_public_value,
1488 .set_peer_public_value = _set_peer_public_value,
1489 .calculate_secret = _calculate_secret,
1490 .get_platform_info = _get_platform_info,
1491 .set_platform_info = _set_platform_info,
1492 .get_tpm_version_info = _get_tpm_version_info,
1493 .set_tpm_version_info = _set_tpm_version_info,
1494 .get_aik = _get_aik,
1495 .set_aik = _set_aik,
1496 .is_path_valid = _is_path_valid,
1497 .hash_file = _hash_file,
1498 .do_measurements = _do_measurements,
1499 .get_metadata = _get_metadata,
1500 .read_pcr = _read_pcr,
1501 .extend_pcr = _extend_pcr,
1502 .quote_tpm = _quote_tpm,
1503 .select_pcr = _select_pcr,
1504 .add_pcr = _add_pcr,
1505 .get_quote_info = _get_quote_info,
1506 .verify_quote_signature = _verify_quote_signature,
1507 .destroy = _destroy,
1508 },
1509 .is_imc = is_imc,
1510 .proto_caps = PTS_PROTO_CAPS_V,
1511 .algorithm = PTS_MEAS_ALGO_SHA256,
1512 .dh_hash_algorithm = PTS_MEAS_ALGO_SHA256,
1513 );
1514
1515 if (is_imc)
1516 {
1517 this->platform_info = extract_platform_info();
1518
1519 if (has_tpm(this))
1520 {
1521 this->has_tpm = TRUE;
1522 this->proto_caps |= PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_D;
1523 load_aik(this);
1524 load_aik_blob(this);
1525 }
1526 }
1527 else
1528 {
1529 this->proto_caps |= PTS_PROTO_CAPS_T | PTS_PROTO_CAPS_D;
1530 }
1531
1532 return &this->public;
1533 }