diff options
author | sam <sam@FreeBSD.org> | 2007-07-11 15:48:36 +0000 |
---|---|---|
committer | sam <sam@FreeBSD.org> | 2007-07-11 15:48:36 +0000 |
commit | 35aef052ff21baa52c4cec68b512986c21f70a48 (patch) | |
tree | c3da7f33886a852f7dceb74373fbdeec49a48f77 /contrib/wpa_supplicant/eap_md5.c | |
parent | 840099f34d8de1ca769f02fae379c4d8e5d6688a (diff) | |
download | FreeBSD-src-35aef052ff21baa52c4cec68b512986c21f70a48.zip FreeBSD-src-35aef052ff21baa52c4cec68b512986c21f70a48.tar.gz |
Import of WPA supplicant 0.5.8
Diffstat (limited to 'contrib/wpa_supplicant/eap_md5.c')
-rw-r--r-- | contrib/wpa_supplicant/eap_md5.c | 89 |
1 files changed, 53 insertions, 36 deletions
diff --git a/contrib/wpa_supplicant/eap_md5.c b/contrib/wpa_supplicant/eap_md5.c index 46a5f55..5dc1685 100644 --- a/contrib/wpa_supplicant/eap_md5.c +++ b/contrib/wpa_supplicant/eap_md5.c @@ -1,6 +1,6 @@ /* - * WPA Supplicant / EAP-MD5 - * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.fi> + * EAP peer method: EAP-MD5 (RFC 3748 and RFC 1994) + * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -12,19 +12,18 @@ * See README and COPYING for more details. */ -#include <stdlib.h> -#include <stdio.h> +#include "includes.h" #include "common.h" #include "eap_i.h" -#include "wpa_supplicant.h" -#include "config_ssid.h" #include "md5.h" #include "crypto.h" static void * eap_md5_init(struct eap_sm *sm) { + /* No need for private data. However, must return non-NULL to indicate + * success. */ return (void *) 1; } @@ -39,35 +38,41 @@ static u8 * eap_md5_process(struct eap_sm *sm, void *priv, const u8 *reqData, size_t reqDataLen, size_t *respDataLen) { - struct wpa_ssid *config = eap_get_config(sm); const struct eap_hdr *req; struct eap_hdr *resp; - const u8 *pos, *challenge; + const u8 *pos, *challenge, *password; u8 *rpos; - int challenge_len; - size_t len; + size_t len, challenge_len, password_len; const u8 *addr[3]; size_t elen[3]; - if (config == NULL || config->password == NULL) { + password = eap_get_config_password(sm, &password_len); + if (password == NULL) { wpa_printf(MSG_INFO, "EAP-MD5: Password not configured"); - eap_sm_request_password(sm, config); + eap_sm_request_password(sm); ret->ignore = TRUE; return NULL; } - pos = eap_hdr_validate(EAP_TYPE_MD5, reqData, reqDataLen, &len); - if (pos == NULL) { + pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_MD5, + reqData, reqDataLen, &len); + if (pos == NULL || len == 0) { + wpa_printf(MSG_INFO, "EAP-MD5: Invalid frame (pos=%p len=%lu)", + pos, (unsigned long) len); ret->ignore = TRUE; return NULL; } + + /* + * CHAP Challenge: + * Value-Size (1 octet) | Value(Challenge) | Name(optional) + */ req = (const struct eap_hdr *) reqData; challenge_len = *pos++; - if (challenge_len == 0 || - challenge_len > len - 1) { + if (challenge_len == 0 || challenge_len > len - 1) { wpa_printf(MSG_INFO, "EAP-MD5: Invalid challenge " - "(challenge_len=%d len=%lu", - challenge_len, (unsigned long) len); + "(challenge_len=%lu len=%lu)", + (unsigned long) challenge_len, (unsigned long) len); ret->ignore = TRUE; return NULL; } @@ -76,26 +81,27 @@ static u8 * eap_md5_process(struct eap_sm *sm, void *priv, wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Challenge", challenge, challenge_len); - wpa_printf(MSG_DEBUG, "EAP-MD5: generating Challenge Response"); + wpa_printf(MSG_DEBUG, "EAP-MD5: Generating Challenge Response"); ret->methodState = METHOD_DONE; ret->decision = DECISION_UNCOND_SUCC; ret->allowNotifications = TRUE; - *respDataLen = sizeof(struct eap_hdr) + 1 + 1 + MD5_MAC_LEN; - resp = malloc(*respDataLen); + resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MD5, respDataLen, + 1 + MD5_MAC_LEN, EAP_CODE_RESPONSE, + req->identifier, &rpos); if (resp == NULL) return NULL; - resp->code = EAP_CODE_RESPONSE; - resp->identifier = req->identifier; - resp->length = host_to_be16(*respDataLen); - rpos = (u8 *) (resp + 1); - *rpos++ = EAP_TYPE_MD5; - *rpos++ = MD5_MAC_LEN; /* Value-Size */ + + /* + * CHAP Response: + * Value-Size (1 octet) | Value(Response) | Name(optional) + */ + *rpos++ = MD5_MAC_LEN; addr[0] = &resp->identifier; elen[0] = 1; - addr[1] = config->password; - elen[1] = config->password_len; + addr[1] = password; + elen[1] = password_len; addr[2] = challenge; elen[2] = challenge_len; md5_vector(3, addr, elen, rpos); @@ -105,11 +111,22 @@ static u8 * eap_md5_process(struct eap_sm *sm, void *priv, } -const struct eap_method eap_method_md5 = +int eap_peer_md5_register(void) { - .method = EAP_TYPE_MD5, - .name = "MD5", - .init = eap_md5_init, - .deinit = eap_md5_deinit, - .process = eap_md5_process, -}; + struct eap_method *eap; + int ret; + + eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION, + EAP_VENDOR_IETF, EAP_TYPE_MD5, "MD5"); + if (eap == NULL) + return -1; + + eap->init = eap_md5_init; + eap->deinit = eap_md5_deinit; + eap->process = eap_md5_process; + + ret = eap_peer_method_register(eap); + if (ret) + eap_peer_method_free(eap); + return ret; +} |