2 * EAP peer method: EAP-GTC (RFC 3748)
3 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
20 static void * eap_gtc_init(struct eap_sm *sm)
22 struct eap_gtc_data *data;
23 data = os_zalloc(sizeof(*data));
27 if (sm->m && sm->m->vendor == EAP_VENDOR_IETF &&
28 sm->m->method == EAP_TYPE_FAST) {
29 wpa_printf(MSG_DEBUG, "EAP-GTC: EAP-FAST tunnel - use prefix "
30 "with challenge/response");
37 static void eap_gtc_deinit(struct eap_sm *sm, void *priv)
39 struct eap_gtc_data *data = priv;
44 static struct wpabuf * eap_gtc_process(struct eap_sm *sm, void *priv,
45 struct eap_method_ret *ret,
46 const struct wpabuf *reqData)
48 struct eap_gtc_data *data = priv;
50 const u8 *pos, *password, *identity;
51 size_t password_len, identity_len, len, plen;
55 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC, reqData, &len);
60 id = eap_get_id(reqData);
62 wpa_hexdump_ascii(MSG_MSGDUMP, "EAP-GTC: Request message", pos, len);
64 (len < 10 || os_memcmp(pos, "CHALLENGE=", 10) != 0)) {
65 wpa_printf(MSG_DEBUG, "EAP-GTC: Challenge did not start with "
68 /* Send an empty response in order to allow tunneled
69 * acknowledgement of the failure. This will also cover the
70 * error case which seems to use EAP-MSCHAPv2 like error
71 * reporting with EAP-GTC inside EAP-FAST tunnel. */
72 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC,
73 0, EAP_CODE_RESPONSE, id);
77 password = eap_get_config_otp(sm, &password_len);
81 password = eap_get_config_password(sm, &password_len);
85 if (password == NULL) {
86 wpa_printf(MSG_INFO, "EAP-GTC: Password not configured");
87 eap_sm_request_otp(sm, (const char *) pos, len);
94 ret->methodState = data->prefix ? METHOD_MAY_CONT : METHOD_DONE;
95 ret->decision = DECISION_COND_SUCC;
96 ret->allowNotifications = FALSE;
99 identity = eap_get_config_identity(sm, &identity_len);
100 if (identity == NULL)
103 plen += 9 + identity_len + 1;
104 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, plen,
105 EAP_CODE_RESPONSE, id);
109 wpabuf_put_data(resp, "RESPONSE=", 9);
110 wpabuf_put_data(resp, identity, identity_len);
111 wpabuf_put_u8(resp, '\0');
113 wpabuf_put_data(resp, password, password_len);
114 wpa_hexdump_ascii_key(MSG_MSGDUMP, "EAP-GTC: Response",
115 wpabuf_head_u8(resp) + sizeof(struct eap_hdr) +
119 wpa_printf(MSG_DEBUG, "EAP-GTC: Forgetting used password");
120 eap_clear_config_otp(sm);
127 int eap_peer_gtc_register(void)
129 struct eap_method *eap;
132 eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
133 EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
137 eap->init = eap_gtc_init;
138 eap->deinit = eap_gtc_deinit;
139 eap->process = eap_gtc_process;
141 ret = eap_peer_method_register(eap);
143 eap_peer_method_free(eap);