2 * rlm_eap_md5.c Handles 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Copyright 2000,2001 The FreeRADIUS server project
21 * Copyright 2001 hereUare Communications, Inc. <raghud@hereuare.com>
24 #include <freeradius-devel/autoconf.h>
31 #include <freeradius-devel/rad_assert.h>
34 * Initiate the EAP-MD5 session by sending a challenge to the peer.
36 static int md5_initiate(void *type_data, EAP_HANDLER *handler)
41 type_data = type_data; /* -Wunused */
44 * Allocate an EAP-MD5 packet.
46 reply = eapmd5_alloc();
48 radlog(L_ERR, "rlm_eap_md5: out of memory");
55 reply->code = PW_MD5_CHALLENGE;
56 reply->length = 1 + MD5_CHALLENGE_LEN; /* one byte of value size */
57 reply->value_size = MD5_CHALLENGE_LEN;
62 reply->value = malloc(reply->value_size);
63 if (reply->value == NULL) {
64 radlog(L_ERR, "rlm_eap_md5: out of memory");
70 * Get a random challenge.
72 for (i = 0; i < reply->value_size; i++) {
73 reply->value[i] = lrad_rand();
75 radlog(L_INFO, "rlm_eap_md5: Issuing Challenge");
78 * Keep track of the challenge.
80 handler->opaque = malloc(reply->value_size);
81 rad_assert(handler->opaque != NULL);
82 memcpy(handler->opaque, reply->value, reply->value_size);
83 handler->free_opaque = free;
86 * Compose the EAP-MD5 packet out of the data structure,
89 eapmd5_compose(handler->eap_ds, reply);
92 * We don't need to authorize the user at this point.
94 * We also don't need to keep the challenge, as it's
95 * stored in 'handler->eap_ds', which will be given back
98 handler->stage = AUTHENTICATE;
105 * Authenticate a previously sent challenge.
107 static int md5_authenticate(UNUSED void *arg, EAP_HANDLER *handler)
111 VALUE_PAIR *password;
114 * Get the User-Password for this user.
116 rad_assert(handler->request != NULL);
117 rad_assert(handler->stage == AUTHENTICATE);
119 password = pairfind(handler->request->config_items, PW_PASSWORD);
120 if (password == NULL) {
121 radlog(L_INFO, "rlm_eap_md5: User-Password is required for EAP-MD5 authentication");
126 * Extract the EAP-MD5 packet.
128 if (!(packet = eapmd5_extract(handler->eap_ds)))
132 * Create a reply, and initialize it.
134 reply = eapmd5_alloc();
138 reply->id = handler->eap_ds->request->id;
142 * Verify the received packet against the previous packet
143 * (i.e. challenge) which we sent out.
145 if (eapmd5_verify(packet, password, handler->opaque)) {
146 reply->code = PW_MD5_SUCCESS;
148 reply->code = PW_MD5_FAILURE;
152 * Compose the EAP-MD5 packet out of the data structure,
155 eapmd5_compose(handler->eap_ds, reply);
157 eapmd5_free(&packet);
162 * The module name should be the only globally exported symbol.
163 * That is, everything else should be 'static'.
165 EAP_TYPE rlm_eap_md5 = {
168 md5_initiate, /* Start the initial request */
169 NULL, /* authorization */
170 md5_authenticate, /* authentication */