2005-06-05 20:52:14 +00:00
|
|
|
/*
|
2007-07-11 15:48:36 +00:00
|
|
|
* EAP peer method: EAP-OTP (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"
|
|
|
|
#include "config_ssid.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void * eap_otp_init(struct eap_sm *sm)
|
|
|
|
{
|
2007-07-11 15:48:36 +00:00
|
|
|
/* No need for private data. However, must return non-NULL to indicate
|
|
|
|
* success. */
|
2005-06-05 20:52:14 +00:00
|
|
|
return (void *) 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void eap_otp_deinit(struct eap_sm *sm, void *priv)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u8 * eap_otp_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)
|
|
|
|
{
|
2006-03-07 05:26:33 +00:00
|
|
|
const struct eap_hdr *req;
|
|
|
|
struct eap_hdr *resp;
|
|
|
|
const u8 *pos, *password;
|
|
|
|
u8 *rpos;
|
2005-06-05 20:52:14 +00:00
|
|
|
size_t password_len, len;
|
2007-07-11 15:48:36 +00:00
|
|
|
int otp;
|
2005-06-05 20:52:14 +00:00
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_OTP,
|
|
|
|
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;
|
2005-06-05 20:52:14 +00:00
|
|
|
wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-OTP: Request message",
|
2006-03-07 05:26:33 +00:00
|
|
|
pos, len);
|
2005-06-05 20:52:14 +00:00
|
|
|
|
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-OTP: 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 = METHOD_DONE;
|
|
|
|
ret->decision = DECISION_COND_SUCC;
|
|
|
|
ret->allowNotifications = FALSE;
|
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_OTP, respDataLen,
|
|
|
|
password_len, EAP_CODE_RESPONSE, req->identifier,
|
|
|
|
&rpos);
|
2005-06-05 20:52:14 +00:00
|
|
|
if (resp == NULL)
|
|
|
|
return NULL;
|
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-OTP: Response",
|
|
|
|
password, password_len);
|
|
|
|
|
2007-07-11 15:48:36 +00:00
|
|
|
if (otp) {
|
2005-06-05 20:52:14 +00:00
|
|
|
wpa_printf(MSG_DEBUG, "EAP-OTP: 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_otp_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_OTP, "OTP");
|
|
|
|
if (eap == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
eap->init = eap_otp_init;
|
|
|
|
eap->deinit = eap_otp_deinit;
|
|
|
|
eap->process = eap_otp_process;
|
|
|
|
|
|
|
|
ret = eap_peer_method_register(eap);
|
|
|
|
if (ret)
|
|
|
|
eap_peer_method_free(eap);
|
|
|
|
return ret;
|
|
|
|
}
|