2 * rlm_eap_peap.c contains the interfaces that are called from eap
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2003 Alan DeKok <aland@freeradius.org>
21 * Copyright 2006 The FreeRADIUS server project
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/autoconf.h>
30 typedef struct rlm_eap_peap_t {
32 * Default tunneled EAP type
34 char *default_eap_type_name;
38 * Use the reply attributes from the tunneled session in
39 * the non-tunneled reply to the client.
41 int use_tunneled_reply;
44 * Use SOME of the request attributes from outside of the
45 * tunneled session in the tunneled request
47 int copy_request_to_tunnel;
51 * Proxy tunneled session as EAP, or as de-capsulated
54 int proxy_tunneled_request_as_eap;
58 * Virtual server for inner tunnel session.
63 * Do we do SoH request?
66 char *soh_virtual_server;
70 static CONF_PARSER module_config[] = {
71 { "default_eap_type", PW_TYPE_STRING_PTR,
72 offsetof(rlm_eap_peap_t, default_eap_type_name), NULL, "mschapv2" },
74 { "copy_request_to_tunnel", PW_TYPE_BOOLEAN,
75 offsetof(rlm_eap_peap_t, copy_request_to_tunnel), NULL, "no" },
77 { "use_tunneled_reply", PW_TYPE_BOOLEAN,
78 offsetof(rlm_eap_peap_t, use_tunneled_reply), NULL, "no" },
81 { "proxy_tunneled_request_as_eap", PW_TYPE_BOOLEAN,
82 offsetof(rlm_eap_peap_t, proxy_tunneled_request_as_eap), NULL, "yes" },
85 { "virtual_server", PW_TYPE_STRING_PTR,
86 offsetof(rlm_eap_peap_t, virtual_server), NULL, NULL },
88 { "soh", PW_TYPE_BOOLEAN,
89 offsetof(rlm_eap_peap_t, soh), NULL, "no" },
91 { "soh_virtual_server", PW_TYPE_STRING_PTR,
92 offsetof(rlm_eap_peap_t, soh_virtual_server), NULL, NULL },
94 { NULL, -1, 0, NULL, NULL } /* end the list */
100 static int eappeap_detach(void *arg)
102 rlm_eap_peap_t *inst = (rlm_eap_peap_t *) arg;
113 static int eappeap_attach(CONF_SECTION *cs, void **instance)
115 rlm_eap_peap_t *inst;
117 inst = malloc(sizeof(*inst));
119 radlog(L_ERR, "rlm_eap_peap: out of memory");
122 memset(inst, 0, sizeof(*inst));
125 * Parse the configuration attributes.
127 if (cf_section_parse(cs, inst, module_config) < 0) {
128 eappeap_detach(inst);
133 * Convert the name to an integer, to make it easier to
136 inst->default_eap_type = eaptype_name2type(inst->default_eap_type_name);
137 if (inst->default_eap_type < 0) {
138 radlog(L_ERR, "rlm_eap_peap: Unknown EAP type %s",
139 inst->default_eap_type_name);
140 eappeap_detach(inst);
150 * Free the PEAP per-session data
152 static void peap_free(void *p)
154 peap_tunnel_t *t = (peap_tunnel_t *) p;
158 pairfree(&t->username);
160 pairfree(&t->accept_vps);
161 pairfree(&t->soh_reply_vps);
168 * Free the PEAP per-session data
170 static peap_tunnel_t *peap_alloc(rlm_eap_peap_t *inst)
174 t = rad_malloc(sizeof(*t));
175 memset(t, 0, sizeof(*t));
177 t->default_eap_type = inst->default_eap_type;
178 t->copy_request_to_tunnel = inst->copy_request_to_tunnel;
179 t->use_tunneled_reply = inst->use_tunneled_reply;
181 t->proxy_tunneled_request_as_eap = inst->proxy_tunneled_request_as_eap;
183 t->virtual_server = inst->virtual_server;
185 t->soh_virtual_server = inst->soh_virtual_server;
186 t->session_resumption_state = PEAP_RESUMPTION_MAYBE;
192 * Do authentication, by letting EAP-TLS do most of the work.
194 static int eappeap_authenticate(void *arg, EAP_HANDLER *handler)
197 eaptls_status_t status;
198 rlm_eap_peap_t *inst = (rlm_eap_peap_t *) arg;
199 tls_session_t *tls_session = (tls_session_t *) handler->opaque;
200 peap_tunnel_t *peap = tls_session->opaque;
201 REQUEST *request = handler->request;
204 * Session resumption requires the storage of data, so
205 * allocate it if it doesn't already exist.
207 if (!tls_session->opaque) {
208 peap = tls_session->opaque = peap_alloc(inst);
209 tls_session->free_opaque = peap_free;
212 status = eaptls_process(handler);
213 RDEBUG2("eaptls_process returned %d\n", status);
216 * EAP-TLS handshake was successful, tell the
217 * client to keep talking.
219 * If this was EAP-TLS, we would just return
220 * an EAP-TLS-Success packet here.
223 RDEBUG2("EAPTLS_SUCCESS");
224 peap->status = PEAP_STATUS_TUNNEL_ESTABLISHED;
228 * The TLS code is still working on the TLS
229 * exchange, and it's a valid TLS request.
234 * FIXME: If the SSL session is established, grab the state
235 * and EAP id from the inner tunnel, and update it with
236 * the expected EAP id!
238 RDEBUG2("EAPTLS_HANDLED");
242 * Handshake is done, proceed with decoding tunneled
246 RDEBUG2("EAPTLS_OK");
250 * Anything else: fail.
253 RDEBUG2("EAPTLS_OTHERS");
258 * Session is established, proceed with decoding
261 RDEBUG2("Session established. Decoding tunneled attributes.");
264 * We may need PEAP data associated with the session, so
265 * allocate it here, if it wasn't already alloacted.
267 if (!tls_session->opaque) {
268 tls_session->opaque = peap_alloc(inst);
269 tls_session->free_opaque = peap_free;
273 * Process the PEAP portion of the request.
275 rcode = eappeap_process(handler, tls_session);
277 case RLM_MODULE_REJECT:
278 eaptls_fail(handler, 0);
281 case RLM_MODULE_HANDLED:
282 eaptls_request(handler->eap_ds, tls_session);
287 * Move the saved VP's from the Access-Accept to
290 peap = tls_session->opaque;
291 if (peap->soh_reply_vps) {
292 RDEBUG2("Using saved attributes from the SoH reply");
293 debug_pair_list(peap->soh_reply_vps);
294 pairadd(&handler->request->reply->vps, peap->soh_reply_vps);
295 peap->soh_reply_vps = NULL;
297 if (peap->accept_vps) {
298 RDEBUG2("Using saved attributes from the original Access-Accept");
299 debug_pair_list(peap->accept_vps);
300 pairadd(&handler->request->reply->vps, peap->accept_vps);
301 peap->accept_vps = NULL;
305 * Success: Automatically return MPPE keys.
307 return eaptls_success(handler, 0);
310 * No response packet, MUST be proxying it.
311 * The main EAP module will take care of discovering
312 * that the request now has a "proxy" packet, and
313 * will proxy it, rather than returning an EAP packet.
315 case RLM_MODULE_UPDATED:
317 rad_assert(handler->request->proxy != NULL);
326 eaptls_fail(handler, 0);
332 * The module name should be the only globally exported symbol.
333 * That is, everything else should be 'static'.
335 EAP_TYPE rlm_eap_peap = {
337 eappeap_attach, /* attach */
339 * Note! There is NO eappeap_initate() function, as the
340 * main EAP module takes care of calling
343 * This is because PEAP is a protocol on top of TLS, so
344 * before we need to do PEAP, we've got to initiate a TLS
347 NULL, /* Start the initial request */
348 NULL, /* authorization */
349 eappeap_authenticate, /* authentication */
350 eappeap_detach /* detach */