2 * Copyright (C) 2010 Sansar Choinyanbuu
3 * Copyright (C) 2010-2013 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
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>.
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
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"
29 #include <tncif_names.h>
30 #include <tncif_pa_subtypes.h>
33 #include <tnc/tnccs/tnccs_manager.h>
34 #include <tnc/imc/imc_manager.h>
35 #include <tnc/imv/imv_manager.h>
37 #include <threading/mutex.h>
38 #include <utils/debug.h>
39 #include <collections/linked_list.h>
42 typedef struct private_tnccs_20_t private_tnccs_20_t
;
45 * Private data of a tnccs_20_t object.
47 struct private_tnccs_20_t
{
50 * Public tnccs_t interface.
55 * TNCC if TRUE, TNCS if FALSE
62 identification_t
*server
;
67 identification_t
*peer
;
70 * Underlying TNC IF-T transport protocol
72 tnc_ift_type_t transport
;
75 * Type of TNC client authentication
80 * PB-TNC State Machine
82 pb_tnc_state_machine_t
*state_machine
;
85 * Connection ID assigned to this TNCCS connection
87 TNC_ConnectionID connection_id
;
90 * PB-TNC messages to be sent
92 linked_list_t
*messages
;
95 * Type of PB-TNC batch being constructed
97 pb_tnc_batch_type_t batch_type
;
100 * Maximum PB-TNC batch size
102 size_t max_batch_len
;
105 * Maximum PA-TNC message size
110 * Mutex locking the batch in construction
115 * Flag set while processing
120 * Flag set by IMC/IMV RequestHandshakeRetry() function
122 bool request_handshake_retry
;
125 * SendMessage() by IMC/IMV only allowed if flag is set
130 * Set of IMV recommendations (TNC Server only)
132 recommendations_t
*recs
;
135 * Callback function to communicate recommendation (TNC Server only)
140 * Data to pass to callback function (TNC Server only)
147 * If the batch type changes then delete all accumulated PB-TNC messages
149 void change_batch_type(private_tnccs_20_t
*this, pb_tnc_batch_type_t batch_type
)
153 if (batch_type
!= this->batch_type
)
155 if (this->batch_type
!= PB_BATCH_NONE
)
157 DBG1(DBG_TNC
, "cancelling PB-TNC %N batch",
158 pb_tnc_batch_type_names
, this->batch_type
);
160 while (this->messages
->remove_last(this->messages
,
161 (void**)&msg
) == SUCCESS
)
166 this->batch_type
= batch_type
;
170 METHOD(tnccs_t
, send_msg
, TNC_Result
,
171 private_tnccs_20_t
* this, TNC_IMCID imc_id
, TNC_IMVID imv_id
,
172 TNC_UInt32 msg_flags
,
173 TNC_BufferReference msg
,
175 TNC_VendorID msg_vid
,
176 TNC_MessageSubtype msg_subtype
)
178 pb_tnc_msg_t
*pb_tnc_msg
;
179 pb_tnc_batch_type_t batch_type
;
180 enum_name_t
*pa_subtype_names
;
185 DBG1(DBG_TNC
, "%s %u not allowed to call SendMessage()",
186 this->is_server ?
"IMV" : "IMC",
187 this->is_server ? imv_id
: imc_id
);
188 return TNC_RESULT_ILLEGAL_OPERATION
;
190 excl
= (msg_flags
& TNC_MESSAGE_FLAGS_EXCLUSIVE
) != 0;
192 pb_tnc_msg
= pb_pa_msg_create(msg_vid
, msg_subtype
, imc_id
, imv_id
,
193 excl
, chunk_create(msg
, msg_len
));
195 pa_subtype_names
= get_pa_subtype_names(msg_vid
);
196 if (pa_subtype_names
)
198 DBG2(DBG_TNC
, "creating PB-PA message type '%N/%N' 0x%06x/0x%08x",
199 pen_names
, msg_vid
, pa_subtype_names
, msg_subtype
,
200 msg_vid
, msg_subtype
);
204 DBG2(DBG_TNC
, "creating PB-PA message type '%N' 0x%06x/0x%08x",
205 pen_names
, msg_vid
, msg_vid
, msg_subtype
);
208 /* adding PA message to SDATA or CDATA batch only */
209 batch_type
= this->is_server ? PB_BATCH_SDATA
: PB_BATCH_CDATA
;
210 this->mutex
->lock(this->mutex
);
211 if (this->batch_type
== PB_BATCH_NONE
)
213 this->batch_type
= batch_type
;
215 if (this->batch_type
== batch_type
)
217 this->messages
->insert_last(this->messages
, pb_tnc_msg
);
221 pb_tnc_msg
->destroy(pb_tnc_msg
);
223 this->mutex
->unlock(this->mutex
);
224 return TNC_RESULT_SUCCESS
;
228 * Handle a single PB-TNC message according to its type
230 static void handle_message(private_tnccs_20_t
*this, pb_tnc_msg_t
*msg
)
232 switch (msg
->get_type(msg
))
234 case PB_MSG_EXPERIMENTAL
:
240 pen_type_t msg_subtype
;
241 u_int16_t imc_id
, imv_id
;
244 enum_name_t
*pa_subtype_names
;
246 pa_msg
= (pb_pa_msg_t
*)msg
;
247 msg_subtype
= pa_msg
->get_subtype(pa_msg
);
248 msg_body
= pa_msg
->get_body(pa_msg
);
249 imc_id
= pa_msg
->get_collector_id(pa_msg
);
250 imv_id
= pa_msg
->get_validator_id(pa_msg
);
251 excl
= pa_msg
->get_exclusive_flag(pa_msg
);
253 pa_subtype_names
= get_pa_subtype_names(msg_subtype
.vendor_id
);
254 if (pa_subtype_names
)
256 DBG2(DBG_TNC
, "handling PB-PA message type '%N/%N' 0x%06x/0x%08x",
257 pen_names
, msg_subtype
.vendor_id
, pa_subtype_names
,
258 msg_subtype
.type
, msg_subtype
.vendor_id
, msg_subtype
.type
);
262 DBG2(DBG_TNC
, "handling PB-PA message type '%N' 0x%06x/0x%08x",
263 pen_names
, msg_subtype
.vendor_id
, msg_subtype
.vendor_id
,
267 this->send_msg
= TRUE
;
270 tnc
->imvs
->receive_message(tnc
->imvs
, this->connection_id
,
271 excl
, msg_body
.ptr
, msg_body
.len
,
272 msg_subtype
.vendor_id
,
273 msg_subtype
.type
, imc_id
, imv_id
);
277 tnc
->imcs
->receive_message(tnc
->imcs
, this->connection_id
,
278 excl
, msg_body
.ptr
, msg_body
.len
,
279 msg_subtype
.vendor_id
,
280 msg_subtype
.type
, imv_id
, imc_id
);
282 this->send_msg
= FALSE
;
285 case PB_MSG_ASSESSMENT_RESULT
:
287 pb_assessment_result_msg_t
*assess_msg
;
290 assess_msg
= (pb_assessment_result_msg_t
*)msg
;
291 result
= assess_msg
->get_assessment_result(assess_msg
);
292 DBG1(DBG_TNC
, "PB-TNC assessment result is '%N'",
293 TNC_IMV_Evaluation_Result_names
, result
);
296 case PB_MSG_ACCESS_RECOMMENDATION
:
298 pb_access_recommendation_msg_t
*rec_msg
;
299 pb_access_recommendation_code_t rec
;
300 TNC_ConnectionState state
= TNC_CONNECTION_STATE_ACCESS_NONE
;
302 rec_msg
= (pb_access_recommendation_msg_t
*)msg
;
303 rec
= rec_msg
->get_access_recommendation(rec_msg
);
304 DBG1(DBG_TNC
, "PB-TNC access recommendation is '%N'",
305 pb_access_recommendation_code_names
, rec
);
308 case PB_REC_ACCESS_ALLOWED
:
309 state
= TNC_CONNECTION_STATE_ACCESS_ALLOWED
;
311 case PB_REC_ACCESS_DENIED
:
312 state
= TNC_CONNECTION_STATE_ACCESS_NONE
;
314 case PB_REC_QUARANTINED
:
315 state
= TNC_CONNECTION_STATE_ACCESS_ISOLATED
;
317 tnc
->imcs
->notify_connection_change(tnc
->imcs
, this->connection_id
,
321 case PB_MSG_REMEDIATION_PARAMETERS
:
323 pb_remediation_parameters_msg_t
*rem_msg
;
324 pen_type_t parameters_type
;
325 chunk_t parameters
, string
, lang_code
;
327 rem_msg
= (pb_remediation_parameters_msg_t
*)msg
;
328 parameters_type
= rem_msg
->get_parameters_type(rem_msg
);
329 parameters
= rem_msg
->get_parameters(rem_msg
);
331 if (parameters_type
.vendor_id
== PEN_IETF
)
333 switch (parameters_type
.type
)
335 case PB_REMEDIATION_URI
:
336 DBG1(DBG_TNC
, "remediation uri: %.*s",
337 parameters
.len
, parameters
.ptr
);
339 case PB_REMEDIATION_STRING
:
340 string
= rem_msg
->get_string(rem_msg
, &lang_code
);
341 DBG1(DBG_TNC
, "remediation string: [%.*s]\n%.*s",
342 lang_code
.len
, lang_code
.ptr
,
343 string
.len
, string
.ptr
);
346 DBG1(DBG_TNC
, "remediation parameters: %B", ¶meters
);
351 DBG1(DBG_TNC
, "remediation parameters: %B", ¶meters
);
357 pb_error_msg_t
*err_msg
;
360 u_int16_t error_code
;
362 err_msg
= (pb_error_msg_t
*)msg
;
363 fatal
= err_msg
->get_fatal_flag(err_msg
);
364 vendor_id
= err_msg
->get_vendor_id(err_msg
);
365 error_code
= err_msg
->get_error_code(err_msg
);
369 this->fatal_error
= TRUE
;
372 if (vendor_id
== PEN_IETF
)
376 case PB_ERROR_INVALID_PARAMETER
:
377 case PB_ERROR_UNSUPPORTED_MANDATORY_MSG
:
378 DBG1(DBG_TNC
, "received %s PB-TNC error '%N' "
380 fatal ?
"fatal" : "non-fatal",
381 pb_tnc_error_code_names
, error_code
,
382 err_msg
->get_offset(err_msg
));
384 case PB_ERROR_VERSION_NOT_SUPPORTED
:
385 DBG1(DBG_TNC
, "received %s PB-TNC error '%N' "
386 "caused by bad version 0x%02x",
387 fatal ?
"fatal" : "non-fatal",
388 pb_tnc_error_code_names
, error_code
,
389 err_msg
->get_bad_version(err_msg
));
391 case PB_ERROR_UNEXPECTED_BATCH_TYPE
:
392 case PB_ERROR_LOCAL_ERROR
:
394 DBG1(DBG_TNC
, "received %s PB-TNC error '%N'",
395 fatal ?
"fatal" : "non-fatal",
396 pb_tnc_error_code_names
, error_code
);
402 DBG1(DBG_TNC
, "received %s PB-TNC error (%u) "
403 "with Vendor ID 0x%06x",
404 fatal ?
"fatal" : "non-fatal",
405 error_code
, vendor_id
);
409 case PB_MSG_LANGUAGE_PREFERENCE
:
411 pb_language_preference_msg_t
*lang_msg
;
414 lang_msg
= (pb_language_preference_msg_t
*)msg
;
415 lang
= lang_msg
->get_language_preference(lang_msg
);
419 DBG2(DBG_TNC
, "setting language preference to '%.*s'",
420 (int)lang
.len
, lang
.ptr
);
421 this->recs
->set_preferred_language(this->recs
, lang
);
425 case PB_MSG_REASON_STRING
:
427 pb_reason_string_msg_t
*reason_msg
;
428 chunk_t reason_string
, language_code
;
430 reason_msg
= (pb_reason_string_msg_t
*)msg
;
431 reason_string
= reason_msg
->get_reason_string(reason_msg
);
432 language_code
= reason_msg
->get_language_code(reason_msg
);
433 DBG1(DBG_TNC
, "reason string is '%.*s' [%.*s]",
434 (int)reason_string
.len
, reason_string
.ptr
,
435 (int)language_code
.len
, language_code
.ptr
);
444 * Build a CRETRY or SRETRY batch
446 static void build_retry_batch(private_tnccs_20_t
*this)
448 pb_tnc_batch_type_t batch_retry_type
;
450 batch_retry_type
= this->is_server ? PB_BATCH_SRETRY
: PB_BATCH_CRETRY
;
451 if (this->batch_type
== batch_retry_type
)
453 /* retry batch has already been selected */
457 change_batch_type(this, batch_retry_type
);
461 this->recs
->clear_recommendation(this->recs
);
462 tnc
->imvs
->notify_connection_change(tnc
->imvs
, this->connection_id
,
463 TNC_CONNECTION_STATE_HANDSHAKE
);
467 METHOD(tls_t
, process
, status_t
,
468 private_tnccs_20_t
*this, void *buf
, size_t buflen
)
471 pb_tnc_batch_t
*batch
;
473 enumerator_t
*enumerator
;
476 if (this->is_server
&& !this->connection_id
)
478 this->connection_id
= tnc
->tnccs
->create_connection(tnc
->tnccs
,
479 TNCCS_2_0
, (tnccs_t
*)this, _send_msg
,
480 &this->request_handshake_retry
,
481 this->max_msg_len
, &this->recs
);
482 if (!this->connection_id
)
486 tnc
->imvs
->notify_connection_change(tnc
->imvs
, this->connection_id
,
487 TNC_CONNECTION_STATE_CREATE
);
488 tnc
->imvs
->notify_connection_change(tnc
->imvs
, this->connection_id
,
489 TNC_CONNECTION_STATE_HANDSHAKE
);
492 data
= chunk_create(buf
, buflen
);
493 DBG1(DBG_TNC
, "received TNCCS batch (%u bytes) for Connection ID %u",
494 data
.len
, this->connection_id
);
495 DBG3(DBG_TNC
, "%B", &data
);
496 batch
= pb_tnc_batch_create_from_data(this->is_server
, data
);
497 status
= batch
->process(batch
, this->state_machine
);
499 if (status
!= FAILED
)
501 enumerator_t
*enumerator
;
503 pb_tnc_batch_type_t batch_type
;
506 batch_type
= batch
->get_type(batch
);
508 if (batch_type
== PB_BATCH_CRETRY
)
510 /* Send an SRETRY batch in response */
511 this->mutex
->lock(this->mutex
);
512 build_retry_batch(this);
513 this->mutex
->unlock(this->mutex
);
515 else if (batch_type
== PB_BATCH_SRETRY
)
517 /* Restart the measurements */
518 tnc
->imcs
->notify_connection_change(tnc
->imcs
,
519 this->connection_id
, TNC_CONNECTION_STATE_HANDSHAKE
);
520 this->send_msg
= TRUE
;
521 tnc
->imcs
->begin_handshake(tnc
->imcs
, this->connection_id
);
522 this->send_msg
= FALSE
;
525 enumerator
= batch
->create_msg_enumerator(batch
);
526 while (enumerator
->enumerate(enumerator
, &msg
))
528 handle_message(this, msg
);
531 enumerator
->destroy(enumerator
);
533 /* received an empty CLOSE batch from PB-TNC client */
534 if (this->is_server
&& batch_type
== PB_BATCH_CLOSE
&& empty
)
536 batch
->destroy(batch
);
537 if (this->fatal_error
)
539 DBG1(DBG_TNC
, "a fatal PB-TNC error occurred, "
540 "terminating connection");
549 this->send_msg
= TRUE
;
552 tnc
->imvs
->batch_ending(tnc
->imvs
, this->connection_id
);
556 tnc
->imcs
->batch_ending(tnc
->imcs
, this->connection_id
);
558 this->send_msg
= FALSE
;
564 this->fatal_error
= TRUE
;
565 this->mutex
->lock(this->mutex
);
566 change_batch_type(this, PB_BATCH_CLOSE
);
567 this->mutex
->unlock(this->mutex
);
568 /* fall through to add error messages to outbound batch */
570 enumerator
= batch
->create_error_enumerator(batch
);
571 while (enumerator
->enumerate(enumerator
, &msg
))
573 this->mutex
->lock(this->mutex
);
574 this->messages
->insert_last(this->messages
, msg
->get_ref(msg
));
575 this->mutex
->unlock(this->mutex
);
577 enumerator
->destroy(enumerator
);
583 batch
->destroy(batch
);
589 * Build a RESULT batch if a final recommendation is available
591 static void check_and_build_recommendation(private_tnccs_20_t
*this)
593 TNC_IMV_Action_Recommendation rec
;
594 TNC_IMV_Evaluation_Result eval
;
595 TNC_ConnectionState state
;
597 chunk_t reason
, language
;
598 enumerator_t
*enumerator
;
600 pb_access_recommendation_code_t pb_rec
;
602 if (!this->recs
->have_recommendation(this->recs
, &rec
, &eval
))
604 tnc
->imvs
->solicit_recommendation(tnc
->imvs
, this->connection_id
);
606 if (this->recs
->have_recommendation(this->recs
, &rec
, &eval
))
608 this->batch_type
= PB_BATCH_RESULT
;
610 msg
= pb_assessment_result_msg_create(eval
);
611 this->messages
->insert_last(this->messages
, msg
);
614 * Map IMV Action Recommendation codes to PB Access Recommendation codes
615 * and communicate Access Recommendation to IMVs
619 case TNC_IMV_ACTION_RECOMMENDATION_ALLOW
:
620 state
= TNC_CONNECTION_STATE_ACCESS_ALLOWED
;
621 pb_rec
= PB_REC_ACCESS_ALLOWED
;
623 case TNC_IMV_ACTION_RECOMMENDATION_ISOLATE
:
624 state
= TNC_CONNECTION_STATE_ACCESS_ISOLATED
;
625 pb_rec
= PB_REC_QUARANTINED
;
627 case TNC_IMV_ACTION_RECOMMENDATION_NO_ACCESS
:
628 case TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION
:
630 state
= TNC_CONNECTION_STATE_ACCESS_NONE
;
631 pb_rec
= PB_REC_ACCESS_DENIED
;
633 tnc
->imvs
->notify_connection_change(tnc
->imvs
, this->connection_id
,
636 msg
= pb_access_recommendation_msg_create(pb_rec
);
637 this->messages
->insert_last(this->messages
, msg
);
639 enumerator
= this->recs
->create_reason_enumerator(this->recs
);
640 while (enumerator
->enumerate(enumerator
, &id
, &reason
, &language
))
642 msg
= pb_reason_string_msg_create(reason
, language
);
643 this->messages
->insert_last(this->messages
, msg
);
645 enumerator
->destroy(enumerator
);
649 METHOD(tls_t
, build
, status_t
,
650 private_tnccs_20_t
*this, void *buf
, size_t *buflen
, size_t *msglen
)
653 pb_tnc_state_t state
;
655 /* Initialize the connection */
656 if (!this->is_server
&& !this->connection_id
)
661 this->connection_id
= tnc
->tnccs
->create_connection(tnc
->tnccs
,
662 TNCCS_2_0
, (tnccs_t
*)this, _send_msg
,
663 &this->request_handshake_retry
,
664 this->max_msg_len
, NULL
);
665 if (!this->connection_id
)
670 /* Create PB-TNC Language Preference message */
671 pref_lang
= tnc
->imcs
->get_preferred_language(tnc
->imcs
);
672 msg
= pb_language_preference_msg_create(chunk_create(pref_lang
,
674 this->mutex
->lock(this->mutex
);
675 this->batch_type
= PB_BATCH_CDATA
;
676 this->messages
->insert_last(this->messages
, msg
);
677 this->mutex
->unlock(this->mutex
);
679 tnc
->imcs
->notify_connection_change(tnc
->imcs
, this->connection_id
,
680 TNC_CONNECTION_STATE_CREATE
);
681 tnc
->imcs
->notify_connection_change(tnc
->imcs
, this->connection_id
,
682 TNC_CONNECTION_STATE_HANDSHAKE
);
683 this->send_msg
= TRUE
;
684 tnc
->imcs
->begin_handshake(tnc
->imcs
, this->connection_id
);
685 this->send_msg
= FALSE
;
688 state
= this->state_machine
->get_state(this->state_machine
);
690 if (this->fatal_error
&& state
== PB_STATE_END
)
692 DBG1(DBG_TNC
, "a fatal PB-TNC error occurred, terminating connection");
696 /* Do not allow any asynchronous IMCs or IMVs to add additional messages */
697 this->mutex
->lock(this->mutex
);
699 if (this->request_handshake_retry
)
701 if (state
!= PB_STATE_INIT
)
703 build_retry_batch(this);
706 /* Reset the flag for the next handshake retry request */
707 this->request_handshake_retry
= FALSE
;
710 if (this->is_server
&& state
== PB_STATE_SERVER_WORKING
&&
711 this->recs
->have_recommendation(this->recs
, NULL
, NULL
))
713 check_and_build_recommendation(this);
716 if (this->batch_type
== PB_BATCH_NONE
)
720 if (state
== PB_STATE_SERVER_WORKING
)
722 if (this->state_machine
->get_empty_cdata(this->state_machine
))
724 check_and_build_recommendation(this);
728 DBG2(DBG_TNC
, "no recommendation available yet, "
729 "sending empty PB-TNC SDATA batch");
730 this->batch_type
= PB_BATCH_SDATA
;
738 case PB_STATE_CLIENT_WORKING
:
739 DBG2(DBG_TNC
, "no client data to send, "
740 "sending empty PB-TNC CDATA batch");
741 this->batch_type
= PB_BATCH_CDATA
;
743 case PB_STATE_DECIDED
:
745 * In the DECIDED state and if no CRETRY is under way,
746 * a PB-TNC client replies with an empty CLOSE batch.
748 this->batch_type
= PB_BATCH_CLOSE
;
756 if (this->batch_type
!= PB_BATCH_NONE
)
758 pb_tnc_batch_t
*batch
;
762 enumerator_t
*enumerator
;
764 if (this->state_machine
->send_batch(this->state_machine
, this->batch_type
))
766 batch
= pb_tnc_batch_create(this->is_server
, this->batch_type
,
767 min(this->max_batch_len
, *buflen
));
769 enumerator
= this->messages
->create_enumerator(this->messages
);
770 while (enumerator
->enumerate(enumerator
, &msg
))
772 if (batch
->add_msg(batch
, msg
))
774 this->messages
->remove_at(this->messages
, enumerator
);
781 enumerator
->destroy(enumerator
);
784 data
= batch
->get_encoding(batch
);
785 DBG1(DBG_TNC
, "sending PB-TNC %N batch (%d bytes) for Connection ID %u",
786 pb_tnc_batch_type_names
, this->batch_type
, data
.len
,
787 this->connection_id
);
788 DBG3(DBG_TNC
, "%B", &data
);
792 memcpy(buf
, data
.ptr
, *buflen
);
793 batch
->destroy(batch
);
795 msg_count
= this->messages
->get_count(this->messages
);
798 DBG2(DBG_TNC
, "queued %d PB-TNC message%s for next %N batch",
799 msg_count
, (msg_count
== 1) ?
"" : "s",
800 pb_tnc_batch_type_names
, this->batch_type
);
804 this->batch_type
= PB_BATCH_NONE
;
807 status
= ALREADY_DONE
;
811 change_batch_type(this, PB_BATCH_NONE
);
812 status
= INVALID_STATE
;
817 DBG1(DBG_TNC
, "no PB-TNC batch to send");
818 status
= INVALID_STATE
;
820 this->mutex
->unlock(this->mutex
);
825 METHOD(tls_t
, is_server
, bool,
826 private_tnccs_20_t
*this)
828 return this->is_server
;
831 METHOD(tls_t
, get_server_id
, identification_t
*,
832 private_tnccs_20_t
*this)
837 METHOD(tls_t
, set_peer_id
, void,
838 private_tnccs_20_t
*this, identification_t
*id
)
840 DESTROY_IF(this->peer
);
841 this->peer
= id
->clone(id
);
844 METHOD(tls_t
, get_peer_id
, identification_t
*,
845 private_tnccs_20_t
*this)
850 METHOD(tls_t
, get_purpose
, tls_purpose_t
,
851 private_tnccs_20_t
*this)
853 return TLS_PURPOSE_EAP_TNC
;
856 METHOD(tls_t
, is_complete
, bool,
857 private_tnccs_20_t
*this)
859 TNC_IMV_Action_Recommendation rec
;
860 TNC_IMV_Evaluation_Result eval
;
862 if (this->recs
&& this->recs
->have_recommendation(this->recs
, &rec
, &eval
))
864 return this->callback ?
this->callback(rec
, eval
) : TRUE
;
872 METHOD(tls_t
, get_eap_msk
, chunk_t
,
873 private_tnccs_20_t
*this)
878 METHOD(tls_t
, destroy
, void,
879 private_tnccs_20_t
*this)
881 tnc
->tnccs
->remove_connection(tnc
->tnccs
, this->connection_id
,
883 this->server
->destroy(this->server
);
884 this->peer
->destroy(this->peer
);
885 this->state_machine
->destroy(this->state_machine
);
886 this->mutex
->destroy(this->mutex
);
887 this->messages
->destroy_offset(this->messages
,
888 offsetof(pb_tnc_msg_t
, destroy
));
892 METHOD(tnccs_t
, get_transport
, tnc_ift_type_t
,
893 private_tnccs_20_t
*this)
895 return this->transport
;
898 METHOD(tnccs_t
, set_transport
, void,
899 private_tnccs_20_t
*this, tnc_ift_type_t transport
)
901 this->transport
= transport
;
904 METHOD(tnccs_t
, get_auth_type
, u_int32_t
,
905 private_tnccs_20_t
*this)
907 return this->auth_type
;
910 METHOD(tnccs_t
, set_auth_type
, void,
911 private_tnccs_20_t
*this, u_int32_t auth_type
)
913 this->auth_type
= auth_type
;
919 tnccs_t
* tnccs_20_create(bool is_server
,
920 identification_t
*server
, identification_t
*peer
,
921 tnc_ift_type_t transport
, tnccs_cb_t cb
)
923 private_tnccs_20_t
*this;
930 .is_server
= _is_server
,
931 .get_server_id
= _get_server_id
,
932 .set_peer_id
= _set_peer_id
,
933 .get_peer_id
= _get_peer_id
,
934 .get_purpose
= _get_purpose
,
935 .is_complete
= _is_complete
,
936 .get_eap_msk
= _get_eap_msk
,
939 .get_transport
= _get_transport
,
940 .set_transport
= _set_transport
,
941 .get_auth_type
= _get_auth_type
,
942 .set_auth_type
= _set_auth_type
,
944 .is_server
= is_server
,
945 .server
= server
->clone(server
),
946 .peer
= peer
->clone(peer
),
947 .transport
= transport
,
949 .state_machine
= pb_tnc_state_machine_create(is_server
),
950 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
951 .messages
= linked_list_create(),
952 .max_batch_len
= lib
->settings
->get_int(lib
->settings
,
953 "libtnccs.plugins.tnccs-20.max_batch_size", 65522),
954 .max_msg_len
= lib
->settings
->get_int(lib
->settings
,
955 "libtnccs.plugins.tnccs-20.max_message_size", 65490),
958 return &this->public;