2005-06-05 20:52:14 +00:00
|
|
|
/*
|
2007-07-11 15:48:36 +00:00
|
|
|
* EAP peer method: EAP-GTC (RFC 3748)
|
|
|
|
* Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
|
2005-06-05 20:52:14 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of BSD
|
|
|
|
* license.
|
|
|
|
*
|
|
|
|
* See README and COPYING for more details.
|
|
|
|
*/
|
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
#include "includes.h"
|
2005-06-05 20:52:14 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "eap_i.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct eap_gtc_data {
|
|
|
|
int prefix;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void * eap_gtc_init(struct eap_sm *sm)
|
|
|
|
{
|
|
|
|
struct eap_gtc_data *data;
|
2007-07-11 15:48:36 +00:00
|
|
|
data = os_zalloc(sizeof(*data));
|
2005-06-05 20:52:14 +00:00
|
|
|
if (data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (sm->m && sm->m->method == EAP_TYPE_FAST) {
|
|
|
|
wpa_printf(MSG_DEBUG, "EAP-GTC: EAP-FAST tunnel - use prefix "
|
|
|
|
"with challenge/response");
|
|
|
|
data->prefix = 1;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void eap_gtc_deinit(struct eap_sm *sm, void *priv)
|
|
|
|
{
|
|
|
|
struct eap_gtc_data *data = priv;
|
2007-07-11 15:48:36 +00:00
|
|
|
os_free(data);
|
2005-06-05 20:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u8 * eap_gtc_process(struct eap_sm *sm, void *priv,
|
|
|
|
struct eap_method_ret *ret,
|
2006-03-07 05:26:33 +00:00
|
|
|
const u8 *reqData, size_t reqDataLen,
|
2005-06-05 20:52:14 +00:00
|
|
|
size_t *respDataLen)
|
|
|
|
{
|
|
|
|
struct eap_gtc_data *data = priv;
|
2006-03-07 05:26:33 +00:00
|
|
|
const struct eap_hdr *req;
|
|
|
|
struct eap_hdr *resp;
|
2007-07-11 15:48:36 +00:00
|
|
|
const u8 *pos, *password, *identity;
|
2006-03-07 05:26:33 +00:00
|
|
|
u8 *rpos;
|
2007-07-11 15:48:36 +00:00
|
|
|
size_t password_len, identity_len, len, plen;
|
|
|
|
int otp;
|
2006-03-07 05:26:33 +00:00
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
|
|
|
|
reqData, reqDataLen, &len);
|
2006-03-07 05:26:33 +00:00
|
|
|
if (pos == NULL) {
|
2005-06-05 20:52:14 +00:00
|
|
|
ret->ignore = TRUE;
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-03-07 05:26:33 +00:00
|
|
|
req = (const struct eap_hdr *) reqData;
|
|
|
|
|
|
|
|
wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-GTC: Request message", pos, len);
|
2005-06-05 20:52:14 +00:00
|
|
|
if (data->prefix &&
|
2007-07-11 15:48:36 +00:00
|
|
|
(len < 10 || os_memcmp(pos, "CHALLENGE=", 10) != 0)) {
|
2005-06-05 20:52:14 +00:00
|
|
|
wpa_printf(MSG_DEBUG, "EAP-GTC: Challenge did not start with "
|
|
|
|
"expected prefix");
|
|
|
|
|
|
|
|
/* Send an empty response in order to allow tunneled
|
|
|
|
* acknowledgement of the failure. This will also cover the
|
|
|
|
* error case which seems to use EAP-MSCHAPv2 like error
|
|
|
|
* reporting with EAP-GTC inside EAP-FAST tunnel. */
|
2007-07-11 15:48:36 +00:00
|
|
|
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC,
|
|
|
|
respDataLen, 0, EAP_CODE_RESPONSE,
|
|
|
|
req->identifier, NULL);
|
2005-06-05 20:52:14 +00:00
|
|
|
return (u8 *) resp;
|
|
|
|
}
|
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
password = eap_get_config_otp(sm, &password_len);
|
|
|
|
if (password)
|
|
|
|
otp = 1;
|
|
|
|
else {
|
|
|
|
password = eap_get_config_password(sm, &password_len);
|
|
|
|
otp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password == NULL) {
|
2005-06-05 20:52:14 +00:00
|
|
|
wpa_printf(MSG_INFO, "EAP-GTC: Password not configured");
|
2007-07-11 15:48:36 +00:00
|
|
|
eap_sm_request_otp(sm, (const char *) pos, len);
|
2005-06-05 20:52:14 +00:00
|
|
|
ret->ignore = TRUE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->ignore = FALSE;
|
|
|
|
|
|
|
|
ret->methodState = data->prefix ? METHOD_MAY_CONT : METHOD_DONE;
|
|
|
|
ret->decision = DECISION_COND_SUCC;
|
|
|
|
ret->allowNotifications = FALSE;
|
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
plen = password_len;
|
|
|
|
identity = eap_get_config_identity(sm, &identity_len);
|
|
|
|
if (identity == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (data->prefix)
|
|
|
|
plen += 9 + identity_len + 1;
|
|
|
|
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, respDataLen,
|
|
|
|
plen, EAP_CODE_RESPONSE, req->identifier, &rpos);
|
2005-06-05 20:52:14 +00:00
|
|
|
if (resp == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (data->prefix) {
|
2007-07-11 15:48:36 +00:00
|
|
|
os_memcpy(rpos, "RESPONSE=", 9);
|
2006-03-07 05:26:33 +00:00
|
|
|
rpos += 9;
|
2007-07-11 15:48:36 +00:00
|
|
|
os_memcpy(rpos, identity, identity_len);
|
|
|
|
rpos += identity_len;
|
2006-03-07 05:26:33 +00:00
|
|
|
*rpos++ = '\0';
|
2005-06-05 20:52:14 +00:00
|
|
|
}
|
2007-07-11 15:48:36 +00:00
|
|
|
os_memcpy(rpos, password, password_len);
|
2005-06-05 20:52:14 +00:00
|
|
|
wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-GTC: Response",
|
2007-07-11 15:48:36 +00:00
|
|
|
(u8 *) (resp + 1) + 1, plen);
|
2005-06-05 20:52:14 +00:00
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
if (otp) {
|
2005-06-05 20:52:14 +00:00
|
|
|
wpa_printf(MSG_DEBUG, "EAP-GTC: Forgetting used password");
|
2007-07-11 15:48:36 +00:00
|
|
|
eap_clear_config_otp(sm);
|
2005-06-05 20:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (u8 *) resp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
int eap_peer_gtc_register(void)
|
2005-06-05 20:52:14 +00:00
|
|
|
{
|
2007-07-11 15:48:36 +00:00
|
|
|
struct eap_method *eap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
|
|
|
|
EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
|
|
|
|
if (eap == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
eap->init = eap_gtc_init;
|
|
|
|
eap->deinit = eap_gtc_deinit;
|
|
|
|
eap->process = eap_gtc_process;
|
|
|
|
|
|
|
|
ret = eap_peer_method_register(eap);
|
|
|
|
if (ret)
|
|
|
|
eap_peer_method_free(eap);
|
|
|
|
return ret;
|
|
|
|
}
|