]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_psk.py
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
13 def test_ap_wpa2_psk(dev
, apdev
):
14 """WPA2-PSK AP with PSK instead of passphrase"""
15 ssid
= "test-wpa2-psk"
16 passphrase
= 'qwertyuiop'
17 psk
= '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
18 params
= hostapd
.wpa2_params(ssid
=ssid
)
19 params
['wpa_psk'] = psk
20 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
21 key_mgmt
= hapd
.get_config()['key_mgmt']
22 if key_mgmt
.split(' ')[0] != "WPA-PSK":
23 raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt
)
24 dev
[0].connect(ssid
, raw_psk
=psk
, scan_freq
="2412")
25 dev
[1].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
27 def test_ap_wpa2_psk_file(dev
, apdev
):
28 """WPA2-PSK AP with PSK from a file"""
29 ssid
= "test-wpa2-psk"
30 passphrase
= 'qwertyuiop'
31 psk
= '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
32 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
33 params
['wpa_psk_file'] = 'hostapd.wpa_psk'
34 hostapd
.add_ap(apdev
[0]['ifname'], params
)
35 dev
[1].connect(ssid
, psk
="very secret", scan_freq
="2412", wait_connect
=False)
36 dev
[2].connect(ssid
, raw_psk
=psk
, scan_freq
="2412")
37 dev
[2].request("REMOVE_NETWORK all")
38 dev
[0].connect(ssid
, psk
="very secret", scan_freq
="2412")
39 dev
[0].request("REMOVE_NETWORK all")
40 dev
[2].connect(ssid
, psk
="another passphrase for all STAs", scan_freq
="2412")
41 dev
[0].connect(ssid
, psk
="another passphrase for all STAs", scan_freq
="2412")
42 ev
= dev
[1].wait_event(["WPA: 4-Way Handshake failed"], timeout
=10)
44 raise Exception("Timed out while waiting for failure report")
45 dev
[1].request("REMOVE_NETWORK all")
47 def test_ap_wpa_ptk_rekey(dev
, apdev
):
48 """WPA-PSK/TKIP AP and PTK rekey enforced by station"""
50 passphrase
= 'qwertyuiop'
51 params
= hostapd
.wpa_params(ssid
=ssid
, passphrase
=passphrase
)
52 hostapd
.add_ap(apdev
[0]['ifname'], params
)
53 dev
[0].connect(ssid
, psk
=passphrase
, wpa_ptk_rekey
="1", scan_freq
="2412")
54 ev
= dev
[0].wait_event(["WPA: Key negotiation completed"])
56 raise Exception("PTK rekey timed out")
57 hwsim_utils
.test_connectivity(dev
[0].ifname
, apdev
[0]['ifname'])