~ubuntu-branches/ubuntu/gutsy/wpasupplicant/gutsy

« back to all changes in this revision

Viewing changes to src/eap_server/eap_gtc.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Alexander Sack
  • Date: 2007-08-26 16:06:57 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070826160657-2m8pxoweuxe8f93t
Tags: 0.6.0+0.5.8-0ubuntu1
* New upstream release
* remove patch 11_erroneous_manpage_ref, applied upstream
* remove patch 25_wpas_dbus_unregister_iface_fix, applied upstream

[ Alexander Sack ]
* bumping upstream version to replace development version 0.6.0 with
  this package from stable release branch.
* attempt to fix wierd timeout and high latency issues by going
  back to stable upstream version (0.5.9) (LP: #140763,
  LP: #141233).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * hostapd / EAP-GTC (RFC 3748)
3
 
 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
4
 
 *
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.
8
 
 *
9
 
 * Alternatively, this software may be distributed under the terms of BSD
10
 
 * license.
11
 
 *
12
 
 * See README and COPYING for more details.
13
 
 */
14
 
 
15
 
#include "includes.h"
16
 
 
17
 
#include "common.h"
18
 
#include "eap_i.h"
19
 
 
20
 
 
21
 
struct eap_gtc_data {
22
 
        enum { CONTINUE, SUCCESS, FAILURE } state;
23
 
};
24
 
 
25
 
 
26
 
static void * eap_gtc_init(struct eap_sm *sm)
27
 
{
28
 
        struct eap_gtc_data *data;
29
 
 
30
 
        data = os_zalloc(sizeof(*data));
31
 
        if (data == NULL)
32
 
                return NULL;
33
 
        data->state = CONTINUE;
34
 
 
35
 
        return data;
36
 
}
37
 
 
38
 
 
39
 
static void eap_gtc_reset(struct eap_sm *sm, void *priv)
40
 
{
41
 
        struct eap_gtc_data *data = priv;
42
 
        free(data);
43
 
}
44
 
 
45
 
 
46
 
static u8 * eap_gtc_buildReq(struct eap_sm *sm, void *priv, int id,
47
 
                             size_t *reqDataLen)
48
 
{
49
 
        struct eap_gtc_data *data = priv;
50
 
        struct eap_hdr *req;
51
 
        u8 *pos;
52
 
        char *msg = "Password";
53
 
        size_t msg_len;
54
 
 
55
 
        msg_len = strlen(msg);
56
 
        req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, reqDataLen,
57
 
                            msg_len, EAP_CODE_REQUEST, id, &pos);
58
 
        if (req == NULL) {
59
 
                wpa_printf(MSG_ERROR, "EAP-GTC: Failed to allocate memory for "
60
 
                           "request");
61
 
                data->state = FAILURE;
62
 
                return NULL;
63
 
        }
64
 
 
65
 
        memcpy(pos, msg, msg_len);
66
 
 
67
 
        data->state = CONTINUE;
68
 
 
69
 
        return (u8 *) req;
70
 
}
71
 
 
72
 
 
73
 
static Boolean eap_gtc_check(struct eap_sm *sm, void *priv,
74
 
                             u8 *respData, size_t respDataLen)
75
 
{
76
 
        const u8 *pos;
77
 
        size_t len;
78
 
 
79
 
        pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
80
 
                               respData, respDataLen, &len);
81
 
        if (pos == NULL || len < 1) {
82
 
                wpa_printf(MSG_INFO, "EAP-GTC: Invalid frame");
83
 
                return TRUE;
84
 
        }
85
 
 
86
 
        return FALSE;
87
 
}
88
 
 
89
 
 
90
 
static void eap_gtc_process(struct eap_sm *sm, void *priv,
91
 
                            u8 *respData, size_t respDataLen)
92
 
{
93
 
        struct eap_gtc_data *data = priv;
94
 
        const u8 *pos;
95
 
        size_t rlen;
96
 
 
97
 
        if (sm->user == NULL || sm->user->password == NULL ||
98
 
            sm->user->password_hash) {
99
 
                wpa_printf(MSG_INFO, "EAP-GTC: Plaintext password not "
100
 
                           "configured");
101
 
                data->state = FAILURE;
102
 
                return;
103
 
        }
104
 
 
105
 
        pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
106
 
                               respData, respDataLen, &rlen);
107
 
        if (pos == NULL || rlen < 1)
108
 
                return; /* Should not happen - frame already validated */
109
 
 
110
 
        wpa_hexdump_key(MSG_MSGDUMP, "EAP-GTC: Response", pos, rlen);
111
 
 
112
 
        if (rlen != sm->user->password_len ||
113
 
            memcmp(pos, sm->user->password, rlen) != 0) {
114
 
                wpa_printf(MSG_DEBUG, "EAP-GTC: Done - Failure");
115
 
                data->state = FAILURE;
116
 
        } else {
117
 
                wpa_printf(MSG_DEBUG, "EAP-GTC: Done - Success");
118
 
                data->state = SUCCESS;
119
 
        }
120
 
}
121
 
 
122
 
 
123
 
static Boolean eap_gtc_isDone(struct eap_sm *sm, void *priv)
124
 
{
125
 
        struct eap_gtc_data *data = priv;
126
 
        return data->state != CONTINUE;
127
 
}
128
 
 
129
 
 
130
 
static Boolean eap_gtc_isSuccess(struct eap_sm *sm, void *priv)
131
 
{
132
 
        struct eap_gtc_data *data = priv;
133
 
        return data->state == SUCCESS;
134
 
}
135
 
 
136
 
 
137
 
int eap_server_gtc_register(void)
138
 
{
139
 
        struct eap_method *eap;
140
 
        int ret;
141
 
 
142
 
        eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
143
 
                                      EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
144
 
        if (eap == NULL)
145
 
                return -1;
146
 
 
147
 
        eap->init = eap_gtc_init;
148
 
        eap->reset = eap_gtc_reset;
149
 
        eap->buildReq = eap_gtc_buildReq;
150
 
        eap->check = eap_gtc_check;
151
 
        eap->process = eap_gtc_process;
152
 
        eap->isDone = eap_gtc_isDone;
153
 
        eap->isSuccess = eap_gtc_isSuccess;
154
 
 
155
 
        ret = eap_server_method_register(eap);
156
 
        if (ret)
157
 
                eap_server_method_free(eap);
158
 
        return ret;
159
 
}