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
);
60 if (pos
== NULL
|| len
== 0) {
61 wpa_printf(MSG_INFO
, "EAP-MD5: Invalid frame (pos=%p len=%lu)",
62 pos
, (unsigned long) len
);
66 req
= (const struct eap_hdr
*) reqData
;
67 challenge_len
= *pos
++;
68 if (challenge_len
== 0 ||
69 challenge_len
> len
- 1) {
70 wpa_printf(MSG_INFO
, "EAP-MD5: Invalid challenge "
71 "(challenge_len=%d len=%lu)",
72 challenge_len
, (unsigned long) len
);
78 wpa_hexdump(MSG_MSGDUMP
, "EAP-MD5: Challenge",
79 challenge
, challenge_len
);
81 wpa_printf(MSG_DEBUG
, "EAP-MD5: generating Challenge Response");
82 ret
->methodState
= METHOD_DONE
;
83 ret
->decision
= DECISION_UNCOND_SUCC
;
84 ret
->allowNotifications
= TRUE
;
86 *respDataLen
= sizeof(struct eap_hdr
) + 1 + 1 + MD5_MAC_LEN
;
87 resp
= malloc(*respDataLen
);
90 resp
->code
= EAP_CODE_RESPONSE
;
91 resp
->identifier
= req
->identifier
;
92 resp
->length
= host_to_be16(*respDataLen
);
93 rpos
= (u8
*) (resp
+ 1);
94 *rpos
++ = EAP_TYPE_MD5
;
95 *rpos
++ = MD5_MAC_LEN
; /* Value-Size */
97 addr
[0] = &resp
->identifier
;
99 addr
[1] = config
->password
;
100 elen
[1] = config
->password_len
;
102 elen
[2] = challenge_len
;
103 md5_vector(3, addr
, elen
, rpos
);
104 wpa_hexdump(MSG_MSGDUMP
, "EAP-MD5: Response", rpos
, MD5_MAC_LEN
);
110 const struct eap_method eap_method_md5
=
112 .method
= EAP_TYPE_MD5
,
114 .init
= eap_md5_init
,
115 .deinit
= eap_md5_deinit
,
116 .process
= eap_md5_process
,