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