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
28 typedef struct rlm_eap_peap_t {
29 char const *tls_conf_name; //!< TLS configuration.
30 fr_tls_server_conf_t *tls_conf;
31 char const *default_method_name; //!< Default tunneled EAP type.
33 bool use_tunneled_reply; //!< Use the reply attributes from the tunneled session in
34 //!< the non-tunneled reply to the client.
36 bool copy_request_to_tunnel; //!< Use SOME of the request attributes from outside of the
37 //!< tunneled session in the tunneled request.
39 bool proxy_tunneled_request_as_eap; //!< Proxy tunneled session as EAP, or as de-capsulated
42 char const *virtual_server; //!< Virtual server for inner tunnel session.
44 bool soh; //!< Do we do SoH request?
45 char const *soh_virtual_server;
46 bool req_client_cert; //!< Do we do require a client cert?
50 static CONF_PARSER module_config[] = {
51 { "tls", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_eap_peap_t, tls_conf_name), NULL },
53 { "default_method", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_eap_peap_t, default_method_name), "mschapv2" },
55 { "copy_request_to_tunnel", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_peap_t, copy_request_to_tunnel), "no" },
57 { "use_tunneled_reply", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_peap_t, use_tunneled_reply), "no" },
60 { "proxy_tunneled_request_as_eap", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_peap_t, proxy_tunneled_request_as_eap), "yes" },
63 { "virtual_server", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_eap_peap_t, virtual_server), NULL },
65 { "soh", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_peap_t, soh), "no" },
67 { "require_client_cert", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_peap_t, req_client_cert), "no" },
69 { "soh_virtual_server", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_eap_peap_t, soh_virtual_server), NULL },
71 { NULL, -1, 0, NULL, NULL } /* end the list */
78 static int eappeap_attach(CONF_SECTION *cs, void **instance)
82 *instance = inst = talloc_zero(cs, rlm_eap_peap_t);
86 * Parse the configuration attributes.
88 if (cf_section_parse(cs, inst, module_config) < 0) {
93 * Convert the name to an integer, to make it easier to
96 inst->default_method = eap_name2type(inst->default_method_name);
97 if (inst->default_method < 0) {
98 ERROR("rlm_eap_peap: Unknown EAP type %s",
99 inst->default_method_name);
104 * Read tls configuration, either from group given by 'tls'
105 * option, or from the eap-tls configuration.
107 inst->tls_conf = eaptls_conf_parse(cs, "tls");
109 if (!inst->tls_conf) {
110 ERROR("rlm_eap_peap: Failed initializing SSL context");
118 * Free the PEAP per-session data
120 static void peap_free(void *p)
122 peap_tunnel_t *t = (peap_tunnel_t *) p;
126 pairfree(&t->username);
128 pairfree(&t->accept_vps);
129 pairfree(&t->soh_reply_vps);
136 * Allocate the PEAP per-session data
138 static peap_tunnel_t *peap_alloc(rlm_eap_peap_t *inst, eap_handler_t *handler)
142 t = talloc_zero(handler, peap_tunnel_t);
144 t->default_method = inst->default_method;
145 t->copy_request_to_tunnel = inst->copy_request_to_tunnel;
146 t->use_tunneled_reply = inst->use_tunneled_reply;
148 t->proxy_tunneled_request_as_eap = inst->proxy_tunneled_request_as_eap;
150 t->virtual_server = inst->virtual_server;
152 t->soh_virtual_server = inst->soh_virtual_server;
153 t->session_resumption_state = PEAP_RESUMPTION_MAYBE;
159 * Send an initial eap-tls request to the peer, using the libeap functions.
161 static int eappeap_initiate(void *type_arg, eap_handler_t *handler)
165 rlm_eap_peap_t *inst;
168 REQUEST *request = handler->request;
173 handler->finished = false;
176 * Check if we need a client certificate.
180 * EAP-TLS-Require-Client-Cert attribute will override
181 * the require_client_cert configuration option.
183 vp = pairfind(handler->request->config_items, PW_EAP_TLS_REQUIRE_CLIENT_CERT, 0, TAG_ANY);
185 client_cert = vp->vp_integer;
187 client_cert = inst->req_client_cert;
190 ssn = eaptls_session(inst->tls_conf, handler, client_cert);
195 handler->opaque = ((void *)ssn);
196 handler->free_opaque = session_free;
199 * Set up type-specific information.
201 ssn->prf_label = "client EAP encryption";
204 * As it is a poorly designed protocol, PEAP uses
205 * bits in the TLS header to indicate PEAP
206 * version numbers. For now, we only support
207 * PEAP version 0, so it doesn't matter too much.
208 * However, if we support later versions of PEAP,
209 * we will need this flag to indicate which
210 * version we're currently dealing with.
212 ssn->peap_flag = 0x00;
215 * PEAP version 0 requires 'include_length = no',
216 * so rather than hoping the user figures it out,
219 ssn->length_flag = 0;
222 * TLS session initialization is over. Now handle TLS
223 * related handshaking or application data.
225 status = eaptls_start(handler->eap_ds, ssn->peap_flag);
226 RDEBUG2("Start returned %d", status);
232 * The next stage to process the packet.
234 handler->stage = AUTHENTICATE;
240 * Do authentication, by letting EAP-TLS do most of the work.
242 static int mod_authenticate(void *arg, eap_handler_t *handler)
245 fr_tls_status_t status;
246 rlm_eap_peap_t *inst = (rlm_eap_peap_t *) arg;
247 tls_session_t *tls_session = (tls_session_t *) handler->opaque;
248 peap_tunnel_t *peap = tls_session->opaque;
249 REQUEST *request = handler->request;
252 * Session resumption requires the storage of data, so
253 * allocate it if it doesn't already exist.
255 if (!tls_session->opaque) {
256 peap = tls_session->opaque = peap_alloc(inst, handler);
257 tls_session->free_opaque = peap_free;
260 status = eaptls_process(handler);
261 RDEBUG2("eaptls_process returned %d\n", status);
264 * EAP-TLS handshake was successful, tell the
265 * client to keep talking.
267 * If this was EAP-TLS, we would just return
268 * an EAP-TLS-Success packet here.
271 RDEBUG2("FR_TLS_SUCCESS");
272 peap->status = PEAP_STATUS_TUNNEL_ESTABLISHED;
276 * The TLS code is still working on the TLS
277 * exchange, and it's a valid TLS request.
282 * FIXME: If the SSL session is established, grab the state
283 * and EAP id from the inner tunnel, and update it with
284 * the expected EAP id!
286 RDEBUG2("FR_TLS_HANDLED");
290 * Handshake is done, proceed with decoding tunneled
294 RDEBUG2("FR_TLS_OK");
298 * Anything else: fail.
301 RDEBUG2("FR_TLS_OTHERS");
306 * Session is established, proceed with decoding
309 RDEBUG2("Session established. Decoding tunneled attributes");
312 * We may need PEAP data associated with the session, so
313 * allocate it here, if it wasn't already alloacted.
315 if (!tls_session->opaque) {
316 tls_session->opaque = peap_alloc(inst, handler);
317 tls_session->free_opaque = peap_free;
321 * Process the PEAP portion of the request.
323 rcode = eappeap_process(handler, tls_session);
325 case RLM_MODULE_REJECT:
326 eaptls_fail(handler, 0);
329 case RLM_MODULE_HANDLED:
330 eaptls_request(handler->eap_ds, tls_session);
335 * Move the saved VP's from the Access-Accept to
338 peap = tls_session->opaque;
339 if (peap->soh_reply_vps) {
340 RDEBUG2("Using saved attributes from the SoH reply");
341 debug_pair_list(peap->soh_reply_vps);
342 pairfilter(handler->request->reply,
343 &handler->request->reply->vps,
344 &peap->soh_reply_vps, 0, 0, TAG_ANY);
346 if (peap->accept_vps) {
347 RDEBUG2("Using saved attributes from the original Access-Accept");
348 debug_pair_list(peap->accept_vps);
349 pairfilter(handler->request->reply,
350 &handler->request->reply->vps,
351 &peap->accept_vps, 0, 0, TAG_ANY);
355 * Success: Automatically return MPPE keys.
357 return eaptls_success(handler, 0);
360 * No response packet, MUST be proxying it.
361 * The main EAP module will take care of discovering
362 * that the request now has a "proxy" packet, and
363 * will proxy it, rather than returning an EAP packet.
365 case RLM_MODULE_UPDATED:
367 rad_assert(handler->request->proxy != NULL);
376 eaptls_fail(handler, 0);
382 * The module name should be the only globally exported symbol.
383 * That is, everything else should be 'static'.
385 rlm_eap_module_t rlm_eap_peap = {
387 eappeap_attach, /* attach */
388 eappeap_initiate, /* Start the initial request */
389 NULL, /* authorization */
390 mod_authenticate, /* authentication */