123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- /*
- * EAP peer method: EAP-GPSK (draft-ietf-emu-eap-gpsk-08.txt)
- * Copyright (c) 2006-2008, 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
- * 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.
- */
- #include "includes.h"
- #include "common.h"
- #include "eap_peer/eap_i.h"
- #include "eap_common/eap_gpsk_common.h"
- struct eap_gpsk_data {
- enum { GPSK_1, GPSK_3, SUCCESS, FAILURE } state;
- u8 rand_server[EAP_GPSK_RAND_LEN];
- u8 rand_peer[EAP_GPSK_RAND_LEN];
- u8 msk[EAP_MSK_LEN];
- u8 emsk[EAP_EMSK_LEN];
- u8 sk[EAP_GPSK_MAX_SK_LEN];
- size_t sk_len;
- u8 pk[EAP_GPSK_MAX_PK_LEN];
- size_t pk_len;
- u8 session_id;
- int session_id_set;
- u8 *id_peer;
- size_t id_peer_len;
- u8 *id_server;
- size_t id_server_len;
- int vendor; /* CSuite/Specifier */
- int specifier; /* CSuite/Specifier */
- u8 *psk;
- size_t psk_len;
- };
- static struct wpabuf * eap_gpsk_send_gpsk_2(struct eap_gpsk_data *data,
- u8 identifier,
- const u8 *csuite_list,
- size_t csuite_list_len);
- static struct wpabuf * eap_gpsk_send_gpsk_4(struct eap_gpsk_data *data,
- u8 identifier);
- #ifndef CONFIG_NO_STDOUT_DEBUG
- static const char * eap_gpsk_state_txt(int state)
- {
- switch (state) {
- case GPSK_1:
- return "GPSK-1";
- case GPSK_3:
- return "GPSK-3";
- case SUCCESS:
- return "SUCCESS";
- case FAILURE:
- return "FAILURE";
- default:
- return "?";
- }
- }
- #endif /* CONFIG_NO_STDOUT_DEBUG */
- static void eap_gpsk_state(struct eap_gpsk_data *data, int state)
- {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: %s -> %s",
- eap_gpsk_state_txt(data->state),
- eap_gpsk_state_txt(state));
- data->state = state;
- }
- static void eap_gpsk_deinit(struct eap_sm *sm, void *priv);
- static void * eap_gpsk_init(struct eap_sm *sm)
- {
- struct eap_gpsk_data *data;
- const u8 *identity, *password;
- size_t identity_len, password_len;
- password = eap_get_config_password(sm, &password_len);
- if (password == NULL) {
- wpa_printf(MSG_INFO, "EAP-GPSK: No key (password) configured");
- return NULL;
- }
- data = os_zalloc(sizeof(*data));
- if (data == NULL)
- return NULL;
- data->state = GPSK_1;
- identity = eap_get_config_identity(sm, &identity_len);
- if (identity) {
- data->id_peer = os_malloc(identity_len);
- if (data->id_peer == NULL) {
- eap_gpsk_deinit(sm, data);
- return NULL;
- }
- os_memcpy(data->id_peer, identity, identity_len);
- data->id_peer_len = identity_len;
- }
- data->psk = os_malloc(password_len);
- if (data->psk == NULL) {
- eap_gpsk_deinit(sm, data);
- return NULL;
- }
- os_memcpy(data->psk, password, password_len);
- data->psk_len = password_len;
- return data;
- }
- static void eap_gpsk_deinit(struct eap_sm *sm, void *priv)
- {
- struct eap_gpsk_data *data = priv;
- os_free(data->id_server);
- os_free(data->id_peer);
- os_free(data->psk);
- os_free(data);
- }
- static const u8 * eap_gpsk_process_id_server(struct eap_gpsk_data *data,
- const u8 *pos, const u8 *end)
- {
- u16 alen;
- if (end - pos < 2) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Too short GPSK-1 packet");
- return NULL;
- }
- alen = WPA_GET_BE16(pos);
- pos += 2;
- if (end - pos < alen) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: ID_Server overflow");
- return NULL;
- }
- os_free(data->id_server);
- data->id_server = os_malloc(alen);
- if (data->id_server == NULL) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: No memory for ID_Server");
- return NULL;
- }
- os_memcpy(data->id_server, pos, alen);
- data->id_server_len = alen;
- wpa_hexdump_ascii(MSG_DEBUG, "EAP-GPSK: ID_Server",
- data->id_server, data->id_server_len);
- pos += alen;
- return pos;
- }
- static const u8 * eap_gpsk_process_rand_server(struct eap_gpsk_data *data,
- const u8 *pos, const u8 *end)
- {
- if (pos == NULL)
- return NULL;
- if (end - pos < EAP_GPSK_RAND_LEN) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: RAND_Server overflow");
- return NULL;
- }
- os_memcpy(data->rand_server, pos, EAP_GPSK_RAND_LEN);
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: RAND_Server",
- data->rand_server, EAP_GPSK_RAND_LEN);
- pos += EAP_GPSK_RAND_LEN;
- return pos;
- }
- static int eap_gpsk_select_csuite(struct eap_sm *sm,
- struct eap_gpsk_data *data,
- const u8 *csuite_list,
- size_t csuite_list_len)
- {
- struct eap_gpsk_csuite *csuite;
- int i, count;
- count = csuite_list_len / sizeof(struct eap_gpsk_csuite);
- data->vendor = EAP_GPSK_VENDOR_IETF;
- data->specifier = EAP_GPSK_CIPHER_RESERVED;
- csuite = (struct eap_gpsk_csuite *) csuite_list;
- for (i = 0; i < count; i++) {
- int vendor, specifier;
- vendor = WPA_GET_BE32(csuite->vendor);
- specifier = WPA_GET_BE16(csuite->specifier);
- wpa_printf(MSG_DEBUG, "EAP-GPSK: CSuite[%d]: %d:%d",
- i, vendor, specifier);
- if (data->vendor == EAP_GPSK_VENDOR_IETF &&
- data->specifier == EAP_GPSK_CIPHER_RESERVED &&
- eap_gpsk_supported_ciphersuite(vendor, specifier)) {
- data->vendor = vendor;
- data->specifier = specifier;
- }
- csuite++;
- }
- if (data->vendor == EAP_GPSK_VENDOR_IETF &&
- data->specifier == EAP_GPSK_CIPHER_RESERVED) {
- wpa_msg(sm->msg_ctx, MSG_INFO, "EAP-GPSK: No supported "
- "ciphersuite found");
- return -1;
- }
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Selected ciphersuite %d:%d",
- data->vendor, data->specifier);
- return 0;
- }
- static const u8 * eap_gpsk_process_csuite_list(struct eap_sm *sm,
- struct eap_gpsk_data *data,
- const u8 **list,
- size_t *list_len,
- const u8 *pos, const u8 *end)
- {
- if (pos == NULL)
- return NULL;
- if (end - pos < 2) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Too short GPSK-1 packet");
- return NULL;
- }
- *list_len = WPA_GET_BE16(pos);
- pos += 2;
- if (end - pos < (int) *list_len) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: CSuite_List overflow");
- return NULL;
- }
- if (*list_len == 0 || (*list_len % sizeof(struct eap_gpsk_csuite))) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Invalid CSuite_List len %lu",
- (unsigned long) *list_len);
- return NULL;
- }
- *list = pos;
- pos += *list_len;
- if (eap_gpsk_select_csuite(sm, data, *list, *list_len) < 0)
- return NULL;
- return pos;
- }
- static struct wpabuf * eap_gpsk_process_gpsk_1(struct eap_sm *sm,
- struct eap_gpsk_data *data,
- struct eap_method_ret *ret,
- const struct wpabuf *reqData,
- const u8 *payload,
- size_t payload_len)
- {
- size_t csuite_list_len;
- const u8 *csuite_list, *pos, *end;
- struct wpabuf *resp;
- if (data->state != GPSK_1) {
- ret->ignore = TRUE;
- return NULL;
- }
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Received Request/GPSK-1");
- end = payload + payload_len;
- pos = eap_gpsk_process_id_server(data, payload, end);
- pos = eap_gpsk_process_rand_server(data, pos, end);
- pos = eap_gpsk_process_csuite_list(sm, data, &csuite_list,
- &csuite_list_len, pos, end);
- if (pos == NULL) {
- eap_gpsk_state(data, FAILURE);
- return NULL;
- }
- resp = eap_gpsk_send_gpsk_2(data, eap_get_id(reqData),
- csuite_list, csuite_list_len);
- if (resp == NULL)
- return NULL;
- eap_gpsk_state(data, GPSK_3);
- return resp;
- }
- static struct wpabuf * eap_gpsk_send_gpsk_2(struct eap_gpsk_data *data,
- u8 identifier,
- const u8 *csuite_list,
- size_t csuite_list_len)
- {
- struct wpabuf *resp;
- size_t len, miclen;
- u8 *rpos, *start;
- struct eap_gpsk_csuite *csuite;
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Sending Response/GPSK-2");
- miclen = eap_gpsk_mic_len(data->vendor, data->specifier);
- len = 1 + 2 + data->id_peer_len + 2 + data->id_server_len +
- 2 * EAP_GPSK_RAND_LEN + 2 + csuite_list_len +
- sizeof(struct eap_gpsk_csuite) + 2 + miclen;
- resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GPSK, len,
- EAP_CODE_RESPONSE, identifier);
- if (resp == NULL)
- return NULL;
- wpabuf_put_u8(resp, EAP_GPSK_OPCODE_GPSK_2);
- start = wpabuf_put(resp, 0);
- wpa_hexdump_ascii(MSG_DEBUG, "EAP-GPSK: ID_Peer",
- data->id_peer, data->id_peer_len);
- wpabuf_put_be16(resp, data->id_peer_len);
- wpabuf_put_data(resp, data->id_peer, data->id_peer_len);
- wpabuf_put_be16(resp, data->id_server_len);
- wpabuf_put_data(resp, data->id_server, data->id_server_len);
- if (os_get_random(data->rand_peer, EAP_GPSK_RAND_LEN)) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Failed to get random data "
- "for RAND_Peer");
- eap_gpsk_state(data, FAILURE);
- wpabuf_free(resp);
- return NULL;
- }
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: RAND_Peer",
- data->rand_peer, EAP_GPSK_RAND_LEN);
- wpabuf_put_data(resp, data->rand_peer, EAP_GPSK_RAND_LEN);
- wpabuf_put_data(resp, data->rand_server, EAP_GPSK_RAND_LEN);
- wpabuf_put_be16(resp, csuite_list_len);
- wpabuf_put_data(resp, csuite_list, csuite_list_len);
- csuite = wpabuf_put(resp, sizeof(*csuite));
- WPA_PUT_BE32(csuite->vendor, data->vendor);
- WPA_PUT_BE16(csuite->specifier, data->specifier);
- if (eap_gpsk_derive_keys(data->psk, data->psk_len,
- data->vendor, data->specifier,
- data->rand_peer, data->rand_server,
- data->id_peer, data->id_peer_len,
- data->id_server, data->id_server_len,
- data->msk, data->emsk,
- data->sk, &data->sk_len,
- data->pk, &data->pk_len) < 0) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Failed to derive keys");
- eap_gpsk_state(data, FAILURE);
- wpabuf_free(resp);
- return NULL;
- }
- /* No PD_Payload_1 */
- wpabuf_put_be16(resp, 0);
- rpos = wpabuf_put(resp, miclen);
- if (eap_gpsk_compute_mic(data->sk, data->sk_len, data->vendor,
- data->specifier, start, rpos - start, rpos) <
- 0) {
- eap_gpsk_state(data, FAILURE);
- wpabuf_free(resp);
- return NULL;
- }
- return resp;
- }
- static const u8 * eap_gpsk_validate_rand(struct eap_gpsk_data *data,
- const u8 *pos, const u8 *end)
- {
- if (end - pos < EAP_GPSK_RAND_LEN) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "RAND_Peer");
- return NULL;
- }
- if (os_memcmp(pos, data->rand_peer, EAP_GPSK_RAND_LEN) != 0) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: RAND_Peer in GPSK-2 and "
- "GPSK-3 did not match");
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: RAND_Peer in GPSK-2",
- data->rand_peer, EAP_GPSK_RAND_LEN);
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: RAND_Peer in GPSK-3",
- pos, EAP_GPSK_RAND_LEN);
- return NULL;
- }
- pos += EAP_GPSK_RAND_LEN;
- if (end - pos < EAP_GPSK_RAND_LEN) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "RAND_Server");
- return NULL;
- }
- if (os_memcmp(pos, data->rand_server, EAP_GPSK_RAND_LEN) != 0) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: RAND_Server in GPSK-1 and "
- "GPSK-3 did not match");
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: RAND_Server in GPSK-1",
- data->rand_server, EAP_GPSK_RAND_LEN);
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: RAND_Server in GPSK-3",
- pos, EAP_GPSK_RAND_LEN);
- return NULL;
- }
- pos += EAP_GPSK_RAND_LEN;
- return pos;
- }
- static const u8 * eap_gpsk_validate_id_server(struct eap_gpsk_data *data,
- const u8 *pos, const u8 *end)
- {
- size_t len;
- if (pos == NULL)
- return NULL;
- if (end - pos < (int) 2) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "length(ID_Server)");
- return NULL;
- }
- len = WPA_GET_BE16(pos);
- pos += 2;
- if (end - pos < (int) len) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "ID_Server");
- return NULL;
- }
- if (len != data->id_server_len ||
- os_memcmp(pos, data->id_server, len) != 0) {
- wpa_printf(MSG_INFO, "EAP-GPSK: ID_Server did not match with "
- "the one used in GPSK-1");
- wpa_hexdump_ascii(MSG_DEBUG, "EAP-GPSK: ID_Server in GPSK-1",
- data->id_server, data->id_server_len);
- wpa_hexdump_ascii(MSG_DEBUG, "EAP-GPSK: ID_Server in GPSK-3",
- pos, len);
- return NULL;
- }
- pos += len;
- return pos;
- }
- static const u8 * eap_gpsk_validate_csuite(struct eap_gpsk_data *data,
- const u8 *pos, const u8 *end)
- {
- int vendor, specifier;
- const struct eap_gpsk_csuite *csuite;
- if (pos == NULL)
- return NULL;
- if (end - pos < (int) sizeof(*csuite)) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "CSuite_Sel");
- return NULL;
- }
- csuite = (const struct eap_gpsk_csuite *) pos;
- vendor = WPA_GET_BE32(csuite->vendor);
- specifier = WPA_GET_BE16(csuite->specifier);
- pos += sizeof(*csuite);
- if (vendor != data->vendor || specifier != data->specifier) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: CSuite_Sel (%d:%d) does not "
- "match with the one sent in GPSK-2 (%d:%d)",
- vendor, specifier, data->vendor, data->specifier);
- return NULL;
- }
- return pos;
- }
- static const u8 * eap_gpsk_validate_pd_payload_2(struct eap_gpsk_data *data,
- const u8 *pos, const u8 *end)
- {
- u16 alen;
- if (pos == NULL)
- return NULL;
- if (end - pos < 2) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "PD_Payload_2 length");
- return NULL;
- }
- alen = WPA_GET_BE16(pos);
- pos += 2;
- if (end - pos < alen) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for "
- "%d-octet PD_Payload_2", alen);
- return NULL;
- }
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: PD_Payload_2", pos, alen);
- pos += alen;
- return pos;
- }
- static const u8 * eap_gpsk_validate_gpsk_3_mic(struct eap_gpsk_data *data,
- const u8 *payload,
- const u8 *pos, const u8 *end)
- {
- size_t miclen;
- u8 mic[EAP_GPSK_MAX_MIC_LEN];
- if (pos == NULL)
- return NULL;
- miclen = eap_gpsk_mic_len(data->vendor, data->specifier);
- if (end - pos < (int) miclen) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Message too short for MIC "
- "(left=%lu miclen=%lu)",
- (unsigned long) (end - pos),
- (unsigned long) miclen);
- return NULL;
- }
- if (eap_gpsk_compute_mic(data->sk, data->sk_len, data->vendor,
- data->specifier, payload, pos - payload, mic)
- < 0) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Failed to compute MIC");
- return NULL;
- }
- if (os_memcmp(mic, pos, miclen) != 0) {
- wpa_printf(MSG_INFO, "EAP-GPSK: Incorrect MIC in GPSK-3");
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: Received MIC", pos, miclen);
- wpa_hexdump(MSG_DEBUG, "EAP-GPSK: Computed MIC", mic, miclen);
- return NULL;
- }
- pos += miclen;
- return pos;
- }
- static struct wpabuf * eap_gpsk_process_gpsk_3(struct eap_sm *sm,
- struct eap_gpsk_data *data,
- struct eap_method_ret *ret,
- const struct wpabuf *reqData,
- const u8 *payload,
- size_t payload_len)
- {
- struct wpabuf *resp;
- const u8 *pos, *end;
- if (data->state != GPSK_3) {
- ret->ignore = TRUE;
- return NULL;
- }
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Received Request/GPSK-3");
- end = payload + payload_len;
- pos = eap_gpsk_validate_rand(data, payload, end);
- pos = eap_gpsk_validate_id_server(data, pos, end);
- pos = eap_gpsk_validate_csuite(data, pos, end);
- pos = eap_gpsk_validate_pd_payload_2(data, pos, end);
- pos = eap_gpsk_validate_gpsk_3_mic(data, payload, pos, end);
- if (pos == NULL) {
- eap_gpsk_state(data, FAILURE);
- return NULL;
- }
- if (pos != end) {
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Ignored %lu bytes of extra "
- "data in the end of GPSK-2",
- (unsigned long) (end - pos));
- }
- resp = eap_gpsk_send_gpsk_4(data, eap_get_id(reqData));
- if (resp == NULL)
- return NULL;
- eap_gpsk_state(data, SUCCESS);
- ret->methodState = METHOD_DONE;
- ret->decision = DECISION_UNCOND_SUCC;
- return resp;
- }
- static struct wpabuf * eap_gpsk_send_gpsk_4(struct eap_gpsk_data *data,
- u8 identifier)
- {
- struct wpabuf *resp;
- u8 *rpos, *start;
- size_t mlen;
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Sending Response/GPSK-4");
- mlen = eap_gpsk_mic_len(data->vendor, data->specifier);
- resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GPSK, 1 + 2 + mlen,
- EAP_CODE_RESPONSE, identifier);
- if (resp == NULL)
- return NULL;
- wpabuf_put_u8(resp, EAP_GPSK_OPCODE_GPSK_4);
- start = wpabuf_put(resp, 0);
- /* No PD_Payload_3 */
- wpabuf_put_be16(resp, 0);
- rpos = wpabuf_put(resp, mlen);
- if (eap_gpsk_compute_mic(data->sk, data->sk_len, data->vendor,
- data->specifier, start, rpos - start, rpos) <
- 0) {
- eap_gpsk_state(data, FAILURE);
- wpabuf_free(resp);
- return NULL;
- }
- return resp;
- }
- static struct wpabuf * eap_gpsk_process(struct eap_sm *sm, void *priv,
- struct eap_method_ret *ret,
- const struct wpabuf *reqData)
- {
- struct eap_gpsk_data *data = priv;
- struct wpabuf *resp;
- const u8 *pos;
- size_t len;
- pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GPSK, reqData, &len);
- if (pos == NULL || len < 1) {
- ret->ignore = TRUE;
- return NULL;
- }
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Received frame: opcode %d", *pos);
- ret->ignore = FALSE;
- ret->methodState = METHOD_MAY_CONT;
- ret->decision = DECISION_FAIL;
- ret->allowNotifications = FALSE;
- switch (*pos) {
- case EAP_GPSK_OPCODE_GPSK_1:
- resp = eap_gpsk_process_gpsk_1(sm, data, ret, reqData,
- pos + 1, len - 1);
- break;
- case EAP_GPSK_OPCODE_GPSK_3:
- resp = eap_gpsk_process_gpsk_3(sm, data, ret, reqData,
- pos + 1, len - 1);
- break;
- default:
- wpa_printf(MSG_DEBUG, "EAP-GPSK: Ignoring message with "
- "unknown opcode %d", *pos);
- ret->ignore = TRUE;
- return NULL;
- }
- return resp;
- }
- static Boolean eap_gpsk_isKeyAvailable(struct eap_sm *sm, void *priv)
- {
- struct eap_gpsk_data *data = priv;
- return data->state == SUCCESS;
- }
- static u8 * eap_gpsk_getKey(struct eap_sm *sm, void *priv, size_t *len)
- {
- struct eap_gpsk_data *data = priv;
- u8 *key;
- if (data->state != SUCCESS)
- return NULL;
- key = os_malloc(EAP_MSK_LEN);
- if (key == NULL)
- return NULL;
- os_memcpy(key, data->msk, EAP_MSK_LEN);
- *len = EAP_MSK_LEN;
- return key;
- }
- static u8 * eap_gpsk_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
- {
- struct eap_gpsk_data *data = priv;
- u8 *key;
- if (data->state != SUCCESS)
- return NULL;
- key = os_malloc(EAP_EMSK_LEN);
- if (key == NULL)
- return NULL;
- os_memcpy(key, data->emsk, EAP_EMSK_LEN);
- *len = EAP_EMSK_LEN;
- return key;
- }
- int eap_peer_gpsk_register(void)
- {
- struct eap_method *eap;
- int ret;
- eap = eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION,
- EAP_VENDOR_IETF, EAP_TYPE_GPSK, "GPSK");
- if (eap == NULL)
- return -1;
- eap->init = eap_gpsk_init;
- eap->deinit = eap_gpsk_deinit;
- eap->process = eap_gpsk_process;
- eap->isKeyAvailable = eap_gpsk_isKeyAvailable;
- eap->getKey = eap_gpsk_getKey;
- eap->get_emsk = eap_gpsk_get_emsk;
- ret = eap_peer_method_register(eap);
- if (ret)
- eap_peer_method_free(eap);
- return ret;
- }
|