eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit fff59913d967be5b6e2c9750d35a1079edc31961
parent 96c61bb6b4dd47562a79a1bdbb3d97a9de5e2fb7
Author: illiliti <illiliti@protonmail.com>
Date:   Mon, 28 Aug 2023 06:41:50 +0300

Merge tag '2.8'

Release 2.8

Diffstat:
MChangeLog | 6++++++
MMakefile.am | 6++++--
Mconfigure.ac | 4++--
Msrc/crypto.c | 10++++------
Msrc/crypto.h | 5+++--
Msrc/eapol.c | 11+++--------
Msrc/ft.c | 14+++++++++++---
Msrc/handshake.c | 61+++++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/handshake.h | 6++++--
Msrc/iwd.config.rst | 10----------
Msrc/netdev.c | 8++++++--
Msrc/scan.c | 8--------
Msrc/station.c | 10+++++++++-
Mtools/hwsim.c | 163++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
14 files changed, 256 insertions(+), 66 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,9 @@ +ver 2.8: + Fix issue with handling OWE AKM in association reply. + +ver 2.7: + Fix issue with handling FT-8021X and SHA256 PMKID derivation. + ver 2.6: Add support for setting driver specific quirks. Add support for disabling power saving mode. diff --git a/Makefile.am b/Makefile.am @@ -63,7 +63,8 @@ ell_headers = ell/util.h \ ell/dhcp6.h \ ell/acd.h \ ell/cleanup.h \ - ell/netconfig.h + ell/netconfig.h \ + ell/sysctl.h ell_sources = ell/private.h \ ell/missing.h \ @@ -143,7 +144,8 @@ ell_sources = ell/private.h \ ell/dhcp6-lease.c \ ell/dhcp6-transport.c \ ell/acd.c \ - ell/netconfig.c + ell/netconfig.c \ + ell/sysctl.c ell_shared = ell/useful.h ell/asn1-private.h diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([iwd],[2.6]) +AC_INIT([iwd],[2.8]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -302,7 +302,7 @@ if (test "${enable_external_ell}" = "yes"); then test "${enable_monitor}" != "no" || test "${enable_wired}" = "yes" || test "${enable_hwsim}" = "yes"); then - ell_min_version="0.57" + ell_min_version="0.58" else ell_min_version="0.5" fi diff --git a/src/crypto.c b/src/crypto.c @@ -1116,9 +1116,10 @@ exit: } /* Defined in 802.11-2012, Section 11.6.1.3 Pairwise Key Hierarchy */ -bool crypto_derive_pmkid(const uint8_t *pmk, +bool crypto_derive_pmkid(const uint8_t *pmk, size_t key_len, const uint8_t *addr1, const uint8_t *addr2, - uint8_t *out_pmkid, bool use_sha256) + uint8_t *out_pmkid, + enum l_checksum_type checksum) { uint8_t data[20]; @@ -1126,10 +1127,7 @@ bool crypto_derive_pmkid(const uint8_t *pmk, memcpy(data + 8, addr2, 6); memcpy(data + 14, addr1, 6); - if (use_sha256) - return hmac_sha256(pmk, 32, data, 20, out_pmkid, 16); - else - return hmac_sha1(pmk, 32, data, 20, out_pmkid, 16); + return hmac_common(checksum, pmk, key_len, data, 20, out_pmkid, 16); } enum l_checksum_type crypto_sae_hash_from_ecc_prime_len(enum crypto_sae type, diff --git a/src/crypto.h b/src/crypto.h @@ -154,9 +154,10 @@ bool crypto_derive_ft_ptk(const uint8_t *pmk_r1, const uint8_t *pmk_r1_name, bool sha384, uint8_t *out_ptk, size_t ptk_len, uint8_t *out_ptk_name); -bool crypto_derive_pmkid(const uint8_t *pmk, +bool crypto_derive_pmkid(const uint8_t *pmk, size_t key_len, const uint8_t *addr1, const uint8_t *addr2, - uint8_t *out_pmkid, bool use_sha256); + uint8_t *out_pmkid, + enum l_checksum_type checksum); enum crypto_sae { CRYPTO_SAE_LOOPING, diff --git a/src/eapol.c b/src/eapol.c @@ -1112,8 +1112,8 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm) memcpy(ek->key_nonce, sm->handshake->anonce, sizeof(ek->key_nonce)); /* Write the PMKID KDE into Key Data field unencrypted */ - crypto_derive_pmkid(sm->handshake->pmk, sm->handshake->spa, aa, - pmkid, false); + crypto_derive_pmkid(sm->handshake->pmk, 32, sm->handshake->spa, aa, + pmkid, L_CHECKSUM_SHA1); eapol_key_data_append(ek, sm->mic_len, HANDSHAKE_KDE_PMKID, pmkid, 16); @@ -1234,12 +1234,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm, if (!found) goto error_unspecified; } else if (pmkid) { - uint8_t own_pmkid[16]; - - if (!handshake_state_get_pmkid(sm->handshake, own_pmkid)) - goto error_unspecified; - - if (l_secure_memcmp(pmkid, own_pmkid, 16)) { + if (!handshake_state_pmkid_matches(sm->handshake, pmkid)) { l_debug("Authenticator sent a PMKID that didn't match"); /* diff --git a/src/ft.c b/src/ft.c @@ -825,15 +825,21 @@ void __ft_rx_action(uint32_t ifindex, const uint8_t *frame, size_t frame_len) ret = ft_over_ds_parse_action_response(frame, frame_len, &spa, &aa, &ies, &ies_len); - if (ret != 0) + if (ret != 0) { + l_debug("Could not parse action response"); return; + } info = ft_info_find(ifindex, aa); - if (!info) + if (!info) { + l_debug("No FT info found for BSS "MAC, MAC_STR(aa)); return; + } - if (!ft_parse_ies(info, hs, ies, ies_len)) + if (!ft_parse_ies(info, hs, ies, ies_len)) { + l_debug("Could not parse action response IEs"); goto ft_error; + } info->parsed = true; @@ -931,6 +937,8 @@ static bool ft_send_action(struct wiphy_radio_work_item *work) memcpy(ft_req + 2, info->spa, 6); memcpy(ft_req + 8, info->aa, 6); + l_debug(""); + if (!ft_build_authenticate_ies(hs, hs->supplicant_ocvc, info->snonce, ies, &len)) goto failed; diff --git a/src/handshake.c b/src/handshake.c @@ -734,10 +734,9 @@ void handshake_state_set_pmkid(struct handshake_state *s, const uint8_t *pmkid) s->have_pmkid = true; } -bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid) +bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid, + enum l_checksum_type sha) { - bool use_sha256; - /* SAE exports pmkid */ if (s->have_pmkid) { memcpy(out_pmkid, s->pmkid, 16); @@ -747,22 +746,56 @@ bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid) if (!s->have_pmk) return false; + return crypto_derive_pmkid(s->pmk, 32, s->spa, s->aa, out_pmkid, + sha); +} + +bool handshake_state_pmkid_matches(struct handshake_state *s, + const uint8_t *check) +{ + uint8_t own_pmkid[16]; + enum l_checksum_type sha; + /* - * Note 802.11 section 11.6.1.3: - * "When the PMKID is calculated for the PMKSA as part of RSN - * preauthentication, the AKM has not yet been negotiated. In this - * case, the HMAC-SHA1-128 based derivation is used for the PMKID - * calculation." + * 802.11-2020 Table 9-151 defines the hashing algorithm to use + * for various AKM's. Note some AKMs are omitted here because they + * export the PMKID individually (SAE/FILS/FT-PSK) + * + * SHA1: + * 00-0F-AC:1 (8021X) + * 00-0F-AC:2 (PSK) + * + * SHA256: + * 00-0F-AC:3 (FT-8021X) + * 00-0F-AC:5 (8021X-SHA256) + * 00-0F-AC:6 (PSK-SHA256) + * + * SHA384: + * 00-0F-AC:13 (FT-8021X-SHA384) */ - if (s->akm_suite & (IE_RSN_AKM_SUITE_8021X_SHA256 | - IE_RSN_AKM_SUITE_PSK_SHA256)) - use_sha256 = true; + IE_RSN_AKM_SUITE_PSK_SHA256 | + IE_RSN_AKM_SUITE_FT_OVER_8021X)) + sha = L_CHECKSUM_SHA256; else - use_sha256 = false; + sha = L_CHECKSUM_SHA1; - return crypto_derive_pmkid(s->pmk, s->spa, s->aa, out_pmkid, - use_sha256); + if (!handshake_state_get_pmkid(s, own_pmkid, sha)) + return false; + + if (l_secure_memcmp(own_pmkid, check, 16)) { + if (s->akm_suite != IE_RSN_AKM_SUITE_FT_OVER_8021X) + return false; + + l_debug("PMKID did not match, trying SHA1 derivation"); + + if (!handshake_state_get_pmkid(s, own_pmkid, L_CHECKSUM_SHA1)) + return false; + + return l_secure_memcmp(own_pmkid, check, 16) == 0; + } + + return true; } void handshake_state_set_gtk(struct handshake_state *s, const uint8_t *key, diff --git a/src/handshake.h b/src/handshake.h @@ -269,8 +269,10 @@ void handshake_state_install_igtk(struct handshake_state *s, void handshake_state_override_pairwise_cipher(struct handshake_state *s, enum ie_rsn_cipher_suite pairwise); -bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid); - +bool handshake_state_get_pmkid(struct handshake_state *s, uint8_t *out_pmkid, + enum l_checksum_type sha); +bool handshake_state_pmkid_matches(struct handshake_state *s, + const uint8_t *check); bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped, size_t key_len, uint8_t *key_out); diff --git a/src/iwd.config.rst b/src/iwd.config.rst @@ -74,16 +74,6 @@ The group ``[General]`` contains general settings. ``[Network]`` settings for additional settings related to network configuration. - * - APRanges - - Values: <IP in prefix notation> - - Sets the range of IP's used for DHCP server (AP mode). The IP should be - in prefix notation e.g. 192.168.1.0/24. AP's which are started in a - profile-less configuration will use this pool of IP's to set the AP's - interface address as well as default DHCP server options. Each AP will - get a new subnet from the range and clients will be addressed in that - subnet to avoid IP conflicts if multiple AP's are started. - * - UseDefaultInterface - Values: true, **false** diff --git a/src/netdev.c b/src/netdev.c @@ -2911,11 +2911,15 @@ process_resp_ies: } if (netdev->owe_sm) { - if (!owe_dh || !owe_akm_found) { - l_error("OWE DH element/RSN not found"); + if (!owe_dh) { + l_error("OWE DH element not found"); goto deauth; } + if (!owe_akm_found) + l_warn("OWE AKM was not included in the RSNE. " + "This AP is out of spec!"); + if (L_WARN_ON(owe_process_dh_ie(netdev->owe_sm, owe_dh, owe_dh_len) != 0)) goto deauth; diff --git a/src/scan.c b/src/scan.c @@ -1230,8 +1230,6 @@ static bool scan_parse_advertisement_protocol(struct scan_bss *bss, { const uint8_t *ptr = data; - l_debug(""); - while (len) { /* * TODO: Store query info for GAS response length verification @@ -1304,8 +1302,6 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss, NULL) < 0) l_warn("Unable to parse BSS Load IE for " MAC, MAC_STR(bss->addr)); - else - l_debug("Load: %u/255", bss->utilization); break; case IE_TYPE_VENDOR_SPECIFIC: @@ -1795,8 +1791,6 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data) uint64_t wdev_id; uint32_t seen_ms_ago = 0; - l_debug("get_scan_callback"); - if (nl80211_parse_attrs(msg, NL80211_ATTR_WDEV, &wdev_id, NL80211_ATTR_UNSPEC) < 0) return; @@ -1875,8 +1869,6 @@ static void get_scan_done(void *user) struct scan_results *results = user; struct scan_context *sc = results->sc; - l_debug("get_scan_done"); - sc->get_scan_cmd_id = 0; if (!results->sr || !results->sr->canceled) diff --git a/src/station.c b/src/station.c @@ -2250,7 +2250,15 @@ static void station_preauthenticate_cb(struct netdev *netdev, new_hs->supplicant_ie[1] + 2, &rsn_info); - handshake_state_get_pmkid(new_hs, pmkid); + /* + * IEEE 802.11 Section 12.7.1.3: + * + * "When the PMKID is calculated for the PMKSA as part of + * preauthentication, the AKM has not yet been negotiated. + * In this case, the HMAC-SHA-1 based derivation is used for + * the PMKID calculation." + */ + handshake_state_get_pmkid(new_hs, pmkid, L_CHECKSUM_SHA1); rsn_info.num_pmkids = 1; rsn_info.pmkids = pmkid; diff --git a/tools/hwsim.c b/tools/hwsim.c @@ -62,6 +62,8 @@ enum { HWSIM_CMD_NEW_RADIO, HWSIM_CMD_DEL_RADIO, HWSIM_CMD_GET_RADIO, + HWSIM_CMD_ADD_MAC_ADDR, + HWSIM_CMD_DEL_MAC_ADDR, __HWSIM_CMD_MAX, }; #define HWSIM_CMD_MAX (__HWSIM_CMD_MAX - 1) @@ -438,6 +440,7 @@ struct interface_info_rec { uint8_t addr[ETH_ALEN]; char *name; uint32_t iftype; + int ref; }; static struct l_queue *radio_info; @@ -513,6 +516,14 @@ static bool interface_info_match_id(const void *a, const void *b) return rec->id == id; } +static bool interface_info_match_addr(const void *a, const void *b) +{ + const struct interface_info_rec *rec = a; + const uint8_t *addr = b; + + return memcmp(rec->addr, addr, ETH_ALEN) == 0; +} + static const char *radio_get_path(const struct radio_info_rec *rec) { static char path[15]; @@ -1570,7 +1581,9 @@ static void process_frame(struct hwsim_frame *frame) hwsim_frame_unref(frame); } -static void unicast_handler(struct l_genl_msg *msg, void *user_data) + + +static void hwsim_frame_event(struct l_genl_msg *msg) { struct hwsim_frame *frame; const struct mmpdu_header *mpdu; @@ -1579,9 +1592,6 @@ static void unicast_handler(struct l_genl_msg *msg, void *user_data) const void *data; const uint8_t *transmitter = NULL, *freq = NULL, *flags = NULL; - if (l_genl_msg_get_command(msg) != HWSIM_CMD_FRAME) - return; - if (!l_genl_attr_init(&attr, msg)) return; @@ -1681,6 +1691,146 @@ static void unicast_handler(struct l_genl_msg *msg, void *user_data) process_frame(frame); } +static bool get_tx_rx_addrs(struct l_genl_msg *msg, const uint8_t **tx_out, + const uint8_t **rx_out) +{ + struct l_genl_attr attr; + uint16_t type, len; + const void *data; + const uint8_t *tx = NULL, *rx = NULL; + + if (!l_genl_attr_init(&attr, msg)) + return false; + + while (l_genl_attr_next(&attr, &type, &len, &data)) { + switch (type) { + case HWSIM_ATTR_ADDR_TRANSMITTER: + if (len != ETH_ALEN) + return false; + + tx = data; + break; + case HWSIM_ATTR_ADDR_RECEIVER: + if (len != ETH_ALEN) + return false; + + rx = data; + break; + default: + break; + } + } + + if (!tx || !rx) + return false; + + *tx_out = tx; + *rx_out = rx; + + return true; +} + +static void hwsim_add_mac_event(struct l_genl_msg *msg) +{ + const uint8_t *tx = NULL, *rx = NULL; + struct radio_info_rec *radio_rec; + struct interface_info_rec *interface_rec; + + if (!get_tx_rx_addrs(msg, &tx, &rx)) + return; + + /* No radio matches the TX address, hwsim must not have created it */ + radio_rec = l_queue_find(radio_info, radio_info_match_addr1, tx); + if (!radio_rec) + return; + + interface_rec = l_queue_find(interface_info, + interface_info_match_addr, rx); + if (interface_rec) { + /* Existing interface, address changes handled via nl80211 */ + if (interface_rec->name) + return; + + /* + * Transient/dummy interface we already know about. This likely + * was created, then a scan changed the address temporarily. + * Reflect this change and increment the ref so the following + * DEL event doesn't destroy it + */ + __atomic_fetch_add(&interface_rec->ref, 1, __ATOMIC_SEQ_CST); + return; + } + + /* + * Create a dummy interface entry for this address that only contains + * the radio and address. This is either a transient entry due to scan + * randomization or an interface created outside this namespace. + */ + interface_rec = l_new(struct interface_info_rec, 1); + interface_rec->radio_rec = radio_rec; + interface_rec->ref = 1; + memcpy(interface_rec->addr, rx, ETH_ALEN); + + l_queue_push_tail(interface_info, interface_rec); +} + +static void hwsim_del_mac_event(struct l_genl_msg *msg) +{ + const uint8_t *tx = NULL, *rx = NULL; + struct radio_info_rec *radio_rec; + struct interface_info_rec *interface_rec; + + if (!get_tx_rx_addrs(msg, &tx, &rx)) + return; + + /* No radio matches the TX address, hwsim must not have created it */ + radio_rec = l_queue_find(radio_info, radio_info_match_addr1, tx); + if (!radio_rec) + return; + + interface_rec = l_queue_find(interface_info, + interface_info_match_addr, rx); + if (!interface_rec) + return; + + /* + * This change is handled via nl80211 so we don't want to touch this + * interface here. + */ + if (interface_rec->name) + return; + + if (__atomic_sub_fetch(&interface_rec->ref, 1, __ATOMIC_SEQ_CST)) + return; + + l_queue_remove(interface_info, interface_rec); + l_free(interface_rec); +} + +static void hwsim_unicast_handler(struct l_genl_msg *msg, void *user_data) +{ + uint8_t cmd; + + if (l_genl_msg_get_error(msg) < 0) + return; + + cmd = l_genl_msg_get_command(msg); + + switch (cmd) { + case HWSIM_CMD_FRAME: + hwsim_frame_event(msg); + break; + case HWSIM_CMD_ADD_MAC_ADDR: + hwsim_add_mac_event(msg); + break; + case HWSIM_CMD_DEL_MAC_ADDR: + hwsim_del_mac_event(msg); + break; + default: + break; + } +} + static void radio_manager_create_callback(struct l_genl_msg *msg, void *user_data) { @@ -2937,8 +3087,9 @@ static void hwsim_ready(void) } if (!l_genl_add_unicast_watch(genl, "MAC80211_HWSIM", - unicast_handler, NULL, NULL)) { - l_error("Failed to set unicast handler"); + hwsim_unicast_handler, + NULL, NULL)) { + l_error("Failed to set hwsim unicast handler"); goto error; }