2 * EAP peer method: EAP-MD5 (RFC 3748 and RFC 1994)
3 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.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.
23 static void * eap_md5_init(struct eap_sm
*sm
)
25 /* No need for private data. However, must return non-NULL to indicate
31 static void eap_md5_deinit(struct eap_sm
*sm
, void *priv
)
36 static u8
* eap_md5_process(struct eap_sm
*sm
, void *priv
,
37 struct eap_method_ret
*ret
,
38 const u8
*reqData
, size_t reqDataLen
,
41 const struct eap_hdr
*req
;
43 const u8
*pos
, *challenge
, *password
;
45 size_t len
, challenge_len
, password_len
;
49 password
= eap_get_config_password(sm
, &password_len
);
50 if (password
== NULL
) {
51 wpa_printf(MSG_INFO
, "EAP-MD5: Password not configured");
52 eap_sm_request_password(sm
);
57 pos
= eap_hdr_validate(EAP_VENDOR_IETF
, EAP_TYPE_MD5
,
58 reqData
, reqDataLen
, &len
);
59 if (pos
== NULL
|| len
== 0) {
60 wpa_printf(MSG_INFO
, "EAP-MD5: Invalid frame (pos=%p len=%lu)",
61 pos
, (unsigned long) len
);
68 * Value-Size (1 octet) | Value(Challenge) | Name(optional)
70 req
= (const struct eap_hdr
*) reqData
;
71 challenge_len
= *pos
++;
72 if (challenge_len
== 0 || challenge_len
> len
- 1) {
73 wpa_printf(MSG_INFO
, "EAP-MD5: Invalid challenge "
74 "(challenge_len=%lu len=%lu)",
75 (unsigned long) challenge_len
, (unsigned long) len
);
81 wpa_hexdump(MSG_MSGDUMP
, "EAP-MD5: Challenge",
82 challenge
, challenge_len
);
84 wpa_printf(MSG_DEBUG
, "EAP-MD5: Generating Challenge Response");
85 ret
->methodState
= METHOD_DONE
;
86 ret
->decision
= DECISION_UNCOND_SUCC
;
87 ret
->allowNotifications
= TRUE
;
89 resp
= eap_msg_alloc(EAP_VENDOR_IETF
, EAP_TYPE_MD5
, respDataLen
,
90 1 + MD5_MAC_LEN
, EAP_CODE_RESPONSE
,
91 req
->identifier
, &rpos
);
97 * Value-Size (1 octet) | Value(Response) | Name(optional)
99 *rpos
++ = MD5_MAC_LEN
;
101 addr
[0] = &resp
->identifier
;
104 elen
[1] = password_len
;
106 elen
[2] = challenge_len
;
107 md5_vector(3, addr
, elen
, rpos
);
108 wpa_hexdump(MSG_MSGDUMP
, "EAP-MD5: Response", rpos
, MD5_MAC_LEN
);
114 int eap_peer_md5_register(void)
116 struct eap_method
*eap
;
119 eap
= eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION
,
120 EAP_VENDOR_IETF
, EAP_TYPE_MD5
, "MD5");
124 eap
->init
= eap_md5_init
;
125 eap
->deinit
= eap_md5_deinit
;
126 eap
->process
= eap_md5_process
;
128 ret
= eap_peer_method_register(eap
);
130 eap_peer_method_free(eap
);