removed unused variables
[strongswan.git] / src / libcharon / plugins / eap_tnc / eap_tnc.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "eap_tnc.h"
17
18 #include <tnc/tnc.h>
19 #include <tnc/tnccs/tnccs_manager.h>
20 #include <tls_eap.h>
21 #include <debug.h>
22 #include <daemon.h>
23
24 /**
25 * Maximum size of an EAP-TNC message
26 */
27 #define EAP_TNC_MAX_MESSAGE_LEN 65535
28
29 /**
30 * Maximum number of EAP-TNC messages allowed
31 */
32 #define EAP_TNC_MAX_MESSAGE_COUNT 10
33
34 typedef struct private_eap_tnc_t private_eap_tnc_t;
35
36 /**
37 * Private data of an eap_tnc_t object.
38 */
39 struct private_eap_tnc_t {
40
41 /**
42 * Public authenticator_t interface.
43 */
44 eap_tnc_t public;
45
46 /**
47 * TLS stack, wrapped by EAP helper
48 */
49 tls_eap_t *tls_eap;
50 };
51
52 METHOD(eap_method_t, initiate, status_t,
53 private_eap_tnc_t *this, eap_payload_t **out)
54 {
55 chunk_t data;
56
57 if (this->tls_eap->initiate(this->tls_eap, &data) == NEED_MORE)
58 {
59 *out = eap_payload_create_data(data);
60 free(data.ptr);
61 return NEED_MORE;
62 }
63 return FAILED;
64 }
65
66 METHOD(eap_method_t, process, status_t,
67 private_eap_tnc_t *this, eap_payload_t *in, eap_payload_t **out)
68 {
69 status_t status;
70 chunk_t data;
71
72 data = in->get_data(in);
73 status = this->tls_eap->process(this->tls_eap, data, &data);
74 if (status == NEED_MORE)
75 {
76 *out = eap_payload_create_data(data);
77 free(data.ptr);
78 }
79 return status;
80 }
81
82 METHOD(eap_method_t, get_type, eap_type_t,
83 private_eap_tnc_t *this, u_int32_t *vendor)
84 {
85 *vendor = 0;
86 return EAP_TNC;
87 }
88
89 METHOD(eap_method_t, get_msk, status_t,
90 private_eap_tnc_t *this, chunk_t *msk)
91 {
92 *msk = this->tls_eap->get_msk(this->tls_eap);
93 if (msk->len)
94 {
95 return SUCCESS;
96 }
97 return FAILED;
98 }
99
100 METHOD(eap_method_t, get_identifier, u_int8_t,
101 private_eap_tnc_t *this)
102 {
103 return this->tls_eap->get_identifier(this->tls_eap);
104 }
105
106 METHOD(eap_method_t, set_identifier, void,
107 private_eap_tnc_t *this, u_int8_t identifier)
108 {
109 this->tls_eap->set_identifier(this->tls_eap, identifier);
110 }
111
112 METHOD(eap_method_t, is_mutual, bool,
113 private_eap_tnc_t *this)
114 {
115 return FALSE;
116 }
117
118 METHOD(eap_method_t, destroy, void,
119 private_eap_tnc_t *this)
120 {
121 this->tls_eap->destroy(this->tls_eap);
122 free(this);
123 }
124
125 /**
126 * Generic private constructor
127 */
128 static eap_tnc_t *eap_tnc_create(identification_t *server,
129 identification_t *peer, bool is_server)
130 {
131 private_eap_tnc_t *this;
132 int max_msg_count;
133 char* protocol;
134 tnccs_type_t type;
135 tnccs_t *tnccs;
136
137 INIT(this,
138 .public = {
139 .eap_method = {
140 .initiate = _initiate,
141 .process = _process,
142 .get_type = _get_type,
143 .is_mutual = _is_mutual,
144 .get_msk = _get_msk,
145 .get_identifier = _get_identifier,
146 .set_identifier = _set_identifier,
147 .destroy = _destroy,
148 },
149 },
150 );
151
152 max_msg_count = lib->settings->get_int(lib->settings,
153 "%s.plugins.eap-tnc.max_message_count",
154 EAP_TNC_MAX_MESSAGE_COUNT, charon->name);
155 protocol = lib->settings->get_str(lib->settings,
156 "%s.plugins.eap-tnc.protocol", "tnccs-1.1", charon->name);
157 if (strcaseeq(protocol, "tnccs-2.0"))
158 {
159 type = TNCCS_2_0;
160 }
161 else if (strcaseeq(protocol, "tnccs-1.1"))
162 {
163 type = TNCCS_1_1;
164 }
165 else if (strcaseeq(protocol, "tnccs-dynamic") && is_server)
166 {
167 type = TNCCS_DYNAMIC;
168 }
169 else
170 {
171 DBG1(DBG_TNC, "TNCCS protocol '%s' not supported", protocol);
172 free(this);
173 return NULL;
174 }
175 tnccs = tnc->tnccs->create_instance(tnc->tnccs, type, is_server);
176 this->tls_eap = tls_eap_create(EAP_TNC, (tls_t*)tnccs,
177 EAP_TNC_MAX_MESSAGE_LEN,
178 max_msg_count, FALSE);
179 if (!this->tls_eap)
180 {
181 free(this);
182 return NULL;
183 }
184 return &this->public;
185 }
186
187 eap_tnc_t *eap_tnc_create_server(identification_t *server,
188 identification_t *peer)
189 {
190 return eap_tnc_create(server, peer, TRUE);
191 }
192
193 eap_tnc_t *eap_tnc_create_peer(identification_t *server,
194 identification_t *peer)
195 {
196 return eap_tnc_create(server, peer, FALSE);
197 }