#include "includes.h"
#include "common.h"
-#include "sha256.h"
-#include "ieee802_11_defs.h"
+#include "crypto/crypto.h"
+#include "crypto/sha256.h"
#include "wps_i.h"
-
-
-static int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Request Type");
- wpabuf_put_be16(msg, ATTR_REQUEST_TYPE);
- wpabuf_put_be16(msg, 1);
- wpabuf_put_u8(msg, type);
- return 0;
-}
-
-
-static int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid)
-{
- wpa_printf(MSG_DEBUG, "WPS: * UUID-E");
- wpabuf_put_be16(msg, ATTR_UUID_E);
- wpabuf_put_be16(msg, WPS_UUID_LEN);
- wpabuf_put_data(msg, uuid, WPS_UUID_LEN);
- return 0;
-}
+#include "wps_dev_attr.h"
static int wps_build_mac_addr(struct wps_data *wps, struct wpabuf *msg)
}
-static int wps_build_config_methods(struct wpabuf *msg, u16 methods)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Config Methods");
- wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
- wpabuf_put_be16(msg, 2);
- wpabuf_put_be16(msg, methods);
- return 0;
-}
-
-
static int wps_build_wps_state(struct wps_data *wps, struct wpabuf *msg)
{
- wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State");
+ u8 state;
+ if (wps->wps->ap)
+ state = wps->wps->wps_state;
+ else
+ state = WPS_STATE_NOT_CONFIGURED;
+ wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
+ state);
wpabuf_put_be16(msg, ATTR_WPS_STATE);
wpabuf_put_be16(msg, 1);
- wpabuf_put_u8(msg, WPS_STATE_CONFIGURED);
- return 0;
-}
-
-
-static int wps_build_manufacturer(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Manufacturer");
- wpabuf_put_be16(msg, ATTR_MANUFACTURER);
- wpabuf_put_be16(msg, 5);
- wpabuf_put_data(msg, "manuf", 5); /* FIX */
- return 0;
-}
-
-
-static int wps_build_model_name(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Model Name");
- wpabuf_put_be16(msg, ATTR_MODEL_NAME);
- wpabuf_put_be16(msg, 10);
- wpabuf_put_data(msg, "model name", 10); /* FIX */
- return 0;
-}
-
-
-static int wps_build_model_number(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Model Number");
- wpabuf_put_be16(msg, ATTR_MODEL_NUMBER);
- wpabuf_put_be16(msg, 12);
- wpabuf_put_data(msg, "model number", 12); /* FIX */
- return 0;
-}
-
-
-static int wps_build_serial_number(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Serial Number");
- wpabuf_put_be16(msg, ATTR_SERIAL_NUMBER);
- wpabuf_put_be16(msg, 5);
- wpabuf_put_data(msg, "12345", 5); /* FIX */
- return 0;
-}
-
-
-static int wps_build_primary_dev_type(struct wps_data *wps, struct wpabuf *msg)
-{
- struct wps_dev_type *dev;
- wpa_printf(MSG_DEBUG, "WPS: * Primary Device Type");
- wpabuf_put_be16(msg, ATTR_PRIMARY_DEV_TYPE);
- wpabuf_put_be16(msg, sizeof(*dev));
- dev = wpabuf_put(msg, sizeof(*dev));
- WPA_PUT_BE16(dev->categ_id, WPS_DEV_COMPUTER);
- WPA_PUT_BE32(dev->oui, WPS_DEV_OUI_WFA);
- WPA_PUT_BE16(dev->sub_categ_id, WPS_DEV_COMPUTER_PC);
- return 0;
-}
-
-
-static int wps_build_dev_name(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Device Name");
- wpabuf_put_be16(msg, ATTR_DEV_NAME);
- wpabuf_put_be16(msg, 8);
- wpabuf_put_data(msg, "dev name", 8); /* FIX */
- return 0;
-}
-
-
-static int wps_build_rf_bands(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * RF Bands");
- wpabuf_put_be16(msg, ATTR_RF_BANDS);
- wpabuf_put_be16(msg, 1);
- wpabuf_put_u8(msg, WPS_RF_24GHZ | WPS_RF_50GHZ);
- return 0;
-}
-
-
-static int wps_build_dev_password_id(struct wpabuf *msg, u16 id)
-{
- wpa_printf(MSG_DEBUG, "WPS: * Device Password ID");
- wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
- wpabuf_put_be16(msg, 2);
- wpabuf_put_be16(msg, id);
- return 0;
-}
-
-
-static int wps_build_config_error(struct wps_data *wps, struct wpabuf *msg)
-{
- u16 err = WPS_CFG_NO_ERROR;
- wpabuf_put_be16(msg, ATTR_CONFIG_ERROR);
- wpabuf_put_be16(msg, 2);
- if (wps && wps->authenticator && wps->wps->ap_setup_locked)
- err = WPS_CFG_SETUP_LOCKED;
- wpa_printf(MSG_DEBUG, "WPS: * Configuration Error (%d)", err);
- wpabuf_put_be16(msg, err);
- return 0;
-}
-
-
-static int wps_build_os_version(struct wps_data *wps, struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS: * OS Version");
- wpabuf_put_be16(msg, ATTR_OS_VERSION);
- wpabuf_put_be16(msg, 4);
- wpabuf_put_be32(msg, 0x80000000); /* FIX */
+ wpabuf_put_u8(msg, state);
return 0;
}
static struct wpabuf * wps_build_m1(struct wps_data *wps)
{
struct wpabuf *msg;
- u16 methods;
if (os_get_random(wps->nonce_e, WPS_NONCE_LEN) < 0)
return NULL;
if (msg == NULL)
return NULL;
- methods = WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD;
- if (wps->pbc)
- methods |= WPS_CONFIG_PUSHBUTTON;
-
if (wps_build_version(msg) ||
wps_build_msg_type(msg, WPS_M1) ||
wps_build_uuid_e(msg, wps->uuid_e) ||
wps_build_auth_type_flags(wps, msg) ||
wps_build_encr_type_flags(wps, msg) ||
wps_build_conn_type_flags(wps, msg) ||
- wps_build_config_methods(msg, methods) ||
+ wps_build_config_methods(msg, wps->wps->config_methods) ||
wps_build_wps_state(wps, msg) ||
- wps_build_manufacturer(wps, msg) ||
- wps_build_model_name(wps, msg) ||
- wps_build_model_number(wps, msg) ||
- wps_build_serial_number(wps, msg) ||
- wps_build_primary_dev_type(wps, msg) ||
- wps_build_dev_name(wps, msg) ||
- wps_build_rf_bands(wps, msg) ||
+ wps_build_device_attrs(&wps->wps->dev, msg) ||
+ wps_build_rf_bands(&wps->wps->dev, msg) ||
wps_build_assoc_state(wps, msg) ||
wps_build_dev_password_id(msg, wps->dev_pw_id) ||
- wps_build_config_error(wps, msg) ||
- wps_build_os_version(wps, msg)) {
+ wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
+ wps_build_os_version(&wps->wps->dev, msg) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0)) {
wpabuf_free(msg);
return NULL;
}
wps_build_msg_type(msg, WPS_M3) ||
wps_build_registrar_nonce(wps, msg) ||
wps_build_e_hash(wps, msg) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0) ||
wps_build_authenticator(wps, msg)) {
wpabuf_free(msg);
return NULL;
wps_build_e_snonce1(wps, plain) ||
wps_build_key_wrap_auth(wps, plain) ||
wps_build_encr_settings(wps, msg, plain) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0) ||
wps_build_authenticator(wps, msg)) {
wpabuf_free(plain);
wpabuf_free(msg);
}
+static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *plain)
+{
+ if (wps->wps->ap_settings) {
+ wpa_printf(MSG_DEBUG, "WPS: * AP Settings (pre-configured)");
+ wpabuf_put_data(plain, wps->wps->ap_settings,
+ wps->wps->ap_settings_len);
+ return 0;
+ }
+
+ return wps_build_cred_ssid(wps, plain) ||
+ wps_build_cred_mac_addr(wps, plain) ||
+ wps_build_cred_auth_type(wps, plain) ||
+ wps_build_cred_encr_type(wps, plain) ||
+ wps_build_cred_network_key(wps, plain);
+}
+
+
static struct wpabuf * wps_build_m7(struct wps_data *wps)
{
struct wpabuf *msg, *plain;
wpa_printf(MSG_DEBUG, "WPS: Building Message M7");
- plain = wpabuf_alloc(500);
+ plain = wpabuf_alloc(500 + wps->wps->ap_settings_len);
if (plain == NULL)
return NULL;
- msg = wpabuf_alloc(1000);
+ msg = wpabuf_alloc(1000 + wps->wps->ap_settings_len);
if (msg == NULL) {
wpabuf_free(plain);
return NULL;
wps_build_msg_type(msg, WPS_M7) ||
wps_build_registrar_nonce(wps, msg) ||
wps_build_e_snonce2(wps, plain) ||
- (wps->authenticator &&
- (wps_build_cred_ssid(wps, plain) ||
- wps_build_cred_mac_addr(wps, plain) ||
- wps_build_cred_auth_type(wps, plain) ||
- wps_build_cred_encr_type(wps, plain) ||
- wps_build_cred_network_key(wps, plain))) ||
+ (wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
wps_build_key_wrap_auth(wps, plain) ||
wps_build_encr_settings(wps, msg, plain) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0) ||
wps_build_authenticator(wps, msg)) {
wpabuf_free(plain);
wpabuf_free(msg);
}
wpabuf_free(plain);
+ if (wps->wps->ap && wps->wps->registrar) {
+ /*
+ * If the Registrar is only learning our current configuration,
+ * it may not continue protocol run to successful completion.
+ * Store information here to make sure it remains available.
+ */
+ wps_device_store(wps->wps->registrar, &wps->peer_dev,
+ wps->uuid_r);
+ }
+
wps->state = RECV_M8;
return msg;
}
if (wps_build_version(msg) ||
wps_build_msg_type(msg, WPS_WSC_DONE) ||
wps_build_enrollee_nonce(wps, msg) ||
- wps_build_registrar_nonce(wps, msg)) {
+ wps_build_registrar_nonce(wps, msg) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0)) {
wpabuf_free(msg);
return NULL;
}
- wps->state = wps->authenticator ? RECV_ACK : WPS_FINISHED;
+ if (wps->wps->ap)
+ wps->state = RECV_ACK;
+ else {
+ wps_success_event(wps->wps);
+ wps->state = WPS_FINISHED;
+ }
return msg;
}
if (wps_build_version(msg) ||
wps_build_msg_type(msg, WPS_WSC_ACK) ||
wps_build_enrollee_nonce(wps, msg) ||
- wps_build_registrar_nonce(wps, msg)) {
+ wps_build_registrar_nonce(wps, msg) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0)) {
wpabuf_free(msg);
return NULL;
}
wps_build_msg_type(msg, WPS_WSC_NACK) ||
wps_build_enrollee_nonce(wps, msg) ||
wps_build_registrar_nonce(wps, msg) ||
- wps_build_config_error(wps, msg)) {
+ wps_build_config_error(msg, wps->config_error) ||
+ wps_build_wfa_ext(msg, 0, NULL, 0)) {
wpabuf_free(msg);
return NULL;
}
}
-struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps, u8 *op_code)
+struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
+ enum wsc_op_code *op_code)
{
struct wpabuf *msg;
*op_code = WSC_MSG;
break;
case RECEIVED_M2D:
+ if (wps->wps->ap) {
+ msg = wps_build_wsc_nack(wps);
+ *op_code = WSC_NACK;
+ break;
+ }
msg = wps_build_wsc_ack(wps);
*op_code = WSC_ACK;
if (msg) {
return -1;
}
+#ifdef CONFIG_WPS_OOB
+ if (wps->dev_pw_id != DEV_PW_DEFAULT &&
+ wps->wps->oob_conf.pubkey_hash) {
+ const u8 *addr[1];
+ u8 hash[WPS_HASH_LEN];
+
+ addr[0] = pk;
+ sha256_vector(1, addr, &pk_len, hash);
+ if (os_memcmp(hash,
+ wpabuf_head(wps->wps->oob_conf.pubkey_hash),
+ WPS_OOB_PUBKEY_HASH_LEN) != 0) {
+ wpa_printf(MSG_ERROR, "WPS: Public Key hash error");
+ return -1;
+ }
+ }
+#endif /* CONFIG_WPS_OOB */
+
wpabuf_free(wps->dh_pubkey_r);
wps->dh_pubkey_r = wpabuf_alloc_copy(pk, pk_len);
if (wps->dh_pubkey_r == NULL)
return -1;
- return wps_derive_keys(wps);
+ if (wps_derive_keys(wps) < 0)
+ return -1;
+
+ return 0;
}
if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
wpa_printf(MSG_DEBUG, "WPS: R-Hash1 derived from R-S1 does "
"not match with the pre-committed value");
+ wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
+ wps_pwd_auth_fail_event(wps->wps, 1, 1);
return -1;
}
if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
wpa_printf(MSG_DEBUG, "WPS: R-Hash2 derived from R-S2 does "
"not match with the pre-committed value");
+ wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
+ wps_pwd_auth_fail_event(wps->wps, 1, 2);
return -1;
}
}
-static int wps_process_cred_network_idx(struct wps_credential *cred,
- const u8 *idx)
+static int wps_process_cred_e(struct wps_data *wps, const u8 *cred,
+ size_t cred_len, int wps2)
{
- if (idx == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Credential did not include "
- "Network Index");
- return -1;
- }
-
- wpa_printf(MSG_DEBUG, "WPS: Network Index: %d", *idx);
-
- return 0;
-}
-
+ struct wps_parse_attr attr;
+ struct wpabuf msg;
-static int wps_process_cred_ssid(struct wps_credential *cred, const u8 *ssid,
- size_t ssid_len)
-{
- if (ssid == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Credential did not include SSID");
+ wpa_printf(MSG_DEBUG, "WPS: Received Credential");
+ os_memset(&wps->cred, 0, sizeof(wps->cred));
+ wpabuf_set(&msg, cred, cred_len);
+ if (wps_parse_msg(&msg, &attr) < 0 ||
+ wps_process_cred(&attr, &wps->cred))
return -1;
- }
- /* Remove zero-padding since some Registrar implementations seem to use
- * hardcoded 32-octet length for this attribute */
- while (ssid_len > 0 && ssid[ssid_len - 1] == 0)
- ssid_len--;
-
- wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", ssid, ssid_len);
- if (ssid_len <= sizeof(cred->ssid)) {
- os_memcpy(cred->ssid, ssid, ssid_len);
- cred->ssid_len = ssid_len;
+ if (os_memcmp(wps->cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN) !=
+ 0) {
+ wpa_printf(MSG_DEBUG, "WPS: MAC Address in the Credential ("
+ MACSTR ") does not match with own address (" MACSTR
+ ")", MAC2STR(wps->cred.mac_addr),
+ MAC2STR(wps->wps->dev.mac_addr));
+ /*
+ * In theory, this could be consider fatal error, but there are
+ * number of deployed implementations using other address here
+ * due to unclarity in the specification. For interoperability
+ * reasons, allow this to be processed since we do not really
+ * use the MAC Address information for anything.
+ */
+#ifdef CONFIG_WPS_STRICT
+ if (wps2) {
+ wpa_printf(MSG_INFO, "WPS: Do not accept incorrect "
+ "MAC Address in AP Settings");
+ return -1;
+ }
+#endif /* CONFIG_WPS_STRICT */
}
- return 0;
-}
-
+#ifdef CONFIG_WPS2
+ if (!(wps->cred.encr_type &
+ (WPS_ENCR_NONE | WPS_ENCR_TKIP | WPS_ENCR_AES))) {
+ if (wps->cred.encr_type & WPS_ENCR_WEP) {
+ wpa_printf(MSG_INFO, "WPS: Reject Credential "
+ "due to WEP configuration");
+ return -2;
+ }
-static int wps_process_cred_auth_type(struct wps_credential *cred,
- const u8 *auth_type)
-{
- if (auth_type == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Credential did not include "
- "Authentication Type");
+ wpa_printf(MSG_INFO, "WPS: Reject Credential due to "
+ "invalid encr_type 0x%x", wps->cred.encr_type);
return -1;
}
+#endif /* CONFIG_WPS2 */
- cred->auth_type = WPA_GET_BE16(auth_type);
- wpa_printf(MSG_DEBUG, "WPS: Authentication Type: 0x%x",
- cred->auth_type);
-
- return 0;
-}
-
-
-static int wps_process_cred_encr_type(struct wps_credential *cred,
- const u8 *encr_type)
-{
- if (encr_type == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Credential did not include "
- "Encryption Type");
- return -1;
+ if (wps->wps->cred_cb) {
+ wps->cred.cred_attr = cred - 4;
+ wps->cred.cred_attr_len = cred_len + 4;
+ wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
+ wps->cred.cred_attr = NULL;
+ wps->cred.cred_attr_len = 0;
}
- cred->encr_type = WPA_GET_BE16(encr_type);
- wpa_printf(MSG_DEBUG, "WPS: Encryption Type: 0x%x",
- cred->encr_type);
-
return 0;
}
-static int wps_process_cred_network_key_idx(struct wps_credential *cred,
- const u8 *key_idx)
+static int wps_process_creds(struct wps_data *wps, const u8 *cred[],
+ size_t cred_len[], size_t num_cred, int wps2)
{
- if (key_idx == NULL)
- return 0; /* optional attribute */
-
- wpa_printf(MSG_DEBUG, "WPS: Network Key Index: %d", *key_idx);
- cred->key_idx = *key_idx;
-
- return 0;
-}
+ size_t i;
+ int ok = 0;
+ if (wps->wps->ap)
+ return 0;
-static int wps_process_cred_network_key(struct wps_credential *cred,
- const u8 *key, size_t key_len)
-{
- if (key == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Credential did not include "
- "Network Key");
+ if (num_cred == 0) {
+ wpa_printf(MSG_DEBUG, "WPS: No Credential attributes "
+ "received");
return -1;
}
- wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key", key, key_len);
- if (key_len <= sizeof(cred->key)) {
- os_memcpy(cred->key, key, key_len);
- cred->key_len = key_len;
+ for (i = 0; i < num_cred; i++) {
+ int res;
+ res = wps_process_cred_e(wps, cred[i], cred_len[i], wps2);
+ if (res == 0)
+ ok++;
+ else if (res == -2)
+ wpa_printf(MSG_DEBUG, "WPS: WEP credential skipped");
+ else
+ return -1;
}
- return 0;
-}
-
-
-static int wps_process_cred_mac_addr(struct wps_credential *cred,
- const u8 *mac_addr)
-{
- if (mac_addr == NULL) {
- wpa_printf(MSG_DEBUG, "WPS: Credential did not include "
- "MAC Address");
+ if (ok == 0) {
+ wpa_printf(MSG_DEBUG, "WPS: No valid Credential attribute "
+ "received");
return -1;
}
- wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR, MAC2STR(mac_addr));
- os_memcpy(cred->mac_addr, mac_addr, ETH_ALEN);
-
return 0;
}
-static int wps_process_cred_eap_type(struct wps_credential *cred,
- const u8 *eap_type, size_t eap_type_len)
+static int wps_process_ap_settings_e(struct wps_data *wps,
+ struct wps_parse_attr *attr,
+ struct wpabuf *attrs, int wps2)
{
- if (eap_type == NULL)
- return 0; /* optional attribute */
-
- wpa_hexdump(MSG_DEBUG, "WPS: EAP Type", eap_type, eap_type_len);
-
- return 0;
-}
-
-
-static int wps_process_cred_eap_identity(struct wps_credential *cred,
- const u8 *identity,
- size_t identity_len)
-{
- if (identity == NULL)
- return 0; /* optional attribute */
-
- wpa_hexdump_ascii(MSG_DEBUG, "WPS: EAP Identity",
- identity, identity_len);
-
- return 0;
-}
-
-
-static int wps_process_cred_key_prov_auto(struct wps_credential *cred,
- const u8 *key_prov_auto)
-{
- if (key_prov_auto == NULL)
- return 0; /* optional attribute */
-
- wpa_printf(MSG_DEBUG, "WPS: Key Provided Automatically: %d",
- *key_prov_auto);
-
- return 0;
-}
-
-
-static int wps_process_cred_802_1x_enabled(struct wps_credential *cred,
- const u8 *dot1x_enabled)
-{
- if (dot1x_enabled == NULL)
- return 0; /* optional attribute */
-
- wpa_printf(MSG_DEBUG, "WPS: 802.1X Enabled: %d", *dot1x_enabled);
-
- return 0;
-}
-
+ struct wps_credential cred;
-static int wps_process_cred(struct wps_data *wps, const u8 *cred,
- size_t cred_len)
-{
- struct wps_parse_attr attr;
- struct wpabuf msg;
+ if (!wps->wps->ap)
+ return 0;
- wpa_printf(MSG_DEBUG, "WPS: Received Credential");
- os_memset(&wps->cred, 0, sizeof(wps->cred));
- wpabuf_set(&msg, cred, cred_len);
- /* TODO: support multiple Network Keys */
- if (wps_parse_msg(&msg, &attr) < 0 ||
- wps_process_cred_network_idx(&wps->cred, attr.network_idx) ||
- wps_process_cred_ssid(&wps->cred, attr.ssid, attr.ssid_len) ||
- wps_process_cred_auth_type(&wps->cred, attr.auth_type) ||
- wps_process_cred_encr_type(&wps->cred, attr.encr_type) ||
- wps_process_cred_network_key_idx(&wps->cred, attr.network_key_idx)
- ||
- wps_process_cred_network_key(&wps->cred, attr.network_key,
- attr.network_key_len) ||
- wps_process_cred_mac_addr(&wps->cred, attr.mac_addr) ||
- wps_process_cred_eap_type(&wps->cred, attr.eap_type,
- attr.eap_type_len) ||
- wps_process_cred_eap_identity(&wps->cred, attr.eap_identity,
- attr.eap_identity_len) ||
- wps_process_cred_key_prov_auto(&wps->cred, attr.key_prov_auto) ||
- wps_process_cred_802_1x_enabled(&wps->cred, attr.dot1x_enabled))
+ if (wps_process_ap_settings(attr, &cred) < 0)
return -1;
- if (wps->wps_cred_cb)
- wps->wps_cred_cb(wps->cb_ctx, &wps->cred);
-
- return 0;
-}
-
+ wpa_printf(MSG_INFO, "WPS: Received new AP configuration from "
+ "Registrar");
-static int wps_process_creds(struct wps_data *wps, const u8 *cred[],
- size_t cred_len[], size_t num_cred)
-{
- size_t i;
+ if (os_memcmp(cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN) !=
+ 0) {
+ wpa_printf(MSG_DEBUG, "WPS: MAC Address in the AP Settings ("
+ MACSTR ") does not match with own address (" MACSTR
+ ")", MAC2STR(cred.mac_addr),
+ MAC2STR(wps->wps->dev.mac_addr));
+ /*
+ * In theory, this could be consider fatal error, but there are
+ * number of deployed implementations using other address here
+ * due to unclarity in the specification. For interoperability
+ * reasons, allow this to be processed since we do not really
+ * use the MAC Address information for anything.
+ */
+#ifdef CONFIG_WPS_STRICT
+ if (wps2) {
+ wpa_printf(MSG_INFO, "WPS: Do not accept incorrect "
+ "MAC Address in AP Settings");
+ return -1;
+ }
+#endif /* CONFIG_WPS_STRICT */
+ }
- if (wps->authenticator)
- return 0;
+#ifdef CONFIG_WPS2
+ 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;
+ }
- if (num_cred == 0) {
- wpa_printf(MSG_DEBUG, "WPS: No Credential attributes "
- "received");
+ wpa_printf(MSG_INFO, "WPS: Reject new AP settings due to "
+ "invalid encr_type 0x%x", cred.encr_type);
return -1;
}
+#endif /* CONFIG_WPS2 */
- for (i = 0; i < num_cred; i++) {
- if (wps_process_cred(wps, cred[i], cred_len[i]))
+#ifdef CONFIG_WPS_STRICT
+ if (wps2) {
+ if ((cred.encr_type & (WPS_ENCR_TKIP | WPS_ENCR_AES)) ==
+ WPS_ENCR_TKIP ||
+ (cred.auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) ==
+ WPS_AUTH_WPAPSK) {
+ wpa_printf(MSG_INFO, "WPS-STRICT: Invalid WSC 2.0 "
+ "AP Settings: WPA-Personal/TKIP only");
return -1;
+ }
}
+#endif /* CONFIG_WPS_STRICT */
- return 0;
-}
-
-
-static int wps_process_ap_settings(struct wps_data *wps,
- struct wps_parse_attr *attr)
-{
- struct wps_credential cred;
-
- if (!wps->authenticator)
- return 0;
-
- wpa_printf(MSG_DEBUG, "WPS: Processing AP Settings");
- os_memset(&cred, 0, sizeof(cred));
- /* TODO: optional attributes New Password and Device Password ID */
- if (wps_process_cred_ssid(&cred, attr->ssid, attr->ssid_len) ||
- wps_process_cred_auth_type(&cred, attr->auth_type) ||
- wps_process_cred_encr_type(&cred, attr->encr_type) ||
- wps_process_cred_network_key_idx(&cred, attr->network_key_idx) ||
- wps_process_cred_network_key(&cred, attr->network_key,
- attr->network_key_len) ||
- wps_process_cred_mac_addr(&cred, attr->mac_addr))
- return -1;
+#ifdef CONFIG_WPS2
+ 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;
+ }
- wpa_printf(MSG_INFO, "WPS: Received new AP configuration from "
- "Registrar");
+ 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;
+ }
+#endif /* CONFIG_WPS2 */
- if (wps->wps->cred_cb)
+ if (wps->wps->cred_cb) {
+ cred.cred_attr = wpabuf_head(attrs);
+ cred.cred_attr_len = wpabuf_len(attrs);
wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
+ }
return 0;
}
if (wps->state != RECV_M2) {
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
"receiving M2", wps->state);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
- wps_process_uuid_r(wps, attr->uuid_r) ||
- wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
- wps_process_authenticator(wps, attr->authenticator, msg))
- return WPS_FAILURE;
+ wps_process_uuid_r(wps, attr->uuid_r)) {
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
- if (wps->authenticator && wps->wps->ap_setup_locked) {
+ if (wps->wps->ap &&
+ (wps->wps->ap_setup_locked || wps->dev_password == NULL)) {
wpa_printf(MSG_DEBUG, "WPS: AP Setup is locked - refuse "
"registration of a new Registrar");
+ wps->config_error = WPS_CFG_SETUP_LOCKED;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
+
+ if (wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
+ wps_process_authenticator(wps, attr->authenticator, msg) ||
+ wps_process_device_attrs(&wps->peer_dev, attr)) {
wps->state = SEND_WSC_NACK;
return WPS_CONTINUE;
}
if (wps->state != RECV_M2) {
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
"receiving M2D", wps->state);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpa_hexdump_ascii(MSG_DEBUG, "WPS: Manufacturer",
wpa_hexdump_ascii(MSG_DEBUG, "WPS: Device Name",
attr->dev_name, attr->dev_name_len);
- /*
- * TODO: notify monitor programs (cli/gui/etc.) of the M2D and provide
- * user information about the registrar properties.
- */
+ if (wps->wps->event_cb) {
+ union wps_event_data data;
+ struct wps_event_m2d *m2d = &data.m2d;
+ os_memset(&data, 0, sizeof(data));
+ if (attr->config_methods)
+ m2d->config_methods =
+ WPA_GET_BE16(attr->config_methods);
+ m2d->manufacturer = attr->manufacturer;
+ m2d->manufacturer_len = attr->manufacturer_len;
+ m2d->model_name = attr->model_name;
+ m2d->model_name_len = attr->model_name_len;
+ m2d->model_number = attr->model_number;
+ m2d->model_number_len = attr->model_number_len;
+ m2d->serial_number = attr->serial_number;
+ m2d->serial_number_len = attr->serial_number_len;
+ m2d->dev_name = attr->dev_name;
+ m2d->dev_name_len = attr->dev_name_len;
+ m2d->primary_dev_type = attr->primary_dev_type;
+ if (attr->config_error)
+ m2d->config_error =
+ WPA_GET_BE16(attr->config_error);
+ if (attr->dev_password_id)
+ m2d->dev_password_id =
+ WPA_GET_BE16(attr->dev_password_id);
+ wps->wps->event_cb(wps->wps->cb_ctx, WPS_EV_M2D, &data);
+ }
wps->state = RECEIVED_M2D;
- return WPS_FAILURE;
+ return WPS_CONTINUE;
}
if (wps->state != RECV_M4) {
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
"receiving M4", wps->state);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
wps_process_authenticator(wps, attr->authenticator, msg) ||
wps_process_r_hash1(wps, attr->r_hash1) ||
- wps_process_r_hash2(wps, attr->r_hash2))
- return WPS_FAILURE;
+ wps_process_r_hash2(wps, attr->r_hash2)) {
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
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");
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
+
+ if (wps_validate_m4_encr(decrypted, attr->version2 != 0) < 0) {
+ wpabuf_free(decrypted);
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
wps_process_r_snonce1(wps, eattr.r_snonce1)) {
wpabuf_free(decrypted);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpabuf_free(decrypted);
if (wps->state != RECV_M6) {
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
"receiving M6", wps->state);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
- wps_process_authenticator(wps, attr->authenticator, msg))
- return WPS_FAILURE;
+ wps_process_authenticator(wps, attr->authenticator, msg)) {
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
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");
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
+
+ if (wps_validate_m6_encr(decrypted, attr->version2 != 0) < 0) {
+ wpabuf_free(decrypted);
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
wps_process_r_snonce2(wps, eattr.r_snonce2)) {
wpabuf_free(decrypted);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpabuf_free(decrypted);
if (wps->state != RECV_M8) {
wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
"receiving M8", wps->state);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
if (wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
- wps_process_authenticator(wps, attr->authenticator, msg))
- return WPS_FAILURE;
+ wps_process_authenticator(wps, attr->authenticator, msg)) {
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
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");
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
+ }
+
+ if (wps_validate_m8_encr(decrypted, wps->wps->ap, attr->version2 != 0)
+ < 0) {
+ wpabuf_free(decrypted);
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
if (wps_parse_msg(decrypted, &eattr) < 0 ||
wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
wps_process_creds(wps, eattr.cred, eattr.cred_len,
- eattr.num_cred) ||
- wps_process_ap_settings(wps, &eattr)) {
+ eattr.num_cred, attr->version2 != NULL) ||
+ wps_process_ap_settings_e(wps, &eattr, decrypted,
+ attr->version2 != NULL)) {
wpabuf_free(decrypted);
- return WPS_FAILURE;
+ wps->state = SEND_WSC_NACK;
+ return WPS_CONTINUE;
}
wpabuf_free(decrypted);
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
- if (attr.version == NULL || *attr.version != WPS_VERSION) {
- wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
- attr.version ? *attr.version : 0);
- return WPS_FAILURE;
- }
-
if (attr.enrollee_nonce == NULL ||
os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
switch (*attr.msg_type) {
case WPS_M2:
+ if (wps_validate_m2(msg) < 0)
+ return WPS_FAILURE;
ret = wps_process_m2(wps, msg, &attr);
break;
case WPS_M2D:
+ if (wps_validate_m2d(msg) < 0)
+ return WPS_FAILURE;
ret = wps_process_m2d(wps, &attr);
break;
case WPS_M4:
+ if (wps_validate_m4(msg) < 0)
+ return WPS_FAILURE;
ret = wps_process_m4(wps, msg, &attr);
+ if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
+ wps_fail_event(wps->wps, WPS_M4);
break;
case WPS_M6:
+ if (wps_validate_m6(msg) < 0)
+ return WPS_FAILURE;
ret = wps_process_m6(wps, msg, &attr);
+ if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
+ wps_fail_event(wps->wps, WPS_M6);
break;
case WPS_M8:
+ if (wps_validate_m8(msg) < 0)
+ return WPS_FAILURE;
ret = wps_process_m8(wps, msg, &attr);
+ if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
+ wps_fail_event(wps->wps, WPS_M8);
break;
default:
wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
return WPS_FAILURE;
}
- if (ret == WPS_CONTINUE) {
+ /*
+ * Save a copy of the last message for Authenticator derivation if we
+ * are continuing. However, skip M2D since it is not authenticated and
+ * neither is the ACK/NACK response frame. This allows the possibly
+ * following M2 to be processed correctly by using the previously sent
+ * M1 in Authenticator derivation.
+ */
+ if (ret == WPS_CONTINUE && *attr.msg_type != WPS_M2D) {
/* Save a copy of the last message for Authenticator derivation
*/
wpabuf_free(wps->last_msg);
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
- if (attr.version == NULL || *attr.version != WPS_VERSION) {
- wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
- attr.version ? *attr.version : 0);
- return WPS_FAILURE;
- }
-
if (attr.msg_type == NULL) {
wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
return WPS_FAILURE;
return WPS_FAILURE;
}
- if (wps->state == RECV_ACK && wps->authenticator) {
+ if (wps->state == RECV_ACK && wps->wps->ap) {
wpa_printf(MSG_DEBUG, "WPS: External Registrar registration "
"completed successfully");
+ wps_success_event(wps->wps);
wps->state = WPS_FINISHED;
return WPS_DONE;
}
if (wps_parse_msg(msg, &attr) < 0)
return WPS_FAILURE;
- if (attr.version == NULL || *attr.version != WPS_VERSION) {
- wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
- attr.version ? *attr.version : 0);
- return WPS_FAILURE;
- }
-
if (attr.msg_type == NULL) {
wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
return WPS_FAILURE;
return WPS_FAILURE;
}
- wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
+ wpa_printf(MSG_DEBUG, "WPS: Registrar terminated negotiation with "
"Configuration Error %d", WPA_GET_BE16(attr.config_error));
+ switch (wps->state) {
+ case RECV_M4:
+ wps_fail_event(wps->wps, WPS_M3);
+ break;
+ case RECV_M6:
+ wps_fail_event(wps->wps, WPS_M5);
+ break;
+ case RECV_M8:
+ wps_fail_event(wps->wps, WPS_M7);
+ break;
+ default:
+ break;
+ }
+
+ /* Followed by NACK if Enrollee is Supplicant or EAP-Failure if
+ * Enrollee is Authenticator */
+ wps->state = SEND_WSC_NACK;
+
return WPS_FAILURE;
}
-enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps, u8 op_code,
+enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
+ enum wsc_op_code op_code,
const struct wpabuf *msg)
{
"op_code=%d)",
(unsigned long) wpabuf_len(msg), op_code);
+ if (op_code == WSC_UPnP) {
+ /* Determine the OpCode based on message type attribute */
+ struct wps_parse_attr attr;
+ if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type) {
+ if (*attr.msg_type == WPS_WSC_ACK)
+ op_code = WSC_ACK;
+ else if (*attr.msg_type == WPS_WSC_NACK)
+ op_code = WSC_NACK;
+ }
+ }
+
switch (op_code) {
case WSC_MSG:
+ case WSC_UPnP:
return wps_process_wsc_msg(wps, msg);
case WSC_ACK:
+ if (wps_validate_wsc_ack(msg) < 0)
+ return WPS_FAILURE;
return wps_process_wsc_ack(wps, msg);
case WSC_NACK:
+ if (wps_validate_wsc_nack(msg) < 0)
+ return WPS_FAILURE;
return wps_process_wsc_nack(wps, msg);
default:
wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
return WPS_FAILURE;
}
}
-
-
-struct wpabuf * wps_enrollee_build_assoc_req_ie(void)
-{
- struct wpabuf *ie;
- u8 *len;
-
- wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
- "Request");
- ie = wpabuf_alloc(100);
- if (ie == NULL)
- return NULL;
-
- wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
- len = wpabuf_put(ie, 1);
- wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
-
- if (wps_build_version(ie) ||
- wps_build_req_type(ie, WPS_REQ_ENROLLEE)) {
- wpabuf_free(ie);
- return NULL;
- }
-
- *len = wpabuf_len(ie) - 2;
-
- return ie;
-}
-
-
-struct wpabuf * wps_enrollee_build_probe_req_ie(int pbc, const u8 *uuid)
-{
- struct wpabuf *ie;
- u8 *len;
- u16 methods;
-
- wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for Probe Request");
- ie = wpabuf_alloc(200);
- if (ie == NULL)
- return NULL;
-
- wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
- len = wpabuf_put(ie, 1);
- wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
-
- if (pbc)
- methods = WPS_CONFIG_PUSHBUTTON;
- else
- methods = WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY |
- WPS_CONFIG_KEYPAD;
-
- if (wps_build_version(ie) ||
- wps_build_req_type(ie, WPS_REQ_ENROLLEE) ||
- wps_build_config_methods(ie, methods) ||
- wps_build_uuid_e(ie, uuid) ||
- wps_build_primary_dev_type(NULL, ie) ||
- wps_build_rf_bands(NULL, ie) ||
- wps_build_assoc_state(NULL, ie) ||
- wps_build_config_error(NULL, ie) ||
- wps_build_dev_password_id(ie, pbc ? DEV_PW_PUSHBUTTON :
- DEV_PW_DEFAULT)) {
- wpabuf_free(ie);
- return NULL;
- }
-
- *len = wpabuf_len(ie) - 2;
-
- return ie;
-}