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