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