ae2660bae4901e01f9c55522280eef315a29f3d4
[strongswan.git] / src / libpts / plugins / imv_attestation / imv_attestation_agent.c
1 /*
2 * Copyright (C) 2011-2012 Sansar Choinyambuu
3 * Copyright (C) 2011-2013 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #define _GNU_SOURCE /* for stdndup() */
18 #include <string.h>
19
20 #include "imv_attestation_agent.h"
21 #include "imv_attestation_state.h"
22 #include "imv_attestation_process.h"
23 #include "imv_attestation_build.h"
24
25 #include <imcv.h>
26 #include <imv/imv_agent.h>
27 #include <imv/imv_msg.h>
28 #include <ietf/ietf_attr.h>
29 #include <ietf/ietf_attr_attr_request.h>
30 #include <ietf/ietf_attr_pa_tnc_error.h>
31 #include <ietf/ietf_attr_product_info.h>
32 #include <ietf/ietf_attr_string_version.h>
33
34 #include <libpts.h>
35
36 #include <pts/pts.h>
37 #include <pts/pts_database.h>
38 #include <pts/pts_creds.h>
39 #include <pts/components/ita/ita_comp_func_name.h>
40
41 #include <tcg/tcg_attr.h>
42 #include <tcg/pts/tcg_pts_attr_meas_algo.h>
43 #include <tcg/pts/tcg_pts_attr_proto_caps.h>
44 #include <tcg/pts/tcg_pts_attr_req_file_meas.h>
45 #include <tcg/pts/tcg_pts_attr_req_file_meta.h>
46
47 #include <tncif_pa_subtypes.h>
48
49 #include <pen/pen.h>
50 #include <utils/debug.h>
51 #include <credentials/credential_manager.h>
52 #include <collections/linked_list.h>
53
54 typedef struct private_imv_attestation_agent_t private_imv_attestation_agent_t;
55
56 /* Subscribed PA-TNC message subtypes */
57 static pen_type_t msg_types[] = {
58 { PEN_TCG, PA_SUBTYPE_TCG_PTS },
59 { PEN_IETF, PA_SUBTYPE_IETF_OPERATING_SYSTEM }
60 };
61
62 /**
63 * Private data of an imv_attestation_agent_t object.
64 */
65 struct private_imv_attestation_agent_t {
66
67 /**
68 * Public members of imv_attestation_agent_t
69 */
70 imv_agent_if_t public;
71
72 /**
73 * IMV agent responsible for generic functions
74 */
75 imv_agent_t *agent;
76
77 /**
78 * Supported PTS measurement algorithms
79 */
80 pts_meas_algorithms_t supported_algorithms;
81
82 /**
83 * Supported PTS Diffie Hellman Groups
84 */
85 pts_dh_group_t supported_dh_groups;
86
87 /**
88 * PTS file measurement database
89 */
90 pts_database_t *pts_db;
91
92 /**
93 * PTS credentials
94 */
95 pts_creds_t *pts_creds;
96
97 /**
98 * PTS credential manager
99 */
100 credential_manager_t *pts_credmgr;
101
102 };
103
104 METHOD(imv_agent_if_t, bind_functions, TNC_Result,
105 private_imv_attestation_agent_t *this, TNC_TNCS_BindFunctionPointer bind_function)
106 {
107 return this->agent->bind_functions(this->agent, bind_function);
108 }
109
110 METHOD(imv_agent_if_t, notify_connection_change, TNC_Result,
111 private_imv_attestation_agent_t *this, TNC_ConnectionID id,
112 TNC_ConnectionState new_state)
113 {
114 imv_state_t *state;
115
116 switch (new_state)
117 {
118 case TNC_CONNECTION_STATE_CREATE:
119 state = imv_attestation_state_create(id);
120 return this->agent->create_state(this->agent, state);
121 case TNC_CONNECTION_STATE_DELETE:
122 return this->agent->delete_state(this->agent, id);
123 default:
124 return this->agent->change_state(this->agent, id, new_state, NULL);
125 }
126 }
127
128 /**
129 * Process a received message
130 */
131 static TNC_Result receive_msg(private_imv_attestation_agent_t *this,
132 imv_state_t *state, imv_msg_t *in_msg)
133 {
134 imv_attestation_state_t *attestation_state;
135 imv_msg_t *out_msg;
136 enumerator_t *enumerator;
137 pa_tnc_attr_t *attr;
138 pen_type_t type;
139 TNC_Result result;
140 pts_t *pts;
141 chunk_t os_name = chunk_empty;
142 chunk_t os_version = chunk_empty;
143 bool fatal_error = FALSE;
144
145 /* parse received PA-TNC message and handle local and remote errors */
146 result = in_msg->receive(in_msg, &fatal_error);
147 if (result != TNC_RESULT_SUCCESS)
148 {
149 return result;
150 }
151
152 attestation_state = (imv_attestation_state_t*)state;
153 pts = attestation_state->get_pts(attestation_state);
154
155 out_msg = imv_msg_create_as_reply(in_msg);
156 out_msg->set_msg_type(out_msg, msg_types[0]);
157
158 /* analyze PA-TNC attributes */
159 enumerator = in_msg->create_attribute_enumerator(in_msg);
160 while (enumerator->enumerate(enumerator, &attr))
161 {
162 type = attr->get_type(attr);
163
164 if (type.vendor_id == PEN_IETF)
165 {
166 switch (type.type)
167 {
168 case IETF_ATTR_PA_TNC_ERROR:
169 {
170 ietf_attr_pa_tnc_error_t *error_attr;
171 pen_type_t error_code;
172 chunk_t msg_info;
173
174 error_attr = (ietf_attr_pa_tnc_error_t*)attr;
175 error_code = error_attr->get_error_code(error_attr);
176
177 if (error_code.vendor_id == PEN_TCG)
178 {
179 msg_info = error_attr->get_msg_info(error_attr);
180
181 DBG1(DBG_IMV, "received TCG-PTS error '%N'",
182 pts_error_code_names, error_code.type);
183 DBG1(DBG_IMV, "error information: %B", &msg_info);
184 fatal_error = TRUE;
185 }
186 break;
187 }
188 case IETF_ATTR_PRODUCT_INFORMATION:
189 {
190 ietf_attr_product_info_t *attr_cast;
191
192 attr_cast = (ietf_attr_product_info_t*)attr;
193 os_name = attr_cast->get_info(attr_cast, NULL, NULL);
194 break;
195 }
196 case IETF_ATTR_STRING_VERSION:
197 {
198 ietf_attr_string_version_t *attr_cast;
199
200 attr_cast = (ietf_attr_string_version_t*)attr;
201 os_version = attr_cast->get_version(attr_cast, NULL, NULL);
202 break;
203 }
204 default:
205 break;
206 }
207 }
208 else if (type.vendor_id == PEN_TCG)
209 {
210 if (!imv_attestation_process(attr, out_msg, state,
211 this->supported_algorithms, this->supported_dh_groups,
212 this->pts_db, this->pts_credmgr))
213 {
214 result = TNC_RESULT_FATAL;
215 break;
216 }
217 }
218 }
219 enumerator->destroy(enumerator);
220
221 /**
222 * The IETF Product Information and String Version attributes
223 * are supposed to arrive in the same PA-TNC message
224 */
225 if (os_name.len && os_version.len)
226 {
227 pts->set_platform_info(pts, os_name, os_version);
228 }
229
230 if (fatal_error || result != TNC_RESULT_SUCCESS)
231 {
232 state->set_recommendation(state,
233 TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
234 TNC_IMV_EVALUATION_RESULT_ERROR);
235 result = out_msg->send_assessment(out_msg);
236 out_msg->destroy(out_msg);
237 if (result != TNC_RESULT_SUCCESS)
238 {
239 return result;
240 }
241 return this->agent->provide_recommendation(this->agent, state);
242 }
243
244 /* send PA-TNC message with excl flag set */
245 result = out_msg->send(out_msg, TRUE);
246 out_msg->destroy(out_msg);
247
248 return result;
249 }
250
251 METHOD(imv_agent_if_t, receive_message, TNC_Result,
252 private_imv_attestation_agent_t *this, TNC_ConnectionID id,
253 TNC_MessageType msg_type, chunk_t msg)
254 {
255 imv_state_t *state;
256 imv_msg_t *in_msg;
257 TNC_Result result;
258
259 if (!this->agent->get_state(this->agent, id, &state))
260 {
261 return TNC_RESULT_FATAL;
262 }
263 in_msg = imv_msg_create_from_data(this->agent, state, id, msg_type, msg);
264 result = receive_msg(this, state, in_msg);
265 in_msg->destroy(in_msg);
266
267 return result;
268 }
269
270 METHOD(imv_agent_if_t, receive_message_long, TNC_Result,
271 private_imv_attestation_agent_t *this, TNC_ConnectionID id,
272 TNC_UInt32 src_imc_id, TNC_UInt32 dst_imv_id,
273 TNC_VendorID msg_vid, TNC_MessageSubtype msg_subtype, chunk_t msg)
274 {
275 imv_state_t *state;
276 imv_msg_t *in_msg;
277 TNC_Result result;
278
279 if (!this->agent->get_state(this->agent, id, &state))
280 {
281 return TNC_RESULT_FATAL;
282 }
283 in_msg = imv_msg_create_from_long_data(this->agent, state, id,
284 src_imc_id, dst_imv_id, msg_vid, msg_subtype, msg);
285 result = receive_msg(this, state, in_msg);
286 in_msg->destroy(in_msg);
287
288 return result;
289 }
290
291 METHOD(imv_agent_if_t, batch_ending, TNC_Result,
292 private_imv_attestation_agent_t *this, TNC_ConnectionID id)
293 {
294 imv_msg_t *out_msg;
295 imv_state_t *state;
296 imv_session_t *session;
297 imv_attestation_state_t *attestation_state;
298 imv_attestation_handshake_state_t handshake_state;
299 imv_workitem_t *workitem;
300 TNC_IMV_Action_Recommendation rec;
301 TNC_IMV_Evaluation_Result eval;
302 TNC_IMVID imv_id;
303 TNC_Result result = TNC_RESULT_SUCCESS;
304 pts_t *pts;
305 char *platform_info;
306 enumerator_t *enumerator;
307
308 if (!this->agent->get_state(this->agent, id, &state))
309 {
310 return TNC_RESULT_FATAL;
311 }
312 attestation_state = (imv_attestation_state_t*)state;
313 pts = attestation_state->get_pts(attestation_state);
314 handshake_state = attestation_state->get_handshake_state(attestation_state);
315 platform_info = pts->get_platform_info(pts);
316 session = state->get_session(state);
317 imv_id = this->agent->get_id(this->agent);
318
319 /* exit if a recommendation has already been provided */
320 if (state->get_action_flags(state) & IMV_ATTESTATION_FLAG_REC)
321 {
322 return TNC_RESULT_SUCCESS;
323 }
324
325 /* send an IETF attribute request if no platform info was received */
326 if (!platform_info &&
327 !(state->get_action_flags(state) & IMV_ATTESTATION_FLAG_ATTR_REQ))
328 {
329 pa_tnc_attr_t *attr;
330 ietf_attr_attr_request_t *attr_cast;
331 imv_msg_t *os_msg;
332
333 attr = ietf_attr_attr_request_create(PEN_IETF,
334 IETF_ATTR_PRODUCT_INFORMATION);
335 attr_cast = (ietf_attr_attr_request_t*)attr;
336 attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_STRING_VERSION);
337
338 os_msg = imv_msg_create(this->agent, state, id, imv_id, TNC_IMCID_ANY,
339 msg_types[1]);
340 os_msg->add_attribute(os_msg, attr);
341 result = os_msg->send(os_msg, FALSE);
342 os_msg->destroy(os_msg);
343
344 if (result != TNC_RESULT_SUCCESS)
345 {
346 return result;
347 }
348 state->set_action_flags(state, IMV_ATTESTATION_FLAG_ATTR_REQ);
349 }
350
351 if (handshake_state == IMV_ATTESTATION_STATE_INIT)
352 {
353 pa_tnc_attr_t *attr;
354 pts_proto_caps_flag_t flags;
355
356 out_msg = imv_msg_create(this->agent, state, id, imv_id, TNC_IMCID_ANY,
357 msg_types[0]);
358
359 /* Send Request Protocol Capabilities attribute */
360 flags = pts->get_proto_caps(pts);
361 attr = tcg_pts_attr_proto_caps_create(flags, TRUE);
362 attr->set_noskip_flag(attr, TRUE);
363 out_msg->add_attribute(out_msg, attr);
364
365 /* Send Measurement Algorithms attribute */
366 attr = tcg_pts_attr_meas_algo_create(this->supported_algorithms, FALSE);
367 attr->set_noskip_flag(attr, TRUE);
368 out_msg->add_attribute(out_msg, attr);
369
370 attestation_state->set_handshake_state(attestation_state,
371 IMV_ATTESTATION_STATE_DISCOVERY);
372
373 /* send these initial PTS attributes and exit */
374 result = out_msg->send(out_msg, FALSE);
375 out_msg->destroy(out_msg);
376
377 return result;
378 }
379
380 /* exit if we are not ready yet for PTS measurements */
381 if (!platform_info || !session ||
382 !(state->get_action_flags(state) & IMV_ATTESTATION_FLAG_ALGO))
383 {
384 return TNC_RESULT_SUCCESS;
385 }
386
387 /* create an empty out message - we might need it */
388 out_msg = imv_msg_create(this->agent, state, id, imv_id, TNC_IMCID_ANY,
389 msg_types[0]);
390
391 /* establish the PTS measurements to be taken */
392 if (!(state->get_action_flags(state) & IMV_ATTESTATION_FLAG_FILE_MEAS))
393 {
394 bool is_dir, no_workitems = TRUE;
395 u_int32_t delimiter = SOLIDUS_UTF;
396 u_int16_t request_id;
397 pa_tnc_attr_t *attr;
398 char *pathname;
399
400 attestation_state->set_handshake_state(attestation_state,
401 IMV_ATTESTATION_STATE_END);
402
403 enumerator = session->create_workitem_enumerator(session);
404 if (enumerator)
405 {
406 while (enumerator->enumerate(enumerator, &workitem))
407 {
408 if (workitem->get_imv_id(workitem) != TNC_IMVID_ANY)
409 {
410 continue;
411 }
412
413 switch (workitem->get_type(workitem))
414 {
415 case IMV_WORKITEM_FILE_REF_MEAS:
416 case IMV_WORKITEM_FILE_MEAS:
417 case IMV_WORKITEM_FILE_META:
418 is_dir = FALSE;
419 break;
420 case IMV_WORKITEM_DIR_REF_MEAS:
421 case IMV_WORKITEM_DIR_MEAS:
422 case IMV_WORKITEM_DIR_META:
423 is_dir = TRUE;
424 break;
425 case IMV_WORKITEM_TPM_ATTEST:
426 {
427 pts_component_t *comp;
428 pts_comp_func_name_t *comp_name;
429 bool no_d_flag, no_t_flag;
430 char result_str[BUF_LEN];
431
432 workitem->set_imv_id(workitem, imv_id);
433 no_workitems = FALSE;
434 no_d_flag = !(pts->get_proto_caps(pts) & PTS_PROTO_CAPS_D);
435 no_t_flag = !(pts->get_proto_caps(pts) & PTS_PROTO_CAPS_T);
436 if (no_d_flag || no_t_flag)
437 {
438 snprintf(result_str, BUF_LEN, "%s%s%s",
439 (no_t_flag) ? "no TPM available" : "",
440 (no_t_flag && no_d_flag) ? ", " : "",
441 (no_d_flag) ? "no DH nonce negotiation" : "");
442 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
443 session->remove_workitem(session, enumerator);
444 rec = workitem->set_result(workitem, result_str, eval);
445 state->update_recommendation(state, rec, eval);
446 imcv_db->finalize_workitem(imcv_db, workitem);
447 workitem->destroy(workitem);
448 continue;
449 }
450
451 /* do TPM BIOS measurements */
452 if (strchr(workitem->get_arg_str(workitem), 'B'))
453 {
454 comp_name = pts_comp_func_name_create(PEN_ITA,
455 PTS_ITA_COMP_FUNC_NAME_IMA,
456 PTS_ITA_QUALIFIER_FLAG_KERNEL |
457 PTS_ITA_QUALIFIER_TYPE_TRUSTED);
458 comp = attestation_state->create_component(
459 attestation_state, comp_name,
460 0, this->pts_db);
461 if (!comp)
462 {
463 comp_name->log(comp_name, "unregistered ");
464 comp_name->destroy(comp_name);
465 }
466 }
467
468 /* do TPM IMA measurements */
469 if (strchr(workitem->get_arg_str(workitem), 'I'))
470 {
471 comp_name = pts_comp_func_name_create(PEN_ITA,
472 PTS_ITA_COMP_FUNC_NAME_IMA,
473 PTS_ITA_QUALIFIER_FLAG_KERNEL |
474 PTS_ITA_QUALIFIER_TYPE_OS);
475 comp = attestation_state->create_component(
476 attestation_state, comp_name,
477 0, this->pts_db);
478 if (!comp)
479 {
480 comp_name->log(comp_name, "unregistered ");
481 comp_name->destroy(comp_name);
482 }
483 }
484
485 /* do TPM TRUSTED BOOT measurements */
486 if (strchr(workitem->get_arg_str(workitem), 'T'))
487 {
488 comp_name = pts_comp_func_name_create(PEN_ITA,
489 PTS_ITA_COMP_FUNC_NAME_TBOOT,
490 PTS_ITA_QUALIFIER_FLAG_KERNEL |
491 PTS_ITA_QUALIFIER_TYPE_TRUSTED);
492 comp = attestation_state->create_component(
493 attestation_state, comp_name,
494 0, this->pts_db);
495 if (!comp)
496 {
497 comp_name->log(comp_name, "unregistered ");
498 comp_name->destroy(comp_name);
499 }
500 }
501 attestation_state->set_handshake_state(attestation_state,
502 IMV_ATTESTATION_STATE_NONCE_REQ);
503 continue;
504 }
505 default:
506 continue;
507 }
508
509 /* initiate file and directory measurements */
510 pathname = this->pts_db->get_pathname(this->pts_db, is_dir,
511 workitem->get_arg_int(workitem));
512 if (!pathname)
513 {
514 continue;
515 }
516 workitem->set_imv_id(workitem, imv_id);
517 no_workitems = FALSE;
518
519 if (workitem->get_type(workitem) == IMV_WORKITEM_FILE_META)
520 {
521 TNC_IMV_Action_Recommendation rec;
522 TNC_IMV_Evaluation_Result eval;
523 char result_str[BUF_LEN];
524
525 DBG2(DBG_IMV, "IMV %d requests metadata for %s '%s'",
526 imv_id, is_dir ? "directory" : "file", pathname);
527
528 /* currently just fire and forget metadata requests */
529 attr = tcg_pts_attr_req_file_meta_create(is_dir,
530 delimiter, pathname);
531 snprintf(result_str, BUF_LEN, "%s metadata requested",
532 is_dir ? "directory" : "file");
533 eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
534 session->remove_workitem(session, enumerator);
535 rec = workitem->set_result(workitem, result_str, eval);
536 state->update_recommendation(state, rec, eval);
537 imcv_db->finalize_workitem(imcv_db, workitem);
538 workitem->destroy(workitem);
539 }
540 else
541 {
542 /* use lower 16 bits of the workitem ID as request ID */
543 request_id = workitem->get_id(workitem) & 0xffff;
544
545 DBG2(DBG_IMV, "IMV %d requests measurement %d for %s '%s'",
546 imv_id, request_id, is_dir ? "directory" : "file",
547 pathname);
548 attr = tcg_pts_attr_req_file_meas_create(is_dir, request_id,
549 delimiter, pathname);
550 }
551 free(pathname);
552 attr->set_noskip_flag(attr, TRUE);
553 out_msg->add_attribute(out_msg, attr);
554 }
555 enumerator->destroy(enumerator);
556
557 /* sent all file and directory measurement and metadata requests */
558 state->set_action_flags(state, IMV_ATTESTATION_FLAG_FILE_MEAS);
559
560 if (no_workitems)
561 {
562 DBG2(DBG_IMV, "IMV %d has no workitems - "
563 "no evaluation requested", imv_id);
564 state->set_recommendation(state,
565 TNC_IMV_ACTION_RECOMMENDATION_ALLOW,
566 TNC_IMV_EVALUATION_RESULT_DONT_KNOW);
567 }
568 }
569 }
570
571 /* check the IMV state for the next PA-TNC attributes to send */
572 enumerator = session->create_workitem_enumerator(session);
573 while (enumerator->enumerate(enumerator, &workitem))
574 {
575 if (workitem->get_type(workitem) == IMV_WORKITEM_TPM_ATTEST)
576 {
577 if (!imv_attestation_build(out_msg, state,
578 this->supported_dh_groups, this->pts_db))
579 {
580 imv_reason_string_t *reason_string;
581 chunk_t result;
582 char *result_str;
583
584 reason_string = imv_reason_string_create("en", ", ");
585 attestation_state->add_comp_evid_reasons(attestation_state,
586 reason_string);
587 result = reason_string->get_encoding(reason_string);
588 result_str = strndup(result.ptr, result.len);
589 reason_string->destroy(reason_string);
590
591 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
592 session->remove_workitem(session, enumerator);
593 rec = workitem->set_result(workitem, result_str, eval);
594 state->update_recommendation(state, rec, eval);
595 imcv_db->finalize_workitem(imcv_db, workitem);
596 }
597 break;
598 }
599 }
600 enumerator->destroy(enumerator);
601
602 /* finalized all workitems? */
603 if (session && session->get_policy_started(session) &&
604 session->get_workitem_count(session, imv_id) == 0 &&
605 attestation_state->get_handshake_state(attestation_state) ==
606 IMV_ATTESTATION_STATE_END)
607 {
608 result = out_msg->send_assessment(out_msg);
609 out_msg->destroy(out_msg);
610 state->set_action_flags(state, IMV_ATTESTATION_FLAG_REC);
611
612 if (result != TNC_RESULT_SUCCESS)
613 {
614 return result;
615 }
616 return this->agent->provide_recommendation(this->agent, state);
617 }
618
619 /* send non-empty PA-TNC message with excl flag not set */
620 if (out_msg->get_attribute_count(out_msg))
621 {
622 result = out_msg->send(out_msg, FALSE);
623 }
624 out_msg->destroy(out_msg);
625
626 return result;
627 }
628
629 METHOD(imv_agent_if_t, solicit_recommendation, TNC_Result,
630 private_imv_attestation_agent_t *this, TNC_ConnectionID id)
631 {
632 TNC_IMVID imv_id;
633 imv_state_t *state;
634 imv_attestation_state_t *attestation_state;
635 imv_session_t *session;
636
637 if (!this->agent->get_state(this->agent, id, &state))
638 {
639 return TNC_RESULT_FATAL;
640 }
641 attestation_state = (imv_attestation_state_t*)state;
642 session = state->get_session(state);
643 imv_id = this->agent->get_id(this->agent);
644
645 if (session)
646 {
647 TNC_IMV_Evaluation_Result eval;
648 TNC_IMV_Action_Recommendation rec;
649 imv_workitem_t *workitem;
650 enumerator_t *enumerator;
651 char *result_str;
652 int pending_file_meas = 0;
653
654 enumerator = session->create_workitem_enumerator(session);
655 if (enumerator)
656 {
657 while (enumerator->enumerate(enumerator, &workitem))
658 {
659 if (workitem->get_imv_id(workitem) != imv_id)
660 {
661 continue;
662 }
663 switch (workitem->get_type(workitem))
664 {
665 case IMV_WORKITEM_FILE_REF_MEAS:
666 case IMV_WORKITEM_FILE_MEAS:
667 case IMV_WORKITEM_DIR_REF_MEAS:
668 case IMV_WORKITEM_DIR_MEAS:
669 result_str = "Pending file measurements";
670 pending_file_meas++;
671 break;
672 case IMV_WORKITEM_TPM_ATTEST:
673 attestation_state->finalize_components(attestation_state);
674 result_str = "Pending component evidence";
675 break;
676 default:
677 continue;
678 }
679 session->remove_workitem(session, enumerator);
680 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
681 rec = workitem->set_result(workitem, result_str, eval);
682 state->update_recommendation(state, rec, eval);
683 imcv_db->finalize_workitem(imcv_db, workitem);
684 workitem->destroy(workitem);
685 }
686 enumerator->destroy(enumerator);
687
688 if (pending_file_meas)
689 {
690 DBG1(DBG_IMV, "failure due to %d pending file measurements",
691 pending_file_meas);
692 attestation_state->set_measurement_error(attestation_state,
693 IMV_ATTESTATION_ERROR_FILE_MEAS_PEND);
694 }
695 }
696 }
697 return this->agent->provide_recommendation(this->agent, state);
698 }
699
700 METHOD(imv_agent_if_t, destroy, void,
701 private_imv_attestation_agent_t *this)
702 {
703 if (this->pts_creds)
704 {
705 this->pts_credmgr->remove_set(this->pts_credmgr,
706 this->pts_creds->get_set(this->pts_creds));
707 this->pts_creds->destroy(this->pts_creds);
708 }
709 DESTROY_IF(this->pts_db);
710 DESTROY_IF(this->pts_credmgr);
711 DESTROY_IF(this->agent);
712 free(this);
713 libpts_deinit();
714 }
715
716 /**
717 * Described in header.
718 */
719 imv_agent_if_t *imv_attestation_agent_create(const char *name, TNC_IMVID id,
720 TNC_Version *actual_version)
721 {
722 private_imv_attestation_agent_t *this;
723 imv_agent_t *agent;
724 char *hash_alg, *dh_group, *cadir;
725 bool mandatory_dh_groups;
726
727 agent = imv_agent_create(name, msg_types, countof(msg_types), id,
728 actual_version);
729 if (!agent)
730 {
731 return NULL;
732 }
733
734 hash_alg = lib->settings->get_str(lib->settings,
735 "%s.plugins.imv-attestation.hash_algorithm", "sha256", lib->ns);
736 dh_group = lib->settings->get_str(lib->settings,
737 "%s.plugins.imv-attestation.dh_group", "ecp256", lib->ns);
738 mandatory_dh_groups = lib->settings->get_bool(lib->settings,
739 "%s.plugins.imv-attestation.mandatory_dh_groups", TRUE, lib->ns);
740 cadir = lib->settings->get_str(lib->settings,
741 "%s.plugins.imv-attestation.cadir", NULL, lib->ns);
742
743 INIT(this,
744 .public = {
745 .bind_functions = _bind_functions,
746 .notify_connection_change = _notify_connection_change,
747 .receive_message = _receive_message,
748 .receive_message_long = _receive_message_long,
749 .batch_ending = _batch_ending,
750 .solicit_recommendation = _solicit_recommendation,
751 .destroy = _destroy,
752 },
753 .agent = agent,
754 .supported_algorithms = PTS_MEAS_ALGO_NONE,
755 .supported_dh_groups = PTS_DH_GROUP_NONE,
756 .pts_credmgr = credential_manager_create(),
757 .pts_creds = pts_creds_create(cadir),
758 .pts_db = pts_database_create(imcv_db),
759 );
760
761 libpts_init();
762
763 if (!pts_meas_algo_probe(&this->supported_algorithms) ||
764 !pts_dh_group_probe(&this->supported_dh_groups, mandatory_dh_groups) ||
765 !pts_meas_algo_update(hash_alg, &this->supported_algorithms) ||
766 !pts_dh_group_update(dh_group, &this->supported_dh_groups))
767 {
768 destroy(this);
769 return NULL;
770 }
771
772 if (this->pts_creds)
773 {
774 this->pts_credmgr->add_set(this->pts_credmgr,
775 this->pts_creds->get_set(this->pts_creds));
776 }
777
778 return &this->public;
779 }