From 790ab927f0df37746b9e08eac4fa5adf9a10e831 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 18 Aug 2017 18:57:18 +0200 Subject: [PATCH] wireless networks: Allow using multiple modes at the same time To be more compatible with networks where encryption methods are unknown, we allow using multiple (or all) methods that we support at the same time. Signed-off-by: Michael Tremer --- src/functions/functions.wireless-networks | 119 ++++++++++++---------- 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/src/functions/functions.wireless-networks b/src/functions/functions.wireless-networks index 9835289..d2a81ac 100644 --- a/src/functions/functions.wireless-networks +++ b/src/functions/functions.wireless-networks @@ -19,7 +19,11 @@ # # ############################################################################### -WIRELESS_NETWORK_CONFIG_SETTINGS="EAP_MODES ENCRYPTION_MODE PRIORITY PSK SSID" +WIRELESS_NETWORK_SUPPORTED_PSK_MODES="WPA2-PSK-SHA256 WPA2-PSK WPA-PSK-SHA256 WPA-PSK" + +WIRELESS_NETWORK_SUPPORTED_MODES="${WIRELESS_NETWORK_SUPPORTED_PSK_MODES} NONE" + +WIRELESS_NETWORK_CONFIG_SETTINGS="EAP_MODES ENCRYPTION_MODES PRIORITY PSK SSID" cli_wireless_network() { case "${1}" in @@ -351,49 +355,58 @@ wireless_network_to_wpa_supplicant() { local pairwise local proto - case "${ENCRYPTION_MODE}" in - # Normal WPA - WPA-PSK) - auth_alg="OPEN" - key_mgmt="WPA-PSK" - proto="WPA" - pairwise="CCMP TKIP" - group="CCMP TKIP WEP104 WEP40" - ;; - - # WPA with stronger algorithms - WPA-PSK-SHA256) - auth_alg="OPEN" - key_mgmt="WPA-PSK-SHA256" - proto="WPA" - pairwise="CCMP TKIP" - group="CCMP TKIP WEP104 WEP40" - ;; - - # Normal WPA2 (802.11i) - WPA2-PSK) - auth_alg="OPEN" - key_mgmt="WPA-PSK" - proto="RSN" - pairwise="CCMP TKIP" - group="CCMP TKIP WEP104 WEP40" - ;; + local mode + for mode in ${WIRELESS_NETWORK_SUPPORTED_MODES}; do + # Skip any disabled modes + if isset ENCRYPTION_MODES && ! list_match "${mode}" ${ENCRYPTION_MODES}; then + continue + fi - # WPA2 with stronger algorithms - WPA2-PSK-SHA256) - auth_alg="OPEN" - key_mgmt="WPA-PSK-SHA256" - proto="RSN" - pairwise="CCMP TKIP" - group="CCMP TKIP WEP104 WEP40" - ;; + case "${mode}" in + # WPA2 (802.11i) + WPA2-PSK|WPA2-PSK-SHA256) + list_append_unique auth_alg "OPEN" + list_append_unique key_mgmt "${mode/WPA2/WPA}" + list_append_unique proto "RSN" + + local p + for p in CCMP TKIP; do + list_append_unique pairwise "${p}" + done + + local g + for g in CCMP TKIP WEP104 WEP40; do + list_append_unique group "${g}" + done + ;; + + # WPA + WPA-PSK|WPA-PSK-SHA256) + list_append_unique auth_alg "OPEN" + list_append_unique key_mgmt "${mode}" + list_append_unique proto "WPA" + + local p + for p in CCMP TKIP; do + list_append_unique pairwise "${p}" + done + + local g + for g in CCMP TKIP WEP104 WEP40; do + list_append_unique group "${g}" + done + ;; + + # No encryption. DANGEROUS! + NONE) + list_append_unique auth_alg "OPEN" + list_append_unique key_mgmt "NONE" + ;; + esac + done - # No encryption. DANGEROUS! - NONE) - auth_alg="OPEN" - key_mgmt="NONE" - ;; - esac + assert isset auth_alg + assert isset key_mgmt print_indent 0 "# ${SSID}" print_indent 0 "network = {" @@ -405,19 +418,17 @@ wireless_network_to_wpa_supplicant() { print_indent 1 "auth_alg=${auth_alg}" print_indent 1 "key_mgmt=${key_mgmt}" - case "${ENCRYPTION_MODE}" in - WPA*) - print_indent 1 "proto=${proto}" - print_indent 1 "pairwise=${pairwise}" - ;; - esac + local i + for i in proto pairwise group; do + print_indent 1 "${i}=${!i}" + done + print - # PSKs - case "${ENCRYPTION_MODE}" in - WPA*PSK) - print_indent 1 "psk=\"${PSK}\"" - ;; - esac + # PSK + if isset PSK; then + print_indent 1 "# Pre Shared Key" + print_indent 1 "psk=\"${PSK}\"" + fi if isset EAP_MODES; then print_indent 1 "# EAP" -- 2.47.3