]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_ciphers.py
94679657e010ef45026792445e5f7f0f21139858
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
9 logger
= logging
.getLogger()
15 def check_cipher(dev
, ap
, cipher
):
16 if cipher
not in dev
.get_capability("pairwise"):
18 params
= { "ssid": "test-wpa2-psk",
19 "wpa_passphrase": "12345678",
21 "wpa_key_mgmt": "WPA-PSK",
22 "rsn_pairwise": cipher
}
23 hapd
= hostapd
.add_ap(ap
['ifname'], params
)
24 dev
.connect("test-wpa2-psk", psk
="12345678",
25 pairwise
=cipher
, group
=cipher
, scan_freq
="2412")
26 hwsim_utils
.test_connectivity(dev
, hapd
)
28 def test_ap_cipher_tkip(dev
, apdev
):
29 """WPA2-PSK/TKIP connection"""
30 return check_cipher(dev
[0], apdev
[0], "TKIP")
32 def test_ap_cipher_tkip_countermeasures_ap(dev
, apdev
):
33 """WPA-PSK/TKIP countermeasures (detected by AP)"""
34 testfile
= "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (dev
[0].get_driver_status_field("phyname"), dev
[0].ifname
)
35 if not os
.path
.exists(testfile
):
38 params
= { "ssid": "tkip-countermeasures",
39 "wpa_passphrase": "12345678",
41 "wpa_key_mgmt": "WPA-PSK",
42 "wpa_pairwise": "TKIP" }
43 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
45 dev
[0].connect("tkip-countermeasures", psk
="12345678",
46 pairwise
="TKIP", group
="TKIP", scan_freq
="2412")
49 with
open(testfile
, "w") as f
:
50 f
.write(apdev
[0]['bssid'])
51 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=1)
53 raise Exception("Unexpected disconnection on first Michael MIC failure")
55 with
open(testfile
, "w") as f
:
56 f
.write("ff:ff:ff:ff:ff:ff")
57 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=10)
59 raise Exception("No disconnection after two Michael MIC failures")
60 if "reason=14" not in ev
:
61 raise Exception("Unexpected disconnection reason: " + ev
)
62 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=1)
64 raise Exception("Unexpected connection during TKIP countermeasures")
66 def test_ap_cipher_tkip_countermeasures_sta(dev
, apdev
):
67 """WPA-PSK/TKIP countermeasures (detected by STA)"""
68 params
= { "ssid": "tkip-countermeasures",
69 "wpa_passphrase": "12345678",
71 "wpa_key_mgmt": "WPA-PSK",
72 "wpa_pairwise": "TKIP" }
73 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
75 testfile
= "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (hapd
.get_driver_status_field("phyname"), apdev
[0]['ifname'])
76 if not os
.path
.exists(testfile
):
79 dev
[0].connect("tkip-countermeasures", psk
="12345678",
80 pairwise
="TKIP", group
="TKIP", scan_freq
="2412")
83 with
open(testfile
, "w") as f
:
84 f
.write(dev
[0].p2p_dev_addr())
85 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=1)
87 raise Exception("Unexpected disconnection on first Michael MIC failure")
89 with
open(testfile
, "w") as f
:
90 f
.write("ff:ff:ff:ff:ff:ff")
91 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=10)
93 raise Exception("No disconnection after two Michael MIC failures")
94 if "reason=14 locally_generated=1" not in ev
:
95 raise Exception("Unexpected disconnection reason: " + ev
)
96 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=1)
98 raise Exception("Unexpected connection during TKIP countermeasures")
100 def test_ap_cipher_ccmp(dev
, apdev
):
101 """WPA2-PSK/CCMP connection"""
102 return check_cipher(dev
[0], apdev
[0], "CCMP")
104 def test_ap_cipher_gcmp(dev
, apdev
):
105 """WPA2-PSK/GCMP connection"""
106 return check_cipher(dev
[0], apdev
[0], "GCMP")
108 def test_ap_cipher_ccmp_256(dev
, apdev
):
109 """WPA2-PSK/CCMP-256 connection"""
110 return check_cipher(dev
[0], apdev
[0], "CCMP-256")
112 def test_ap_cipher_gcmp_256(dev
, apdev
):
113 """WPA2-PSK/GCMP-256 connection"""
114 return check_cipher(dev
[0], apdev
[0], "GCMP-256")
116 def test_ap_cipher_mixed_wpa_wpa2(dev
, apdev
):
117 """WPA2-PSK/CCMP/ and WPA-PSK/TKIP mixed configuration"""
118 ssid
= "test-wpa-wpa2-psk"
119 passphrase
= "12345678"
120 params
= { "ssid": ssid
,
121 "wpa_passphrase": passphrase
,
123 "wpa_key_mgmt": "WPA-PSK",
124 "rsn_pairwise": "CCMP",
125 "wpa_pairwise": "TKIP" }
126 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
127 dev
[0].connect(ssid
, psk
=passphrase
, proto
="WPA2",
128 pairwise
="CCMP", group
="TKIP", scan_freq
="2412")
129 status
= dev
[0].get_status()
130 if status
['key_mgmt'] != 'WPA2-PSK':
131 raise Exception("Incorrect key_mgmt reported")
132 if status
['pairwise_cipher'] != 'CCMP':
133 raise Exception("Incorrect pairwise_cipher reported")
134 if status
['group_cipher'] != 'TKIP':
135 raise Exception("Incorrect group_cipher reported")
136 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
137 if bss
['ssid'] != ssid
:
138 raise Exception("Unexpected SSID in the BSS entry")
139 if "[WPA-PSK-TKIP]" not in bss
['flags']:
140 raise Exception("Missing BSS flag WPA-PSK-TKIP")
141 if "[WPA2-PSK-CCMP]" not in bss
['flags']:
142 raise Exception("Missing BSS flag WPA2-PSK-CCMP")
143 hwsim_utils
.test_connectivity(dev
[0], hapd
)
145 dev
[1].connect(ssid
, psk
=passphrase
, proto
="WPA",
146 pairwise
="TKIP", group
="TKIP", scan_freq
="2412")
147 status
= dev
[1].get_status()
148 if status
['key_mgmt'] != 'WPA-PSK':
149 raise Exception("Incorrect key_mgmt reported")
150 if status
['pairwise_cipher'] != 'TKIP':
151 raise Exception("Incorrect pairwise_cipher reported")
152 if status
['group_cipher'] != 'TKIP':
153 raise Exception("Incorrect group_cipher reported")
154 hwsim_utils
.test_connectivity(dev
[1], hapd
)
155 hwsim_utils
.test_connectivity(dev
[0], dev
[1])