moved imc_manager to libtnccs
[strongswan.git] / src / libcharon / plugins / tnccs_20 / tnccs_20.c
1 /*
2 * Copyright (C) 2010 Sansar Choinyanbuu
3 * Copyright (C) 2010-2011 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 "tnccs_20.h"
18 #include "batch/pb_tnc_batch.h"
19 #include "messages/pb_tnc_msg.h"
20 #include "messages/pb_pa_msg.h"
21 #include "messages/pb_error_msg.h"
22 #include "messages/pb_assessment_result_msg.h"
23 #include "messages/pb_access_recommendation_msg.h"
24 #include "messages/pb_remediation_parameters_msg.h"
25 #include "messages/pb_reason_string_msg.h"
26 #include "messages/pb_language_preference_msg.h"
27 #include "state_machine/pb_tnc_state_machine.h"
28
29 #include <tncif_names.h>
30 #include <tncif_pa_subtypes.h>
31
32 #include <imc/imc_manager.h>
33
34 #include <debug.h>
35 #include <daemon.h>
36 #include <threading/mutex.h>
37 #include <tnc/tnccs/tnccs.h>
38 #include <pen/pen.h>
39
40 typedef struct private_tnccs_20_t private_tnccs_20_t;
41
42 /**
43 * Private data of a tnccs_20_t object.
44 */
45 struct private_tnccs_20_t {
46
47 /**
48 * Public tls_t interface.
49 */
50 tls_t public;
51
52 /**
53 * TNCC if TRUE, TNCS if FALSE
54 */
55 bool is_server;
56
57 /**
58 * PB-TNC State Machine
59 */
60 pb_tnc_state_machine_t *state_machine;
61
62 /**
63 * Connection ID assigned to this TNCCS connection
64 */
65 TNC_ConnectionID connection_id;
66
67 /**
68 * PB-TNC batch being constructed
69 */
70 pb_tnc_batch_t *batch;
71
72 /**
73 * Mutex locking the batch in construction
74 */
75 mutex_t *mutex;
76
77 /**
78 * Flag set while processing
79 */
80 bool fatal_error;
81
82 /**
83 * Flag set by IMC/IMV RequestHandshakeRetry() function
84 */
85 bool request_handshake_retry;
86
87 /**
88 * SendMessage() by IMC/IMV only allowed if flag is set
89 */
90 bool send_msg;
91
92 /**
93 * Set of IMV recommendations (TNC Server only)
94 */
95 recommendations_t *recs;
96
97 /**
98 * TNC IMC manager controlling Integrity Measurement Collectors
99 */
100 imc_manager_t *imcs;
101
102 };
103
104 METHOD(tnccs_t, send_msg, TNC_Result,
105 private_tnccs_20_t* this, TNC_IMCID imc_id, TNC_IMVID imv_id,
106 TNC_BufferReference msg,
107 TNC_UInt32 msg_len,
108 TNC_MessageType msg_type)
109 {
110 TNC_MessageSubtype msg_sub_type;
111 TNC_VendorID msg_vendor_id;
112 pb_tnc_msg_t *pb_tnc_msg;
113 pb_tnc_batch_type_t batch_type;
114 enum_name_t *pa_subtype_names;
115
116 if (!this->send_msg)
117 {
118 DBG1(DBG_TNC, "%s %u not allowed to call SendMessage()",
119 this->is_server ? "IMV" : "IMC",
120 this->is_server ? imv_id : imc_id);
121 return TNC_RESULT_ILLEGAL_OPERATION;
122 }
123
124 msg_sub_type = msg_type & TNC_SUBTYPE_ANY;
125 msg_vendor_id = (msg_type >> 8) & TNC_VENDORID_ANY;
126
127 pb_tnc_msg = pb_pa_msg_create(msg_vendor_id, msg_sub_type, imc_id, imv_id,
128 chunk_create(msg, msg_len));
129
130 pa_subtype_names = get_pa_subtype_names(msg_vendor_id);
131 if (pa_subtype_names)
132 {
133 DBG2(DBG_TNC, "creating PB-PA message type '%N/%N' 0x%06x/0x%02x",
134 pen_names, msg_vendor_id, pa_subtype_names, msg_sub_type,
135 msg_vendor_id, msg_sub_type);
136 }
137 else
138 {
139 DBG2(DBG_TNC, "creating PB-PA message type '%N' 0x%06x/0x%02x",
140 pen_names, msg_vendor_id, msg_vendor_id, msg_sub_type);
141 }
142
143 /* adding PA message to SDATA or CDATA batch only */
144 batch_type = this->is_server ? PB_BATCH_SDATA : PB_BATCH_CDATA;
145 this->mutex->lock(this->mutex);
146 if (!this->batch)
147 {
148 this->batch = pb_tnc_batch_create(this->is_server, batch_type);
149 }
150 if (this->batch->get_type(this->batch) == batch_type)
151 {
152 this->batch->add_msg(this->batch, pb_tnc_msg);
153 }
154 else
155 {
156 pb_tnc_msg->destroy(pb_tnc_msg);
157 }
158 this->mutex->unlock(this->mutex);
159 return TNC_RESULT_SUCCESS;
160 }
161
162 /**
163 * Handle a single PB-TNC message according to its type
164 */
165 static void handle_message(private_tnccs_20_t *this, pb_tnc_msg_t *msg)
166 {
167 switch (msg->get_type(msg))
168 {
169 case PB_MSG_EXPERIMENTAL:
170 /* nothing to do */
171 break;
172 case PB_MSG_PA:
173 {
174 pb_pa_msg_t *pa_msg;
175 TNC_MessageType msg_type;
176 u_int32_t vendor_id, subtype;
177 chunk_t msg_body;
178 enum_name_t *pa_subtype_names;
179
180 pa_msg = (pb_pa_msg_t*)msg;
181 vendor_id = pa_msg->get_vendor_id(pa_msg, &subtype);
182 msg_type = (vendor_id << 8) | (subtype & 0xff);
183 msg_body = pa_msg->get_body(pa_msg);
184
185 pa_subtype_names = get_pa_subtype_names(vendor_id);
186 if (pa_subtype_names)
187 {
188 DBG2(DBG_TNC, "handling PB-PA message type '%N/%N' 0x%06x/0x%02x",
189 pen_names, vendor_id, pa_subtype_names, subtype,
190 vendor_id, subtype);
191 }
192 else
193 {
194 DBG2(DBG_TNC, "handling PB-PA message type '%N' 0x%06x/0x%02x",
195 pen_names, vendor_id, vendor_id, subtype);
196 }
197
198 this->send_msg = TRUE;
199 if (this->is_server)
200 {
201 charon->imvs->receive_message(charon->imvs,
202 this->connection_id, msg_body.ptr, msg_body.len, msg_type);
203 }
204 else
205 {
206 this->imcs->receive_message(this->imcs,
207 this->connection_id, msg_body.ptr, msg_body.len,msg_type);
208 }
209 this->send_msg = FALSE;
210 break;
211 }
212 case PB_MSG_ASSESSMENT_RESULT:
213 {
214 pb_assessment_result_msg_t *assess_msg;
215 u_int32_t result;
216
217 assess_msg = (pb_assessment_result_msg_t*)msg;
218 result = assess_msg->get_assessment_result(assess_msg);
219 DBG1(DBG_TNC, "PB-TNC assessment result is '%N'",
220 TNC_IMV_Evaluation_Result_names, result);
221 break;
222 }
223 case PB_MSG_ACCESS_RECOMMENDATION:
224 {
225 pb_access_recommendation_msg_t *rec_msg;
226 pb_access_recommendation_code_t rec;
227 TNC_ConnectionState state = TNC_CONNECTION_STATE_ACCESS_NONE;
228
229 rec_msg = (pb_access_recommendation_msg_t*)msg;
230 rec = rec_msg->get_access_recommendation(rec_msg);
231 DBG1(DBG_TNC, "PB-TNC access recommendation is '%N'",
232 pb_access_recommendation_code_names, rec);
233 switch (rec)
234 {
235 case PB_REC_ACCESS_ALLOWED:
236 state = TNC_CONNECTION_STATE_ACCESS_ALLOWED;
237 break;
238 case PB_REC_ACCESS_DENIED:
239 state = TNC_CONNECTION_STATE_ACCESS_NONE;
240 break;
241 case PB_REC_QUARANTINED:
242 state = TNC_CONNECTION_STATE_ACCESS_ISOLATED;
243 }
244 this->imcs->notify_connection_change(this->imcs,
245 this->connection_id, state);
246 break;
247 }
248 case PB_MSG_REMEDIATION_PARAMETERS:
249 {
250 /* TODO : Remediation parameters message processing */
251 break;
252 }
253 case PB_MSG_ERROR:
254 {
255 pb_error_msg_t *err_msg;
256 bool fatal;
257 u_int32_t vendor_id;
258 u_int16_t error_code;
259
260 err_msg = (pb_error_msg_t*)msg;
261 fatal = err_msg->get_fatal_flag(err_msg);
262 vendor_id = err_msg->get_vendor_id(err_msg);
263 error_code = err_msg->get_error_code(err_msg);
264
265 if (fatal)
266 {
267 this->fatal_error = TRUE;
268 }
269
270 if (vendor_id == PEN_IETF)
271 {
272 switch (error_code)
273 {
274 case PB_ERROR_INVALID_PARAMETER:
275 case PB_ERROR_UNSUPPORTED_MANDATORY_MSG:
276 DBG1(DBG_TNC, "received %s PB-TNC error '%N' "
277 "(offset %u bytes)",
278 fatal ? "fatal" : "non-fatal",
279 pb_tnc_error_code_names, error_code,
280 err_msg->get_offset(err_msg));
281 break;
282 case PB_ERROR_VERSION_NOT_SUPPORTED:
283 DBG1(DBG_TNC, "received %s PB-TNC error '%N' "
284 "caused by bad version 0x%02x",
285 fatal ? "fatal" : "non-fatal",
286 pb_tnc_error_code_names, error_code,
287 err_msg->get_bad_version(err_msg));
288 break;
289 case PB_ERROR_UNEXPECTED_BATCH_TYPE:
290 case PB_ERROR_LOCAL_ERROR:
291 default:
292 DBG1(DBG_TNC, "received %s PB-TNC error '%N'",
293 fatal ? "fatal" : "non-fatal",
294 pb_tnc_error_code_names, error_code);
295 break;
296 }
297 }
298 else
299 {
300 DBG1(DBG_TNC, "received %s PB-TNC error (%u) "
301 "with Vendor ID 0x%06x",
302 fatal ? "fatal" : "non-fatal",
303 error_code, vendor_id);
304 }
305 break;
306 }
307 case PB_MSG_LANGUAGE_PREFERENCE:
308 {
309 pb_language_preference_msg_t *lang_msg;
310 chunk_t lang;
311
312 lang_msg = (pb_language_preference_msg_t*)msg;
313 lang = lang_msg->get_language_preference(lang_msg);
314
315 DBG2(DBG_TNC, "setting language preference to '%.*s'",
316 lang.len, lang.ptr);
317 this->recs->set_preferred_language(this->recs, lang);
318 break;
319 }
320 case PB_MSG_REASON_STRING:
321 {
322 pb_reason_string_msg_t *reason_msg;
323 chunk_t reason_string, language_code;
324
325 reason_msg = (pb_reason_string_msg_t*)msg;
326 reason_string = reason_msg->get_reason_string(reason_msg);
327 language_code = reason_msg->get_language_code(reason_msg);
328 DBG2(DBG_TNC, "reason string is '%.*s'", reason_string.len,
329 reason_string.ptr);
330 DBG2(DBG_TNC, "language code is '%.*s'", language_code.len,
331 language_code.ptr);
332 break;
333 }
334 default:
335 break;
336 }
337 }
338
339 /**
340 * Build a CRETRY or SRETRY batch
341 */
342 static void build_retry_batch(private_tnccs_20_t *this)
343 {
344 pb_tnc_batch_type_t batch_retry_type;
345
346 batch_retry_type = this->is_server ? PB_BATCH_SRETRY : PB_BATCH_CRETRY;
347 if (this->batch)
348 {
349 if (this->batch->get_type(this->batch) == batch_retry_type)
350 {
351 /* retry batch has already been created */
352 return;
353 }
354 DBG1(DBG_TNC, "cancelling PB-TNC %N batch",
355 pb_tnc_batch_type_names, this->batch->get_type(this->batch));
356 this->batch->destroy(this->batch);
357 }
358 if (this->is_server)
359 {
360 charon->imvs->notify_connection_change(charon->imvs,
361 this->connection_id, TNC_CONNECTION_STATE_HANDSHAKE);
362 }
363 this->batch = pb_tnc_batch_create(this->is_server, batch_retry_type);
364 }
365
366 METHOD(tls_t, process, status_t,
367 private_tnccs_20_t *this, void *buf, size_t buflen)
368 {
369 chunk_t data;
370 pb_tnc_batch_t *batch;
371 pb_tnc_msg_t *msg;
372 enumerator_t *enumerator;
373 status_t status;
374
375 if (this->is_server && !this->connection_id)
376 {
377 this->connection_id = charon->tnccs->create_connection(charon->tnccs,
378 (tnccs_t*)this, _send_msg,
379 &this->request_handshake_retry, &this->recs);
380 if (!this->connection_id)
381 {
382 return FAILED;
383 }
384 charon->imvs->notify_connection_change(charon->imvs,
385 this->connection_id, TNC_CONNECTION_STATE_CREATE);
386 charon->imvs->notify_connection_change(charon->imvs,
387 this->connection_id, TNC_CONNECTION_STATE_HANDSHAKE);
388 }
389
390 data = chunk_create(buf, buflen);
391 DBG1(DBG_TNC, "received TNCCS batch (%u bytes) for Connection ID %u",
392 data.len, this->connection_id);
393 DBG3(DBG_TNC, "%B", &data);
394 batch = pb_tnc_batch_create_from_data(this->is_server, data);
395 status = batch->process(batch, this->state_machine);
396
397 if (status != FAILED)
398 {
399 enumerator_t *enumerator;
400 pb_tnc_msg_t *msg;
401 pb_tnc_batch_type_t batch_type;
402 bool empty = TRUE;
403
404 batch_type = batch->get_type(batch);
405
406 if (batch_type == PB_BATCH_CRETRY)
407 {
408 /* Send an SRETRY batch in response */
409 this->mutex->lock(this->mutex);
410 build_retry_batch(this);
411 this->mutex->unlock(this->mutex);
412 }
413 else if (batch_type == PB_BATCH_SRETRY)
414 {
415 /* Restart the measurements */
416 this->imcs->notify_connection_change(this->imcs,
417 this->connection_id, TNC_CONNECTION_STATE_HANDSHAKE);
418 this->send_msg = TRUE;
419 this->imcs->begin_handshake(this->imcs, this->connection_id);
420 this->send_msg = FALSE;
421 }
422
423 enumerator = batch->create_msg_enumerator(batch);
424 while (enumerator->enumerate(enumerator, &msg))
425 {
426 handle_message(this, msg);
427 empty = FALSE;
428 }
429 enumerator->destroy(enumerator);
430
431 /* received an empty CLOSE batch from PB-TNC client */
432 if (this->is_server && batch_type == PB_BATCH_CLOSE && empty)
433 {
434 batch->destroy(batch);
435 if (this->fatal_error)
436 {
437 DBG1(DBG_TNC, "a fatal PB-TNC error occurred, "
438 "terminating connection");
439 return FAILED;
440 }
441 else
442 {
443 return SUCCESS;
444 }
445 }
446
447 this->send_msg = TRUE;
448 if (this->is_server)
449 {
450 charon->imvs->batch_ending(charon->imvs, this->connection_id);
451 }
452 else
453 {
454 this->imcs->batch_ending(this->imcs, this->connection_id);
455 }
456 this->send_msg = FALSE;
457 }
458
459 switch (status)
460 {
461 case FAILED:
462 this->fatal_error = TRUE;
463 this->mutex->lock(this->mutex);
464 if (this->batch)
465 {
466 DBG1(DBG_TNC, "cancelling PB-TNC %N batch",
467 pb_tnc_batch_type_names, this->batch->get_type(this->batch));
468 this->batch->destroy(this->batch);
469 }
470 this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_CLOSE);
471 this->mutex->unlock(this->mutex);
472 /* fall through to add error messages to outbound batch */
473 case VERIFY_ERROR:
474 enumerator = batch->create_error_enumerator(batch);
475 while (enumerator->enumerate(enumerator, &msg))
476 {
477 this->mutex->lock(this->mutex);
478 this->batch->add_msg(this->batch, msg->get_ref(msg));
479 this->mutex->unlock(this->mutex);
480 }
481 enumerator->destroy(enumerator);
482 break;
483 case SUCCESS:
484 default:
485 break;
486 }
487 batch->destroy(batch);
488
489 return NEED_MORE;
490 }
491
492 /**
493 * Build a RESULT batch if a final recommendation is available
494 */
495 static void check_and_build_recommendation(private_tnccs_20_t *this)
496 {
497 TNC_IMV_Action_Recommendation rec;
498 TNC_IMV_Evaluation_Result eval;
499 TNC_IMVID id;
500 chunk_t reason, language;
501 enumerator_t *enumerator;
502 pb_tnc_msg_t *msg;
503 pb_access_recommendation_code_t pb_rec;
504
505 if (!this->recs->have_recommendation(this->recs, &rec, &eval))
506 {
507 charon->imvs->solicit_recommendation(charon->imvs, this->connection_id);
508 }
509 if (this->recs->have_recommendation(this->recs, &rec, &eval))
510 {
511 this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_RESULT);
512
513 msg = pb_assessment_result_msg_create(eval);
514 this->batch->add_msg(this->batch, msg);
515
516 /**
517 * Map IMV Action Recommendation codes to PB Access Recommendation codes
518 */
519 switch (rec)
520 {
521 case TNC_IMV_ACTION_RECOMMENDATION_ALLOW:
522 pb_rec = PB_REC_ACCESS_ALLOWED;
523 break;
524 case TNC_IMV_ACTION_RECOMMENDATION_ISOLATE:
525 pb_rec = PB_REC_QUARANTINED;
526 break;
527 case TNC_IMV_ACTION_RECOMMENDATION_NO_ACCESS:
528 case TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION:
529 default:
530 pb_rec = PB_REC_ACCESS_DENIED;
531 }
532 msg = pb_access_recommendation_msg_create(pb_rec);
533 this->batch->add_msg(this->batch, msg);
534
535 enumerator = this->recs->create_reason_enumerator(this->recs);
536 while (enumerator->enumerate(enumerator, &id, &reason, &language))
537 {
538 msg = pb_reason_string_msg_create(reason, language);
539 this->batch->add_msg(this->batch, msg);
540 }
541 enumerator->destroy(enumerator);
542 this->recs->clear_reasons(this->recs);
543 }
544 }
545
546 METHOD(tls_t, build, status_t,
547 private_tnccs_20_t *this, void *buf, size_t *buflen, size_t *msglen)
548 {
549 status_t status;
550 pb_tnc_state_t state;
551
552 /* Initialize the connection */
553 if (!this->is_server && !this->connection_id)
554 {
555 pb_tnc_msg_t *msg;
556 char *pref_lang;
557
558 this->connection_id = charon->tnccs->create_connection(charon->tnccs,
559 (tnccs_t*)this, _send_msg,
560 &this->request_handshake_retry, NULL);
561 if (!this->connection_id)
562 {
563 return FAILED;
564 }
565
566 /* Create PB-TNC Language Preference message */
567 pref_lang = this->imcs->get_preferred_language(this->imcs);
568 msg = pb_language_preference_msg_create(chunk_create(pref_lang,
569 strlen(pref_lang)));
570 this->mutex->lock(this->mutex);
571 this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_CDATA);
572 this->batch->add_msg(this->batch, msg);
573 this->mutex->unlock(this->mutex);
574
575 this->imcs->notify_connection_change(this->imcs,
576 this->connection_id, TNC_CONNECTION_STATE_CREATE);
577 this->imcs->notify_connection_change(this->imcs,
578 this->connection_id, TNC_CONNECTION_STATE_HANDSHAKE);
579 this->send_msg = TRUE;
580 this->imcs->begin_handshake(this->imcs, this->connection_id);
581 this->send_msg = FALSE;
582 }
583
584 state = this->state_machine->get_state(this->state_machine);
585
586 if (this->is_server && this->fatal_error && state == PB_STATE_END)
587 {
588 DBG1(DBG_TNC, "a fatal PB-TNC error occurred, terminating connection");
589 return FAILED;
590 }
591
592 /* Do not allow any asynchronous IMCs or IMVs to add additional messages */
593 this->mutex->lock(this->mutex);
594
595 if (this->request_handshake_retry)
596 {
597 if (state != PB_STATE_INIT)
598 {
599 build_retry_batch(this);
600 }
601
602 /* Reset the flag for the next handshake retry request */
603 this->request_handshake_retry = FALSE;
604 }
605
606 if (!this->batch)
607 {
608 if (this->is_server)
609 {
610 if (state == PB_STATE_SERVER_WORKING)
611 {
612 check_and_build_recommendation(this);
613 }
614 }
615 else
616 {
617 /**
618 * if the DECIDED state has been reached and no CRETRY is under way
619 * or if a CLOSE batch with error messages has been received,
620 * a PB-TNC client replies with an empty CLOSE batch.
621 */
622 if (state == PB_STATE_DECIDED || state == PB_STATE_END)
623 {
624 this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_CLOSE);
625 }
626 }
627 }
628
629 if (this->batch)
630 {
631 pb_tnc_batch_type_t batch_type;
632 chunk_t data;
633
634 batch_type = this->batch->get_type(this->batch);
635
636 if (this->state_machine->send_batch(this->state_machine, batch_type))
637 {
638 this->batch->build(this->batch);
639 data = this->batch->get_encoding(this->batch);
640 DBG1(DBG_TNC, "sending PB-TNC %N batch (%d bytes) for Connection ID %u",
641 pb_tnc_batch_type_names, batch_type, data.len,
642 this->connection_id);
643 DBG3(DBG_TNC, "%B", &data);
644 *msglen = data.len;
645
646 if (data.len > *buflen)
647 {
648 DBG1(DBG_TNC, "fragmentation of PB-TNC batch not supported yet");
649 }
650 else
651 {
652 *buflen = data.len;
653 }
654 memcpy(buf, data.ptr, *buflen);
655 status = ALREADY_DONE;
656 }
657 else
658 {
659 DBG1(DBG_TNC, "cancelling unexpected PB-TNC batch type: %N",
660 pb_tnc_batch_type_names, batch_type);
661 status = INVALID_STATE;
662 }
663
664 this->batch->destroy(this->batch);
665 this->batch = NULL;
666 }
667 else
668 {
669 DBG1(DBG_TNC, "no PB-TNC batch to send");
670 status = INVALID_STATE;
671 }
672 this->mutex->unlock(this->mutex);
673
674 return status;
675 }
676
677 METHOD(tls_t, is_server, bool,
678 private_tnccs_20_t *this)
679 {
680 return this->is_server;
681 }
682
683 METHOD(tls_t, get_purpose, tls_purpose_t,
684 private_tnccs_20_t *this)
685 {
686 return TLS_PURPOSE_EAP_TNC;
687 }
688
689 METHOD(tls_t, is_complete, bool,
690 private_tnccs_20_t *this)
691 {
692 TNC_IMV_Action_Recommendation rec;
693 TNC_IMV_Evaluation_Result eval;
694
695 if (this->recs && this->recs->have_recommendation(this->recs, &rec, &eval))
696 {
697 return charon->imvs->enforce_recommendation(charon->imvs, rec, eval);
698 }
699 else
700 {
701 return FALSE;
702 }
703 }
704
705 METHOD(tls_t, get_eap_msk, chunk_t,
706 private_tnccs_20_t *this)
707 {
708 return chunk_empty;
709 }
710
711 METHOD(tls_t, destroy, void,
712 private_tnccs_20_t *this)
713 {
714 charon->tnccs->remove_connection(charon->tnccs, this->connection_id,
715 this->is_server);
716 this->state_machine->destroy(this->state_machine);
717 this->mutex->destroy(this->mutex);
718 DESTROY_IF(this->batch);
719 free(this);
720 }
721
722 /**
723 * See header
724 */
725 tls_t *tnccs_20_create(bool is_server)
726 {
727 private_tnccs_20_t *this;
728
729 INIT(this,
730 .public = {
731 .process = _process,
732 .build = _build,
733 .is_server = _is_server,
734 .get_purpose = _get_purpose,
735 .is_complete = _is_complete,
736 .get_eap_msk = _get_eap_msk,
737 .destroy = _destroy,
738 },
739 .is_server = is_server,
740 .state_machine = pb_tnc_state_machine_create(is_server),
741 .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
742 .imcs = lib->get(lib, "imc-manager"),
743 );
744
745 return &this->public;
746 }