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