2008-11-23 18:34:26 +01:00
|
|
|
/*
|
|
|
|
* Wi-Fi Protected Setup - Registrar
|
2016-01-01 10:59:20 +01:00
|
|
|
* Copyright (c) 2008-2016, Jouni Malinen <j@w1.fi>
|
2008-11-23 18:34:26 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-11-23 18:34:26 +01:00
|
|
|
*/
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
#include "utils/includes.h"
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/base64.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "utils/uuid.h"
|
|
|
|
#include "utils/list.h"
|
2009-11-29 22:04:43 +01:00
|
|
|
#include "crypto/crypto.h"
|
|
|
|
#include "crypto/sha256.h"
|
2010-11-24 00:05:20 +01:00
|
|
|
#include "crypto/random.h"
|
2009-11-29 22:04:43 +01:00
|
|
|
#include "common/ieee802_11_defs.h"
|
2008-11-23 18:34:26 +01:00
|
|
|
#include "wps_i.h"
|
|
|
|
#include "wps_dev_attr.h"
|
2009-01-29 17:47:02 +01:00
|
|
|
#include "wps_upnp.h"
|
2009-12-12 15:54:59 +01:00
|
|
|
#include "wps_upnp_i.h"
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2010-05-26 10:16:54 +02:00
|
|
|
#ifndef CONFIG_WPS_STRICT
|
2009-05-06 09:56:18 +02:00
|
|
|
#define WPS_WORKAROUNDS
|
2010-05-26 10:16:54 +02:00
|
|
|
#endif /* CONFIG_WPS_STRICT */
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2012-06-27 21:15:55 +02:00
|
|
|
#ifdef CONFIG_WPS_NFC
|
|
|
|
|
|
|
|
struct wps_nfc_pw_token {
|
|
|
|
struct dl_list list;
|
|
|
|
u8 pubkey_hash[WPS_OOB_PUBKEY_HASH_LEN];
|
2013-04-27 17:50:14 +02:00
|
|
|
unsigned int peer_pk_hash_known:1;
|
2012-06-27 21:15:55 +02:00
|
|
|
u16 pw_id;
|
2013-02-24 09:57:49 +01:00
|
|
|
u8 dev_pw[WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1];
|
2012-06-27 21:15:55 +02:00
|
|
|
size_t dev_pw_len;
|
2013-02-24 16:30:18 +01:00
|
|
|
int pk_hash_provided_oob; /* whether own PK hash was provided OOB */
|
2012-06-27 21:15:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_remove_nfc_pw_token(struct wps_nfc_pw_token *token)
|
|
|
|
{
|
|
|
|
dl_list_del(&token->list);
|
2014-07-02 00:46:45 +02:00
|
|
|
bin_clear_free(token, sizeof(*token));
|
2012-06-27 21:15:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_free_nfc_pw_tokens(struct dl_list *tokens, u16 pw_id)
|
|
|
|
{
|
|
|
|
struct wps_nfc_pw_token *token, *prev;
|
|
|
|
dl_list_for_each_safe(token, prev, tokens, struct wps_nfc_pw_token,
|
|
|
|
list) {
|
|
|
|
if (pw_id == 0 || pw_id == token->pw_id)
|
|
|
|
wps_remove_nfc_pw_token(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wps_nfc_pw_token * wps_get_nfc_pw_token(struct dl_list *tokens,
|
|
|
|
u16 pw_id)
|
|
|
|
{
|
|
|
|
struct wps_nfc_pw_token *token;
|
|
|
|
dl_list_for_each(token, tokens, struct wps_nfc_pw_token, list) {
|
|
|
|
if (pw_id == token->pw_id)
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_WPS_NFC */
|
|
|
|
|
|
|
|
#define wps_free_nfc_pw_tokens(t, p) do { } while (0)
|
|
|
|
|
|
|
|
#endif /* CONFIG_WPS_NFC */
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
struct wps_uuid_pin {
|
2009-12-19 21:26:55 +01:00
|
|
|
struct dl_list list;
|
2008-11-23 18:34:26 +01:00
|
|
|
u8 uuid[WPS_UUID_LEN];
|
2008-11-30 19:32:03 +01:00
|
|
|
int wildcard_uuid;
|
2008-11-23 18:34:26 +01:00
|
|
|
u8 *pin;
|
|
|
|
size_t pin_len;
|
2009-05-26 16:44:44 +02:00
|
|
|
#define PIN_LOCKED BIT(0)
|
|
|
|
#define PIN_EXPIRES BIT(1)
|
|
|
|
int flags;
|
2013-12-16 21:08:35 +01:00
|
|
|
struct os_reltime expiration;
|
2009-12-12 15:40:10 +01:00
|
|
|
u8 enrollee_addr[ETH_ALEN];
|
2008-11-23 18:34:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_free_pin(struct wps_uuid_pin *pin)
|
|
|
|
{
|
2014-07-02 00:46:45 +02:00
|
|
|
bin_clear_free(pin->pin, pin->pin_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
os_free(pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
static void wps_remove_pin(struct wps_uuid_pin *pin)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_del(&pin->list);
|
|
|
|
wps_free_pin(pin);
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
|
|
|
|
static void wps_free_pins(struct dl_list *pins)
|
|
|
|
{
|
|
|
|
struct wps_uuid_pin *pin, *prev;
|
|
|
|
dl_list_for_each_safe(pin, prev, pins, struct wps_uuid_pin, list)
|
|
|
|
wps_remove_pin(pin);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wps_pbc_session {
|
|
|
|
struct wps_pbc_session *next;
|
|
|
|
u8 addr[ETH_ALEN];
|
|
|
|
u8 uuid_e[WPS_UUID_LEN];
|
2013-12-16 21:08:36 +01:00
|
|
|
struct os_reltime timestamp;
|
2008-11-23 18:34:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_free_pbc_sessions(struct wps_pbc_session *pbc)
|
|
|
|
{
|
|
|
|
struct wps_pbc_session *prev;
|
|
|
|
|
|
|
|
while (pbc) {
|
|
|
|
prev = pbc;
|
|
|
|
pbc = pbc->next;
|
|
|
|
os_free(prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-07 21:09:13 +02:00
|
|
|
struct wps_registrar_device {
|
|
|
|
struct wps_registrar_device *next;
|
|
|
|
struct wps_device_data dev;
|
|
|
|
u8 uuid[WPS_UUID_LEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
struct wps_registrar {
|
|
|
|
struct wps_context *wps;
|
|
|
|
|
|
|
|
int pbc;
|
|
|
|
int selected_registrar;
|
|
|
|
|
2013-09-01 09:47:34 +02:00
|
|
|
int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
|
|
|
|
const u8 *psk, size_t psk_len);
|
2009-12-24 18:46:06 +01:00
|
|
|
int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
|
|
|
|
struct wpabuf *probe_resp_ie);
|
2008-11-23 18:34:26 +01:00
|
|
|
void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
|
|
|
|
const struct wps_device_data *dev);
|
2009-01-21 12:48:10 +01:00
|
|
|
void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
|
2012-02-29 19:42:48 +01:00
|
|
|
const u8 *uuid_e, const u8 *dev_pw,
|
|
|
|
size_t dev_pw_len);
|
2009-11-13 21:07:11 +01:00
|
|
|
void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
|
|
|
|
u16 sel_reg_config_methods);
|
2009-12-28 15:24:04 +01:00
|
|
|
void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
|
|
|
|
const u8 *pri_dev_type, u16 config_methods,
|
|
|
|
u16 dev_password_id, u8 request_type,
|
|
|
|
const char *dev_name);
|
2008-11-23 18:34:26 +01:00
|
|
|
void *cb_ctx;
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
struct dl_list pins;
|
2012-06-27 21:15:55 +02:00
|
|
|
struct dl_list nfc_pw_tokens;
|
2008-11-23 18:34:26 +01:00
|
|
|
struct wps_pbc_session *pbc_sessions;
|
2009-01-16 21:50:41 +01:00
|
|
|
|
|
|
|
int skip_cred_build;
|
|
|
|
struct wpabuf *extra_cred;
|
2009-01-21 12:48:10 +01:00
|
|
|
int disable_auto_conf;
|
2009-12-12 15:54:59 +01:00
|
|
|
int sel_reg_union;
|
2009-01-29 17:47:02 +01:00
|
|
|
int sel_reg_dev_password_id_override;
|
|
|
|
int sel_reg_config_methods_override;
|
2009-03-08 18:36:02 +01:00
|
|
|
int static_wep_only;
|
2010-09-21 00:32:29 +02:00
|
|
|
int dualband;
|
2013-09-01 09:08:30 +02:00
|
|
|
int force_per_enrollee_psk;
|
2009-09-07 21:09:13 +02:00
|
|
|
|
|
|
|
struct wps_registrar_device *devices;
|
2009-11-01 20:59:30 +01:00
|
|
|
|
|
|
|
int force_pbc_overlap;
|
2009-12-12 15:40:10 +01:00
|
|
|
|
|
|
|
u8 authorized_macs[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
|
|
|
|
u8 authorized_macs_union[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
|
2011-02-07 17:28:36 +01:00
|
|
|
|
|
|
|
u8 p2p_dev_addr[ETH_ALEN];
|
2012-11-15 18:59:04 +01:00
|
|
|
|
|
|
|
u8 pbc_ignore_uuid[WPS_UUID_LEN];
|
2013-12-16 21:08:37 +01:00
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
struct os_reltime pbc_ignore_start;
|
|
|
|
#endif /* WPS_WORKAROUNDS */
|
2008-11-23 18:34:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_set_ie(struct wps_registrar *reg);
|
|
|
|
static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx);
|
2009-01-29 17:47:02 +01:00
|
|
|
static void wps_registrar_set_selected_timeout(void *eloop_ctx,
|
|
|
|
void *timeout_ctx);
|
2012-10-10 16:38:06 +02:00
|
|
|
static void wps_registrar_remove_pin(struct wps_registrar *reg,
|
|
|
|
struct wps_uuid_pin *pin);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
|
2009-12-12 15:40:10 +01:00
|
|
|
static void wps_registrar_add_authorized_mac(struct wps_registrar *reg,
|
|
|
|
const u8 *addr)
|
|
|
|
{
|
|
|
|
int i;
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add authorized MAC " MACSTR,
|
|
|
|
MAC2STR(addr));
|
2009-12-12 15:40:10 +01:00
|
|
|
for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++)
|
2010-07-22 18:37:22 +02:00
|
|
|
if (os_memcmp(reg->authorized_macs[i], addr, ETH_ALEN) == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Authorized MAC was "
|
|
|
|
"already in the list");
|
2009-12-12 15:40:10 +01:00
|
|
|
return; /* already in list */
|
2010-07-22 18:37:22 +02:00
|
|
|
}
|
2009-12-12 15:40:10 +01:00
|
|
|
for (i = WPS_MAX_AUTHORIZED_MACS - 1; i > 0; i--)
|
|
|
|
os_memcpy(reg->authorized_macs[i], reg->authorized_macs[i - 1],
|
|
|
|
ETH_ALEN);
|
|
|
|
os_memcpy(reg->authorized_macs[0], addr, ETH_ALEN);
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs",
|
|
|
|
(u8 *) reg->authorized_macs, sizeof(reg->authorized_macs));
|
2009-12-12 15:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_registrar_remove_authorized_mac(struct wps_registrar *reg,
|
|
|
|
const u8 *addr)
|
|
|
|
{
|
|
|
|
int i;
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Remove authorized MAC " MACSTR,
|
|
|
|
MAC2STR(addr));
|
2009-12-12 15:40:10 +01:00
|
|
|
for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++) {
|
|
|
|
if (os_memcmp(reg->authorized_macs, addr, ETH_ALEN) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2010-07-22 18:37:22 +02:00
|
|
|
if (i == WPS_MAX_AUTHORIZED_MACS) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Authorized MAC was not in the "
|
|
|
|
"list");
|
2009-12-12 15:40:10 +01:00
|
|
|
return; /* not in the list */
|
2010-07-22 18:37:22 +02:00
|
|
|
}
|
2009-12-12 15:40:10 +01:00
|
|
|
for (; i + 1 < WPS_MAX_AUTHORIZED_MACS; i++)
|
|
|
|
os_memcpy(reg->authorized_macs[i], reg->authorized_macs[i + 1],
|
|
|
|
ETH_ALEN);
|
|
|
|
os_memset(reg->authorized_macs[WPS_MAX_AUTHORIZED_MACS - 1], 0,
|
|
|
|
ETH_ALEN);
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs",
|
|
|
|
(u8 *) reg->authorized_macs, sizeof(reg->authorized_macs));
|
2009-12-12 15:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-07 21:09:13 +02:00
|
|
|
static void wps_free_devices(struct wps_registrar_device *dev)
|
|
|
|
{
|
|
|
|
struct wps_registrar_device *prev;
|
|
|
|
|
|
|
|
while (dev) {
|
|
|
|
prev = dev;
|
|
|
|
dev = dev->next;
|
|
|
|
wps_device_data_free(&prev->dev);
|
|
|
|
os_free(prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wps_registrar_device * wps_device_get(struct wps_registrar *reg,
|
|
|
|
const u8 *addr)
|
|
|
|
{
|
|
|
|
struct wps_registrar_device *dev;
|
|
|
|
|
|
|
|
for (dev = reg->devices; dev; dev = dev->next) {
|
|
|
|
if (os_memcmp(dev->dev.mac_addr, addr, ETH_ALEN) == 0)
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_device_clone_data(struct wps_device_data *dst,
|
|
|
|
struct wps_device_data *src)
|
|
|
|
{
|
|
|
|
os_memcpy(dst->mac_addr, src->mac_addr, ETH_ALEN);
|
2009-11-26 10:39:29 +01:00
|
|
|
os_memcpy(dst->pri_dev_type, src->pri_dev_type, WPS_DEV_TYPE_LEN);
|
2009-09-07 21:09:13 +02:00
|
|
|
|
|
|
|
#define WPS_STRDUP(n) \
|
|
|
|
os_free(dst->n); \
|
|
|
|
dst->n = src->n ? os_strdup(src->n) : NULL
|
|
|
|
|
|
|
|
WPS_STRDUP(device_name);
|
|
|
|
WPS_STRDUP(manufacturer);
|
|
|
|
WPS_STRDUP(model_name);
|
|
|
|
WPS_STRDUP(model_number);
|
|
|
|
WPS_STRDUP(serial_number);
|
|
|
|
#undef WPS_STRDUP
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wps_device_store(struct wps_registrar *reg,
|
|
|
|
struct wps_device_data *dev, const u8 *uuid)
|
|
|
|
{
|
|
|
|
struct wps_registrar_device *d;
|
|
|
|
|
|
|
|
d = wps_device_get(reg, dev->mac_addr);
|
|
|
|
if (d == NULL) {
|
|
|
|
d = os_zalloc(sizeof(*d));
|
|
|
|
if (d == NULL)
|
|
|
|
return -1;
|
|
|
|
d->next = reg->devices;
|
|
|
|
reg->devices = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
wps_device_clone_data(&d->dev, dev);
|
|
|
|
os_memcpy(d->uuid, uuid, WPS_UUID_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static void wps_registrar_add_pbc_session(struct wps_registrar *reg,
|
|
|
|
const u8 *addr, const u8 *uuid_e)
|
|
|
|
{
|
|
|
|
struct wps_pbc_session *pbc, *prev = NULL;
|
2013-12-16 21:08:36 +01:00
|
|
|
struct os_reltime now;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2013-12-16 21:08:36 +01:00
|
|
|
os_get_reltime(&now);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
pbc = reg->pbc_sessions;
|
|
|
|
while (pbc) {
|
|
|
|
if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
|
|
|
|
os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
|
|
|
|
if (prev)
|
|
|
|
prev->next = pbc->next;
|
|
|
|
else
|
|
|
|
reg->pbc_sessions = pbc->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = pbc;
|
|
|
|
pbc = pbc->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pbc) {
|
|
|
|
pbc = os_zalloc(sizeof(*pbc));
|
|
|
|
if (pbc == NULL)
|
|
|
|
return;
|
|
|
|
os_memcpy(pbc->addr, addr, ETH_ALEN);
|
|
|
|
if (uuid_e)
|
|
|
|
os_memcpy(pbc->uuid_e, uuid_e, WPS_UUID_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
pbc->next = reg->pbc_sessions;
|
|
|
|
reg->pbc_sessions = pbc;
|
|
|
|
pbc->timestamp = now;
|
|
|
|
|
|
|
|
/* remove entries that have timed out */
|
|
|
|
prev = pbc;
|
|
|
|
pbc = pbc->next;
|
|
|
|
|
|
|
|
while (pbc) {
|
2013-12-16 21:08:36 +01:00
|
|
|
if (os_reltime_expired(&now, &pbc->timestamp,
|
|
|
|
WPS_PBC_WALK_TIME)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
prev->next = NULL;
|
|
|
|
wps_free_pbc_sessions(pbc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = pbc;
|
|
|
|
pbc = pbc->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_registrar_remove_pbc_session(struct wps_registrar *reg,
|
2011-12-11 11:03:18 +01:00
|
|
|
const u8 *uuid_e,
|
|
|
|
const u8 *p2p_dev_addr)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2011-03-17 17:03:20 +01:00
|
|
|
struct wps_pbc_session *pbc, *prev = NULL, *tmp;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
pbc = reg->pbc_sessions;
|
|
|
|
while (pbc) {
|
2011-12-11 11:03:18 +01:00
|
|
|
if (os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0 ||
|
|
|
|
(p2p_dev_addr && !is_zero_ether_addr(reg->p2p_dev_addr) &&
|
|
|
|
os_memcmp(reg->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
|
|
|
|
0)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
if (prev)
|
|
|
|
prev->next = pbc->next;
|
|
|
|
else
|
|
|
|
reg->pbc_sessions = pbc->next;
|
2011-03-17 17:03:20 +01:00
|
|
|
tmp = pbc;
|
|
|
|
pbc = pbc->next;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Removing PBC session for "
|
|
|
|
"addr=" MACSTR, MAC2STR(tmp->addr));
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Removed UUID-E",
|
|
|
|
tmp->uuid_e, WPS_UUID_LEN);
|
|
|
|
os_free(tmp);
|
|
|
|
continue;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
prev = pbc;
|
|
|
|
pbc = pbc->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 04:19:53 +02:00
|
|
|
int wps_registrar_pbc_overlap(struct wps_registrar *reg,
|
|
|
|
const u8 *addr, const u8 *uuid_e)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
struct wps_pbc_session *pbc;
|
2011-03-10 17:33:53 +01:00
|
|
|
struct wps_pbc_session *first = NULL;
|
2013-12-16 21:08:36 +01:00
|
|
|
struct os_reltime now;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2013-12-16 21:08:36 +01:00
|
|
|
os_get_reltime(&now);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2011-03-17 17:04:56 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Checking active PBC sessions for overlap");
|
|
|
|
|
|
|
|
if (uuid_e) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add one for the requested UUID");
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Requested UUID",
|
|
|
|
uuid_e, WPS_UUID_LEN);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
for (pbc = reg->pbc_sessions; pbc; pbc = pbc->next) {
|
2011-03-17 17:04:56 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Consider PBC session with " MACSTR,
|
|
|
|
MAC2STR(pbc->addr));
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID-E",
|
|
|
|
pbc->uuid_e, WPS_UUID_LEN);
|
2013-12-16 21:08:36 +01:00
|
|
|
if (os_reltime_expired(&now, &pbc->timestamp,
|
|
|
|
WPS_PBC_WALK_TIME)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC walk time has expired");
|
2008-11-23 18:34:26 +01:00
|
|
|
break;
|
2011-03-17 17:04:56 +01:00
|
|
|
}
|
2011-03-10 17:33:53 +01:00
|
|
|
if (first &&
|
2011-03-17 17:04:56 +01:00
|
|
|
os_memcmp(pbc->uuid_e, first->uuid_e, WPS_UUID_LEN) == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Same Enrollee");
|
2011-03-10 17:33:53 +01:00
|
|
|
continue; /* same Enrollee */
|
2011-03-17 17:04:56 +01:00
|
|
|
}
|
2011-03-10 17:33:53 +01:00
|
|
|
if (uuid_e == NULL ||
|
2011-03-17 17:04:56 +01:00
|
|
|
os_memcmp(uuid_e, pbc->uuid_e, WPS_UUID_LEN)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: New Enrollee");
|
2008-11-23 18:34:26 +01:00
|
|
|
count++;
|
2011-03-17 17:04:56 +01:00
|
|
|
}
|
2011-03-10 17:33:53 +01:00
|
|
|
if (first == NULL)
|
|
|
|
first = pbc;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:04:56 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: %u active PBC session(s) found", count);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
return count > 1 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
|
|
|
|
wps->wps_state);
|
|
|
|
wpabuf_put_be16(msg, ATTR_WPS_STATE);
|
|
|
|
wpabuf_put_be16(msg, 1);
|
|
|
|
wpabuf_put_u8(msg, wps->wps_state);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-06 20:39:32 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
static void wps_registrar_free_pending_m2(struct wps_context *wps)
|
|
|
|
{
|
|
|
|
struct upnp_pending_message *p, *p2, *prev = NULL;
|
|
|
|
p = wps->upnp_msgs;
|
|
|
|
while (p) {
|
|
|
|
if (p->type == WPS_M2 || p->type == WPS_M2D) {
|
|
|
|
if (prev == NULL)
|
|
|
|
wps->upnp_msgs = p->next;
|
|
|
|
else
|
|
|
|
prev->next = p->next;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS UPnP: Drop pending M2/M2D");
|
|
|
|
p2 = p;
|
|
|
|
p = p->next;
|
|
|
|
wpabuf_free(p2->msg);
|
|
|
|
os_free(p2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prev = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static int wps_build_ap_setup_locked(struct wps_context *wps,
|
|
|
|
struct wpabuf *msg)
|
|
|
|
{
|
2010-11-17 15:48:39 +01:00
|
|
|
if (wps->ap_setup_locked && wps->ap_setup_locked != 2) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * AP Setup Locked");
|
|
|
|
wpabuf_put_be16(msg, ATTR_AP_SETUP_LOCKED);
|
|
|
|
wpabuf_put_be16(msg, 1);
|
|
|
|
wpabuf_put_u8(msg, 1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_selected_registrar(struct wps_registrar *reg,
|
|
|
|
struct wpabuf *msg)
|
|
|
|
{
|
2009-12-12 15:54:59 +01:00
|
|
|
if (!reg->sel_reg_union)
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
|
|
|
|
wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR);
|
|
|
|
wpabuf_put_be16(msg, 1);
|
|
|
|
wpabuf_put_u8(msg, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_sel_reg_dev_password_id(struct wps_registrar *reg,
|
|
|
|
struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
|
2009-12-12 15:54:59 +01:00
|
|
|
if (!reg->sel_reg_union)
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
2009-01-29 17:47:02 +01:00
|
|
|
if (reg->sel_reg_dev_password_id_override >= 0)
|
|
|
|
id = reg->sel_reg_dev_password_id_override;
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Device Password ID (%d)", id);
|
|
|
|
wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
|
|
|
|
wpabuf_put_be16(msg, 2);
|
|
|
|
wpabuf_put_be16(msg, id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-21 00:32:29 +02:00
|
|
|
static int wps_build_sel_pbc_reg_uuid_e(struct wps_registrar *reg,
|
|
|
|
struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
|
|
|
|
if (!reg->sel_reg_union)
|
|
|
|
return 0;
|
|
|
|
if (reg->sel_reg_dev_password_id_override >= 0)
|
|
|
|
id = reg->sel_reg_dev_password_id_override;
|
|
|
|
if (id != DEV_PW_PUSHBUTTON || !reg->dualband)
|
|
|
|
return 0;
|
|
|
|
return wps_build_uuid_e(msg, reg->wps->uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-19 07:53:15 +02:00
|
|
|
static void wps_set_pushbutton(u16 *methods, u16 conf_methods)
|
|
|
|
{
|
|
|
|
*methods |= WPS_CONFIG_PUSHBUTTON;
|
2012-06-25 11:20:37 +02:00
|
|
|
if ((conf_methods & WPS_CONFIG_VIRT_PUSHBUTTON) ==
|
|
|
|
WPS_CONFIG_VIRT_PUSHBUTTON)
|
2010-07-19 07:53:15 +02:00
|
|
|
*methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
|
2012-06-25 11:20:37 +02:00
|
|
|
if ((conf_methods & WPS_CONFIG_PHY_PUSHBUTTON) ==
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON)
|
2010-07-19 07:53:15 +02:00
|
|
|
*methods |= WPS_CONFIG_PHY_PUSHBUTTON;
|
2012-06-25 11:20:37 +02:00
|
|
|
if ((*methods & WPS_CONFIG_VIRT_PUSHBUTTON) !=
|
|
|
|
WPS_CONFIG_VIRT_PUSHBUTTON &&
|
|
|
|
(*methods & WPS_CONFIG_PHY_PUSHBUTTON) !=
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON) {
|
2010-07-19 07:53:15 +02:00
|
|
|
/*
|
|
|
|
* Required to include virtual/physical flag, but we were not
|
|
|
|
* configured with push button type, so have to default to one
|
|
|
|
* of them.
|
|
|
|
*/
|
|
|
|
*methods |= WPS_CONFIG_PHY_PUSHBUTTON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static int wps_build_sel_reg_config_methods(struct wps_registrar *reg,
|
|
|
|
struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
u16 methods;
|
2009-12-12 15:54:59 +01:00
|
|
|
if (!reg->sel_reg_union)
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
2010-06-18 03:35:18 +02:00
|
|
|
methods = reg->wps->config_methods;
|
|
|
|
methods &= ~WPS_CONFIG_PUSHBUTTON;
|
|
|
|
methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON);
|
2010-07-19 07:53:15 +02:00
|
|
|
if (reg->pbc)
|
|
|
|
wps_set_pushbutton(&methods, reg->wps->config_methods);
|
2009-01-29 17:47:02 +01:00
|
|
|
if (reg->sel_reg_config_methods_override >= 0)
|
|
|
|
methods = reg->sel_reg_config_methods_override;
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar Config Methods (%x)",
|
|
|
|
methods);
|
|
|
|
wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR_CONFIG_METHODS);
|
|
|
|
wpabuf_put_be16(msg, 2);
|
|
|
|
wpabuf_put_be16(msg, methods);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_probe_config_methods(struct wps_registrar *reg,
|
|
|
|
struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
u16 methods;
|
2010-03-13 12:39:22 +01:00
|
|
|
/*
|
|
|
|
* These are the methods that the AP supports as an Enrollee for adding
|
|
|
|
* external Registrars.
|
|
|
|
*/
|
2010-06-18 03:35:18 +02:00
|
|
|
methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
|
|
|
|
methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
|
|
|
|
wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
|
|
|
|
wpabuf_put_be16(msg, 2);
|
|
|
|
wpabuf_put_be16(msg, methods);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 11:44:02 +01:00
|
|
|
static int wps_build_config_methods_r(struct wps_registrar *reg,
|
|
|
|
struct wpabuf *msg)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2011-08-11 16:03:57 +02:00
|
|
|
return wps_build_config_methods(msg, reg->wps->config_methods);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 19:23:20 +02:00
|
|
|
const u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count)
|
2009-12-12 15:40:10 +01:00
|
|
|
{
|
2010-07-29 19:23:20 +02:00
|
|
|
*count = 0;
|
2009-12-12 15:40:10 +01:00
|
|
|
|
2010-07-29 19:23:20 +02:00
|
|
|
while (*count < WPS_MAX_AUTHORIZED_MACS) {
|
|
|
|
if (is_zero_ether_addr(reg->authorized_macs_union[*count]))
|
2009-12-12 15:40:10 +01:00
|
|
|
break;
|
2010-07-29 19:23:20 +02:00
|
|
|
(*count)++;
|
2009-12-12 15:40:10 +01:00
|
|
|
}
|
|
|
|
|
2010-07-29 19:23:20 +02:00
|
|
|
return (const u8 *) reg->authorized_macs_union;
|
2009-12-12 15:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-03 18:50:49 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_init - Initialize WPS Registrar data
|
|
|
|
* @wps: Pointer to longterm WPS context
|
|
|
|
* @cfg: Registrar configuration
|
|
|
|
* Returns: Pointer to allocated Registrar data or %NULL on failure
|
|
|
|
*
|
|
|
|
* This function is used to initialize WPS Registrar functionality. It can be
|
|
|
|
* used for a single Registrar run (e.g., when run in a supplicant) or multiple
|
|
|
|
* runs (e.g., when run as an internal Registrar in an AP). Caller is
|
|
|
|
* responsible for freeing the returned data with wps_registrar_deinit() when
|
|
|
|
* Registrar functionality is not needed anymore.
|
|
|
|
*/
|
2008-11-23 18:34:26 +01:00
|
|
|
struct wps_registrar *
|
|
|
|
wps_registrar_init(struct wps_context *wps,
|
|
|
|
const struct wps_registrar_config *cfg)
|
|
|
|
{
|
|
|
|
struct wps_registrar *reg = os_zalloc(sizeof(*reg));
|
|
|
|
if (reg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_init(®->pins);
|
2012-06-27 21:15:55 +02:00
|
|
|
dl_list_init(®->nfc_pw_tokens);
|
2008-11-23 18:34:26 +01:00
|
|
|
reg->wps = wps;
|
|
|
|
reg->new_psk_cb = cfg->new_psk_cb;
|
|
|
|
reg->set_ie_cb = cfg->set_ie_cb;
|
|
|
|
reg->pin_needed_cb = cfg->pin_needed_cb;
|
2009-01-21 12:48:10 +01:00
|
|
|
reg->reg_success_cb = cfg->reg_success_cb;
|
2009-11-13 21:07:11 +01:00
|
|
|
reg->set_sel_reg_cb = cfg->set_sel_reg_cb;
|
2009-12-28 15:24:04 +01:00
|
|
|
reg->enrollee_seen_cb = cfg->enrollee_seen_cb;
|
2008-11-23 18:34:26 +01:00
|
|
|
reg->cb_ctx = cfg->cb_ctx;
|
2009-01-16 21:50:41 +01:00
|
|
|
reg->skip_cred_build = cfg->skip_cred_build;
|
|
|
|
if (cfg->extra_cred) {
|
|
|
|
reg->extra_cred = wpabuf_alloc_copy(cfg->extra_cred,
|
|
|
|
cfg->extra_cred_len);
|
|
|
|
if (reg->extra_cred == NULL) {
|
|
|
|
os_free(reg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-01-21 12:48:10 +01:00
|
|
|
reg->disable_auto_conf = cfg->disable_auto_conf;
|
2009-01-29 17:47:02 +01:00
|
|
|
reg->sel_reg_dev_password_id_override = -1;
|
2009-02-09 18:50:52 +01:00
|
|
|
reg->sel_reg_config_methods_override = -1;
|
2009-03-08 18:36:02 +01:00
|
|
|
reg->static_wep_only = cfg->static_wep_only;
|
2010-09-21 00:32:29 +02:00
|
|
|
reg->dualband = cfg->dualband;
|
2013-09-01 09:08:30 +02:00
|
|
|
reg->force_per_enrollee_psk = cfg->force_per_enrollee_psk;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if (wps_set_ie(reg)) {
|
|
|
|
wps_registrar_deinit(reg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-21 16:32:35 +01:00
|
|
|
void wps_registrar_flush(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
if (reg == NULL)
|
|
|
|
return;
|
|
|
|
wps_free_pins(®->pins);
|
|
|
|
wps_free_nfc_pw_tokens(®->nfc_pw_tokens, 0);
|
|
|
|
wps_free_pbc_sessions(reg->pbc_sessions);
|
|
|
|
reg->pbc_sessions = NULL;
|
|
|
|
wps_free_devices(reg->devices);
|
|
|
|
reg->devices = NULL;
|
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
reg->pbc_ignore_start.sec = 0;
|
|
|
|
#endif /* WPS_WORKAROUNDS */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-03 18:50:49 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_deinit - Deinitialize WPS Registrar data
|
2009-01-04 12:43:05 +01:00
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
2009-01-03 18:50:49 +01:00
|
|
|
*/
|
2008-11-23 18:34:26 +01:00
|
|
|
void wps_registrar_deinit(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
if (reg == NULL)
|
|
|
|
return;
|
|
|
|
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
|
2009-01-29 17:47:02 +01:00
|
|
|
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
|
2014-12-21 16:32:35 +01:00
|
|
|
wps_registrar_flush(reg);
|
2009-01-16 21:50:41 +01:00
|
|
|
wpabuf_free(reg->extra_cred);
|
2008-11-23 18:34:26 +01:00
|
|
|
os_free(reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-10 16:38:06 +02:00
|
|
|
static void wps_registrar_invalidate_unused(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
struct wps_uuid_pin *pin;
|
|
|
|
|
|
|
|
dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
|
|
|
|
if (pin->wildcard_uuid == 1 && !(pin->flags & PIN_LOCKED)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalidate previously "
|
|
|
|
"configured wildcard PIN");
|
|
|
|
wps_registrar_remove_pin(reg, pin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 12:43:05 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_add_pin - Configure a new PIN for Registrar
|
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
2009-12-12 15:40:10 +01:00
|
|
|
* @addr: Enrollee MAC address or %NULL if not known
|
2009-01-04 12:43:05 +01:00
|
|
|
* @uuid: UUID-E or %NULL for wildcard (any UUID)
|
|
|
|
* @pin: PIN (Device Password)
|
|
|
|
* @pin_len: Length of pin in octets
|
2009-05-26 16:44:44 +02:00
|
|
|
* @timeout: Time (in seconds) when the PIN will be invalidated; 0 = no timeout
|
2009-01-04 12:43:05 +01:00
|
|
|
* Returns: 0 on success, -1 on failure
|
|
|
|
*/
|
2009-12-12 15:40:10 +01:00
|
|
|
int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
|
|
|
|
const u8 *uuid, const u8 *pin, size_t pin_len,
|
|
|
|
int timeout)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
struct wps_uuid_pin *p;
|
|
|
|
|
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
return -1;
|
2009-12-12 15:40:10 +01:00
|
|
|
if (addr)
|
|
|
|
os_memcpy(p->enrollee_addr, addr, ETH_ALEN);
|
2008-11-30 19:32:03 +01:00
|
|
|
if (uuid == NULL)
|
|
|
|
p->wildcard_uuid = 1;
|
|
|
|
else
|
|
|
|
os_memcpy(p->uuid, uuid, WPS_UUID_LEN);
|
2008-11-23 18:34:26 +01:00
|
|
|
p->pin = os_malloc(pin_len);
|
|
|
|
if (p->pin == NULL) {
|
|
|
|
os_free(p);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
os_memcpy(p->pin, pin, pin_len);
|
|
|
|
p->pin_len = pin_len;
|
|
|
|
|
2009-05-26 16:44:44 +02:00
|
|
|
if (timeout) {
|
|
|
|
p->flags |= PIN_EXPIRES;
|
2013-12-16 21:08:35 +01:00
|
|
|
os_get_reltime(&p->expiration);
|
2009-05-26 16:44:44 +02:00
|
|
|
p->expiration.sec += timeout;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:38:06 +02:00
|
|
|
if (p->wildcard_uuid)
|
|
|
|
wps_registrar_invalidate_unused(reg);
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_add(®->pins, &p->list);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-05-26 16:44:44 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: A new PIN configured (timeout=%d)",
|
|
|
|
timeout);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
|
|
|
|
wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
|
|
|
|
reg->selected_registrar = 1;
|
|
|
|
reg->pbc = 0;
|
2009-12-12 15:40:10 +01:00
|
|
|
if (addr)
|
|
|
|
wps_registrar_add_authorized_mac(reg, addr);
|
2010-07-18 03:12:00 +02:00
|
|
|
else
|
|
|
|
wps_registrar_add_authorized_mac(
|
|
|
|
reg, (u8 *) "\xff\xff\xff\xff\xff\xff");
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-11-01 21:19:02 +01:00
|
|
|
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
|
|
|
|
eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
|
|
|
|
wps_registrar_set_selected_timeout,
|
|
|
|
reg, NULL);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-06 19:51:06 +02:00
|
|
|
static void wps_registrar_remove_pin(struct wps_registrar *reg,
|
|
|
|
struct wps_uuid_pin *pin)
|
|
|
|
{
|
|
|
|
u8 *addr;
|
|
|
|
u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
|
|
|
if (is_zero_ether_addr(pin->enrollee_addr))
|
|
|
|
addr = bcast;
|
|
|
|
else
|
|
|
|
addr = pin->enrollee_addr;
|
|
|
|
wps_registrar_remove_authorized_mac(reg, addr);
|
|
|
|
wps_remove_pin(pin);
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2010-09-06 19:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-26 16:44:44 +02:00
|
|
|
static void wps_registrar_expire_pins(struct wps_registrar *reg)
|
|
|
|
{
|
2009-12-19 21:26:55 +01:00
|
|
|
struct wps_uuid_pin *pin, *prev;
|
2013-12-16 21:08:35 +01:00
|
|
|
struct os_reltime now;
|
2009-05-26 16:44:44 +02:00
|
|
|
|
2013-12-16 21:08:35 +01:00
|
|
|
os_get_reltime(&now);
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
|
|
|
|
{
|
2009-05-26 16:44:44 +02:00
|
|
|
if ((pin->flags & PIN_EXPIRES) &&
|
2013-12-16 21:08:35 +01:00
|
|
|
os_reltime_before(&pin->expiration, &now)) {
|
2009-05-26 16:44:44 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID",
|
2009-12-19 21:26:55 +01:00
|
|
|
pin->uuid, WPS_UUID_LEN);
|
2010-09-06 19:51:06 +02:00
|
|
|
wps_registrar_remove_pin(reg, pin);
|
2009-05-26 16:44:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-06 19:51:06 +02:00
|
|
|
/**
|
|
|
|
* wps_registrar_invalidate_wildcard_pin - Invalidate a wildcard PIN
|
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
2012-02-29 19:42:48 +01:00
|
|
|
* @dev_pw: PIN to search for or %NULL to match any
|
|
|
|
* @dev_pw_len: Length of dev_pw in octets
|
2010-09-06 19:51:06 +02:00
|
|
|
* Returns: 0 on success, -1 if not wildcard PIN is enabled
|
|
|
|
*/
|
2012-02-29 19:42:48 +01:00
|
|
|
static int wps_registrar_invalidate_wildcard_pin(struct wps_registrar *reg,
|
|
|
|
const u8 *dev_pw,
|
|
|
|
size_t dev_pw_len)
|
2010-09-06 19:51:06 +02:00
|
|
|
{
|
|
|
|
struct wps_uuid_pin *pin, *prev;
|
|
|
|
|
|
|
|
dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
|
|
|
|
{
|
2012-02-29 19:42:48 +01:00
|
|
|
if (dev_pw && pin->pin &&
|
|
|
|
(dev_pw_len != pin->pin_len ||
|
2014-06-29 18:38:17 +02:00
|
|
|
os_memcmp_const(dev_pw, pin->pin, dev_pw_len) != 0))
|
2012-02-29 19:42:48 +01:00
|
|
|
continue; /* different PIN */
|
2010-09-06 19:51:06 +02:00
|
|
|
if (pin->wildcard_uuid) {
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
|
|
|
|
pin->uuid, WPS_UUID_LEN);
|
|
|
|
wps_registrar_remove_pin(reg, pin);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 12:43:05 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_invalidate_pin - Invalidate a PIN for a specific UUID-E
|
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
|
|
|
* @uuid: UUID-E
|
|
|
|
* Returns: 0 on success, -1 on failure (e.g., PIN not found)
|
|
|
|
*/
|
2008-11-23 18:34:26 +01:00
|
|
|
int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid)
|
|
|
|
{
|
|
|
|
struct wps_uuid_pin *pin, *prev;
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
|
|
|
|
{
|
2008-11-23 18:34:26 +01:00
|
|
|
if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
|
|
|
|
pin->uuid, WPS_UUID_LEN);
|
2010-09-06 19:51:06 +02:00
|
|
|
wps_registrar_remove_pin(reg, pin);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
|
|
|
|
const u8 *uuid, size_t *pin_len)
|
|
|
|
{
|
2009-12-19 21:26:55 +01:00
|
|
|
struct wps_uuid_pin *pin, *found = NULL;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-05-26 16:44:44 +02:00
|
|
|
wps_registrar_expire_pins(reg);
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
|
2008-11-30 19:32:03 +01:00
|
|
|
if (!pin->wildcard_uuid &&
|
2009-12-19 21:26:55 +01:00
|
|
|
os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
|
|
|
|
found = pin;
|
2008-11-30 19:32:03 +01:00
|
|
|
break;
|
2009-12-19 21:26:55 +01:00
|
|
|
}
|
2008-11-30 19:32:03 +01:00
|
|
|
}
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
if (!found) {
|
2008-11-30 19:32:03 +01:00
|
|
|
/* Check for wildcard UUIDs since none of the UUID-specific
|
|
|
|
* PINs matched */
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
|
2012-02-08 11:37:57 +01:00
|
|
|
if (pin->wildcard_uuid == 1 ||
|
|
|
|
pin->wildcard_uuid == 2) {
|
2008-11-30 19:32:03 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
|
|
|
|
"PIN. Assigned it for this UUID-E");
|
2012-02-08 11:37:57 +01:00
|
|
|
pin->wildcard_uuid++;
|
2008-11-30 19:32:03 +01:00
|
|
|
os_memcpy(pin->uuid, uuid, WPS_UUID_LEN);
|
2009-12-19 21:26:55 +01:00
|
|
|
found = pin;
|
2008-11-30 19:32:03 +01:00
|
|
|
break;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
if (!found)
|
2008-11-30 19:32:03 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the PIN to avoid attacks based on concurrent re-use of the PIN
|
|
|
|
* that could otherwise avoid PIN invalidations.
|
|
|
|
*/
|
2009-12-19 21:26:55 +01:00
|
|
|
if (found->flags & PIN_LOCKED) {
|
2008-11-30 19:32:03 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
|
|
|
|
"allow concurrent re-use");
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-19 21:26:55 +01:00
|
|
|
*pin_len = found->pin_len;
|
|
|
|
found->flags |= PIN_LOCKED;
|
|
|
|
return found->pin;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 12:43:05 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_unlock_pin - Unlock a PIN for a specific UUID-E
|
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
|
|
|
* @uuid: UUID-E
|
|
|
|
* Returns: 0 on success, -1 on failure
|
|
|
|
*
|
|
|
|
* PINs are locked to enforce only one concurrent use. This function unlocks a
|
|
|
|
* PIN to allow it to be used again. If the specified PIN was configured using
|
|
|
|
* a wildcard UUID, it will be removed instead of allowing multiple uses.
|
|
|
|
*/
|
2008-11-23 18:34:26 +01:00
|
|
|
int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid)
|
|
|
|
{
|
|
|
|
struct wps_uuid_pin *pin;
|
|
|
|
|
2009-12-19 21:26:55 +01:00
|
|
|
dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
|
2008-11-23 18:34:26 +01:00
|
|
|
if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
|
2012-02-08 11:37:57 +01:00
|
|
|
if (pin->wildcard_uuid == 3) {
|
2008-11-30 19:32:03 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
|
|
|
|
"wildcard PIN");
|
|
|
|
return wps_registrar_invalidate_pin(reg, uuid);
|
|
|
|
}
|
2009-05-26 16:44:44 +02:00
|
|
|
pin->flags &= ~PIN_LOCKED;
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 12:43:05 +01:00
|
|
|
static void wps_registrar_stop_pbc(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
reg->selected_registrar = 0;
|
|
|
|
reg->pbc = 0;
|
2011-02-07 17:28:36 +01:00
|
|
|
os_memset(reg->p2p_dev_addr, 0, ETH_ALEN);
|
2010-11-09 10:24:06 +01:00
|
|
|
wps_registrar_remove_authorized_mac(reg,
|
|
|
|
(u8 *) "\xff\xff\xff\xff\xff\xff");
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-01-04 12:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wps_registrar *reg = eloop_ctx;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
|
2009-11-01 20:26:13 +01:00
|
|
|
wps_pbc_timeout_event(reg->wps);
|
2009-01-04 12:43:05 +01:00
|
|
|
wps_registrar_stop_pbc(reg);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 12:43:05 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_button_pushed - Notify Registrar that AP button was pushed
|
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
2011-02-07 17:28:36 +01:00
|
|
|
* @p2p_dev_addr: Limit allowed PBC devices to the specified P2P device, %NULL
|
|
|
|
* indicates no such filtering
|
2011-03-10 17:59:51 +01:00
|
|
|
* Returns: 0 on success, -1 on failure, -2 on session overlap
|
2009-01-04 12:43:05 +01:00
|
|
|
*
|
|
|
|
* This function is called on an AP when a push button is pushed to activate
|
|
|
|
* PBC mode. The PBC mode will be stopped after walk time (2 minutes) timeout
|
2011-03-10 17:59:51 +01:00
|
|
|
* or when a PBC registration is completed. If more than one Enrollee in active
|
|
|
|
* PBC mode has been detected during the monitor time (previous 2 minutes), the
|
2011-09-21 23:43:59 +02:00
|
|
|
* PBC mode is not activated and -2 is returned to indicate session overlap.
|
|
|
|
* This is skipped if a specific Enrollee is selected.
|
2009-01-04 12:43:05 +01:00
|
|
|
*/
|
2011-02-07 17:28:36 +01:00
|
|
|
int wps_registrar_button_pushed(struct wps_registrar *reg,
|
|
|
|
const u8 *p2p_dev_addr)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2011-03-10 17:51:00 +01:00
|
|
|
if (p2p_dev_addr == NULL &&
|
|
|
|
wps_registrar_pbc_overlap(reg, NULL, NULL)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
|
|
|
|
"mode");
|
2009-11-01 20:26:13 +01:00
|
|
|
wps_pbc_overlap_event(reg->wps);
|
2011-03-10 17:59:51 +01:00
|
|
|
return -2;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
|
2009-11-01 20:59:30 +01:00
|
|
|
reg->force_pbc_overlap = 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
reg->selected_registrar = 1;
|
|
|
|
reg->pbc = 1;
|
2011-02-07 17:28:36 +01:00
|
|
|
if (p2p_dev_addr)
|
|
|
|
os_memcpy(reg->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
|
|
|
|
else
|
|
|
|
os_memset(reg->p2p_dev_addr, 0, ETH_ALEN);
|
2010-11-09 10:24:06 +01:00
|
|
|
wps_registrar_add_authorized_mac(reg,
|
|
|
|
(u8 *) "\xff\xff\xff\xff\xff\xff");
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2013-08-23 15:01:30 +02:00
|
|
|
wps_pbc_active_event(reg->wps);
|
2010-09-23 23:45:55 +02:00
|
|
|
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
|
2008-11-23 18:34:26 +01:00
|
|
|
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
|
|
|
|
eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
|
|
|
|
reg, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_registrar_pbc_completed(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
|
|
|
|
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
|
2009-01-04 12:43:05 +01:00
|
|
|
wps_registrar_stop_pbc(reg);
|
2013-08-23 15:01:30 +02:00
|
|
|
wps_pbc_disable_event(reg->wps);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2009-12-12 15:54:59 +01:00
|
|
|
|
2009-11-01 21:19:02 +01:00
|
|
|
static void wps_registrar_pin_completed(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
|
|
|
|
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
|
|
|
|
reg->selected_registrar = 0;
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-11-01 21:19:02 +01:00
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2012-02-29 19:42:48 +01:00
|
|
|
void wps_registrar_complete(struct wps_registrar *registrar, const u8 *uuid_e,
|
|
|
|
const u8 *dev_pw, size_t dev_pw_len)
|
2011-11-30 15:48:14 +01:00
|
|
|
{
|
|
|
|
if (registrar->pbc) {
|
|
|
|
wps_registrar_remove_pbc_session(registrar,
|
2011-12-11 11:03:18 +01:00
|
|
|
uuid_e, NULL);
|
2011-11-30 15:48:14 +01:00
|
|
|
wps_registrar_pbc_completed(registrar);
|
2013-12-16 21:08:37 +01:00
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
os_get_reltime(®istrar->pbc_ignore_start);
|
|
|
|
#endif /* WPS_WORKAROUNDS */
|
2012-11-15 18:59:04 +01:00
|
|
|
os_memcpy(registrar->pbc_ignore_uuid, uuid_e, WPS_UUID_LEN);
|
2011-11-30 15:48:14 +01:00
|
|
|
} else {
|
|
|
|
wps_registrar_pin_completed(registrar);
|
|
|
|
}
|
2012-02-29 19:42:48 +01:00
|
|
|
|
|
|
|
if (dev_pw &&
|
|
|
|
wps_registrar_invalidate_wildcard_pin(registrar, dev_pw,
|
|
|
|
dev_pw_len) == 0) {
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: Invalidated wildcard PIN",
|
|
|
|
dev_pw, dev_pw_len);
|
|
|
|
}
|
2011-11-30 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-06 19:51:06 +02:00
|
|
|
int wps_registrar_wps_cancel(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
if (reg->pbc) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC is set - cancelling it");
|
|
|
|
wps_registrar_pbc_timeout(reg, NULL);
|
2011-12-29 20:32:06 +01:00
|
|
|
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
|
2010-09-06 19:51:06 +02:00
|
|
|
return 1;
|
|
|
|
} else if (reg->selected_registrar) {
|
|
|
|
/* PIN Method */
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PIN is set - cancelling it");
|
|
|
|
wps_registrar_pin_completed(reg);
|
2012-02-29 19:42:48 +01:00
|
|
|
wps_registrar_invalidate_wildcard_pin(reg, NULL, 0);
|
2010-09-06 19:51:06 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 12:43:05 +01:00
|
|
|
/**
|
|
|
|
* wps_registrar_probe_req_rx - Notify Registrar of Probe Request
|
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
|
|
|
* @addr: MAC address of the Probe Request sender
|
|
|
|
* @wps_data: WPS IE contents
|
|
|
|
*
|
|
|
|
* This function is called on an AP when a Probe Request with WPS IE is
|
|
|
|
* received. This is used to track PBC mode use and to detect possible overlap
|
|
|
|
* situation with other WPS APs.
|
|
|
|
*/
|
2008-11-23 18:34:26 +01:00
|
|
|
void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
|
2010-07-18 23:30:24 +02:00
|
|
|
const struct wpabuf *wps_data,
|
|
|
|
int p2p_wildcard)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
2012-11-15 18:59:04 +01:00
|
|
|
int skip_add = 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wpa_hexdump_buf(MSG_MSGDUMP,
|
|
|
|
"WPS: Probe Request with WPS data received",
|
|
|
|
wps_data);
|
|
|
|
|
2009-02-06 13:15:47 +01:00
|
|
|
if (wps_parse_msg(wps_data, &attr) < 0)
|
|
|
|
return;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if (attr.config_methods == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Config Methods attribute in "
|
|
|
|
"Probe Request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-03 18:34:44 +02:00
|
|
|
if (attr.dev_password_id == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Device Password Id attribute "
|
|
|
|
"in Probe Request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg->enrollee_seen_cb && attr.uuid_e &&
|
2010-07-18 23:30:24 +02:00
|
|
|
attr.primary_dev_type && attr.request_type && !p2p_wildcard) {
|
2009-12-28 15:24:04 +01:00
|
|
|
char *dev_name = NULL;
|
|
|
|
if (attr.dev_name) {
|
|
|
|
dev_name = os_zalloc(attr.dev_name_len + 1);
|
|
|
|
if (dev_name) {
|
|
|
|
os_memcpy(dev_name, attr.dev_name,
|
|
|
|
attr.dev_name_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reg->enrollee_seen_cb(reg->cb_ctx, addr, attr.uuid_e,
|
|
|
|
attr.primary_dev_type,
|
|
|
|
WPA_GET_BE16(attr.config_methods),
|
|
|
|
WPA_GET_BE16(attr.dev_password_id),
|
|
|
|
*attr.request_type, dev_name);
|
|
|
|
os_free(dev_name);
|
|
|
|
}
|
|
|
|
|
2010-04-03 18:34:44 +02:00
|
|
|
if (WPA_GET_BE16(attr.dev_password_id) != DEV_PW_PUSHBUTTON)
|
2008-11-23 18:34:26 +01:00
|
|
|
return; /* Not PBC */
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
|
|
|
|
MACSTR, MAC2STR(addr));
|
2010-01-01 22:38:51 +01:00
|
|
|
if (attr.uuid_e == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid Probe Request WPS IE: No "
|
|
|
|
"UUID-E included");
|
|
|
|
return;
|
|
|
|
}
|
2011-03-10 17:38:16 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID-E from Probe Request", attr.uuid_e,
|
|
|
|
WPS_UUID_LEN);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2012-11-15 18:59:04 +01:00
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
if (reg->pbc_ignore_start.sec &&
|
|
|
|
os_memcmp(attr.uuid_e, reg->pbc_ignore_uuid, WPS_UUID_LEN) == 0) {
|
2013-12-16 21:08:37 +01:00
|
|
|
struct os_reltime now, dur;
|
|
|
|
os_get_reltime(&now);
|
|
|
|
os_reltime_sub(&now, ®->pbc_ignore_start, &dur);
|
2012-11-15 18:59:04 +01:00
|
|
|
if (dur.sec >= 0 && dur.sec < 5) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Ignore PBC activation "
|
|
|
|
"based on Probe Request from the Enrollee "
|
|
|
|
"that just completed PBC provisioning");
|
|
|
|
skip_add = 1;
|
|
|
|
} else
|
|
|
|
reg->pbc_ignore_start.sec = 0;
|
|
|
|
}
|
|
|
|
#endif /* WPS_WORKAROUNDS */
|
|
|
|
|
|
|
|
if (!skip_add)
|
|
|
|
wps_registrar_add_pbc_session(reg, addr, attr.uuid_e);
|
2009-11-01 20:59:30 +01:00
|
|
|
if (wps_registrar_pbc_overlap(reg, addr, attr.uuid_e)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC session overlap detected");
|
|
|
|
reg->force_pbc_overlap = 1;
|
|
|
|
wps_pbc_overlap_event(reg->wps);
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-13 12:26:21 +01:00
|
|
|
int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
|
|
|
|
const u8 *p2p_dev_addr, const u8 *psk, size_t psk_len)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
if (reg->new_psk_cb == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2013-09-01 09:47:34 +02:00
|
|
|
return reg->new_psk_cb(reg->cb_ctx, mac_addr, p2p_dev_addr, psk,
|
|
|
|
psk_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_cb_pin_needed(struct wps_registrar *reg, const u8 *uuid_e,
|
|
|
|
const struct wps_device_data *dev)
|
|
|
|
{
|
|
|
|
if (reg->pin_needed_cb == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
reg->pin_needed_cb(reg->cb_ctx, uuid_e, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-21 12:48:10 +01:00
|
|
|
static void wps_cb_reg_success(struct wps_registrar *reg, const u8 *mac_addr,
|
2012-02-29 19:42:48 +01:00
|
|
|
const u8 *uuid_e, const u8 *dev_pw,
|
|
|
|
size_t dev_pw_len)
|
2009-01-21 12:48:10 +01:00
|
|
|
{
|
|
|
|
if (reg->reg_success_cb == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-02-29 19:42:48 +01:00
|
|
|
reg->reg_success_cb(reg->cb_ctx, mac_addr, uuid_e, dev_pw, dev_pw_len);
|
2009-01-21 12:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-24 18:46:06 +01:00
|
|
|
static int wps_cb_set_ie(struct wps_registrar *reg, struct wpabuf *beacon_ie,
|
|
|
|
struct wpabuf *probe_resp_ie)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2009-12-24 18:46:06 +01:00
|
|
|
return reg->set_ie_cb(reg->cb_ctx, beacon_ie, probe_resp_ie);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-13 21:07:11 +01:00
|
|
|
static void wps_cb_set_sel_reg(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
u16 methods = 0;
|
|
|
|
if (reg->set_sel_reg_cb == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (reg->selected_registrar) {
|
2010-06-18 03:35:18 +02:00
|
|
|
methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
|
|
|
|
methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON);
|
2010-07-19 07:53:15 +02:00
|
|
|
if (reg->pbc)
|
|
|
|
wps_set_pushbutton(&methods, reg->wps->config_methods);
|
2009-11-13 21:07:11 +01:00
|
|
|
}
|
|
|
|
|
2010-07-19 07:53:15 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: wps_cb_set_sel_reg: sel_reg=%d "
|
|
|
|
"config_methods=0x%x pbc=%d methods=0x%x",
|
|
|
|
reg->selected_registrar, reg->wps->config_methods,
|
|
|
|
reg->pbc, methods);
|
|
|
|
|
2009-11-13 21:07:11 +01:00
|
|
|
reg->set_sel_reg_cb(reg->cb_ctx, reg->selected_registrar,
|
|
|
|
reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT,
|
|
|
|
methods);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static int wps_set_ie(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
struct wpabuf *beacon;
|
|
|
|
struct wpabuf *probe;
|
2010-07-29 19:23:20 +02:00
|
|
|
const u8 *auth_macs;
|
|
|
|
size_t count;
|
2011-03-19 10:44:42 +01:00
|
|
|
size_t vendor_len = 0;
|
|
|
|
int i;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-12-25 00:29:59 +01:00
|
|
|
if (reg->set_ie_cb == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-19 10:44:42 +01:00
|
|
|
for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) {
|
|
|
|
if (reg->wps->dev.vendor_ext[i]) {
|
|
|
|
vendor_len += 2 + 2;
|
|
|
|
vendor_len += wpabuf_len(reg->wps->dev.vendor_ext[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
beacon = wpabuf_alloc(400 + vendor_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
if (beacon == NULL)
|
|
|
|
return -1;
|
2011-03-19 10:44:42 +01:00
|
|
|
probe = wpabuf_alloc(500 + vendor_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
if (probe == NULL) {
|
|
|
|
wpabuf_free(beacon);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-07-29 19:23:20 +02:00
|
|
|
auth_macs = wps_authorized_macs(reg, &count);
|
|
|
|
|
2009-12-12 15:40:10 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Build Beacon IEs");
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_build_version(beacon) ||
|
|
|
|
wps_build_wps_state(reg->wps, beacon) ||
|
|
|
|
wps_build_ap_setup_locked(reg->wps, beacon) ||
|
|
|
|
wps_build_selected_registrar(reg, beacon) ||
|
|
|
|
wps_build_sel_reg_dev_password_id(reg, beacon) ||
|
|
|
|
wps_build_sel_reg_config_methods(reg, beacon) ||
|
2010-09-21 00:32:29 +02:00
|
|
|
wps_build_sel_pbc_reg_uuid_e(reg, beacon) ||
|
2013-08-25 09:55:53 +02:00
|
|
|
(reg->dualband && wps_build_rf_bands(®->wps->dev, beacon, 0)) ||
|
2011-03-19 10:44:42 +01:00
|
|
|
wps_build_wfa_ext(beacon, 0, auth_macs, count) ||
|
|
|
|
wps_build_vendor_ext(®->wps->dev, beacon)) {
|
2009-12-12 15:40:10 +01:00
|
|
|
wpabuf_free(beacon);
|
|
|
|
wpabuf_free(probe);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-19 10:39:51 +01:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (wps_build_dev_name(®->wps->dev, beacon) ||
|
|
|
|
wps_build_primary_dev_type(®->wps->dev, beacon)) {
|
|
|
|
wpabuf_free(beacon);
|
|
|
|
wpabuf_free(probe);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2009-12-12 15:40:10 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Build Probe Response IEs");
|
|
|
|
|
|
|
|
if (wps_build_version(probe) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_wps_state(reg->wps, probe) ||
|
|
|
|
wps_build_ap_setup_locked(reg->wps, probe) ||
|
|
|
|
wps_build_selected_registrar(reg, probe) ||
|
|
|
|
wps_build_sel_reg_dev_password_id(reg, probe) ||
|
|
|
|
wps_build_sel_reg_config_methods(reg, probe) ||
|
2010-05-26 17:46:08 +02:00
|
|
|
wps_build_resp_type(probe, reg->wps->ap ? WPS_RESP_AP :
|
|
|
|
WPS_RESP_REGISTRAR) ||
|
2008-11-29 11:44:02 +01:00
|
|
|
wps_build_uuid_e(probe, reg->wps->uuid) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_device_attrs(®->wps->dev, probe) ||
|
|
|
|
wps_build_probe_config_methods(reg, probe) ||
|
2013-08-25 09:55:53 +02:00
|
|
|
(reg->dualband && wps_build_rf_bands(®->wps->dev, probe, 0)) ||
|
2011-03-19 10:44:42 +01:00
|
|
|
wps_build_wfa_ext(probe, 0, auth_macs, count) ||
|
|
|
|
wps_build_vendor_ext(®->wps->dev, probe)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_free(beacon);
|
|
|
|
wpabuf_free(probe);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-29 21:06:34 +01:00
|
|
|
beacon = wps_ie_encapsulate(beacon);
|
|
|
|
probe = wps_ie_encapsulate(probe);
|
|
|
|
|
|
|
|
if (!beacon || !probe) {
|
|
|
|
wpabuf_free(beacon);
|
|
|
|
wpabuf_free(probe);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-03-08 18:36:02 +01:00
|
|
|
if (reg->static_wep_only) {
|
|
|
|
/*
|
|
|
|
* Windows XP and Vista clients can get confused about
|
|
|
|
* EAP-Identity/Request when they probe the network with
|
|
|
|
* EAPOL-Start. In such a case, they may assume the network is
|
|
|
|
* using IEEE 802.1X and prompt user for a certificate while
|
|
|
|
* the correct (non-WPS) behavior would be to ask for the
|
|
|
|
* static WEP key. As a workaround, use Microsoft Provisioning
|
|
|
|
* IE to advertise that legacy 802.1X is not supported.
|
|
|
|
*/
|
|
|
|
const u8 ms_wps[7] = {
|
|
|
|
WLAN_EID_VENDOR_SPECIFIC, 5,
|
|
|
|
/* Microsoft Provisioning IE (00:50:f2:5) */
|
|
|
|
0x00, 0x50, 0xf2, 5,
|
|
|
|
0x00 /* no legacy 802.1X or MS WPS */
|
|
|
|
};
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add Microsoft Provisioning IE "
|
|
|
|
"into Beacon/Probe Response frames");
|
|
|
|
wpabuf_put_data(beacon, ms_wps, sizeof(ms_wps));
|
|
|
|
wpabuf_put_data(probe, ms_wps, sizeof(ms_wps));
|
|
|
|
}
|
|
|
|
|
2009-12-24 18:46:06 +01:00
|
|
|
return wps_cb_set_ie(reg, beacon, probe);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_get_dev_password(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
const u8 *pin;
|
2008-12-10 23:56:37 +01:00
|
|
|
size_t pin_len = 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2014-07-02 00:46:45 +02:00
|
|
|
bin_clear_free(wps->dev_password, wps->dev_password_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->dev_password = NULL;
|
|
|
|
|
|
|
|
if (wps->pbc) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Use default PIN for PBC");
|
|
|
|
pin = (const u8 *) "00000000";
|
|
|
|
pin_len = 8;
|
2012-06-27 21:15:55 +02:00
|
|
|
#ifdef CONFIG_WPS_NFC
|
|
|
|
} else if (wps->nfc_pw_token) {
|
2013-04-02 17:30:58 +02:00
|
|
|
if (wps->nfc_pw_token->pw_id == DEV_PW_NFC_CONNECTION_HANDOVER)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Using NFC connection "
|
|
|
|
"handover and abbreviated WPS handshake "
|
|
|
|
"without Device Password");
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-27 21:15:55 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Use OOB Device Password from NFC "
|
|
|
|
"Password Token");
|
|
|
|
pin = wps->nfc_pw_token->dev_pw;
|
|
|
|
pin_len = wps->nfc_pw_token->dev_pw_len;
|
2013-09-08 17:08:26 +02:00
|
|
|
} else if (wps->dev_pw_id >= 0x10 &&
|
|
|
|
wps->wps->ap_nfc_dev_pw_id == wps->dev_pw_id &&
|
|
|
|
wps->wps->ap_nfc_dev_pw) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Use OOB Device Password from own NFC Password Token");
|
|
|
|
pin = wpabuf_head(wps->wps->ap_nfc_dev_pw);
|
|
|
|
pin_len = wpabuf_len(wps->wps->ap_nfc_dev_pw);
|
2012-06-27 21:15:55 +02:00
|
|
|
#endif /* CONFIG_WPS_NFC */
|
2008-11-23 18:34:26 +01:00
|
|
|
} else {
|
2009-01-03 19:09:35 +01:00
|
|
|
pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
|
2008-11-23 18:34:26 +01:00
|
|
|
&pin_len);
|
2013-02-14 19:41:14 +01:00
|
|
|
if (pin && wps->dev_pw_id >= 0x10) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No match for OOB Device "
|
|
|
|
"Password ID, but PIN found");
|
|
|
|
/*
|
|
|
|
* See whether Enrollee is willing to use PIN instead.
|
|
|
|
*/
|
|
|
|
wps->dev_pw_id = DEV_PW_DEFAULT;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
if (pin == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
|
2013-09-08 17:09:38 +02:00
|
|
|
"the Enrollee (context %p registrar %p)",
|
|
|
|
wps->wps, wps->wps->registrar);
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
|
|
|
|
&wps->peer_dev);
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wps->dev_password = os_malloc(pin_len);
|
|
|
|
if (wps->dev_password == NULL)
|
|
|
|
return -1;
|
|
|
|
os_memcpy(wps->dev_password, pin, pin_len);
|
|
|
|
wps->dev_password_len = pin_len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * UUID-R");
|
|
|
|
wpabuf_put_be16(msg, ATTR_UUID_R);
|
|
|
|
wpabuf_put_be16(msg, WPS_UUID_LEN);
|
|
|
|
wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
u8 *hash;
|
|
|
|
const u8 *addr[4];
|
|
|
|
size_t len[4];
|
|
|
|
|
2010-11-24 00:05:20 +01:00
|
|
|
if (random_get_bytes(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: R-S2",
|
|
|
|
wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
|
|
|
|
|
|
|
|
if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
|
|
|
|
"R-Hash derivation");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * R-Hash1");
|
|
|
|
wpabuf_put_be16(msg, ATTR_R_HASH1);
|
|
|
|
wpabuf_put_be16(msg, SHA256_MAC_LEN);
|
|
|
|
hash = wpabuf_put(msg, SHA256_MAC_LEN);
|
|
|
|
/* R-Hash1 = HMAC_AuthKey(R-S1 || PSK1 || PK_E || PK_R) */
|
|
|
|
addr[0] = wps->snonce;
|
|
|
|
len[0] = WPS_SECRET_NONCE_LEN;
|
|
|
|
addr[1] = wps->psk1;
|
|
|
|
len[1] = WPS_PSK_LEN;
|
|
|
|
addr[2] = wpabuf_head(wps->dh_pubkey_e);
|
|
|
|
len[2] = wpabuf_len(wps->dh_pubkey_e);
|
|
|
|
addr[3] = wpabuf_head(wps->dh_pubkey_r);
|
|
|
|
len[3] = wpabuf_len(wps->dh_pubkey_r);
|
|
|
|
hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", hash, SHA256_MAC_LEN);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * R-Hash2");
|
|
|
|
wpabuf_put_be16(msg, ATTR_R_HASH2);
|
|
|
|
wpabuf_put_be16(msg, SHA256_MAC_LEN);
|
|
|
|
hash = wpabuf_put(msg, SHA256_MAC_LEN);
|
|
|
|
/* R-Hash2 = HMAC_AuthKey(R-S2 || PSK2 || PK_E || PK_R) */
|
|
|
|
addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
|
|
|
|
addr[1] = wps->psk2;
|
|
|
|
hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", hash, SHA256_MAC_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * R-SNonce1");
|
|
|
|
wpabuf_put_be16(msg, ATTR_R_SNONCE1);
|
|
|
|
wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
|
|
|
|
wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * R-SNonce2");
|
|
|
|
wpabuf_put_be16(msg, ATTR_R_SNONCE2);
|
|
|
|
wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
|
|
|
|
wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
|
|
|
|
WPS_SECRET_NONCE_LEN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
static int wps_build_cred_network_idx(struct wpabuf *msg,
|
2009-11-15 21:46:30 +01:00
|
|
|
const struct wps_credential *cred)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2010-09-23 04:20:01 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Network Index (1)");
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_put_be16(msg, ATTR_NETWORK_INDEX);
|
|
|
|
wpabuf_put_be16(msg, 1);
|
2009-01-17 20:14:13 +01:00
|
|
|
wpabuf_put_u8(msg, 1);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
static int wps_build_cred_ssid(struct wpabuf *msg,
|
2009-11-15 21:46:30 +01:00
|
|
|
const struct wps_credential *cred)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * SSID");
|
2010-09-23 04:20:01 +02:00
|
|
|
wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID for Credential",
|
|
|
|
cred->ssid, cred->ssid_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_put_be16(msg, ATTR_SSID);
|
2008-11-27 20:14:39 +01:00
|
|
|
wpabuf_put_be16(msg, cred->ssid_len);
|
|
|
|
wpabuf_put_data(msg, cred->ssid, cred->ssid_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
static int wps_build_cred_auth_type(struct wpabuf *msg,
|
2009-11-15 21:46:30 +01:00
|
|
|
const struct wps_credential *cred)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
|
2008-11-27 20:14:39 +01:00
|
|
|
cred->auth_type);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_put_be16(msg, ATTR_AUTH_TYPE);
|
|
|
|
wpabuf_put_be16(msg, 2);
|
2008-11-27 20:14:39 +01:00
|
|
|
wpabuf_put_be16(msg, cred->auth_type);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
static int wps_build_cred_encr_type(struct wpabuf *msg,
|
2009-11-15 21:46:30 +01:00
|
|
|
const struct wps_credential *cred)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
|
2008-11-27 20:14:39 +01:00
|
|
|
cred->encr_type);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_put_be16(msg, ATTR_ENCR_TYPE);
|
|
|
|
wpabuf_put_be16(msg, 2);
|
2008-11-27 20:14:39 +01:00
|
|
|
wpabuf_put_be16(msg, cred->encr_type);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
static int wps_build_cred_network_key(struct wpabuf *msg,
|
2009-11-24 23:57:00 +01:00
|
|
|
const struct wps_credential *cred)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2009-12-21 11:46:19 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%d)",
|
|
|
|
(int) cred->key_len);
|
2010-09-23 04:20:01 +02:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
|
|
|
|
cred->key, cred->key_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
|
2008-11-27 20:14:39 +01:00
|
|
|
wpabuf_put_be16(msg, cred->key_len);
|
|
|
|
wpabuf_put_data(msg, cred->key, cred->key_len);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
static int wps_build_credential(struct wpabuf *msg,
|
2009-11-15 21:46:30 +01:00
|
|
|
const struct wps_credential *cred)
|
2008-11-27 20:14:39 +01:00
|
|
|
{
|
|
|
|
if (wps_build_cred_network_idx(msg, cred) ||
|
|
|
|
wps_build_cred_ssid(msg, cred) ||
|
|
|
|
wps_build_cred_auth_type(msg, cred) ||
|
|
|
|
wps_build_cred_encr_type(msg, cred) ||
|
|
|
|
wps_build_cred_network_key(msg, cred) ||
|
2013-04-27 21:13:36 +02:00
|
|
|
wps_build_mac_addr(msg, cred->mac_addr))
|
2008-11-27 20:14:39 +01:00
|
|
|
return -1;
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-30 21:26:37 +02:00
|
|
|
int wps_build_credential_wrap(struct wpabuf *msg,
|
|
|
|
const struct wps_credential *cred)
|
|
|
|
{
|
|
|
|
struct wpabuf *wbuf;
|
|
|
|
wbuf = wpabuf_alloc(200);
|
|
|
|
if (wbuf == NULL)
|
|
|
|
return -1;
|
|
|
|
if (wps_build_credential(wbuf, cred)) {
|
|
|
|
wpabuf_free(wbuf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wpabuf_put_be16(msg, ATTR_CRED);
|
|
|
|
wpabuf_put_be16(msg, wpabuf_len(wbuf));
|
|
|
|
wpabuf_put_buf(msg, wbuf);
|
|
|
|
wpabuf_free(wbuf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-26 20:57:38 +01:00
|
|
|
int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
struct wpabuf *cred;
|
|
|
|
|
2009-01-16 21:50:41 +01:00
|
|
|
if (wps->wps->registrar->skip_cred_build)
|
|
|
|
goto skip_cred_build;
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Credential");
|
2009-11-15 21:46:30 +01:00
|
|
|
if (wps->use_cred) {
|
|
|
|
os_memcpy(&wps->cred, wps->use_cred, sizeof(wps->cred));
|
|
|
|
goto use_provided;
|
|
|
|
}
|
2008-11-27 20:14:39 +01:00
|
|
|
os_memset(&wps->cred, 0, sizeof(wps->cred));
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
|
|
|
|
wps->cred.ssid_len = wps->wps->ssid_len;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
/* Select the best authentication and encryption type */
|
2016-01-01 10:59:20 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPS: Own auth types 0x%x - masked Enrollee auth types 0x%x",
|
|
|
|
wps->wps->auth_types, wps->auth_type);
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps->auth_type & WPS_AUTH_WPA2PSK)
|
|
|
|
wps->auth_type = WPS_AUTH_WPA2PSK;
|
|
|
|
else if (wps->auth_type & WPS_AUTH_WPAPSK)
|
|
|
|
wps->auth_type = WPS_AUTH_WPAPSK;
|
|
|
|
else if (wps->auth_type & WPS_AUTH_OPEN)
|
|
|
|
wps->auth_type = WPS_AUTH_OPEN;
|
|
|
|
else {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unsupported auth_type 0x%x",
|
|
|
|
wps->auth_type);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-27 20:14:39 +01:00
|
|
|
wps->cred.auth_type = wps->auth_type;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2016-01-01 10:59:20 +01:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPS: Own encr types 0x%x (rsn: 0x%x, wpa: 0x%x) - masked Enrollee encr types 0x%x",
|
|
|
|
wps->wps->encr_types, wps->wps->encr_types_rsn,
|
|
|
|
wps->wps->encr_types_wpa, wps->encr_type);
|
|
|
|
if (wps->wps->ap && wps->auth_type == WPS_AUTH_WPA2PSK)
|
|
|
|
wps->encr_type &= wps->wps->encr_types_rsn;
|
|
|
|
else if (wps->wps->ap && wps->auth_type == WPS_AUTH_WPAPSK)
|
|
|
|
wps->encr_type &= wps->wps->encr_types_wpa;
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps->auth_type == WPS_AUTH_WPA2PSK ||
|
|
|
|
wps->auth_type == WPS_AUTH_WPAPSK) {
|
|
|
|
if (wps->encr_type & WPS_ENCR_AES)
|
|
|
|
wps->encr_type = WPS_ENCR_AES;
|
|
|
|
else if (wps->encr_type & WPS_ENCR_TKIP)
|
|
|
|
wps->encr_type = WPS_ENCR_TKIP;
|
|
|
|
else {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
|
|
|
|
"type for WPA/WPA2");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-06 10:18:10 +02:00
|
|
|
if (wps->encr_type & WPS_ENCR_NONE)
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->encr_type = WPS_ENCR_NONE;
|
2014-04-06 10:18:10 +02:00
|
|
|
#ifdef CONFIG_TESTING_OPTIONS
|
|
|
|
else if (wps->encr_type & WPS_ENCR_WEP)
|
|
|
|
wps->encr_type = WPS_ENCR_WEP;
|
|
|
|
#endif /* CONFIG_TESTING_OPTIONS */
|
2008-11-23 18:34:26 +01:00
|
|
|
else {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
|
|
|
|
"type for non-WPA/WPA2 mode");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2008-11-27 20:14:39 +01:00
|
|
|
wps->cred.encr_type = wps->encr_type;
|
2009-11-18 23:31:57 +01:00
|
|
|
/*
|
|
|
|
* Set MAC address in the Credential to be the Enrollee's MAC address
|
|
|
|
*/
|
|
|
|
os_memcpy(wps->cred.mac_addr, wps->mac_addr_e, ETH_ALEN);
|
2008-11-27 20:14:39 +01:00
|
|
|
|
2009-01-21 12:48:10 +01:00
|
|
|
if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
|
|
|
|
!wps->wps->registrar->disable_auto_conf) {
|
2008-11-27 20:14:39 +01:00
|
|
|
u8 r[16];
|
|
|
|
/* Generate a random passphrase */
|
2014-09-08 11:54:18 +02:00
|
|
|
if (random_pool_ready() != 1 ||
|
|
|
|
random_get_bytes(r, sizeof(r)) < 0) {
|
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"WPS: Could not generate random PSK");
|
2008-11-27 20:14:39 +01:00
|
|
|
return -1;
|
2014-09-08 11:54:18 +02:00
|
|
|
}
|
2008-11-27 20:14:39 +01:00
|
|
|
os_free(wps->new_psk);
|
|
|
|
wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
|
|
|
|
if (wps->new_psk == NULL)
|
|
|
|
return -1;
|
|
|
|
wps->new_psk_len--; /* remove newline */
|
|
|
|
while (wps->new_psk_len &&
|
|
|
|
wps->new_psk[wps->new_psk_len - 1] == '=')
|
|
|
|
wps->new_psk_len--;
|
|
|
|
wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated passphrase",
|
|
|
|
wps->new_psk, wps->new_psk_len);
|
|
|
|
os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
|
|
|
|
wps->cred.key_len = wps->new_psk_len;
|
2013-09-01 09:08:30 +02:00
|
|
|
} else if (!wps->wps->registrar->force_per_enrollee_psk &&
|
|
|
|
wps->use_psk_key && wps->wps->psk_set) {
|
2009-12-21 11:46:19 +01:00
|
|
|
char hex[65];
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Use PSK format for Network Key");
|
|
|
|
wpa_snprintf_hex(hex, sizeof(hex), wps->wps->psk, 32);
|
|
|
|
os_memcpy(wps->cred.key, hex, 32 * 2);
|
|
|
|
wps->cred.key_len = 32 * 2;
|
2013-09-01 09:08:30 +02:00
|
|
|
} else if (!wps->wps->registrar->force_per_enrollee_psk &&
|
|
|
|
wps->wps->network_key) {
|
2008-11-27 20:14:39 +01:00
|
|
|
os_memcpy(wps->cred.key, wps->wps->network_key,
|
|
|
|
wps->wps->network_key_len);
|
|
|
|
wps->cred.key_len = wps->wps->network_key_len;
|
|
|
|
} else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
|
|
|
|
char hex[65];
|
|
|
|
/* Generate a random per-device PSK */
|
|
|
|
os_free(wps->new_psk);
|
|
|
|
wps->new_psk_len = 32;
|
|
|
|
wps->new_psk = os_malloc(wps->new_psk_len);
|
|
|
|
if (wps->new_psk == NULL)
|
|
|
|
return -1;
|
2014-09-08 11:54:18 +02:00
|
|
|
if (random_pool_ready() != 1 ||
|
|
|
|
random_get_bytes(wps->new_psk, wps->new_psk_len) < 0) {
|
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"WPS: Could not generate random PSK");
|
2008-11-27 20:14:39 +01:00
|
|
|
os_free(wps->new_psk);
|
|
|
|
wps->new_psk = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
|
|
|
|
wps->new_psk, wps->new_psk_len);
|
|
|
|
wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
|
|
|
|
wps->new_psk_len);
|
|
|
|
os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
|
|
|
|
wps->cred.key_len = wps->new_psk_len * 2;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-11-15 21:46:30 +01:00
|
|
|
use_provided:
|
2010-09-22 04:51:23 +02:00
|
|
|
#ifdef CONFIG_WPS_TESTING
|
|
|
|
if (wps_testing_dummy_cred)
|
|
|
|
cred = wpabuf_alloc(200);
|
|
|
|
else
|
|
|
|
cred = NULL;
|
2010-06-04 08:34:34 +02:00
|
|
|
if (cred) {
|
|
|
|
struct wps_credential dummy;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add dummy credential");
|
|
|
|
os_memset(&dummy, 0, sizeof(dummy));
|
|
|
|
os_memcpy(dummy.ssid, "dummy", 5);
|
|
|
|
dummy.ssid_len = 5;
|
|
|
|
dummy.auth_type = WPS_AUTH_WPA2PSK;
|
|
|
|
dummy.encr_type = WPS_ENCR_AES;
|
|
|
|
os_memcpy(dummy.key, "dummy psk", 9);
|
|
|
|
dummy.key_len = 9;
|
|
|
|
os_memcpy(dummy.mac_addr, wps->mac_addr_e, ETH_ALEN);
|
|
|
|
wps_build_credential(cred, &dummy);
|
|
|
|
wpa_hexdump_buf(MSG_DEBUG, "WPS: Dummy Credential", cred);
|
|
|
|
|
|
|
|
wpabuf_put_be16(msg, ATTR_CRED);
|
|
|
|
wpabuf_put_be16(msg, wpabuf_len(cred));
|
|
|
|
wpabuf_put_buf(msg, cred);
|
|
|
|
|
|
|
|
wpabuf_free(cred);
|
|
|
|
}
|
2010-09-22 04:51:23 +02:00
|
|
|
#endif /* CONFIG_WPS_TESTING */
|
2010-06-04 08:34:34 +02:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
cred = wpabuf_alloc(200);
|
|
|
|
if (cred == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
if (wps_build_credential(cred, &wps->cred)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_free(cred);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
wpabuf_put_be16(msg, ATTR_CRED);
|
|
|
|
wpabuf_put_be16(msg, wpabuf_len(cred));
|
|
|
|
wpabuf_put_buf(msg, cred);
|
|
|
|
wpabuf_free(cred);
|
|
|
|
|
2009-01-16 21:50:41 +01:00
|
|
|
skip_cred_build:
|
|
|
|
if (wps->wps->registrar->extra_cred) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * Credential (pre-configured)");
|
|
|
|
wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
|
|
|
|
}
|
|
|
|
|
2008-11-27 20:14:39 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: * AP Settings");
|
|
|
|
|
|
|
|
if (wps_build_credential(msg, &wps->cred))
|
|
|
|
return -1;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-30 21:10:40 +01:00
|
|
|
static struct wpabuf * wps_build_ap_cred(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
struct wpabuf *msg, *plain;
|
|
|
|
|
|
|
|
msg = wpabuf_alloc(1000);
|
|
|
|
if (msg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
plain = wpabuf_alloc(200);
|
|
|
|
if (plain == NULL) {
|
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_build_ap_settings(wps, plain)) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpabuf_put_be16(msg, ATTR_CRED);
|
|
|
|
wpabuf_put_be16(msg, wpabuf_len(plain));
|
|
|
|
wpabuf_put_buf(msg, plain);
|
|
|
|
wpabuf_free(plain);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static struct wpabuf * wps_build_m2(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
struct wpabuf *msg;
|
2013-02-24 16:30:18 +01:00
|
|
|
int config_in_m2 = 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2010-11-24 00:05:20 +01:00
|
|
|
if (random_get_bytes(wps->nonce_r, WPS_NONCE_LEN) < 0)
|
2008-11-23 18:34:26 +01:00
|
|
|
return NULL;
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
|
|
|
|
wps->nonce_r, WPS_NONCE_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Building Message M2");
|
|
|
|
msg = wpabuf_alloc(1000);
|
|
|
|
if (msg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (wps_build_version(msg) ||
|
|
|
|
wps_build_msg_type(msg, WPS_M2) ||
|
|
|
|
wps_build_enrollee_nonce(wps, msg) ||
|
|
|
|
wps_build_registrar_nonce(wps, msg) ||
|
|
|
|
wps_build_uuid_r(wps, msg) ||
|
|
|
|
wps_build_public_key(wps, msg) ||
|
|
|
|
wps_derive_keys(wps) ||
|
|
|
|
wps_build_auth_type_flags(wps, msg) ||
|
|
|
|
wps_build_encr_type_flags(wps, msg) ||
|
|
|
|
wps_build_conn_type_flags(wps, msg) ||
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_build_config_methods_r(wps->wps->registrar, msg) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_device_attrs(&wps->wps->dev, msg) ||
|
2013-08-25 09:55:53 +02:00
|
|
|
wps_build_rf_bands(&wps->wps->dev, msg,
|
|
|
|
wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_assoc_state(wps, msg) ||
|
2008-11-29 11:44:02 +01:00
|
|
|
wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
|
2009-02-06 13:03:34 +01:00
|
|
|
wps_build_dev_password_id(msg, wps->dev_pw_id) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_os_version(&wps->wps->dev, msg) ||
|
2013-02-24 16:30:18 +01:00
|
|
|
wps_build_wfa_ext(msg, 0, NULL, 0)) {
|
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_NFC
|
2013-04-27 17:50:14 +02:00
|
|
|
if (wps->nfc_pw_token && wps->nfc_pw_token->pk_hash_provided_oob &&
|
|
|
|
wps->nfc_pw_token->pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) {
|
2013-02-24 16:30:18 +01:00
|
|
|
/*
|
|
|
|
* Use abbreviated handshake since public key hash allowed
|
|
|
|
* Enrollee to validate our public key similarly to how Enrollee
|
|
|
|
* public key was validated. There is no need to validate Device
|
|
|
|
* Password in this case.
|
|
|
|
*/
|
|
|
|
struct wpabuf *plain = wpabuf_alloc(500);
|
|
|
|
if (plain == NULL ||
|
|
|
|
wps_build_cred(wps, plain) ||
|
|
|
|
wps_build_key_wrap_auth(wps, plain) ||
|
|
|
|
wps_build_encr_settings(wps, msg, plain)) {
|
|
|
|
wpabuf_free(msg);
|
|
|
|
wpabuf_free(plain);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wpabuf_free(plain);
|
|
|
|
config_in_m2 = 1;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_NFC */
|
|
|
|
|
|
|
|
if (wps_build_authenticator(wps, msg)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-12 11:38:14 +01:00
|
|
|
wps->int_reg = 1;
|
2013-02-24 16:30:18 +01:00
|
|
|
wps->state = config_in_m2 ? RECV_DONE : RECV_M3;
|
2008-11-23 18:34:26 +01:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wpabuf * wps_build_m2d(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
struct wpabuf *msg;
|
2009-11-01 19:57:36 +01:00
|
|
|
u16 err = wps->config_error;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Building Message M2D");
|
|
|
|
msg = wpabuf_alloc(1000);
|
|
|
|
if (msg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-11-01 19:57:36 +01:00
|
|
|
if (wps->wps->ap && wps->wps->ap_setup_locked &&
|
|
|
|
err == WPS_CFG_NO_ERROR)
|
2008-11-29 11:44:02 +01:00
|
|
|
err = WPS_CFG_SETUP_LOCKED;
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_build_version(msg) ||
|
|
|
|
wps_build_msg_type(msg, WPS_M2D) ||
|
|
|
|
wps_build_enrollee_nonce(wps, msg) ||
|
|
|
|
wps_build_registrar_nonce(wps, msg) ||
|
|
|
|
wps_build_uuid_r(wps, msg) ||
|
|
|
|
wps_build_auth_type_flags(wps, msg) ||
|
|
|
|
wps_build_encr_type_flags(wps, msg) ||
|
|
|
|
wps_build_conn_type_flags(wps, msg) ||
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_build_config_methods_r(wps->wps->registrar, msg) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_device_attrs(&wps->wps->dev, msg) ||
|
2013-08-25 09:55:53 +02:00
|
|
|
wps_build_rf_bands(&wps->wps->dev, msg,
|
|
|
|
wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_assoc_state(wps, msg) ||
|
2008-11-29 11:44:02 +01:00
|
|
|
wps_build_config_error(msg, err) ||
|
2009-12-11 17:00:10 +01:00
|
|
|
wps_build_os_version(&wps->wps->dev, msg) ||
|
2010-07-29 19:23:20 +02:00
|
|
|
wps_build_wfa_ext(msg, 0, NULL, 0)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wps->state = RECV_M2D_ACK;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wpabuf * wps_build_m4(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
struct wpabuf *msg, *plain;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Building Message M4");
|
|
|
|
|
|
|
|
wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
|
|
|
|
|
|
|
|
plain = wpabuf_alloc(200);
|
|
|
|
if (plain == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
msg = wpabuf_alloc(1000);
|
|
|
|
if (msg == NULL) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_build_version(msg) ||
|
|
|
|
wps_build_msg_type(msg, WPS_M4) ||
|
|
|
|
wps_build_enrollee_nonce(wps, msg) ||
|
|
|
|
wps_build_r_hash(wps, msg) ||
|
|
|
|
wps_build_r_snonce1(wps, plain) ||
|
|
|
|
wps_build_key_wrap_auth(wps, plain) ||
|
|
|
|
wps_build_encr_settings(wps, msg, plain) ||
|
2010-07-29 19:23:20 +02:00
|
|
|
wps_build_wfa_ext(msg, 0, NULL, 0) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_authenticator(wps, msg)) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wpabuf_free(plain);
|
|
|
|
|
|
|
|
wps->state = RECV_M5;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wpabuf * wps_build_m6(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
struct wpabuf *msg, *plain;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Building Message M6");
|
|
|
|
|
|
|
|
plain = wpabuf_alloc(200);
|
|
|
|
if (plain == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
msg = wpabuf_alloc(1000);
|
|
|
|
if (msg == NULL) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_build_version(msg) ||
|
|
|
|
wps_build_msg_type(msg, WPS_M6) ||
|
|
|
|
wps_build_enrollee_nonce(wps, msg) ||
|
|
|
|
wps_build_r_snonce2(wps, plain) ||
|
|
|
|
wps_build_key_wrap_auth(wps, plain) ||
|
|
|
|
wps_build_encr_settings(wps, msg, plain) ||
|
2010-07-29 19:23:20 +02:00
|
|
|
wps_build_wfa_ext(msg, 0, NULL, 0) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_authenticator(wps, msg)) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wpabuf_free(plain);
|
|
|
|
|
|
|
|
wps->wps_pin_revealed = 1;
|
|
|
|
wps->state = RECV_M7;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wpabuf * wps_build_m8(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
struct wpabuf *msg, *plain;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
|
|
|
|
|
|
|
|
plain = wpabuf_alloc(500);
|
|
|
|
if (plain == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
msg = wpabuf_alloc(1000);
|
|
|
|
if (msg == NULL) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_build_version(msg) ||
|
|
|
|
wps_build_msg_type(msg, WPS_M8) ||
|
|
|
|
wps_build_enrollee_nonce(wps, msg) ||
|
2009-11-15 21:46:30 +01:00
|
|
|
((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
|
|
|
|
(!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_key_wrap_auth(wps, plain) ||
|
|
|
|
wps_build_encr_settings(wps, msg, plain) ||
|
2010-07-29 19:23:20 +02:00
|
|
|
wps_build_wfa_ext(msg, 0, NULL, 0) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_build_authenticator(wps, msg)) {
|
|
|
|
wpabuf_free(plain);
|
|
|
|
wpabuf_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wpabuf_free(plain);
|
|
|
|
|
|
|
|
wps->state = RECV_DONE;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-03 18:50:49 +01:00
|
|
|
struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
|
|
|
|
enum wsc_op_code *op_code)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
struct wpabuf *msg;
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
2010-02-12 11:38:14 +01:00
|
|
|
if (!wps->int_reg && wps->wps->wps_upnp) {
|
2009-02-06 20:39:32 +01:00
|
|
|
struct upnp_pending_message *p, *prev = NULL;
|
|
|
|
if (wps->ext_reg > 1)
|
|
|
|
wps_registrar_free_pending_m2(wps->wps);
|
|
|
|
p = wps->wps->upnp_msgs;
|
|
|
|
/* TODO: check pending message MAC address */
|
|
|
|
while (p && p->next) {
|
|
|
|
prev = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Use pending message from "
|
|
|
|
"UPnP");
|
|
|
|
if (prev)
|
|
|
|
prev->next = NULL;
|
|
|
|
else
|
|
|
|
wps->wps->upnp_msgs = NULL;
|
|
|
|
msg = p->msg;
|
2009-11-13 21:29:31 +01:00
|
|
|
switch (p->type) {
|
|
|
|
case WPS_WSC_ACK:
|
|
|
|
*op_code = WSC_ACK;
|
|
|
|
break;
|
|
|
|
case WPS_WSC_NACK:
|
|
|
|
*op_code = WSC_NACK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*op_code = WSC_MSG;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-06 20:39:32 +01:00
|
|
|
os_free(p);
|
|
|
|
if (wps->ext_reg == 0)
|
|
|
|
wps->ext_reg = 1;
|
|
|
|
return msg;
|
|
|
|
}
|
2009-01-29 17:47:02 +01:00
|
|
|
}
|
|
|
|
if (wps->ext_reg) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Using external Registrar, but no "
|
|
|
|
"pending message available");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
switch (wps->state) {
|
|
|
|
case SEND_M2:
|
|
|
|
if (wps_get_dev_password(wps) < 0)
|
|
|
|
msg = wps_build_m2d(wps);
|
|
|
|
else
|
|
|
|
msg = wps_build_m2(wps);
|
|
|
|
*op_code = WSC_MSG;
|
|
|
|
break;
|
|
|
|
case SEND_M2D:
|
|
|
|
msg = wps_build_m2d(wps);
|
|
|
|
*op_code = WSC_MSG;
|
|
|
|
break;
|
|
|
|
case SEND_M4:
|
|
|
|
msg = wps_build_m4(wps);
|
|
|
|
*op_code = WSC_MSG;
|
|
|
|
break;
|
|
|
|
case SEND_M6:
|
|
|
|
msg = wps_build_m6(wps);
|
|
|
|
*op_code = WSC_MSG;
|
|
|
|
break;
|
|
|
|
case SEND_M8:
|
|
|
|
msg = wps_build_m8(wps);
|
|
|
|
*op_code = WSC_MSG;
|
|
|
|
break;
|
|
|
|
case RECV_DONE:
|
|
|
|
msg = wps_build_wsc_ack(wps);
|
|
|
|
*op_code = WSC_ACK;
|
|
|
|
break;
|
2008-12-16 21:37:55 +01:00
|
|
|
case SEND_WSC_NACK:
|
|
|
|
msg = wps_build_wsc_nack(wps);
|
|
|
|
*op_code = WSC_NACK;
|
|
|
|
break;
|
2008-11-23 18:34:26 +01:00
|
|
|
default:
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
|
|
|
|
"a message", wps->state);
|
|
|
|
msg = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*op_code == WSC_MSG && msg) {
|
|
|
|
/* Save a copy of the last message for Authenticator derivation
|
|
|
|
*/
|
|
|
|
wpabuf_free(wps->last_msg);
|
|
|
|
wps->last_msg = wpabuf_dup(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
|
|
|
|
{
|
|
|
|
if (e_nonce == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
|
|
|
|
wps->nonce_e, WPS_NONCE_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
|
|
|
|
{
|
|
|
|
if (r_nonce == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid Registrar Nonce received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
|
|
|
|
{
|
|
|
|
if (uuid_e == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No UUID-E received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
|
|
|
|
{
|
|
|
|
if (pw_id == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Device Password ID received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wps->dev_pw_id = WPA_GET_BE16(pw_id);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
|
|
|
|
{
|
|
|
|
if (e_hash1 == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No E-Hash1 received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
|
|
|
|
{
|
|
|
|
if (e_hash2 == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No E-Hash2 received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
|
|
|
|
{
|
|
|
|
u8 hash[SHA256_MAC_LEN];
|
|
|
|
const u8 *addr[4];
|
|
|
|
size_t len[4];
|
|
|
|
|
|
|
|
if (e_snonce1 == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No E-SNonce1 received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce1", e_snonce1,
|
|
|
|
WPS_SECRET_NONCE_LEN);
|
|
|
|
|
|
|
|
/* E-Hash1 = HMAC_AuthKey(E-S1 || PSK1 || PK_E || PK_R) */
|
|
|
|
addr[0] = e_snonce1;
|
|
|
|
len[0] = WPS_SECRET_NONCE_LEN;
|
|
|
|
addr[1] = wps->psk1;
|
|
|
|
len[1] = WPS_PSK_LEN;
|
|
|
|
addr[2] = wpabuf_head(wps->dh_pubkey_e);
|
|
|
|
len[2] = wpabuf_len(wps->dh_pubkey_e);
|
|
|
|
addr[3] = wpabuf_head(wps->dh_pubkey_r);
|
|
|
|
len[3] = wpabuf_len(wps->dh_pubkey_r);
|
|
|
|
hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
|
|
|
|
|
2014-06-29 18:38:17 +02:00
|
|
|
if (os_memcmp_const(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: E-Hash1 derived from E-S1 does "
|
|
|
|
"not match with the pre-committed value");
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
|
2013-08-23 15:01:55 +02:00
|
|
|
wps_pwd_auth_fail_event(wps->wps, 0, 1, wps->mac_addr_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the first "
|
|
|
|
"half of the device password");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
|
|
|
|
{
|
|
|
|
u8 hash[SHA256_MAC_LEN];
|
|
|
|
const u8 *addr[4];
|
|
|
|
size_t len[4];
|
|
|
|
|
|
|
|
if (e_snonce2 == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No E-SNonce2 received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce2", e_snonce2,
|
|
|
|
WPS_SECRET_NONCE_LEN);
|
|
|
|
|
|
|
|
/* E-Hash2 = HMAC_AuthKey(E-S2 || PSK2 || PK_E || PK_R) */
|
|
|
|
addr[0] = e_snonce2;
|
|
|
|
len[0] = WPS_SECRET_NONCE_LEN;
|
|
|
|
addr[1] = wps->psk2;
|
|
|
|
len[1] = WPS_PSK_LEN;
|
|
|
|
addr[2] = wpabuf_head(wps->dh_pubkey_e);
|
|
|
|
len[2] = wpabuf_len(wps->dh_pubkey_e);
|
|
|
|
addr[3] = wpabuf_head(wps->dh_pubkey_r);
|
|
|
|
len[3] = wpabuf_len(wps->dh_pubkey_r);
|
|
|
|
hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
|
|
|
|
|
2014-06-29 18:38:17 +02:00
|
|
|
if (os_memcmp_const(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: E-Hash2 derived from E-S2 does "
|
|
|
|
"not match with the pre-committed value");
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
|
2013-08-23 15:01:55 +02:00
|
|
|
wps_pwd_auth_fail_event(wps->wps, 0, 2, wps->mac_addr_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the second "
|
|
|
|
"half of the device password");
|
|
|
|
wps->wps_pin_revealed = 0;
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2012-02-08 11:37:57 +01:00
|
|
|
/*
|
|
|
|
* In case wildcard PIN is used and WPS handshake succeeds in the first
|
|
|
|
* attempt, wps_registrar_unlock_pin() would not free the PIN, so make
|
|
|
|
* sure the PIN gets invalidated here.
|
|
|
|
*/
|
|
|
|
wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
|
|
|
|
{
|
|
|
|
if (mac_addr == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No MAC Address received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee MAC Address " MACSTR,
|
|
|
|
MAC2STR(mac_addr));
|
|
|
|
os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
|
|
|
|
os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
|
|
|
|
size_t pk_len)
|
|
|
|
{
|
|
|
|
if (pk == NULL || pk_len == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpabuf_free(wps->dh_pubkey_e);
|
|
|
|
wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
|
|
|
|
if (wps->dh_pubkey_e == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
|
|
|
|
{
|
|
|
|
u16 auth_types;
|
|
|
|
|
|
|
|
if (auth == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Authentication Type flags "
|
|
|
|
"received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auth_types = WPA_GET_BE16(auth);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Authentication Type flags 0x%x",
|
|
|
|
auth_types);
|
|
|
|
wps->auth_type = wps->wps->auth_types & auth_types;
|
|
|
|
if (wps->auth_type == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No match in supported "
|
2008-11-30 18:56:11 +01:00
|
|
|
"authentication types (own 0x%x Enrollee 0x%x)",
|
|
|
|
wps->wps->auth_types, auth_types);
|
2009-05-06 09:56:18 +02:00
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
/*
|
|
|
|
* Some deployed implementations seem to advertise incorrect
|
|
|
|
* information in this attribute. For example, Linksys WRT350N
|
|
|
|
* seems to have a byteorder bug that breaks this negotiation.
|
|
|
|
* In order to interoperate with existing implementations,
|
|
|
|
* assume that the Enrollee supports everything we do.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
|
|
|
|
"does not advertise supported authentication types "
|
|
|
|
"correctly");
|
|
|
|
wps->auth_type = wps->wps->auth_types;
|
|
|
|
#else /* WPS_WORKAROUNDS */
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
2009-05-06 09:56:18 +02:00
|
|
|
#endif /* WPS_WORKAROUNDS */
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
|
|
|
|
{
|
|
|
|
u16 encr_types;
|
|
|
|
|
|
|
|
if (encr == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Encryption Type flags "
|
|
|
|
"received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
encr_types = WPA_GET_BE16(encr);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Encryption Type flags 0x%x",
|
|
|
|
encr_types);
|
|
|
|
wps->encr_type = wps->wps->encr_types & encr_types;
|
|
|
|
if (wps->encr_type == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No match in supported "
|
2009-05-06 09:56:18 +02:00
|
|
|
"encryption types (own 0x%x Enrollee 0x%x)",
|
|
|
|
wps->wps->encr_types, encr_types);
|
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
/*
|
|
|
|
* Some deployed implementations seem to advertise incorrect
|
|
|
|
* information in this attribute. For example, Linksys WRT350N
|
|
|
|
* seems to have a byteorder bug that breaks this negotiation.
|
|
|
|
* In order to interoperate with existing implementations,
|
|
|
|
* assume that the Enrollee supports everything we do.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
|
|
|
|
"does not advertise supported encryption types "
|
|
|
|
"correctly");
|
|
|
|
wps->encr_type = wps->wps->encr_types;
|
|
|
|
#else /* WPS_WORKAROUNDS */
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
2009-05-06 09:56:18 +02:00
|
|
|
#endif /* WPS_WORKAROUNDS */
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
|
|
|
|
{
|
|
|
|
if (conn == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Connection Type flags "
|
|
|
|
"received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Connection Type flags 0x%x",
|
|
|
|
*conn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
|
|
|
|
{
|
|
|
|
u16 m;
|
|
|
|
|
|
|
|
if (methods == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Config Methods received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m = WPA_GET_BE16(methods);
|
|
|
|
|
2009-12-21 11:58:02 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x"
|
|
|
|
"%s%s%s%s%s%s%s%s%s", m,
|
|
|
|
m & WPS_CONFIG_USBA ? " [USBA]" : "",
|
|
|
|
m & WPS_CONFIG_ETHERNET ? " [Ethernet]" : "",
|
|
|
|
m & WPS_CONFIG_LABEL ? " [Label]" : "",
|
|
|
|
m & WPS_CONFIG_DISPLAY ? " [Display]" : "",
|
|
|
|
m & WPS_CONFIG_EXT_NFC_TOKEN ? " [Ext NFC Token]" : "",
|
|
|
|
m & WPS_CONFIG_INT_NFC_TOKEN ? " [Int NFC Token]" : "",
|
|
|
|
m & WPS_CONFIG_NFC_INTERFACE ? " [NFC]" : "",
|
|
|
|
m & WPS_CONFIG_PUSHBUTTON ? " [PBC]" : "",
|
|
|
|
m & WPS_CONFIG_KEYPAD ? " [Keypad]" : "");
|
|
|
|
|
|
|
|
if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
|
|
|
|
/*
|
|
|
|
* The Enrollee does not have a display so it is unlikely to be
|
|
|
|
* able to show the passphrase to a user and as such, could
|
|
|
|
* benefit from receiving PSK to reduce key derivation time.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Prefer PSK format key due to "
|
|
|
|
"Enrollee not supporting display");
|
|
|
|
wps->use_psk_key = 1;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
|
|
|
|
{
|
|
|
|
if (state == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Wi-Fi Protected Setup State "
|
|
|
|
"received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Wi-Fi Protected Setup State %d",
|
|
|
|
*state);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
|
|
|
|
{
|
|
|
|
u16 a;
|
|
|
|
|
|
|
|
if (assoc == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Association State received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = WPA_GET_BE16(assoc);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_process_config_error(struct wps_data *wps, const u8 *err)
|
|
|
|
{
|
|
|
|
u16 e;
|
|
|
|
|
|
|
|
if (err == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
e = WPA_GET_BE16(err);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-07 17:28:36 +01:00
|
|
|
static int wps_registrar_p2p_dev_addr_match(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wps_registrar *reg = wps->wps->registrar;
|
|
|
|
|
|
|
|
if (is_zero_ether_addr(reg->p2p_dev_addr))
|
|
|
|
return 1; /* no filtering in use */
|
|
|
|
|
|
|
|
if (os_memcmp(reg->p2p_dev_addr, wps->p2p_dev_addr, ETH_ALEN) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No match on P2P Device Address "
|
|
|
|
"filtering for PBC: expected " MACSTR " was "
|
|
|
|
MACSTR " - indicate PBC session overlap",
|
|
|
|
MAC2STR(reg->p2p_dev_addr),
|
|
|
|
MAC2STR(wps->p2p_dev_addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 17:51:00 +01:00
|
|
|
static int wps_registrar_skip_overlap(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct wps_registrar *reg = wps->wps->registrar;
|
|
|
|
|
|
|
|
if (is_zero_ether_addr(reg->p2p_dev_addr))
|
|
|
|
return 0; /* no specific Enrollee selected */
|
|
|
|
|
|
|
|
if (os_memcmp(reg->p2p_dev_addr, wps->p2p_dev_addr, ETH_ALEN) == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Skip PBC overlap due to selected "
|
|
|
|
"Enrollee match");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static enum wps_process_res wps_process_m1(struct wps_data *wps,
|
|
|
|
struct wps_parse_attr *attr)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received M1");
|
|
|
|
|
|
|
|
if (wps->state != RECV_M1) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
|
|
|
|
"receiving M1", wps->state);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_process_uuid_e(wps, attr->uuid_e) ||
|
|
|
|
wps_process_mac_addr(wps, attr->mac_addr) ||
|
|
|
|
wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
|
|
|
|
wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
|
|
|
|
wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
|
|
|
|
wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
|
|
|
|
wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
|
|
|
|
wps_process_config_methods(wps, attr->config_methods) ||
|
|
|
|
wps_process_wps_state(wps, attr->wps_state) ||
|
|
|
|
wps_process_device_attrs(&wps->peer_dev, attr) ||
|
2008-11-29 11:59:43 +01:00
|
|
|
wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_process_assoc_state(wps, attr->assoc_state) ||
|
|
|
|
wps_process_dev_password_id(wps, attr->dev_password_id) ||
|
|
|
|
wps_process_config_error(wps, attr->config_error) ||
|
|
|
|
wps_process_os_version(&wps->peer_dev, attr->os_version))
|
|
|
|
return WPS_FAILURE;
|
|
|
|
|
2009-02-26 20:57:38 +01:00
|
|
|
if (wps->dev_pw_id < 0x10 &&
|
|
|
|
wps->dev_pw_id != DEV_PW_DEFAULT &&
|
2014-09-11 17:27:44 +02:00
|
|
|
wps->dev_pw_id != DEV_PW_P2PS_DEFAULT &&
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
|
|
|
|
wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
|
|
|
|
wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
|
2013-04-02 17:30:58 +02:00
|
|
|
#ifdef CONFIG_WPS_NFC
|
|
|
|
wps->dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER &&
|
|
|
|
#endif /* CONFIG_WPS_NFC */
|
2009-01-03 19:09:35 +01:00
|
|
|
(wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
|
|
|
|
!wps->wps->registrar->pbc)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unsupported Device Password ID %d",
|
|
|
|
wps->dev_pw_id);
|
|
|
|
wps->state = SEND_M2D;
|
|
|
|
return WPS_CONTINUE;
|
2009-02-26 20:57:38 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 21:15:55 +02:00
|
|
|
#ifdef CONFIG_WPS_NFC
|
2013-04-02 17:30:58 +02:00
|
|
|
if (wps->dev_pw_id >= 0x10 ||
|
|
|
|
wps->dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) {
|
2012-06-27 21:15:55 +02:00
|
|
|
struct wps_nfc_pw_token *token;
|
|
|
|
const u8 *addr[1];
|
|
|
|
u8 hash[WPS_HASH_LEN];
|
|
|
|
|
2013-09-08 17:09:38 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Searching for NFC token match for id=%d (ctx %p registrar %p)",
|
|
|
|
wps->dev_pw_id, wps->wps, wps->wps->registrar);
|
2012-06-27 21:15:55 +02:00
|
|
|
token = wps_get_nfc_pw_token(
|
|
|
|
&wps->wps->registrar->nfc_pw_tokens, wps->dev_pw_id);
|
2013-04-27 17:50:14 +02:00
|
|
|
if (token && token->peer_pk_hash_known) {
|
2015-09-07 21:56:40 +02:00
|
|
|
size_t len;
|
|
|
|
|
2012-06-27 21:15:55 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Found matching NFC "
|
|
|
|
"Password Token");
|
|
|
|
dl_list_del(&token->list);
|
|
|
|
wps->nfc_pw_token = token;
|
|
|
|
|
|
|
|
addr[0] = attr->public_key;
|
2015-09-07 21:56:40 +02:00
|
|
|
len = attr->public_key_len;
|
|
|
|
sha256_vector(1, addr, &len, hash);
|
2014-06-29 18:38:17 +02:00
|
|
|
if (os_memcmp_const(hash,
|
|
|
|
wps->nfc_pw_token->pubkey_hash,
|
|
|
|
WPS_OOB_PUBKEY_HASH_LEN) != 0) {
|
2012-06-27 21:15:55 +02:00
|
|
|
wpa_printf(MSG_ERROR, "WPS: Public Key hash "
|
|
|
|
"mismatch");
|
2013-04-13 20:15:36 +02:00
|
|
|
wps->state = SEND_M2D;
|
|
|
|
wps->config_error =
|
|
|
|
WPS_CFG_PUBLIC_KEY_HASH_MISMATCH;
|
|
|
|
return WPS_CONTINUE;
|
2012-06-27 21:15:55 +02:00
|
|
|
}
|
2013-04-27 17:50:14 +02:00
|
|
|
} else if (token) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Found matching NFC "
|
|
|
|
"Password Token (no peer PK hash)");
|
|
|
|
wps->nfc_pw_token = token;
|
2013-09-08 17:08:26 +02:00
|
|
|
} else if (wps->dev_pw_id >= 0x10 &&
|
|
|
|
wps->wps->ap_nfc_dev_pw_id == wps->dev_pw_id &&
|
|
|
|
wps->wps->ap_nfc_dev_pw) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Found match with own NFC Password Token");
|
2012-06-27 21:15:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_NFC */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
|
2011-03-10 17:51:00 +01:00
|
|
|
if ((wps->wps->registrar->force_pbc_overlap ||
|
|
|
|
wps_registrar_pbc_overlap(wps->wps->registrar,
|
|
|
|
wps->mac_addr_e, wps->uuid_e) ||
|
|
|
|
!wps_registrar_p2p_dev_addr_match(wps)) &&
|
|
|
|
!wps_registrar_skip_overlap(wps)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PBC overlap - deny PBC "
|
|
|
|
"negotiation");
|
|
|
|
wps->state = SEND_M2D;
|
2009-11-01 19:57:36 +01:00
|
|
|
wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
|
2009-11-01 20:26:13 +01:00
|
|
|
wps_pbc_overlap_event(wps->wps);
|
2011-02-07 17:28:36 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M1,
|
|
|
|
WPS_CFG_MULTIPLE_PBC_DETECTED,
|
2013-08-23 15:01:55 +02:00
|
|
|
WPS_EI_NO_ERROR, wps->mac_addr_e);
|
2009-11-01 20:59:30 +01:00
|
|
|
wps->wps->registrar->force_pbc_overlap = 1;
|
2008-11-23 18:34:26 +01:00
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_registrar_add_pbc_session(wps->wps->registrar,
|
|
|
|
wps->mac_addr_e, wps->uuid_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->pbc = 1;
|
|
|
|
}
|
|
|
|
|
2010-07-06 00:37:47 +02:00
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
/*
|
|
|
|
* It looks like Mac OS X 10.6.3 and 10.6.4 do not like Network Key in
|
|
|
|
* passphrase format. To avoid interop issues, force PSK format to be
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
if (!wps->use_psk_key &&
|
|
|
|
wps->peer_dev.manufacturer &&
|
|
|
|
os_strncmp(wps->peer_dev.manufacturer, "Apple ", 6) == 0 &&
|
|
|
|
wps->peer_dev.model_name &&
|
|
|
|
os_strcmp(wps->peer_dev.model_name, "AirPort") == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Workaround - Force Network Key in "
|
|
|
|
"PSK format");
|
|
|
|
wps->use_psk_key = 1;
|
|
|
|
}
|
|
|
|
#endif /* WPS_WORKAROUNDS */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->state = SEND_M2;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum wps_process_res wps_process_m3(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg,
|
|
|
|
struct wps_parse_attr *attr)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received M3");
|
|
|
|
|
|
|
|
if (wps->state != RECV_M3) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
|
|
|
|
"receiving M3", wps->state);
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2011-03-10 17:51:00 +01:00
|
|
|
if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
|
|
|
|
!wps_registrar_skip_overlap(wps)) {
|
2009-11-01 20:59:30 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
|
|
|
|
"session overlap");
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
|
|
|
|
wps_process_authenticator(wps, attr->authenticator, msg) ||
|
|
|
|
wps_process_e_hash1(wps, attr->e_hash1) ||
|
2008-12-16 21:37:55 +01:00
|
|
|
wps_process_e_hash2(wps, attr->e_hash2)) {
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wps->state = SEND_M4;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum wps_process_res wps_process_m5(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg,
|
|
|
|
struct wps_parse_attr *attr)
|
|
|
|
{
|
|
|
|
struct wpabuf *decrypted;
|
|
|
|
struct wps_parse_attr eattr;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received M5");
|
|
|
|
|
|
|
|
if (wps->state != RECV_M5) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
|
|
|
|
"receiving M5", wps->state);
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2011-03-10 17:51:00 +01:00
|
|
|
if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
|
|
|
|
!wps_registrar_skip_overlap(wps)) {
|
2009-11-01 20:59:30 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
|
|
|
|
"session overlap");
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
|
2008-12-16 21:37:55 +01:00
|
|
|
wps_process_authenticator(wps, attr->authenticator, msg)) {
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
|
|
|
|
attr->encr_settings_len);
|
|
|
|
if (decrypted == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
|
|
|
|
"Settings attribute");
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2010-09-23 04:17:13 +02:00
|
|
|
if (wps_validate_m5_encr(decrypted, attr->version2 != NULL) < 0) {
|
2010-05-26 16:16:14 +02:00
|
|
|
wpabuf_free(decrypted);
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
|
|
|
|
"attribute");
|
|
|
|
if (wps_parse_msg(decrypted, &eattr) < 0 ||
|
|
|
|
wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
|
|
|
|
wps_process_e_snonce1(wps, eattr.e_snonce1)) {
|
|
|
|
wpabuf_free(decrypted);
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
wpabuf_free(decrypted);
|
|
|
|
|
|
|
|
wps->state = SEND_M6;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-10 14:53:35 +02:00
|
|
|
static void wps_sta_cred_cb(struct wps_data *wps)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Update credential to only include a single authentication and
|
|
|
|
* encryption type in case the AP configuration includes more than one
|
|
|
|
* option.
|
|
|
|
*/
|
|
|
|
if (wps->cred.auth_type & WPS_AUTH_WPA2PSK)
|
|
|
|
wps->cred.auth_type = WPS_AUTH_WPA2PSK;
|
|
|
|
else if (wps->cred.auth_type & WPS_AUTH_WPAPSK)
|
|
|
|
wps->cred.auth_type = WPS_AUTH_WPAPSK;
|
|
|
|
if (wps->cred.encr_type & WPS_ENCR_AES)
|
|
|
|
wps->cred.encr_type = WPS_ENCR_AES;
|
|
|
|
else if (wps->cred.encr_type & WPS_ENCR_TKIP)
|
|
|
|
wps->cred.encr_type = WPS_ENCR_TKIP;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Update local configuration based on the "
|
|
|
|
"AP configuration");
|
|
|
|
if (wps->wps->cred_cb)
|
|
|
|
wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-06 12:58:15 +02:00
|
|
|
static void wps_cred_update(struct wps_credential *dst,
|
|
|
|
struct wps_credential *src)
|
|
|
|
{
|
|
|
|
os_memcpy(dst->ssid, src->ssid, sizeof(dst->ssid));
|
|
|
|
dst->ssid_len = src->ssid_len;
|
|
|
|
dst->auth_type = src->auth_type;
|
|
|
|
dst->encr_type = src->encr_type;
|
|
|
|
dst->key_idx = src->key_idx;
|
|
|
|
os_memcpy(dst->key, src->key, sizeof(dst->key));
|
|
|
|
dst->key_len = src->key_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-27 19:32:39 +01:00
|
|
|
static int wps_process_ap_settings_r(struct wps_data *wps,
|
|
|
|
struct wps_parse_attr *attr)
|
|
|
|
{
|
2011-10-30 21:10:40 +01:00
|
|
|
struct wpabuf *msg;
|
|
|
|
|
2009-11-15 17:54:37 +01:00
|
|
|
if (wps->wps->ap || wps->er)
|
2008-11-27 19:32:39 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* AP Settings Attributes in M7 when Enrollee is an AP */
|
2008-11-27 20:14:39 +01:00
|
|
|
if (wps_process_ap_settings(attr, &wps->cred) < 0)
|
2008-11-27 19:32:39 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
|
|
|
|
|
2009-09-06 12:58:15 +02:00
|
|
|
if (wps->new_ap_settings) {
|
|
|
|
wpa_printf(MSG_INFO, "WPS: Update AP configuration based on "
|
|
|
|
"new settings");
|
|
|
|
wps_cred_update(&wps->cred, wps->new_ap_settings);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Use the AP PIN only to receive the current AP settings, not
|
|
|
|
* to reconfigure the AP.
|
|
|
|
*/
|
2010-09-23 23:45:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear selected registrar here since we do not get to
|
|
|
|
* WSC_Done in this protocol run.
|
|
|
|
*/
|
|
|
|
wps_registrar_pin_completed(wps->wps->registrar);
|
|
|
|
|
2011-10-30 21:10:40 +01:00
|
|
|
msg = wps_build_ap_cred(wps);
|
|
|
|
if (msg == NULL)
|
|
|
|
return -1;
|
|
|
|
wps->cred.cred_attr = wpabuf_head(msg);
|
|
|
|
wps->cred.cred_attr_len = wpabuf_len(msg);
|
|
|
|
|
2009-11-15 21:27:06 +01:00
|
|
|
if (wps->ap_settings_cb) {
|
|
|
|
wps->ap_settings_cb(wps->ap_settings_cb_ctx,
|
|
|
|
&wps->cred);
|
2011-10-30 21:10:40 +01:00
|
|
|
wpabuf_free(msg);
|
2009-11-15 21:27:06 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2009-09-06 12:58:15 +02:00
|
|
|
wps_sta_cred_cb(wps);
|
2011-10-30 21:10:40 +01:00
|
|
|
|
|
|
|
wps->cred.cred_attr = NULL;
|
|
|
|
wps->cred.cred_attr_len = 0;
|
|
|
|
wpabuf_free(msg);
|
|
|
|
|
2009-09-06 12:58:15 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2008-11-27 19:32:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static enum wps_process_res wps_process_m7(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg,
|
|
|
|
struct wps_parse_attr *attr)
|
|
|
|
{
|
|
|
|
struct wpabuf *decrypted;
|
|
|
|
struct wps_parse_attr eattr;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received M7");
|
|
|
|
|
|
|
|
if (wps->state != RECV_M7) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
|
|
|
|
"receiving M7", wps->state);
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2011-03-10 17:51:00 +01:00
|
|
|
if (wps->pbc && wps->wps->registrar->force_pbc_overlap &&
|
|
|
|
!wps_registrar_skip_overlap(wps)) {
|
2009-11-01 20:59:30 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
|
|
|
|
"session overlap");
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
|
2008-12-16 21:37:55 +01:00
|
|
|
wps_process_authenticator(wps, attr->authenticator, msg)) {
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
|
|
|
|
attr->encr_settings_len);
|
|
|
|
if (decrypted == NULL) {
|
2009-11-15 17:54:37 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt Encrypted "
|
2008-11-23 18:34:26 +01:00
|
|
|
"Settings attribute");
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2010-09-23 04:17:13 +02:00
|
|
|
if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er,
|
|
|
|
attr->version2 != NULL) < 0) {
|
2010-05-26 16:16:14 +02:00
|
|
|
wpabuf_free(decrypted);
|
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
|
|
|
|
"attribute");
|
|
|
|
if (wps_parse_msg(decrypted, &eattr) < 0 ||
|
|
|
|
wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
|
2008-11-27 19:32:39 +01:00
|
|
|
wps_process_e_snonce2(wps, eattr.e_snonce2) ||
|
|
|
|
wps_process_ap_settings_r(wps, &eattr)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_free(decrypted);
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
2008-11-27 19:32:39 +01:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
wpabuf_free(decrypted);
|
|
|
|
|
|
|
|
wps->state = SEND_M8;
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
enum wps_process_res ret = WPS_CONTINUE;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
|
|
|
|
|
|
|
|
if (wps_parse_msg(msg, &attr) < 0)
|
|
|
|
return WPS_FAILURE;
|
|
|
|
|
|
|
|
if (attr.msg_type == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
|
2010-11-04 17:17:00 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
return WPS_CONTINUE;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*attr.msg_type != WPS_M1 &&
|
|
|
|
(attr.registrar_nonce == NULL ||
|
|
|
|
os_memcmp(wps->nonce_r, attr.registrar_nonce,
|
2012-08-13 18:50:33 +02:00
|
|
|
WPS_NONCE_LEN) != 0)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*attr.msg_type) {
|
|
|
|
case WPS_M1:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_m1(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
if (wps->wps->wps_upnp && attr.mac_addr) {
|
|
|
|
/* Remove old pending messages when starting new run */
|
2009-02-06 20:39:32 +01:00
|
|
|
wps_free_pending_msgs(wps->wps->upnp_msgs);
|
|
|
|
wps->wps->upnp_msgs = NULL;
|
2009-01-29 17:47:02 +01:00
|
|
|
|
|
|
|
upnp_wps_device_send_wlan_event(
|
|
|
|
wps->wps->wps_upnp, attr.mac_addr,
|
|
|
|
UPNP_WPS_WLANEVENT_TYPE_EAP, msg);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2008-11-23 18:34:26 +01:00
|
|
|
ret = wps_process_m1(wps, &attr);
|
|
|
|
break;
|
|
|
|
case WPS_M3:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_m3(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2008-11-23 18:34:26 +01:00
|
|
|
ret = wps_process_m3(wps, msg, &attr);
|
2008-12-19 21:19:41 +01:00
|
|
|
if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M3, wps->config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
break;
|
|
|
|
case WPS_M5:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_m5(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2008-11-23 18:34:26 +01:00
|
|
|
ret = wps_process_m5(wps, msg, &attr);
|
2008-12-19 21:19:41 +01:00
|
|
|
if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M5, wps->config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
break;
|
|
|
|
case WPS_M7:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_m7(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2008-11-23 18:34:26 +01:00
|
|
|
ret = wps_process_m7(wps, msg, &attr);
|
2008-12-19 21:19:41 +01:00
|
|
|
if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M7, wps->config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
|
|
|
|
*attr.msg_type);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == WPS_CONTINUE) {
|
|
|
|
/* Save a copy of the last message for Authenticator derivation
|
|
|
|
*/
|
|
|
|
wpabuf_free(wps->last_msg);
|
|
|
|
wps->last_msg = wpabuf_dup(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
|
|
|
|
|
|
|
|
if (wps_parse_msg(msg, &attr) < 0)
|
|
|
|
return WPS_FAILURE;
|
|
|
|
|
|
|
|
if (attr.msg_type == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*attr.msg_type != WPS_WSC_ACK) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
|
|
|
|
*attr.msg_type);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
|
|
|
|
upnp_wps_subscribers(wps->wps->wps_upnp)) {
|
2009-02-06 20:39:32 +01:00
|
|
|
if (wps->wps->upnp_msgs)
|
2009-01-29 17:47:02 +01:00
|
|
|
return WPS_CONTINUE;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
|
|
|
|
"external Registrar");
|
|
|
|
return WPS_PENDING;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (attr.registrar_nonce == NULL ||
|
2012-08-13 18:50:33 +02:00
|
|
|
os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.enrollee_nonce == NULL ||
|
2012-08-13 18:50:33 +02:00
|
|
|
os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps->state == RECV_M2D_ACK) {
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
if (wps->wps->wps_upnp &&
|
|
|
|
upnp_wps_subscribers(wps->wps->wps_upnp)) {
|
2009-02-06 20:39:32 +01:00
|
|
|
if (wps->wps->upnp_msgs)
|
2009-01-29 17:47:02 +01:00
|
|
|
return WPS_CONTINUE;
|
2009-02-06 20:39:32 +01:00
|
|
|
if (wps->ext_reg == 0)
|
|
|
|
wps->ext_reg = 1;
|
2009-01-29 17:47:02 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
|
|
|
|
"external Registrar");
|
|
|
|
return WPS_PENDING;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No more registrars available - "
|
|
|
|
"terminate negotiation");
|
|
|
|
}
|
|
|
|
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
2008-12-19 21:19:41 +01:00
|
|
|
int old_state;
|
2010-10-14 19:49:54 +02:00
|
|
|
u16 config_error;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
|
|
|
|
|
2008-12-19 21:19:41 +01:00
|
|
|
old_state = wps->state;
|
2008-12-16 21:37:55 +01:00
|
|
|
wps->state = SEND_WSC_NACK;
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_parse_msg(msg, &attr) < 0)
|
|
|
|
return WPS_FAILURE;
|
|
|
|
|
|
|
|
if (attr.msg_type == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*attr.msg_type != WPS_WSC_NACK) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
|
|
|
|
*attr.msg_type);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
if (wps->wps->wps_upnp && wps->ext_reg) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
|
|
|
|
"Registrar terminated by the Enrollee");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (attr.registrar_nonce == NULL ||
|
2012-08-13 18:50:33 +02:00
|
|
|
os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.enrollee_nonce == NULL ||
|
2012-08-13 18:50:33 +02:00
|
|
|
os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.config_error == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
|
|
|
|
"in WSC_NACK");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-10-14 19:49:54 +02:00
|
|
|
config_error = WPA_GET_BE16(attr.config_error);
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
|
2010-10-14 19:49:54 +02:00
|
|
|
"Configuration Error %d", config_error);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2008-12-19 21:19:41 +01:00
|
|
|
switch (old_state) {
|
|
|
|
case RECV_M3:
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M2, config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-12-19 21:19:41 +01:00
|
|
|
break;
|
|
|
|
case RECV_M5:
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M4, config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-12-19 21:19:41 +01:00
|
|
|
break;
|
|
|
|
case RECV_M7:
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M6, config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-12-19 21:19:41 +01:00
|
|
|
break;
|
|
|
|
case RECV_DONE:
|
2011-01-13 16:50:59 +01:00
|
|
|
wps_fail_event(wps->wps, WPS_M8, config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-12-19 21:19:41 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
|
|
|
|
const struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done");
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
if (wps->state != RECV_DONE &&
|
|
|
|
(!wps->wps->wps_upnp || !wps->ext_reg)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
|
|
|
|
"receiving WSC_Done", wps->state);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_parse_msg(msg, &attr) < 0)
|
|
|
|
return WPS_FAILURE;
|
|
|
|
|
|
|
|
if (attr.msg_type == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*attr.msg_type != WPS_WSC_DONE) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
|
|
|
|
*attr.msg_type);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
if (wps->wps->wps_upnp && wps->ext_reg) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
|
|
|
|
"Registrar completed successfully");
|
2009-09-07 21:09:13 +02:00
|
|
|
wps_device_store(wps->wps->registrar, &wps->peer_dev,
|
|
|
|
wps->uuid_e);
|
2009-01-29 17:47:02 +01:00
|
|
|
return WPS_DONE;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (attr.registrar_nonce == NULL ||
|
2012-08-13 18:50:33 +02:00
|
|
|
os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN) != 0)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.enrollee_nonce == NULL ||
|
2012-08-13 18:50:33 +02:00
|
|
|
os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN) != 0) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
|
2009-09-07 21:09:13 +02:00
|
|
|
wps_device_store(wps->wps->registrar, &wps->peer_dev,
|
|
|
|
wps->uuid_e);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
|
2009-01-21 12:48:10 +01:00
|
|
|
wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
|
2008-11-23 18:34:26 +01:00
|
|
|
struct wps_credential cred;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based "
|
|
|
|
"on first Enrollee connection");
|
|
|
|
|
|
|
|
os_memset(&cred, 0, sizeof(cred));
|
|
|
|
os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
|
|
|
|
cred.ssid_len = wps->wps->ssid_len;
|
2015-04-27 19:42:08 +02:00
|
|
|
if (wps->wps->rf_band_cb(wps->wps->cb_ctx) == WPS_RF_60GHZ) {
|
|
|
|
cred.auth_type = WPS_AUTH_WPA2PSK;
|
|
|
|
cred.encr_type = WPS_ENCR_AES;
|
|
|
|
} else {
|
|
|
|
cred.auth_type = WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK;
|
|
|
|
cred.encr_type = WPS_ENCR_TKIP | WPS_ENCR_AES;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
|
|
|
|
cred.key_len = wps->new_psk_len;
|
|
|
|
|
|
|
|
wps->wps->wps_state = WPS_STATE_CONFIGURED;
|
|
|
|
wpa_hexdump_ascii_key(MSG_DEBUG,
|
|
|
|
"WPS: Generated random passphrase",
|
|
|
|
wps->new_psk, wps->new_psk_len);
|
|
|
|
if (wps->wps->cred_cb)
|
|
|
|
wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
|
|
|
|
|
|
|
|
os_free(wps->new_psk);
|
|
|
|
wps->new_psk = NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-15 21:46:30 +01:00
|
|
|
if (!wps->wps->ap && !wps->er)
|
2009-06-10 14:53:35 +02:00
|
|
|
wps_sta_cred_cb(wps);
|
2008-11-27 20:23:43 +01:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps->new_psk) {
|
2009-01-03 19:09:35 +01:00
|
|
|
if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
|
2013-09-01 09:47:34 +02:00
|
|
|
wps->p2p_dev_addr, wps->new_psk,
|
|
|
|
wps->new_psk_len)) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Failed to configure the "
|
|
|
|
"new PSK");
|
|
|
|
}
|
|
|
|
os_free(wps->new_psk);
|
|
|
|
wps->new_psk = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-29 19:42:48 +01:00
|
|
|
wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e,
|
|
|
|
wps->dev_password, wps->dev_password_len);
|
2009-01-21 12:48:10 +01:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps->pbc) {
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_registrar_remove_pbc_session(wps->wps->registrar,
|
2011-12-11 11:03:18 +01:00
|
|
|
wps->uuid_e,
|
|
|
|
wps->p2p_dev_addr);
|
2009-01-03 19:09:35 +01:00
|
|
|
wps_registrar_pbc_completed(wps->wps->registrar);
|
2013-12-16 21:08:37 +01:00
|
|
|
#ifdef WPS_WORKAROUNDS
|
|
|
|
os_get_reltime(&wps->wps->registrar->pbc_ignore_start);
|
|
|
|
#endif /* WPS_WORKAROUNDS */
|
2012-11-15 18:59:04 +01:00
|
|
|
os_memcpy(wps->wps->registrar->pbc_ignore_uuid, wps->uuid_e,
|
|
|
|
WPS_UUID_LEN);
|
2009-11-01 21:19:02 +01:00
|
|
|
} else {
|
|
|
|
wps_registrar_pin_completed(wps->wps->registrar);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
2009-12-12 15:40:10 +01:00
|
|
|
/* TODO: maintain AuthorizedMACs somewhere separately for each ER and
|
|
|
|
* merge them into APs own list.. */
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2013-08-23 15:01:55 +02:00
|
|
|
wps_success_event(wps->wps, wps->mac_addr_e);
|
2008-12-19 21:34:18 +01:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
return WPS_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
|
2009-01-03 18:50:49 +01:00
|
|
|
enum wsc_op_code op_code,
|
2008-11-23 18:34:26 +01:00
|
|
|
const struct wpabuf *msg)
|
|
|
|
{
|
2008-12-19 21:19:41 +01:00
|
|
|
enum wps_process_res ret;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
|
|
|
|
"op_code=%d)",
|
|
|
|
(unsigned long) wpabuf_len(msg), op_code);
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
2009-02-06 20:39:32 +01:00
|
|
|
if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) {
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type &&
|
|
|
|
*attr.msg_type == WPS_M3)
|
|
|
|
wps->ext_reg = 2; /* past M2/M2D phase */
|
|
|
|
}
|
|
|
|
if (wps->ext_reg > 1)
|
|
|
|
wps_registrar_free_pending_m2(wps->wps);
|
|
|
|
if (wps->wps->wps_upnp && wps->ext_reg &&
|
|
|
|
wps->wps->upnp_msgs == NULL &&
|
2009-11-13 21:40:07 +01:00
|
|
|
(op_code == WSC_MSG || op_code == WSC_Done || op_code == WSC_NACK))
|
|
|
|
{
|
2009-01-29 17:47:02 +01:00
|
|
|
struct wps_parse_attr attr;
|
|
|
|
int type;
|
|
|
|
if (wps_parse_msg(msg, &attr) < 0 || attr.msg_type == NULL)
|
|
|
|
type = -1;
|
|
|
|
else
|
|
|
|
type = *attr.msg_type;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)"
|
|
|
|
" to external Registrar for processing", type);
|
|
|
|
upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
|
|
|
|
wps->mac_addr_e,
|
|
|
|
UPNP_WPS_WLANEVENT_TYPE_EAP,
|
|
|
|
msg);
|
|
|
|
if (op_code == WSC_MSG)
|
|
|
|
return WPS_PENDING;
|
|
|
|
} else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using "
|
|
|
|
"external Registrar");
|
|
|
|
return WPS_CONTINUE;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
switch (op_code) {
|
|
|
|
case WSC_MSG:
|
|
|
|
return wps_process_wsc_msg(wps, msg);
|
|
|
|
case WSC_ACK:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_wsc_ack(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2008-11-23 18:34:26 +01:00
|
|
|
return wps_process_wsc_ack(wps, msg);
|
|
|
|
case WSC_NACK:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_wsc_nack(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2008-11-23 18:34:26 +01:00
|
|
|
return wps_process_wsc_nack(wps, msg);
|
|
|
|
case WSC_Done:
|
2010-05-26 16:16:14 +02:00
|
|
|
if (wps_validate_wsc_done(msg) < 0)
|
|
|
|
return WPS_FAILURE;
|
2008-12-19 21:19:41 +01:00
|
|
|
ret = wps_process_wsc_done(wps, msg);
|
|
|
|
if (ret == WPS_FAILURE) {
|
|
|
|
wps->state = SEND_WSC_NACK;
|
2010-10-14 19:49:54 +02:00
|
|
|
wps_fail_event(wps->wps, WPS_WSC_DONE,
|
2011-01-13 16:50:59 +01:00
|
|
|
wps->config_error,
|
2013-08-23 15:01:55 +02:00
|
|
|
wps->error_indication, wps->mac_addr_e);
|
2008-12-19 21:19:41 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2008-11-23 18:34:26 +01:00
|
|
|
default:
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
|
|
|
|
return WPS_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2009-01-23 20:57:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
int wps_registrar_update_ie(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
return wps_set_ie(reg);
|
|
|
|
}
|
2009-01-29 17:47:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void wps_registrar_set_selected_timeout(void *eloop_ctx,
|
|
|
|
void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wps_registrar *reg = eloop_ctx;
|
|
|
|
|
2009-12-12 15:54:59 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
|
|
|
|
"unselect internal Registrar");
|
2009-01-29 17:47:02 +01:00
|
|
|
reg->selected_registrar = 0;
|
|
|
|
reg->pbc = 0;
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-12-12 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
static void wps_registrar_sel_reg_add(struct wps_registrar *reg,
|
|
|
|
struct subscription *s)
|
|
|
|
{
|
2009-12-12 15:40:10 +01:00
|
|
|
int i, j;
|
2009-12-12 15:54:59 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: External Registrar selected (dev_pw_id=%d "
|
|
|
|
"config_methods=0x%x)",
|
|
|
|
s->dev_password_id, s->config_methods);
|
|
|
|
reg->sel_reg_union = 1;
|
|
|
|
if (reg->sel_reg_dev_password_id_override != DEV_PW_PUSHBUTTON)
|
|
|
|
reg->sel_reg_dev_password_id_override = s->dev_password_id;
|
|
|
|
if (reg->sel_reg_config_methods_override == -1)
|
|
|
|
reg->sel_reg_config_methods_override = 0;
|
|
|
|
reg->sel_reg_config_methods_override |= s->config_methods;
|
2009-12-12 15:40:10 +01:00
|
|
|
for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++)
|
|
|
|
if (is_zero_ether_addr(reg->authorized_macs_union[i]))
|
|
|
|
break;
|
|
|
|
for (j = 0; i < WPS_MAX_AUTHORIZED_MACS && j < WPS_MAX_AUTHORIZED_MACS;
|
|
|
|
j++) {
|
|
|
|
if (is_zero_ether_addr(s->authorized_macs[j]))
|
|
|
|
break;
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add authorized MAC into union: "
|
|
|
|
MACSTR, MAC2STR(s->authorized_macs[j]));
|
2009-12-12 15:40:10 +01:00
|
|
|
os_memcpy(reg->authorized_macs_union[i],
|
|
|
|
s->authorized_macs[j], ETH_ALEN);
|
|
|
|
i++;
|
|
|
|
}
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs union",
|
|
|
|
(u8 *) reg->authorized_macs_union,
|
|
|
|
sizeof(reg->authorized_macs_union));
|
2009-12-12 15:54:59 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_registrar_sel_reg_union(struct wps_registrar *reg)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
struct subscription *s;
|
|
|
|
|
|
|
|
if (reg->wps->wps_upnp == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-12-19 13:15:43 +01:00
|
|
|
dl_list_for_each(s, ®->wps->wps_upnp->subscriptions,
|
|
|
|
struct subscription, list) {
|
2009-12-19 12:47:00 +01:00
|
|
|
struct subscr_addr *sa;
|
|
|
|
sa = dl_list_first(&s->addr_list, struct subscr_addr, list);
|
|
|
|
if (sa) {
|
2009-12-12 15:54:59 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: External Registrar %s:%d",
|
2009-12-19 12:47:00 +01:00
|
|
|
inet_ntoa(sa->saddr.sin_addr),
|
|
|
|
ntohs(sa->saddr.sin_port));
|
|
|
|
}
|
2009-12-12 15:54:59 +01:00
|
|
|
if (s->selected_registrar)
|
|
|
|
wps_registrar_sel_reg_add(reg, s);
|
|
|
|
else
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: External Registrar not "
|
|
|
|
"selected");
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2009-01-29 17:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 15:54:59 +01:00
|
|
|
* wps_registrar_selected_registrar_changed - SetSelectedRegistrar change
|
2009-01-29 17:47:02 +01:00
|
|
|
* @reg: Registrar data from wps_registrar_init()
|
|
|
|
*
|
2009-12-12 15:54:59 +01:00
|
|
|
* This function is called when selected registrar state changes, e.g., when an
|
|
|
|
* AP receives a SetSelectedRegistrar UPnP message.
|
2009-01-29 17:47:02 +01:00
|
|
|
*/
|
2013-04-02 17:27:36 +02:00
|
|
|
void wps_registrar_selected_registrar_changed(struct wps_registrar *reg,
|
|
|
|
u16 dev_pw_id)
|
2009-01-29 17:47:02 +01:00
|
|
|
{
|
2009-12-12 15:54:59 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Selected registrar information changed");
|
2009-01-29 17:47:02 +01:00
|
|
|
|
2009-12-12 15:54:59 +01:00
|
|
|
reg->sel_reg_union = reg->selected_registrar;
|
|
|
|
reg->sel_reg_dev_password_id_override = -1;
|
|
|
|
reg->sel_reg_config_methods_override = -1;
|
2009-12-12 15:40:10 +01:00
|
|
|
os_memcpy(reg->authorized_macs_union, reg->authorized_macs,
|
|
|
|
WPS_MAX_AUTHORIZED_MACS * ETH_ALEN);
|
2010-07-22 18:37:22 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs union (start with own)",
|
|
|
|
(u8 *) reg->authorized_macs_union,
|
|
|
|
sizeof(reg->authorized_macs_union));
|
2009-12-12 15:54:59 +01:00
|
|
|
if (reg->selected_registrar) {
|
2010-07-19 07:53:15 +02:00
|
|
|
u16 methods;
|
|
|
|
|
|
|
|
methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
|
|
|
|
methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON);
|
2009-12-12 15:54:59 +01:00
|
|
|
if (reg->pbc) {
|
|
|
|
reg->sel_reg_dev_password_id_override =
|
|
|
|
DEV_PW_PUSHBUTTON;
|
2010-07-19 07:53:15 +02:00
|
|
|
wps_set_pushbutton(&methods, reg->wps->config_methods);
|
2013-04-02 17:27:36 +02:00
|
|
|
} else if (dev_pw_id)
|
|
|
|
reg->sel_reg_dev_password_id_override = dev_pw_id;
|
2009-12-12 15:54:59 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
|
|
|
|
"(pbc=%d)", reg->pbc);
|
2010-07-19 07:53:15 +02:00
|
|
|
reg->sel_reg_config_methods_override = methods;
|
2009-12-12 15:54:59 +01:00
|
|
|
} else
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Internal Registrar not selected");
|
2009-01-29 17:47:02 +01:00
|
|
|
|
2009-12-12 15:54:59 +01:00
|
|
|
wps_registrar_sel_reg_union(reg);
|
2009-01-29 17:47:02 +01:00
|
|
|
|
|
|
|
wps_set_ie(reg);
|
2009-12-12 15:54:59 +01:00
|
|
|
wps_cb_set_sel_reg(reg);
|
2009-01-29 17:47:02 +01:00
|
|
|
}
|
2009-09-07 21:09:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
|
|
|
|
char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
struct wps_registrar_device *d;
|
|
|
|
int len = 0, ret;
|
|
|
|
char uuid[40];
|
2009-11-26 10:39:29 +01:00
|
|
|
char devtype[WPS_DEV_TYPE_BUFSIZE];
|
2009-09-07 21:09:13 +02:00
|
|
|
|
|
|
|
d = wps_device_get(reg, addr);
|
|
|
|
if (d == NULL)
|
|
|
|
return 0;
|
|
|
|
if (uuid_bin2str(d->uuid, uuid, sizeof(uuid)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = os_snprintf(buf + len, buflen - len,
|
|
|
|
"wpsUuid=%s\n"
|
2009-11-26 10:39:29 +01:00
|
|
|
"wpsPrimaryDeviceType=%s\n"
|
2009-09-07 21:09:13 +02:00
|
|
|
"wpsDeviceName=%s\n"
|
|
|
|
"wpsManufacturer=%s\n"
|
|
|
|
"wpsModelName=%s\n"
|
|
|
|
"wpsModelNumber=%s\n"
|
|
|
|
"wpsSerialNumber=%s\n",
|
|
|
|
uuid,
|
2009-11-26 10:39:29 +01:00
|
|
|
wps_dev_type_bin2str(d->dev.pri_dev_type, devtype,
|
|
|
|
sizeof(devtype)),
|
2009-09-07 21:09:13 +02:00
|
|
|
d->dev.device_name ? d->dev.device_name : "",
|
|
|
|
d->dev.manufacturer ? d->dev.manufacturer : "",
|
|
|
|
d->dev.model_name ? d->dev.model_name : "",
|
|
|
|
d->dev.model_number ? d->dev.model_number : "",
|
|
|
|
d->dev.serial_number ? d->dev.serial_number : "");
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(buflen - len, ret))
|
2009-09-07 21:09:13 +02:00
|
|
|
return len;
|
|
|
|
len += ret;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2010-10-21 15:49:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
int wps_registrar_config_ap(struct wps_registrar *reg,
|
|
|
|
struct wps_credential *cred)
|
|
|
|
{
|
2014-01-05 16:09:56 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: encr_type=0x%x", cred->encr_type);
|
2010-10-21 15:49:41 +02:00
|
|
|
if (!(cred->encr_type & (WPS_ENCR_NONE | WPS_ENCR_TKIP |
|
|
|
|
WPS_ENCR_AES))) {
|
|
|
|
if (cred->encr_type & WPS_ENCR_WEP) {
|
|
|
|
wpa_printf(MSG_INFO, "WPS: Reject new AP settings "
|
|
|
|
"due to WEP configuration");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "WPS: Reject new AP settings due to "
|
|
|
|
"invalid encr_type 0x%x", cred->encr_type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cred->encr_type & (WPS_ENCR_TKIP | WPS_ENCR_AES)) ==
|
|
|
|
WPS_ENCR_TKIP) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Upgrade encr_type TKIP -> "
|
|
|
|
"TKIP+AES");
|
|
|
|
cred->encr_type |= WPS_ENCR_AES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) ==
|
|
|
|
WPS_AUTH_WPAPSK) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Upgrade auth_type WPAPSK -> "
|
|
|
|
"WPAPSK+WPA2PSK");
|
|
|
|
cred->auth_type |= WPS_AUTH_WPA2PSK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg->wps->cred_cb)
|
|
|
|
return reg->wps->cred_cb(reg->wps->cb_ctx, cred);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2012-06-27 19:54:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_NFC
|
2012-06-27 21:15:55 +02:00
|
|
|
|
|
|
|
int wps_registrar_add_nfc_pw_token(struct wps_registrar *reg,
|
|
|
|
const u8 *pubkey_hash, u16 pw_id,
|
2013-02-24 16:30:18 +01:00
|
|
|
const u8 *dev_pw, size_t dev_pw_len,
|
|
|
|
int pk_hash_provided_oob)
|
2012-06-27 21:15:55 +02:00
|
|
|
{
|
|
|
|
struct wps_nfc_pw_token *token;
|
|
|
|
|
|
|
|
if (dev_pw_len > WPS_OOB_DEVICE_PASSWORD_LEN)
|
|
|
|
return -1;
|
|
|
|
|
2013-04-27 17:50:14 +02:00
|
|
|
if (pw_id == DEV_PW_NFC_CONNECTION_HANDOVER &&
|
|
|
|
(pubkey_hash == NULL || !pk_hash_provided_oob)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected NFC Password Token "
|
|
|
|
"addition - missing public key hash");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-27 21:15:55 +02:00
|
|
|
wps_free_nfc_pw_tokens(®->nfc_pw_tokens, pw_id);
|
|
|
|
|
|
|
|
token = os_zalloc(sizeof(*token));
|
|
|
|
if (token == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2013-04-27 17:50:14 +02:00
|
|
|
token->peer_pk_hash_known = pubkey_hash != NULL;
|
|
|
|
if (pubkey_hash)
|
|
|
|
os_memcpy(token->pubkey_hash, pubkey_hash,
|
|
|
|
WPS_OOB_PUBKEY_HASH_LEN);
|
2012-06-27 21:15:55 +02:00
|
|
|
token->pw_id = pw_id;
|
2013-02-24 16:30:18 +01:00
|
|
|
token->pk_hash_provided_oob = pk_hash_provided_oob;
|
2013-04-02 17:30:58 +02:00
|
|
|
if (dev_pw) {
|
|
|
|
wpa_snprintf_hex_uppercase((char *) token->dev_pw,
|
|
|
|
sizeof(token->dev_pw),
|
|
|
|
dev_pw, dev_pw_len);
|
|
|
|
token->dev_pw_len = dev_pw_len * 2;
|
|
|
|
}
|
2012-06-27 21:15:55 +02:00
|
|
|
|
|
|
|
dl_list_add(®->nfc_pw_tokens, &token->list);
|
|
|
|
|
|
|
|
reg->selected_registrar = 1;
|
|
|
|
reg->pbc = 0;
|
|
|
|
wps_registrar_add_authorized_mac(reg,
|
|
|
|
(u8 *) "\xff\xff\xff\xff\xff\xff");
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, pw_id);
|
2012-06-27 21:15:55 +02:00
|
|
|
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
|
|
|
|
eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
|
|
|
|
wps_registrar_set_selected_timeout,
|
|
|
|
reg, NULL);
|
|
|
|
|
2013-04-02 17:27:36 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Added NFC Device Password %u to Registrar",
|
|
|
|
pw_id);
|
|
|
|
|
2012-06-27 21:15:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-27 19:54:56 +02:00
|
|
|
int wps_registrar_add_nfc_password_token(struct wps_registrar *reg,
|
|
|
|
const u8 *oob_dev_pw,
|
|
|
|
size_t oob_dev_pw_len)
|
|
|
|
{
|
|
|
|
const u8 *pos, *hash, *dev_pw;
|
|
|
|
u16 id;
|
|
|
|
size_t dev_pw_len;
|
|
|
|
|
2013-04-02 17:30:58 +02:00
|
|
|
if (oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2 ||
|
2012-06-27 19:54:56 +02:00
|
|
|
oob_dev_pw_len > WPS_OOB_PUBKEY_HASH_LEN + 2 +
|
|
|
|
WPS_OOB_DEVICE_PASSWORD_LEN)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hash = oob_dev_pw;
|
|
|
|
pos = oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN;
|
|
|
|
id = WPA_GET_BE16(pos);
|
|
|
|
dev_pw = pos + 2;
|
|
|
|
dev_pw_len = oob_dev_pw + oob_dev_pw_len - dev_pw;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add NFC Password Token for Password ID %u",
|
|
|
|
id);
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Public Key Hash",
|
|
|
|
hash, WPS_OOB_PUBKEY_HASH_LEN);
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: Device Password", dev_pw, dev_pw_len);
|
|
|
|
|
2012-06-27 21:15:55 +02:00
|
|
|
return wps_registrar_add_nfc_pw_token(reg, hash, id, dev_pw,
|
2013-02-24 16:30:18 +01:00
|
|
|
dev_pw_len, 0);
|
2012-06-27 19:54:56 +02:00
|
|
|
}
|
2012-06-27 21:15:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
void wps_registrar_remove_nfc_pw_token(struct wps_registrar *reg,
|
|
|
|
struct wps_nfc_pw_token *token)
|
|
|
|
{
|
|
|
|
wps_registrar_remove_authorized_mac(reg,
|
|
|
|
(u8 *) "\xff\xff\xff\xff\xff\xff");
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2013-04-27 17:50:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the NFC password token if it was used only for a single protocol
|
|
|
|
* run. The static handover case uses the same password token multiple
|
|
|
|
* times, so do not free that case here.
|
|
|
|
*/
|
|
|
|
if (token->peer_pk_hash_known)
|
|
|
|
os_free(token);
|
2012-06-27 21:15:55 +02:00
|
|
|
}
|
|
|
|
|
2012-06-27 19:54:56 +02:00
|
|
|
#endif /* CONFIG_WPS_NFC */
|