2 * EAP peer method: EAP-MD5 (RFC 3748 and RFC 1994)
3 * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
13 #include "eap_common/chap.h"
16 static void * eap_md5_init(struct eap_sm *sm)
18 /* No need for private data. However, must return non-NULL to indicate
24 static void eap_md5_deinit(struct eap_sm *sm, void *priv)
29 static struct wpabuf * eap_md5_process(struct eap_sm *sm, void *priv,
30 struct eap_method_ret *ret,
31 const struct wpabuf *reqData)
34 const u8 *pos, *challenge, *password;
36 size_t len, challenge_len, password_len;
38 password = eap_get_config_password(sm, &password_len);
39 if (password == NULL) {
40 wpa_printf(MSG_INFO, "EAP-MD5: Password not configured");
41 eap_sm_request_password(sm);
46 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_MD5, reqData, &len);
47 if (pos == NULL || len == 0) {
48 wpa_printf(MSG_INFO, "EAP-MD5: Invalid frame (pos=%p len=%lu)",
49 pos, (unsigned long) len);
56 * Value-Size (1 octet) | Value(Challenge) | Name(optional)
58 challenge_len = *pos++;
59 if (challenge_len == 0 || challenge_len > len - 1) {
60 wpa_printf(MSG_INFO, "EAP-MD5: Invalid challenge "
61 "(challenge_len=%lu len=%lu)",
62 (unsigned long) challenge_len, (unsigned long) len);
68 wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Challenge",
69 challenge, challenge_len);
71 wpa_printf(MSG_DEBUG, "EAP-MD5: Generating Challenge Response");
72 ret->methodState = METHOD_DONE;
73 ret->decision = DECISION_COND_SUCC;
74 ret->allowNotifications = TRUE;
76 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_MD5, 1 + CHAP_MD5_LEN,
77 EAP_CODE_RESPONSE, eap_get_id(reqData));
83 * Value-Size (1 octet) | Value(Response) | Name(optional)
85 wpabuf_put_u8(resp, CHAP_MD5_LEN);
87 id = eap_get_id(resp);
88 rpos = wpabuf_put(resp, CHAP_MD5_LEN);
89 if (chap_md5(id, password, password_len, challenge, challenge_len,
91 wpa_printf(MSG_INFO, "EAP-MD5: CHAP MD5 operation failed");
96 wpa_hexdump(MSG_MSGDUMP, "EAP-MD5: Response", rpos, CHAP_MD5_LEN);
102 int eap_peer_md5_register(void)
104 struct eap_method *eap;
107 eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
108 EAP_VENDOR_IETF, EAP_TYPE_MD5, "MD5");
112 eap->init = eap_md5_init;
113 eap->deinit = eap_md5_deinit;
114 eap->process = eap_md5_process;
116 ret = eap_peer_method_register(eap);
118 eap_peer_method_free(eap);