Do TPM measurements only if there is a TPMRA workitem
[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 TNC_IMVID imv_id;
297 TNC_Result result = TNC_RESULT_SUCCESS;
298 pts_t *pts;
299 char *platform_info;
300
301 if (!this->agent->get_state(this->agent, id, &state))
302 {
303 return TNC_RESULT_FATAL;
304 }
305 attestation_state = (imv_attestation_state_t*)state;
306 pts = attestation_state->get_pts(attestation_state);
307 handshake_state = attestation_state->get_handshake_state(attestation_state);
308 platform_info = pts->get_platform_info(pts);
309 session = state->get_session(state);
310 imv_id = this->agent->get_id(this->agent);
311
312 /* exit if a recommendation has already been provided */
313 if (state->get_action_flags(state) & IMV_ATTESTATION_FLAG_REC)
314 {
315 return TNC_RESULT_SUCCESS;
316 }
317
318 /* send an IETF attribute request if no platform info was received */
319 if (!platform_info &&
320 !(state->get_action_flags(state) & IMV_ATTESTATION_FLAG_ATTR_REQ))
321 {
322 pa_tnc_attr_t *attr;
323 ietf_attr_attr_request_t *attr_cast;
324 imv_msg_t *os_msg;
325
326 attr = ietf_attr_attr_request_create(PEN_IETF,
327 IETF_ATTR_PRODUCT_INFORMATION);
328 attr_cast = (ietf_attr_attr_request_t*)attr;
329 attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_STRING_VERSION);
330
331 os_msg = imv_msg_create(this->agent, state, id, imv_id, TNC_IMCID_ANY,
332 msg_types[1]);
333 os_msg->add_attribute(os_msg, attr);
334 result = os_msg->send(os_msg, FALSE);
335 os_msg->destroy(os_msg);
336
337 if (result != TNC_RESULT_SUCCESS)
338 {
339 return result;
340 }
341 state->set_action_flags(state, IMV_ATTESTATION_FLAG_ATTR_REQ);
342 }
343
344 /* create an empty out message - we might need it */
345 out_msg = imv_msg_create(this->agent, state, id, imv_id, TNC_IMCID_ANY,
346 msg_types[0]);
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 /* Send Request Protocol Capabilities attribute */
354 flags = pts->get_proto_caps(pts);
355 attr = tcg_pts_attr_proto_caps_create(flags, TRUE);
356 attr->set_noskip_flag(attr, TRUE);
357 out_msg->add_attribute(out_msg, attr);
358
359 /* Send Measurement Algorithms attribute */
360 attr = tcg_pts_attr_meas_algo_create(this->supported_algorithms, FALSE);
361 attr->set_noskip_flag(attr, TRUE);
362 out_msg->add_attribute(out_msg, attr);
363
364 attestation_state->set_handshake_state(attestation_state,
365 IMV_ATTESTATION_STATE_DISCOVERY);
366 }
367
368 if (platform_info && session &&
369 (state->get_action_flags(state) & IMV_ATTESTATION_FLAG_ALGO) &&
370 !(state->get_action_flags(state) & IMV_ATTESTATION_FLAG_FILE_MEAS))
371 {
372 imv_workitem_t *workitem;
373 bool is_dir, no_workitems = TRUE;
374 u_int32_t delimiter = SOLIDUS_UTF;
375 u_int16_t request_id;
376 pa_tnc_attr_t *attr;
377 char *pathname;
378 enumerator_t *enumerator;
379
380 attestation_state->set_handshake_state(attestation_state,
381 IMV_ATTESTATION_STATE_END);
382
383 enumerator = session->create_workitem_enumerator(session);
384 if (enumerator)
385 {
386 while (enumerator->enumerate(enumerator, &workitem))
387 {
388 if (workitem->get_imv_id(workitem) != TNC_IMVID_ANY)
389 {
390 continue;
391 }
392
393 switch (workitem->get_type(workitem))
394 {
395 case IMV_WORKITEM_FILE_REF_MEAS:
396 case IMV_WORKITEM_FILE_MEAS:
397 case IMV_WORKITEM_FILE_META:
398 is_dir = FALSE;
399 break;
400 case IMV_WORKITEM_DIR_REF_MEAS:
401 case IMV_WORKITEM_DIR_MEAS:
402 case IMV_WORKITEM_DIR_META:
403 is_dir = TRUE;
404 break;
405 case IMV_WORKITEM_TPM_ATTEST:
406 {
407 pts_component_t *comp;
408 pts_comp_func_name_t *comp_name;
409 TNC_IMV_Action_Recommendation rec;
410 TNC_IMV_Evaluation_Result eval;
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 if (!imv_attestation_build(out_msg, state, this->supported_dh_groups,
539 this->pts_db))
540 {
541 state->set_recommendation(state,
542 TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
543 TNC_IMV_EVALUATION_RESULT_ERROR);
544 result = out_msg->send_assessment(out_msg);
545 out_msg->destroy(out_msg);
546 state->set_action_flags(state, IMV_ATTESTATION_FLAG_REC);
547
548 if (result != TNC_RESULT_SUCCESS)
549 {
550 return result;
551 }
552 return this->agent->provide_recommendation(this->agent, state);
553 }
554
555 /* finalized all workitems? */
556 if (session && session->get_policy_started(session) &&
557 session->get_workitem_count(session, imv_id) == 0 &&
558 attestation_state->get_handshake_state(attestation_state) ==
559 IMV_ATTESTATION_STATE_END)
560 {
561 result = out_msg->send_assessment(out_msg);
562 out_msg->destroy(out_msg);
563 state->set_action_flags(state, IMV_ATTESTATION_FLAG_REC);
564
565 if (result != TNC_RESULT_SUCCESS)
566 {
567 return result;
568 }
569 return this->agent->provide_recommendation(this->agent, state);
570 }
571
572 /* send non-empty PA-TNC message with excl flag not set */
573 if (out_msg->get_attribute_count(out_msg))
574 {
575 result = out_msg->send(out_msg, FALSE);
576 }
577 out_msg->destroy(out_msg);
578
579 return result;
580 }
581
582 METHOD(imv_agent_if_t, solicit_recommendation, TNC_Result,
583 private_imv_attestation_agent_t *this, TNC_ConnectionID id)
584 {
585 TNC_IMVID imv_id;
586 imv_state_t *state;
587 imv_attestation_state_t *attestation_state;
588 imv_session_t *session;
589
590 if (!this->agent->get_state(this->agent, id, &state))
591 {
592 return TNC_RESULT_FATAL;
593 }
594 attestation_state = (imv_attestation_state_t*)state;
595 session = state->get_session(state);
596 imv_id = this->agent->get_id(this->agent);
597
598 if (session)
599 {
600 TNC_IMV_Evaluation_Result eval;
601 TNC_IMV_Action_Recommendation rec;
602 imv_workitem_t *workitem;
603 enumerator_t *enumerator;
604 char *result_str;
605 int pending_file_meas = 0;
606
607 enumerator = session->create_workitem_enumerator(session);
608 if (enumerator)
609 {
610 while (enumerator->enumerate(enumerator, &workitem))
611 {
612 if (workitem->get_imv_id(workitem) != imv_id)
613 {
614 continue;
615 }
616 switch (workitem->get_type(workitem))
617 {
618 case IMV_WORKITEM_FILE_REF_MEAS:
619 case IMV_WORKITEM_FILE_MEAS:
620 case IMV_WORKITEM_DIR_REF_MEAS:
621 case IMV_WORKITEM_DIR_MEAS:
622 result_str = "Pending file measurements";
623 pending_file_meas++;
624 break;
625 case IMV_WORKITEM_TPM_ATTEST:
626 attestation_state->finalize_components(attestation_state);
627 result_str = "Pending component evidence";
628 break;
629 default:
630 continue;
631 }
632 session->remove_workitem(session, enumerator);
633 eval = TNC_IMV_EVALUATION_RESULT_ERROR;
634 rec = workitem->set_result(workitem, result_str, eval);
635 state->update_recommendation(state, rec, eval);
636 imcv_db->finalize_workitem(imcv_db, workitem);
637 workitem->destroy(workitem);
638 }
639 enumerator->destroy(enumerator);
640
641 if (pending_file_meas)
642 {
643 DBG1(DBG_IMV, "failure due to %d pending file measurements",
644 pending_file_meas);
645 attestation_state->set_measurement_error(attestation_state,
646 IMV_ATTESTATION_ERROR_FILE_MEAS_PEND);
647 }
648 }
649 }
650 return this->agent->provide_recommendation(this->agent, state);
651 }
652
653 METHOD(imv_agent_if_t, destroy, void,
654 private_imv_attestation_agent_t *this)
655 {
656 if (this->pts_creds)
657 {
658 this->pts_credmgr->remove_set(this->pts_credmgr,
659 this->pts_creds->get_set(this->pts_creds));
660 this->pts_creds->destroy(this->pts_creds);
661 }
662 DESTROY_IF(this->pts_db);
663 DESTROY_IF(this->pts_credmgr);
664 DESTROY_IF(this->agent);
665 free(this);
666 libpts_deinit();
667 }
668
669 /**
670 * Described in header.
671 */
672 imv_agent_if_t *imv_attestation_agent_create(const char *name, TNC_IMVID id,
673 TNC_Version *actual_version)
674 {
675 private_imv_attestation_agent_t *this;
676 imv_agent_t *agent;
677 char *hash_alg, *dh_group, *cadir;
678
679 agent = imv_agent_create(name, msg_types, countof(msg_types), id,
680 actual_version);
681 if (!agent)
682 {
683 return NULL;
684 }
685
686 hash_alg = lib->settings->get_str(lib->settings,
687 "libimcv.plugins.imv-attestation.hash_algorithm", "sha256");
688 dh_group = lib->settings->get_str(lib->settings,
689 "libimcv.plugins.imv-attestation.dh_group", "ecp256");
690 cadir = lib->settings->get_str(lib->settings,
691 "libimcv.plugins.imv-attestation.cadir", NULL);
692
693 INIT(this,
694 .public = {
695 .bind_functions = _bind_functions,
696 .notify_connection_change = _notify_connection_change,
697 .receive_message = _receive_message,
698 .receive_message_long = _receive_message_long,
699 .batch_ending = _batch_ending,
700 .solicit_recommendation = _solicit_recommendation,
701 .destroy = _destroy,
702 },
703 .agent = agent,
704 .supported_algorithms = PTS_MEAS_ALGO_NONE,
705 .supported_dh_groups = PTS_DH_GROUP_NONE,
706 .pts_credmgr = credential_manager_create(),
707 .pts_creds = pts_creds_create(cadir),
708 .pts_db = pts_database_create(imcv_db),
709 );
710
711 libpts_init();
712
713 if (!pts_meas_algo_probe(&this->supported_algorithms) ||
714 !pts_dh_group_probe(&this->supported_dh_groups) ||
715 !pts_meas_algo_update(hash_alg, &this->supported_algorithms) ||
716 !pts_dh_group_update(dh_group, &this->supported_dh_groups))
717 {
718 destroy(this);
719 return NULL;
720 }
721
722 if (this->pts_creds)
723 {
724 this->pts_credmgr->add_set(this->pts_credmgr,
725 this->pts_creds->get_set(this->pts_creds));
726 }
727
728 return &this->public;
729 }