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;
50 * Proxy tunneled session as EAP, or as de-capsulated
53 int proxy_tunneled_request_as_eap;
56 * Virtual server for inner tunnel session.
62 static CONF_PARSER module_config[] = {
63 { "default_eap_type", PW_TYPE_STRING_PTR,
64 offsetof(rlm_eap_peap_t, default_eap_type_name), NULL, "mschapv2" },
66 { "copy_request_to_tunnel", PW_TYPE_BOOLEAN,
67 offsetof(rlm_eap_peap_t, copy_request_to_tunnel), NULL, "no" },
69 { "use_tunneled_reply", PW_TYPE_BOOLEAN,
70 offsetof(rlm_eap_peap_t, use_tunneled_reply), NULL, "no" },
72 { "proxy_tunneled_request_as_eap", PW_TYPE_BOOLEAN,
73 offsetof(rlm_eap_peap_t, proxy_tunneled_request_as_eap), NULL, "yes" },
75 { "virtual_server", PW_TYPE_STRING_PTR,
76 offsetof(rlm_eap_peap_t, virtual_server), NULL, NULL },
78 { NULL, -1, 0, NULL, NULL } /* end the list */
84 static int eappeap_detach(void *arg)
86 rlm_eap_peap_t *inst = (rlm_eap_peap_t *) arg;
97 static int eappeap_attach(CONF_SECTION *cs, void **instance)
101 inst = malloc(sizeof(*inst));
103 radlog(L_ERR, "rlm_eap_peap: out of memory");
106 memset(inst, 0, sizeof(*inst));
109 * Parse the configuration attributes.
111 if (cf_section_parse(cs, inst, module_config) < 0) {
112 eappeap_detach(inst);
117 * Convert the name to an integer, to make it easier to
120 inst->default_eap_type = eaptype_name2type(inst->default_eap_type_name);
121 if (inst->default_eap_type < 0) {
122 radlog(L_ERR, "rlm_eap_peap: Unknown EAP type %s",
123 inst->default_eap_type_name);
124 eappeap_detach(inst);
134 * Free the PEAP per-session data
136 static void peap_free(void *p)
138 peap_tunnel_t *t = (peap_tunnel_t *) p;
142 pairfree(&t->username);
144 pairfree(&t->accept_vps);
151 * Free the PEAP per-session data
153 static peap_tunnel_t *peap_alloc(rlm_eap_peap_t *inst)
157 t = rad_malloc(sizeof(*t));
158 memset(t, 0, sizeof(*t));
160 t->default_eap_type = inst->default_eap_type;
161 t->copy_request_to_tunnel = inst->copy_request_to_tunnel;
162 t->use_tunneled_reply = inst->use_tunneled_reply;
163 t->proxy_tunneled_request_as_eap = inst->proxy_tunneled_request_as_eap;
164 t->virtual_server = inst->virtual_server;
170 * Do authentication, by letting EAP-TLS do most of the work.
172 static int eappeap_authenticate(void *arg, EAP_HANDLER *handler)
175 eaptls_status_t status;
176 rlm_eap_peap_t *inst = (rlm_eap_peap_t *) arg;
177 tls_session_t *tls_session = (tls_session_t *) handler->opaque;
178 peap_tunnel_t *peap = NULL;
180 DEBUG2(" rlm_eap_peap: Authenticate");
182 status = eaptls_process(handler);
183 DEBUG2(" eaptls_process returned %d\n", status);
186 * EAP-TLS handshake was successful, tell the
187 * client to keep talking.
189 * If this was EAP-TLS, we would just return
190 * an EAP-TLS-Success packet here.
194 eap_packet_t eap_packet;
196 eap_packet.code = PW_EAP_REQUEST;
197 eap_packet.id = handler->eap_ds->response->id + 1;
198 eap_packet.length[0] = 0;
199 eap_packet.length[1] = EAP_HEADER_LEN + 1;
200 eap_packet.data[0] = PW_EAP_IDENTITY;
202 (tls_session->record_plus)(&tls_session->clean_in,
203 &eap_packet, sizeof(eap_packet));
205 tls_handshake_send(tls_session);
206 (tls_session->record_init)(&tls_session->clean_in);
208 eaptls_request(handler->eap_ds, tls_session);
209 DEBUG2(" rlm_eap_peap: EAPTLS_SUCCESS");
213 * The TLS code is still working on the TLS
214 * exchange, and it's a valid TLS request.
219 * FIXME: If the SSL session is established, grab the state
220 * and EAP id from the inner tunnel, and update it with
221 * the expected EAP id!
223 DEBUG2(" rlm_eap_peap: EAPTLS_HANDLED");
227 * Handshake is done, proceed with decoding tunneled
231 DEBUG2(" rlm_eap_peap: EAPTLS_OK");
235 * Anything else: fail.
238 DEBUG2(" rlm_eap_peap: EAPTLS_OTHERS");
243 * Session is established, proceed with decoding
246 DEBUG2(" rlm_eap_peap: Session established. Decoding tunneled attributes.");
249 * We may need PEAP data associated with the session, so
250 * allocate it here, if it wasn't already alloacted.
252 if (!tls_session->opaque) {
253 tls_session->opaque = peap_alloc(inst);
254 tls_session->free_opaque = peap_free;
258 * Process the PEAP portion of the request.
260 rcode = eappeap_process(handler, tls_session);
262 case RLM_MODULE_REJECT:
263 eaptls_fail(handler->eap_ds, 0);
266 case RLM_MODULE_HANDLED:
267 eaptls_request(handler->eap_ds, tls_session);
271 eaptls_success(handler->eap_ds, 0);
274 * Move the saved VP's from the Access-Accept to
277 peap = tls_session->opaque;
278 if (peap->accept_vps) {
279 DEBUG2(" Using saved attributes from the original Access-Accept");
281 pairmove(&handler->request->reply->vps, &peap->accept_vps);
282 pairfree(&peap->accept_vps);
284 eaptls_gen_mppe_keys(&handler->request->reply->vps,
286 "client EAP encryption");
291 * No response packet, MUST be proxying it.
292 * The main EAP module will take care of discovering
293 * that the request now has a "proxy" packet, and
294 * will proxy it, rather than returning an EAP packet.
296 case RLM_MODULE_UPDATED:
297 rad_assert(handler->request->proxy != NULL);
305 eaptls_fail(handler->eap_ds, 0);
311 * The module name should be the only globally exported symbol.
312 * That is, everything else should be 'static'.
314 EAP_TYPE rlm_eap_peap = {
316 eappeap_attach, /* attach */
318 * Note! There is NO eappeap_initate() function, as the
319 * main EAP module takes care of calling
322 * This is because PEAP is a protocol on top of TLS, so
323 * before we need to do PEAP, we've got to initiate a TLS
326 NULL, /* Start the initial request */
327 NULL, /* authorization */
328 eappeap_authenticate, /* authentication */
329 eappeap_detach /* detach */