summaryrefslogtreecommitdiffstats
path: root/contrib/wpa_supplicant/eap_gtc.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/wpa_supplicant/eap_gtc.c')
-rw-r--r--contrib/wpa_supplicant/eap_gtc.c120
1 files changed, 57 insertions, 63 deletions
diff --git a/contrib/wpa_supplicant/eap_gtc.c b/contrib/wpa_supplicant/eap_gtc.c
index 3665746..ed4f8f3 100644
--- a/contrib/wpa_supplicant/eap_gtc.c
+++ b/contrib/wpa_supplicant/eap_gtc.c
@@ -1,6 +1,6 @@
/*
- * WPA Supplicant / EAP-GTC (RFC 2284)
- * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.fi>
+ * EAP peer method: EAP-GTC (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,14 +12,10 @@
* 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"
struct eap_gtc_data {
@@ -30,10 +26,9 @@ struct eap_gtc_data {
static void * eap_gtc_init(struct eap_sm *sm)
{
struct eap_gtc_data *data;
- data = malloc(sizeof(*data));
+ data = os_zalloc(sizeof(*data));
if (data == NULL)
return NULL;
- memset(data, 0, sizeof(*data));
if (sm->m && sm->m->method == EAP_TYPE_FAST) {
wpa_printf(MSG_DEBUG, "EAP-GTC: EAP-FAST tunnel - use prefix "
@@ -47,7 +42,7 @@ static void * eap_gtc_init(struct eap_sm *sm)
static void eap_gtc_deinit(struct eap_sm *sm, void *priv)
{
struct eap_gtc_data *data = priv;
- free(data);
+ os_free(data);
}
@@ -57,14 +52,15 @@ static u8 * eap_gtc_process(struct eap_sm *sm, void *priv,
size_t *respDataLen)
{
struct eap_gtc_data *data = priv;
- struct wpa_ssid *config = eap_get_config(sm);
const struct eap_hdr *req;
struct eap_hdr *resp;
- const u8 *pos, *password;
+ const u8 *pos, *password, *identity;
u8 *rpos;
- size_t password_len, len;
+ size_t password_len, identity_len, len, plen;
+ int otp;
- pos = eap_hdr_validate(EAP_TYPE_GTC, reqData, reqDataLen, &len);
+ pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
+ reqData, reqDataLen, &len);
if (pos == NULL) {
ret->ignore = TRUE;
return NULL;
@@ -73,7 +69,7 @@ static u8 * eap_gtc_process(struct eap_sm *sm, void *priv,
wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-GTC: Request message", pos, len);
if (data->prefix &&
- (len < 10 || memcmp(pos, "CHALLENGE=", 10) != 0)) {
+ (len < 10 || os_memcmp(pos, "CHALLENGE=", 10) != 0)) {
wpa_printf(MSG_DEBUG, "EAP-GTC: Challenge did not start with "
"expected prefix");
@@ -81,81 +77,79 @@ static u8 * eap_gtc_process(struct eap_sm *sm, void *priv,
* 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. */
- *respDataLen = sizeof(struct eap_hdr) + 1;
- resp = malloc(*respDataLen);
- 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_GTC;
+ resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC,
+ respDataLen, 0, EAP_CODE_RESPONSE,
+ req->identifier, NULL);
return (u8 *) resp;
}
- 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-GTC: 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 = data->prefix ? METHOD_MAY_CONT : METHOD_DONE;
ret->decision = DECISION_COND_SUCC;
ret->allowNotifications = FALSE;
- *respDataLen = sizeof(struct eap_hdr) + 1 + password_len;
- if (data->prefix) {
- *respDataLen += 9 + config->identity_len + 1;
- }
- resp = malloc(*respDataLen);
+ 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);
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_GTC;
if (data->prefix) {
- memcpy(rpos, "RESPONSE=", 9);
+ os_memcpy(rpos, "RESPONSE=", 9);
rpos += 9;
- memcpy(rpos, config->identity, config->identity_len);
- rpos += config->identity_len;
+ os_memcpy(rpos, identity, identity_len);
+ rpos += identity_len;
*rpos++ = '\0';
}
- memcpy(rpos, password, password_len);
+ os_memcpy(rpos, password, password_len);
wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-GTC: Response",
- (u8 *) (resp + 1) + 1,
- *respDataLen - sizeof(struct eap_hdr) - 1);
+ (u8 *) (resp + 1) + 1, plen);
- if (config->otp) {
+ if (otp) {
wpa_printf(MSG_DEBUG, "EAP-GTC: 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_gtc =
+int eap_peer_gtc_register(void)
{
- .method = EAP_TYPE_GTC,
- .name = "GTC",
- .init = eap_gtc_init,
- .deinit = eap_gtc_deinit,
- .process = eap_gtc_process,
-};
+ 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;
+}
OpenPOWER on IntegriCloud