Merge pull request #154130 from rnhmjoj/fix-wpa

nixos/wireless: enable PMF by default

authored by Michele Guerini Rocco and committed by GitHub 5af7724c 37246842

+42 -3
+42 -3
nixos/modules/services/networking/wpa_supplicant.nix
··· 10 cfg = config.networking.wireless; 11 opt = options.networking.wireless; 12 13 # Content of wpa_supplicant.conf 14 generatedConfig = concatStringsSep "\n" ( 15 - (mapAttrsToList mkNetwork cfg.networks) 16 ++ optional cfg.userControlled.enable (concatStringsSep "\n" 17 [ "ctrl_interface=/run/wpa_supplicant" 18 "ctrl_interface_group=${cfg.userControlled.group}" 19 "update_config=1" 20 ]) 21 ++ optional cfg.scanOnLowSignal ''bgscan="simple:30:-70:3600"'' 22 ++ optional (cfg.extraConfig != "") cfg.extraConfig); 23 ··· 33 finalConfig = ''"$RUNTIME_DIRECTORY"/wpa_supplicant.conf''; 34 35 # Creates a network block for wpa_supplicant.conf 36 - mkNetwork = ssid: opts: 37 let 38 quote = x: ''"${x}"''; 39 indent = x: " " + x; ··· 43 else opts.pskRaw; 44 45 options = [ 46 - "ssid=${quote ssid}" 47 (if pskString != null || opts.auth != null 48 then "key_mgmt=${concatStringsSep " " opts.authProtocols}" 49 else "key_mgmt=NONE") ··· 172 Whether to periodically scan for (better) networks when the signal of 173 the current one is low. This will make roaming between access points 174 faster, but will consume more power. 175 ''; 176 }; 177
··· 10 cfg = config.networking.wireless; 11 opt = options.networking.wireless; 12 13 + wpa3Protocols = [ "SAE" "FT-SAE" ]; 14 + hasWPA3 = opts: !mutuallyExclusive opts.authProtocols wpa3Protocols; 15 + 16 + # Gives a WPA3 network higher priority 17 + increaseWPA3Priority = opts: 18 + opts // optionalAttrs (hasWPA3 opts) 19 + { priority = if opts.priority == null 20 + then 1 21 + else opts.priority + 1; 22 + }; 23 + 24 + # Creates a WPA2 fallback network 25 + mkWPA2Fallback = opts: 26 + opts // { authProtocols = subtractLists wpa3Protocols opts.authProtocols; }; 27 + 28 + # Networks attrset as a list 29 + networkList = mapAttrsToList (ssid: opts: opts // { inherit ssid; }) 30 + cfg.networks; 31 + 32 + # List of all networks (normal + generated fallbacks) 33 + allNetworks = 34 + if cfg.fallbackToWPA2 35 + then map increaseWPA3Priority networkList 36 + ++ map mkWPA2Fallback (filter hasWPA3 networkList) 37 + else networkList; 38 + 39 # Content of wpa_supplicant.conf 40 generatedConfig = concatStringsSep "\n" ( 41 + (map mkNetwork allNetworks) 42 ++ optional cfg.userControlled.enable (concatStringsSep "\n" 43 [ "ctrl_interface=/run/wpa_supplicant" 44 "ctrl_interface_group=${cfg.userControlled.group}" 45 "update_config=1" 46 ]) 47 + ++ [ "pmf=1" ] 48 ++ optional cfg.scanOnLowSignal ''bgscan="simple:30:-70:3600"'' 49 ++ optional (cfg.extraConfig != "") cfg.extraConfig); 50 ··· 60 finalConfig = ''"$RUNTIME_DIRECTORY"/wpa_supplicant.conf''; 61 62 # Creates a network block for wpa_supplicant.conf 63 + mkNetwork = opts: 64 let 65 quote = x: ''"${x}"''; 66 indent = x: " " + x; ··· 70 else opts.pskRaw; 71 72 options = [ 73 + "ssid=${quote opts.ssid}" 74 (if pskString != null || opts.auth != null 75 then "key_mgmt=${concatStringsSep " " opts.authProtocols}" 76 else "key_mgmt=NONE") ··· 199 Whether to periodically scan for (better) networks when the signal of 200 the current one is low. This will make roaming between access points 201 faster, but will consume more power. 202 + ''; 203 + }; 204 + 205 + fallbackToWPA2 = mkOption { 206 + type = types.bool; 207 + default = true; 208 + description = '' 209 + Whether to fall back to WPA2 authentication protocols if WPA3 failed. 210 + This allows old wireless cards (that lack recent features required by 211 + WPA3) to connect to mixed WPA2/WPA3 access points. 212 + 213 + To avoid possible downgrade attacks, disable this options. 214 ''; 215 }; 216