2 * WPA Supplicant / EAP-MD5
3 * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
20 #include "wpa_supplicant.h"
21 #include "config_ssid.h"
26 static void * eap_md5_init(struct eap_sm *sm)
32 static void eap_md5_deinit(struct eap_sm *sm, void *priv)
37 static u8 * eap_md5_process(struct eap_sm *sm, void *priv,
38 struct eap_method_ret *ret,
39 const u8 *reqData, size_t reqDataLen,
42 struct wpa_ssid *config = eap_get_config(sm);
43 const struct eap_hdr *req;
45 const u8 *pos, *challenge;
52 if (config == NULL || config->password == NULL) {
53 wpa_printf(MSG_INFO, "EAP-MD5: Password not configured");
54 eap_sm_request_password(sm, config);
59 pos = eap_hdr_validate(EAP_TYPE_MD5, reqData, reqDataLen, &len);
64 req = (const struct eap_hdr *) reqData;
65 challenge_len = *pos++;
66 if (challenge_len == 0 ||
67 challenge_len > len - 1) {
68 wpa_printf(MSG_INFO, "EAP-MD5: Invalid challenge "
69 "(challenge_len=%d len=%lu",
70 challenge_len, (unsigned long) len);
76 wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Challenge",
77 challenge, challenge_len);
79 wpa_printf(MSG_DEBUG, "EAP-MD5: generating Challenge Response");
80 ret->methodState = METHOD_DONE;
81 ret->decision = DECISION_UNCOND_SUCC;
82 ret->allowNotifications = TRUE;
84 *respDataLen = sizeof(struct eap_hdr) + 1 + 1 + MD5_MAC_LEN;
85 resp = malloc(*respDataLen);
88 resp->code = EAP_CODE_RESPONSE;
89 resp->identifier = req->identifier;
90 resp->length = host_to_be16(*respDataLen);
91 rpos = (u8 *) (resp + 1);
92 *rpos++ = EAP_TYPE_MD5;
93 *rpos++ = MD5_MAC_LEN; /* Value-Size */
95 addr[0] = &resp->identifier;
97 addr[1] = config->password;
98 elen[1] = config->password_len;
100 elen[2] = challenge_len;
101 md5_vector(3, addr, elen, rpos);
102 wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Response", rpos, MD5_MAC_LEN);
108 const struct eap_method eap_method_md5 =
110 .method = EAP_TYPE_MD5,
112 .init = eap_md5_init,
113 .deinit = eap_md5_deinit,
114 .process = eap_md5_process,