wiphy: change wiphy_control_port_capable -> enabled
James Prestwood
PATCH v2 1/11 wiphy: change wiphy_control_port_capable -> enabled
Move the reading of ControlPortOverNL80211 into wiphy itself and renamed wiphy_control_port_capable to wiphy_control_port_enabled. This makes things easier for any modules interested in control port support since they will only have to check this one API rather than read the settings and check capability.
--- src/netdev.c | 7 +------ src/wiphy.c | 16 +++++++++++++--- src/wiphy.h | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-)
src/netdev.c +1 -6
@@ -203,7 +203,6 @@ static struct l_netlink *rtnl = NULL;static struct l_genl_family *nl80211;static struct l_queue *netdev_list;static struct watchlist netdev_watches; -static bool pae_over_nl80211;static bool mac_per_ssid; static unsigned int iov_ie_append(struct iovec *iov,
@@ -6096,7 +6095,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,return NULL ; } -if (!pae_over_nl80211 || !wiphy_control_port_capable (wiphy)) { +if (!wiphy_control_port_enabled (wiphy)) { pae_io =pae_open (ifindex);if (!pae_io) {l_error ("Unable to open PAE interface" );
@@ -6233,10 +6232,6 @@ static int netdev_init(void) &LOW_SIGNAL_THRESHOLD_5GHZ))LOW_SIGNAL_THRESHOLD_5GHZ =-76 ; -if (!l_settings_get_bool (settings,"General" ,"ControlPortOverNL80211" , - &pae_over_nl80211)) - pae_over_nl80211 = true; - rand_addr_str =l_settings_get_value (settings,"General" ,"AddressRandomization" );if (rand_addr_str && !strcmp (rand_addr_str,"network" ))
src/wiphy.c +13 -3
@@ -555,8 +555,11 @@ bool wiphy_uses_default_if(struct wiphy *wiphy)return false; } -bool wiphy_control_port_capable (struct wiphy *wiphy) +bool wiphy_control_port_enabled (struct wiphy *wiphy) { +const struct l_settings *settings =iwd_get_config (); +bool enabled; +if (wiphy->driver_info && wiphy->driver_info->flags &FORCE_PAE ) { l_info("Not using Control Port due to driver quirks: %s",
@@ -564,8 +567,15 @@ bool wiphy_control_port_capable(struct wiphy *wiphy)return false; } -return wiphy_has_ext_feature (wiphy, -NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211 ); +if (!wiphy_has_ext_feature (wiphy, +NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211 )) +return false; + +if (!l_settings_get_bool (settings,"General" , +"ControlPortOverNL80211" , &enabled)) + enabled = true; + +return enabled; }const uint8_t *wiphy_get_permanent_address (struct wiphy *wiphy)
src/wiphy.h +1 -1
@@ -102,7 +102,7 @@ bool wiphy_supports_firmware_roam(struct wiphy *wiphy);const char *wiphy_get_driver (struct wiphy *wiphy);const char *wiphy_get_name (struct wiphy *wiphy);bool wiphy_uses_default_if (struct wiphy *wiphy); -bool wiphy_control_port_capable (struct wiphy *wiphy); +bool wiphy_control_port_enabled (struct wiphy *wiphy);const uint8_t *wiphy_get_permanent_address (struct wiphy *wiphy);const uint8_t *wiphy_get_extended_capabilities (struct wiphy *wiphy,uint32_t iftype);
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 2/11 handshake: add flags/key_index for extended key IDs
ext_key_id_capable indicates the handshake has set the capability bit in the RSN info. This will only be set if the AP also has the capability set.
use_ext_key_id indicates if extended key ID procedure should be used. This is required because an AP may not send the KDE (even with capabilities set) meaning we fall back to the legacy zero key index.
ptk_index is the key index the AP chose for a given rekey.
--- src/handshake.h | 3 +++ 1 file changed, 3 insertions(+)
src/handshake.h +3 -0
@@ -128,6 +128,7 @@ struct handshake_state { bool support_fils : 1; bool authenticator_ocvc : 1; bool supplicant_ocvc : 1; + bool ext_key_id_capable : 1;uint8_t ssid[32 ];size_t ssid_len;char *passphrase;
@@ -138,6 +139,8 @@ struct handshake_state {uint8_t gtk_rsc[6 ]; uint8_t proto_version : 2;unsigned int gtk_index; + bool use_ext_key_id : 1; +uint8_t ptk_index;struct erp_cache_entry *erp_cache; bool support_ip_allocation : 1;uint32_t client_ip_addr;
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 3/11 handshake: add callback for extended key IDs
In reply to James PrestwoodThe procedure for setting extended key IDs is different from the single PTK key. The key ID is toggled between 0 and 1 and the new key is set as RX only, then set to RX/TX after message 4/4 goes out.
Since netdev needs to set this new key before sending message 4, eapol can include a built message which netdev will store if required (i.e. using PAE).
--- src/handshake.c | 21 +++++++++++++++++++++ src/handshake.h | 13 +++++++++++++ 2 files changed, 34 insertions(+)
src/handshake.c +21 -0
@@ -76,6 +76,7 @@ static handshake_get_nonce_func_t get_nonce = handshake_get_nonce;static handshake_install_tk_func_t install_tk =NULL ;static handshake_install_gtk_func_t install_gtk =NULL ;static handshake_install_igtk_func_t install_igtk =NULL ; +static handshake_install_ext_tk_func_t install_ext_tk =NULL ;void __handshake_set_get_nonce_func (handshake_get_nonce_func_t func) {
@@ -97,6 +98,11 @@ void __handshake_set_install_igtk_func(handshake_install_igtk_func_t func) install_igtk = func; } +void __handshake_set_install_ext_tk_func (handshake_install_ext_tk_func_t func) +{ + install_ext_tk = func; +} +void handshake_state_free (struct handshake_state *s) { __typeof__(s->free) destroy = s->free;
@@ -663,6 +669,21 @@ void handshake_state_install_ptk(struct handshake_state *s) } } +void handshake_state_install_ext_ptk (struct handshake_state *s, +uint8_t key_idx, +struct eapol_frame *ek,uint16_t proto, +bool noencrypt) +{ +if (install_ext_tk) { +uint32_t cipher = +ie_rsn_cipher_suite_to_cipher (s->pairwise_cipher); + +install_ext_tk (s, key_idx,handshake_get_tk (s), cipher, ek, + proto, noencrypt); + } +} + + void handshake_state_install_gtk(struct handshake_state *s, uint16_t gtk_key_index, const uint8_t *gtk, size_t gtk_len,
src/handshake.h +13 -0
@@ -27,6 +27,7 @@struct handshake_state ;enum crypto_cipher ; +struct eapol_frame ;enum handshake_kde {/* 802.11-2020 Table 12-9 in section 12.7.2 */
@@ -78,11 +79,18 @@ typedef void (*handshake_install_igtk_func_t)(struct handshake_state *hs, const uint8_t *igtk, uint8_t igtk_len, const uint8_t *ipn, uint8_t ipn_len, uint32_t cipher); +typedef void (*handshake_install_rx_tk_cb_t )(bool success,void *user_data); +typedef void (*handshake_install_ext_tk_func_t )(struct handshake_state *hs, +uint8_t key_idx,const uint8_t *tk, +uint32_t cipher, +const struct eapol_frame *step4, +uint16_t proto,bool noencrypt);void __handshake_set_get_nonce_func (handshake_get_nonce_func_t func);void __handshake_set_install_tk_func (handshake_install_tk_func_t func);void __handshake_set_install_gtk_func (handshake_install_gtk_func_t func);void __handshake_set_install_igtk_func (handshake_install_igtk_func_t func); +void __handshake_set_install_ext_tk_func (handshake_install_ext_tk_func_t func);struct handshake_state {uint32_t ifindex;
@@ -227,6 +235,11 @@ size_t handshake_state_get_kek_len(struct handshake_state *s);const uint8_t *handshake_state_get_kek (struct handshake_state *s);void handshake_state_install_ptk (struct handshake_state *s); +void handshake_state_install_ext_ptk (struct handshake_state *s, +uint8_t key_idx, +struct eapol_frame *ek,uint16_t proto, +bool noencrypt); + void handshake_state_install_gtk(struct handshake_state *s, uint16_t gtk_key_index, const uint8_t *gtk, size_t gtk_len,
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 4/11 eapol: support extended key IDs
In reply to James Prestwood802.11 added Extended Key IDs which aim to solve the issue of PTK key replacement during rekeys. Since swapping out the existing PTK may result in data loss because there may be in flight packets still using the old PTK.
Extended Key IDs use two key IDs for the PTK, which toggle between 0 and 1. During a rekey a new PTK is derived which uses the key ID not already taken by the existing PTK. This new PTK is added as RX only, then message 4/4 is sent. This ensure message 4 is encrypted using the previous PTK. Once sent, the new PTK can be modified to both RX and TX and the rekey is complete.
To handle this in eapol the extended key ID KDE is parsed which gives us the new PTK key index. Using the new handshake callback (handshake_state_set_ext_tk) the new TK is installed. The 4th message is also included as an argument which is taken care of by netdev (in case waiting for NEW_KEY is required due to PAE socekts).
--- src/eapol.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-)
src/eapol.c +55 -6
@@ -860,6 +860,7 @@ struct eapol_sm {uint8_t installed_igtk_len;uint8_t installed_igtk[CRYPTO_MAX_IGTK_LEN ];unsigned int mic_len; + bool rekey : 1; };static void eapol_sm_destroy (void *value)
@@ -1223,6 +1224,9 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,return ; } +if (sm->handshake->ptk_complete) + sm->rekey = true; +handshake_state_new_snonce (sm->handshake);handshake_state_set_anonce (sm->handshake, ek->key_nonce);
@@ -1649,6 +1653,8 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,size_t gtk_len;const uint8_t *igtk =NULL ;size_t igtk_len; +const uint8_t *key_id =NULL ; +size_t key_id_len;const uint8_t *rsne;struct ie_rsn_info rsn_info;const uint8_t *optional_rsne =NULL ;
@@ -1856,6 +1862,41 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm, }else igtk =NULL ; + key_id =handshake_util_find_kde (HANDSHAKE_KDE_KEY_ID , + decrypted_key_data, + decrypted_key_data_size, &key_id_len); +if (key_id && hs->ext_key_id_capable) { +uint8_t idx; + +if (key_id_len !=2 ) { +l_error ("invalid Key ID KDE format" ); +handshake_failed (sm,MMPDU_REASON_CODE_UNSPECIFIED ); +return ; + } + + idx =bit_field (key_id[0 ],0 ,2 ); + +/* +* IEEE 802.11-2020 - 12.7.6.4 4-way handshake message 3 +* "... the Authenticator assigns a new Key ID for the PTKSA in +* the range of 0 to 1 that is different from the Key ID +* assigned in the previous handshake" +*/ +if (idx !=0 && idx !=1 && idx != hs->ptk_index) { +l_error ("invalid Key ID KDE value (%u)" , idx); +handshake_failed (sm,MMPDU_REASON_CODE_UNSPECIFIED ); +return ; + } + + hs->ptk_index = idx; + +/* initial connection's don't do the RX only key dance */ +if (sm->rekey) + hs->use_ext_key_id = true; + +l_debug ("using Extended key ID %u" , hs->ptk_index); + } +if (hs->support_ip_allocation) {size_t len; const uint8_t *ip_alloc_kde =
@@ -1934,12 +1975,6 @@ retransmit: } } -eapol_sm_write (sm, (struct eapol_frame *) step4, unencrypted); -l_free (step4); - -if (hs->ptk_complete) -return ; -/* * For WPA1 the group handshake should be happening after we set the * ptk, this flag tells netdev to wait for the gtk/igtk before
@@ -1954,6 +1989,20 @@ retransmit:if (igtk)eapol_install_igtk (sm, igtk_key_index, igtk, igtk_len); +if (hs->use_ext_key_id && sm->rekey) { +handshake_state_install_ext_ptk (hs, hs->ptk_index, + (struct eapol_frame *) step4, +ETH_P_PAE , unencrypted); + +return ; + } + +eapol_sm_write (sm, (struct eapol_frame *) step4, unencrypted); +l_free (step4); + +if (hs->ptk_complete) +return ; +handshake_state_install_ptk (hs);if (rekey_offload)
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 5/11 netdev: support extended key IDs
In reply to James PrestwoodThis implements the new handshake callback for setting a TK with an extended key ID. The procedure is different from legacy zero index TKs.
First the new TK is set as RX only. Then message 4 should be sent out (so it uses the existing TK). This poses a slight issue with PAE sockets since message order is not guaranteed. In this case the 4th message is stored and sent after the new TK is installed. Then the new TK is modified using SET_KEY to both send and receive.
In the case of control port over NL80211 the above can be avoided and we can simply install the new key, send message 4, and modify the TK as TX + RX all in sequence, without waiting for any callbacks.
--- src/netdev.c | 408 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 307 insertions(+), 101 deletions(-)
src/netdev.c +307 -101
@@ -87,6 +87,7 @@ struct netdev_handshake_state {uint32_t group_management_new_key_cmd_id;uint32_t set_station_cmd_id;uint32_t set_pmk_cmd_id; +uint32_t pairwise_set_key_tx_cmd_id;bool ptk_installed;bool gtk_installed;bool igtk_installed;
@@ -102,6 +103,12 @@ struct netdev_ft_over_ds_info { bool parsed : 1; }; +struct netdev_ext_key_info { +uint16_t proto; +bool noencrypt; +struct eapol_frame frame[0 ]; +}; +struct netdev {uint32_t index;uint64_t wdev_id;
@@ -170,6 +177,8 @@ struct netdev {struct l_queue *ft_ds_list; +struct netdev_ext_key_info *ext_key_info; + bool connected : 1; bool associated : 1; bool operational : 1;
@@ -336,6 +345,11 @@ static void netdev_handshake_state_cancel_all(l_genl_family_cancel (nl80211, nhs->set_pmk_cmd_id); nhs->set_pmk_cmd_id =0 ; } + +if (nhs->pairwise_set_key_tx_cmd_id) { +l_genl_family_cancel (nl80211, nhs->pairwise_set_key_tx_cmd_id); + nhs->pairwise_set_key_tx_cmd_id =0 ; + } }static void netdev_handshake_state_free (struct handshake_state *hs)
@@ -766,6 +780,11 @@ static void netdev_connect_free(struct netdev *netdev) netdev->handshake =NULL ; } +if (netdev->ext_key_info) { +l_free (netdev->ext_key_info); + netdev->ext_key_info =NULL ; + } +if (netdev->neighbor_report_cb) { netdev->neighbor_report_cb (netdev, -ENOTCONN ,NULL ,0 , netdev->user_data);
@@ -1693,6 +1712,24 @@ static void netdev_set_igtk(struct handshake_state *hs, uint16_t key_index,netdev_setting_keys_failed (nhs, -EIO ); } +static struct l_genl_msg *netdev_build_cmd_set_key_tx (struct netdev *netdev) +{ +uint8_t key_mode =NL80211_KEY_SET_TX ; +struct l_genl_msg *msg =l_genl_msg_new_sized (NL80211_CMD_SET_KEY ,512 ); + +l_genl_msg_append_attr (msg,NL80211_ATTR_MAC ,ETH_ALEN , + netdev->handshake->aa); +l_genl_msg_append_attr (msg,NL80211_ATTR_IFINDEX ,4 , &netdev->index); + +l_genl_msg_enter_nested (msg,NL80211_ATTR_KEY ); +l_genl_msg_append_attr (msg,NL80211_KEY_IDX ,1 , + &netdev->handshake->ptk_index); +l_genl_msg_append_attr (msg,NL80211_KEY_MODE ,1 , &key_mode); +l_genl_msg_leave_nested (msg); + +return msg; +} +static void netdev_new_pairwise_key_cb (struct l_genl_msg *msg,void *data) {struct netdev_handshake_state *nhs = data;
@@ -1730,6 +1767,177 @@ error:netdev_setting_keys_failed (nhs, err); } +static struct l_genl_msg *netdev_build_control_port_frame (struct netdev *netdev, +const uint8_t *to, +uint16_t proto, +bool unencrypted, +const void *body, +size_t body_len) +{ +struct l_genl_msg *msg; + + msg =l_genl_msg_new_sized (NL80211_CMD_CONTROL_PORT_FRAME , +128 + body_len); + +l_genl_msg_append_attr (msg,NL80211_ATTR_IFINDEX ,4 , &netdev->index); +l_genl_msg_append_attr (msg,NL80211_ATTR_FRAME , body_len, body); +l_genl_msg_append_attr (msg,NL80211_ATTR_CONTROL_PORT_ETHERTYPE ,2 , + &proto); +l_genl_msg_append_attr (msg,NL80211_ATTR_MAC ,ETH_ALEN , to); + +if (unencrypted) +l_genl_msg_append_attr (msg, +NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT ,0 ,NULL ); + +return msg; +} + +static int netdev_set_key_tx (struct netdev *netdev) +{ +struct netdev_handshake_state *nhs =l_container_of (netdev->handshake, + struct netdev_handshake_state, super); +struct l_genl_msg *msg =netdev_build_cmd_set_key_tx (netdev); + +l_free (netdev->ext_key_info); + netdev->ext_key_info =NULL ; + + nhs->pairwise_set_key_tx_cmd_id =l_genl_family_send (nl80211, msg, + netdev_new_pairwise_key_cb, + nhs,NULL ); +if (nhs->pairwise_set_key_tx_cmd_id >0 ) +return 0 ; + +return -EIO ; +} + +static void netdev_control_port_frame_cb (struct l_genl_msg *msg, +void *user_data) +{ +struct netdev *netdev = user_data; +struct netdev_handshake_state *nhs =l_container_of (netdev->handshake, + struct netdev_handshake_state, super); +int err =l_genl_msg_get_error (msg); +const char *ext_error; + +if (err <0 ) + goto error; + +if (netdev->ext_key_info) { +if (netdev_set_key_tx (netdev) <0 ) +netdev_setting_keys_failed (nhs, -EIO ); + } + +return ; + +error: + ext_error =l_genl_msg_get_extended_error (msg); +l_error ("CMD_CONTROL_PORT failed: %s" , + ext_error ? ext_error :strerror (-err)); +} + +static int netdev_control_port_write_pae (struct netdev *netdev, +const uint8_t *dest, +uint16_t proto, +const struct eapol_frame *ef, +bool noencrypt) +{ +int fd =l_io_get_fd (netdev->pae_io); +struct sockaddr_ll sll; +size_t frame_size =sizeof (struct eapol_header ) + +L_BE16_TO_CPU (ef->header.packet_len); +ssize_t r; + +memset (&sll,0 ,sizeof (sll)); + sll.sll_family =AF_PACKET ; + sll.sll_ifindex = netdev->index; + sll.sll_protocol =htons (proto); + sll.sll_halen =ETH_ALEN ; +memcpy (sll.sll_addr, dest,ETH_ALEN ); + + r =sendto (fd, ef, frame_size,0 , + (struct sockaddr *) &sll,sizeof (sll)); +if (r <0 ) +l_error ("EAPoL write socket: %s" ,strerror (errno)); + +return r; +} + +static int netdev_control_port_frame (uint32_t ifindex, +const uint8_t *dest,uint16_t proto, +const struct eapol_frame *ef, +bool noencrypt, +void *user_data) +{ +struct l_genl_msg *msg; +struct netdev *netdev; +size_t frame_size; +int err; + + netdev =netdev_find (ifindex); +if (!netdev) +return -ENOENT ; + + frame_size =sizeof (struct eapol_header ) + +L_BE16_TO_CPU (ef->header.packet_len); + +if (!netdev->pae_over_nl80211) { + err =netdev_control_port_write_pae (netdev, dest, proto, + ef, noencrypt); +if (err <0 ) +return err; + +if (!netdev->ext_key_info) +return 0 ; + +return netdev_set_key_tx (netdev); + } + + msg =netdev_build_control_port_frame (netdev, dest, proto, noencrypt, + ef, frame_size); +if (!msg) +return -ENOMEM ; + +if (!l_genl_family_send (nl80211, msg, netdev_control_port_frame_cb, + netdev,NULL )) { +l_genl_msg_unref (msg); +return -EINVAL ; + } + +return 0 ; +} + +static void netdev_new_rx_pairwise_key_cb (struct l_genl_msg *msg,void *data) +{ +struct netdev_handshake_state *nhs = data; +struct netdev *netdev = nhs->netdev; +struct netdev_ext_key_info *info = netdev->ext_key_info; +int err =l_genl_msg_get_error (msg); + + nhs->pairwise_new_key_cmd_id =0 ; + +if (err <0 ) { +const char *ext_error =l_genl_msg_get_extended_error (msg); + +l_error ("New Key for RX Pairwise Key failed for ifindex: %d:%s" , + netdev->index, + ext_error ? ext_error :strerror (-err)); + goto error; + } + +if (!info) +return ; + + err =netdev_control_port_frame (netdev->index, netdev->handshake->aa, + info->proto, info->frame, info->noencrypt,NULL ); +if (err <0 ) + goto error; + +return ; + +error: +netdev_setting_keys_failed (nhs, err); +} + static struct l_genl_msg *netdev_build_cmd_new_key_pairwise( struct netdev *netdev, uint32_t cipher,
@@ -1751,6 +1959,36 @@ static struct l_genl_msg *netdev_build_cmd_new_key_pairwise(return msg; } +static struct l_genl_msg *netdev_build_cmd_new_rx_key_pairwise ( +struct netdev *netdev, +uint32_t cipher, +const uint8_t *aa, +const uint8_t *tk, +size_t tk_len, +uint8_t key_id) +{ +uint8_t key_mode =NL80211_KEY_NO_TX ; +uint32_t key_type =NL80211_KEYTYPE_PAIRWISE ; +struct l_genl_msg *msg; + + msg =l_genl_msg_new_sized (NL80211_CMD_NEW_KEY ,512 ); + +l_genl_msg_append_attr (msg,NL80211_ATTR_MAC ,ETH_ALEN , aa); +l_genl_msg_append_attr (msg,NL80211_ATTR_IFINDEX ,4 , &netdev->index); + +l_genl_msg_enter_nested (msg,NL80211_ATTR_KEY ); + +l_genl_msg_append_attr (msg,NL80211_KEY_DATA , tk_len, tk); +l_genl_msg_append_attr (msg,NL80211_KEY_CIPHER ,4 , &cipher); +l_genl_msg_append_attr (msg,NL80211_KEY_IDX ,1 , &key_id); +l_genl_msg_append_attr (msg,NL80211_KEY_MODE ,1 , &key_mode); +l_genl_msg_append_attr (msg,NL80211_KEY_TYPE ,4 , &key_type); + +l_genl_msg_leave_nested (msg); + +return msg; +} +static void netdev_group_timeout_cb (struct l_timeout *timeout,void *user_data) {struct netdev_handshake_state *nhs = user_data;
@@ -1836,6 +2074,74 @@ invalid_key:netdev_setting_keys_failed (nhs, err); } +static void netdev_set_ext_tk (struct handshake_state *hs,uint8_t key_idx, +const uint8_t *tk,uint32_t cipher, +const struct eapol_frame *step4,uint16_t proto, +bool noencrypt) +{ +struct netdev_handshake_state *nhs = + l_container_of(hs, struct netdev_handshake_state, super); +uint8_t tk_buf[32 ]; +struct netdev *netdev = nhs->netdev; +struct l_genl_msg *msg; +const uint8_t *addr =netdev_choose_key_address (nhs); +int err; +size_t frame_size =sizeof (struct eapol_header ) + +L_BE16_TO_CPU (step4->header.packet_len); + + err = -ENOENT ; +if (!netdev_copy_tk (tk_buf, tk, cipher, false)) + goto invalid_key; + + msg =netdev_build_cmd_new_rx_key_pairwise (netdev, cipher, addr, tk_buf, +crypto_cipher_key_len (cipher), + hs->ptk_index); + nhs->pairwise_new_key_cmd_id = +l_genl_family_send (nl80211, msg, netdev_new_rx_pairwise_key_cb, + nhs,NULL ); + +if (!nhs->pairwise_new_key_cmd_id) + goto io_error; + +/* +* Without control port we cannot guarantee the order that messages go +* out and must wait for NEW_KEY to call back before sending message 4 +*/ +if (!wiphy_control_port_enabled (netdev->wiphy)) { + netdev->ext_key_info =l_malloc ( +sizeof (struct netdev_ext_key_info ) + + frame_size); +memcpy (netdev->ext_key_info->frame, step4, frame_size); + netdev->ext_key_info->proto = proto; + netdev->ext_key_info->noencrypt = noencrypt; +return ; + } + +/* +* Otherwise, order of messages will be guaranteed. Therefore we can +* send send message 4, and set the TK to TX (below) without waiting for +* any callbacks +*/ +netdev_control_port_frame (netdev->index, netdev->handshake->aa, proto, + step4, noencrypt,NULL ); + +/* Then toggle to RX + TX */ + msg =netdev_build_cmd_set_key_tx (netdev); + + nhs->pairwise_set_key_tx_cmd_id =l_genl_family_send (nl80211, msg, + netdev_new_pairwise_key_cb, + nhs,NULL ); +if (nhs->pairwise_set_key_tx_cmd_id >0 ) +return ; + +io_error: + err = -EIO ; +l_genl_msg_unref (msg); + +invalid_key: +netdev_setting_keys_failed (nhs, err); +} +static void netdev_set_pmk_cb (struct l_genl_msg *msg,void *user_data) {struct netdev_handshake_state *nhs = user_data;
@@ -5122,107 +5428,6 @@ static void netdev_control_port_frame_event(struct l_genl_msg *msg, frame, frame_len, unencrypted); } -static struct l_genl_msg *netdev_build_control_port_frame (struct netdev *netdev, -const uint8_t *to, -uint16_t proto, -bool unencrypted, -const void *body, -size_t body_len) -{ -struct l_genl_msg *msg; - - msg =l_genl_msg_new_sized (NL80211_CMD_CONTROL_PORT_FRAME , -128 + body_len); - -l_genl_msg_append_attr (msg,NL80211_ATTR_IFINDEX ,4 , &netdev->index); -l_genl_msg_append_attr (msg,NL80211_ATTR_FRAME , body_len, body); -l_genl_msg_append_attr (msg,NL80211_ATTR_CONTROL_PORT_ETHERTYPE ,2 , - &proto); -l_genl_msg_append_attr (msg,NL80211_ATTR_MAC ,ETH_ALEN , to); - -if (unencrypted) -l_genl_msg_append_attr (msg, -NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT ,0 ,NULL ); - -return msg; -} - -static void netdev_control_port_frame_cb (struct l_genl_msg *msg, -void *user_data) -{ -int err =l_genl_msg_get_error (msg); -const char *ext_error; - -if (err >=0 ) -return ; - - ext_error =l_genl_msg_get_extended_error (msg); -l_error ("CMD_CONTROL_PORT failed: %s" , - ext_error ? ext_error :strerror (-err)); -} - -static int netdev_control_port_write_pae (struct netdev *netdev, -const uint8_t *dest, -uint16_t proto, -const struct eapol_frame *ef, -bool noencrypt) -{ -int fd =l_io_get_fd (netdev->pae_io); -struct sockaddr_ll sll; -size_t frame_size =sizeof (struct eapol_header ) + -L_BE16_TO_CPU (ef->header.packet_len); -ssize_t r; - -memset (&sll,0 ,sizeof (sll)); - sll.sll_family =AF_PACKET ; - sll.sll_ifindex = netdev->index; - sll.sll_protocol =htons (proto); - sll.sll_halen =ETH_ALEN ; -memcpy (sll.sll_addr, dest,ETH_ALEN ); - - r =sendto (fd, ef, frame_size,0 , - (struct sockaddr *) &sll,sizeof (sll)); -if (r <0 ) -l_error ("EAPoL write socket: %s" ,strerror (errno)); - -return r; -} - -static int netdev_control_port_frame (uint32_t ifindex, -const uint8_t *dest,uint16_t proto, -const struct eapol_frame *ef, -bool noencrypt, -void *user_data) -{ -struct l_genl_msg *msg; -struct netdev *netdev; -size_t frame_size; - - netdev =netdev_find (ifindex); -if (!netdev) -return -ENOENT ; - - frame_size =sizeof (struct eapol_header ) + -L_BE16_TO_CPU (ef->header.packet_len); - -if (!netdev->pae_over_nl80211) -return netdev_control_port_write_pae (netdev, dest, proto, - ef, noencrypt); - - msg =netdev_build_control_port_frame (netdev, dest, proto, noencrypt, - ef, frame_size); -if (!msg) -return -ENOMEM ; - -if (!l_genl_family_send (nl80211, msg, netdev_control_port_frame_cb, - netdev,NULL )) { -l_genl_msg_unref (msg); -return -EINVAL ; - } - -return 0 ; -} -static void netdev_unicast_notify (struct l_genl_msg *msg,void *user_data) {struct netdev *netdev =NULL ;
@@ -6243,6 +6448,7 @@ static int netdev_init(void)__handshake_set_install_tk_func (netdev_set_tk);__handshake_set_install_gtk_func (netdev_set_gtk);__handshake_set_install_igtk_func (netdev_set_igtk); +__handshake_set_install_ext_tk_func (netdev_set_ext_tk);__eapol_set_rekey_offload_func (netdev_set_rekey_offload);__eapol_set_tx_packet_func (netdev_control_port_frame);
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 6/11 station: set extended key capability
In reply to James PrestwoodIf wiphy and the AP suppor it, set the Extended Key ID capability bit in the RSN info and set the handshake to use it.
--- src/station.c | 6 ++++++ 1 file changed, 6 insertions(+)
src/station.c +6 -0
@@ -1087,6 +1087,12 @@ build_ie: info.ocvc = !disable_ocv; +/* Extended Key IDs can only be used if supported by both AP and STA */ +if (wiphy_supports_ext_key_id (wiphy) && bss_info.extended_key_id) { + info.extended_key_id = true; + hs->ext_key_id_capable = true; + } +/* RSN takes priority */ if (bss->rsne) { ap_ie = bss->rsne;
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 7/11 auto-t: iwd.py: make wait() a static method
In reply to James PrestwoodThis allows it to be used without initializing an IWD class:
IWD.wait(1)
--- autotests/util/iwd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
autotests/util/iwd.py +2 -1
@@ -1133,7 +1133,8 @@ class IWD(AsyncOpAbstract): ' condition was not met in '\ + str(max_wait) + ' sec')) - def wait(self, time): + @staticmethod + def wait(time): ctx.non_block_wait(lambda : False, time, exception=False) @staticmethod
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 8/11 nl80211util: set multicast on new group keys
In reply to James PrestwoodThis may not be required but setting the group key mode explicitly to multicast makes things consistent, even if only for the benefit of reading iwmon logs easier.
--- src/nl80211util.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
src/nl80211util.c +5 -9
@@ -247,6 +247,7 @@ struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher size_t ctr_len, const uint8_t *addr) { struct l_genl_msg *msg; +uint32_t type =NL80211_KEYTYPE_GROUP ; msg =l_genl_msg_new_sized (NL80211_CMD_NEW_KEY ,512 );
@@ -263,16 +264,11 @@ struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipherif (ctr)l_genl_msg_append_attr (msg,NL80211_KEY_SEQ , ctr_len, ctr); -if (addr) { -uint32_t type =NL80211_KEYTYPE_GROUP ; - -l_genl_msg_append_attr (msg,NL80211_KEY_TYPE ,4 , &type); -l_genl_msg_enter_nested (msg,NL80211_KEY_DEFAULT_TYPES ); -l_genl_msg_append_attr (msg,NL80211_KEY_DEFAULT_TYPE_MULTICAST , +l_genl_msg_append_attr (msg,NL80211_KEY_TYPE ,4 , &type); +l_genl_msg_enter_nested (msg,NL80211_KEY_DEFAULT_TYPES ); +l_genl_msg_append_attr (msg,NL80211_KEY_DEFAULT_TYPE_MULTICAST ,0 ,NULL ); -l_genl_msg_leave_nested (msg); - } - +l_genl_msg_leave_nested (msg);l_genl_msg_leave_nested (msg);return msg;
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 9/11 auto-t: hostapd.py: separate GTK and PTK rekeys
In reply to James PrestwoodREKEY_GTK kicks off the GTK only handshake where REKEY_PTK does both (via the 4-way). The way this utility was written was causing hostapd some major issues since both REKEY_GTK and REKEY_PTK was used.
Instead if address is set only do REKEY_PTK. This will also rekey the GTK via the 4-way handshake.
If no address is set do REKEY_GTK which will only rekey the GTK.
--- autotests/util/hostapd.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
autotests/util/hostapd.py +7 -3
@@ -202,11 +202,15 @@ class HostapdCLI(object): cmd = self.cmdline + ['req_beacon', addr, request] ctx.start_process(cmd).wait() - def rekey(self, address): + def rekey(self, address=None): + if address: + cmd = 'REKEY_PTK %s' % address + self.ctrl_sock.sendall(cmd.encode('utf-8')) + self.wait_for_event('EAPOL-4WAY-HS-COMPLETED') + return + cmd = 'REKEY_GTK' self.ctrl_sock.sendall(cmd.encode('utf-8')) - cmd = 'REKEY_PTK %s' % address - self.ctrl_sock.sendall(cmd.encode('utf-8')) @property def bssid(self):
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 10/11 auto-t: Add test for extended key IDs
In reply to James Prestwood--- .../testWPA2-ext-key-id/connection_test.py | 85 +++++++++++++++++++ autotests/testWPA2-ext-key-id/hw.conf | 6 ++ autotests/testWPA2-ext-key-id/main_pae.conf | 2 + autotests/testWPA2-ext-key-id/ssidCCMP.conf | 11 +++ 4 files changed, 104 insertions(+) create mode 100644 autotests/testWPA2-ext-key-id/connection_test.py create mode 100644 autotests/testWPA2-ext-key-id/hw.conf create mode 100644 autotests/testWPA2-ext-key-id/main_pae.conf create mode 100644 autotests/testWPA2-ext-key-id/ssidCCMP.conf
autotests/testWPA2-ext-key-id/connection_test.py new file +85 -0
@@ -0,0 +1,85 @@ +#!/usr/bin/python3 + +import unittest +import sys +import os + +sys.path.append('../util') +from iwd import IWD_CONFIG_DIR +from iwd import IWD +from iwd import PSKAgent +from iwd import NetworkType +from hostapd import HostapdCLI +import testutil + +class Test(unittest.TestCase): + + def validate(self, wd): + hapd = HostapdCLI('ssidCCMP.conf') + + psk_agent = PSKAgent("secret123") + wd.register_psk_agent(psk_agent) + + devices = wd.list_devices(1) + device = devices[0] + + ordered_network = device.get_ordered_network('ssidCCMP') + + self.assertEqual(ordered_network.type, NetworkType.psk) + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + ordered_network.network_object.connect() + + condition = 'obj.state == DeviceState.connected' + wd.wait_for_object_condition(device, condition) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected() + + # Rekey 5 times just to make sure the key ID can be toggled back and + # forth without causing problems. + for i in range(5): + hapd.rekey(device.address) + + testutil.test_iface_operstate() + testutil.test_ifaces_connected() + + device.disconnect() + + condition = 'not obj.connected' + wd.wait_for_object_condition(ordered_network.network_object, condition) + + wd.unregister_psk_agent(psk_agent) + + def test_ext_key_control_port(self): + self.wd = IWD(True) + + self.validate(self.wd) + + def test_ext_key_pae(self): + IWD.copy_to_storage('main_pae.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf') + + self.wd = IWD(True) + + self.validate(self.wd) + + def tearDown(self): + try: + os.system('rm -rf %s/main.conf' % IWD_CONFIG_DIR) + except: + pass + + self.wd = None + + @classmethod + def setUpClass(cls): + pass + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True)
autotests/testWPA2-ext-key-id/hw.conf new file +6 -0
@@ -0,0 +1,6 @@ +[SETUP] +num_radios=2 +start_iwd=0 + +[HOSTAPD] +rad0=ssidCCMP.conf
autotests/testWPA2-ext-key-id/main_pae.conf new file +2 -0
@@ -0,0 +1,2 @@ +[General] +ControlPortOverNL80211=false
autotests/testWPA2-ext-key-id/ssidCCMP.conf new file +11 -0
@@ -0,0 +1,11 @@ +hw_mode=g +channel=1 +ssid=ssidCCMP + +wpa=2 +wpa_pairwise=CCMP +wpa_passphrase=secret123 + +ieee80211w=2 +wpa_key_mgmt=WPA-PSK-SHA256 +extended_key_id=1
Signature · 1 line
2.31.1
James Prestwood
PATCH v2 11/11 auto-t: update rekey() use to not wait for event
In reply to James PrestwoodThe hostapd event wait was moved into rekey() itself.
--- autotests/testFILS/fils_256_test.py | 1 - autotests/testFILS/fils_384_test.py | 1 - autotests/testFT-FILS/connection_test.py | 1 - autotests/testPSK-roam/connection_test.py | 1 - 4 files changed, 4 deletions(-)
autotests/testFILS/fils_256_test.py +0 -1
@@ -56,7 +56,6 @@ class Test(unittest.TestCase): testutil.test_ifaces_connected(device.name, hapd.ifname) hapd.rekey(device.address) - hapd.wait_for_event('EAPOL-4WAY-HS-COMPLETED') device.disconnect()
autotests/testFILS/fils_384_test.py +0 -1
@@ -56,7 +56,6 @@ class Test(unittest.TestCase): testutil.test_ifaces_connected(device.name, hapd.ifname) hapd.rekey(device.address) - hapd.wait_for_event('EAPOL-4WAY-HS-COMPLETED') device.disconnect()
autotests/testFT-FILS/connection_test.py +0 -1
@@ -96,7 +96,6 @@ class Test(unittest.TestCase): (self.bss_hostapd[0].ifname, device.name, True, True)) self.bss_hostapd[1].rekey(device.address) - self.bss_hostapd[1].wait_for_event('EAPOL-4WAY-HS-COMPLETED') def test_fils_ft_roam_sha256(self): wd = IWD(True)
autotests/testPSK-roam/connection_test.py +0 -1
@@ -81,7 +81,6 @@ class Test(unittest.TestCase): (self.bss_hostapd[0].ifname, device.name, True, True)) self.bss_hostapd[1].rekey(device.address) - self.bss_hostapd[1].wait_for_event('EAPOL-4WAY-HS-COMPLETED') device.roam(self.bss_hostapd[0].bssid)
Signature · 1 line
2.31.1