nixos/wireless: don't attempt fallback on WPA3 only networks

main
rnhmjoj 2 years ago
parent d67ad28fc3
commit 3b8fa47f58
No known key found for this signature in database
GPG Key ID: BFBAF4C975F76450
  1. 10
      nixos/modules/services/networking/wpa_supplicant.nix
  2. 19
      nixos/tests/wpa_supplicant.nix

@ -11,11 +11,15 @@ let
opt = options.networking.wireless;
wpa3Protocols = [ "SAE" "FT-SAE" ];
hasWPA3 = opts: !mutuallyExclusive opts.authProtocols wpa3Protocols;
hasMixedWPA = opts:
let
hasWPA3 = !mutuallyExclusive opts.authProtocols wpa3Protocols;
others = subtractLists wpa3Protocols opts.authProtocols;
in hasWPA3 && others != [];
# Gives a WPA3 network higher priority
increaseWPA3Priority = opts:
opts // optionalAttrs (hasWPA3 opts)
opts // optionalAttrs (hasMixedWPA opts)
{ priority = if opts.priority == null
then 1
else opts.priority + 1;
@ -33,7 +37,7 @@ let
allNetworks =
if cfg.fallbackToWPA2
then map increaseWPA3Priority networkList
++ map mkWPA2Fallback (filter hasWPA3 networkList)
++ map mkWPA2Fallback (filter hasMixedWPA networkList)
else networkList;
# Content of wpa_supplicant.conf

@ -27,8 +27,19 @@ import ./make-test-python.nix ({ pkgs, lib, ...}:
enable = lib.mkOverride 0 true;
userControlled.enable = true;
interfaces = [ "wlan1" ];
fallbackToWPA2 = true;
networks = {
# test WPA2 fallback
mixed-wpa = {
psk = "password";
authProtocols = [ "WPA-PSK" "SAE" ];
};
sae-only = {
psk = "password";
authProtocols = [ "SAE" ];
};
# test network
nixos-test.psk = "@PSK_NIXOS_TEST@";
@ -64,8 +75,12 @@ import ./make-test-python.nix ({ pkgs, lib, ...}:
machine.succeed(f"grep -q @PSK_MISSING@ {config_file}")
machine.succeed(f"grep -q P@ssowrdWithSome@tSymbol {config_file}")
# save file for manual inspection
machine.copy_from_vm(config_file)
with subtest("WPA2 fallbacks have been generated"):
assert int(machine.succeed(f"grep -c sae-only {config_file}")) == 1
assert int(machine.succeed(f"grep -c mixed-wpa {config_file}")) == 2
# save file for manual inspection
machine.copy_from_vm(config_file)
with subtest("Daemon is running and accepting connections"):
machine.wait_for_unit("wpa_supplicant-wlan1.service")

Loading…
Cancel
Save