Catch AIK errors
[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 /* create an empty out message - we might need it */
349 out_msg = imv_msg_create(this->agent, state, id, imv_id, TNC_IMCID_ANY,
350 msg_types[0]);
351
352 if (handshake_state == IMV_ATTESTATION_STATE_INIT)
353 {
354 pa_tnc_attr_t *attr;
355 pts_proto_caps_flag_t flags;
356
357 /* Send Request Protocol Capabilities attribute */
358 flags = pts->get_proto_caps(pts);
359 attr = tcg_pts_attr_proto_caps_create(flags, TRUE);
360 attr->set_noskip_flag(attr, TRUE);
361 out_msg->add_attribute(out_msg, attr);
362
363 /* Send Measurement Algorithms attribute */
364 attr = tcg_pts_attr_meas_algo_create(this->supported_algorithms, FALSE);
365 attr->set_noskip_flag(attr, TRUE);
366 out_msg->add_attribute(out_msg, attr);
367
368 attestation_state->set_handshake_state(attestation_state,
369 IMV_ATTESTATION_STATE_DISCOVERY);
370 }
371
372 if (platform_info && session &&
373 (state->get_action_flags(state) & IMV_ATTESTATION_FLAG_ALGO) &&
374 !(state->get_action_flags(state) & IMV_ATTESTATION_FLAG_FILE_MEAS))
375 {
376 bool is_dir, no_workitems = TRUE;
377 u_int32_t delimiter = SOLIDUS_UTF;
378 u_int16_t request_id;
379 pa_tnc_attr_t *attr;
380 char *pathname;
381
382 attestation_state->set_handshake_state(attestation_state,
383 IMV_ATTESTATION_STATE_END);
384
385 enumerator = session->create_workitem_enumerator(session);
386 if (enumerator)
387 {
388 while (enumerator->enumerate(enumerator, &workitem))
389 {
390 if (workitem->get_imv_id(workitem) != TNC_IMVID_ANY)
391 {
392 continue;
393 }
394
395 switch (workitem->get_type(workitem))
396 {
397 case IMV_WORKITEM_FILE_REF_MEAS:
398 case IMV_WORKITEM_FILE_MEAS:
399 case IMV_WORKITEM_FILE_META:
400 is_dir = FALSE;
401 break;
402 case IMV_WORKITEM_DIR_REF_MEAS:
403 case IMV_WORKITEM_DIR_MEAS:
404 case IMV_WORKITEM_DIR_META:
405 is_dir = TRUE;
406 break;
407 case IMV_WORKITEM_TPM_ATTEST:
408 {
409 pts_component_t *comp;
410 pts_comp_func_name_t *comp_name;
411 bool no_d_flag, no_t_flag;
412 char result_str[BUF_LEN];
413
414 workitem->set_imv_id(workitem, imv_id);
415 no_workitems = FALSE;
416 no_d_flag = !(pts->get_proto_caps(pts) & PTS_PROTO_CAPS_D);
417 no_t_flag = !(pts->get_proto_caps(pts) & PTS_PROTO_CAPS_T);
418 if (no_d_flag || no_t_flag)
419 {
420 snprintf(result_str, BUF_LEN, "%s%s%s",
421 (no_t_flag) ? "no TPM available" : "",
422 (no_t_flag && no_d_flag) ? ", " : "",
423 (no_d_flag) ? "no DH nonce negotiation" : "");
424 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
425 session->remove_workitem(session, enumerator);
426 rec = workitem->set_result(workitem, result_str, eval);
427 state->update_recommendation(state, rec, eval);
428 imcv_db->finalize_workitem(imcv_db, workitem);
429 workitem->destroy(workitem);
430 continue;
431 }
432
433 /* do TPM BIOS measurements */
434 if (strchr(workitem->get_arg_str(workitem), 'B'))
435 {
436 comp_name = pts_comp_func_name_create(PEN_ITA,
437 PTS_ITA_COMP_FUNC_NAME_IMA,
438 PTS_ITA_QUALIFIER_FLAG_KERNEL |
439 PTS_ITA_QUALIFIER_TYPE_TRUSTED);
440 comp = attestation_state->create_component(
441 attestation_state, comp_name,
442 0, this->pts_db);
443 if (!comp)
444 {
445 comp_name->log(comp_name, "unregistered ");
446 comp_name->destroy(comp_name);
447 }
448 }
449
450 /* do TPM IMA measurements */
451 if (strchr(workitem->get_arg_str(workitem), 'I'))
452 {
453 comp_name = pts_comp_func_name_create(PEN_ITA,
454 PTS_ITA_COMP_FUNC_NAME_IMA,
455 PTS_ITA_QUALIFIER_FLAG_KERNEL |
456 PTS_ITA_QUALIFIER_TYPE_OS);
457 comp = attestation_state->create_component(
458 attestation_state, comp_name,
459 0, this->pts_db);
460 if (!comp)
461 {
462 comp_name->log(comp_name, "unregistered ");
463 comp_name->destroy(comp_name);
464 }
465 }
466
467 attestation_state->set_handshake_state(attestation_state,
468 IMV_ATTESTATION_STATE_NONCE_REQ);
469 continue;
470 }
471 default:
472 continue;
473 }
474
475 /* initiate file and directory measurements */
476 pathname = this->pts_db->get_pathname(this->pts_db, is_dir,
477 workitem->get_arg_int(workitem));
478 if (!pathname)
479 {
480 continue;
481 }
482 workitem->set_imv_id(workitem, imv_id);
483 no_workitems = FALSE;
484
485 if (workitem->get_type(workitem) == IMV_WORKITEM_FILE_META)
486 {
487 TNC_IMV_Action_Recommendation rec;
488 TNC_IMV_Evaluation_Result eval;
489 char result_str[BUF_LEN];
490
491 DBG2(DBG_IMV, "IMV %d requests metadata for %s '%s'",
492 imv_id, is_dir ? "directory" : "file", pathname);
493
494 /* currently just fire and forget metadata requests */
495 attr = tcg_pts_attr_req_file_meta_create(is_dir,
496 delimiter, pathname);
497 snprintf(result_str, BUF_LEN, "%s metadata requested",
498 is_dir ? "directory" : "file");
499 eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
500 session->remove_workitem(session, enumerator);
501 rec = workitem->set_result(workitem, result_str, eval);
502 state->update_recommendation(state, rec, eval);
503 imcv_db->finalize_workitem(imcv_db, workitem);
504 workitem->destroy(workitem);
505 }
506 else
507 {
508 /* use lower 16 bits of the workitem ID as request ID */
509 request_id = workitem->get_id(workitem) & 0xffff;
510
511 DBG2(DBG_IMV, "IMV %d requests measurement %d for %s '%s'",
512 imv_id, request_id, is_dir ? "directory" : "file",
513 pathname);
514 attr = tcg_pts_attr_req_file_meas_create(is_dir, request_id,
515 delimiter, pathname);
516 }
517 free(pathname);
518 attr->set_noskip_flag(attr, TRUE);
519 out_msg->add_attribute(out_msg, attr);
520 }
521 enumerator->destroy(enumerator);
522
523 /* sent all file and directory measurement and metadata requests */
524 state->set_action_flags(state, IMV_ATTESTATION_FLAG_FILE_MEAS);
525
526 if (no_workitems)
527 {
528 DBG2(DBG_IMV, "IMV %d has no workitems - "
529 "no evaluation requested", imv_id);
530 state->set_recommendation(state,
531 TNC_IMV_ACTION_RECOMMENDATION_ALLOW,
532 TNC_IMV_EVALUATION_RESULT_DONT_KNOW);
533 }
534 }
535 }
536
537 /* check the IMV state for the next PA-TNC attributes to send */
538 enumerator = session->create_workitem_enumerator(session);
539 while (enumerator->enumerate(enumerator, &workitem))
540 {
541 if (workitem->get_type(workitem) == IMV_WORKITEM_TPM_ATTEST)
542 {
543 if (!imv_attestation_build(out_msg, state,
544 this->supported_dh_groups, this->pts_db))
545 {
546 imv_reason_string_t *reason_string;
547 chunk_t result;
548 char *result_str;
549
550 reason_string = imv_reason_string_create("en", ", ");
551 attestation_state->add_comp_evid_reasons(attestation_state,
552 reason_string);
553 result = reason_string->get_encoding(reason_string);
554 result_str = strndup(result.ptr, result.len);
555 reason_string->destroy(reason_string);
556
557 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
558 session->remove_workitem(session, enumerator);
559 rec = workitem->set_result(workitem, result_str, eval);
560 state->update_recommendation(state, rec, eval);
561 imcv_db->finalize_workitem(imcv_db, workitem);
562 }
563 break;
564 }
565 }
566 enumerator->destroy(enumerator);
567
568 /* finalized all workitems? */
569 if (session && session->get_policy_started(session) &&
570 session->get_workitem_count(session, imv_id) == 0 &&
571 attestation_state->get_handshake_state(attestation_state) ==
572 IMV_ATTESTATION_STATE_END)
573 {
574 result = out_msg->send_assessment(out_msg);
575 out_msg->destroy(out_msg);
576 state->set_action_flags(state, IMV_ATTESTATION_FLAG_REC);
577
578 if (result != TNC_RESULT_SUCCESS)
579 {
580 return result;
581 }
582 return this->agent->provide_recommendation(this->agent, state);
583 }
584
585 /* send non-empty PA-TNC message with excl flag not set */
586 if (out_msg->get_attribute_count(out_msg))
587 {
588 result = out_msg->send(out_msg, FALSE);
589 }
590 out_msg->destroy(out_msg);
591
592 return result;
593 }
594
595 METHOD(imv_agent_if_t, solicit_recommendation, TNC_Result,
596 private_imv_attestation_agent_t *this, TNC_ConnectionID id)
597 {
598 TNC_IMVID imv_id;
599 imv_state_t *state;
600 imv_attestation_state_t *attestation_state;
601 imv_session_t *session;
602
603 if (!this->agent->get_state(this->agent, id, &state))
604 {
605 return TNC_RESULT_FATAL;
606 }
607 attestation_state = (imv_attestation_state_t*)state;
608 session = state->get_session(state);
609 imv_id = this->agent->get_id(this->agent);
610
611 if (session)
612 {
613 TNC_IMV_Evaluation_Result eval;
614 TNC_IMV_Action_Recommendation rec;
615 imv_workitem_t *workitem;
616 enumerator_t *enumerator;
617 char *result_str;
618 int pending_file_meas = 0;
619
620 enumerator = session->create_workitem_enumerator(session);
621 if (enumerator)
622 {
623 while (enumerator->enumerate(enumerator, &workitem))
624 {
625 if (workitem->get_imv_id(workitem) != imv_id)
626 {
627 continue;
628 }
629 switch (workitem->get_type(workitem))
630 {
631 case IMV_WORKITEM_FILE_REF_MEAS:
632 case IMV_WORKITEM_FILE_MEAS:
633 case IMV_WORKITEM_DIR_REF_MEAS:
634 case IMV_WORKITEM_DIR_MEAS:
635 result_str = "Pending file measurements";
636 pending_file_meas++;
637 break;
638 case IMV_WORKITEM_TPM_ATTEST:
639 attestation_state->finalize_components(attestation_state);
640 result_str = "Pending component evidence";
641 break;
642 default:
643 continue;
644 }
645 session->remove_workitem(session, enumerator);
646 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
647 rec = workitem->set_result(workitem, result_str, eval);
648 state->update_recommendation(state, rec, eval);
649 imcv_db->finalize_workitem(imcv_db, workitem);
650 workitem->destroy(workitem);
651 }
652 enumerator->destroy(enumerator);
653
654 if (pending_file_meas)
655 {
656 DBG1(DBG_IMV, "failure due to %d pending file measurements",
657 pending_file_meas);
658 attestation_state->set_measurement_error(attestation_state,
659 IMV_ATTESTATION_ERROR_FILE_MEAS_PEND);
660 }
661 }
662 }
663 return this->agent->provide_recommendation(this->agent, state);
664 }
665
666 METHOD(imv_agent_if_t, destroy, void,
667 private_imv_attestation_agent_t *this)
668 {
669 if (this->pts_creds)
670 {
671 this->pts_credmgr->remove_set(this->pts_credmgr,
672 this->pts_creds->get_set(this->pts_creds));
673 this->pts_creds->destroy(this->pts_creds);
674 }
675 DESTROY_IF(this->pts_db);
676 DESTROY_IF(this->pts_credmgr);
677 DESTROY_IF(this->agent);
678 free(this);
679 libpts_deinit();
680 }
681
682 /**
683 * Described in header.
684 */
685 imv_agent_if_t *imv_attestation_agent_create(const char *name, TNC_IMVID id,
686 TNC_Version *actual_version)
687 {
688 private_imv_attestation_agent_t *this;
689 imv_agent_t *agent;
690 char *hash_alg, *dh_group, *cadir;
691
692 agent = imv_agent_create(name, msg_types, countof(msg_types), id,
693 actual_version);
694 if (!agent)
695 {
696 return NULL;
697 }
698
699 hash_alg = lib->settings->get_str(lib->settings,
700 "libimcv.plugins.imv-attestation.hash_algorithm", "sha256");
701 dh_group = lib->settings->get_str(lib->settings,
702 "libimcv.plugins.imv-attestation.dh_group", "ecp256");
703 cadir = lib->settings->get_str(lib->settings,
704 "libimcv.plugins.imv-attestation.cadir", NULL);
705
706 INIT(this,
707 .public = {
708 .bind_functions = _bind_functions,
709 .notify_connection_change = _notify_connection_change,
710 .receive_message = _receive_message,
711 .receive_message_long = _receive_message_long,
712 .batch_ending = _batch_ending,
713 .solicit_recommendation = _solicit_recommendation,
714 .destroy = _destroy,
715 },
716 .agent = agent,
717 .supported_algorithms = PTS_MEAS_ALGO_NONE,
718 .supported_dh_groups = PTS_DH_GROUP_NONE,
719 .pts_credmgr = credential_manager_create(),
720 .pts_creds = pts_creds_create(cadir),
721 .pts_db = pts_database_create(imcv_db),
722 );
723
724 libpts_init();
725
726 if (!pts_meas_algo_probe(&this->supported_algorithms) ||
727 !pts_dh_group_probe(&this->supported_dh_groups) ||
728 !pts_meas_algo_update(hash_alg, &this->supported_algorithms) ||
729 !pts_dh_group_update(dh_group, &this->supported_dh_groups))
730 {
731 destroy(this);
732 return NULL;
733 }
734
735 if (this->pts_creds)
736 {
737 this->pts_credmgr->add_set(this->pts_credmgr,
738 this->pts_creds->get_set(this->pts_creds));
739 }
740
741 return &this->public;
742 }