eap_md5.c

Go to the documentation of this file.
00001 
00016 #include <stdlib.h>
00017 #include <stdio.h>
00018 
00019 #include "common.h"
00020 #include "eap_i.h"
00021 #include "wpa_supplicant.h"
00022 #include "config_ssid.h"
00023 #include "md5.h"
00024 #include "crypto.h"
00025 
00026 
00027 static void * eap_md5_init(struct eap_sm *sm)
00028 {
00029         return (void *) 1;
00030 }
00031 
00032 
00033 static void eap_md5_deinit(struct eap_sm *sm, void *priv)
00034 {
00035 }
00036 
00037 
00038 static u8 * eap_md5_process(struct eap_sm *sm, void *priv,
00039                             struct eap_method_ret *ret,
00040                             const u8 *reqData, size_t reqDataLen,
00041                             size_t *respDataLen)
00042 {
00043         struct wpa_ssid *config = eap_get_config(sm);
00044         const struct eap_hdr *req;
00045         struct eap_hdr *resp;
00046         const u8 *pos, *challenge;
00047         u8 *rpos;
00048         int challenge_len;
00049         size_t len;
00050         const u8 *addr[3];
00051         size_t elen[3];
00052 
00053         if (config == NULL || config->password == NULL) {
00054                 wpa_printf(MSG_INFO, "EAP-MD5: Password not configured");
00055                 eap_sm_request_password(sm, config);
00056                 ret->ignore = TRUE;
00057                 return NULL;
00058         }
00059 
00060         pos = eap_hdr_validate(EAP_TYPE_MD5, reqData, reqDataLen, &len);
00061         if (pos == NULL || len == 0) {
00062                 wpa_printf(MSG_INFO, "EAP-MD5: Invalid frame (pos=%p len=%lu)",
00063                            pos, (unsigned long) len);
00064                 ret->ignore = TRUE;
00065                 return NULL;
00066         }
00067         req = (const struct eap_hdr *) reqData;
00068         challenge_len = *pos++;
00069         if (challenge_len == 0 ||
00070             challenge_len > len - 1) {
00071                 wpa_printf(MSG_INFO, "EAP-MD5: Invalid challenge "
00072                            "(challenge_len=%d len=%lu)",
00073                            challenge_len, (unsigned long) len);
00074                 ret->ignore = TRUE;
00075                 return NULL;
00076         }
00077         ret->ignore = FALSE;
00078         challenge = pos;
00079         wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Challenge",
00080                     challenge, challenge_len);
00081 
00082         wpa_printf(MSG_DEBUG, "EAP-MD5: generating Challenge Response");
00083         ret->methodState = METHOD_DONE;
00084         ret->decision = DECISION_UNCOND_SUCC;
00085         ret->allowNotifications = TRUE;
00086 
00087         *respDataLen = sizeof(struct eap_hdr) + 1 + 1 + MD5_MAC_LEN;
00088         resp = malloc(*respDataLen);
00089         if (resp == NULL)
00090                 return NULL;
00091         resp->code = EAP_CODE_RESPONSE;
00092         resp->identifier = req->identifier;
00093         resp->length = host_to_be16(*respDataLen);
00094         rpos = (u8 *) (resp + 1);
00095         *rpos++ = EAP_TYPE_MD5;
00096         *rpos++ = MD5_MAC_LEN; /* Value-Size */
00097 
00098         addr[0] = &resp->identifier;
00099         elen[0] = 1;
00100         addr[1] = config->password;
00101         elen[1] = config->password_len;
00102         addr[2] = challenge;
00103         elen[2] = challenge_len;
00104         md5_vector(3, addr, elen, rpos);
00105         wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Response", rpos, MD5_MAC_LEN);
00106 
00107         return (u8 *) resp;
00108 }
00109 
00110 
00111 const struct eap_method eap_method_md5 =
00112 {
00113         .method = EAP_TYPE_MD5,
00114         .name = "MD5",
00115         .init = eap_md5_init,
00116         .deinit = eap_md5_deinit,
00117         .process = eap_md5_process,
00118 };
00119 

Generated on Sat May 6 21:13:35 2006 for wpa_supplicant by  doxygen 1.4.2