2 * hostapd / EAP-GTC (RFC 3748)
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 enum { CONTINUE, SUCCESS, FAILURE } state;
27 static void * eap_gtc_init(struct eap_sm *sm)
29 struct eap_gtc_data *data;
31 data = wpa_zalloc(sizeof(*data));
34 data->state = CONTINUE;
40 static void eap_gtc_reset(struct eap_sm *sm, void *priv)
42 struct eap_gtc_data *data = priv;
47 static u8 * eap_gtc_buildReq(struct eap_sm *sm, void *priv, int id,
50 struct eap_gtc_data *data = priv;
53 char *msg = "Password";
56 msg_len = strlen(msg);
57 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, reqDataLen,
58 msg_len, EAP_CODE_REQUEST, id, &pos);
60 wpa_printf(MSG_ERROR, "EAP-GTC: Failed to allocate memory for "
62 data->state = FAILURE;
66 memcpy(pos, msg, msg_len);
68 data->state = CONTINUE;
74 static Boolean eap_gtc_check(struct eap_sm *sm, void *priv,
75 u8 *respData, size_t respDataLen)
80 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
81 respData, respDataLen, &len);
82 if (pos == NULL || len < 1) {
83 wpa_printf(MSG_INFO, "EAP-GTC: Invalid frame");
91 static void eap_gtc_process(struct eap_sm *sm, void *priv,
92 u8 *respData, size_t respDataLen)
94 struct eap_gtc_data *data = priv;
98 if (sm->user == NULL || sm->user->password == NULL ||
99 sm->user->password_hash) {
100 wpa_printf(MSG_INFO, "EAP-GTC: Plaintext password not "
102 data->state = FAILURE;
106 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
107 respData, respDataLen, &rlen);
108 if (pos == NULL || rlen < 1)
109 return; /* Should not happen - frame already validated */
111 wpa_hexdump_key(MSG_MSGDUMP, "EAP-GTC: Response", pos, rlen);
113 if (rlen != sm->user->password_len ||
114 memcmp(pos, sm->user->password, rlen) != 0) {
115 wpa_printf(MSG_DEBUG, "EAP-GTC: Done - Failure");
116 data->state = FAILURE;
118 wpa_printf(MSG_DEBUG, "EAP-GTC: Done - Success");
119 data->state = SUCCESS;
124 static Boolean eap_gtc_isDone(struct eap_sm *sm, void *priv)
126 struct eap_gtc_data *data = priv;
127 return data->state != CONTINUE;
131 static Boolean eap_gtc_isSuccess(struct eap_sm *sm, void *priv)
133 struct eap_gtc_data *data = priv;
134 return data->state == SUCCESS;
138 int eap_server_gtc_register(void)
140 struct eap_method *eap;
143 eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
144 EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
148 eap->init = eap_gtc_init;
149 eap->reset = eap_gtc_reset;
150 eap->buildReq = eap_gtc_buildReq;
151 eap->check = eap_gtc_check;
152 eap->process = eap_gtc_process;
153 eap->isDone = eap_gtc_isDone;
154 eap->isSuccess = eap_gtc_isSuccess;
156 ret = eap_server_method_register(eap);
158 eap_server_method_free(eap);