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