commit c7dc1c20fbfc9a1a5ba21f2a56edda337f77ed03
parent f94ab388f7b482376b4083c99c3f107c012c56b4
Author: illiliti <illiliti@protonmail.com>
Date: Tue, 3 Aug 2021 01:38:09 +0300
Merge tag '1.16'
Release 1.16
Diffstat:
80 files changed, 2619 insertions(+), 1535 deletions(-)
diff --git a/AUTHORS b/AUTHORS
@@ -28,3 +28,5 @@ Mathy Vanhoef <Mathy.Vanhoef@kuleuven.be>
Jonathan Liu <net147@gmail.com>
Daniel Lin <ephemient@gmail.com>
Sean Anderson <sean.anderson@seco.com>
+Joseph Benden <joe@benden.us>
+Michael Johnson <mjohnson459@gmail.com>
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,9 @@
+ver 1.16:
+ Fix issue with writing provisioning files with a passphrase.
+ Add support for Authenticator & Supplicant RSN Extension elements.
+ Add support for handling Transition Disable info.
+ Add support for SAE Hash-to-Element feature.
+
ver 1.15:
Add support for FT-over-DS procedure with multiple BSS.
Add support for estimation of VHT RX data rate.
diff --git a/Makefile.am b/Makefile.am
@@ -526,6 +526,7 @@ unit_test_sae_SOURCES = unit/test-sae.c \
src/util.h src/util.c \
src/mpdu.h src/mpdu.c
unit_test_sae_LDADD = $(ell_ldadd)
+unit_test_sae_LDFLAGS = -Wl,-wrap,l_ecc_supported_ike_groups
unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \
src/crypto.h src/crypto.c \
diff --git a/autotests/testBSSBlacklist/bad_pass_test.py b/autotests/testBSSBlacklist/bad_pass_test.py
@@ -32,12 +32,12 @@ class Test(unittest.TestCase):
rule1 = hwsim.rules.create()
rule1.source = bss_radio[1].addresses[0]
rule1.bidirectional = True
- rule1.signal = -3000
+ rule1.signal = -7000
rule2 = hwsim.rules.create()
rule2.source = bss_radio[2].addresses[0]
rule2.bidirectional = True
- rule2.signal = -4000
+ rule2.signal = -8000
wd = IWD(True)
diff --git a/autotests/testBSSBlacklist/connection_test.py b/autotests/testBSSBlacklist/connection_test.py
@@ -34,12 +34,12 @@ class Test(unittest.TestCase):
rule1 = hwsim.rules.create()
rule1.source = bss_radio[1].addresses[0]
rule1.bidirectional = True
- rule1.signal = -3000
+ rule1.signal = -7000
rule2 = hwsim.rules.create()
rule2.source = bss_radio[2].addresses[0]
rule2.bidirectional = True
- rule2.signal = -4000
+ rule2.signal = -8000
wd = IWD(True)
diff --git a/autotests/testBSSBlacklist/main.conf b/autotests/testBSSBlacklist/main.conf
@@ -2,4 +2,4 @@
InitialTimeout=10
[Scan]
-disable_mac_randomization=true
+DisableMacAddressRandomization=true
diff --git a/autotests/testBSSBlacklist/temp_blacklist_test.py b/autotests/testBSSBlacklist/temp_blacklist_test.py
@@ -32,7 +32,7 @@ class Test(unittest.TestCase):
rule1 = hwsim.rules.create()
rule1.source = bss_radio[1].addresses[0]
rule1.bidirectional = True
- rule1.signal = -2500
+ rule1.signal = -7000
rule2 = hwsim.rules.create()
rule2.source = bss_radio[2].addresses[0]
diff --git a/autotests/testFT-FILS-SHA256/ft-eap-ccmp-2.conf b/autotests/testFT-FILS-SHA256/ft-eap-ccmp-2.conf
@@ -9,7 +9,7 @@ nas_identifier=dummy2
wpa=2
# Can support WPA-EAP and FT-EAP (space separated list) at the same
# time but we want to force FT
-wpa_key_mgmt=FT-FILS-SHA256
+wpa_key_mgmt=WPA-EAP FT-FILS-SHA256
wpa_pairwise=CCMP
ieee8021x=1
diff --git a/autotests/testFT-FILS-SHA384/ft-eap-ccmp-2.conf b/autotests/testFT-FILS-SHA384/ft-eap-ccmp-2.conf
@@ -9,7 +9,7 @@ nas_identifier=dummy2
wpa=2
# Can support WPA-EAP and FT-EAP (space separated list) at the same
# time but we want to force FT
-wpa_key_mgmt=FT-FILS-SHA384
+wpa_key_mgmt=WPA-EAP FT-FILS-SHA384
wpa_pairwise=CCMP
ieee8021x=1
diff --git a/autotests/testP2P/connection_test.py b/autotests/testP2P/connection_test.py
@@ -27,7 +27,7 @@ class Test(unittest.TestCase):
def p2p_connect_test(self, preauthorize, go):
wd = IWD()
- wpas = Wpas(p2p=True)
+ wpas = self.wpas = Wpas(p2p=True)
wpas_go_intent = 10 if not go else 1
# Not strictly necessary but prevents the station interface from queuing its scans
@@ -35,7 +35,7 @@ class Test(unittest.TestCase):
wd.list_devices(1)[0].disconnect()
devices = wd.list_p2p_devices(1)
- p2p = devices[0]
+ p2p = self.p2p = devices[0]
p2p.enabled = True
p2p.name = 'testdev1'
@@ -94,15 +94,17 @@ class Test(unittest.TestCase):
if not go:
ctx.start_process(['ifconfig', peer_ifname, '192.168.1.20', 'netmask', '255.255.255.0'], wait=True)
- os.system('> /tmp/dhcpd.leases')
- dhcp = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', peer_ifname])
+ os.system('> /tmp/dhcp.leases')
+ dhcp = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcp.leases', peer_ifname])
+ self.dhcp = dhcp
wd.wait_for_object_condition(wpas, 'len(obj.p2p_clients) == 1', max_wait=3)
client = wpas.p2p_clients[request['peer_iface']]
self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
else:
- dhcp = ctx.start_process(['dhclient', '-v', '-d', '--no-pid', '-cf', '/dev/null', '-lf', '/tmp/dhcpd.leases',
+ dhcp = ctx.start_process(['dhclient', '-v', '-d', '--no-pid', '-cf', '/dev/null', '-lf', '/tmp/dhcp.leases',
'-sf', '/tmp/dhclient-script', peer_ifname])
+ self.dhcp = dhcp
wd.wait_for_object_condition(peer, 'obj.connected', max_wait=15)
time.sleep(1) # Give the client time to set the IP
@@ -127,9 +129,22 @@ class Test(unittest.TestCase):
wd.wait_for_object_condition(wpas, 'obj.p2p_group is None', max_wait=3)
self.assertEqual(peer.connected, False)
- p2p.enabled = False
- ctx.stop_process(dhcp)
- wpas.clean_up()
+ def setUp(self):
+ self.p2p = None
+ self.wpas = None
+ self.dhcp = None
+
+ def tearDown(self):
+ if self.p2p is not None:
+ self.p2p.enabled = False
+ if self.wpas is not None:
+ self.wpas.clean_up()
+ self.wpas = None
+ if self.dhcp is not None:
+ ctx.stop_process(self.dhcp)
+ for path in ['/tmp/dhcp.leases']:
+ if os.path.exists(path):
+ os.remove(path)
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testSAE-AntiClogging/clogging_test.py b/autotests/testSAE-AntiClogging/clogging_test.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+import iwd
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hostapd import HostapdCLI
+
+class Test(unittest.TestCase):
+
+ def validate_connection(self, wd):
+ networks = []
+
+ psk_agent = PSKAgent(["secret123"] * 4)
+ wd.register_psk_agent(psk_agent)
+
+ devices = wd.list_devices(4)
+ self.assertIsNotNone(devices)
+
+ for d in devices:
+ d.disconnect()
+ d.scan()
+ wd.wait_for_object_condition(d, 'obj.scanning')
+
+ for d in devices:
+ wd.wait_for_object_condition(d, 'not obj.scanning')
+
+ for i in range(len(devices)):
+ network = devices[i].get_ordered_network('ssidSAE-Clogging')
+ self.assertEqual(network.type, NetworkType.psk)
+ networks.append(network)
+
+ condition = 'not obj.connected'
+ wd.wait_for_object_condition(network.network_object, condition)
+
+ for n in networks:
+ n.network_object.connect(wait=False)
+
+ for d in devices:
+ condition = 'obj.state == DeviceState.connected'
+ wd.wait_for_object_condition(d, condition)
+
+ for d in devices:
+ d.disconnect()
+
+ for n in networks:
+ condition = 'not obj.connected'
+ wd.wait_for_object_condition(n.network_object, condition)
+
+ wd.unregister_psk_agent(psk_agent)
+
+ def test_SAE_H2E_Group20(self):
+ self.hostapd.set_value('sae_pwe', '1');
+ self.hostapd.set_value('sae_groups', '20');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+ wd = IWD(True)
+ self.validate_connection(wd)
+ wd.clear_storage()
+
+ def test_SAE(self):
+ self.hostapd.set_value('sae_pwe', '0');
+ self.hostapd.set_value('sae_groups', '19');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+ wd = IWD(True)
+ self.validate_connection(wd)
+ wd.clear_storage()
+
+ @classmethod
+ def setUpClass(cls):
+ cls.hostapd = HostapdCLI(config='ssidSAE-Clogging.conf')
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
diff --git a/autotests/testSAE-AntiClogging/hw.conf b/autotests/testSAE-AntiClogging/hw.conf
@@ -0,0 +1,6 @@
+[SETUP]
+num_radios=5
+start_iwd=0
+
+[HOSTAPD]
+rad0=ssidSAE-Clogging.conf
diff --git a/autotests/testSAE-AntiClogging/main.conf b/autotests/testSAE-AntiClogging/main.conf
@@ -0,0 +1,6 @@
+[Scan]
+#
+# Discovery of the hidden networks with randomization flag set works with real
+# hardware, but fails when used in simulated environment with mac80211_hwsim.
+# Disable MAC randomization for the tests with hidden networks.
+DisableMacAddressRandomization=true
diff --git a/autotests/testSAE/ssidSAE-Clogging.conf b/autotests/testSAE-AntiClogging/ssidSAE-Clogging.conf
diff --git a/autotests/testSAE/autoconnect_test.py b/autotests/testSAE/autoconnect_test.py
@@ -8,21 +8,16 @@ import iwd
from iwd import IWD
from iwd import PSKAgent
from iwd import NetworkType
+from hostapd import HostapdCLI
class Test(unittest.TestCase):
def validate_connection(self, wd):
- devices = wd.list_devices(4)
+ devices = wd.list_devices(1)
self.assertIsNotNone(devices)
device = devices[0]
- # These devices aren't used in this test, this makes logs a bit nicer
- # since these devices would presumably start autoconnecting.
- devices[1].disconnect()
- devices[2].disconnect()
- devices[3].disconnect()
-
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
@@ -38,13 +33,26 @@ class Test(unittest.TestCase):
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
- def test_connection_success(self):
+ def test_SAE(self):
+ self.hostapd.set_value('sae_pwe', '0');
+ self.hostapd.set_value('sae_groups', '19');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+
wd = IWD(True)
+ self.validate_connection(wd)
+ def test_SAE_H2E(self):
+ self.hostapd.set_value('sae_pwe', '1');
+ self.hostapd.set_value('sae_groups', '20');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+ wd = IWD(True)
self.validate_connection(wd)
@classmethod
def setUpClass(cls):
+ cls.hostapd = HostapdCLI(config='ssidSAE.conf')
IWD.copy_to_storage('ssidSAE.psk')
pass
diff --git a/autotests/testSAE/clogging_test.py b/autotests/testSAE/clogging_test.py
@@ -1,77 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-
-sys.path.append('../util')
-import iwd
-from iwd import IWD
-from iwd import PSKAgent
-from iwd import NetworkType
-
-class Test(unittest.TestCase):
-
- def validate_connection(self, wd):
- networks = []
-
- psk_agent = PSKAgent(["secret123"] * 4)
- wd.register_psk_agent(psk_agent)
-
- devices = wd.list_devices(4)
- self.assertIsNotNone(devices)
-
- for d in devices:
- condition = 'not obj.scanning'
- wd.wait_for_object_condition(d, condition)
-
- d.scan()
-
- for d in devices:
- condition = 'not obj.scanning'
- wd.wait_for_object_condition(d, condition)
-
- for i in range(len(devices)):
- network = devices[i].get_ordered_network('ssidSAE-Clogging')
-
- self.assertEqual(network.type, NetworkType.psk)
-
- networks.append(network)
-
- condition = 'not obj.connected'
- wd.wait_for_object_condition(network.network_object, condition)
-
- for n in networks:
- n.network_object.connect(wait=False)
-
- for d in devices:
- condition = 'obj.state == DeviceState.connected'
- wd.wait_for_object_condition(d, condition)
-
- for d in devices:
- condition = 'obj.state == DeviceState.connected'
- wd.wait_for_object_condition(d, condition)
-
- for d in devices:
- d.disconnect()
-
- for n in networks:
- condition = 'not obj.connected'
- wd.wait_for_object_condition(n.network_object, condition)
-
- wd.unregister_psk_agent(psk_agent)
-
- def test_connection_success(self):
- wd = IWD(True)
-
- self.validate_connection(wd)
-
- @classmethod
- def setUpClass(cls):
- pass
-
- @classmethod
- def tearDownClass(cls):
- IWD.clear_storage()
-
-if __name__ == '__main__':
- unittest.main(exit=True)
diff --git a/autotests/testSAE/connection_test.py b/autotests/testSAE/connection_test.py
@@ -14,36 +14,26 @@ import testutil
class Test(unittest.TestCase):
def validate_connection(self, wd):
- hostapd = HostapdCLI(config='ssidSAE.conf')
-
psk_agent = PSKAgent("secret123")
wd.register_psk_agent(psk_agent)
- devices = wd.list_devices(4)
+ devices = wd.list_devices(1)
self.assertIsNotNone(devices)
device = devices[0]
- # These devices aren't used in this test, this makes logs a bit nicer
- # since these devices would presumably start autoconnecting.
- devices[1].disconnect()
- devices[2].disconnect()
- devices[3].disconnect()
+ device.disconnect()
- condition = 'not obj.scanning'
- wd.wait_for_object_condition(device, condition)
+ wd.wait_for_object_condition(device, 'not obj.scanning')
device.scan()
- condition = 'not obj.scanning'
- wd.wait_for_object_condition(device, condition)
+ wd.wait_for_object_condition(device, 'obj.scanning')
+ wd.wait_for_object_condition(device, 'not obj.scanning')
network = device.get_ordered_network('ssidSAE')
self.assertEqual(network.type, NetworkType.psk)
- condition = 'not obj.connected'
- wd.wait_for_object_condition(network.network_object, condition)
-
network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
@@ -52,7 +42,7 @@ class Test(unittest.TestCase):
wd.wait(2)
testutil.test_iface_operstate(intf=device.name)
- testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname)
+ testutil.test_ifaces_connected(if0=device.name, if1=self.hostapd.ifname)
device.disconnect()
@@ -61,18 +51,49 @@ class Test(unittest.TestCase):
wd.unregister_psk_agent(psk_agent)
- def test_connection_success(self):
+ def test_SAE(self):
+ self.hostapd.set_value('sae_pwe', '0');
+ self.hostapd.set_value('sae_groups', '19');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
wd = IWD(True)
+ self.validate_connection(wd)
+ wd.clear_storage()
+ def test_SAE_Group20(self):
+ self.hostapd.set_value('sae_pwe', '0');
+ self.hostapd.set_value('sae_groups', '20');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+ wd = IWD(True)
self.validate_connection(wd)
+ wd.clear_storage()
+
+ def test_SAE_H2E(self):
+ self.hostapd.set_value('sae_pwe', '1');
+ self.hostapd.set_value('sae_groups', '19');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+ wd = IWD(True)
+ self.validate_connection(wd)
+ wd.clear_storage()
+
+ def test_SAE_H2E_Group20(self):
+ self.hostapd.set_value('sae_pwe', '1');
+ self.hostapd.set_value('sae_groups', '20');
+ self.hostapd.reload()
+ self.hostapd.wait_for_event("AP-ENABLED")
+ wd = IWD(True)
+ self.validate_connection(wd)
+ wd.clear_storage()
@classmethod
def setUpClass(cls):
- pass
+ cls.hostapd = HostapdCLI(config='ssidSAE.conf')
@classmethod
def tearDownClass(cls):
- IWD.clear_storage()
+ pass
if __name__ == '__main__':
unittest.main(exit=True)
diff --git a/autotests/testSAE/failure_test.py b/autotests/testSAE/failure_test.py
@@ -12,7 +12,6 @@ from iwd import NetworkType
class Test(unittest.TestCase):
def validate_connection(self, wd):
-
psk_agent = PSKAgent("InvalidSecret")
wd.register_psk_agent(psk_agent)
@@ -42,7 +41,6 @@ class Test(unittest.TestCase):
def test_connection_success(self):
wd = IWD(True)
-
self.validate_connection(wd)
@classmethod
diff --git a/autotests/testSAE/group_20_connection_test.py b/autotests/testSAE/group_20_connection_test.py
@@ -1,78 +0,0 @@
-#!/usr/bin/python3
-
-import unittest
-import sys
-
-sys.path.append('../util')
-import iwd
-from iwd import IWD
-from iwd import PSKAgent
-from iwd import NetworkType
-from hostapd import HostapdCLI
-import testutil
-
-class Test(unittest.TestCase):
-
- def validate_connection(self, wd):
- hostapd = HostapdCLI(config='ssidSAE-20.conf')
-
- psk_agent = PSKAgent("secret123")
- wd.register_psk_agent(psk_agent)
-
- devices = wd.list_devices(4)
- self.assertIsNotNone(devices)
- device = devices[0]
-
- # These devices aren't used in this test, this makes logs a bit nicer
- # since these devices would presumably start autoconnecting.
- devices[1].disconnect()
- devices[2].disconnect()
- devices[3].disconnect()
-
- condition = 'not obj.scanning'
- wd.wait_for_object_condition(device, condition)
-
- device.scan()
-
- condition = 'not obj.scanning'
- wd.wait_for_object_condition(device, condition)
-
- network = device.get_ordered_network('ssidSAE-20')
-
- self.assertEqual(network.type, NetworkType.psk)
-
- condition = 'not obj.connected'
- wd.wait_for_object_condition(network.network_object, condition)
-
- network.network_object.connect()
-
- condition = 'obj.state == DeviceState.connected'
- wd.wait_for_object_condition(device, condition)
-
- wd.wait(2)
-
- testutil.test_iface_operstate(intf=device.name)
- testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname)
-
- device.disconnect()
-
- condition = 'not obj.connected'
- wd.wait_for_object_condition(network.network_object, condition)
-
- wd.unregister_psk_agent(psk_agent)
-
- def test_connection_success(self):
- wd = IWD(True)
-
- self.validate_connection(wd)
-
- @classmethod
- def setUpClass(cls):
- pass
-
- @classmethod
- def tearDownClass(cls):
- IWD.clear_storage()
-
-if __name__ == '__main__':
- unittest.main(exit=True)
diff --git a/autotests/testSAE/hw.conf b/autotests/testSAE/hw.conf
@@ -1,8 +1,6 @@
[SETUP]
-num_radios=7
+num_radios=2
start_iwd=0
[HOSTAPD]
rad0=ssidSAE.conf
-rad1=ssidSAE-Clogging.conf
-rad2=ssidSAE-20.conf
diff --git a/autotests/testSAE/main.conf b/autotests/testSAE/main.conf
@@ -0,0 +1,6 @@
+[Scan]
+#
+# Discovery of the hidden networks with randomization flag set works with real
+# hardware, but fails when used in simulated environment with mac80211_hwsim.
+# Disable MAC randomization for the tests with hidden networks.
+DisableMacAddressRandomization=true
diff --git a/autotests/testSAE/ssidSAE-20.conf b/autotests/testSAE/ssidSAE-20.conf
@@ -1,10 +0,0 @@
-hw_mode=g
-channel=1
-ssid=ssidSAE-20
-
-wpa=2
-wpa_key_mgmt=SAE
-wpa_pairwise=CCMP
-sae_password=secret123|mac=ff:ff:ff:ff:ff:ff
-sae_groups=20
-ieee80211w=2
diff --git a/autotests/testSAE/ssidSAE.conf b/autotests/testSAE/ssidSAE.conf
@@ -6,4 +6,5 @@ wpa=2
wpa_key_mgmt=SAE
wpa_pairwise=CCMP
sae_password=secret123|mac=ff:ff:ff:ff:ff:ff
+sae_groups=19
ieee80211w=2
diff --git a/autotests/testSAE/ssidSAE.psk b/autotests/testSAE/ssidSAE.psk
@@ -1,3 +1,2 @@
[Security]
-PreSharedKey=6d44ed0e3a2e1de04c753d66369ece3b9534094ab7ec9ce76798641a9fa68b13
Passphrase=secret123
diff --git a/autotests/testSAE/timeout_test.py b/autotests/testSAE/timeout_test.py
@@ -19,14 +19,7 @@ class Test(unittest.TestCase):
psk_agent = PSKAgent(["secret123", "secret123"])
wd.register_psk_agent(psk_agent)
- devices = wd.list_devices(4)
-
- # These devices aren't used in this test, this makes logs a bit nicer
- # since these devices would presumably start autoconnecting.
- devices[1].disconnect()
- devices[2].disconnect()
- devices[3].disconnect()
-
+ devices = wd.list_devices(1)
self.assertIsNotNone(devices)
device = devices[0]
@@ -68,7 +61,6 @@ class Test(unittest.TestCase):
def test_connection_success(self):
wd = IWD(True)
-
self.validate_connection(wd)
@classmethod
diff --git a/autotests/testScan/hw.conf b/autotests/testScan/hw.conf
@@ -1,9 +1,10 @@
[SETUP]
-num_radios=5
+num_radios=6
start_iwd=0
[HOSTAPD]
-rad0=ssid_hidden.conf
-rad1=ssid_open.conf
-rad2=ssid_8021x.conf
-rad3=ssid_psk.conf
+rad0=ssid_hidden_0.conf
+rad1=ssid_hidden_1.conf
+rad2=ssid_open.conf
+rad3=ssid_8021x.conf
+rad4=ssid_psk.conf
diff --git a/autotests/testScan/periodic_scan_test.py b/autotests/testScan/periodic_scan_test.py
@@ -12,11 +12,7 @@ class Test(unittest.TestCase):
'ssid_open': False,
'ssid_psk': False,
'ssid_8021x': False,
- 'ssid_hidden_5': False,
- 'ssid_hidden_6': False,
- 'ssid_hidden_7': False,
- 'ssid_hidden_8': False,
- 'ssid_hidden_9': False,
+ 'ssid_hidden_1': False,
}
def set_network(self, ssid):
@@ -61,11 +57,7 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
- IWD.copy_to_storage('ssid_hidden_5.open')
- IWD.copy_to_storage('ssid_hidden_6.open')
- IWD.copy_to_storage('ssid_hidden_7.open')
- IWD.copy_to_storage('ssid_hidden_8.open')
- IWD.copy_to_storage('ssid_hidden_9.open')
+ IWD.copy_to_storage('ssid_hidden_1.open')
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testScan/requested_scan_test.py b/autotests/testScan/requested_scan_test.py
@@ -15,10 +15,6 @@ class Test(unittest.TestCase):
'ssid_psk': False,
'ssid_8021x': False,
'ssid_hidden_0': False,
- 'ssid_hidden_1': False,
- 'ssid_hidden_2': False,
- 'ssid_hidden_3': False,
- 'ssid_hidden_4': False,
}
def set_network(self, ssid):
@@ -63,10 +59,6 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
IWD.copy_to_storage('ssid_hidden_0.open')
- IWD.copy_to_storage('ssid_hidden_1.open')
- IWD.copy_to_storage('ssid_hidden_2.open')
- IWD.copy_to_storage('ssid_hidden_3.open')
- IWD.copy_to_storage('ssid_hidden_4.open')
@classmethod
def tearDownClass(cls):
diff --git a/autotests/testScan/ssid_hidden.conf b/autotests/testScan/ssid_hidden.conf
@@ -1,41 +0,0 @@
-ssid=ssid_hidden_0
-interface=wln0
-hw_mode=g
-channel=1
-ignore_broadcast_ssid=1
-
-bss=wln0_1
-ssid=ssid_hidden_1
-ignore_broadcast_ssid=1
-
-bss=wln0_2
-ssid=ssid_hidden_2
-ignore_broadcast_ssid=1
-
-bss=wln0_3
-ssid=ssid_hidden_3
-ignore_broadcast_ssid=1
-
-bss=wln0_4
-ssid=ssid_hidden_4
-ignore_broadcast_ssid=1
-
-bss=wln0_5
-ssid=ssid_hidden_5
-ignore_broadcast_ssid=1
-
-bss=wln0_6
-ssid=ssid_hidden_6
-ignore_broadcast_ssid=1
-
-bss=wln0_7
-ssid=ssid_hidden_7
-ignore_broadcast_ssid=1
-
-bss=wln0_8
-ssid=ssid_hidden_8
-ignore_broadcast_ssid=1
-
-bss=wln0_9
-ssid=ssid_hidden_9
-ignore_broadcast_ssid=1
diff --git a/autotests/testScan/ssid_hidden_0.conf b/autotests/testScan/ssid_hidden_0.conf
@@ -0,0 +1,4 @@
+ssid=ssid_hidden_0
+hw_mode=g
+channel=1
+ignore_broadcast_ssid=1
diff --git a/autotests/testScan/ssid_hidden_1.conf b/autotests/testScan/ssid_hidden_1.conf
@@ -0,0 +1,4 @@
+ssid=ssid_hidden_1
+hw_mode=g
+channel=1
+ignore_broadcast_ssid=1
diff --git a/autotests/testScan/ssid_hidden_2.open b/autotests/testScan/ssid_hidden_2.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_3.open b/autotests/testScan/ssid_hidden_3.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_4.open b/autotests/testScan/ssid_hidden_4.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_5.open b/autotests/testScan/ssid_hidden_5.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_6.open b/autotests/testScan/ssid_hidden_6.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_7.open b/autotests/testScan/ssid_hidden_7.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_8.open b/autotests/testScan/ssid_hidden_8.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/testScan/ssid_hidden_9.open b/autotests/testScan/ssid_hidden_9.open
@@ -1,3 +0,0 @@
-[Settings]
-AutoConnect=false
-Hidden=true
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
@@ -118,7 +118,11 @@ class HostapdCLI:
return
self.ctrl_sock.close()
- os.remove(self.local_ctrl)
+
+ try:
+ os.remove(self.local_ctrl)
+ except:
+ pass
if self._hostapd_restarted:
ctx.stop_process(ctx.hostapd.process, force)
@@ -129,6 +133,10 @@ class HostapdCLI:
def __del__(self):
self._del_hostapd()
+ def set_value(self, key, value):
+ cmd = self.cmdline + ['set', key, value]
+ ctx.start_process(cmd, wait=True)
+
def wps_push_button(self):
ctx.start_process(self.cmdline + ['wps_pbc'], wait=True)
diff --git a/autotests/util/wpas.py b/autotests/util/wpas.py
@@ -245,6 +245,9 @@ class Wpas:
if self.io_watch is not None:
GLib.source_remove(self.io_watch)
self.io_watch = None
+ for ifname in self.sockets:
+ self.sockets[ifname].close()
+ self.sockets = {}
if self.wpa_supplicant is not None:
ctx.stop_process(self.wpa_supplicant)
self.wpa_supplicant = None
@@ -253,11 +256,5 @@ class Wpas:
os.remove(path)
self.cleanup_paths = []
- def _stop_wpas(self):
- self.clean_up()
- for ifname in self.sockets:
- self.sockets[ifname].close()
- self.sockets = {}
-
def __del__(self):
- self._stop_wpas()
+ self.clean_up()
diff --git a/configure.ac b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ(2.60)
-AC_INIT(iwd, 1.15)
+AC_INIT(iwd, 1.16)
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_AUX_DIR(build-aux)
@@ -267,7 +267,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.41"
+ ell_min_version="0.42"
else
ell_min_version="0.5"
fi
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
@@ -5631,6 +5631,7 @@ static const struct attr_entry control_port_attr_table[] = {
"Interface Index", ATTR_U32 },
{ NL80211_ATTR_WIPHY,
"Wiphy", ATTR_U32 },
+ { }
};
static const struct attr_entry scan_flag_table[] = {
diff --git a/src/anqp.c b/src/anqp.c
@@ -53,8 +53,6 @@ struct anqp_request {
uint32_t id;
};
-static uint8_t anqp_token = 0;
-
static void anqp_destroy(void *user_data)
{
struct anqp_request *request = user_data;
@@ -185,6 +183,7 @@ static void anqp_frame_timeout(int error, void *user_data)
}
static uint8_t *anqp_build_frame(const uint8_t *addr, struct scan_bss *bss,
+ uint8_t anqp_token,
const uint8_t *anqp, size_t len,
size_t *len_out)
{
@@ -202,7 +201,7 @@ static uint8_t *anqp_build_frame(const uint8_t *addr, struct scan_bss *bss,
*ptr++ = 0x04; /* Category: Public */
*ptr++ = 0x0a; /* Action: GAS initial Request */
- *ptr++ = anqp_token++; /* Dialog Token */
+ *ptr++ = anqp_token; /* Dialog Token */
*ptr++ = IE_TYPE_ADVERTISEMENT_PROTOCOL;
*ptr++ = 2;
@@ -233,10 +232,16 @@ uint32_t anqp_request(uint64_t wdev_id, const uint8_t *addr,
request->frequency = bss->frequency;
request->anqp_cb = cb;
request->anqp_destroy = destroy;
- request->anqp_token = anqp_token;
+ /*
+ * WPA3 Specificiation version 3, Section 9.4:
+ * "A STA shall use a randomized dialog token for every new GAS
+ * exchange."
+ */
+ l_getrandom(&request->anqp_token, sizeof(request->anqp_token));
request->anqp_data = user_data;
- request->frame = anqp_build_frame(addr, bss, anqp, len,
+ request->frame = anqp_build_frame(addr, bss, request->anqp_token,
+ anqp, len,
&request->frame_len);
iov[0].iov_base = request->frame;
diff --git a/src/ap.c b/src/ap.c
@@ -688,7 +688,6 @@ static size_t ap_build_beacon_pr_head(struct ap_state *ap,
size_t out_len)
{
struct mmpdu_header *mpdu = (void *) out_buf;
- unsigned int len;
uint16_t capability = IE_BSS_CAP_ESS | IE_BSS_CAP_PRIVACY;
const uint8_t *bssid = netdev_get_address(ap->netdev);
uint32_t minr, maxr, count, r;
@@ -740,8 +739,8 @@ static size_t ap_build_beacon_pr_head(struct ap_state *ap,
ie_tlv_builder_next(&builder, IE_TYPE_DSSS_PARAMETER_SET);
ie_tlv_builder_set_data(&builder, &ap->channel, 1);
- ie_tlv_builder_finalize(&builder, &len);
- return 36 + len;
+ ie_tlv_builder_finalize(&builder, &out_len);
+ return 36 + out_len;
}
/* Beacon / Probe Response frame portion after the TIM IE */
diff --git a/src/band.c b/src/band.c
@@ -115,7 +115,7 @@ int band_estimate_nonht_rate(const struct band *band,
}
if (!max_rate)
- return -EINVAL;
+ return -ENETUNREACH;
*out_data_rate = max_rate * 500000;
return 0;
@@ -261,7 +261,7 @@ int band_estimate_ht_rx_rate(const struct band *band,
* Number of Spatial Streams Supported' field at bits 98 and 99.
*
* Note 44 on page 1662 of 802.11-2016 states:
- * "How a non-AP STA determines an AP’s HT MCS transmission support,
+ * "How a non-AP STA determines an AP's HT MCS transmission support,
* if the Tx MCS Set subfield in the HT Capabilities element
* advertised by the AP is equal to 0 or if he Tx Rx MCS Set Not Equal
* subfield in that element is equal to 1, is implementation dependent.
@@ -306,7 +306,7 @@ int band_estimate_ht_rx_rate(const struct band *band,
rssi, sgi, out_data_rate))
return 0;
- return -EINVAL;
+ return -ENETUNREACH;
}
static bool find_best_mcs_vht(uint8_t max_index, enum ofdm_channel_width width,
@@ -463,5 +463,5 @@ try_vht80:
rssi, nss, sgi, out_data_rate))
return 0;
- return -EINVAL;
+ return -ENETUNREACH;
}
diff --git a/src/crypto.c b/src/crypto.c
@@ -33,6 +33,7 @@
#include <ell/ell.h>
+#include "ell/useful.h"
#include "src/missing.h"
#include "src/crypto.h"
@@ -610,6 +611,79 @@ bool prf_sha1(const void *key, size_t key_len,
return true;
}
+/* PRF+ from RFC 5295 Section 3.1.2 (also RFC 4306 Section 2.13) */
+bool prf_plus(enum l_checksum_type type, const void *key, size_t key_len,
+ const char *label, void *out, size_t out_len,
+ size_t n_extra, ...)
+{
+ struct iovec iov[n_extra + 3];
+ uint8_t *t = out;
+ size_t t_len = 0;
+ uint8_t count = 1;
+ uint8_t *out_ptr = out;
+ va_list va;
+ struct l_checksum *hmac;
+ ssize_t ret;
+ size_t i;
+
+ iov[1].iov_base = (void *) label;
+ iov[1].iov_len = strlen(label);
+
+ /* Include the '\0' from the label in S if extra arguments provided */
+ if (n_extra)
+ iov[1].iov_len += 1;
+
+ va_start(va, n_extra);
+
+ for (i = 0; i < n_extra; i++) {
+ iov[i + 2].iov_base = va_arg(va, void *);
+ iov[i + 2].iov_len = va_arg(va, size_t);
+ }
+
+ va_end(va);
+
+ iov[n_extra + 2].iov_base = &count;
+ iov[n_extra + 2].iov_len = 1;
+
+ hmac = l_checksum_new_hmac(type, key, key_len);
+ if (!hmac)
+ return false;
+
+ while (out_len > 0) {
+ iov[0].iov_base = t;
+ iov[0].iov_len = t_len;
+
+ if (!l_checksum_updatev(hmac, iov, n_extra + 3)) {
+ l_checksum_free(hmac);
+ return false;
+ }
+
+ ret = l_checksum_get_digest(hmac, out_ptr, out_len);
+ if (ret < 0) {
+ l_checksum_free(hmac);
+ return false;
+ }
+
+ /*
+ * RFC specifies that T(0) = empty string, so after the first
+ * iteration we update the length for T(1)...T(N)
+ */
+ t_len = ret;
+ t = out_ptr;
+ count++;
+
+ out_len -= ret;
+ out_ptr += ret;
+
+ if (out_len)
+ l_checksum_reset(hmac);
+ }
+
+ l_checksum_free(hmac);
+
+ return true;
+}
+
bool prf_plus_sha1(const void *key, size_t key_len,
const void *label, size_t label_len,
const void *seed, size_t seed_len,
@@ -675,13 +749,15 @@ bool prf_plus_sha1(const void *key, size_t key_len,
}
/* Defined in 802.11-2012, Section 11.6.1.7.2 Key derivation function (KDF) */
-bool kdf_sha256(const void *key, size_t key_len,
+bool crypto_kdf(enum l_checksum_type type, const void *key, size_t key_len,
const void *prefix, size_t prefix_len,
const void *data, size_t data_len, void *output, size_t size)
{
struct l_checksum *hmac;
unsigned int i, offset = 0;
unsigned int counter;
+ unsigned int chunk_size;
+ unsigned int n_iterations;
uint8_t counter_le[2];
uint8_t length_le[2];
struct iovec iov[4] = {
@@ -691,19 +767,21 @@ bool kdf_sha256(const void *key, size_t key_len,
[3] = { .iov_base = length_le, .iov_len = 2 },
};
- hmac = l_checksum_new_hmac(L_CHECKSUM_SHA256, key, key_len);
+ hmac = l_checksum_new_hmac(type, key, key_len);
if (!hmac)
return false;
+ chunk_size = l_checksum_digest_length(type);
+ n_iterations = (size + chunk_size - 1) / chunk_size;
+
/* Length is denominated in bits, not bytes */
l_put_le16(size * 8, length_le);
- /* KDF processes in 256-bit chunks (32 bytes) */
- for (i = 0, counter = 1; i < (size + 31) / 32; i++, counter++) {
+ for (i = 0, counter = 1; i < n_iterations; i++, counter++) {
size_t len;
- if (size - offset > 32)
- len = 32;
+ if (size - offset > chunk_size)
+ len = chunk_size;
else
len = size - offset;
@@ -720,49 +798,20 @@ bool kdf_sha256(const void *key, size_t key_len,
return true;
}
-bool kdf_sha384(const void *key, size_t key_len,
+bool kdf_sha256(const void *key, size_t key_len,
const void *prefix, size_t prefix_len,
const void *data, size_t data_len, void *output, size_t size)
{
- struct l_checksum *hmac;
- unsigned int i, offset = 0;
- unsigned int counter;
- uint8_t counter_le[2];
- uint8_t length_le[2];
- struct iovec iov[4] = {
- [0] = { .iov_base = counter_le, .iov_len = 2 },
- [1] = { .iov_base = (void *) prefix, .iov_len = prefix_len },
- [2] = { .iov_base = (void *) data, .iov_len = data_len },
- [3] = { .iov_base = length_le, .iov_len = 2 },
- };
-
- hmac = l_checksum_new_hmac(L_CHECKSUM_SHA384, key, key_len);
- if (!hmac)
- return false;
-
- /* Length is denominated in bits, not bytes */
- l_put_le16(size * 8, length_le);
-
- /* KDF processes in 384-bit chunks (48 bytes) */
- for (i = 0, counter = 1; i < (size + 47) / 48; i++, counter++) {
- size_t len;
-
- if (size - offset > 48)
- len = 48;
- else
- len = size - offset;
-
- l_put_le16(counter, counter_le);
-
- l_checksum_updatev(hmac, iov, 4);
- l_checksum_get_digest(hmac, output + offset, len);
-
- offset += len;
- }
-
- l_checksum_free(hmac);
+ return crypto_kdf(L_CHECKSUM_SHA256, key, key_len, prefix, prefix_len,
+ data, data_len, output, size);
+}
- return true;
+bool kdf_sha384(const void *key, size_t key_len,
+ const void *prefix, size_t prefix_len,
+ const void *data, size_t data_len, void *output, size_t size)
+{
+ return crypto_kdf(L_CHECKSUM_SHA384, key, key_len, prefix, prefix_len,
+ data, data_len, output, size);
}
/*
@@ -770,9 +819,9 @@ bool kdf_sha384(const void *key, size_t key_len,
*
* Null key equates to a zero key (makes calls in EAP-PWD more convenient)
*/
-bool hkdf_extract(enum l_checksum_type type, const uint8_t *key,
+bool hkdf_extract(enum l_checksum_type type, const void *key,
size_t key_len, uint8_t num_args,
- uint8_t *out, ...)
+ void *out, ...)
{
struct l_checksum *hmac;
struct iovec iov[num_args];
@@ -812,59 +861,9 @@ bool hkdf_extract(enum l_checksum_type type, const uint8_t *key,
}
bool hkdf_expand(enum l_checksum_type type, const uint8_t *key, size_t key_len,
- const char *info, size_t info_len, void *out,
- size_t out_len)
+ const char *info, void *out, size_t out_len)
{
- uint8_t *t = out;
- size_t t_len = 0;
- struct l_checksum *hmac;
- uint8_t count = 1;
- uint8_t *out_ptr = out;
-
- hmac = l_checksum_new_hmac(type, key, key_len);
- if (!hmac)
- return false;
-
- while (out_len > 0) {
- ssize_t ret;
- struct iovec iov[3];
-
- iov[0].iov_base = t;
- iov[0].iov_len = t_len;
- iov[1].iov_base = (void *) info;
- iov[1].iov_len = info_len;
- iov[2].iov_base = &count;
- iov[2].iov_len = 1;
-
- if (!l_checksum_updatev(hmac, iov, 3)) {
- l_checksum_free(hmac);
- return false;
- }
-
- ret = l_checksum_get_digest(hmac, out_ptr, out_len);
- if (ret < 0) {
- l_checksum_free(hmac);
- return false;
- }
-
- /*
- * RFC specifies that T(0) = empty string, so after the first
- * iteration we update the length for T(1)...T(N)
- */
- t_len = ret;
- t = out_ptr;
- count++;
-
- out_len -= ret;
- out_ptr += ret;
-
- if (out_len)
- l_checksum_reset(hmac);
- }
-
- l_checksum_free(hmac);
-
- return true;
+ return prf_plus(type, key, key_len, info, out, out_len, 0);
}
/*
@@ -874,7 +873,7 @@ bool hkdf_expand(enum l_checksum_type type, const uint8_t *key, size_t key_len,
*
* 802.11, Section 11.6.1.3:
* The PTK shall be derived from the PMK by
- * PTK ← PRF-X(PMK, “Pairwise key expansion”, Min(AA,SPA) || Max(AA,SPA) ||
+ * PTK = PRF-X(PMK, "Pairwise key expansion", Min(AA,SPA) || Max(AA,SPA) ||
* Min(ANonce,SNonce) || Max(ANonce,SNonce))
* where X = 256 + TK_bits. The value of TK_bits is cipher-suite dependent and
* is defined in Table 11-4. The Min and Max operations for IEEE 802 addresses
@@ -915,14 +914,12 @@ static bool crypto_derive_ptk(const uint8_t *pmk, size_t pmk_len,
}
pos += 64;
- if (type == L_CHECKSUM_SHA384)
- return kdf_sha384(pmk, pmk_len, label, strlen(label),
- data, sizeof(data), out_ptk, ptk_len);
- else if (type == L_CHECKSUM_SHA256)
- return kdf_sha256(pmk, pmk_len, label, strlen(label),
+
+ if (type == L_CHECKSUM_SHA1)
+ return prf_sha1(pmk, pmk_len, label, strlen(label),
data, sizeof(data), out_ptk, ptk_len);
else
- return prf_sha1(pmk, pmk_len, label, strlen(label),
+ return crypto_kdf(type, pmk, pmk_len, label, strlen(label),
data, sizeof(data), out_ptk, ptk_len);
}
@@ -1121,3 +1118,119 @@ bool crypto_derive_pmkid(const uint8_t *pmk,
else
return hmac_sha1(pmk, 32, data, 20, out_pmkid, 16);
}
+
+enum l_checksum_type crypto_sae_hash_from_ecc_prime_len(enum crypto_sae type,
+ size_t prime_len)
+{
+ /*
+ * If used with the looping technique described in 12.4.4.2.2 and
+ * 12.4.4.3.2, H and CN are instantiated with SHA-256.
+ */
+ if (type == CRYPTO_SAE_LOOPING)
+ return L_CHECKSUM_SHA256;
+
+ /* 802.11-2020, Table 12-1 Hash algorithm based on length of prime */
+ if (prime_len <= 256 / 8)
+ return L_CHECKSUM_SHA256;
+
+ if (prime_len <= 384 / 8)
+ return L_CHECKSUM_SHA384;
+
+ return L_CHECKSUM_SHA512;
+}
+
+struct l_ecc_point *crypto_derive_sae_pt_ecc(unsigned int group,
+ const char *ssid,
+ const char *password,
+ const char *identifier)
+{
+ const struct l_ecc_curve *curve = l_ecc_curve_from_ike_group(group);
+ enum l_checksum_type hash;
+ size_t hash_len;
+ uint8_t pwd_seed[64]; /* SHA512 is the biggest possible right now */
+ uint8_t pwd_value[128];
+ size_t pwd_value_len;
+ _auto_(l_ecc_scalar_free) struct l_ecc_scalar *u1 = NULL;
+ _auto_(l_ecc_scalar_free) struct l_ecc_scalar *u2 = NULL;
+ _auto_(l_ecc_point_free) struct l_ecc_point *p1 = NULL;
+ _auto_(l_ecc_point_free) struct l_ecc_point *p2 = NULL;
+ _auto_(l_ecc_point_free) struct l_ecc_point *pt = NULL;
+
+ if (!curve)
+ return NULL;
+
+ hash = crypto_sae_hash_from_ecc_prime_len(CRYPTO_SAE_HASH_TO_ELEMENT,
+ l_ecc_curve_get_scalar_bytes(curve));
+ hash_len = l_checksum_digest_length(hash);
+
+ /* pwd-seed = HKDF-Extract(ssid, password [|| identifier]) */
+ hkdf_extract(hash, ssid, strlen(ssid), 2, pwd_seed,
+ password, strlen(password),
+ identifier, identifier ? strlen(identifier) : 0);
+
+ /* len = olen(p) + floor(olen(p)/2) */
+ pwd_value_len = l_ecc_curve_get_scalar_bytes(curve);
+ pwd_value_len += pwd_value_len / 2;
+
+ /*
+ * pwd-value = HKDF-Expand(pwd-seed, "SAE Hash to Element u1 P1", len)
+ */
+ hkdf_expand(hash, pwd_seed, hash_len, "SAE Hash to Element u1 P1",
+ pwd_value, pwd_value_len);
+ u1 = l_ecc_scalar_new_modp(curve, pwd_value, pwd_value_len);
+
+ /*
+ * pwd-value = HKDF-Expand(pwd-seed, "SAE Hash to Element u2 P2", len)
+ */
+ hkdf_expand(hash, pwd_seed, hash_len, "SAE Hash to Element u2 P2",
+ pwd_value, pwd_value_len);
+ u2 = l_ecc_scalar_new_modp(curve, pwd_value, pwd_value_len);
+
+ p1 = l_ecc_point_from_sswu(u1);
+ p2 = l_ecc_point_from_sswu(u2);
+
+ pt = l_ecc_point_new(curve);
+ l_ecc_point_add(pt, p1, p2);
+
+ return l_steal_ptr(pt);
+}
+
+struct l_ecc_point *crypto_derive_sae_pwe_from_pt_ecc(const uint8_t *mac1,
+ const uint8_t *mac2,
+ const struct l_ecc_point *pt)
+{
+ const struct l_ecc_curve *curve = l_ecc_point_get_curve(pt);
+ enum l_checksum_type hash;
+ size_t hash_len;
+ uint8_t sorted_macs[12];
+ uint8_t val_buf[64]; /* Max for SHA-512 */
+ struct l_ecc_scalar *val;
+ struct l_ecc_point *pwe;
+
+ if (!pt || !curve)
+ return false;
+
+ hash = crypto_sae_hash_from_ecc_prime_len(CRYPTO_SAE_HASH_TO_ELEMENT,
+ l_ecc_curve_get_scalar_bytes(curve));
+ hash_len = l_checksum_digest_length(hash);
+
+ /*
+ * val = H(0n, MAX(STA-A-MAC, STA-B-MAC) || MIN(STA-A-MAC, STA-B-MAC))
+ */
+ if (memcmp(mac1, mac2, 6) > 0) {
+ memcpy(sorted_macs, mac1, 6);
+ memcpy(sorted_macs + 6, mac2, 6);
+ } else {
+ memcpy(sorted_macs, mac2, 6);
+ memcpy(sorted_macs + 6, mac1, 6);
+ }
+
+ hkdf_extract(hash, NULL, 0, 1, val_buf,
+ sorted_macs, sizeof(sorted_macs));
+ val = l_ecc_scalar_new_reduced_1_to_n(curve, val_buf, hash_len);
+ pwe = l_ecc_point_new(curve);
+ l_ecc_point_multiply(pwe, val, pt);
+ l_ecc_scalar_free(val);
+
+ return pwe;
+}
diff --git a/src/crypto.h b/src/crypto.h
@@ -23,6 +23,8 @@
#include <stddef.h>
#include <stdbool.h>
+struct l_ecc_point;
+
enum crypto_cipher {
CRYPTO_CIPHER_WEP40 = 0x000fac01,
CRYPTO_CIPHER_WEP104 = 0x000fac05,
@@ -97,6 +99,9 @@ int crypto_psk_from_passphrase(const char *passphrase,
const unsigned char *ssid, size_t ssid_len,
unsigned char *out_psk);
+bool crypto_kdf(enum l_checksum_type type, const void *key, size_t key_len,
+ const void *prefix, size_t prefix_len,
+ const void *data, size_t data_len, void *output, size_t size);
bool kdf_sha256(const void *key, size_t key_len,
const void *prefix, size_t prefix_len,
const void *data, size_t data_len, void *output, size_t size);
@@ -109,12 +114,16 @@ bool prf_sha1(const void *key, size_t key_len,
bool prf_plus_sha1(const void *key, size_t key_len,
const void *prefix, size_t prefix_len,
const void *data, size_t data_len, void *output, size_t size);
-bool hkdf_extract(enum l_checksum_type type, const uint8_t *key, size_t key_len,
- uint8_t num_args, uint8_t *out, ...);
+
+bool prf_plus(enum l_checksum_type type, const void *key, size_t key_len,
+ const char *label, void *out, size_t out_len,
+ size_t n_extra, ...);
+
+bool hkdf_extract(enum l_checksum_type type, const void *key, size_t key_len,
+ uint8_t num_args, void *out, ...);
bool hkdf_expand(enum l_checksum_type type, const uint8_t *key, size_t key_len,
- const char *info, size_t info_len, void *out,
- size_t out_len);
+ const char *info, void *out, size_t out_len);
bool crypto_derive_pairwise_ptk(const uint8_t *pmk, size_t pmk_len,
const uint8_t *addr1, const uint8_t *addr2,
@@ -142,3 +151,18 @@ bool crypto_derive_ft_ptk(const uint8_t *pmk_r1, const uint8_t *pmk_r1_name,
bool crypto_derive_pmkid(const uint8_t *pmk,
const uint8_t *addr1, const uint8_t *addr2,
uint8_t *out_pmkid, bool use_sha256);
+
+enum crypto_sae {
+ CRYPTO_SAE_LOOPING,
+ CRYPTO_SAE_HASH_TO_ELEMENT,
+};
+
+enum l_checksum_type crypto_sae_hash_from_ecc_prime_len(enum crypto_sae type,
+ size_t prime_len);
+struct l_ecc_point *crypto_derive_sae_pt_ecc(unsigned int group,
+ const char *ssid,
+ const char *password,
+ const char *identifier);
+struct l_ecc_point *crypto_derive_sae_pwe_from_pt_ecc(const uint8_t *mac1,
+ const uint8_t *mac2,
+ const struct l_ecc_point *pt);
diff --git a/src/eap-aka.c b/src/eap-aka.c
@@ -189,7 +189,7 @@ static void check_milenage_cb(const uint8_t *res, const uint8_t *ck,
struct eap_aka_handle *aka = eap_get_data(eap);
size_t resp_len = aka->protected ? 44 : 40;
- uint8_t response[resp_len + 4];
+ uint8_t response[EAP_SIM_ROUND(resp_len + 4)];
uint8_t *pos = response;
if (auts) {
@@ -512,7 +512,7 @@ static void handle_notification(struct eap_state *eap, const uint8_t *pkt,
if (value == EAP_SIM_SUCCESS && aka->protected &&
aka->state == EAP_AKA_STATE_CHALLENGE) {
/* header + MAC + MAC header */
- uint8_t response[8 + EAP_SIM_MAC_LEN + 4];
+ uint8_t response[EAP_SIM_ROUND(8 + EAP_SIM_MAC_LEN + 4)];
uint8_t *pos = response;
/*
@@ -564,7 +564,7 @@ static void handle_identity(struct eap_state *eap, const uint8_t *pkt,
size_t len)
{
struct eap_aka_handle *aka = eap_get_data(eap);
- uint8_t response[8 + strlen(aka->identity) + 4];
+ uint8_t response[EAP_SIM_ROUND(8 + strlen(aka->identity) + 4)];
uint8_t *pos = response;
if (aka->state != EAP_AKA_STATE_UNCONNECTED) {
diff --git a/src/eap-pwd.c b/src/eap-pwd.c
@@ -264,7 +264,7 @@ static void eap_pwd_handle_id(struct eap_state *eap,
group = l_get_be16(pkt);
- pwd->curve = l_ecc_curve_get_ike_group(group);
+ pwd->curve = l_ecc_curve_from_ike_group(group);
if (!pwd->curve) {
l_error("group %d not supported", group);
goto error;
diff --git a/src/eapol.c b/src/eapol.c
@@ -1098,6 +1098,15 @@ static void eapol_ptk_1_of_4_retry(struct l_timeout *timeout, void *user_data)
eapol_set_key_timeout(sm, eapol_ptk_1_of_4_retry);
}
+static inline size_t append_ie(uint8_t *ies, const uint8_t *ie)
+{
+ if (!ie)
+ return 0;
+
+ memcpy(ies, ie, ie[1] + 2);
+ return ie[1] + 2;
+}
+
static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
const struct eapol_key *ek,
bool unencrypted)
@@ -1105,7 +1114,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
const uint8_t *kck;
struct eapol_key *step2;
uint8_t mic[MIC_MAXLEN];
- uint8_t ies[512];
+ uint8_t ies[1024];
size_t ies_len;
const uint8_t *own_ie = sm->handshake->supplicant_ie;
const uint8_t *pmkid;
@@ -1142,7 +1151,8 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
goto error_unspecified;
for (i = 0; i < rsn_info.num_pmkids; i++)
- if (!memcmp(rsn_info.pmkids + i * 16, pmkid, 16)) {
+ if (!l_secure_memcmp(rsn_info.pmkids + i * 16,
+ pmkid, 16)) {
found = true;
break;
}
@@ -1155,7 +1165,7 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
if (!handshake_state_get_pmkid(sm->handshake, own_pmkid))
goto error_unspecified;
- if (memcmp(pmkid, own_pmkid, 16)) {
+ if (l_secure_memcmp(pmkid, own_pmkid, 16)) {
l_debug("Authenticator sent a PMKID that didn't match");
/*
@@ -1209,9 +1219,6 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
(IE_RSN_AKM_SUITE_FT_OVER_8021X |
IE_RSN_AKM_SUITE_FT_USING_PSK |
IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256)) {
- const uint8_t *mde = sm->handshake->mde;
- const uint8_t *fte = sm->handshake->fte;
-
/*
* Rebuild the RSNE to include the PMKR1Name and append
* MDE + FTE.
@@ -1222,14 +1229,10 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
ie_build_rsne(&rsn_info, ies);
ies_len = ies[1] + 2;
- memcpy(ies + ies_len, mde, mde[1] + 2);
- ies_len += mde[1] + 2;
-
- memcpy(ies + ies_len, fte, fte[1] + 2);
- ies_len += fte[1] + 2;
+ ies_len += append_ie(ies + ies_len, sm->handshake->mde);
+ ies_len += append_ie(ies + ies_len, sm->handshake->fte);
} else {
- ies_len = own_ie[1] + 2;
- memcpy(ies, own_ie, ies_len);
+ ies_len = append_ie(ies, own_ie);
}
if (sm->handshake->support_ip_allocation) {
@@ -1241,6 +1244,14 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
ies[ies_len++] = 0x01;
}
+ /*
+ * 802.11-2020, Section 12.7.6.3:
+ * "The RSNXE that the Supplicant sent in its (Re)Association Request
+ * frame, if this element is present in the (Re)Association Request
+ * frame that the Supplicant sent."
+ */
+ ies_len += append_ie(ies + ies_len, sm->handshake->supplicant_rsnxe);
+
step2 = eapol_create_ptk_2_of_4(sm->protocol_version,
ek->key_descriptor_version,
L_BE64_TO_CPU(ek->key_replay_counter),
@@ -1487,13 +1498,14 @@ static void eapol_handle_ptk_2_of_4(struct eapol_sm *sm,
}
if (sm->handshake->support_ip_allocation) {
+ size_t len;
const uint8_t *ip_req_kde =
- eapol_find_wfa_kde(EAPOL_KEY_DATA(ek, sm->mic_len),
+ handshake_util_find_kde(HANDSHAKE_KDE_IP_ADDRESS_REQ,
+ EAPOL_KEY_DATA(ek, sm->mic_len),
EAPOL_KEY_DATA_LEN(ek, sm->mic_len),
- HANDSHAKE_KDE_IP_ADDRESS_REQ & 255);
+ &len);
- if (ip_req_kde &&
- (ip_req_kde[1] < 5 || ip_req_kde[6] != 0x01)) {
+ if (ip_req_kde && (len < 1 || ip_req_kde[0] != 0x01)) {
l_debug("Invalid IP Address Request KDE in frame 2/4");
handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
return;
@@ -1551,12 +1563,40 @@ static bool eapol_check_ip_mask(const uint8_t *mask,
(uint32_t) (mask_uint << __builtin_popcountl(mask_uint)) == 0;
}
+static int eapol_ie_matches(const void *ies, size_t ies_len,
+ enum ie_type type, uint8_t *target_ie)
+{
+ struct ie_tlv_iter iter;
+
+ ie_tlv_iter_init(&iter, ies, ies_len);
+
+ while (ie_tlv_iter_next(&iter)) {
+ if (ie_tlv_iter_get_tag(&iter) != type)
+ continue;
+
+ if (!target_ie)
+ return -EINVAL;
+
+ if (memcmp(ie_tlv_iter_get_data(&iter) - 2,
+ target_ie, target_ie[1] + 2))
+ return -EBADMSG;
+
+ return 0;
+ }
+
+ if (!target_ie)
+ return 0;
+
+ return -ENOENT;
+}
+
static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
const struct eapol_key *ek,
const uint8_t *decrypted_key_data,
size_t decrypted_key_data_size,
bool unencrypted)
{
+ struct handshake_state *hs = sm->handshake;
const uint8_t *kck;
const uint8_t *kek;
struct eapol_key *step4;
@@ -1567,12 +1607,14 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
size_t igtk_len;
const uint8_t *rsne;
const uint8_t *optional_rsne = NULL;
+ const uint8_t *transition_disable;
+ size_t transition_disable_len;
uint8_t gtk_key_index;
uint16_t igtk_key_index;
- l_debug("ifindex=%u", sm->handshake->ifindex);
+ l_debug("ifindex=%u", hs->ifindex);
- if (!eapol_verify_ptk_3_of_4(ek, sm->handshake->wpa_ie, sm->mic_len)) {
+ if (!eapol_verify_ptk_3_of_4(ek, hs->wpa_ie, sm->mic_len)) {
handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);
return;
}
@@ -1584,7 +1626,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
* or if the ANonce value in message 3 differs from the ANonce value
* in message 1."
*/
- if (memcmp(sm->handshake->anonce, ek->key_nonce, sizeof(ek->key_nonce)))
+ if (memcmp(hs->anonce, ek->key_nonce, sizeof(ek->key_nonce)))
return;
/*
@@ -1593,10 +1635,10 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
* not identical to that the STA received in the Beacon or Probe
* Response frame, the STA shall disassociate.
*/
- if (sm->handshake->wpa_ie)
+ if (hs->wpa_ie)
rsne = eapol_find_wpa_ie(decrypted_key_data,
decrypted_key_data_size);
- else if (sm->handshake->osen_ie)
+ else if (hs->osen_ie)
rsne = eapol_find_wfa_kde(decrypted_key_data,
decrypted_key_data_size,
IE_WFA_OI_OSEN);
@@ -1608,54 +1650,58 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
if (!rsne)
goto error_ie_different;
- if (!handshake_util_ap_ie_matches(rsne, sm->handshake->authenticator_ie,
- sm->handshake->wpa_ie))
+ if (!handshake_util_ap_ie_matches(rsne, hs->authenticator_ie,
+ hs->wpa_ie))
goto error_ie_different;
- if (sm->handshake->akm_suite &
+ if (hs->akm_suite &
(IE_RSN_AKM_SUITE_FT_OVER_8021X |
IE_RSN_AKM_SUITE_FT_USING_PSK |
IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256)) {
- struct ie_tlv_iter iter;
struct ie_rsn_info ie_info;
- const uint8_t *mde = sm->handshake->mde;
- const uint8_t *fte = sm->handshake->fte;
if (ie_parse_rsne_from_data(rsne, rsne[1] + 2, &ie_info) < 0)
goto error_ie_different;
if (ie_info.num_pmkids != 1 || memcmp(ie_info.pmkids,
- sm->handshake->pmk_r1_name, 16))
+ hs->pmk_r1_name, 16))
goto error_ie_different;
- ie_tlv_iter_init(&iter, decrypted_key_data,
- decrypted_key_data_size);
-
- while (ie_tlv_iter_next(&iter))
- switch (ie_tlv_iter_get_tag(&iter)) {
- case IE_TYPE_MOBILITY_DOMAIN:
- if (memcmp(ie_tlv_iter_get_data(&iter) - 2,
- mde, mde[1] + 2))
- goto error_ie_different;
-
- break;
-
- case IE_TYPE_FAST_BSS_TRANSITION:
- if (memcmp(ie_tlv_iter_get_data(&iter) - 2,
- fte, fte[1] + 2))
- goto error_ie_different;
+ if (eapol_ie_matches(decrypted_key_data,
+ decrypted_key_data_size,
+ IE_TYPE_MOBILITY_DOMAIN,
+ hs->mde) < 0)
+ goto error_ie_different;
- break;
- }
+ if (eapol_ie_matches(decrypted_key_data,
+ decrypted_key_data_size,
+ IE_TYPE_FAST_BSS_TRANSITION,
+ hs->fte) < 0)
+ goto error_ie_different;
}
/*
+ * 802.11-2020, Section 12.7.6.4:
+ * "If the RSNXE is present, the Supplicant verifies that the RSNXE is
+ * identical to that the STA received in the Beacon or Probe Response
+ * frame."
+ *
+ * Verify only if RSN is used
+ */
+ if (!hs->osen_ie && !hs->wpa_ie &&
+ eapol_ie_matches(decrypted_key_data,
+ decrypted_key_data_size,
+ IE_TYPE_RSNX,
+ hs->authenticator_rsnxe) < 0)
+ goto error_ie_different;
+
+ /*
* If ptk_complete is set, then we are receiving Message 3 again.
* It must be a retransmission, otherwise the anonce wouldn't match
* and we wouldn't get here. Skip processing the rest of the message
* and send our reply. Do not install the keys again.
*/
- if (sm->handshake->ptk_complete)
+ if (hs->ptk_complete)
goto retransmit;
/*
@@ -1681,7 +1727,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
* pairwise cipher suite which is advertised by an AP, but
* which policy disallows for this particular STA. An
* Authenticator may, therefore, insert a second RSNE to
- * overrule the STA's selection. An Authenticator’s SME shall
+ * overrule the STA's selection. An Authenticator's SME shall
* insert the second RSNE, after the first RSNE, only for this
* purpose. The pairwise cipher suite in the second RSNE
* included shall be one of the ciphers advertised by the
@@ -1708,12 +1754,11 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
return;
}
- handshake_state_override_pairwise_cipher(sm->handshake,
- override);
+ handshake_state_override_pairwise_cipher(hs, override);
}
- if (!sm->handshake->wpa_ie && sm->handshake->group_cipher !=
- IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC) {
+ if (!hs->wpa_ie && hs->group_cipher !=
+ IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC) {
gtk = handshake_util_find_gtk_kde(decrypted_key_data,
decrypted_key_data_size,
>k_len);
@@ -1730,7 +1775,7 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
} else
gtk = NULL;
- if (sm->handshake->mfp) {
+ if (hs->mfp) {
igtk = handshake_util_find_igtk_kde(decrypted_key_data,
decrypted_key_data_size,
&igtk_len);
@@ -1745,35 +1790,42 @@ static void eapol_handle_ptk_3_of_4(struct eapol_sm *sm,
} else
igtk = NULL;
- if (sm->handshake->support_ip_allocation) {
+ if (hs->support_ip_allocation) {
+ size_t len;
const uint8_t *ip_alloc_kde =
- eapol_find_wfa_kde(decrypted_key_data,
- decrypted_key_data_size,
- HANDSHAKE_KDE_IP_ADDRESS_ALLOC & 255);
-
- if (ip_alloc_kde &&
- (ip_alloc_kde[1] < 16 ||
- !eapol_check_ip_mask(ip_alloc_kde + 10,
- ip_alloc_kde + 6,
- ip_alloc_kde + 14))) {
+ handshake_util_find_kde(HANDSHAKE_KDE_IP_ADDRESS_ALLOC,
+ decrypted_key_data,
+ decrypted_key_data_size,
+ &len);
+
+ if (ip_alloc_kde && (len < 12 ||
+ !eapol_check_ip_mask(ip_alloc_kde + 4,
+ ip_alloc_kde,
+ ip_alloc_kde + 8))) {
l_debug("Invalid IP Allocation KDE in frame 3/4");
handshake_failed(sm, MMPDU_REASON_CODE_INVALID_IE);
return;
}
- sm->handshake->support_ip_allocation = ip_alloc_kde != NULL;
+ hs->support_ip_allocation = ip_alloc_kde != NULL;
if (ip_alloc_kde) {
- sm->handshake->client_ip_addr =
- l_get_be32(ip_alloc_kde + 6);
- sm->handshake->subnet_mask =
- l_get_be32(ip_alloc_kde + 10);
- sm->handshake->go_ip_addr =
- l_get_be32(ip_alloc_kde + 14);
+ hs->client_ip_addr = l_get_be32(ip_alloc_kde);
+ hs->subnet_mask = l_get_be32(ip_alloc_kde + 4);
+ hs->go_ip_addr = l_get_be32(ip_alloc_kde + 8);
} else
l_debug("Authenticator ignored our IP Address Request");
}
+ transition_disable =
+ handshake_util_find_kde(HANDSHAKE_KDE_TRANSITION_DISABLE,
+ decrypted_key_data,
+ decrypted_key_data_size,
+ &transition_disable_len);
+ if (transition_disable)
+ handshake_event(hs, HANDSHAKE_EVENT_TRANSITION_DISABLE,
+ transition_disable, transition_disable_len);
+
retransmit:
/*
* 802.11-2016, Section 12.7.6.4:
@@ -1790,14 +1842,14 @@ retransmit:
step4 = eapol_create_ptk_4_of_4(sm->protocol_version,
ek->key_descriptor_version,
sm->replay_counter,
- sm->handshake->wpa_ie, sm->mic_len);
+ hs->wpa_ie, sm->mic_len);
- kck = handshake_state_get_kck(sm->handshake);
- kek = handshake_state_get_kek(sm->handshake);
+ kck = handshake_state_get_kck(hs);
+ kek = handshake_state_get_kek(hs);
if (sm->mic_len) {
- if (!eapol_calculate_mic(sm->handshake->akm_suite, kck,
- step4, mic, sm->mic_len)) {
+ if (!eapol_calculate_mic(hs->akm_suite, kck,
+ step4, mic, sm->mic_len)) {
l_debug("MIC Calculation failed");
l_free(step4);
handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);
@@ -1806,10 +1858,9 @@ retransmit:
memcpy(EAPOL_KEY_MIC(step4), mic, sm->mic_len);
} else {
- if (!eapol_aes_siv_encrypt(
- handshake_state_get_kek(sm->handshake),
- handshake_state_get_kek_len(sm->handshake),
- step4, NULL, 0)) {
+ if (!eapol_aes_siv_encrypt(handshake_state_get_kek(hs),
+ handshake_state_get_kek_len(hs),
+ step4, NULL, 0)) {
l_debug("AES-SIV encryption failed");
l_free(step4);
handshake_failed(sm, MMPDU_REASON_CODE_UNSPECIFIED);
@@ -1820,7 +1871,7 @@ retransmit:
eapol_sm_write(sm, (struct eapol_frame *) step4, unencrypted);
l_free(step4);
- if (sm->handshake->ptk_complete)
+ if (hs->ptk_complete)
return;
/*
@@ -1828,9 +1879,8 @@ retransmit:
* ptk, this flag tells netdev to wait for the gtk/igtk before
* completing the connection.
*/
- if (!gtk && sm->handshake->group_cipher !=
- IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC)
- sm->handshake->wait_for_gtk = true;
+ if (!gtk && hs->group_cipher != IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC)
+ hs->wait_for_gtk = true;
if (gtk)
eapol_install_gtk(sm, gtk_key_index, gtk, gtk_len, ek->key_rsc);
@@ -1838,10 +1888,10 @@ retransmit:
if (igtk)
eapol_install_igtk(sm, igtk_key_index, igtk, igtk_len);
- handshake_state_install_ptk(sm->handshake);
+ handshake_state_install_ptk(hs);
if (rekey_offload)
- rekey_offload(sm->handshake->ifindex, kek, kck,
+ rekey_offload(hs->ifindex, kek, kck,
sm->replay_counter, sm->user_data);
l_timeout_remove(sm->timeout);
@@ -2213,12 +2263,12 @@ static void eapol_eap_results_cb(const uint8_t *msk_data, size_t msk_len,
/*
* 802.11i 8.5.1.2:
* "When not using a PSK, the PMK is derived from the AAA key.
- * The PMK shall be computed as the first 256 bits (bits 0–255)
- * of the AAA key: PMK ← L(PTK, 0, 256)."
+ * The PMK shall be computed as the first 256 bits (bits 0-255)
+ * of the AAA key: PMK = L(PTK, 0, 256)."
* 802.11-2016 12.7.1.3:
* "When not using a PSK, the PMK is derived from the MSK.
* The PMK shall be computed as the first PMK_bits bits
- * (bits 0 to PMK_bits–1) of the MSK: PMK = L(MSK, 0, PMK_bits)."
+ * (bits 0 to PMK_bits-1) of the MSK: PMK = L(MSK, 0, PMK_bits)."
* RFC5247 explains AAA-Key refers to the MSK and confirms the
* first 32 bytes of the MSK are used. MSK is at least 64 octets
* long per RFC3748. Note WEP derives the PTK from MSK differently.
diff --git a/src/erp.c b/src/erp.c
@@ -278,17 +278,15 @@ static bool erp_derive_emsk_name(const uint8_t *session_id, size_t session_len,
char buf[static 17])
{
uint8_t hex[8];
- char info[7] = { 'E', 'M', 'S', 'K', '\0', 0x0, 0x8};
+ uint16_t eight = L_CPU_TO_BE16(8);
char *ascii;
- if (!hkdf_expand(L_CHECKSUM_SHA256, session_id, session_len, info,
- sizeof(info), hex, 8))
+ if (!prf_plus(L_CHECKSUM_SHA256, session_id, session_len, "EMSK",
+ hex, 8, 1, &eight, sizeof(eight)))
return false;
ascii = l_util_hexstring(hex, 8);
-
strcpy(buf, ascii);
-
l_free(ascii);
return true;
@@ -308,26 +306,17 @@ static bool erp_derive_emsk_name(const uint8_t *session_id, size_t session_len,
static bool erp_derive_reauth_keys(const uint8_t *emsk, size_t emsk_len,
void *r_rk, void *r_ik)
{
- char info[256];
- char *ptr;
+ uint16_t len = L_CPU_TO_BE16(emsk_len);
+ uint8_t cryptosuite = ERP_CRYPTOSUITE_SHA256_128;
- ptr = info + l_strlcpy(info, ERP_RRK_LABEL, sizeof(info)) + 1;
-
- l_put_be16(emsk_len, ptr);
- ptr += 2;
-
- if (!hkdf_expand(L_CHECKSUM_SHA256, emsk, emsk_len, (const char *)info,
- ptr - info, r_rk, emsk_len))
+ if (!prf_plus(L_CHECKSUM_SHA256, emsk, emsk_len, ERP_RRK_LABEL,
+ r_rk, emsk_len, 1,
+ &len, sizeof(len)))
return false;
- ptr = info + l_strlcpy(info, ERP_RIK_LABEL, sizeof(info)) + 1;
-
- *ptr++ = ERP_CRYPTOSUITE_SHA256_128;
- l_put_be16(emsk_len, ptr);
- ptr += 2;
-
- if (!hkdf_expand(L_CHECKSUM_SHA256, r_rk, emsk_len, (const char *) info,
- ptr - info, r_ik, emsk_len))
+ if (!prf_plus(L_CHECKSUM_SHA256, r_rk, emsk_len, ERP_RIK_LABEL,
+ r_ik, emsk_len, 2,
+ &cryptosuite, 1, &len, sizeof(len)))
return false;
return true;
@@ -411,11 +400,10 @@ int erp_rx_packet(struct erp_state *erp, const uint8_t *pkt, size_t len)
struct erp_tlv_iter iter;
enum eap_erp_cryptosuite cs;
uint8_t hash[16];
- char info[256];
- char *ptr = info;
const uint8_t *nai = NULL;
uint8_t type;
uint16_t seq;
+ uint16_t length;
bool r;
/*
@@ -503,16 +491,14 @@ int erp_rx_packet(struct erp_state *erp, const uint8_t *pkt, size_t len)
/*
* RFC 6696 Section 4.6 - rMSK Derivation
*/
- strcpy(ptr, ERP_RMSK_LABEL);
- ptr += strlen(ERP_RMSK_LABEL);
- *ptr++ = '\0';
- l_put_be16(erp->seq, ptr);
- ptr += 2;
- l_put_be16(64, ptr);
- ptr += 2;
-
- if (!hkdf_expand(L_CHECKSUM_SHA256, erp->r_rk, erp->cache->emsk_len,
- info, ptr - info, erp->rmsk, erp->cache->emsk_len))
+ seq = L_CPU_TO_BE16(erp->seq);
+ length = L_CPU_TO_BE16(64);
+
+ if (!prf_plus(L_CHECKSUM_SHA256, erp->r_rk, erp->cache->emsk_len,
+ ERP_RMSK_LABEL,
+ erp->rmsk, erp->cache->emsk_len, 2,
+ &seq, sizeof(seq),
+ &length, sizeof(length)))
goto eap_failed;
return 0;
diff --git a/src/fils.c b/src/fils.c
@@ -91,7 +91,6 @@ static void fils_erp_tx_func(const uint8_t *eap_data, size_t len,
struct ie_tlv_builder builder;
uint8_t data[256];
uint8_t *ptr = data;
- unsigned int tlv_len;
struct ie_rsn_info rsn_info;
uint8_t *rsne;
@@ -133,9 +132,9 @@ static void fils_erp_tx_func(const uint8_t *eap_data, size_t len,
fils->hs->mde[1]);
}
- ie_tlv_builder_finalize(&builder, &tlv_len);
+ ie_tlv_builder_finalize(&builder, &len);
- fils->auth(data, ptr - data + tlv_len, fils->user_data);
+ fils->auth(data, ptr - data + len, fils->user_data);
}
static int fils_derive_key_data(struct fils_sm *fils)
@@ -153,7 +152,7 @@ static int fils_derive_key_data(struct fils_sm *fils)
size_t iov_elems = 0;
size_t fils_ft_len = 0;
bool sha384;
- unsigned int ie_len;
+ size_t ie_len;
uint8_t *rsne = NULL;
rmsk = erp_get_rmsk(fils->erp, &rmsk_len);
@@ -191,10 +190,10 @@ static int fils_derive_key_data(struct fils_sm *fils)
/*
* IEEE 802.11ai - 12.12.2.5.3 PTKSA key derivation with FILS
- * authentication
+ * authentication
*
- * FILS-Key-Data = PRF-X(PMK, “FILS PTK Derivation”, SPA || AA ||
- * SNonce || ANonce)
+ * FILS-Key-Data = PRF-X(PMK, "FILS PTK Derivation", SPA || AA ||
+ * SNonce || ANonce)
*/
memcpy(ptr, fils->hs->spa, 6);
ptr += 6;
@@ -339,8 +338,8 @@ static int fils_rx_authenticate(struct auth_proto *driver, const uint8_t *frame,
size_t len)
{
struct fils_sm *fils = l_container_of(driver, struct fils_sm, ap);
- const struct mmpdu_header *hdr = mpdu_validate(frame, len);
- const struct mmpdu_authentication *auth;
+ const struct mmpdu_header *hdr = (const struct mmpdu_header *) frame;
+ const struct mmpdu_authentication *auth = mmpdu_body(hdr);
uint16_t alg;
struct ie_tlv_iter iter;
const uint8_t *anonce = NULL;
@@ -351,18 +350,6 @@ static int fils_rx_authenticate(struct auth_proto *driver, const uint8_t *frame,
const uint8_t *mde = NULL;
const uint8_t *fte = NULL;
- if (!hdr) {
- l_debug("Auth frame header did not validate");
- return -EBADMSG;
- }
-
- auth = mmpdu_body(hdr);
-
- if (!auth) {
- l_debug("Auth frame body did not validate");
- return -EBADMSG;
- }
-
if (auth->status != 0) {
l_debug("invalid status %u", auth->status);
return L_LE16_TO_CPU(auth->status);
@@ -459,8 +446,8 @@ static int fils_rx_associate(struct auth_proto *driver, const uint8_t *frame,
size_t len)
{
struct fils_sm *fils = l_container_of(driver, struct fils_sm, ap);
- const struct mmpdu_header *hdr = mpdu_validate(frame, len);
- const struct mmpdu_association_response *assoc;
+ const struct mmpdu_header *hdr = (const struct mmpdu_header *) frame;
+ const struct mmpdu_association_response *assoc = mmpdu_body(hdr);
struct ie_tlv_iter iter;
uint8_t key_rsc[8];
const uint8_t *gtk = NULL;
@@ -476,18 +463,6 @@ static int fils_rx_associate(struct auth_proto *driver, const uint8_t *frame,
uint8_t data[44];
uint8_t *ptr = data;
- if (!hdr) {
- l_debug("Assoc frame header did not validate");
- return -EBADMSG;
- }
-
- assoc = mmpdu_body(hdr);
-
- if (!assoc) {
- l_debug("Assoc frame body did not validate");
- return -EBADMSG;
- }
-
if (assoc->status_code != 0)
return L_CPU_TO_LE16(assoc->status_code);
diff --git a/src/handshake.c b/src/handshake.c
@@ -42,6 +42,29 @@
#include "src/util.h"
#include "src/handshake.h"
+static inline unsigned int n_ecc_groups()
+{
+ const unsigned int *groups = l_ecc_supported_ike_groups();
+ unsigned int j = 0;
+
+ while (groups[j])
+ j += 1;
+
+ return j;
+}
+
+static inline int ecc_group_index(unsigned int group)
+{
+ const unsigned int *groups = l_ecc_supported_ike_groups();
+ int j;
+
+ for (j = 0; groups[j]; j++)
+ if (groups[j] == group)
+ return j;
+
+ return -ENOENT;
+}
+
static bool handshake_get_nonce(uint8_t nonce[])
{
return l_getrandom(nonce, 32);
@@ -78,6 +101,8 @@ void handshake_state_free(struct handshake_state *s)
l_free(s->authenticator_ie);
l_free(s->supplicant_ie);
+ l_free(s->authenticator_rsnxe);
+ l_free(s->supplicant_rsnxe);
l_free(s->mde);
l_free(s->fte);
@@ -86,6 +111,15 @@ void handshake_state_free(struct handshake_state *s)
l_free(s->passphrase);
}
+ if (s->ecc_sae_pts) {
+ unsigned int i;
+
+ for (i = 0; i < n_ecc_groups(); i++)
+ l_ecc_point_free(s->ecc_sae_pts[i]);
+
+ l_free(s->ecc_sae_pts);
+ }
+
explicit_bzero(s, sizeof(*s));
if (destroy)
@@ -209,6 +243,39 @@ bool handshake_state_set_supplicant_ie(struct handshake_state *s,
return handshake_state_setup_own_ciphers(s, &info);
}
+static void replace_ie(uint8_t **old, const uint8_t *new)
+{
+ if (*old == NULL) {
+ *old = new ? l_memdup(new, new[1] + 2) : NULL;
+ return;
+ }
+
+ if (!new) {
+ l_free(*old);
+ *old = NULL;
+ return;
+ }
+
+ if ((*old)[1] == new[1] && !memcmp(*old, new, new[1] + 2))
+ return;
+
+ l_free(*old);
+ *old = l_memdup(new, new[1] + 2);
+}
+
+void handshake_state_set_authenticator_rsnxe(struct handshake_state *s,
+ const uint8_t *ie)
+{
+ l_free(s->authenticator_rsnxe);
+ s->authenticator_rsnxe = ie ? l_memdup(ie, ie[1] + 2) : NULL;
+}
+
+void handshake_state_set_supplicant_rsnxe(struct handshake_state *s,
+ const uint8_t *ie)
+{
+ replace_ie(&s->supplicant_rsnxe, ie);
+}
+
void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid,
size_t ssid_len)
{
@@ -218,18 +285,12 @@ void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid,
void handshake_state_set_mde(struct handshake_state *s, const uint8_t *mde)
{
- if (s->mde)
- l_free(s->mde);
-
- s->mde = mde ? l_memdup(mde, mde[1] + 2) : NULL;
+ replace_ie(&s->mde, mde);
}
void handshake_state_set_fte(struct handshake_state *s, const uint8_t *fte)
{
- if (s->fte)
- l_free(s->fte);
-
- s->fte = fte ? l_memdup(fte, fte[1] + 2) : NULL;
+ replace_ie(&s->fte, fte);
}
void handshake_state_set_kh_ids(struct handshake_state *s,
@@ -752,8 +813,9 @@ bool handshake_util_ap_ie_matches(const uint8_t *msg_ie,
return true;
}
-static const uint8_t *find_kde(const uint8_t *data, size_t data_len,
- size_t *out_len, enum handshake_kde selector)
+const uint8_t *handshake_util_find_kde(enum handshake_kde selector,
+ const uint8_t *data, size_t data_len,
+ size_t *out_kde_len)
{
struct ie_tlv_iter iter;
const uint8_t *result;
@@ -774,8 +836,8 @@ static const uint8_t *find_kde(const uint8_t *data, size_t data_len,
if (l_get_be32(result) != selector)
continue;
- if (out_len)
- *out_len = len - 4;
+ if (out_kde_len)
+ *out_kde_len = len - 4;
return result + 4;
}
@@ -787,8 +849,8 @@ const uint8_t *handshake_util_find_gtk_kde(const uint8_t *data, size_t data_len,
size_t *out_gtk_len)
{
size_t gtk_len;
- const uint8_t *gtk = find_kde(data, data_len, >k_len,
- HANDSHAKE_KDE_GTK);
+ const uint8_t *gtk = handshake_util_find_kde(HANDSHAKE_KDE_GTK,
+ data, data_len, >k_len);
if (!gtk)
return NULL;
@@ -814,8 +876,8 @@ const uint8_t *handshake_util_find_igtk_kde(const uint8_t *data,
size_t *out_igtk_len)
{
size_t igtk_len;
- const uint8_t *igtk = find_kde(data, data_len, &igtk_len,
- HANDSHAKE_KDE_IGTK);
+ const uint8_t *igtk = handshake_util_find_kde(HANDSHAKE_KDE_IGTK,
+ data, data_len, &igtk_len);
if (!igtk)
return NULL;
@@ -842,7 +904,8 @@ const uint8_t *handshake_util_find_pmkid_kde(const uint8_t *data,
const uint8_t *pmkid;
size_t pmkid_len;
- pmkid = find_kde(data, data_len, &pmkid_len, HANDSHAKE_KDE_PMKID);
+ pmkid = handshake_util_find_kde(HANDSHAKE_KDE_PMKID, data, data_len,
+ &pmkid_len);
if (pmkid && pmkid_len != 16)
return NULL;
@@ -921,3 +984,28 @@ bool handshake_decode_fte_key(struct handshake_state *s, const uint8_t *wrapped,
return true;
}
+
+/* Add SAE-PT for ECC groups. The group is carried by the point itself */
+bool handshake_state_add_ecc_sae_pt(struct handshake_state *s,
+ const struct l_ecc_point *pt)
+{
+ const struct l_ecc_curve *curve;
+ int i;
+
+ if (!pt)
+ return false;
+
+ curve = l_ecc_point_get_curve(pt);
+
+ if (!s->ecc_sae_pts)
+ s->ecc_sae_pts = l_new(struct l_ecc_point *, n_ecc_groups());
+
+ if ((i = ecc_group_index(l_ecc_curve_get_ike_group(curve))) < 0)
+ return false;
+
+ if (s->ecc_sae_pts[i])
+ return false;
+
+ s->ecc_sae_pts[i] = l_ecc_point_clone(pt);
+ return true;
+}
diff --git a/src/handshake.h b/src/handshake.h
@@ -44,6 +44,8 @@ enum handshake_kde {
/* Wi-Fi P2P Technical Specification v1.7 4.2.8 */
HANDSHAKE_KDE_IP_ADDRESS_REQ = 0x506f9a04,
HANDSHAKE_KDE_IP_ADDRESS_ALLOC = 0x506f9a05,
+ /* Wi-Fi WPA3 Specification v3.0 Table 4 */
+ HANDSHAKE_KDE_TRANSITION_DISABLE = 0x506f9a20,
};
enum handshake_event {
@@ -54,6 +56,7 @@ enum handshake_event {
HANDSHAKE_EVENT_FAILED,
HANDSHAKE_EVENT_REKEY_FAILED,
HANDSHAKE_EVENT_EAP_NOTIFY,
+ HANDSHAKE_EVENT_TRANSITION_DISABLE,
};
typedef void (*handshake_event_func_t)(struct handshake_state *hs,
@@ -85,6 +88,8 @@ struct handshake_state {
uint8_t aa[6];
uint8_t *authenticator_ie;
uint8_t *supplicant_ie;
+ uint8_t *authenticator_rsnxe;
+ uint8_t *supplicant_rsnxe;
uint8_t *mde;
uint8_t *fte;
enum ie_rsn_cipher_suite pairwise_cipher;
@@ -104,6 +109,7 @@ struct handshake_state {
uint8_t fils_ft[48];
uint8_t fils_ft_len;
struct l_settings *settings_8021x;
+ struct l_ecc_point **ecc_sae_pts;
bool have_snonce : 1;
bool ptk_complete : 1;
bool wpa_ie : 1;
@@ -163,6 +169,10 @@ bool handshake_state_set_authenticator_ie(struct handshake_state *s,
const uint8_t *ie);
bool handshake_state_set_supplicant_ie(struct handshake_state *s,
const uint8_t *ie);
+void handshake_state_set_authenticator_rsnxe(struct handshake_state *s,
+ const uint8_t *ie);
+void handshake_state_set_supplicant_rsnxe(struct handshake_state *s,
+ const uint8_t *ie);
void handshake_state_set_ssid(struct handshake_state *s,
const uint8_t *ssid, size_t ssid_len);
void handshake_state_set_mde(struct handshake_state *s,
@@ -178,6 +188,8 @@ void handshake_state_set_event_func(struct handshake_state *s,
void *user_data);
void handshake_state_set_passphrase(struct handshake_state *s,
const char *passphrase);
+bool handshake_state_add_ecc_sae_pt(struct handshake_state *s,
+ const struct l_ecc_point *pt);
void handshake_state_set_no_rekey(struct handshake_state *s, bool no_rekey);
void handshake_state_set_fils_ft(struct handshake_state *s,
@@ -224,6 +236,9 @@ void handshake_state_set_gtk(struct handshake_state *s, const uint8_t *key,
bool handshake_util_ap_ie_matches(const uint8_t *msg_ie,
const uint8_t *scan_ie, bool is_wpa);
+const uint8_t *handshake_util_find_kde(enum handshake_kde selector,
+ const uint8_t *data, size_t data_len,
+ size_t *out_kde_len);
const uint8_t *handshake_util_find_gtk_kde(const uint8_t *data, size_t data_len,
size_t *out_gtk_len);
const uint8_t *handshake_util_find_igtk_kde(const uint8_t *data,
diff --git a/src/hotspot.c b/src/hotspot.c
@@ -314,7 +314,8 @@ static struct network_info_ops hotspot_ops = {
};
static struct hs20_config *hs20_config_new(struct l_settings *settings,
- char *filename)
+ char *filename,
+ struct network_config *c)
{
struct hs20_config *config;
char *hessid_str;
@@ -322,21 +323,14 @@ static struct hs20_config *hs20_config_new(struct l_settings *settings,
size_t rc_len;
uint8_t *rc;
char *name;
- bool autoconnect;
/* One of HESSID, NAI realms, or Roaming Consortium must be included */
hessid_str = l_settings_get_string(settings, "Hotspot", "HESSID");
-
nai_realms = l_settings_get_string_list(settings, "Hotspot",
"NAIRealmNames", ',');
-
rc = l_settings_get_bytes(settings, "Hotspot", "RoamingConsortium",
&rc_len);
- if (!l_settings_get_bool(settings, "Settings", "AutoConnect",
- &autoconnect))
- autoconnect = true;
-
name = l_settings_get_string(settings, "Hotspot", "Name");
if ((!hessid_str && !nai_realms && !rc) || !name) {
@@ -376,14 +370,11 @@ static struct hs20_config *hs20_config_new(struct l_settings *settings,
config->rc_len = rc_len;
}
- config->super.is_autoconnectable = autoconnect;
+ __network_info_init(&config->super, NULL, SECURITY_8021X, c);
config->super.is_hotspot = true;
- config->super.type = SECURITY_8021X;
- config->super.ops = &hotspot_ops;
- config->super.connected_time = l_path_get_mtime(filename);
config->name = name;
-
config->filename = l_strdup(filename);
+ config->super.ops = &hotspot_ops;
known_networks_add(&config->super);
@@ -404,7 +395,8 @@ static void hs20_dir_watch_cb(const char *filename,
{
struct l_settings *new;
uint64_t connected_time;
- struct hs20_config *config;
+ struct hs20_config *hs20;
+ struct network_config config;
L_AUTO_FREE_VAR(char *, full_path) = NULL;
@@ -427,34 +419,29 @@ static void hs20_dir_watch_cb(const char *filename,
return;
}
- config = hs20_config_new(new, full_path);
+ __network_config_parse(new, full_path, &config);
+
+ hs20 = hs20_config_new(new, full_path, &config);
l_settings_free(new);
- if (!config)
+ if (!hs20)
return;
- l_queue_push_head(hs20_settings, config);
+ l_queue_push_head(hs20_settings, hs20);
break;
case L_DIR_WATCH_EVENT_REMOVED:
- config = l_queue_remove_if(hs20_settings, match_filename,
+ hs20 = l_queue_remove_if(hs20_settings, match_filename,
full_path);
- if (!config)
+ if (!hs20)
return;
- known_networks_remove(&config->super);
-
- /*
- * TODO: Disconnect any networks using this provisioning file
- */
-
+ known_networks_remove(&hs20->super);
break;
case L_DIR_WATCH_EVENT_MODIFIED:
- config = l_queue_find(hs20_settings, match_filename, full_path);
- if (!config)
+ hs20 = l_queue_find(hs20_settings, match_filename, full_path);
+ if (!hs20)
return;
- connected_time = l_path_get_mtime(full_path);
-
new = l_settings_new();
if (!l_settings_load_from_file(new, full_path)) {
@@ -462,9 +449,10 @@ static void hs20_dir_watch_cb(const char *filename,
return;
}
- known_network_set_connected_time(&config->super,
- connected_time);
- known_network_update(&config->super, new);
+ __network_config_parse(new, full_path, &config);
+ known_network_update(&hs20->super, &config);
+
+ /* TODO: Update hotspot specific settings */
l_settings_free(new);
@@ -472,14 +460,13 @@ static void hs20_dir_watch_cb(const char *filename,
case L_DIR_WATCH_EVENT_ACCESSED:
break;
case L_DIR_WATCH_EVENT_ATTRIB:
- config = l_queue_find(hs20_settings, match_filename, full_path);
- if (!config)
+ hs20 = l_queue_find(hs20_settings, match_filename, full_path);
+ if (!hs20)
return;
connected_time = l_path_get_mtime(full_path);
- known_network_set_connected_time(&config->super,
+ known_network_set_connected_time(&hs20->super,
connected_time);
-
break;
}
}
@@ -503,9 +490,10 @@ static int hotspot_init(void)
hs20_settings = l_queue_new();
while ((dirent = readdir(dir))) {
- struct hs20_config *config;
+ struct hs20_config *hs20;
struct l_settings *s;
char *filename;
+ struct network_config config;
if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
continue;
@@ -516,10 +504,11 @@ static int hotspot_init(void)
if (!l_settings_load_from_file(s, filename))
goto next;
- config = hs20_config_new(s, filename);
+ __network_config_parse(s, filename, &config);
- if (config)
- l_queue_push_head(hs20_settings, config);
+ hs20 = hs20_config_new(s, filename, &config);
+ if (hs20)
+ l_queue_push_head(hs20_settings, hs20);
next:
l_free(filename);
diff --git a/src/ie.c b/src/ie.c
@@ -393,7 +393,7 @@ bool ie_tlv_builder_recurse(struct ie_tlv_builder *builder,
}
unsigned char *ie_tlv_builder_finalize(struct ie_tlv_builder *builder,
- unsigned int *out_len)
+ size_t *out_len)
{
unsigned int len = 0;
@@ -2083,3 +2083,23 @@ int ie_build_hs20_indication(uint8_t version, uint8_t *to)
return 0;
}
+
+bool ie_rsnxe_capable(const uint8_t *rsnxe, unsigned int bit)
+{
+ unsigned int field_len;
+
+ if (!rsnxe)
+ return false;
+
+ if (rsnxe[1] == 0)
+ return false;
+
+ field_len = bit_field(rsnxe[2], 0, 4);
+ if (field_len + 1 != rsnxe[1])
+ return false;
+
+ if ((bit / 8) > field_len)
+ return false;
+
+ return test_bit(rsnxe + 2, bit);
+}
diff --git a/src/ie.h b/src/ie.h
@@ -212,10 +212,44 @@ enum ie_type {
IE_TYPE_DEVICE_LOCATION = 204,
IE_TYPE_WHITE_SPACE_MAP = 205,
IE_TYPE_FINE_TIMING_MEASUREMENT_PARAMETERS = 206,
- /* Reserved 207 - 220 */
+ IE_TYPE_S1G_OPEN_LOOP_LINK_MARGIN_INDEX = 207,
+ IE_TYPE_RPS = 208,
+ IE_TYPE_PAGE_SLICE = 209,
+ IE_TYPE_AID_REQUEST = 210,
+ IE_TYPE_AID_RESPONSE = 211,
+ IE_TYPE_S1G_SECTOR_OPERATION = 212,
+ IE_TYPE_S1G_BEACON_COMPATIBILITY = 213,
+ IE_TYPE_SHORT_BEACON_INTERVAL = 214,
+ IE_TYPE_CHANGE_SEQUENCE = 215,
+ IE_TYPE_TWT = 216,
+ IE_TYPE_S1G_CAPABILITIES = 217,
+ /* Reserved 218 - 219 */
+ IE_TYPE_SUBCHANNEL_SELECTIVE_TRANSMISSION = 220,
IE_TYPE_VENDOR_SPECIFIC = 221,
- /* Reserved 222 - 254 */
+ IE_TYPE_AUTHENTICATION_CONTROL = 222,
+ IE_TYPE_TSF_TIMER_ACCURACY = 223,
+ IE_TYPE_S1G_RELAY = 224,
+ IE_TYPE_REACHABLE_ADDRESS = 225,
+ IE_TYPE_S1G_RELAY_DISCOVERY = 226,
+ /* Reserved 227 */
+ IE_TYPE_AID_ANNOUNCEMENT = 228,
+ IE_TYPE_PV1_PROBE_RESPONSE_OPTION = 229,
+ IE_TYPE_EL_OPERATION = 230,
+ IE_TYPE_SECTORIZED_GROUP_ID_LIST = 231,
+ IE_TYPE_S1G_OPERATION = 232,
+ IE_TYPE_HEADER_COMPRESSION = 233,
+ IE_TYPE_SST_OPERATION = 234,
+ IE_TYPE_MAD = 235,
+ IE_TYPE_S1G_RELAY_ACTIVATION = 236,
+ IE_TYPE_CAG_NUMBER = 237,
+ /* Reserved 238 */
+ IE_TYPE_AP_CSN = 239,
IE_TYPE_FILS_INDICATION = 240,
+ IE_TYPE_DILS = 241,
+ IE_TYPE_FRAGMENT = 242,
+ /* Reserved 243 */
+ IE_TYPE_RSNX = 244,
+ /* Reserved 245 - 254 */
IE_TYPE_EXTENSION = 255,
IE_TYPE_FILS_REQUEST_PARAMETERS = 256 + 2,
@@ -232,6 +266,10 @@ enum ie_type {
IE_TYPE_FILS_NONCE = 256 + 13,
IE_TYPE_FUTURE_CHANNEL_GUIDANCE = 256 + 14,
IE_TYPE_OWE_DH_PARAM = 256 + 32,
+ IE_TYPE_PASSWORD_IDENTIFIER = 256 + 33,
+ IE_TYPE_OCI = 256 + 54,
+ IE_TYPE_REJECTED_GROUPS = 256 + 92,
+ IE_TYPE_ANTI_CLOGGING_TOKEN_CONTAINER = 256 + 93,
};
/*
@@ -459,7 +497,7 @@ bool ie_tlv_builder_set_data(struct ie_tlv_builder *builder,
bool ie_tlv_builder_recurse(struct ie_tlv_builder *builder,
struct ie_tlv_builder *recurse);
unsigned char *ie_tlv_builder_finalize(struct ie_tlv_builder *builder,
- unsigned int *out_len);
+ size_t *out_len);
uint32_t ie_rsn_cipher_suite_to_cipher(enum ie_rsn_cipher_suite suite);
@@ -529,3 +567,10 @@ int ie_parse_hs20_indication_from_data(const uint8_t *data, size_t len,
uint8_t *version, uint16_t *pps_mo_id,
uint8_t *domain_id);
int ie_build_hs20_indication(uint8_t version, uint8_t *to);
+
+enum ie_rsnx_capability {
+ IE_RSNX_PROTECTED_TWT = 4,
+ IE_RSNX_SAE_H2E = 5,
+};
+
+bool ie_rsnxe_capable(const uint8_t *rsnxe, unsigned int bit);
diff --git a/src/iwd.network.rst b/src/iwd.network.rst
@@ -143,6 +143,37 @@ The group ``[Settings]`` contains general settings.
iwd.config. This setting should not be used with
[Settings].AlwaysRandomizeAddress, if both are set AddressOverride will
be used.
+ * - TransitionDisable
+ - Values: true, **false**
+
+ If enabled, the use of TKIP pairwise cipher and connections without
+ Management Frame Protection are disallowed. This will make certain
+ legacy access points unavailable for use. Additional security hardening
+ can also be applied via the [Settings].DisabledTransitionModes setting.
+
+ Properly configured Access Points will typically update this setting
+ appropriately via Transition Disable indications. User customization
+ of this value is thus typically not required.
+ * - DisabledTransitionModes
+ - Comma-separated list of disabled transition modes:
+
+ * personal
+ * enterprise
+ * open
+
+ If 'personal' mode is disabled, then legacy WPA2-Personal access points
+ are no longer available to be connected to or roamed to. Only access
+ points utilizing WPA3-Personal will be considered.
+
+ If 'enterprise' mode is disabled, then legacy WPA2-Enterprise access
+ points are no longer available to be connected to or roamed to.
+
+ If 'open' mode is disabled, then non-OWE enabled access points will
+ not be connected to.
+
+ Properly configured Access Points will typically update this setting
+ appropriately via Transition Disable indications. User customization
+ of this value is thus typically not required.
Network Authentication Settings
-------------------------------
@@ -322,6 +353,12 @@ network configuration with the static addresses.
`optional`. DomainName setting can be used to override the DomainName
value obtained from the DHCP server.
+ * - SendHostname
+ - Values: true, **false**
+
+ Configures DHCP to include the hostname in the request. This setting
+ is disabled by default.
+
The group ``[IPv6]`` contains settings for Internet Protocol version 6 (IPv6)
network configuration.
diff --git a/src/iwd.service.in b/src/iwd.service.in
@@ -11,7 +11,7 @@ ExecStart=@libexecdir@/iwd
NotifyAccess=main
LimitNPROC=1
Restart=on-failure
-CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW
+CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE
PrivateTmp=true
NoNewPrivileges=true
DevicePolicy=closed
diff --git a/src/knownnetworks.c b/src/knownnetworks.c
@@ -52,6 +52,93 @@ static struct l_dir_watch *storage_dir_watch;
static struct watchlist known_network_watches;
static struct l_settings *known_freqs;
+void __network_config_parse(const struct l_settings *settings,
+ const char *full_path,
+ struct network_config *config)
+{
+ bool b;
+ const char *value;
+ uint8_t new_addr[6];
+
+ memset(config, 0, sizeof(struct network_config));
+
+ config->connected_time = l_path_get_mtime(full_path);
+
+ /* If no entry, default to AutoConnectable=True */
+ if (!l_settings_get_bool(settings, NET_AUTOCONNECT, &b))
+ b = true;
+
+ config->is_autoconnectable = b;
+
+ if (!l_settings_get_bool(settings, NET_HIDDEN, &b))
+ b = false;
+
+ config->is_hidden = b;
+
+ if (!l_settings_get_bool(settings, NET_ALWAYS_RANDOMIZE_ADDRESS, &b))
+ b = false;
+
+ config->always_random_addr = b;
+
+ value = l_settings_get_value(settings, NET_ADDRESS_OVERRIDE);
+ if (value) {
+ if (util_string_to_address(value, new_addr) &&
+ util_is_valid_sta_address(new_addr)) {
+ config->override_addr = true;
+ memcpy(config->sta_addr, new_addr, sizeof(new_addr));
+ } else
+ l_warn("[%s].%s is not a valid MAC address",
+ NET_ADDRESS_OVERRIDE);
+ }
+
+ if (config->override_addr && config->always_random_addr) {
+ l_warn("Cannot use both [%s].%s and [%s].%s, using latter",
+ NET_ALWAYS_RANDOMIZE_ADDRESS,
+ NET_ADDRESS_OVERRIDE);
+ config->always_random_addr = false;
+ }
+
+ if (!l_settings_get_bool(settings, NET_TRANSITION_DISABLE, &b))
+ b = false;
+
+ config->have_transition_disable = b;
+ if (config->have_transition_disable) {
+ unsigned int i;
+ char **modes = l_settings_get_string_list(settings,
+ NET_TRANSITION_DISABLE_MODES, ' ');
+
+ for (i = 0; modes && modes[i]; i++) {
+ if (!strcmp(modes[i], "personal"))
+ set_bit(&config->transition_disable, 0);
+ else if (!strcmp(modes[i], "enterprise"))
+ set_bit(&config->transition_disable, 2);
+ else if (!strcmp(modes[i], "open"))
+ set_bit(&config->transition_disable, 3);
+ else
+ l_warn("[%s].%s: Unrecognized value: %s",
+ NET_TRANSITION_DISABLE_MODES,
+ modes[i]);
+ }
+
+ l_strfreev(modes);
+ }
+}
+
+void __network_info_init(struct network_info *info,
+ const char *ssid, enum security security,
+ struct network_config *config)
+{
+ if (ssid)
+ strcpy(info->ssid, ssid);
+
+ info->type = security;
+
+ memcpy(&info->config, config, sizeof(struct network_config));
+
+ if (info->config.is_hidden)
+ num_known_hidden_networks++;
+}
+
static void network_info_free(void *data)
{
struct network_info *network = data;
@@ -65,10 +152,12 @@ static int connected_time_compare(const void *a, const void *b, void *user_data)
{
const struct network_info *ni_a = a;
const struct network_info *ni_b = b;
+ uint64_t ta = ni_a->config.connected_time;
+ uint64_t tb = ni_b->config.connected_time;
- if (l_time_after(ni_a->connected_time, ni_b->connected_time))
+ if (l_time_after(ta, tb))
return -1;
- else if (l_time_before(ni_a->connected_time, ni_b->connected_time))
+ else if (l_time_before(ta, tb))
return 1;
return 0;
@@ -138,10 +227,10 @@ static void known_network_register_dbus(struct network_info *network)
static void known_network_set_autoconnect(struct network_info *network,
bool autoconnect)
{
- if (network->is_autoconnectable == autoconnect)
+ if (network->config.is_autoconnectable == autoconnect)
return;
- network->is_autoconnectable = autoconnect;
+ network->config.is_autoconnectable = autoconnect;
#ifdef HAVE_DBUS
l_dbus_property_changed(dbus_get_bus(), known_network_get_path(network),
@@ -261,7 +350,7 @@ const uint8_t *network_info_get_uuid(struct network_info *info)
* been forgotten.
*/
to_hash = l_strdup_printf("%s_%" PRIu64, file_path,
- info->connected_time);
+ info->config.connected_time);
l_uuid_v5(nsid, to_hash, strlen(to_hash), info->uuid);
l_free(to_hash);
l_free(file_path);
@@ -341,10 +430,10 @@ bool network_info_match_nai_realm(const struct network_info *info,
void known_network_set_connected_time(struct network_info *network,
uint64_t connected_time)
{
- if (network->connected_time == connected_time)
+ if (network->config.connected_time == connected_time)
return;
- network->connected_time = connected_time;
+ network->config.connected_time = connected_time;
#ifdef HAVE_DBUS
l_dbus_property_changed(dbus_get_bus(),
@@ -358,18 +447,16 @@ void known_network_set_connected_time(struct network_info *network,
}
void known_network_update(struct network_info *network,
- struct l_settings *settings)
+ struct network_config *new)
{
- bool is_hidden;
- bool is_autoconnectable;
+ struct network_config *old = &network->config;
- if (!l_settings_get_bool(settings, "Settings", "Hidden", &is_hidden))
- is_hidden = false;
+ known_network_set_connected_time(network, new->connected_time);
- if (network->is_hidden != is_hidden) {
- if (network->is_hidden && !is_hidden)
+ if (old->is_hidden != new->is_hidden) {
+ if (old->is_hidden && !new->is_hidden)
num_known_hidden_networks--;
- else if (!network->is_hidden && is_hidden)
+ else if (!old->is_hidden && new->is_hidden)
num_known_hidden_networks++;
#ifdef HAVE_DBUS
@@ -378,16 +465,13 @@ void known_network_update(struct network_info *network,
IWD_KNOWN_NETWORK_INTERFACE,
"Hidden");
#endif
- }
- network->is_hidden = is_hidden;
+ old->is_hidden = new->is_hidden;
+ }
- /* If no entry, default to AutoConnectable=True */
- if (!l_settings_get_bool(settings, "Settings", "AutoConnect",
- &is_autoconnectable))
- is_autoconnectable = true;
+ known_network_set_autoconnect(network, new->is_autoconnectable);
- known_network_set_autoconnect(network, is_autoconnectable);
+ memcpy(&network->config, new, sizeof(struct network_config));
}
bool known_networks_foreach(known_networks_foreach_func_t function,
@@ -549,7 +633,7 @@ static bool known_network_property_get_hidden(struct l_dbus *dbus,
void *user_data)
{
struct network_info *network = user_data;
- bool is_hidden = network->is_hidden;
+ bool is_hidden = network->config.is_hidden;
l_dbus_message_builder_append_basic(builder, 'b', &is_hidden);
@@ -562,7 +646,7 @@ static bool known_network_property_get_autoconnect(struct l_dbus *dbus,
void *user_data)
{
struct network_info *network = user_data;
- bool autoconnect = network->is_autoconnectable;
+ bool autoconnect = network->config.is_autoconnectable;
l_dbus_message_builder_append_basic(builder, 'b', &autoconnect);
@@ -583,14 +667,14 @@ static struct l_dbus_message *known_network_property_set_autoconnect(
if (!l_dbus_message_iter_get_variant(new_value, "b", &autoconnect))
return dbus_error_invalid_args(message);
- if (network->is_autoconnectable == autoconnect)
+ if (network->config.is_autoconnectable == autoconnect)
return l_dbus_message_new_method_return(message);
settings = network->ops->open(network);
if (!settings)
return dbus_error_failed(message);
- l_settings_set_bool(settings, "Settings", "AutoConnect", autoconnect);
+ l_settings_set_bool(settings, NET_AUTOCONNECT, autoconnect);
network->ops->sync(network, settings);
l_settings_free(settings);
@@ -606,9 +690,9 @@ static bool known_network_property_get_last_connected(struct l_dbus *dbus,
struct network_info *network = user_data;
char datestr[64];
struct tm tm;
- time_t seconds = l_time_to_secs(network->connected_time);
+ time_t seconds = l_time_to_secs(network->config.connected_time);
- if (network->connected_time == 0)
+ if (seconds == 0)
return false;
gmtime_r(&seconds, &tm);
@@ -643,7 +727,7 @@ static void setup_known_network_interface(struct l_dbus_interface *interface)
void known_networks_remove(struct network_info *network)
{
- if (network->is_hidden)
+ if (network->config.is_hidden)
num_known_hidden_networks--;
l_queue_remove(known_networks, network);
@@ -680,33 +764,13 @@ void known_networks_add(struct network_info *network)
}
static void known_network_new(const char *ssid, enum security security,
- struct l_settings *settings,
- uint64_t connected_time)
+ struct network_config *config)
{
- bool is_hidden;
- bool is_autoconnectable;
struct network_info *network;
network = l_new(struct network_info, 1);
- strcpy(network->ssid, ssid);
- network->type = security;
- network->connected_time = connected_time;
+ __network_info_init(network, ssid, security, config);
network->ops = &known_network_ops;
-
- if (!l_settings_get_bool(settings, "Settings", "Hidden",
- &is_hidden))
- is_hidden = false;
-
- if (!l_settings_get_bool(settings, "Settings", "AutoConnect",
- &is_autoconnectable))
- is_autoconnectable = true;
-
- if (is_hidden)
- num_known_hidden_networks++;
-
- network->is_hidden = is_hidden;
- network->is_autoconnectable = is_autoconnectable;
-
known_networks_add(network);
}
@@ -751,15 +815,14 @@ static void known_networks_watch_cb(const char *filename,
settings = storage_network_open(security, ssid);
if (settings) {
- connected_time = l_path_get_mtime(full_path);
+ struct network_config config;
- if (network_before) {
- known_network_set_connected_time(network_before,
- connected_time);
- known_network_update(network_before, settings);
- } else
- known_network_new(ssid, security, settings,
- connected_time);
+ __network_config_parse(settings, full_path, &config);
+
+ if (network_before)
+ known_network_update(network_before, &config);
+ else
+ known_network_new(ssid, security, &config);
} else if (network_before)
known_networks_remove(network_before);
@@ -1022,7 +1085,6 @@ static int known_networks_init(void)
const char *ssid;
enum security security;
struct l_settings *settings;
- uint64_t connected_time;
L_AUTO_FREE_VAR(char *, full_path) = NULL;
if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
@@ -1038,10 +1100,10 @@ static int known_networks_init(void)
full_path = storage_get_network_file_path(security, ssid);
if (settings) {
- connected_time = l_path_get_mtime(full_path);
+ struct network_config config;
- known_network_new(ssid, security, settings,
- connected_time);
+ __network_config_parse(settings, full_path, &config);
+ known_network_new(ssid, security, &config);
}
l_settings_free(settings);
diff --git a/src/knownnetworks.h b/src/knownnetworks.h
@@ -20,6 +20,14 @@
*
*/
+#define SETTINGS "Settings"
+#define NET_HIDDEN SETTINGS, "Hidden"
+#define NET_AUTOCONNECT SETTINGS, "AutoConnect"
+#define NET_ALWAYS_RANDOMIZE_ADDRESS SETTINGS, "AlwaysRandomizeAddress"
+#define NET_ADDRESS_OVERRIDE SETTINGS, "AddressOverride"
+#define NET_TRANSITION_DISABLE SETTINGS, "TransitionDisable"
+#define NET_TRANSITION_DISABLE_MODES SETTINGS, "DisabledTransitionModes"
+
enum security;
struct scan_freq_set;
struct network_info;
@@ -54,18 +62,27 @@ struct network_info_ops {
const char **nai_realms);
};
+struct network_config {
+ uint64_t connected_time; /* Time last connected */
+ bool is_hidden:1;
+ bool is_autoconnectable:1;
+ bool override_addr:1;
+ bool always_random_addr:1;
+ uint8_t sta_addr[6];
+ bool have_transition_disable : 1;
+ uint8_t transition_disable;
+};
+
struct network_info {
const struct network_info_ops *ops;
char ssid[33];
enum security type;
struct l_queue *known_frequencies;
- uint64_t connected_time; /* Time last connected */
int seen_count; /* Ref count for network.info */
uint8_t uuid[16];
- bool is_hidden:1;
- bool is_autoconnectable:1;
bool is_hotspot:1;
bool has_uuid:1;
+ struct network_config config;
};
typedef bool (*known_networks_foreach_func_t)(const struct network_info *info,
@@ -80,6 +97,13 @@ struct known_frequency {
uint32_t frequency;
};
+void __network_config_parse(const struct l_settings *settings,
+ const char *path,
+ struct network_config *config);
+void __network_info_init(struct network_info *info,
+ const char *ssid, enum security security,
+ struct network_config *config);
+
int known_network_offset(const struct network_info *target);
bool known_networks_foreach(known_networks_foreach_func_t function,
void *user_data);
@@ -125,7 +149,7 @@ bool network_info_match_nai_realm(const struct network_info *info,
void known_networks_add(struct network_info *info);
void known_network_update(struct network_info *info,
- struct l_settings *settings);
+ struct network_config *new_config);
void known_network_set_connected_time(struct network_info *network,
uint64_t connected_time);
void known_networks_remove(struct network_info *info);
diff --git a/src/mpdu.h b/src/mpdu.h
@@ -124,9 +124,10 @@ enum mmpdu_reason_code {
};
/*
- * 802.11-2016, Section 9.4.1.9 Status Code field
+ * 802.11-2020, Section 9.4.1.9 Status Code field
*/
enum mmpdu_status_code {
+ MMPDU_STATUS_CODE_SUCCESS = 0,
MMPDU_STATUS_CODE_UNSPECIFIED = 1,
MMPDU_STATUS_CODE_TDLS_REJECTED_ALT_PROV = 2,
MMPDU_STATUS_CODE_TDLS_REJECTED = 3,
@@ -230,6 +231,7 @@ enum mmpdu_status_code {
MMPDU_STATUS_CODE_ENABLEMENT_DENIED = 105,
MMPDU_STATUS_CODE_RESTRICT_AUTH_GDB = 106,
MMPDU_STATUS_CODE_AUTHORIZATION_DEENABLED = 107,
+ MMPDU_STATUS_CODE_SAE_HASH_TO_ELEMENT = 126,
};
/* 802.11, Section 8.2.4.1.1, Figure 8-2 */
diff --git a/src/netconfig.c b/src/netconfig.c
@@ -1004,6 +1004,8 @@ bool netconfig_configure(struct netconfig *netconfig,
netconfig_notify_func_t notify, void *user_data)
{
char *mdns;
+ char hostname[HOST_NAME_MAX + 1];
+ bool send_hostname;
netconfig->dns4_overrides = l_settings_get_string_list(active_settings,
"IPv4", "DNS", ' ');
@@ -1044,6 +1046,20 @@ bool netconfig_configure(struct netconfig *netconfig,
l_dhcp6_client_set_address(netconfig->dhcp6_client, ARPHRD_ETHER,
mac_address, ETH_ALEN);
+ if (!l_settings_get_bool(active_settings,
+ "IPv4", "SendHostname", &send_hostname))
+ send_hostname = false;
+
+ if (send_hostname) {
+ if (gethostname(hostname, sizeof(hostname)) == 0) {
+ l_dhcp_client_set_hostname(
+ netconfig->dhcp_client, hostname);
+ } else {
+ l_warn("netconfig: Unable to get hostname. "
+ "Error %d: %s", errno, strerror(errno));
+ }
+ }
+
netconfig_ipv4_select_and_install(netconfig);
netconfig_ipv6_select_and_install(netconfig);
diff --git a/src/netdev.c b/src/netdev.c
@@ -39,6 +39,8 @@
#include <ell/ell.h>
+#include "ell/useful.h"
+
#include "linux/nl80211.h"
#include "src/iwd.h"
@@ -117,7 +119,6 @@ struct netdev {
netdev_command_cb_t adhoc_cb;
void *user_data;
struct eapol_sm *sm;
- struct sae_sm *sae_sm;
struct auth_proto *ap;
struct handshake_state *handshake;
uint32_t connect_cmd_id;
@@ -202,6 +203,22 @@ static struct watchlist netdev_watches;
static bool pae_over_nl80211;
static bool mac_per_ssid;
+static unsigned int iov_ie_append(struct iovec *iov,
+ unsigned int n_iov, unsigned int c,
+ const uint8_t *ie)
+{
+ if (L_WARN_ON(c >= n_iov))
+ return n_iov;
+
+ if (!ie)
+ return c;
+
+ iov[c].iov_base = (void *) ie;
+ iov[c].iov_len = ie[1] + 2;
+
+ return c + 1u;
+}
+
const char *netdev_iftype_to_string(uint32_t iftype)
{
switch (iftype) {
@@ -1989,6 +2006,7 @@ static void parse_request_ies(struct netdev *netdev, const uint8_t *ies,
{
struct ie_tlv_iter iter;
const void *data;
+ const uint8_t *rsnxe = NULL;
/*
* The driver may have modified the IEs we passed to CMD_CONNECT
@@ -2005,6 +2023,10 @@ static void parse_request_ies(struct netdev *netdev, const uint8_t *ies,
handshake_state_set_supplicant_ie(netdev->handshake,
data - 2);
break;
+ case IE_TYPE_RSNX:
+ if (!rsnxe)
+ rsnxe = data - 2;
+ break;
case IE_TYPE_VENDOR_SPECIFIC:
if (!is_ie_wpa_ie(data, ie_tlv_iter_get_length(&iter)))
break;
@@ -2017,6 +2039,9 @@ static void parse_request_ies(struct netdev *netdev, const uint8_t *ies,
break;
}
}
+
+ /* RSNXE element might be omitted when FTing */
+ handshake_state_set_supplicant_rsnxe(netdev->handshake, rsnxe);
}
static void netdev_driver_connected(struct netdev *netdev)
@@ -2393,10 +2418,19 @@ static void netdev_authenticate_event(struct l_genl_msg *msg,
}
}
- if (!frame)
+ if (L_WARN_ON(!frame))
goto auth_error;
if (netdev->ap) {
+ const struct mmpdu_header *hdr;
+ const struct mmpdu_authentication *auth;
+
+ if (L_WARN_ON(!(hdr = mpdu_validate(frame, frame_len))))
+ goto auth_error;
+
+ auth = mmpdu_body(hdr);
+ status_code = L_CPU_TO_LE16(auth->status);
+
ret = auth_proto_rx_authenticate(netdev->ap, frame, frame_len);
if (ret == 0 || ret == -EAGAIN)
return;
@@ -2461,10 +2495,19 @@ static void netdev_associate_event(struct l_genl_msg *msg,
}
}
- if (!frame)
+ if (L_WARN_ON(!frame))
goto assoc_failed;
if (netdev->ap) {
+ const struct mmpdu_header *hdr;
+ const struct mmpdu_association_response *assoc;
+
+ if (L_WARN_ON(!(hdr = mpdu_validate(frame, frame_len))))
+ goto assoc_failed;
+
+ assoc = mmpdu_body(hdr);
+ status_code = L_CPU_TO_LE16(assoc->status_code);
+
ret = auth_proto_rx_associate(netdev->ap, frame, frame_len);
if (ret == 0) {
bool fils = !!(netdev->handshake->akm_suite &
@@ -2659,23 +2702,19 @@ static void netdev_sae_tx_authenticate(const uint8_t *body,
static void netdev_sae_tx_associate(void *user_data)
{
struct netdev *netdev = user_data;
+ struct handshake_state *hs = netdev->handshake;
struct l_genl_msg *msg;
- struct iovec iov[2];
- int iov_elems = 0;
+ struct iovec iov[3];
+ unsigned int n_iov = L_ARRAY_SIZE(iov);
+ unsigned int n_used = 0;
msg = netdev_build_cmd_associate_common(netdev);
- iov[iov_elems].iov_base = netdev->handshake->supplicant_ie;
- iov[iov_elems].iov_len = netdev->handshake->supplicant_ie[1] + 2;
- iov_elems++;
+ n_used = iov_ie_append(iov, n_iov, n_used, hs->supplicant_ie);
+ n_used = iov_ie_append(iov, n_iov, n_used, hs->mde);
+ n_used = iov_ie_append(iov, n_iov, n_used, hs->supplicant_rsnxe);
- if (netdev->handshake->mde) {
- iov[iov_elems].iov_base = netdev->handshake->mde;
- iov[iov_elems].iov_len = netdev->handshake->mde[1] + 2;
- iov_elems++;
- }
-
- l_genl_msg_append_attrv(msg, NL80211_ATTR_IE, iov, iov_elems);
+ l_genl_msg_append_attrv(msg, NL80211_ATTR_IE, iov, n_used);
if (!l_genl_family_send(nl80211, msg, netdev_assoc_cb, netdev, NULL)) {
l_genl_msg_unref(msg);
@@ -3122,6 +3161,100 @@ static int netdev_start_powered_mac_change(struct netdev *netdev)
return 0;
}
+static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
+ struct netdev *netdev,
+ const int8_t *levels,
+ size_t levels_num)
+{
+ struct l_genl_msg *msg;
+ uint32_t hyst = 5;
+ int thold_count;
+ int32_t thold_list[levels_num + 2];
+ int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
+ LOW_SIGNAL_THRESHOLD;
+
+ if (levels_num == 0) {
+ thold_list[0] = threshold;
+ thold_count = 1;
+ } else {
+ /*
+ * Build the list of all the threshold values we care about:
+ * - the low/high level threshold,
+ * - the value ranges requested by
+ * netdev_set_rssi_report_levels
+ */
+ unsigned int i;
+ bool low_sig_added = false;
+
+ thold_count = 0;
+ for (i = 0; i < levels_num; i++) {
+ int32_t val = levels[levels_num - i - 1];
+
+ if (i && thold_list[thold_count - 1] >= val)
+ return NULL;
+
+ if (val >= threshold && !low_sig_added) {
+ thold_list[thold_count++] = threshold;
+ low_sig_added = true;
+
+ /* Duplicate values are not allowed */
+ if (val == threshold)
+ continue;
+ }
+
+ thold_list[thold_count++] = val;
+ }
+ }
+
+ msg = l_genl_msg_new_sized(NL80211_CMD_SET_CQM, 32 + thold_count * 4);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
+ l_genl_msg_enter_nested(msg, NL80211_ATTR_CQM);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_CQM_RSSI_THOLD,
+ thold_count * 4, thold_list);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_CQM_RSSI_HYST, 4, &hyst);
+ l_genl_msg_leave_nested(msg);
+
+ return msg;
+}
+
+static void netdev_cmd_set_cqm_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_SET_CQM failed: %s",
+ ext_error ? ext_error : strerror(-err));
+}
+
+static int netdev_cqm_rssi_update(struct netdev *netdev)
+{
+ struct l_genl_msg *msg;
+
+ l_debug("");
+
+ if (!wiphy_has_ext_feature(netdev->wiphy,
+ NL80211_EXT_FEATURE_CQM_RSSI_LIST))
+ msg = netdev_build_cmd_cqm_rssi_update(netdev, NULL, 0);
+ else
+ msg = netdev_build_cmd_cqm_rssi_update(netdev,
+ netdev->rssi_levels,
+ netdev->rssi_levels_num);
+ if (!msg)
+ return -EINVAL;
+
+ if (!l_genl_family_send(nl80211, msg, netdev_cmd_set_cqm_cb,
+ NULL, NULL)) {
+ l_genl_msg_unref(msg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
static bool netdev_connection_work_ready(struct wiphy_radio_work_item *item)
{
struct netdev *netdev = l_container_of(item, struct netdev, work);
@@ -3270,6 +3403,7 @@ static int netdev_connect_common(struct netdev *netdev,
netdev->frequency = bss->frequency;
netdev->cur_rssi = bss->signal_strength / 100;
netdev_rssi_level_init(netdev);
+ netdev_cqm_rssi_update(netdev);
handshake_state_set_authenticator_address(hs, bss->addr);
@@ -3322,6 +3456,18 @@ int netdev_connect(struct netdev *netdev, struct scan_bss *bss,
netdev->ap = sae_sm_new(hs, netdev_sae_tx_authenticate,
netdev_sae_tx_associate,
netdev);
+
+ if (sae_sm_is_h2e(netdev->ap)) {
+ uint8_t own_rsnxe[20];
+
+ if (wiphy_get_rsnxe(netdev->wiphy,
+ own_rsnxe, sizeof(own_rsnxe))) {
+ set_bit(own_rsnxe + 2, IE_RSNX_SAE_H2E);
+ handshake_state_set_supplicant_rsnxe(hs,
+ own_rsnxe);
+ }
+ }
+
break;
case IE_RSN_AKM_SUITE_OWE:
netdev->ap = owe_sm_new(hs, netdev_owe_tx_authenticate,
@@ -3341,9 +3487,6 @@ build_cmd_connect:
cmd_connect = netdev_build_cmd_connect(netdev, bss, hs,
NULL, vendor_ies, num_vendor_ies);
- if (!cmd_connect)
- return -EINVAL;
-
if (!is_offload(hs) && (is_rsn || hs->settings_8021x)) {
sm = eapol_sm_new(hs);
@@ -3458,8 +3601,6 @@ int netdev_reassociate(struct netdev *netdev, struct scan_bss *target_bss,
cmd_connect = netdev_build_cmd_connect(netdev, target_bss, hs,
orig_bss->addr, NULL, 0);
- if (!cmd_connect)
- return -EINVAL;
if (is_rsn)
sm = eapol_sm_new(hs);
@@ -3655,9 +3796,6 @@ static void netdev_ft_tx_authenticate(struct iovec *iov,
cmd_authenticate = netdev_build_cmd_authenticate(netdev,
NL80211_AUTHTYPE_FT);
- if (!cmd_authenticate)
- goto restore_snonce;
-
l_genl_msg_append_attrv(cmd_authenticate, NL80211_ATTR_IE, iov,
iov_len);
@@ -3761,6 +3899,7 @@ static void prepare_ft(struct netdev *netdev, struct scan_bss *target_bss)
}
netdev_rssi_polling_update(netdev);
+ netdev_cqm_rssi_update(netdev);
if (netdev->sm) {
eapol_sm_free(netdev->sm);
@@ -4861,75 +5000,6 @@ static void netdev_unicast_notify(struct l_genl_msg *msg, void *user_data)
}
}
-static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
- struct netdev *netdev,
- const int8_t *levels,
- size_t levels_num)
-{
- struct l_genl_msg *msg;
- uint32_t hyst = 5;
- int thold_count;
- int32_t thold_list[levels_num + 2];
- int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
- LOW_SIGNAL_THRESHOLD;
-
- if (levels_num == 0) {
- thold_list[0] = threshold;
- thold_count = 1;
- } else {
- /*
- * Build the list of all the threshold values we care about:
- * - the low/high level threshold,
- * - the value ranges requested by
- * netdev_set_rssi_report_levels
- */
- unsigned int i;
- bool low_sig_added = false;
-
- thold_count = 0;
- for (i = 0; i < levels_num; i++) {
- int32_t val = levels[levels_num - i - 1];
-
- if (i && thold_list[thold_count - 1] >= val)
- return NULL;
-
- if (val >= threshold && !low_sig_added) {
- thold_list[thold_count++] = threshold;
- low_sig_added = true;
-
- /* Duplicate values are not allowed */
- if (val == threshold)
- continue;
- }
-
- thold_list[thold_count++] = val;
- }
- }
-
- msg = l_genl_msg_new_sized(NL80211_CMD_SET_CQM, 32 + thold_count * 4);
- l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
- l_genl_msg_enter_nested(msg, NL80211_ATTR_CQM);
- l_genl_msg_append_attr(msg, NL80211_ATTR_CQM_RSSI_THOLD,
- thold_count * 4, thold_list);
- l_genl_msg_append_attr(msg, NL80211_ATTR_CQM_RSSI_HYST, 4, &hyst);
- l_genl_msg_leave_nested(msg);
-
- return msg;
-}
-
-static void netdev_cmd_set_cqm_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_SET_CQM failed: %s",
- ext_error ? ext_error : strerror(-err));
-}
-
int netdev_set_rssi_report_levels(struct netdev *netdev, const int8_t *levels,
size_t levels_num)
{
@@ -5088,31 +5158,6 @@ int netdev_get_all_stations(struct netdev *netdev, netdev_get_station_cb_t cb,
return 0;
}
-static int netdev_cqm_rssi_update(struct netdev *netdev)
-{
- struct l_genl_msg *msg;
-
- l_debug("");
-
- if (!wiphy_has_ext_feature(netdev->wiphy,
- NL80211_EXT_FEATURE_CQM_RSSI_LIST))
- msg = netdev_build_cmd_cqm_rssi_update(netdev, NULL, 0);
- else
- msg = netdev_build_cmd_cqm_rssi_update(netdev,
- netdev->rssi_levels,
- netdev->rssi_levels_num);
- if (!msg)
- return -EINVAL;
-
- if (!l_genl_family_send(nl80211, msg, netdev_cmd_set_cqm_cb,
- NULL, NULL)) {
- l_genl_msg_unref(msg);
- return -EIO;
- }
-
- return 0;
-}
-
static void netdev_add_station_frame_watches(struct netdev *netdev)
{
static const uint8_t action_neighbor_report_prefix[2] = { 0x05, 0x05 };
@@ -5149,8 +5194,6 @@ static void netdev_setup_interface(struct netdev *netdev)
{
switch (netdev->type) {
case NL80211_IFTYPE_STATION:
- /* Set RSSI threshold for CQM notifications */
- netdev_cqm_rssi_update(netdev);
netdev_add_station_frame_watches(netdev);
break;
default:
diff --git a/src/network.c b/src/network.c
@@ -29,6 +29,7 @@
#include <errno.h>
#include <limits.h>
#include <alloca.h>
+#include <linux/if_ether.h>
#include <ell/ell.h>
@@ -53,6 +54,9 @@
#include "src/blacklist.h"
#include "src/util.h"
#include "src/erp.h"
+#include "src/handshake.h"
+
+#define SAE_PT_SETTING "SAE-PT-Group%u"
static uint32_t known_networks_watch;
static uint32_t anqp_watch;
@@ -65,6 +69,8 @@ struct network {
struct network_info *info;
unsigned char *psk;
char *passphrase;
+ struct l_ecc_point *sae_pt_19; /* SAE PT for Group 19 */
+ struct l_ecc_point *sae_pt_20; /* SAE PT for Group 20 */
unsigned int agent_request;
struct l_queue *bss_list;
struct l_settings *settings;
@@ -73,10 +79,12 @@ struct network {
uint8_t hessid[6];
char **nai_realms;
uint8_t *rc_ie;
- bool update_psk:1; /* Whether PSK should be written to storage */
+ bool sync_settings:1; /* should settings be synced on connect? */
bool ask_passphrase:1; /* Whether we should force-ask agent */
bool is_hs20:1;
bool anqp_pending:1; /* Set if there is a pending ANQP request */
+ uint8_t transition_disable; /* Temporary cache until info is set */
+ bool have_transition_disable:1;
int rank;
/* Holds DBus Connect() message if it comes in before ANQP finishes */
struct l_dbus_message *connect_after_anqp;
@@ -104,12 +112,22 @@ static void network_reset_psk(struct network *network)
static void network_reset_passphrase(struct network *network)
{
- if (network->passphrase)
+ if (network->passphrase) {
explicit_bzero(network->passphrase,
strlen(network->passphrase));
+ l_free(network->passphrase);
+ network->passphrase = NULL;
+ }
- l_free(network->passphrase);
- network->passphrase = NULL;
+ if (network->sae_pt_19) {
+ l_ecc_point_free(network->sae_pt_19);
+ network->sae_pt_19 = NULL;
+ }
+
+ if (network->sae_pt_20) {
+ l_ecc_point_free(network->sae_pt_20);
+ network->sae_pt_20 = NULL;
+ }
}
static void network_settings_close(struct network *network)
@@ -198,6 +216,7 @@ static const double rankmod_table[] = {
bool network_rankmod(const struct network *network, double *rankmod)
{
+ struct network_info *info = network->info;
int n;
int nmax;
@@ -206,7 +225,7 @@ bool network_rankmod(const struct network *network, double *rankmod)
* to at least once are autoconnectable. Known Networks that
* we have never connected to are not.
*/
- if (!network->info || !network->info->connected_time)
+ if (!info || !info->config.connected_time)
return false;
n = known_network_offset(network->info);
@@ -258,49 +277,69 @@ enum security network_get_security(const struct network *network)
return network->security;
}
-const uint8_t *network_get_psk(struct network *network)
+static const uint8_t *network_get_psk(struct network *network)
{
+ int r;
+
if (network->psk)
return network->psk;
network->psk = l_malloc(32);
- if (crypto_psk_from_passphrase(network->passphrase,
+ if ((r = crypto_psk_from_passphrase(network->passphrase,
(unsigned char *)network->ssid,
strlen(network->ssid),
- network->psk) < 0) {
+ network->psk)) < 0) {
l_free(network->psk);
network->psk = NULL;
- }
+ l_error("PSK generation failed: %s.", strerror(-r));
+ } else
+ network->sync_settings = true;
return network->psk;
}
-const char *network_get_passphrase(const struct network *network)
+static struct l_ecc_point *network_generate_sae_pt(struct network *network,
+ unsigned int group)
{
- return network->passphrase;
+ struct l_ecc_point *pt;
+
+ l_debug("Generating PT for Group %u", group);
+
+ pt = crypto_derive_sae_pt_ecc(group, network->ssid,
+ network->passphrase, NULL);
+ if (!pt)
+ l_warn("SAE PT generation for Group %u failed", group);
+
+ return pt;
}
-bool network_set_passphrase(struct network *network, const char *passphrase)
+static bool __network_set_passphrase(struct network *network,
+ const char *passphrase)
{
- if (network_get_security(network) != SECURITY_PSK)
- return false;
-
- if (!crypto_passphrase_is_valid(passphrase))
+ if (!passphrase || !crypto_passphrase_is_valid(passphrase))
return false;
- if (!network_settings_load(network))
- network->settings = l_settings_new();
-
network_reset_passphrase(network);
network->passphrase = l_strdup(passphrase);
+ network->sae_pt_19 = network_generate_sae_pt(network, 19);
+ network->sae_pt_20 = network_generate_sae_pt(network, 20);
+
+ network->sync_settings = true;
+
return true;
}
-struct l_queue *network_get_secrets(const struct network *network)
+bool network_set_passphrase(struct network *network, const char *passphrase)
{
- return network->secrets;
+ if (network_get_security(network) != SECURITY_PSK)
+ return false;
+
+ if (!network_settings_load(network))
+ network->settings = l_settings_new();
+
+ return __network_set_passphrase(network, passphrase);
}
bool network_set_psk(struct network *network, const uint8_t *psk)
@@ -316,6 +355,29 @@ bool network_set_psk(struct network *network, const uint8_t *psk)
return true;
}
+int network_set_transition_disable(struct network *network,
+ const uint8_t *td, size_t len)
+{
+ struct network_info *info = network->info;
+ /* We only recognize bits 0, 2, 3 */
+ uint8_t supported_bitmask = 0x0d;
+
+ if (len < 1)
+ return -EBADMSG;
+
+ network->have_transition_disable = true;
+ network->transition_disable = td[0] & supported_bitmask;
+
+ if (info && info->config.have_transition_disable &&
+ info->config.transition_disable ==
+ network->transition_disable)
+ return 0;
+
+ network->sync_settings = true;
+
+ return 0;
+}
+
int network_get_signal_strength(const struct network *network)
{
struct scan_bss *best_bss = l_queue_peek_head(network->bss_list);
@@ -375,19 +437,148 @@ static bool network_set_8021x_secrets(struct network *network)
return true;
}
+static int network_set_handshake_secrets_psk(struct network *network,
+ struct handshake_state *hs)
+{
+ /* SAE will generate/set the PMK */
+ if (IE_AKM_IS_SAE(hs->akm_suite)) {
+ if (!network->passphrase)
+ return -ENOKEY;
+
+ handshake_state_set_passphrase(hs, network->passphrase);
+
+ if (ie_rsnxe_capable(hs->authenticator_rsnxe,
+ IE_RSNX_SAE_H2E)) {
+ l_debug("Authenticator is SAE H2E capable");
+ handshake_state_add_ecc_sae_pt(hs, network->sae_pt_19);
+ handshake_state_add_ecc_sae_pt(hs, network->sae_pt_20);
+ }
+ } else {
+ const uint8_t *psk = network_get_psk(network);
+
+ if (!psk)
+ return -ENOKEY;
+
+ handshake_state_set_pmk(hs, psk, 32);
+ }
+
+ return 0;
+}
+
+int network_handshake_setup(struct network *network,
+ struct handshake_state *hs)
+{
+ struct station *station = network->station;
+ struct wiphy *wiphy = station_get_wiphy(station);
+ struct l_settings *settings = network->settings;
+ struct network_info *info = network->info;
+ uint32_t eapol_proto_version;
+ uint8_t new_addr[ETH_ALEN];
+ int r;
+
+ switch (network->security) {
+ case SECURITY_PSK:
+ r = network_set_handshake_secrets_psk(network, hs);
+ if (r < 0)
+ return r;
+
+ break;
+ case SECURITY_8021X:
+ handshake_state_set_8021x_config(hs, settings);
+ break;
+ case SECURITY_NONE:
+ break;
+ case SECURITY_WEP:
+ return -ENOTSUP;
+ }
+
+ handshake_state_set_ssid(hs, (void *) network->ssid,
+ strlen(network->ssid));
+
+ if (settings && l_settings_get_uint(settings, "EAPoL",
+ "ProtocolVersion",
+ &eapol_proto_version)) {
+ if (eapol_proto_version > 3) {
+ l_warn("Invalid ProtocolVersion value - should be 0-3");
+ eapol_proto_version = 0;
+ }
+
+ if (eapol_proto_version)
+ l_debug("Overriding EAPoL protocol version to: %u",
+ eapol_proto_version);
+
+ handshake_state_set_protocol_version(hs, eapol_proto_version);
+ }
+
+ /*
+ * We have three possible options here:
+ * 1. per-network MAC generation (default, no option in network config)
+ * 2. per-network full MAC randomization
+ * 3. per-network MAC override
+ */
+ if (info && info->config.override_addr)
+ handshake_state_set_supplicant_address(hs,
+ info->config.sta_addr);
+ else if (info && info->config.always_random_addr) {
+ wiphy_generate_random_address(wiphy, new_addr);
+ handshake_state_set_supplicant_address(hs, new_addr);
+ }
+
+ return 0;
+}
+
+static int network_settings_load_pt_ecc(struct network *network,
+ const char *path,
+ unsigned int group,
+ struct l_ecc_point **out_pt)
+{
+ _auto_(l_free) char *key = l_strdup_printf(SAE_PT_SETTING, group);
+ size_t pt_len;
+ _auto_(l_free) uint8_t *pt = l_settings_get_bytes(network->settings,
+ "Security", key, &pt_len);
+ const struct l_ecc_curve *curve = l_ecc_curve_from_ike_group((group));
+
+ if (!curve)
+ return -EINVAL;
+
+ if (!pt)
+ goto generate;
+
+ if (pt_len != l_ecc_curve_get_scalar_bytes(curve) * 2)
+ goto bad_format;
+
+ *out_pt = l_ecc_point_from_data(curve, L_ECC_POINT_TYPE_FULL,
+ pt, pt_len);
+ if (*out_pt)
+ return 0;
+
+bad_format:
+ l_error("%s: invalid %s format", path, key);
+
+generate:
+ if (!network->passphrase)
+ return -ENOKEY;
+
+ *out_pt = network_generate_sae_pt(network, group);
+ if (*out_pt)
+ return 1;
+
+ return -EIO;
+}
+
static int network_load_psk(struct network *network, bool need_passphrase)
{
const char *ssid = network_get_ssid(network);
enum security security = network_get_security(network);
size_t psk_len;
- uint8_t *psk = l_settings_get_bytes(network->settings, "Security",
+ _auto_(l_free) uint8_t *psk =
+ l_settings_get_bytes(network->settings, "Security",
"PreSharedKey", &psk_len);
_auto_(l_free) char *passphrase =
l_settings_get_string(network->settings,
"Security", "Passphrase");
_auto_(l_free) char *path =
storage_get_network_file_path(security, ssid);
- int r;
if (psk && psk_len != 32) {
l_error("%s: invalid PreSharedKey format", path);
@@ -411,66 +602,113 @@ static int network_load_psk(struct network *network, bool need_passphrase)
network_reset_psk(network);
network->passphrase = l_steal_ptr(passphrase);
- if (psk) {
- network->psk = psk;
- return 0;
+ if (network_settings_load_pt_ecc(network, path,
+ 19, &network->sae_pt_19) > 0)
+ network->sync_settings = true;
+
+ if (network_settings_load_pt_ecc(network, path,
+ 20, &network->sae_pt_20) > 0)
+ network->sync_settings = true;
+
+ network->psk = l_steal_ptr(psk);
+
+ return 0;
+}
+
+static void network_settings_save_sae_pt_ecc(struct l_settings *settings,
+ struct l_ecc_point *pt)
+{
+ const struct l_ecc_curve *curve = l_ecc_point_get_curve(pt);
+ unsigned int group = l_ecc_curve_get_ike_group(curve);
+ _auto_(l_free) char *key = l_strdup_printf(SAE_PT_SETTING, group);
+ uint8_t buf[256];
+ ssize_t len;
+
+ len = l_ecc_point_get_data(pt, buf, sizeof(buf));
+ if (len < 0) {
+ l_warn("Unable to serialize '%s'", key);
+ return;
}
- network->psk = l_malloc(32);
- r = crypto_psk_from_passphrase(network->passphrase, (uint8_t *) ssid,
- strlen(ssid), network->psk);
- if (!r) {
- network->update_psk = true;
- return 0;
+ l_settings_set_bytes(settings, "Security", key, buf, len);
+}
+
+static void network_settings_save(struct network *network,
+ struct l_settings *settings)
+{
+ if (network->have_transition_disable) {
+ char *modes[4];
+ unsigned int i = 0;
+
+ l_settings_set_bool(settings, NET_TRANSITION_DISABLE, true);
+
+ if (test_bit(&network->transition_disable, 0))
+ modes[i++] = "personal";
+
+ if (test_bit(&network->transition_disable, 2))
+ modes[i++] = "enterprise";
+
+ if (test_bit(&network->transition_disable, 3))
+ modes[i++] = "open";
+
+ modes[i] = NULL;
+
+ l_settings_set_string_list(settings,
+ NET_TRANSITION_DISABLE_MODES,
+ modes, ' ');
}
- l_error("PSK generation failed: %s", strerror(-r));
+ if (network->security != SECURITY_PSK)
+ return;
+
+ /* We only update the [Security] bits here, wipe the group first */
+ l_settings_remove_group(settings, "Security");
- network_reset_passphrase(network);
- network_reset_psk(network);
+ if (network->psk)
+ l_settings_set_bytes(settings, "Security", "PreSharedKey",
+ network->psk, 32);
- return r;
+ if (network->passphrase)
+ l_settings_set_string(settings, "Security", "Passphrase",
+ network->passphrase);
+
+ if (network->sae_pt_19)
+ network_settings_save_sae_pt_ecc(settings, network->sae_pt_19);
+
+ if (network->sae_pt_20)
+ network_settings_save_sae_pt_ecc(settings, network->sae_pt_20);
}
-void network_sync_psk(struct network *network)
+void network_sync_settings(struct network *network)
{
- struct l_settings *fs_settings;
- const char *ssid = network_get_ssid(network);
+ struct network_info *info = network->info;
- if (!network->update_psk)
+ if (!network->sync_settings)
return;
- network->update_psk = false;
+ l_debug("");
- fs_settings = storage_network_open(SECURITY_PSK, ssid);
+ network->sync_settings = false;
- if (network->psk) {
- l_settings_set_bytes(network->settings, "Security",
- "PreSharedKey",
- network->psk, 32);
+ /*
+ * Re-open the settings from Disk, in case they were updated
+ * since we last opened them.
+ */
+ if (network->info) {
+ struct l_settings *fs_settings = info->ops->open(info);
- if (fs_settings)
- l_settings_set_bytes(fs_settings, "Security",
- "PreSharedKey",
- network->psk, 32);
- }
+ if (L_WARN_ON(!fs_settings))
+ return;
- if (network->passphrase) {
- l_settings_set_string(network->settings, "Security",
- "Passphrase",
- network->passphrase);
-
- if (fs_settings)
- l_settings_set_string(fs_settings, "Security",
- "Passphrase",
- network->passphrase);
+ network_settings_save(network, fs_settings);
+ info->ops->sync(info, fs_settings);
+ l_settings_free(fs_settings);
+ return;
}
- if (fs_settings) {
- storage_network_sync(SECURITY_PSK, ssid, fs_settings);
- l_settings_free(fs_settings);
- } else
- storage_network_sync(SECURITY_PSK, ssid, network->settings);
+ network_settings_save(network, network->settings);
+ storage_network_sync(network->security, network->ssid,
+ network->settings);
}
const struct network_info *network_get_info(const struct network *network)
@@ -523,60 +761,144 @@ static bool bss_is_sae(const struct scan_bss *bss)
return __bss_is_sae(bss, &rsn);
}
-int network_autoconnect(struct network *network, struct scan_bss *bss)
+int network_can_connect_bss(struct network *network, const struct scan_bss *bss)
{
struct station *station = network->station;
struct wiphy *wiphy = station_get_wiphy(station);
enum security security = network_get_security(network);
+ struct network_info *info = network->info;
+ struct network_config *config = info ? &info->config : NULL;
+ bool can_transition_disable = wiphy_can_transition_disable(wiphy);
struct ie_rsn_info rsn;
- bool is_rsn;
int ret;
- /* already waiting for an agent request, connect in progress */
- if (network->agent_request)
- return -EALREADY;
-
switch (security) {
case SECURITY_NONE:
- is_rsn = false;
- break;
case SECURITY_PSK:
- if (network->ask_passphrase)
- return -ENOKEY;
-
- /* Fall through */
case SECURITY_8021X:
- is_rsn = true;
break;
default:
- return -ENOTSUP;
+ return -ENOSYS;
}
- if (!network_settings_load(network))
- return -ENOKEY;
+ memset(&rsn, 0, sizeof(rsn));
+ ret = scan_bss_get_rsn_info(bss, &rsn);
+ if (ret < 0) {
+ /*
+ * WPA3 Specification Version 3, Section 8
+ * Transition Disable implies PMF, no TKIP, yet
+ * Bit 3 is specified as 'Open system authentication without
+ * encryption'.
+ *
+ * We assume the spec means us to check bit 3 here
+ */
+ if (ret == -ENOENT && security == SECURITY_NONE) {
+ if (!config)
+ return 0;
+
+ if (!config->have_transition_disable ||
+ !test_bit(&config->transition_disable,
+ 3))
+ return 0;
+
+ if (!can_transition_disable) {
+ l_debug("HW not capable of Transition Disable");
+ return 0;
+ }
+ }
- ret = -EPERM;
- if (!network->info->is_autoconnectable)
- goto close_settings;
+ return ret;
+ }
- if (!is_rsn)
- goto done;
+ if (!config || !config->have_transition_disable)
+ goto no_transition_disable;
- memset(&rsn, 0, sizeof(rsn));
- scan_bss_get_rsn_info(bss, &rsn);
+ if (!can_transition_disable) {
+ l_debug("HW not capable of Transition Disable, skip");
+ goto no_transition_disable;
+ }
+
+ /*
+ * WPA3 Specification, v3, Section 8:
+ * - Disable use of WEP and TKIP
+ * - Disallow association without negotiation of PMF
+ */
+ rsn.pairwise_ciphers &= ~IE_RSN_CIPHER_SUITE_TKIP;
+
+ if (!rsn.group_management_cipher)
+ return -EPERM;
+
+ rsn.mfpr = true;
+
+ /* WPA3-Personal */
+ if (test_bit(&config->transition_disable, 0)) {
+ rsn.akm_suites &= ~IE_RSN_AKM_SUITE_PSK;
+ rsn.akm_suites &= ~IE_RSN_AKM_SUITE_PSK_SHA256;
+ rsn.akm_suites &= ~IE_RSN_AKM_SUITE_FT_USING_PSK;
+ }
+
+ /* WPA3-Enterprise */
+ if (test_bit(&config->transition_disable, 2))
+ rsn.akm_suites &= ~IE_RSN_AKM_SUITE_8021X;
- if (!wiphy_select_cipher(wiphy, rsn.pairwise_ciphers) ||
- !wiphy_select_cipher(wiphy, rsn.group_cipher)) {
- l_debug("Cipher mismatch");
- ret = -ENETUNREACH;
- goto close_settings;
+ /* Enhanced Open */
+ if (test_bit(&config->transition_disable, 3)) {
+ if (!(rsn.akm_suites & IE_RSN_AKM_SUITE_OWE))
+ return -EPERM;
}
- if (security == SECURITY_PSK) {
- ret = network_load_psk(network, __bss_is_sae(bss, &rsn));
+no_transition_disable:
+ if (!wiphy_select_cipher(wiphy, rsn.pairwise_ciphers))
+ return -ENOTSUP;
+
+ if (!wiphy_select_cipher(wiphy, rsn.group_cipher))
+ return -ENOTSUP;
+
+ if (rsn.mfpr && !wiphy_select_cipher(wiphy,
+ rsn.group_management_cipher))
+ return -EPERM;
+
+ if (!wiphy_select_akm(wiphy, bss, security, &rsn, false))
+ return -ENOTSUP;
+
+ return 0;
+}
+
+int network_autoconnect(struct network *network, struct scan_bss *bss)
+{
+ struct station *station = network->station;
+ enum security security = network_get_security(network);
+ struct network_info *info = network->info;
+ struct network_config *config;
+ int ret;
+
+ /* already waiting for an agent request, connect in progress */
+ if (network->agent_request)
+ return -EALREADY;
+
+ if (network->ask_passphrase)
+ return -ENOKEY;
+
+ if (!info)
+ return -ENOENT;
+
+ config = &info->config;
+
+ if (!config->is_autoconnectable)
+ return -EPERM;
+
+ if (!network_settings_load(network))
+ return -ENOKEY;
+
+ switch (security) {
+ case SECURITY_PSK:
+ ret = network_load_psk(network, bss_is_sae(bss));
if (ret < 0)
goto close_settings;
- } else if (security == SECURITY_8021X) {
+
+ break;
+ case SECURITY_8021X:
+ {
struct l_queue *missing_secrets = NULL;
ret = eap_check_settings(network->settings, network->secrets,
@@ -592,9 +914,16 @@ int network_autoconnect(struct network *network, struct scan_bss *bss)
if (!network_set_8021x_secrets(network))
goto close_settings;
+
+ break;
+ }
+
+ case SECURITY_NONE:
+ break;
+ default:
+ return -ENOTSUP;
}
-done:
return __station_connect_network(station, network, bss);
close_settings:
@@ -609,7 +938,7 @@ void network_connect_failed(struct network *network, bool in_handshake)
* for the passphrase once more
*/
if (network_get_security(network) == SECURITY_PSK && in_handshake) {
- network->update_psk = false;
+ network->sync_settings = false;
network->ask_passphrase = true;
}
@@ -779,26 +1108,18 @@ struct scan_bss *network_bss_select(struct network *network,
bool fallback_to_blacklist)
{
struct l_queue *bss_list = network->bss_list;
- struct wiphy *wiphy = station_get_wiphy(network->station);
const struct l_queue_entry *bss_entry;
struct scan_bss *candidate = NULL;
- bool fils_hint = network_has_erp_identity(network);
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
bss_entry = bss_entry->next) {
struct scan_bss *bss = bss_entry->data;
+ int ret = network_can_connect_bss(network, bss);
- switch (network_get_security(network)) {
- case SECURITY_PSK:
- case SECURITY_8021X:
- if (!wiphy_can_connect(wiphy, bss, fils_hint))
- continue;
- /* fall through */
- case SECURITY_NONE:
- break;
- default:
+ if (ret == -ENOSYS)
return NULL;
- }
+ else if (ret < 0)
+ continue;
/*
* We only want to record the first (best) candidate. In case
@@ -833,9 +1154,7 @@ static void passphrase_callback(enum agent_result result,
{
struct network *network = user_data;
struct station *station = network->station;
- const char *ssid = network_get_ssid(network);
struct scan_bss *bss;
- int r;
l_debug("result %d", result);
@@ -862,39 +1181,13 @@ static void passphrase_callback(enum agent_result result,
}
network_reset_psk(network);
- network->psk = l_malloc(32);
- r = crypto_psk_from_passphrase(passphrase,
- (uint8_t *) ssid, strlen(ssid),
- network->psk);
- if (r) {
- struct l_dbus_message *error;
-
- l_free(network->psk);
- network->psk = NULL;
-
- if (r == -ERANGE || r == -EINVAL)
- error = dbus_error_invalid_format(message);
- else {
- l_error("PSK generation failed: %s. "
- "Ensure Crypto Engine is properly configured",
- strerror(-r));
- error = dbus_error_failed(message);
- }
- dbus_pending_reply(&message, error);
+ if (!__network_set_passphrase(network, passphrase)) {
+ dbus_pending_reply(&message,
+ dbus_error_invalid_format(message));
goto err;
}
- network_reset_passphrase(network);
- network->passphrase = l_strdup(passphrase);
-
- /*
- * We need to store the PSK in our permanent store. However, before
- * we do that, make sure the PSK works. We write to the store only
- * when we are connected
- */
- network->update_psk = true;
-
station_connect_network(station, network, bss, message);
l_dbus_message_unref(message);
return;
@@ -1291,7 +1584,7 @@ struct l_dbus_message *network_connect_new_hidden_network(
/*
* This is not a Known Network. If connection succeeds, either
- * network_sync_psk or network_connected will save this network
+ * network_sync_settings or network_connected will save this network
* as hidden and trigger an update to the hidden networks count.
*/
@@ -1301,7 +1594,7 @@ struct l_dbus_message *network_connect_new_hidden_network(
return dbus_error_not_supported(message);
network->settings = l_settings_new();
- l_settings_set_bool(network->settings, "Settings", "Hidden", true);
+ l_settings_set_bool(network->settings, NET_HIDDEN, true);
switch (network_get_security(network)) {
case SECURITY_PSK:
@@ -1481,6 +1774,7 @@ void network_rank_update(struct network *network, bool connected)
* here and in network_bss_select but those should be rare cases.
*/
struct scan_bss *best_bss = l_queue_peek_head(network->bss_list);
+ struct network_info *info = network->info;
/*
* The rank should separate networks into four groups that use
@@ -1499,13 +1793,13 @@ void network_rank_update(struct network *network, bool connected)
return;
}
- if (!network->info) { /* Not known, assign negative rank */
+ if (!info) { /* Not known, assign negative rank */
network->rank = (int) best_bss->rank - USHRT_MAX;
return;
}
- if (network->info->connected_time != 0) {
- int n = known_network_offset(network->info);
+ if (info->config.connected_time != 0) {
+ int n = known_network_offset(info);
L_WARN_ON(n < 0);
@@ -1545,7 +1839,7 @@ static void network_unset_hotspot(struct network *network, void *user_data)
static void emit_known_network_removed(struct station *station, void *user_data)
{
struct network_info *info = user_data;
- bool was_hidden = info->is_hidden;
+ bool was_hidden = info->config.is_hidden;
struct network *connected_network;
struct network *network = NULL;
diff --git a/src/network.h b/src/network.h
@@ -28,6 +28,7 @@ struct device;
struct station;
struct network;
struct scan_bss;
+struct handshake_state;
void network_connected(struct network *network);
void network_disconnected(struct network *network);
@@ -39,19 +40,25 @@ struct network *network_create(struct station *station, const char *ssid,
const char *network_get_ssid(const struct network *network);
const char *network_get_path(const struct network *network);
enum security network_get_security(const struct network *network);
-const uint8_t *network_get_psk(struct network *network);
-const char *network_get_passphrase(const struct network *network);
bool network_set_passphrase(struct network *network, const char *passphrase);
-struct l_queue *network_get_secrets(const struct network *network);
int network_get_signal_strength(const struct network *network);
struct l_settings *network_get_settings(const struct network *network);
bool network_set_psk(struct network *network, const uint8_t *psk);
-void network_sync_psk(struct network *network);
+
+int network_set_transition_disable(struct network *network,
+ const uint8_t *td, size_t len);
+
+int network_handshake_setup(struct network *network,
+ struct handshake_state *hs);
+
+void network_sync_settings(struct network *network);
const struct network_info *network_get_info(const struct network *network);
void network_set_info(struct network *network, struct network_info *info);
+int network_can_connect_bss(struct network *network,
+ const struct scan_bss *bss);
int network_autoconnect(struct network *network, struct scan_bss *bss);
void network_connect_failed(struct network *network, bool in_handshake);
bool network_bss_add(struct network *network, struct scan_bss *bss);
diff --git a/src/owe.c b/src/owe.c
@@ -57,7 +57,7 @@ static bool owe_reset(struct owe_sm *owe)
return false;
owe->group = owe->ecc_groups[owe->retry];
- owe->curve = l_ecc_curve_get_ike_group(owe->group);
+ owe->curve = l_ecc_curve_from_ike_group(owe->group);
if (owe->private)
l_ecc_scalar_free(owe->private);
@@ -193,8 +193,7 @@ static bool owe_compute_keys(struct owe_sm *owe, const void *public_key,
goto failed;
/* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
- if (!hkdf_expand(type, prk, nbytes, "OWE Key Generation",
- strlen("OWE Key Generation"), pmk, nbytes))
+ if (!hkdf_expand(type, prk, nbytes, "OWE Key Generation", pmk, nbytes))
goto failed;
sha = l_checksum_new(type);
@@ -241,8 +240,8 @@ static int owe_rx_associate(struct auth_proto *ap, const uint8_t *frame,
{
struct owe_sm *owe = l_container_of(ap, struct owe_sm, ap);
- const struct mmpdu_header *mpdu = NULL;
- const struct mmpdu_association_response *body;
+ const struct mmpdu_header *mpdu = (const struct mmpdu_header *) frame;
+ const struct mmpdu_association_response *body = mmpdu_body(mpdu);
struct ie_tlv_iter iter;
size_t owe_dh_len = 0;
const uint8_t *owe_dh = NULL;
@@ -250,14 +249,6 @@ static int owe_rx_associate(struct auth_proto *ap, const uint8_t *frame,
bool akm_found = false;
const void *data;
- mpdu = mpdu_validate(frame, len);
- if (!mpdu) {
- l_error("could not process frame");
- return -EBADMSG;
- }
-
- body = mmpdu_body(mpdu);
-
if (L_LE16_TO_CPU(body->status_code) ==
MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP) {
if (!owe_retry(owe))
@@ -343,7 +334,7 @@ struct auth_proto *owe_sm_new(struct handshake_state *hs,
owe->auth_tx = auth;
owe->assoc_tx = assoc;
owe->user_data = user_data;
- owe->ecc_groups = l_ecc_curve_get_supported_ike_groups();
+ owe->ecc_groups = l_ecc_supported_ike_groups();
owe->ap.start = owe_start;
owe->ap.free = owe_free;
diff --git a/src/p2p.c b/src/p2p.c
@@ -1517,7 +1517,8 @@ static void p2p_try_connect_group(struct p2p_device *dev)
scan_bss_get_rsn_info(bss, &bss_info);
- rsn_info.akm_suites = wiphy_select_akm(dev->wiphy, bss, false);
+ rsn_info.akm_suites = wiphy_select_akm(dev->wiphy, bss, SECURITY_PSK,
+ &bss_info, false);
if (!rsn_info.akm_suites)
goto not_supported;
@@ -1820,6 +1821,8 @@ static bool p2p_provision_scan_notify(int err, struct l_queue *bss_list,
struct p2p_capability_attr *capability;
enum wsc_device_password_id device_password_id;
const uint8_t *amacs;
+ struct wsc_probe_response wsc_probe_info;
+ struct wsc_beacon wsc_beacon_info;
/*
* Check if we found our target GO, some of these checks may
@@ -1847,15 +1850,13 @@ static bool p2p_provision_scan_notify(int err, struct l_queue *bss_list,
}
if (bss->source_frame == SCAN_BSS_PROBE_RESP) {
- struct wsc_probe_response wsc_info;
-
if (!bss->p2p_probe_resp_info) {
l_error("SSID matched but no valid P2P IE");
continue;
}
if (wsc_parse_probe_response(bss->wsc, bss->wsc_size,
- &wsc_info) < 0) {
+ &wsc_probe_info) < 0) {
l_error("SSID matched but can't parse WSC "
"Probe Response info");
continue;
@@ -1863,30 +1864,28 @@ static bool p2p_provision_scan_notify(int err, struct l_queue *bss_list,
group_id = bss->p2p_probe_resp_info->
device_info.device_addr;
- selected_reg = wsc_info.selected_registrar;
+ selected_reg = wsc_probe_info.selected_registrar;
capability = &bss->p2p_probe_resp_info->capability;
- device_password_id = wsc_info.device_password_id;
- amacs = wsc_info.authorized_macs;
+ device_password_id = wsc_probe_info.device_password_id;
+ amacs = wsc_probe_info.authorized_macs;
} else if (bss->source_frame == SCAN_BSS_BEACON) {
- struct wsc_beacon wsc_info;
-
if (!bss->p2p_beacon_info) {
l_error("SSID matched but no valid P2P IE");
continue;
}
if (wsc_parse_beacon(bss->wsc, bss->wsc_size,
- &wsc_info) < 0) {
+ &wsc_beacon_info) < 0) {
l_error("SSID matched but can't parse WSC "
"Beacon info");
continue;
}
group_id = bss->p2p_beacon_info->device_addr;
- selected_reg = wsc_info.selected_registrar;
+ selected_reg = wsc_beacon_info.selected_registrar;
capability = &bss->p2p_beacon_info->capability;
- device_password_id = wsc_info.device_password_id;
- amacs = wsc_info.authorized_macs;
+ device_password_id = wsc_beacon_info.device_password_id;
+ amacs = wsc_beacon_info.authorized_macs;
} else
continue;
diff --git a/src/sae.c b/src/sae.c
@@ -32,8 +32,11 @@
#include "src/handshake.h"
#include "src/crypto.h"
#include "src/mpdu.h"
-#include "src/sae.h"
#include "src/auth-proto.h"
+#include "src/sae.h"
+
+/* SHA-512 is the highest supported hashing function as of 802.11-2020 */
+#define SAE_MAX_HASH_LEN 64
#define SAE_RETRANSMIT_TIMEOUT 2
#define SAE_SYNC_MAX 3
@@ -53,15 +56,15 @@ struct sae_sm {
enum sae_state state;
const struct l_ecc_curve *curve;
unsigned int group;
- uint8_t group_retry;
- const unsigned int *ecc_groups;
+ int group_retry;
+ uint16_t *rejected_groups;
struct l_ecc_scalar *rand;
struct l_ecc_scalar *scalar;
struct l_ecc_scalar *p_scalar;
struct l_ecc_point *element;
struct l_ecc_point *p_element;
uint16_t send_confirm;
- uint8_t kck[32];
+ uint8_t kck[SAE_MAX_HASH_LEN];
uint8_t pmk[32];
uint8_t pmkid[16];
uint8_t *token;
@@ -79,8 +82,99 @@ struct sae_sm {
sae_tx_authenticate_func_t tx_auth;
sae_tx_associate_func_t tx_assoc;
void *user_data;
+ enum crypto_sae sae_type;
};
+static enum mmpdu_status_code sae_status_code(struct sae_sm *sm)
+{
+ switch (sm->sae_type) {
+ case CRYPTO_SAE_LOOPING:
+ return MMPDU_STATUS_CODE_SUCCESS;
+ case CRYPTO_SAE_HASH_TO_ELEMENT:
+ return MMPDU_STATUS_CODE_SAE_HASH_TO_ELEMENT;
+ }
+
+ return MMPDU_STATUS_CODE_UNSPECIFIED;
+}
+
+static void sae_rejected_groups_append(struct sae_sm *sm, uint16_t group)
+{
+ uint16_t i;
+
+ if (!sm->rejected_groups) {
+ sm->rejected_groups = reallocarray(NULL, 2, sizeof(uint16_t));
+ sm->rejected_groups[0] = 1;
+ sm->rejected_groups[1] = group;
+ return;
+ }
+
+ for (i = 1; i <= sm->rejected_groups[0]; i++)
+ if (sm->rejected_groups[i] == group)
+ return;
+
+ sm->rejected_groups = reallocarray(sm->rejected_groups,
+ i + 1, sizeof(uint16_t));
+ sm->rejected_groups[0] += 1;
+ sm->rejected_groups[i] = group;
+}
+
+static void sae_reset_state(struct sae_sm *sm)
+{
+ l_ecc_scalar_free(sm->scalar);
+ sm->scalar = NULL;
+ l_ecc_scalar_free(sm->p_scalar);
+ sm->p_scalar = NULL;
+ l_ecc_scalar_free(sm->rand);
+ sm->rand = NULL;
+ l_ecc_point_free(sm->element);
+ sm->element = NULL;
+ l_ecc_point_free(sm->p_element);
+ sm->p_element = NULL;
+ l_ecc_point_free(sm->pwe);
+ sm->pwe = NULL;
+}
+
+static int sae_choose_next_group(struct sae_sm *sm)
+{
+ const unsigned int *ecc_groups = l_ecc_supported_ike_groups();
+ bool reset = sm->group_retry >= 0;
+
+ do {
+ sm->group_retry++;
+
+ if (ecc_groups[sm->group_retry] == 0)
+ return -ENOENT;
+ } while (sm->sae_type != CRYPTO_SAE_LOOPING &&
+ !sm->handshake->ecc_sae_pts[sm->group_retry]);
+
+ if (reset)
+ sae_reset_state(sm);
+
+ sm->group = ecc_groups[sm->group_retry];
+ sm->curve = l_ecc_curve_from_ike_group(sm->group);
+
+ return 0;
+}
+
+static int sae_valid_group(struct sae_sm *sm, unsigned int group)
+{
+ const unsigned int *ecc_groups = l_ecc_supported_ike_groups();
+ unsigned int i;
+
+ for (i = sm->group_retry; ecc_groups[i]; i++) {
+ if (ecc_groups[i] != group)
+ continue;
+
+ if (sm->sae_type != CRYPTO_SAE_LOOPING &&
+ !sm->handshake->ecc_sae_pts[i])
+ continue;
+
+ return i;
+ }
+
+ return -ENOENT;
+}
+
static bool sae_pwd_seed(const uint8_t *addr1, const uint8_t *addr2,
uint8_t *base, size_t base_len,
uint8_t counter, uint8_t *out)
@@ -145,25 +239,31 @@ static struct l_ecc_scalar *sae_pwd_value(const struct l_ecc_curve *curve,
}
/* IEEE 802.11-2016 - Section 12.4.2 Assumptions on SAE */
-static bool sae_cn(const uint8_t *kck, uint16_t send_confirm,
+static ssize_t sae_cn(struct sae_sm *sm, uint16_t send_confirm,
struct l_ecc_scalar *scalar1,
struct l_ecc_point *element1,
struct l_ecc_scalar *scalar2,
struct l_ecc_point *element2,
uint8_t *confirm)
{
+ enum l_checksum_type hash =
+ crypto_sae_hash_from_ecc_prime_len(sm->sae_type,
+ l_ecc_curve_get_scalar_bytes(sm->curve));
+ size_t hash_len = l_checksum_digest_length(hash);
uint8_t s1[L_ECC_SCALAR_MAX_BYTES];
uint8_t s2[L_ECC_SCALAR_MAX_BYTES];
uint8_t e1[L_ECC_POINT_MAX_BYTES];
uint8_t e2[L_ECC_POINT_MAX_BYTES];
struct l_checksum *hmac;
struct iovec iov[5];
- int ret;
+ ssize_t ret;
- hmac = l_checksum_new_hmac(L_CHECKSUM_SHA256, kck, 32);
+ hmac = l_checksum_new_hmac(hash, sm->kck, hash_len);
if (!hmac)
return false;
+ send_confirm = L_CPU_TO_LE16(send_confirm);
+
iov[0].iov_base = &send_confirm;
iov[0].iov_len = 2;
iov[1].iov_base = (void *) s1;
@@ -176,32 +276,35 @@ static bool sae_cn(const uint8_t *kck, uint16_t send_confirm,
iov[4].iov_len = l_ecc_point_get_data(element2, e2, sizeof(e2));
l_checksum_updatev(hmac, iov, 5);
-
- ret = l_checksum_get_digest(hmac, confirm, 32);
-
+ ret = l_checksum_get_digest(hmac, confirm, hash_len);
l_checksum_free(hmac);
- return (ret == 32);
+ return ret;
}
-static void sae_reject_authentication(struct sae_sm *sm, uint16_t reason)
+static int sae_reject(struct sae_sm *sm, uint16_t transaction, uint16_t status)
{
uint8_t reject[6];
uint8_t *ptr = reject;
+ if (!sm->handshake->authenticator)
+ return -EPROTO;
+
/* transaction */
- l_put_u16(1, ptr);
+ l_put_u16(transaction, ptr);
ptr += 2;
- /* status success */
- l_put_u16(reason, ptr);
+
+ l_put_u16(status, ptr);
ptr += 2;
- if (reason == MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP) {
+ if (status == MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP) {
l_put_u16(sm->group, ptr);
ptr += 2;
}
sm->tx_auth(reject, ptr - reject, sm->user_data);
+
+ return status;
}
static struct l_ecc_scalar *sae_new_residue(const struct l_ecc_curve *curve,
@@ -268,8 +371,10 @@ static uint8_t sae_is_quadradic_residue(const struct l_ecc_curve *curve,
* IEEE 802.11-2016 Section 12.4.4.2.2
* Generation of the password element with ECC groups
*/
-static bool sae_compute_pwe(struct sae_sm *sm, char *password,
- const uint8_t *addr1, const uint8_t *addr2)
+static struct l_ecc_point *sae_compute_pwe(const struct l_ecc_curve *curve,
+ const char *password,
+ const uint8_t *addr1,
+ const uint8_t *addr2)
{
uint8_t found = 0;
uint8_t is_residue;
@@ -285,10 +390,11 @@ static bool sae_compute_pwe(struct sae_sm *sm, char *password,
struct l_ecc_scalar *qr;
struct l_ecc_scalar *qnr;
uint8_t qnr_bin[L_ECC_SCALAR_MAX_BYTES] = {0};
+ struct l_ecc_point *pwe;
/* create qr/qnr prior to beginning hunting-and-pecking loop */
- qr = sae_new_residue(sm->curve, true);
- qnr = sae_new_residue(sm->curve, false);
+ qr = sae_new_residue(curve, true);
+ qnr = sae_new_residue(curve, false);
l_ecc_scalar_get_data(qnr, qnr_bin, sizeof(qnr_bin));
/*
@@ -326,13 +432,13 @@ static bool sae_compute_pwe(struct sae_sm *sm, char *password,
* execution can continue whatever the result is, without
* changing the outcome.
*/
- pwd_value = sae_pwd_value(sm->curve, pwd_seed, qnr_bin);
+ pwd_value = sae_pwd_value(curve, pwd_seed, qnr_bin);
/*
* Check if the candidate is a valid x-coordinate on our curve,
* and convert it from scalar to binary.
*/
- is_residue = sae_is_quadradic_residue(sm->curve, pwd_value,
+ is_residue = sae_is_quadradic_residue(curve, pwd_value,
qr, qnr);
l_ecc_scalar_get_data(pwd_value, x_cand, sizeof(x_cand));
@@ -362,37 +468,46 @@ static bool sae_compute_pwe(struct sae_sm *sm, char *password,
if (!found) {
l_error("max PWE iterations reached!");
- return false;
+ return NULL;
}
- sm->pwe = l_ecc_point_from_data(sm->curve, !is_odd + 2, x, sizeof(x));
- if (!sm->pwe) {
+ pwe = l_ecc_point_from_data(curve, !is_odd + 2, x, sizeof(x));
+ if (!pwe)
l_error("computing y failed, was x quadratic residue?");
- return false;
- }
- return true;
+ return pwe;
}
-static bool sae_build_commit(struct sae_sm *sm, const uint8_t *addr1,
+static int sae_build_commit(struct sae_sm *sm, const uint8_t *addr1,
const uint8_t *addr2, uint8_t *commit,
- size_t *len, bool retry)
+ size_t len, bool retry)
{
struct l_ecc_scalar *mask;
uint8_t *ptr = commit;
struct l_ecc_scalar *order;
+ struct ie_tlv_builder builder;
if (retry)
goto old_commit;
- if (!sm->handshake->passphrase) {
- l_error("no handshake passphrase found");
- return false;
+ switch (sm->sae_type) {
+ case CRYPTO_SAE_HASH_TO_ELEMENT:
+ {
+ const struct l_ecc_point *pt =
+ sm->handshake->ecc_sae_pts[sm->group_retry];
+
+ sm->pwe = crypto_derive_sae_pwe_from_pt_ecc(addr1, addr2, pt);
+ break;
+ }
+ case CRYPTO_SAE_LOOPING:
+ sm->pwe = sae_compute_pwe(sm->curve, sm->handshake->passphrase,
+ addr1, addr2);
+ break;
}
- if (!sae_compute_pwe(sm, sm->handshake->passphrase, addr1, addr2)) {
+ if (!sm->pwe) {
l_error("could not compute PWE");
- return false;
+ return -EIO;
}
sm->scalar = l_ecc_scalar_new(sm->curve, NULL, 0);
@@ -420,17 +535,25 @@ static bool sae_build_commit(struct sae_sm *sm, const uint8_t *addr1,
*/
old_commit:
- /* transaction */
+ /*
+ * 12.4.7.4 Encoding and decoding of SAE Commit messages
+ * Refer to Table 9-40 for order and Table 9-41 for presence
+ * of elements
+ */
+
+ /* "a Transaction Sequence Number of 1" */
l_put_le16(1, ptr);
ptr += 2;
- /* status success */
- l_put_le16(0, ptr);
+
+ /* "a Status Code of SUCCESS or SAE_HASH_TO_ELEMENT" */
+ l_put_le16(sae_status_code(sm), ptr);
ptr += 2;
+
/* group */
l_put_le16(sm->group, ptr);
ptr += 2;
- if (sm->token) {
+ if (sm->sae_type == CRYPTO_SAE_LOOPING && sm->token) {
memcpy(ptr, sm->token, sm->token_len);
ptr += sm->token_len;
}
@@ -438,23 +561,40 @@ old_commit:
ptr += l_ecc_scalar_get_data(sm->scalar, ptr, L_ECC_SCALAR_MAX_BYTES);
ptr += l_ecc_point_get_data(sm->element, ptr, L_ECC_POINT_MAX_BYTES);
- *len = ptr - commit;
+ ie_tlv_builder_init(&builder, ptr, len - (ptr - commit));
- return true;
+ if (sm->sae_type != CRYPTO_SAE_LOOPING && sm->rejected_groups) {
+ ie_tlv_builder_next(&builder, IE_TYPE_REJECTED_GROUPS);
+ ie_tlv_builder_set_data(&builder, sm->rejected_groups + 1,
+ sm->rejected_groups[0] * sizeof(uint16_t));
+ }
+
+ if (sm->sae_type != CRYPTO_SAE_LOOPING && sm->token) {
+ ie_tlv_builder_next(&builder,
+ IE_TYPE_ANTI_CLOGGING_TOKEN_CONTAINER);
+ ie_tlv_builder_set_data(&builder, sm->token, sm->token_len);
+ }
+
+ ie_tlv_builder_finalize(&builder, &len);
+
+ return ptr - commit + len;
}
-static void sae_send_confirm(struct sae_sm *sm)
+static bool sae_send_confirm(struct sae_sm *sm)
{
- uint8_t confirm[32];
- uint8_t body[38];
+ uint8_t confirm[SAE_MAX_HASH_LEN];
+ uint8_t body[sizeof(confirm) + 6];
uint8_t *ptr = body;
+ ssize_t r;
/*
* confirm = CN(KCK, send-confirm, commit-scalar, COMMIT-ELEMENT,
* peer-commit-scalar, PEER-COMMIT-ELEMENT)
*/
- sae_cn(sm->kck, sm->sc, sm->scalar, sm->element, sm->p_scalar,
+ r = sae_cn(sm, sm->sc, sm->scalar, sm->element, sm->p_scalar,
sm->p_element, confirm);
+ if (r < 0)
+ return false;
l_put_le16(2, ptr);
ptr += 2;
@@ -462,56 +602,39 @@ static void sae_send_confirm(struct sae_sm *sm)
ptr += 2;
l_put_le16(sm->sc, ptr);
ptr += 2;
- memcpy(ptr, confirm, 32);
- ptr += 32;
+ memcpy(ptr, confirm, r);
+ ptr += r;
- sm->state = SAE_STATE_CONFIRMED;
-
- sm->tx_auth(body, 38, sm->user_data);
+ sm->tx_auth(body, ptr - body, sm->user_data);
+ return true;
}
static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
const uint8_t *frame, size_t len)
{
uint8_t *ptr = (uint8_t *) frame;
- uint8_t k[L_ECC_SCALAR_MAX_BYTES];
+ unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
+ enum l_checksum_type hash =
+ crypto_sae_hash_from_ecc_prime_len(sm->sae_type, nbytes);
+ size_t hash_len = l_checksum_digest_length(hash);
struct l_ecc_point *k_point;
- uint8_t zero_key[32] = { 0 };
- uint8_t keyseed[32];
- uint8_t kck_and_pmk[2][32];
+ uint8_t k[L_ECC_SCALAR_MAX_BYTES];
+ ssize_t klen;
+ const void *salt = NULL;
+ size_t salt_len = 0;
+ uint8_t keyseed[SAE_MAX_HASH_LEN];
+ uint8_t kck_and_pmk[SAE_MAX_HASH_LEN + 32];
uint8_t tmp[L_ECC_SCALAR_MAX_BYTES];
struct l_ecc_scalar *tmp_scalar;
- uint16_t group;
- uint16_t reason = MMPDU_REASON_CODE_UNSPECIFIED;
- ssize_t klen;
struct l_ecc_scalar *order;
- unsigned int nbytes = l_ecc_curve_get_scalar_bytes(sm->curve);
-
- if (sm->state != SAE_STATE_COMMITTED) {
- l_error("bad state %u", sm->state);
- goto reject;
- }
-
- /* Scalar + Point + group */
- if (len < nbytes + nbytes * 2 + 2) {
- l_error("bad packet length");
- goto reject;
- }
- group = l_get_le16(ptr);
ptr += 2;
- if (group != sm->group) {
- sae_reject_authentication(sm,
- MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
- return 0;
- }
-
sm->p_scalar = l_ecc_scalar_new(sm->curve, ptr, nbytes);
if (!sm->p_scalar) {
l_error("Server sent invalid P_Scalar during commit");
- reason = MMPDU_REASON_CODE_UNSPECIFIED;
- goto reject;
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
}
ptr += nbytes;
@@ -520,16 +643,20 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
ptr, nbytes * 2);
if (!sm->p_element) {
l_error("Server sent invalid P_Element during commit");
- reason = MMPDU_REASON_CODE_UNSPECIFIED;
- goto reject;
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
}
+ /*
+ * If they match those sent as part of the protocol instance's own
+ * SAE Commit message, the frame shall be silently discarded (because
+ * it is evidence of a reflection attack) and the t0 (retransmission)
+ * timer shall be set.
+ */
if (l_ecc_scalars_are_equal(sm->p_scalar, sm->scalar) ||
l_ecc_points_are_equal(sm->p_element, sm->element)) {
- /* possible reflection attack, silently discard message */
l_warn("peer scalar or element matched own, discarding frame");
-
- return 0;
+ return -ENOMSG;
}
sm->sc++;
@@ -556,18 +683,46 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
* i.e., if P = (x, y) then F(P) = x.
*/
klen = l_ecc_point_get_x(k_point, k, sizeof(k));
-
l_ecc_point_free(k_point);
if (klen < 0)
- goto reject;
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
+
+ /*
+ * keyseed = H(salt, k)
+ *
+ * 802.11-2020 12.4.5.4:
+ * Hash to Element case:
+ * "... a salt consisting of the concatenation of the rejected groups
+ * from each peer's Rejected Groups element shall be
+ * passed to the KDF; those of the peer with the highest MAC address go
+ * first (if only one sent a Rejected Groups element then the salt will
+ * consist of that list). "
+ *
+ * Looping case:
+ * "...the salt shall consist of a series of octets of the value zero
+ * whose length equals the length of the digest of the hash function
+ * used to instantiate H()."
+ *
+ * NOTE: We use hkdf_extract here since it is just an hmac invocation
+ * and it handles the case of the zero key for us.
+ */
+ if (sm->sae_type != CRYPTO_SAE_LOOPING && sm->rejected_groups) {
+ salt = sm->rejected_groups + 1;
+ salt_len = sm->rejected_groups[0] * sizeof(uint16_t);
+ }
- /* keyseed = H(<0>32, k) */
- hmac_sha256(zero_key, 32, k, klen, keyseed, 32);
+ hkdf_extract(hash, salt, salt_len, 1, keyseed, k, klen);
/*
- * kck_and_pmk = KDF-Hash-512(keyseed, "SAE KCK and PMK",
- (commit-scalar + peer-commit-scalar) mod r)
+ * context = (commit-scalar + peer-commit-scalar) mod r
+ * Length = Q + 256
+ * kck_and_pmk = KDF-Hash-Length(keyseed, "SAE KCK and PMK", context)
+ * KCK = L(kck_and_pmk, 0, Q)
+ * PMK = L(kck_and_pmk, Q, 256)
+ *
+ * Q is the length of the digest of the H(), the hash function used
*/
tmp_scalar = l_ecc_scalar_new(sm->curve, NULL, 0);
order = l_ecc_curve_get_order(sm->curve);
@@ -575,11 +730,12 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
l_ecc_scalar_add(tmp_scalar, sm->p_scalar, sm->scalar, order);
l_ecc_scalar_get_data(tmp_scalar, tmp, sizeof(tmp));
- kdf_sha256(keyseed, 32, "SAE KCK and PMK", strlen("SAE KCK and PMK"),
- tmp, nbytes, kck_and_pmk, 64);
+ crypto_kdf(hash, keyseed, hash_len,
+ "SAE KCK and PMK", strlen("SAE KCK and PMK"),
+ tmp, nbytes, kck_and_pmk, hash_len + 32);
- memcpy(sm->kck, kck_and_pmk[0], 32);
- memcpy(sm->pmk, kck_and_pmk[1], 32);
+ memcpy(sm->kck, kck_and_pmk, hash_len);
+ memcpy(sm->pmk, kck_and_pmk + hash_len, 32);
/*
* PMKID = L((commit-scalar + peer-commit-scalar) mod r, 0, 128)
@@ -593,27 +749,27 @@ static int sae_process_commit(struct sae_sm *sm, const uint8_t *from,
/* don't set the handshakes pmkid until confirm is verified */
memcpy(sm->pmkid, tmp, 16);
- sae_send_confirm(sm);
+ if (!sae_send_confirm(sm))
+ return -EPROTO;
- return 0;
+ sm->state = SAE_STATE_CONFIRMED;
-reject:
- sae_reject_authentication(sm, reason);
- return -EBADMSG;
+ return 0;
}
static bool sae_verify_confirm(struct sae_sm *sm, const uint8_t *frame)
{
- uint8_t check[32];
+ uint8_t check[SAE_MAX_HASH_LEN];
uint16_t rc = l_get_le16(frame);
+ ssize_t r;
- sae_cn(sm->kck, rc, sm->p_scalar, sm->p_element, sm->scalar,
+ r = sae_cn(sm, rc, sm->p_scalar, sm->p_element, sm->scalar,
sm->element, check);
+ if (r < 0)
+ return false;
- if (memcmp(frame + 2, check, 32)) {
- l_error("confirm did not match");
+ if (memcmp(frame + 2, check, r))
return false;
- }
sm->rc = rc;
@@ -625,19 +781,18 @@ static int sae_process_confirm(struct sae_sm *sm, const uint8_t *from,
{
const uint8_t *ptr = frame;
- if (sm->state != SAE_STATE_CONFIRMED) {
- l_error("bad state %u", sm->state);
- goto reject;
- }
-
- if (len < 34) {
- l_error("bad length");
- goto reject;
+ /*
+ * If processing is unsuccessful and the SAE Confirm message is not
+ * verified, protocol instance shall remain in Confirmed state.
+ *
+ * NOTE: We diverge from the protocol here and bail out early
+ */
+ if (!sae_verify_confirm(sm, ptr)) {
+ l_error("SAE: Confirm could not be verified");
+ return sae_reject(sm, SAE_STATE_CONFIRMED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
}
- if (!sae_verify_confirm(sm, ptr))
- goto reject;
-
/* Sc shall be set to the value 2^16 - 1 */
sm->sc = 0xffff;
@@ -649,25 +804,21 @@ static int sae_process_confirm(struct sae_sm *sm, const uint8_t *from,
sm->tx_assoc(sm->user_data);
return 0;
-
-reject:
- sae_reject_authentication(sm, MMPDU_REASON_CODE_UNSPECIFIED);
- return -EBADMSG;
}
static bool sae_send_commit(struct sae_sm *sm, bool retry)
{
struct handshake_state *hs = sm->handshake;
- /* regular commit + possible 256 byte token + 6 bytes header */
- uint8_t commit[L_ECC_SCALAR_MAX_BYTES + L_ECC_POINT_MAX_BYTES + 262];
- size_t len;
+ /* regular commit + 3x IEs (257 bytes) + 6 bytes header */
+ uint8_t commit[L_ECC_SCALAR_MAX_BYTES + L_ECC_POINT_MAX_BYTES + 777];
+ int r;
- if (!sae_build_commit(sm, hs->spa, hs->aa, commit, &len, retry))
+ r = sae_build_commit(sm, hs->spa, hs->aa,
+ commit, sizeof(commit), retry);
+ if (r < 0)
return false;
- sm->state = SAE_STATE_COMMITTED;
-
- sm->tx_auth(commit, len, sm->user_data);
+ sm->tx_auth(commit, r, sm->user_data);
return true;
}
@@ -694,10 +845,42 @@ static bool sae_assoc_timeout(struct auth_proto *ap)
* sent. The new SAE Commit message shall be transmitted to the peer, Sync shall
* be zeroed, and the t0 (retransmission) timer shall be set.
*/
-static void sae_process_anti_clogging(struct sae_sm *sm, const uint8_t *ptr,
+static int sae_process_anti_clogging(struct sae_sm *sm, const uint8_t *ptr,
size_t len)
{
/*
+ * 802.11 doesn't talk about validating the group of the Anti-Clogging
+ * Request message. We assume here that the group is something that
+ * we would have potentially sent
+ */
+ if (len < 2)
+ return -EBADMSG;
+
+ if (sae_valid_group(sm, l_get_le16(ptr)) < 0)
+ return -EBADMSG;
+
+ len -= 2;
+ ptr += 2;
+
+ /*
+ * 802.11-2020, Table 9-41:
+ * When the hash-to-element method is used to derive the PWE, the
+ * Anti-Clogging Token Container element is present if the
+ * Status Code field is ANTI_CLOGGING_TOKEN_REQUIRED
+ */
+ if (sm->sae_type != CRYPTO_SAE_LOOPING) {
+ if (len < 3)
+ return -EBADMSG;
+
+ if (ptr[0] != IE_TYPE_EXTENSION || ptr[2] != 93 ||
+ ptr[1] < 2 || len < ptr[1] + 2u)
+ return -EBADMSG;
+
+ len = ptr[1] - 1;
+ ptr += 3;
+ }
+
+ /*
* IEEE 802.11-2016 - Section 12.4.6 Anti-clogging tokens
*
* "It is suggested that an Anti-Clogging Token not exceed 256 octets"
@@ -707,16 +890,19 @@ static void sae_process_anti_clogging(struct sae_sm *sm, const uint8_t *ptr,
* going to be 2 bytes less than the passed in length. This is why we
* are checking 3 > len > 258.
*/
- if (len < 3 || len > 258) {
+ if (len < 1 || len > 256) {
l_error("anti-clogging token size invalid %zu", len);
- return;
+ return -EBADMSG;
}
- sm->token = l_memdup(ptr + 2, len - 2);
- sm->token_len = len - 2;
+ l_free(sm->token);
+ sm->token = l_memdup(ptr, len);
+ sm->token_len = len;
sm->sync = 0;
sae_send_commit(sm, true);
+
+ return -EAGAIN;
}
/*
@@ -742,34 +928,13 @@ static int sae_verify_nothing(struct sae_sm *sm, uint16_t transaction,
return -EBADMSG;
/* reject with unsupported group */
- if (l_get_le16(frame) != sm->group) {
- sae_reject_authentication(sm,
+ if (l_get_le16(frame) != sm->group)
+ return sae_reject(sm, SAE_STATE_COMMITTED,
MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
- return -EBADMSG;
- }
return 0;
}
-static void sae_reset_state(struct sae_sm *sm)
-{
- l_free(sm->token);
- sm->token = NULL;
-
- l_ecc_scalar_free(sm->scalar);
- sm->scalar = NULL;
- l_ecc_scalar_free(sm->p_scalar);
- sm->p_scalar = NULL;
- l_ecc_scalar_free(sm->rand);
- sm->rand = NULL;
- l_ecc_point_free(sm->element);
- sm->element = NULL;
- l_ecc_point_free(sm->p_element);
- sm->p_element = NULL;
- l_ecc_point_free(sm->pwe);
- sm->pwe = NULL;
-}
-
/*
* 802.11-2016 - 12.4.8.6.4 Protocol instance behavior - Committed state
*/
@@ -777,6 +942,9 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction,
uint16_t status, const uint8_t *frame,
size_t len)
{
+ unsigned int skip;
+ struct ie_tlv_iter iter;
+
/*
* Upon receipt of a Con event...
* Then the protocol instance checks the value of Sync. If it
@@ -788,20 +956,18 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction,
*/
if (transaction == SAE_STATE_CONFIRMED) {
if (sm->sync > SAE_SYNC_MAX)
- return -EBADMSG;
+ return -ETIMEDOUT;
sm->sync++;
-
sae_send_commit(sm, true);
return -EAGAIN;
}
- switch (status) {
- case MMPDU_STATUS_CODE_ANTI_CLOGGING_TOKEN_REQ:
- sae_process_anti_clogging(sm, frame, len);
- return -EAGAIN;
- case MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP:
+ if (status == MMPDU_STATUS_CODE_ANTI_CLOGGING_TOKEN_REQ)
+ return sae_process_anti_clogging(sm, frame, len);
+
+ if (status == MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP) {
/*
* TODO: hostapd in its current state does not include the
* group number as it should. This is a violation of the spec,
@@ -822,19 +988,9 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction,
if (len == 0)
l_warn("AP did not include group number in response!");
else if (len >= 2 && (l_get_le16(frame) != sm->group))
- return -EBADMSG;
+ return -ENOMSG;
- sm->group_retry++;
-
- if (sm->ecc_groups[sm->group_retry] == 0) {
- /*
- * "If there are no other groups to choose, the protocol
- * instance shall send a Del event to the parent process
- * and transitions back to Nothing state"
- */
- sm->state = SAE_STATE_NOTHING;
- goto reject_unsupp_group;
- }
+ sae_rejected_groups_append(sm, L_CPU_TO_LE16(sm->group));
/*
* "If the rejected group matches the last offered group, the
@@ -844,97 +1000,88 @@ static int sae_verify_committed(struct sae_sm *sm, uint16_t transaction,
* zeros Sync, sets the t0 (retransmission) timer, and remains
* in Committed state"
*/
-
- sae_reset_state(sm);
-
- sm->group = sm->ecc_groups[sm->group_retry];
- sm->curve = l_ecc_curve_get_ike_group(sm->group);
+ if (sae_choose_next_group(sm) < 0) {
+ /*
+ * "If there are no other groups to choose, the protocol
+ * instance shall send a Del event to the parent process
+ * and transitions back to Nothing state"
+ */
+ sm->state = SAE_STATE_NOTHING;
+ goto reject_unsupp_group;
+ }
sm->sync = 0;
-
sae_send_commit(sm, false);
return -EAGAIN;
- case 0:
- if (len < 2)
- return -EBADMSG;
-
- if (l_get_le16(frame) == sm->group)
- return 0;
-
- if (!l_ecc_curve_get_ike_group(l_get_le16(frame))) {
- if (sm->sync > SAE_SYNC_MAX)
- return -EBADMSG;
+ }
- sm->sync++;
+ /*
+ * If the Status is some other nonzero value, the frame shall be
+ * silently discarded and the t0 (retransmission) timer shall be set.
+ */
+ if (status != 0 && status != MMPDU_STATUS_CODE_SAE_HASH_TO_ELEMENT)
+ return -ENOMSG;
- goto reject_unsupp_group;
- }
+ if (status != sae_status_code(sm))
+ return -EBADMSG;
- /*
- * If we get here we know that the groups do not match, but the
- * group provided in the frame is supported. From section
- * 12.4.8.6.4 we see:
- *
- * "If the group is supported but does not match that used when
- * the protocol instance constructed its SAE Commit message,
- * DiffGrp shall be set and the local identity and peer identity
- * shall be checked"
- */
+ if (len < 2)
+ return -EBADMSG;
- if (memcmp(sm->handshake->spa, sm->handshake->aa, 6) > 0) {
- /*
- * "The mesh STA, with the numerically greater of the two
- * MAC addresses, drops the received SAE Commit message,
- * retransmits its last SAE Commit message, and shall
- * set the t0 (retransmission) timer and remain in
- * Committed state"
- */
- sae_send_commit(sm, true);
+ if (l_get_le16(frame) != sm->group) {
+ l_error("SAE: Peer tried to change group -- Reject");
+ goto reject_unsupp_group;
+ }
- return 0;
- }
+ len -= 2;
+ frame += 2;
- /*
- * "The mesh STA, with the numerically lesser of the two
- * MAC addresses, zeros Sync, shall increment Sc, choose
- * the group from the received SAE Commit message,
- * generate new PWE and new secret values according to
- * 12.4.5.2, process the received SAE Commit message
- * according to 12.4.5.4, generate a new SAE Commit
- * message and SAE Confirm message, and shall transmit
- * the new Commit and Confirm to the peer. It shall then
- * transition to Confirmed state."
- */
- sm->sync = 0;
- sm->sc++;
- sm->group = l_get_le16(frame);
- sm->curve = l_ecc_curve_get_ike_group(sm->group);
+ skip = l_ecc_curve_get_scalar_bytes(sm->curve) * 3;
+ if (len < skip)
+ return -EBADMSG;
- sae_send_commit(sm, false);
+ /* If H2E isn't being used, there should be no IEs in use */
+ if (status == 0)
+ return 0;
- sm->state = SAE_STATE_CONFIRMED;
+ len -= skip;
+ frame += skip;
- /*
- * The processing and sending of the confirm message
- * will happen after we return. Since we have set the
- * state to CONFIRMED, our confirm handler will get
- * called.
- */
+ ie_tlv_iter_init(&iter, frame, len);
- return 0;
- default:
+ while (ie_tlv_iter_next(&iter)) {
+ switch (ie_tlv_iter_get_tag(&iter)) {
/*
- * If the Status is some other nonzero value, the frame shall
- * be silently discarded...
+ * If the peer's SAE Commit message contains a Rejected Groups
+ * element, the list of rejected groups shall be checked to
+ * ensure that all of the groups in the list are groups that
+ * would be rejected. If any groups in the list would not be
+ * rejected then processing of the SAE Commit message
+ * terminates and the STA shall reject the peer's
+ * authentication.
+ *
+ * NOTE: We currently only support the Initiator role, and so
+ * do not reject any groups. We should never receive this
+ * element
*/
- return 0;
+ case IE_TYPE_REJECTED_GROUPS:
+ l_error("SAE: Unexpected Rejected Groups IE");
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
+ /* We don't request tokens, so we shouldn't get any */
+ case IE_TYPE_ANTI_CLOGGING_TOKEN_CONTAINER:
+ l_error("SAE: Unexpected Anti-Clogging Container IE");
+ return sae_reject(sm, SAE_STATE_COMMITTED,
+ MMPDU_STATUS_CODE_UNSPECIFIED);
+ }
}
+ return 0;
+
reject_unsupp_group:
- sae_reject_authentication(sm,
+ return sae_reject(sm, SAE_STATE_COMMITTED,
MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
- return MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP;
}
/*
@@ -944,14 +1091,35 @@ static int sae_verify_confirmed(struct sae_sm *sm, uint16_t trans,
uint16_t status, const uint8_t *frame,
size_t len)
{
- if (trans == SAE_STATE_CONFIRMED)
+ if (trans == SAE_STATE_CONFIRMED) {
+ enum l_checksum_type hash =
+ crypto_sae_hash_from_ecc_prime_len(sm->sae_type,
+ l_ecc_curve_get_scalar_bytes(sm->curve));
+ size_t hash_len = l_checksum_digest_length(hash);
+
+ /* Most likely the password is wrong */
+ if (status == MMPDU_STATUS_CODE_UNSPECIFIED && len == 0)
+ return -ENOKEY;
+
+ if (status != MMPDU_STATUS_CODE_SUCCESS)
+ return -EPROTO;
+
+ if (len < hash_len + 2) {
+ l_error("SAE: Confirm packet too short");
+ return -EBADMSG;
+ }
+
return 0;
+ }
/*
- * If the Status is nonzero, the frame shall be silently discarded...
+ * Upon receipt of a Com event, the t0 (retransmission) timer shall be
+ * canceled. If the Status is nonzero, the frame shall be silently
+ * discarded, the t0 (retransmission) timer set, and the protocol
+ * instance shall remain in the Confirmed state.
*/
if (status != 0)
- return 0;
+ return -ENOMSG;
/*
* If Sync is greater than dot11RSNASAESync, the protocol instance
@@ -959,14 +1127,14 @@ static int sae_verify_confirmed(struct sae_sm *sm, uint16_t trans,
* Nothing state.
*/
if (sm->sync > SAE_SYNC_MAX)
- return -EBADMSG;
+ return -ETIMEDOUT;
if (len < 2)
return -EBADMSG;
/* frame shall be silently discarded */
if (l_get_le16(frame) != sm->group)
- return 0;
+ return -EBADMSG;
/*
* the protocol instance shall increment Sync, increment Sc, and
@@ -976,9 +1144,11 @@ static int sae_verify_confirmed(struct sae_sm *sm, uint16_t trans,
sm->sc++;
sae_send_commit(sm, true);
- sae_send_confirm(sm);
- return 0;
+ if (!sae_send_confirm(sm))
+ return -EPROTO;
+
+ return -EAGAIN;
}
/*
@@ -997,7 +1167,7 @@ static int sae_verify_accepted(struct sae_sm *sm, uint16_t trans,
}
if (sm->sync > SAE_SYNC_MAX)
- return -EBADMSG;
+ return -ETIMEDOUT;
if (len < 2)
return -EBADMSG;
@@ -1028,9 +1198,10 @@ static int sae_verify_accepted(struct sae_sm *sm, uint16_t trans,
sm->sync++;
sm->sc = 0xffff;
- sae_send_confirm(sm);
+ if (!sae_send_confirm(sm))
+ return -EPROTO;
- return 0;
+ return -EAGAIN;
}
static int sae_verify_packet(struct sae_sm *sm, uint16_t trans,
@@ -1052,24 +1223,17 @@ static int sae_verify_packet(struct sae_sm *sm, uint16_t trans,
}
/* should never get here */
- return -1;
+ return -EPROTO;
}
static int sae_rx_authenticate(struct auth_proto *ap,
const uint8_t *frame, size_t len)
{
struct sae_sm *sm = l_container_of(ap, struct sae_sm, ap);
- const struct mmpdu_header *hdr = mpdu_validate(frame, len);
- const struct mmpdu_authentication *auth;
+ const struct mmpdu_header *hdr = (const struct mmpdu_header *) frame;
+ const struct mmpdu_authentication *auth = mmpdu_body(hdr);
int ret;
- if (!hdr) {
- l_debug("Auth frame header did not validate");
- goto reject;
- }
-
- auth = mmpdu_body(hdr);
-
len -= mmpdu_header_len(hdr);
ret = sae_verify_packet(sm, L_LE16_TO_CPU(auth->transaction_sequence),
@@ -1090,28 +1254,18 @@ static int sae_rx_authenticate(struct auth_proto *ap,
L_LE16_TO_CPU(auth->transaction_sequence));
}
-reject:
- sae_reject_authentication(sm, MMPDU_REASON_CODE_UNSPECIFIED);
-
- return -EBADMSG;
+ /* should never get here */
+ return -EPROTO;
}
static int sae_rx_associate(struct auth_proto *ap, const uint8_t *frame,
size_t len)
{
- const struct mmpdu_header *mpdu = NULL;
- const struct mmpdu_association_response *body;
-
- mpdu = mpdu_validate(frame, len);
- if (!mpdu) {
- l_error("could not process frame");
- return -EBADMSG;
- }
-
- body = mmpdu_body(mpdu);
+ const struct mmpdu_header *mpdu = (const struct mmpdu_header *)frame;
+ const struct mmpdu_association_response *body = mmpdu_body(mpdu);
if (body->status_code != 0)
- return L_LE16_TO_CPU(body->status_code);
+ return -EPROTO;
return 0;
}
@@ -1125,15 +1279,37 @@ static bool sae_start(struct auth_proto *ap)
else
memcpy(sm->peer, sm->handshake->aa, 6);
+ if (sm->sae_type == CRYPTO_SAE_LOOPING && !sm->handshake->passphrase) {
+ l_error("SAE: No passphrase set");
+ return false;
+ }
+
+ if (sae_choose_next_group(sm) < 0)
+ return false;
+
+ sm->state = SAE_STATE_COMMITTED;
return sae_send_commit(sm, false);
}
+bool sae_sm_is_h2e(struct auth_proto *ap)
+{
+ struct sae_sm *sm = l_container_of(ap, struct sae_sm, ap);
+
+ return sm->sae_type != CRYPTO_SAE_LOOPING;
+}
+
static void sae_free(struct auth_proto *ap)
{
struct sae_sm *sm = l_container_of(ap, struct sae_sm, ap);
sae_reset_state(sm);
+ l_free(sm->token);
+ sm->token = NULL;
+
+ if (sm->rejected_groups)
+ free(sm->rejected_groups);
+
/* zero out whole structure, including keys */
explicit_bzero(sm, sizeof(struct sae_sm));
@@ -1146,20 +1322,17 @@ struct auth_proto *sae_sm_new(struct handshake_state *hs,
void *user_data)
{
struct sae_sm *sm;
+ const void *rsnxe;
sm = l_new(struct sae_sm, 1);
- if (!sm)
- return NULL;
+ sm->group_retry = -1;
sm->tx_auth = tx_auth;
sm->tx_assoc = tx_assoc;
sm->user_data = user_data;
sm->handshake = hs;
sm->state = SAE_STATE_NOTHING;
- sm->ecc_groups = l_ecc_curve_get_supported_ike_groups();
- sm->group = sm->ecc_groups[sm->group_retry];
- sm->curve = l_ecc_curve_get_ike_group(sm->group);
sm->ap.start = sae_start;
sm->ap.free = sae_free;
@@ -1167,5 +1340,16 @@ struct auth_proto *sae_sm_new(struct handshake_state *hs,
sm->ap.rx_associate = sae_rx_associate;
sm->ap.assoc_timeout = sae_assoc_timeout;
+ rsnxe = hs->authenticator ? hs->supplicant_rsnxe :
+ hs->authenticator_rsnxe;
+
+ if (ie_rsnxe_capable(rsnxe, IE_RSNX_SAE_H2E) && hs->ecc_sae_pts) {
+ l_debug("Using SAE H2E");
+ sm->sae_type = CRYPTO_SAE_HASH_TO_ELEMENT;
+ } else {
+ l_debug("Using SAE Hunting and Pecking");
+ sm->sae_type = CRYPTO_SAE_LOOPING;
+ }
+
return &sm->ap;
}
diff --git a/src/sae.h b/src/sae.h
@@ -20,6 +20,7 @@
*
*/
+struct auth_proto;
struct sae_sm;
struct handshake_state;
@@ -27,6 +28,8 @@ typedef void (*sae_tx_authenticate_func_t)(const uint8_t *data, size_t len,
void *user_data);
typedef void (*sae_tx_associate_func_t)(void *user_data);
+bool sae_sm_is_h2e(struct auth_proto *ap);
+
struct auth_proto *sae_sm_new(struct handshake_state *hs,
sae_tx_authenticate_func_t tx_auth,
sae_tx_associate_func_t tx_assoc,
diff --git a/src/scan.c b/src/scan.c
@@ -490,7 +490,7 @@ static bool scan_cmds_add_hidden(const struct network_info *network,
{
struct scan_cmds_add_data *data = user_data;
- if (!network->is_hidden)
+ if (!network->config.is_hidden)
return true;
l_genl_msg_append_attr(*data->cmd, NL80211_ATTR_SSID,
@@ -1004,6 +1004,11 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
bss->rsne = l_memdup(iter.data - 2,
iter.len + 2);
break;
+ case IE_TYPE_RSNX:
+ if (!bss->rsnxe)
+ bss->rsnxe = l_memdup(iter.data - 2,
+ iter.len + 2);
+ break;
case IE_TYPE_BSS_LOAD:
if (ie_parse_bss_load(&iter, NULL, &bss->utilization,
NULL) < 0)
@@ -1230,11 +1235,15 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr,
bss->data_rate = 2000000;
if (ies) {
+ int ret;
+
if (!scan_parse_bss_information_elements(bss, ies, ies_len))
goto fail;
- L_WARN_ON(wiphy_estimate_data_rate(wiphy, ies, ies_len, bss,
- &bss->data_rate) < 0);
+ ret = wiphy_estimate_data_rate(wiphy, ies, ies_len, bss,
+ &bss->data_rate);
+ if (ret < 0 && ret != -ENETUNREACH)
+ l_warn("wiphy_estimate_data_rate() failed");
}
return bss;
@@ -1351,6 +1360,7 @@ fail:
void scan_bss_free(struct scan_bss *bss)
{
l_free(bss->rsne);
+ l_free(bss->rsnxe);
l_free(bss->wpa);
l_free(bss->wsc);
l_free(bss->osen);
diff --git a/src/scan.h b/src/scan.h
@@ -51,6 +51,7 @@ struct scan_bss {
int32_t signal_strength;
uint16_t capability;
uint8_t *rsne;
+ uint8_t *rsnxe;
uint8_t *wpa;
uint8_t *osen;
uint8_t *wsc; /* Concatenated WSC IEs */
diff --git a/src/station.c b/src/station.c
@@ -706,8 +706,8 @@ static void station_handshake_event(struct handshake_state *hs,
case HANDSHAKE_EVENT_SETTING_KEYS:
l_debug("Setting keys");
- /* If we got here, then our PSK works. Save if required */
- network_sync_psk(network);
+ /* If we got here, then our settings work. Update if needed */
+ network_sync_settings(network);
break;
case HANDSHAKE_EVENT_FAILED:
netdev_handshake_failed(hs, va_arg(args, int));
@@ -716,6 +716,14 @@ static void station_handshake_event(struct handshake_state *hs,
l_warn("Unable to securely rekey on this hw/kernel...");
station_reconnect(station);
break;
+ case HANDSHAKE_EVENT_TRANSITION_DISABLE:
+ {
+ const uint8_t *td = va_arg(args, const uint8_t *);
+ size_t len = va_arg(args, size_t);
+
+ network_set_transition_disable(network, td, len);
+ break;
+ }
case HANDSHAKE_EVENT_COMPLETE:
case HANDSHAKE_EVENT_SETTING_KEYS_FAILED:
case HANDSHAKE_EVENT_EAP_NOTIFY:
@@ -760,7 +768,8 @@ static int station_build_handshake_rsn(struct handshake_state *hs,
if (security == SECURITY_8021X && hs->support_fils)
fils_hint = network_has_erp_identity(network);
- info.akm_suites = wiphy_select_akm(wiphy, bss, fils_hint);
+ info.akm_suites = wiphy_select_akm(wiphy, bss, security,
+ &bss_info, fils_hint);
/*
* Special case for OWE. With OWE we still need to build up the
@@ -867,16 +876,8 @@ static struct handshake_state *station_handshake_setup(struct station *station,
struct network *network,
struct scan_bss *bss)
{
- enum security security = network_get_security(network);
- struct l_settings *settings = network_get_settings(network);
struct wiphy *wiphy = station->wiphy;
struct handshake_state *hs;
- const char *ssid;
- uint32_t eapol_proto_version;
- const char *value;
- bool full_random;
- bool override = false;
- uint8_t new_addr[ETH_ALEN];
hs = netdev_handshake_state_new(station->netdev);
@@ -885,45 +886,10 @@ static struct handshake_state *station_handshake_setup(struct station *station,
if (station_build_handshake_rsn(hs, wiphy, network, bss) < 0)
goto not_supported;
- ssid = network_get_ssid(network);
- handshake_state_set_ssid(hs, (void *) ssid, strlen(ssid));
+ handshake_state_set_authenticator_rsnxe(hs, bss->rsnxe);
- if (settings && l_settings_get_uint(settings, "EAPoL",
- "ProtocolVersion",
- &eapol_proto_version)) {
- if (eapol_proto_version > 3) {
- l_warn("Invalid ProtocolVersion value - should be 0-3");
- eapol_proto_version = 0;
- }
-
- if (eapol_proto_version)
- l_debug("Overriding EAPoL protocol version to: %u",
- eapol_proto_version);
-
- handshake_state_set_protocol_version(hs, eapol_proto_version);
- }
-
- if (security == SECURITY_PSK) {
- /* SAE will generate/set the PMK */
- if (IE_AKM_IS_SAE(hs->akm_suite)) {
- const char *passphrase =
- network_get_passphrase(network);
-
- if (!passphrase)
- goto no_psk;
-
- handshake_state_set_passphrase(hs, passphrase);
- } else {
- const uint8_t *psk = network_get_psk(network);
-
- if (!psk)
- goto no_psk;
-
- handshake_state_set_pmk(hs, psk, 32);
- }
- } else if (security == SECURITY_8021X)
- handshake_state_set_8021x_config(hs,
- network_get_settings(network));
+ if (network_handshake_setup(network, hs) < 0)
+ goto not_supported;
/*
* If FILS was chosen, the ERP cache has been verified to exist. We
@@ -936,49 +902,10 @@ static struct handshake_state *station_handshake_setup(struct station *station,
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384))
hs->erp_cache = erp_cache_get(network_get_ssid(network));
- /*
- * We have three possible options here:
- * 1. per-network MAC generation (default, no option in network config)
- * 2. per-network full MAC randomization
- * 3. per-network MAC override
- */
-
- if (!l_settings_get_bool(settings, "Settings",
- "AlwaysRandomizeAddress",
- &full_random))
- full_random = false;
-
- value = l_settings_get_value(settings, "Settings",
- "AddressOverride");
- if (value) {
- if (util_string_to_address(value, new_addr) &&
- util_is_valid_sta_address(new_addr))
- override = true;
- else
- l_warn("[Network].AddressOverride is not a valid "
- "MAC address");
- }
-
- if (override && full_random) {
- l_warn("Cannot use both AlwaysRandomizeAddress and "
- "AddressOverride concurrently, defaulting to override");
- full_random = false;
- }
-
- if (override)
- handshake_state_set_supplicant_address(hs, new_addr);
- else if (full_random) {
- wiphy_generate_random_address(wiphy, new_addr);
- handshake_state_set_supplicant_address(hs, new_addr);
- }
-
return hs;
-no_psk:
- l_warn("Missing network PSK/passphrase");
not_supported:
handshake_state_free(hs);
-
return NULL;
}
@@ -1221,9 +1148,6 @@ static void station_enter_state(struct station *station,
periodic_scan_stop(station);
break;
case STATION_STATE_DISCONNECTING:
- l_dbus_object_remove_interface(dbus_get_bus(),
- netdev_get_path(station->netdev),
- IWD_STATION_DIAGNOSTIC_INTERFACE);
break;
case STATION_STATE_ROAMING:
break;
@@ -1330,6 +1254,8 @@ static void station_reset_connection_state(struct station *station)
IWD_STATION_INTERFACE, "ConnectedNetwork");
l_dbus_property_changed(dbus, network_get_path(network),
IWD_NETWORK_INTERFACE, "Connected");
+ l_dbus_object_remove_interface(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_DIAGNOSTIC_INTERFACE);
#endif
}
@@ -1912,7 +1838,6 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
uint16_t mdid;
enum security orig_security, security;
bool seen = false;
- bool fils_hint = network_has_erp_identity(network);
if (err) {
station_roam_failed(station);
@@ -1969,7 +1894,7 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
seen = true;
- if (!wiphy_can_connect(station->wiphy, bss, fils_hint))
+ if (network_can_connect_bss(network, bss) < 0)
goto next;
if (blacklist_contains_bss(bss->addr))
@@ -3801,6 +3726,9 @@ static struct l_dbus_message *station_get_diagnostics(struct l_dbus *dbus,
struct station *station = user_data;
int ret;
+ if (station->get_station_pending)
+ return dbus_error_busy(message);
+
ret = netdev_get_current_station(station->netdev,
station_get_diagnostic_cb, station,
station_get_diagnostic_destroy);
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -131,6 +131,24 @@ enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask)
static bool wiphy_can_connect_sae(struct wiphy *wiphy)
{
/*
+ * WPA3 Specification version 3, Section 2.2:
+ * A STA shall not enable WEP and TKIP
+ */
+ if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_CCMP)) {
+ l_debug("HW not CCMP capable, can't use SAE");
+ return false;
+ }
+
+ /*
+ * WPA3 Specification version 3, Section 2.3:
+ * A STA shall negotiate PMF when associating to an AP using SAE
+ */
+ if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP)) {
+ l_debug("HW not MFP capable, can't use SAE");
+ return false;
+ }
+
+ /*
* SAE support in the kernel is a complete mess in that there are 3
* different ways the hardware can support SAE:
*
@@ -175,19 +193,14 @@ static bool wiphy_can_connect_sae(struct wiphy *wiphy)
}
enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
- struct scan_bss *bss,
+ const struct scan_bss *bss,
+ enum security security,
+ const struct ie_rsn_info *info,
bool fils_capable_hint)
{
- struct ie_rsn_info info;
- enum security security;
bool psk_offload = wiphy_has_ext_feature(wiphy,
NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK);
- memset(&info, 0, sizeof(info));
- scan_bss_get_rsn_info(bss, &info);
-
- security = security_determine(bss->capability, &info);
-
/*
* If FT is available, use FT authentication to keep the door open
* for fast transitions. Otherwise use SHA256 version if present.
@@ -195,32 +208,32 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
if (security == SECURITY_8021X) {
if (wiphy_has_feature(wiphy, NL80211_EXT_FEATURE_FILS_STA) &&
fils_capable_hint) {
- if ((info.akm_suites &
+ if ((info->akm_suites &
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384) &&
bss->rsne && bss->mde_present)
return IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384;
- if ((info.akm_suites &
+ if ((info->akm_suites &
IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256) &&
bss->rsne && bss->mde_present)
return IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256;
- if (info.akm_suites & IE_RSN_AKM_SUITE_FILS_SHA384)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_FILS_SHA384)
return IE_RSN_AKM_SUITE_FILS_SHA384;
- if (info.akm_suites & IE_RSN_AKM_SUITE_FILS_SHA256)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_FILS_SHA256)
return IE_RSN_AKM_SUITE_FILS_SHA256;
}
- if ((info.akm_suites & IE_RSN_AKM_SUITE_FT_OVER_8021X) &&
+ if ((info->akm_suites & IE_RSN_AKM_SUITE_FT_OVER_8021X) &&
bss->rsne && bss->mde_present &&
wiphy->support_cmds_auth_assoc)
return IE_RSN_AKM_SUITE_FT_OVER_8021X;
- if (info.akm_suites & IE_RSN_AKM_SUITE_8021X_SHA256)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_8021X_SHA256)
return IE_RSN_AKM_SUITE_8021X_SHA256;
- if (info.akm_suites & IE_RSN_AKM_SUITE_8021X)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_8021X)
return IE_RSN_AKM_SUITE_8021X;
} else if (security == SECURITY_PSK) {
/*
@@ -229,23 +242,17 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
* MFPR/MFPC bits correctly. If any of these conditions are not
* met, we can fallback to WPA2 (if the AKM is present).
*/
- if (ie_rsne_is_wpa3_personal(&info)) {
+ if (ie_rsne_is_wpa3_personal(info)) {
l_debug("Network is WPA3-Personal...");
- if (!(wiphy->supported_ciphers &
- IE_RSN_CIPHER_SUITE_BIP)) {
- l_debug("HW not MFP capable, trying WPA2");
- goto wpa2_personal;
- }
-
if (!wiphy_can_connect_sae(wiphy))
goto wpa2_personal;
- if (info.akm_suites &
+ if (info->akm_suites &
IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256)
return IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256;
- if (info.akm_suites & IE_RSN_AKM_SUITE_SAE_SHA256)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_SAE_SHA256)
return IE_RSN_AKM_SUITE_SAE_SHA256;
}
@@ -255,20 +262,20 @@ wpa2_personal:
* supports PSK offload. Without Auth/Assoc, PSK offload is the
* only mechanism to allow FT on these cards.
*/
- if ((info.akm_suites & IE_RSN_AKM_SUITE_FT_USING_PSK) &&
+ if ((info->akm_suites & IE_RSN_AKM_SUITE_FT_USING_PSK) &&
bss->rsne && bss->mde_present) {
if (wiphy->support_cmds_auth_assoc ||
(psk_offload && wiphy->support_fw_roam))
return IE_RSN_AKM_SUITE_FT_USING_PSK;
}
- if (info.akm_suites & IE_RSN_AKM_SUITE_PSK_SHA256)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_PSK_SHA256)
return IE_RSN_AKM_SUITE_PSK_SHA256;
- if (info.akm_suites & IE_RSN_AKM_SUITE_PSK)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_PSK)
return IE_RSN_AKM_SUITE_PSK;
} else if (security == SECURITY_NONE) {
- if (info.akm_suites & IE_RSN_AKM_SUITE_OWE)
+ if (info->akm_suites & IE_RSN_AKM_SUITE_OWE)
return IE_RSN_AKM_SUITE_OWE;
}
@@ -411,28 +418,16 @@ const struct scan_freq_set *wiphy_get_supported_freqs(
return wiphy->supported_freqs;
}
-bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss,
- bool fils_hint)
+bool wiphy_can_transition_disable(struct wiphy *wiphy)
{
- struct ie_rsn_info rsn_info;
- int r;
-
- memset(&rsn_info, 0, sizeof(rsn_info));
- r = scan_bss_get_rsn_info(bss, &rsn_info);
-
- if (r == 0) {
- if (!wiphy_select_cipher(wiphy, rsn_info.pairwise_ciphers))
- return false;
-
- if (!wiphy_select_cipher(wiphy, rsn_info.group_cipher))
- return false;
-
- if (rsn_info.mfpr && !wiphy_select_cipher(wiphy,
- rsn_info.group_management_cipher))
- return false;
+ /*
+ * WPA3 Specification version 3, Section 2.2:
+ * A STA shall not enable WEP and TKIP
+ */
+ if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_CCMP))
+ return false;
- return wiphy_select_akm(wiphy, bss, fils_hint);
- } else if (r != -ENOENT)
+ if (!(wiphy->supported_ciphers & IE_RSN_CIPHER_SUITE_BIP))
return false;
return true;
@@ -539,6 +534,26 @@ const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy)
return wiphy->rm_enabled_capabilities;
}
+bool wiphy_get_rsnxe(const struct wiphy *wiphy, uint8_t *buf, size_t len)
+{
+ if (len < 3)
+ return false;
+
+ buf[0] = IE_TYPE_RSNX;
+ buf[1] = 1;
+
+ /*
+ * Lower 4 bits of the first octet:
+ * The length of the Extended RSN Capabilities field, in octets,
+ * minus 1, i.e., n - 1.
+ */
+ buf[2] = 0;
+
+ /* No other bits set for now */
+
+ return true;
+}
+
static void wiphy_address_constrain(struct wiphy *wiphy, uint8_t addr[static 6])
{
switch (mac_randomize_bytes) {
@@ -756,13 +771,10 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,
out_data_rate))
return 0;
- if (!band_estimate_nonht_rate(bandp, supported_rates,
+ return band_estimate_nonht_rate(bandp, supported_rates,
ext_supported_rates,
bss->signal_strength / 100,
- out_data_rate))
- return 0;
-
- return -ENOTSUP;
+ out_data_rate);
}
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -27,6 +27,8 @@ struct wiphy;
struct scan_bss;
struct scan_freq_set;
struct wiphy_radio_work_item;
+struct ie_rsn_info;
+enum security;
typedef bool (*wiphy_radio_work_func_t)(struct wiphy_radio_work_item *item);
typedef void (*wiphy_radio_work_destroy_func_t)(
@@ -56,7 +58,9 @@ typedef void (*wiphy_destroy_func_t)(void *user_data);
enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy,
uint16_t mask);
enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy,
- struct scan_bss *bss,
+ const struct scan_bss *bss,
+ enum security security,
+ const struct ie_rsn_info *info,
bool fils_capable_hint);
struct wiphy *wiphy_find(int wiphy_id);
@@ -78,8 +82,7 @@ const char *wiphy_get_path(struct wiphy *wiphy);
uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
const struct scan_freq_set *wiphy_get_supported_freqs(
const struct wiphy *wiphy);
-bool wiphy_can_connect(struct wiphy *wiphy, struct scan_bss *bss,
- bool fils_hint);
+bool wiphy_can_transition_disable(struct wiphy *wiphy);
bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy);
bool wiphy_can_randomize_mac_addr(struct wiphy *wiphy);
bool wiphy_rrm_capable(struct wiphy *wiphy);
@@ -101,6 +104,7 @@ const uint8_t *wiphy_get_permanent_address(struct wiphy *wiphy);
const uint8_t *wiphy_get_extended_capabilities(struct wiphy *wiphy,
uint32_t iftype);
const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy);
+bool wiphy_get_rsnxe(const struct wiphy *wiphy, uint8_t *buf, size_t len);
void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out);
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6]);
diff --git a/src/wsc.c b/src/wsc.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <ell/ell.h>
+#include "ell/useful.h"
#include "src/missing.h"
#include "src/module.h"
#include "src/dbus.h"
@@ -40,7 +41,6 @@
#include "src/util.h"
#include "src/handshake.h"
#include "src/eap-wsc.h"
-#include "src/crypto.h"
#include "src/common.h"
#include "src/storage.h"
#include "src/iwd.h"
@@ -525,21 +525,40 @@ static void wsc_store_credentials(struct wsc_credentials_info *creds,
{
unsigned int i;
+ /* We don't store any non-open/psk credentials */
for (i = 0; i < n_creds; i++) {
enum security security = creds[i].security;
const char *ssid = creds[i].ssid;
- struct l_settings *settings = l_settings_new();
+ _auto_(l_settings_free) struct l_settings *settings =
+ l_settings_new();
+ _auto_(l_free) char *path =
+ storage_get_network_file_path(security, ssid);
- l_debug("Storing credential for '%s(%s)'", ssid,
- security_to_str(security));
+ if (l_settings_load_from_file(settings, path)) {
+ /*
+ * Nothing to do,
+ * so don't overwrite any existing settings
+ */
+ if (security == SECURITY_NONE)
+ continue;
+
+ /* Remove any existing Security keys */
+ l_settings_remove_group(settings, "Security");
+ }
- if (security == SECURITY_PSK)
- l_settings_set_bytes(settings, "Security",
+ if (security == SECURITY_PSK) {
+ if (creds[i].has_passphrase)
+ l_settings_set_string(settings, "Security",
+ "Passphrase", creds[i].passphrase);
+ else
+ l_settings_set_bytes(settings, "Security",
"PreSharedKey", creds[i].psk,
sizeof(creds[i].psk));
+ }
+ l_debug("Storing credential for '%s(%s)'", ssid,
+ security_to_str(security));
storage_network_sync(security, ssid, settings);
- l_settings_free(settings);
}
}
diff --git a/tools/test-runner b/tools/test-runner
@@ -175,24 +175,12 @@ class Process:
self.io_watch = None
self.cleanup = cleanup
self.verbose = False
-
- if not namespace:
- self.output_name = '/tmp/%s-out' % self.name
- else:
- self.output_name = '/tmp/%s-%s-out' % (self.name, namespace)
+ self.out = ''
if namespace:
self.args = ['ip', 'netns', 'exec', namespace]
self.args.extend(args)
- #
- # For simplicity all processes will write to a temp file
- # (/tmp/<name>-out). If any verbose options are required this file
- # will get an IO watch and write out any bytes to the needed FDs.
- #
- self.stdout = open(self.output_name, 'a+')
- self.io_position = self.stdout.tell()
-
if ctx:
# Verbose requested, add stdout/stderr to write FD list.
# This will end up always returning true if logging is
@@ -228,18 +216,18 @@ class Process:
os.fchown(f.fileno(), int(ctx.args.log_uid), int(ctx.args.log_gid))
self.write_fds.append(f)
- #
- # Only add an IO watch for long running processes. If
- # the process is being waited for, the log/outfile bits
- # will be handled after the process exists.
- #
- if self.write_fds != [] and not wait and not check or self.verbose:
- self.io_watch = GLib.io_add_watch(self.stdout, GLib.IO_IN,
- self.io_callback)
-
- self.pid = subprocess.Popen(self.args, stdout=self.stdout, stderr=self.stdout,
+ self.pid = subprocess.Popen(self.args, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
env=env, cwd=os.getcwd())
+ # Set as non-blocking so read() in the IO callback doesn't block forever
+ fl = fcntl.fcntl(self.pid.stdout, fcntl.F_GETFL)
+ fcntl.fcntl(self.pid.stdout, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+
+ if not wait and not check:
+ self.io_watch = GLib.io_add_watch(self.pid.stdout, GLib.IO_IN |
+ GLib.IO_HUP | GLib.IO_ERR, self.io_callback)
+
print("Starting process {}".format(self.pid.args))
if not wait and not check:
@@ -249,12 +237,7 @@ class Process:
self.killed = True
self.ret = self.pid.returncode
- self.stdout.seek(self.io_position)
- self.out = self.stdout.read()
- self.stdout.seek(0, 2)
-
- if len(self.write_fds) > 0:
- self.process_io(self.stdout)
+ self.process_io(self.pid.stdout)
self.write_fds = []
@@ -263,21 +246,16 @@ class Process:
raise subprocess.CalledProcessError(returncode=self.ret, cmd=self.args)
def process_io(self, source):
- #
- # The file will have already been written to, meaning the seek
- # position points to EOF. This is why the position is saved so
- # we can seek to where we were last time, read data, and seek
- # back to EOF.
- #
- source.seek(self.io_position)
data = source.read()
- self.io_position += len(data)
- source.seek(self.io_position)
-
- if len(data) == 0:
+ if not data:
return True
+ data = data.decode('utf-8')
+
+ # Save data away in case the caller needs it (e.g. list_sta)
+ self.out += data
+
for f in self.write_fds:
f.write(data)
f.flush()
@@ -294,10 +272,6 @@ class Process:
def __del__(self):
print("Del process %s" % self.args)
- os.remove(self.output_name)
-
- self.stdout.close()
-
if not self.killed:
self.kill()
@@ -312,19 +286,22 @@ class Process:
else:
self.pid.terminate()
- self.pid.wait(timeout=15)
- self.pid = None
+ try:
+ self.pid.wait(timeout=15)
+ except:
+ dbg("Process %s did not complete in 15 seconds!" % self.name)
+ self.pid.kill()
if self.ctx and self in self.ctx.processes:
self.ctx.processes.remove(self)
- self.ctx = None
-
- self.process_io(self.stdout)
-
if self.cleanup:
self.cleanup()
+ self.process_io(self.pid.stdout)
+
+ self.ctx = None
+ self.pid = None
self.write_fds = []
if self.io_watch:
@@ -593,9 +570,6 @@ class Namespace:
self.radios = []
- if self.name == "root":
- self._bus = dbus.bus.BusConnection(address_or_type=self.dbus_address)
-
for p in list(self.processes):
print("Killing process %s" % p.name)
p.kill()
@@ -1192,6 +1166,10 @@ def post_test(ctx, to_copy):
dbg("\n")
os.remove('/tmp/' + f)
+ # Special case for when logging is enabled
+ if os.path.isfile('/tmp/iwd-tls-debug-server-cert.pem'):
+ os.remove('/tmp/iwd-tls-debug-server-cert.pem')
+
allowed = ['phonesim.conf', 'certs', 'secrets', 'iwd']
for f in [f for f in os.listdir('/tmp') if f not in allowed]:
dbg("File %s was not cleaned up!" % f)
@@ -1364,7 +1342,7 @@ def run_tests():
config.ctx = TestContext(args)
if args.log:
- mount('logdir', args.log, '9p', 0, 'trans=virtio,version=9p2000.L')
+ mount('logdir', args.log, '9p', 0, 'trans=virtio,version=9p2000.L,msize=10240')
# Clear out any log files from other test runs
for f in glob('%s/*' % args.log):
print("removing %s" % f)
@@ -1375,7 +1353,7 @@ def run_tests():
os.remove(f)
elif args.monitor:
parent = os.path.abspath(os.path.join(args.monitor, os.pardir))
- mount('mondir', parent, '9p', 0, 'trans=virtio,version=9p2000.L')
+ mount('mondir', parent, '9p', 0, 'trans=virtio,version=9p2000.L,msize=10240')
if config.ctx.args.unit_tests is None:
run_auto_tests(config.ctx, args)
@@ -1581,7 +1559,7 @@ class Main:
if self.args.valgrind:
ram = 512
else:
- ram = 256
+ ram = 384
print("Using %d cores, %d RAM for VM" % (smp, ram))
diff --git a/unit/test-ie.c b/unit/test-ie.c
@@ -156,8 +156,10 @@ static int create_ie(int ie_count, struct ie_tlv_builder *builder,
static void ie_test_writer(const void *data)
{
struct test_data *test = (struct test_data *)data;
+ size_t expected_len = test->len;
struct ie_tlv_builder builder;
- unsigned int final_len = 0, builder_len, expected_len = test->len;
+ size_t final_len = 0;
+ size_t builder_len;
const unsigned char *expected_buf = test->buf;
unsigned int ie_count = 0;
char *str;
@@ -250,7 +252,7 @@ static void ie_test_writer(const void *data)
assert(!memcmp(test->buf, expected_buf, final_len));
}
- printf("Wrote %d IE total len %d\n", ie_count, expected_len);
+ printf("Wrote %d IE total len %zu\n", ie_count, expected_len);
}
static void ie_test_writer_invalid_tag(const void *data)
@@ -291,7 +293,7 @@ static void ie_test_reader_extended(const void *data)
static void ie_test_writer_extended(const void *data)
{
struct ie_tlv_builder builder;
- unsigned int builder_len;
+ size_t builder_len;
static const uint8_t expected[] = {
0xff, 0x05, 0x0a, 0xff, 0x01, 0x02, 0x03,
};
diff --git a/unit/test-sae.c b/unit/test-sae.c
@@ -34,6 +34,15 @@
#include "src/mpdu.h"
#include "src/sae.h"
#include "src/auth-proto.h"
+#include "src/crypto.h"
+
+const unsigned int *__wrap_l_ecc_supported_ike_groups(void);
+
+const unsigned int *__wrap_l_ecc_supported_ike_groups(void)
+{
+ static unsigned int supported_ike_groups[2] = { 19, 0 };
+ return supported_ike_groups;
+}
struct test_handshake_state {
struct handshake_state super;
@@ -374,9 +383,7 @@ static void test_bad_group(const void *arg)
sizeof(aa_commit_bad_group));
assert(auth_proto_rx_authenticate(ap, (uint8_t *)frame, len) ==
- MMPDU_STATUS_CODE_UNSUPP_FINITE_CYCLIC_GROUP);
-
- assert(td->tx_reject_occurred);
+ -EPROTO);
test_destruct(td);
auth_proto_free(ap);
@@ -627,6 +634,245 @@ static void test_end_to_end(const void *arg)
l_free(td2);
}
+static void test_pt_pwe(const void *data)
+{
+ static const char *ssid = "byteme";
+ static const char *identifier = "psk4internet";
+ static const char *password = "mekmitasdigoat";
+ static const uint8_t mac1[] = { 0x00, 0x09, 0x5b, 0x66, 0xec, 0x1e };
+ static const uint8_t mac2[] = { 0x00, 0x0b, 0x6b, 0xd9, 0x02, 0x46 };
+ static const uint8_t prk[] = {
+ 0x3b, 0xd5, 0x3f, 0xe9, 0x22, 0x3d, 0xc0, 0x28,
+ 0x0f, 0xbf, 0xce, 0x17, 0xd7, 0xa3, 0x56, 0x40,
+ 0x64, 0xe2, 0x0f, 0x48, 0xc6, 0xec, 0x72, 0x24,
+ 0x6c, 0xe3, 0x67, 0xb5, 0x56, 0x9a, 0x22, 0xaf,
+ };
+ static const uint8_t okm1[] = {
+ 0xa5, 0x04, 0x44, 0x69, 0xab, 0x16, 0xf2, 0x5b,
+ 0x6a, 0xbf, 0x1e, 0x0e, 0x37, 0xa3, 0x6b, 0x56,
+ 0xf5, 0x0b, 0xe7, 0x33, 0x69, 0x05, 0x3d, 0xf8,
+ 0xdb, 0x87, 0x98, 0x9a, 0x6b, 0x66, 0xfd, 0x1a,
+ 0x49, 0x1f, 0x1c, 0xda, 0xcb, 0xd0, 0x79, 0x31,
+ 0x62, 0x0f, 0x83, 0x00, 0x8f, 0xfc, 0x0e, 0xcc,
+ };
+ static const uint8_t u1_data[] = {
+ 0xdc, 0x94, 0x1b, 0xc3, 0xc6, 0xa2, 0xb4, 0x94,
+ 0x8b, 0x6c, 0x61, 0xd5, 0x55, 0x90, 0xec, 0xb1,
+ 0xf0, 0xc5, 0x1c, 0x4b, 0x1b, 0xeb, 0xaf, 0xf6,
+ 0x77, 0xe5, 0x93, 0x69, 0x8d, 0x5a, 0x53, 0xc6,
+ };
+ static const uint8_t okm2[] = {
+ 0x9b, 0x4e, 0x0d, 0x5b, 0x18, 0x79, 0xf2, 0x53,
+ 0xc5, 0x31, 0x96, 0x15, 0x09, 0x9b, 0x05, 0xae,
+ 0xc5, 0xb0, 0x6f, 0xa5, 0xe7, 0x88, 0xbc, 0xfd,
+ 0x1e, 0x9e, 0xa6, 0x0d, 0x33, 0x43, 0x69, 0x27,
+ 0x19, 0x08, 0x14, 0xc3, 0x22, 0xa6, 0x25, 0x85,
+ 0xc9, 0x3c, 0x57, 0x7b, 0xba, 0xa3, 0xd3, 0x07,
+ };
+ static const uint8_t u2_data[] = {
+ 0x1b, 0x83, 0x75, 0xa5, 0x18, 0xbc, 0x21, 0x39,
+ 0x6a, 0xd6, 0xa6, 0x5e, 0x55, 0x97, 0xe0, 0xbf,
+ 0x80, 0xd7, 0x93, 0xb6, 0xd6, 0x6e, 0x25, 0x34,
+ 0xa6, 0xe7, 0xdf, 0xe3, 0xee, 0x22, 0x61, 0x6f,
+ };
+ static const uint8_t p1x_data[] = {
+ 0xa0, 0x7c, 0x26, 0x07, 0x64, 0xa1, 0x34, 0x45,
+ 0xff, 0x8c, 0xd9, 0x7c, 0x5a, 0xcc, 0x64, 0x4e,
+ 0x71, 0x19, 0xbd, 0xe5, 0x1b, 0xad, 0x42, 0x58,
+ 0x3e, 0xed, 0x6f, 0x41, 0x09, 0x63, 0x9e, 0x6b,
+ };
+ static const uint8_t p1y_data[] = {
+ 0x3b, 0xdc, 0x8d, 0xf0, 0xd3, 0x23, 0x37, 0x93,
+ 0x6c, 0x74, 0xdf, 0x60, 0x49, 0x33, 0xa4, 0x54,
+ 0x14, 0x22, 0x51, 0xc5, 0x3c, 0x57, 0x6c, 0x03,
+ 0x51, 0xb2, 0x8d, 0xea, 0xf9, 0x42, 0x8d, 0x7e,
+ };
+ static const uint8_t p2x_data[] = {
+ 0x72, 0xcd, 0x2a, 0x96, 0x7a, 0x83, 0x7f, 0xea,
+ 0x50, 0x51, 0xf0, 0x13, 0x3d, 0xb4, 0x62, 0x27,
+ 0x77, 0x5b, 0xa0, 0x9f, 0x7b, 0x6d, 0xfb, 0x99,
+ 0xae, 0x7a, 0x8e, 0xf2, 0x2c, 0x7d, 0x34, 0xa0,
+ };
+ static const uint8_t p2y_data[] = {
+ 0x86, 0x43, 0x90, 0xd7, 0x97, 0xd3, 0x52, 0xb3,
+ 0x68, 0xd3, 0x11, 0xaf, 0x51, 0x5b, 0xde, 0x11,
+ 0x6f, 0xe5, 0x44, 0x59, 0xfe, 0xc8, 0x67, 0xee,
+ 0x18, 0xa8, 0xa1, 0x61, 0x9c, 0xa3, 0xff, 0x59,
+ };
+ static const uint8_t ptx_data[] = {
+ 0xb6, 0xe3, 0x8c, 0x98, 0x75, 0x0c, 0x68, 0x4b,
+ 0x5d, 0x17, 0xc3, 0xd8, 0xc9, 0xa4, 0x10, 0x0b,
+ 0x39, 0x93, 0x12, 0x79, 0x18, 0x7c, 0xa6, 0xcc,
+ 0xed, 0x5f, 0x37, 0xef, 0x46, 0xdd, 0xfa, 0x97,
+ };
+ static const uint8_t pty_data[] = {
+ 0x56, 0x87, 0xe9, 0x72, 0xe5, 0x0f, 0x73, 0xe3,
+ 0x89, 0x88, 0x61, 0xe7, 0xed, 0xad, 0x21, 0xbe,
+ 0xa7, 0xd5, 0xf6, 0x22, 0xdf, 0x88, 0x24, 0x3b,
+ 0xb8, 0x04, 0x92, 0x0a, 0xe8, 0xe6, 0x47, 0xfa,
+ };
+ static const uint8_t val_data[] = {
+ 0xbb, 0x7f, 0x9c, 0xac, 0x5a, 0xa8, 0xb7, 0x2c,
+ 0x02, 0xb5, 0xda, 0xac, 0xc2, 0x77, 0x1a, 0xbe,
+ 0x74, 0xe7, 0x26, 0x04, 0x61, 0x22, 0x95, 0xec,
+ 0xa2, 0xce, 0x18, 0x36, 0x3a, 0xe9, 0xa9, 0x27,
+ };
+ static const uint8_t pwex_data[] = {
+ 0xc9, 0x30, 0x49, 0xb9, 0xe6, 0x40, 0x00, 0xf8,
+ 0x48, 0x20, 0x16, 0x49, 0xe9, 0x99, 0xf2, 0xb5,
+ 0xc2, 0x2d, 0xea, 0x69, 0xb5, 0x63, 0x2c, 0x9d,
+ 0xf4, 0xd6, 0x33, 0xb8, 0xaa, 0x1f, 0x6c, 0x1e,
+ };
+ static const uint8_t pwey_data[] = {
+ 0x73, 0x63, 0x4e, 0x94, 0xb5, 0x3d, 0x82, 0xe7,
+ 0x38, 0x3a, 0x8d, 0x25, 0x81, 0x99, 0xd9, 0xdc,
+ 0x1a, 0x5e, 0xe8, 0x26, 0x9d, 0x06, 0x03, 0x82,
+ 0xcc, 0xbf, 0x33, 0xe6, 0x14, 0xff, 0x59, 0xa0,
+ };
+
+ const struct l_ecc_curve *curve;
+ struct l_ecc_scalar *u1;
+ struct l_ecc_scalar *u2;
+ struct l_ecc_scalar *val;
+ struct l_ecc_point *p1;
+ struct l_ecc_point *p2;
+ struct l_ecc_point *pt;
+ struct l_ecc_point *pwe;
+ enum l_checksum_type hash;
+ size_t hash_len;
+ uint8_t pwd_seed[64]; /* SHA512 is the biggest possible right now */
+ uint8_t pwd_value[128];
+ size_t pwd_value_len;
+ uint8_t ubuf[64];
+ uint64_t num[L_ECC_MAX_DIGITS];
+ uint8_t zero[64] = { 0 };
+ uint8_t val_buf[32];
+ uint8_t sorted_macs[12];
+
+ curve = l_ecc_curve_from_ike_group(19);
+ assert(curve);
+
+ hash = crypto_sae_hash_from_ecc_prime_len(CRYPTO_SAE_HASH_TO_ELEMENT,
+ l_ecc_curve_get_scalar_bytes(curve));
+ hash_len = l_checksum_digest_length(hash);
+
+ assert(hash_len == 32);
+
+ /* pwd-seed = HKDF-Extract(ssid, password [|| identifier]) */
+ assert(hkdf_extract(hash, ssid, strlen(ssid), 2, pwd_seed,
+ password, strlen(password),
+ identifier, strlen(identifier)));
+ assert(!memcmp(pwd_seed, prk, sizeof(prk)));
+
+ /* len = olen(p) + floor(olen(p)/2) */
+ pwd_value_len = l_ecc_curve_get_scalar_bytes(curve);
+ pwd_value_len += pwd_value_len / 2;
+
+ /*
+ * pwd-value = HKDF-Expand(pwd-seed, "SAE Hash to Element u1 P1", len)
+ */
+ assert(hkdf_expand(hash, pwd_seed, hash_len,
+ "SAE Hash to Element u1 P1",
+ pwd_value, pwd_value_len));
+ assert(!memcmp(pwd_value, okm1, sizeof(okm1)));
+
+ u1 = l_ecc_scalar_new_modp(curve, pwd_value, pwd_value_len);
+ assert(u1);
+
+ assert(l_ecc_scalar_get_data(u1, ubuf, sizeof(ubuf)) ==
+ (ssize_t) sizeof(u1_data));
+ assert(!memcmp(ubuf, u1_data, sizeof(u1_data)));
+
+ /*
+ * pwd-value = HKDF-Expand(pwd-seed, "SAE Hash to Element u2 P2", len)
+ */
+ assert(hkdf_expand(hash, pwd_seed, hash_len,
+ "SAE Hash to Element u2 P2",
+ pwd_value, pwd_value_len));
+ assert(!memcmp(pwd_value, okm2, sizeof(okm2)));
+
+ u2 = l_ecc_scalar_new_modp(curve, pwd_value, pwd_value_len);
+ assert(u2);
+
+ assert(l_ecc_scalar_get_data(u2, ubuf, sizeof(ubuf)) ==
+ (ssize_t) sizeof(u2_data));
+ assert(!memcmp(ubuf, u2_data, sizeof(u2_data)));
+
+ p1 = l_ecc_point_from_sswu(u1);
+ assert(p1);
+
+ assert(l_ecc_point_get_x(p1, num, sizeof(num)) > 0);
+ assert(!memcmp(num, p1x_data, sizeof(p1x_data)));
+
+ assert(l_ecc_point_get_y(p1, num, sizeof(num)) > 0);
+ assert(!memcmp(num, p1y_data, sizeof(p1y_data)));
+
+ p2 = l_ecc_point_from_sswu(u2);
+ assert(p2);
+
+ assert(l_ecc_point_get_x(p2, num, sizeof(num)) > 0);
+ assert(!memcmp(num, p2x_data, sizeof(p2x_data)));
+
+ assert(l_ecc_point_get_y(p2, num, sizeof(num)) > 0);
+ assert(!memcmp(num, p2y_data, sizeof(p2y_data)));
+
+ pt = l_ecc_point_new(curve);
+ assert(pt);
+ assert(l_ecc_point_add(pt, p1, p2));
+
+ assert(l_ecc_point_get_x(pt, num, sizeof(num)) > 0);
+ assert(!memcmp(num, ptx_data, sizeof(ptx_data)));
+
+ assert(l_ecc_point_get_y(pt, num, sizeof(num)) > 0);
+ assert(!memcmp(num, pty_data, sizeof(pty_data)));
+
+ l_ecc_point_free(p1);
+ l_ecc_point_free(p2);
+ l_ecc_scalar_free(u1);
+ l_ecc_scalar_free(u2);
+
+ p1 = crypto_derive_sae_pt_ecc(19, ssid, password, identifier);
+ assert(p1);
+ assert(l_ecc_points_are_equal(p1, pt));
+ l_ecc_point_free(p1);
+
+ if (memcmp(mac1, mac2, 6) > 0) {
+ memcpy(sorted_macs, mac1, 6);
+ memcpy(sorted_macs + 6, mac2, 6);
+ } else {
+ memcpy(sorted_macs, mac2, 6);
+ memcpy(sorted_macs + 6, mac1, 6);
+ }
+
+ assert(hkdf_extract(hash, zero, hash_len, 1, val_buf,
+ sorted_macs, sizeof(sorted_macs)));
+ val = l_ecc_scalar_new_reduced_1_to_n(curve, val_buf, sizeof(val_buf));
+ assert(val);
+ assert(l_ecc_scalar_get_data(val, ubuf, sizeof(ubuf)) ==
+ (ssize_t) sizeof(val_data));
+ assert(!memcmp(ubuf, val_data, sizeof(val_data)));
+
+ pwe = l_ecc_point_new(curve);
+ assert(pwe);
+ assert(l_ecc_point_multiply(pwe, val, pt));
+
+ assert(l_ecc_point_get_x(pwe, num, sizeof(num)) > 0);
+ assert(!memcmp(num, pwex_data, sizeof(pwex_data)));
+
+ assert(l_ecc_point_get_y(pwe, num, sizeof(num)) > 0);
+ assert(!memcmp(num, pwey_data, sizeof(pwey_data)));
+
+ l_ecc_scalar_free(val);
+
+ p1 = crypto_derive_sae_pwe_from_pt_ecc(mac1, mac2, pt);
+ assert(p1);
+ assert(l_ecc_points_are_equal(p1, pwe));
+ l_ecc_point_free(p1);
+
+ l_ecc_point_free(pwe);
+ l_ecc_point_free(pt);
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -651,6 +897,8 @@ int main(int argc, char *argv[])
l_test_add("SAE confirm after accept", test_confirm_after_accept, NULL);
l_test_add("SAE end-to-end", test_end_to_end, NULL);
+ l_test_add("SAE pt-pwe", test_pt_pwe, NULL);
+
done:
return l_test_run();
}