diff options
Diffstat (limited to 'contrib/wpa_supplicant/eap_otp.c')
-rw-r--r-- | contrib/wpa_supplicant/eap_otp.c | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/contrib/wpa_supplicant/eap_otp.c b/contrib/wpa_supplicant/eap_otp.c index e7ec44c4340b..4cb131f30b4e 100644 --- a/contrib/wpa_supplicant/eap_otp.c +++ b/contrib/wpa_supplicant/eap_otp.c @@ -1,6 +1,6 @@ /* - * WPA Supplicant / EAP-OTP (RFC 3748) - * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.fi> + * EAP peer method: EAP-OTP (RFC 3748) + * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi> * * 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 @@ -12,18 +12,17 @@ * See README and COPYING for more details. */ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> +#include "includes.h" #include "common.h" #include "eap_i.h" -#include "wpa_supplicant.h" #include "config_ssid.h" static void * eap_otp_init(struct eap_sm *sm) { + /* No need for private data. However, must return non-NULL to indicate + * success. */ return (void *) 1; } @@ -38,14 +37,15 @@ static u8 * eap_otp_process(struct eap_sm *sm, void *priv, const u8 *reqData, size_t reqDataLen, size_t *respDataLen) { - struct wpa_ssid *config = eap_get_config(sm); const struct eap_hdr *req; struct eap_hdr *resp; const u8 *pos, *password; u8 *rpos; size_t password_len, len; + int otp; - pos = eap_hdr_validate(EAP_TYPE_OTP, reqData, reqDataLen, &len); + pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_OTP, + reqData, reqDataLen, &len); if (pos == NULL) { ret->ignore = TRUE; return NULL; @@ -54,58 +54,61 @@ static u8 * eap_otp_process(struct eap_sm *sm, void *priv, wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-OTP: Request message", pos, len); - if (config == NULL || - (config->password == NULL && config->otp == NULL)) { + 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) { wpa_printf(MSG_INFO, "EAP-OTP: Password not configured"); - eap_sm_request_otp(sm, config, (const char *) pos, len); + eap_sm_request_otp(sm, (const char *) pos, len); ret->ignore = TRUE; return NULL; } - if (config->otp) { - password = config->otp; - password_len = config->otp_len; - } else { - password = config->password; - password_len = config->password_len; - } - ret->ignore = FALSE; ret->methodState = METHOD_DONE; ret->decision = DECISION_COND_SUCC; ret->allowNotifications = FALSE; - *respDataLen = sizeof(struct eap_hdr) + 1 + password_len; - resp = malloc(*respDataLen); + resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_OTP, respDataLen, + password_len, EAP_CODE_RESPONSE, req->identifier, + &rpos); if (resp == NULL) return NULL; - resp->code = EAP_CODE_RESPONSE; - resp->identifier = req->identifier; - resp->length = host_to_be16(*respDataLen); - rpos = (u8 *) (resp + 1); - *rpos++ = EAP_TYPE_OTP; - memcpy(rpos, password, password_len); + os_memcpy(rpos, password, password_len); wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-OTP: Response", password, password_len); - if (config->otp) { + if (otp) { wpa_printf(MSG_DEBUG, "EAP-OTP: Forgetting used password"); - memset(config->otp, 0, config->otp_len); - free(config->otp); - config->otp = NULL; - config->otp_len = 0; + eap_clear_config_otp(sm); } return (u8 *) resp; } -const struct eap_method eap_method_otp = +int eap_peer_otp_register(void) { - .method = EAP_TYPE_OTP, - .name = "OTP", - .init = eap_otp_init, - .deinit = eap_otp_deinit, - .process = eap_otp_process, -}; + 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; +} |