]>
Commit | Line | Data |
---|---|---|
302b7a1b | 1 | # WPS tests |
a1eabc74 | 2 | # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi> |
302b7a1b JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
9fd6804d | 7 | from remotehost import remote_compatible |
6aaa661a | 8 | import base64 |
476daa05 | 9 | import binascii |
7511ead0 JM |
10 | from Crypto.Cipher import AES |
11 | import hashlib | |
12 | import hmac | |
2035b170 | 13 | import os |
302b7a1b | 14 | import time |
2602a2ff | 15 | import stat |
302b7a1b JM |
16 | import subprocess |
17 | import logging | |
c9aa4308 | 18 | logger = logging.getLogger() |
1013a576 | 19 | import re |
44ff0400 | 20 | import socket |
7511ead0 | 21 | import struct |
47c549fd JM |
22 | import httplib |
23 | import urlparse | |
24 | import urllib | |
25 | import xml.etree.ElementTree as ET | |
26 | import StringIO | |
c965ae03 | 27 | import SocketServer |
302b7a1b JM |
28 | |
29 | import hwsim_utils | |
30 | import hostapd | |
1531402e | 31 | from wpasupplicant import WpaSupplicant |
c965ae03 | 32 | from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips |
1e35aa15 | 33 | from utils import wait_fail_trigger |
d8e5a55f | 34 | from test_ap_eap import int_eap_server_params |
302b7a1b | 35 | |
24b7f282 JM |
36 | def wps_start_ap(apdev, ssid="test-wps-conf"): |
37 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
38 | "wpa_passphrase": "12345678", "wpa": "2", | |
39 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
afc26df2 | 40 | return hostapd.add_ap(apdev, params) |
24b7f282 | 41 | |
9fd6804d | 42 | @remote_compatible |
ae3ad328 | 43 | def test_ap_wps_init(dev, apdev): |
302b7a1b JM |
44 | """Initial AP configuration with first WPS Enrollee""" |
45 | ssid = "test-wps" | |
6f334bf7 JD |
46 | hapd = hostapd.add_ap(apdev[0], |
47 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
302b7a1b JM |
48 | logger.info("WPS provisioning step") |
49 | hapd.request("WPS_PBC") | |
d671a420 JM |
50 | if "PBC Status: Active" not in hapd.request("WPS_GET_STATUS"): |
51 | raise Exception("PBC status not shown correctly") | |
b9018833 JM |
52 | |
53 | id = dev[0].add_network() | |
54 | dev[0].set_network_quoted(id, "ssid", "home") | |
55 | dev[0].set_network_quoted(id, "psk", "12345678") | |
56 | dev[0].request("ENABLE_NETWORK %s no-connect" % id) | |
57 | ||
58 | id = dev[0].add_network() | |
59 | dev[0].set_network_quoted(id, "ssid", "home2") | |
60 | dev[0].set_network(id, "bssid", "00:11:22:33:44:55") | |
61 | dev[0].set_network(id, "key_mgmt", "NONE") | |
62 | dev[0].request("ENABLE_NETWORK %s no-connect" % id) | |
63 | ||
302b7a1b | 64 | dev[0].request("WPS_PBC") |
5f35a5e2 | 65 | dev[0].wait_connected(timeout=30) |
302b7a1b | 66 | status = dev[0].get_status() |
ae3ad328 | 67 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
68 | raise Exception("Not fully connected") |
69 | if status['ssid'] != ssid: | |
70 | raise Exception("Unexpected SSID") | |
71 | if status['pairwise_cipher'] != 'CCMP': | |
72 | raise Exception("Unexpected encryption configuration") | |
73 | if status['key_mgmt'] != 'WPA2-PSK': | |
74 | raise Exception("Unexpected key_mgmt") | |
75 | ||
d671a420 JM |
76 | status = hapd.request("WPS_GET_STATUS") |
77 | if "PBC Status: Disabled" not in status: | |
78 | raise Exception("PBC status not shown correctly") | |
79 | if "Last WPS result: Success" not in status: | |
80 | raise Exception("Last WPS result not shown correctly") | |
81 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
82 | raise Exception("Peer address not shown correctly") | |
75b25ece JM |
83 | conf = hapd.request("GET_CONFIG") |
84 | if "wps_state=configured" not in conf: | |
85 | raise Exception("AP not in WPS configured state") | |
742408af JM |
86 | if "wpa=3" not in conf: |
87 | raise Exception("AP not in WPA+WPA2 configuration") | |
75b25ece JM |
88 | if "rsn_pairwise_cipher=CCMP TKIP" not in conf: |
89 | raise Exception("Unexpected rsn_pairwise_cipher") | |
90 | if "wpa_pairwise_cipher=CCMP TKIP" not in conf: | |
91 | raise Exception("Unexpected wpa_pairwise_cipher") | |
92 | if "group_cipher=TKIP" not in conf: | |
93 | raise Exception("Unexpected group_cipher") | |
d671a420 | 94 | |
b9018833 JM |
95 | if len(dev[0].list_networks()) != 3: |
96 | raise Exception("Unexpected number of network blocks") | |
97 | ||
18030dc0 JM |
98 | def test_ap_wps_init_2ap_pbc(dev, apdev): |
99 | """Initial two-radio AP configuration with first WPS PBC Enrollee""" | |
100 | ssid = "test-wps" | |
101 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" } | |
6f334bf7 | 102 | hapd = hostapd.add_ap(apdev[0], params) |
8b8a1864 | 103 | hostapd.add_ap(apdev[1], params) |
18030dc0 JM |
104 | logger.info("WPS provisioning step") |
105 | hapd.request("WPS_PBC") | |
84a40841 JM |
106 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
107 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
108 | bss = dev[0].get_bss(apdev[0]['bssid']) |
109 | if "[WPS-PBC]" not in bss['flags']: | |
110 | raise Exception("WPS-PBC flag missing from AP1") | |
111 | bss = dev[0].get_bss(apdev[1]['bssid']) | |
112 | if "[WPS-PBC]" not in bss['flags']: | |
113 | raise Exception("WPS-PBC flag missing from AP2") | |
114 | dev[0].dump_monitor() | |
f19d87f1 | 115 | dev[0].request("SET wps_cred_processing 2") |
18030dc0 | 116 | dev[0].request("WPS_PBC") |
f19d87f1 JM |
117 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=30) |
118 | dev[0].request("SET wps_cred_processing 0") | |
119 | if ev is None: | |
120 | raise Exception("WPS cred event not seen") | |
121 | if "100e" not in ev: | |
122 | raise Exception("WPS attributes not included in the cred event") | |
5f35a5e2 | 123 | dev[0].wait_connected(timeout=30) |
18030dc0 | 124 | |
84a40841 JM |
125 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
126 | dev[1].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
127 | bss = dev[1].get_bss(apdev[0]['bssid']) |
128 | if "[WPS-PBC]" in bss['flags']: | |
129 | raise Exception("WPS-PBC flag not cleared from AP1") | |
130 | bss = dev[1].get_bss(apdev[1]['bssid']) | |
131 | if "[WPS-PBC]" in bss['flags']: | |
0bde923c | 132 | raise Exception("WPS-PBC flag not cleared from AP2") |
18030dc0 JM |
133 | |
134 | def test_ap_wps_init_2ap_pin(dev, apdev): | |
135 | """Initial two-radio AP configuration with first WPS PIN Enrollee""" | |
136 | ssid = "test-wps" | |
137 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" } | |
6f334bf7 | 138 | hapd = hostapd.add_ap(apdev[0], params) |
8b8a1864 | 139 | hostapd.add_ap(apdev[1], params) |
18030dc0 JM |
140 | logger.info("WPS provisioning step") |
141 | pin = dev[0].wps_read_pin() | |
142 | hapd.request("WPS_PIN any " + pin) | |
84a40841 JM |
143 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
144 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
145 | bss = dev[0].get_bss(apdev[0]['bssid']) |
146 | if "[WPS-AUTH]" not in bss['flags']: | |
147 | raise Exception("WPS-AUTH flag missing from AP1") | |
148 | bss = dev[0].get_bss(apdev[1]['bssid']) | |
149 | if "[WPS-AUTH]" not in bss['flags']: | |
150 | raise Exception("WPS-AUTH flag missing from AP2") | |
151 | dev[0].dump_monitor() | |
152 | dev[0].request("WPS_PIN any " + pin) | |
5f35a5e2 | 153 | dev[0].wait_connected(timeout=30) |
18030dc0 | 154 | |
84a40841 JM |
155 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
156 | dev[1].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
157 | bss = dev[1].get_bss(apdev[0]['bssid']) |
158 | if "[WPS-AUTH]" in bss['flags']: | |
159 | raise Exception("WPS-AUTH flag not cleared from AP1") | |
160 | bss = dev[1].get_bss(apdev[1]['bssid']) | |
161 | if "[WPS-AUTH]" in bss['flags']: | |
0bde923c | 162 | raise Exception("WPS-AUTH flag not cleared from AP2") |
18030dc0 | 163 | |
9fd6804d | 164 | @remote_compatible |
35831e94 JM |
165 | def test_ap_wps_init_through_wps_config(dev, apdev): |
166 | """Initial AP configuration using wps_config command""" | |
167 | ssid = "test-wps-init-config" | |
6f334bf7 JD |
168 | hapd = hostapd.add_ap(apdev[0], |
169 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
35831e94 JM |
170 | if "FAIL" in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")): |
171 | raise Exception("WPS_CONFIG command failed") | |
180cd73d JM |
172 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5) |
173 | if ev is None: | |
174 | raise Exception("Timeout on WPS-NEW-AP-SETTINGS events") | |
175 | # It takes some time for the AP to update Beacon and Probe Response frames, | |
176 | # so wait here before requesting the scan to be started to avoid adding | |
177 | # extra five second wait to the test due to fetching obsolete scan results. | |
178 | hapd.ping() | |
179 | time.sleep(0.2) | |
35831e94 JM |
180 | dev[0].connect(ssid, psk="12345678", scan_freq="2412", proto="WPA2", |
181 | pairwise="CCMP", group="CCMP") | |
182 | ||
9fd6804d | 183 | @remote_compatible |
fbf6b717 JM |
184 | def test_ap_wps_init_through_wps_config_2(dev, apdev): |
185 | """AP configuration using wps_config and wps_cred_processing=2""" | |
186 | ssid = "test-wps-init-config" | |
6f334bf7 JD |
187 | hapd = hostapd.add_ap(apdev[0], |
188 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
189 | "wps_cred_processing": "2" }) | |
fbf6b717 JM |
190 | if "FAIL" in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")): |
191 | raise Exception("WPS_CONFIG command failed") | |
192 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5) | |
193 | if ev is None: | |
194 | raise Exception("Timeout on WPS-NEW-AP-SETTINGS events") | |
195 | if "100e" not in ev: | |
196 | raise Exception("WPS-NEW-AP-SETTINGS did not include Credential") | |
197 | ||
9fd6804d | 198 | @remote_compatible |
e1eb0e9e JM |
199 | def test_ap_wps_invalid_wps_config_passphrase(dev, apdev): |
200 | """AP configuration using wps_config command with invalid passphrase""" | |
201 | ssid = "test-wps-init-config" | |
6f334bf7 JD |
202 | hapd = hostapd.add_ap(apdev[0], |
203 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
e1eb0e9e JM |
204 | if "FAIL" not in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "1234567".encode("hex")): |
205 | raise Exception("Invalid WPS_CONFIG command accepted") | |
206 | ||
ae3ad328 | 207 | def test_ap_wps_conf(dev, apdev): |
302b7a1b JM |
208 | """WPS PBC provisioning with configured AP""" |
209 | ssid = "test-wps-conf" | |
6f334bf7 JD |
210 | hapd = hostapd.add_ap(apdev[0], |
211 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
212 | "wpa_passphrase": "12345678", "wpa": "2", | |
213 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
302b7a1b JM |
214 | logger.info("WPS provisioning step") |
215 | hapd.request("WPS_PBC") | |
33d0b157 | 216 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 217 | dev[0].dump_monitor() |
33d0b157 | 218 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 219 | dev[0].wait_connected(timeout=30) |
302b7a1b | 220 | status = dev[0].get_status() |
ae3ad328 | 221 | if status['wpa_state'] != 'COMPLETED': |
302b7a1b | 222 | raise Exception("Not fully connected") |
ae3ad328 JM |
223 | if status['bssid'] != apdev[0]['bssid']: |
224 | raise Exception("Unexpected BSSID") | |
302b7a1b JM |
225 | if status['ssid'] != ssid: |
226 | raise Exception("Unexpected SSID") | |
227 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
228 | raise Exception("Unexpected encryption configuration") | |
229 | if status['key_mgmt'] != 'WPA2-PSK': | |
230 | raise Exception("Unexpected key_mgmt") | |
231 | ||
097cd9cd JM |
232 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) |
233 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
234 | raise Exception("Device name not available in STA command") | |
235 | ||
daad14cc JM |
236 | def test_ap_wps_conf_5ghz(dev, apdev): |
237 | """WPS PBC provisioning with configured AP on 5 GHz band""" | |
238 | try: | |
9d7fdac5 | 239 | hapd = None |
daad14cc JM |
240 | ssid = "test-wps-conf" |
241 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
242 | "wpa_passphrase": "12345678", "wpa": "2", | |
243 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
244 | "country_code": "FI", "hw_mode": "a", "channel": "36" } | |
8b8a1864 | 245 | hapd = hostapd.add_ap(apdev[0], params) |
daad14cc JM |
246 | logger.info("WPS provisioning step") |
247 | hapd.request("WPS_PBC") | |
33d0b157 JM |
248 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="5180") |
249 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 250 | dev[0].wait_connected(timeout=30) |
daad14cc JM |
251 | |
252 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) | |
253 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
254 | raise Exception("Device name not available in STA command") | |
255 | finally: | |
9d7fdac5 JM |
256 | dev[0].request("DISCONNECT") |
257 | if hapd: | |
258 | hapd.request("DISABLE") | |
c4668009 | 259 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 260 | dev[0].flush_scan_cache() |
daad14cc JM |
261 | |
262 | def test_ap_wps_conf_chan14(dev, apdev): | |
263 | """WPS PBC provisioning with configured AP on channel 14""" | |
264 | try: | |
9d7fdac5 | 265 | hapd = None |
daad14cc JM |
266 | ssid = "test-wps-conf" |
267 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
268 | "wpa_passphrase": "12345678", "wpa": "2", | |
269 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
270 | "country_code": "JP", "hw_mode": "b", "channel": "14" } | |
8b8a1864 | 271 | hapd = hostapd.add_ap(apdev[0], params) |
daad14cc JM |
272 | logger.info("WPS provisioning step") |
273 | hapd.request("WPS_PBC") | |
274 | dev[0].request("WPS_PBC") | |
5f35a5e2 | 275 | dev[0].wait_connected(timeout=30) |
daad14cc JM |
276 | |
277 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) | |
278 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
279 | raise Exception("Device name not available in STA command") | |
280 | finally: | |
9d7fdac5 JM |
281 | dev[0].request("DISCONNECT") |
282 | if hapd: | |
283 | hapd.request("DISABLE") | |
c4668009 | 284 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 285 | dev[0].flush_scan_cache() |
daad14cc | 286 | |
9fd6804d | 287 | @remote_compatible |
04e62788 JM |
288 | def test_ap_wps_twice(dev, apdev): |
289 | """WPS provisioning with twice to change passphrase""" | |
290 | ssid = "test-wps-twice" | |
291 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
292 | "wpa_passphrase": "12345678", "wpa": "2", | |
293 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
01703a9f | 294 | hapd = hostapd.add_ap(apdev[0], params) |
04e62788 JM |
295 | logger.info("WPS provisioning step") |
296 | hapd.request("WPS_PBC") | |
33d0b157 | 297 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
04e62788 | 298 | dev[0].dump_monitor() |
33d0b157 | 299 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 300 | dev[0].wait_connected(timeout=30) |
04e62788 JM |
301 | dev[0].request("DISCONNECT") |
302 | ||
303 | logger.info("Restart AP with different passphrase and re-run WPS") | |
01703a9f | 304 | hostapd.remove_bss(apdev[0]) |
04e62788 | 305 | params['wpa_passphrase'] = 'another passphrase' |
01703a9f | 306 | hapd = hostapd.add_ap(apdev[0], params) |
04e62788 JM |
307 | logger.info("WPS provisioning step") |
308 | hapd.request("WPS_PBC") | |
309 | dev[0].dump_monitor() | |
33d0b157 | 310 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 311 | dev[0].wait_connected(timeout=30) |
04e62788 JM |
312 | networks = dev[0].list_networks() |
313 | if len(networks) > 1: | |
314 | raise Exception("Unexpected duplicated network block present") | |
315 | ||
9fd6804d | 316 | @remote_compatible |
d658205a JM |
317 | def test_ap_wps_incorrect_pin(dev, apdev): |
318 | """WPS PIN provisioning with incorrect PIN""" | |
319 | ssid = "test-wps-incorrect-pin" | |
6f334bf7 JD |
320 | hapd = hostapd.add_ap(apdev[0], |
321 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
322 | "wpa_passphrase": "12345678", "wpa": "2", | |
323 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
d658205a JM |
324 | |
325 | logger.info("WPS provisioning attempt 1") | |
326 | hapd.request("WPS_PIN any 12345670") | |
33d0b157 | 327 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
d658205a | 328 | dev[0].dump_monitor() |
33d0b157 | 329 | dev[0].request("WPS_PIN %s 55554444" % apdev[0]['bssid']) |
d658205a JM |
330 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=30) |
331 | if ev is None: | |
332 | raise Exception("WPS operation timed out") | |
333 | if "config_error=18" not in ev: | |
334 | raise Exception("Incorrect config_error reported") | |
335 | if "msg=8" not in ev: | |
336 | raise Exception("PIN error detected on incorrect message") | |
5f35a5e2 | 337 | dev[0].wait_disconnected(timeout=10) |
d658205a JM |
338 | dev[0].request("WPS_CANCEL") |
339 | # if a scan was in progress, wait for it to complete before trying WPS again | |
340 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
341 | ||
d671a420 JM |
342 | status = hapd.request("WPS_GET_STATUS") |
343 | if "Last WPS result: Failed" not in status: | |
344 | raise Exception("WPS failure result not shown correctly") | |
345 | ||
d658205a JM |
346 | logger.info("WPS provisioning attempt 2") |
347 | hapd.request("WPS_PIN any 12345670") | |
348 | dev[0].dump_monitor() | |
33d0b157 | 349 | dev[0].request("WPS_PIN %s 12344444" % apdev[0]['bssid']) |
d658205a JM |
350 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=30) |
351 | if ev is None: | |
352 | raise Exception("WPS operation timed out") | |
353 | if "config_error=18" not in ev: | |
354 | raise Exception("Incorrect config_error reported") | |
355 | if "msg=10" not in ev: | |
356 | raise Exception("PIN error detected on incorrect message") | |
5f35a5e2 | 357 | dev[0].wait_disconnected(timeout=10) |
d658205a | 358 | |
9fd6804d | 359 | @remote_compatible |
ae3ad328 | 360 | def test_ap_wps_conf_pin(dev, apdev): |
302b7a1b JM |
361 | """WPS PIN provisioning with configured AP""" |
362 | ssid = "test-wps-conf-pin" | |
6f334bf7 JD |
363 | hapd = hostapd.add_ap(apdev[0], |
364 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
365 | "wpa_passphrase": "12345678", "wpa": "2", | |
366 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
302b7a1b JM |
367 | logger.info("WPS provisioning step") |
368 | pin = dev[0].wps_read_pin() | |
369 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 370 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 371 | dev[0].dump_monitor() |
33d0b157 | 372 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 373 | dev[0].wait_connected(timeout=30) |
302b7a1b | 374 | status = dev[0].get_status() |
ae3ad328 | 375 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
376 | raise Exception("Not fully connected") |
377 | if status['ssid'] != ssid: | |
378 | raise Exception("Unexpected SSID") | |
379 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
380 | raise Exception("Unexpected encryption configuration") | |
381 | if status['key_mgmt'] != 'WPA2-PSK': | |
382 | raise Exception("Unexpected key_mgmt") | |
383 | ||
84a40841 | 384 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
362ba6de JM |
385 | bss = dev[1].get_bss(apdev[0]['bssid']) |
386 | if "[WPS-AUTH]" in bss['flags']: | |
387 | raise Exception("WPS-AUTH flag not cleared") | |
a60a6d6b | 388 | logger.info("Try to connect from another station using the same PIN") |
33d0b157 | 389 | pin = dev[1].request("WPS_PIN " + apdev[0]['bssid']) |
a60a6d6b JM |
390 | ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30) |
391 | if ev is None: | |
392 | raise Exception("Operation timed out") | |
393 | if "WPS-M2D" not in ev: | |
394 | raise Exception("Unexpected WPS operation started") | |
6e12eaa4 | 395 | hapd.request("WPS_PIN any " + pin) |
5f35a5e2 | 396 | dev[1].wait_connected(timeout=30) |
362ba6de | 397 | |
ff518fbd JM |
398 | def test_ap_wps_conf_pin_mixed_mode(dev, apdev): |
399 | """WPS PIN provisioning with configured AP (WPA+WPA2)""" | |
400 | ssid = "test-wps-conf-pin-mixed" | |
6f334bf7 JD |
401 | hapd = hostapd.add_ap(apdev[0], |
402 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
403 | "wpa_passphrase": "12345678", "wpa": "3", | |
404 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
405 | "wpa_pairwise": "TKIP" }) | |
ff518fbd JM |
406 | |
407 | logger.info("WPS provisioning step") | |
408 | pin = dev[0].wps_read_pin() | |
409 | hapd.request("WPS_PIN any " + pin) | |
410 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
411 | dev[0].dump_monitor() | |
412 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
413 | dev[0].wait_connected(timeout=30) | |
414 | status = dev[0].get_status() | |
415 | dev[0].request("REMOVE_NETWORK all") | |
416 | dev[0].wait_disconnected() | |
417 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP' or status['key_mgmt'] != 'WPA2-PSK': | |
418 | raise Exception("Unexpected encryption/key_mgmt configuration: pairwise=%s group=%s key_mgmt=%s" % (status['pairwise_cipher'], status['group_cipher'], status['key_mgmt'])) | |
419 | ||
420 | logger.info("WPS provisioning step (auth_types=0x1b)") | |
421 | if "OK" not in dev[0].request("SET wps_force_auth_types 0x1b"): | |
422 | raise Exception("Failed to set wps_force_auth_types 0x1b") | |
423 | pin = dev[0].wps_read_pin() | |
424 | hapd.request("WPS_PIN any " + pin) | |
425 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
426 | dev[0].dump_monitor() | |
427 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
428 | dev[0].wait_connected(timeout=30) | |
429 | status = dev[0].get_status() | |
430 | dev[0].request("REMOVE_NETWORK all") | |
431 | dev[0].wait_disconnected() | |
432 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP' or status['key_mgmt'] != 'WPA2-PSK': | |
433 | raise Exception("Unexpected encryption/key_mgmt configuration: pairwise=%s group=%s key_mgmt=%s" % (status['pairwise_cipher'], status['group_cipher'], status['key_mgmt'])) | |
434 | ||
435 | logger.info("WPS provisioning step (auth_types=0 encr_types=0)") | |
436 | if "OK" not in dev[0].request("SET wps_force_auth_types 0"): | |
437 | raise Exception("Failed to set wps_force_auth_types 0") | |
438 | if "OK" not in dev[0].request("SET wps_force_encr_types 0"): | |
439 | raise Exception("Failed to set wps_force_encr_types 0") | |
440 | pin = dev[0].wps_read_pin() | |
441 | hapd.request("WPS_PIN any " + pin) | |
442 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
443 | dev[0].dump_monitor() | |
444 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
445 | dev[0].wait_connected(timeout=30) | |
446 | status = dev[0].get_status() | |
447 | dev[0].request("REMOVE_NETWORK all") | |
448 | dev[0].wait_disconnected() | |
449 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP' or status['key_mgmt'] != 'WPA2-PSK': | |
450 | raise Exception("Unexpected encryption/key_mgmt configuration: pairwise=%s group=%s key_mgmt=%s" % (status['pairwise_cipher'], status['group_cipher'], status['key_mgmt'])) | |
451 | ||
452 | dev[0].request("SET wps_force_auth_types ") | |
453 | dev[0].request("SET wps_force_encr_types ") | |
454 | ||
9fd6804d | 455 | @remote_compatible |
6257f9c0 JM |
456 | def test_ap_wps_conf_pin_v1(dev, apdev): |
457 | """WPS PIN provisioning with configured WPS v1.0 AP""" | |
458 | ssid = "test-wps-conf-pin-v1" | |
6f334bf7 JD |
459 | hapd = hostapd.add_ap(apdev[0], |
460 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
461 | "wpa_passphrase": "12345678", "wpa": "2", | |
462 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
6257f9c0 JM |
463 | logger.info("WPS provisioning step") |
464 | pin = dev[0].wps_read_pin() | |
465 | hapd.request("SET wps_version_number 0x10") | |
466 | hapd.request("WPS_PIN any " + pin) | |
467 | found = False | |
468 | for i in range(0, 10): | |
469 | dev[0].scan(freq="2412") | |
470 | if "[WPS-PIN]" in dev[0].request("SCAN_RESULTS"): | |
471 | found = True | |
472 | break | |
473 | if not found: | |
474 | hapd.request("SET wps_version_number 0x20") | |
475 | raise Exception("WPS-PIN flag not seen in scan results") | |
476 | dev[0].dump_monitor() | |
33d0b157 | 477 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 478 | dev[0].wait_connected(timeout=30) |
6257f9c0 | 479 | hapd.request("SET wps_version_number 0x20") |
6257f9c0 | 480 | |
9fd6804d | 481 | @remote_compatible |
e9129860 JM |
482 | def test_ap_wps_conf_pin_2sta(dev, apdev): |
483 | """Two stations trying to use WPS PIN at the same time""" | |
484 | ssid = "test-wps-conf-pin2" | |
6f334bf7 JD |
485 | hapd = hostapd.add_ap(apdev[0], |
486 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
487 | "wpa_passphrase": "12345678", "wpa": "2", | |
488 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e9129860 JM |
489 | logger.info("WPS provisioning step") |
490 | pin = "12345670" | |
491 | pin2 = "55554444" | |
492 | hapd.request("WPS_PIN " + dev[0].get_status_field("uuid") + " " + pin) | |
493 | hapd.request("WPS_PIN " + dev[1].get_status_field("uuid") + " " + pin) | |
e9129860 | 494 | dev[0].dump_monitor() |
e9129860 | 495 | dev[1].dump_monitor() |
33d0b157 JM |
496 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
497 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
498 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
499 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5f35a5e2 JM |
500 | dev[0].wait_connected(timeout=30) |
501 | dev[1].wait_connected(timeout=30) | |
0489e880 | 502 | |
9fd6804d | 503 | @remote_compatible |
0489e880 JM |
504 | def test_ap_wps_conf_pin_timeout(dev, apdev): |
505 | """WPS PIN provisioning with configured AP timing out PIN""" | |
506 | ssid = "test-wps-conf-pin" | |
6f334bf7 JD |
507 | hapd = hostapd.add_ap(apdev[0], |
508 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
509 | "wpa_passphrase": "12345678", "wpa": "2", | |
510 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
0489e880 JM |
511 | addr = dev[0].p2p_interface_addr() |
512 | pin = dev[0].wps_read_pin() | |
513 | if "FAIL" not in hapd.request("WPS_PIN "): | |
514 | raise Exception("Unexpected success on invalid WPS_PIN") | |
515 | hapd.request("WPS_PIN any " + pin + " 1") | |
33d0b157 | 516 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
0489e880 | 517 | time.sleep(1.1) |
33d0b157 | 518 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
0489e880 JM |
519 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=20) |
520 | if ev is None: | |
521 | raise Exception("WPS-PIN-NEEDED event timed out") | |
522 | ev = dev[0].wait_event(["WPS-M2D"]) | |
523 | if ev is None: | |
524 | raise Exception("M2D not reported") | |
525 | dev[0].request("WPS_CANCEL") | |
526 | ||
527 | hapd.request("WPS_PIN any " + pin + " 20 " + addr) | |
33d0b157 | 528 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 529 | dev[0].wait_connected(timeout=30) |
e9129860 | 530 | |
ae3ad328 | 531 | def test_ap_wps_reg_connect(dev, apdev): |
302b7a1b | 532 | """WPS registrar using AP PIN to connect""" |
803edd1c | 533 | ssid = "test-wps-reg-ap-pin" |
302b7a1b | 534 | appin = "12345670" |
8b8a1864 | 535 | hostapd.add_ap(apdev[0], |
302b7a1b JM |
536 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
537 | "wpa_passphrase": "12345678", "wpa": "2", | |
538 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
539 | "ap_pin": appin}) | |
540 | logger.info("WPS provisioning step") | |
302b7a1b | 541 | dev[0].dump_monitor() |
33d0b157 | 542 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 543 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
302b7a1b | 544 | status = dev[0].get_status() |
ae3ad328 | 545 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
546 | raise Exception("Not fully connected") |
547 | if status['ssid'] != ssid: | |
548 | raise Exception("Unexpected SSID") | |
549 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
550 | raise Exception("Unexpected encryption configuration") | |
551 | if status['key_mgmt'] != 'WPA2-PSK': | |
552 | raise Exception("Unexpected key_mgmt") | |
553 | ||
e60be3b3 JM |
554 | def test_ap_wps_reg_connect_mixed_mode(dev, apdev): |
555 | """WPS registrar using AP PIN to connect (WPA+WPA2)""" | |
556 | ssid = "test-wps-reg-ap-pin" | |
557 | appin = "12345670" | |
8b8a1864 | 558 | hostapd.add_ap(apdev[0], |
e60be3b3 JM |
559 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
560 | "wpa_passphrase": "12345678", "wpa": "3", | |
561 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
562 | "wpa_pairwise": "TKIP", "ap_pin": appin}) | |
563 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
564 | dev[0].wps_reg(apdev[0]['bssid'], appin) | |
565 | status = dev[0].get_status() | |
566 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
567 | raise Exception("Not fully connected") | |
568 | if status['ssid'] != ssid: | |
569 | raise Exception("Unexpected SSID") | |
570 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
571 | raise Exception("Unexpected encryption configuration") | |
572 | if status['key_mgmt'] != 'WPA2-PSK': | |
573 | raise Exception("Unexpected key_mgmt") | |
574 | ||
7511ead0 JM |
575 | def test_ap_wps_reg_override_ap_settings(dev, apdev): |
576 | """WPS registrar and ap_settings override""" | |
577 | ap_settings = "/tmp/ap_wps_reg_override_ap_settings" | |
578 | try: | |
579 | os.remove(ap_settings) | |
580 | except: | |
581 | pass | |
582 | # Override AP Settings with values that point to another AP | |
583 | data = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
584 | data += build_wsc_attr(ATTR_SSID, "test") | |
585 | data += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
586 | data += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
587 | data += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
588 | data += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[1]['bssid'].replace(':', ''))) | |
589 | with open(ap_settings, "w") as f: | |
590 | f.write(data) | |
591 | ssid = "test-wps-reg-ap-pin" | |
592 | appin = "12345670" | |
8b8a1864 | 593 | hostapd.add_ap(apdev[0], |
7511ead0 JM |
594 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
595 | "wpa_passphrase": "12345678", "wpa": "2", | |
596 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
597 | "ap_pin": appin, "ap_settings": ap_settings }) | |
8b8a1864 | 598 | hapd2 = hostapd.add_ap(apdev[1], { "ssid": "test" }) |
7511ead0 JM |
599 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
600 | dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412) | |
601 | dev[0].wps_reg(apdev[0]['bssid'], appin) | |
602 | ev = hapd2.wait_event(['AP-STA-CONNECTED'], timeout=10) | |
603 | os.remove(ap_settings) | |
604 | if ev is None: | |
605 | raise Exception("No connection with the other AP") | |
606 | ||
9488858f JM |
607 | def check_wps_reg_failure(dev, ap, appin): |
608 | dev.request("WPS_REG " + ap['bssid'] + " " + appin) | |
609 | ev = dev.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout=15) | |
610 | if ev is None: | |
611 | raise Exception("WPS operation timed out") | |
612 | if "WPS-SUCCESS" in ev: | |
613 | raise Exception("WPS operation succeeded unexpectedly") | |
614 | if "config_error=15" not in ev: | |
615 | raise Exception("WPS setup locked state was not reported correctly") | |
616 | ||
e4357b19 JM |
617 | def test_ap_wps_random_ap_pin(dev, apdev): |
618 | """WPS registrar using random AP PIN""" | |
619 | ssid = "test-wps-reg-random-ap-pin" | |
620 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
6f334bf7 JD |
621 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
622 | "wpa_passphrase": "12345678", "wpa": "2", | |
623 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
624 | "device_name": "Wireless AP", "manufacturer": "Company", | |
625 | "model_name": "WAP", "model_number": "123", | |
626 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
627 | "os_version": "01020300", | |
628 | "config_methods": "label push_button", | |
629 | "uuid": ap_uuid, "upnp_iface": "lo" } | |
630 | hapd = hostapd.add_ap(apdev[0], params) | |
e4357b19 JM |
631 | appin = hapd.request("WPS_AP_PIN random") |
632 | if "FAIL" in appin: | |
633 | raise Exception("Could not generate random AP PIN") | |
634 | if appin not in hapd.request("WPS_AP_PIN get"): | |
635 | raise Exception("Could not fetch current AP PIN") | |
636 | logger.info("WPS provisioning step") | |
33d0b157 | 637 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
e4357b19 JM |
638 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
639 | ||
640 | hapd.request("WPS_AP_PIN disable") | |
641 | logger.info("WPS provisioning step with AP PIN disabled") | |
33d0b157 | 642 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9488858f JM |
643 | check_wps_reg_failure(dev[1], apdev[0], appin) |
644 | ||
645 | logger.info("WPS provisioning step with AP PIN reset") | |
646 | appin = "12345670" | |
647 | hapd.request("WPS_AP_PIN set " + appin) | |
648 | dev[1].wps_reg(apdev[0]['bssid'], appin) | |
649 | dev[0].request("REMOVE_NETWORK all") | |
650 | dev[1].request("REMOVE_NETWORK all") | |
5f35a5e2 JM |
651 | dev[0].wait_disconnected(timeout=10) |
652 | dev[1].wait_disconnected(timeout=10) | |
9488858f JM |
653 | |
654 | logger.info("WPS provisioning step after AP PIN timeout") | |
655 | hapd.request("WPS_AP_PIN disable") | |
656 | appin = hapd.request("WPS_AP_PIN random 1") | |
657 | time.sleep(1.1) | |
658 | if "FAIL" not in hapd.request("WPS_AP_PIN get"): | |
659 | raise Exception("AP PIN unexpectedly still enabled") | |
660 | check_wps_reg_failure(dev[0], apdev[0], appin) | |
661 | ||
662 | logger.info("WPS provisioning step after AP PIN timeout(2)") | |
663 | hapd.request("WPS_AP_PIN disable") | |
664 | appin = "12345670" | |
665 | hapd.request("WPS_AP_PIN set " + appin + " 1") | |
666 | time.sleep(1.1) | |
667 | if "FAIL" not in hapd.request("WPS_AP_PIN get"): | |
668 | raise Exception("AP PIN unexpectedly still enabled") | |
669 | check_wps_reg_failure(dev[1], apdev[0], appin) | |
e4357b19 | 670 | |
24b7f282 | 671 | with fail_test(hapd, 1, "os_get_random;wps_generate_pin"): |
20c48fd9 | 672 | hapd.request("WPS_AP_PIN random 1") |
24b7f282 JM |
673 | hapd.request("WPS_AP_PIN disable") |
674 | ||
675 | with alloc_fail(hapd, 1, "upnp_wps_set_ap_pin"): | |
676 | hapd.request("WPS_AP_PIN set 12345670") | |
677 | hapd.request("WPS_AP_PIN disable") | |
678 | ||
ae3ad328 | 679 | def test_ap_wps_reg_config(dev, apdev): |
4b727c5c | 680 | """WPS registrar configuring an AP using AP PIN""" |
302b7a1b JM |
681 | ssid = "test-wps-init-ap-pin" |
682 | appin = "12345670" | |
8b8a1864 | 683 | hostapd.add_ap(apdev[0], |
302b7a1b JM |
684 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
685 | "ap_pin": appin}) | |
686 | logger.info("WPS configuration step") | |
33d0b157 | 687 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
302b7a1b JM |
688 | dev[0].dump_monitor() |
689 | new_ssid = "wps-new-ssid" | |
690 | new_passphrase = "1234567890" | |
6edaee9c JM |
691 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", |
692 | new_passphrase) | |
302b7a1b | 693 | status = dev[0].get_status() |
ae3ad328 | 694 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
695 | raise Exception("Not fully connected") |
696 | if status['ssid'] != new_ssid: | |
697 | raise Exception("Unexpected SSID") | |
698 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
699 | raise Exception("Unexpected encryption configuration") | |
700 | if status['key_mgmt'] != 'WPA2-PSK': | |
701 | raise Exception("Unexpected key_mgmt") | |
702 | ||
375afd7c JM |
703 | logger.info("Re-configure back to open") |
704 | dev[0].request("REMOVE_NETWORK all") | |
243dcc4a | 705 | dev[0].flush_scan_cache() |
375afd7c JM |
706 | dev[0].dump_monitor() |
707 | dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-open", "OPEN", "NONE", "") | |
708 | status = dev[0].get_status() | |
709 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
710 | raise Exception("Not fully connected") | |
711 | if status['ssid'] != "wps-open": | |
712 | raise Exception("Unexpected SSID") | |
713 | if status['key_mgmt'] != 'NONE': | |
714 | raise Exception("Unexpected key_mgmt") | |
715 | ||
4b727c5c JM |
716 | def test_ap_wps_reg_config_ext_processing(dev, apdev): |
717 | """WPS registrar configuring an AP with external config processing""" | |
718 | ssid = "test-wps-init-ap-pin" | |
719 | appin = "12345670" | |
720 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
721 | "wps_cred_processing": "1", "ap_pin": appin} | |
8b8a1864 | 722 | hapd = hostapd.add_ap(apdev[0], params) |
33d0b157 | 723 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
4b727c5c JM |
724 | new_ssid = "wps-new-ssid" |
725 | new_passphrase = "1234567890" | |
726 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", | |
727 | new_passphrase, no_wait=True) | |
728 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
729 | if ev is None: | |
730 | raise Exception("WPS registrar operation timed out") | |
731 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=15) | |
732 | if ev is None: | |
733 | raise Exception("WPS configuration timed out") | |
734 | if "1026" not in ev: | |
735 | raise Exception("AP Settings missing from event") | |
736 | hapd.request("SET wps_cred_processing 0") | |
737 | if "FAIL" in hapd.request("WPS_CONFIG " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex")): | |
738 | raise Exception("WPS_CONFIG command failed") | |
5f35a5e2 | 739 | dev[0].wait_connected(timeout=15) |
4b727c5c | 740 | |
eeefe187 JM |
741 | def test_ap_wps_reg_config_tkip(dev, apdev): |
742 | """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP""" | |
a1eabc74 | 743 | skip_with_fips(dev[0]) |
eeefe187 JM |
744 | ssid = "test-wps-init-ap" |
745 | appin = "12345670" | |
8b8a1864 | 746 | hostapd.add_ap(apdev[0], |
eeefe187 JM |
747 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", |
748 | "ap_pin": appin}) | |
749 | logger.info("WPS configuration step") | |
eeefe187 | 750 | dev[0].request("SET wps_version_number 0x10") |
33d0b157 | 751 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
eeefe187 JM |
752 | dev[0].dump_monitor() |
753 | new_ssid = "wps-new-ssid-with-tkip" | |
754 | new_passphrase = "1234567890" | |
755 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP", | |
756 | new_passphrase) | |
757 | logger.info("Re-connect to verify WPA2 mixed mode") | |
758 | dev[0].request("DISCONNECT") | |
759 | id = 0 | |
760 | dev[0].set_network(id, "pairwise", "CCMP") | |
761 | dev[0].set_network(id, "proto", "RSN") | |
762 | dev[0].connect_network(id) | |
763 | status = dev[0].get_status() | |
764 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
3c086180 | 765 | raise Exception("Not fully connected: wpa_state={} bssid={}".format(status['wpa_state'], status['bssid'])) |
eeefe187 JM |
766 | if status['ssid'] != new_ssid: |
767 | raise Exception("Unexpected SSID") | |
768 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
769 | raise Exception("Unexpected encryption configuration") | |
770 | if status['key_mgmt'] != 'WPA2-PSK': | |
771 | raise Exception("Unexpected key_mgmt") | |
772 | ||
6645ff50 JM |
773 | def test_ap_wps_setup_locked(dev, apdev): |
774 | """WPS registrar locking up AP setup on AP PIN failures""" | |
775 | ssid = "test-wps-incorrect-ap-pin" | |
776 | appin = "12345670" | |
6f334bf7 JD |
777 | hapd = hostapd.add_ap(apdev[0], |
778 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
779 | "wpa_passphrase": "12345678", "wpa": "2", | |
780 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
781 | "ap_pin": appin}) | |
6645ff50 JM |
782 | new_ssid = "wps-new-ssid-test" |
783 | new_passphrase = "1234567890" | |
784 | ||
33d0b157 | 785 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6645ff50 JM |
786 | ap_setup_locked=False |
787 | for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]: | |
788 | dev[0].dump_monitor() | |
789 | logger.info("Try incorrect AP PIN - attempt " + pin) | |
790 | dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK", | |
791 | "CCMP", new_passphrase, no_wait=True) | |
792 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"]) | |
793 | if ev is None: | |
794 | raise Exception("Timeout on receiving WPS operation failure event") | |
795 | if "CTRL-EVENT-CONNECTED" in ev: | |
796 | raise Exception("Unexpected connection") | |
797 | if "config_error=15" in ev: | |
798 | logger.info("AP Setup Locked") | |
799 | ap_setup_locked=True | |
800 | elif "config_error=18" not in ev: | |
801 | raise Exception("config_error=18 not reported") | |
5f35a5e2 | 802 | dev[0].wait_disconnected(timeout=10) |
6645ff50 JM |
803 | time.sleep(0.1) |
804 | if not ap_setup_locked: | |
805 | raise Exception("AP setup was not locked") | |
24b7f282 JM |
806 | dev[0].request("WPS_CANCEL") |
807 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True, | |
808 | only_new=True) | |
809 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
810 | if 'wps_ap_setup_locked' not in bss or bss['wps_ap_setup_locked'] != '1': | |
811 | logger.info("BSS: " + str(bss)) | |
812 | raise Exception("AP Setup Locked not indicated in scan results") | |
6645ff50 | 813 | |
d671a420 JM |
814 | status = hapd.request("WPS_GET_STATUS") |
815 | if "Last WPS result: Failed" not in status: | |
816 | raise Exception("WPS failure result not shown correctly") | |
817 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
818 | raise Exception("Peer address not shown correctly") | |
819 | ||
6645ff50 JM |
820 | time.sleep(0.5) |
821 | dev[0].dump_monitor() | |
822 | logger.info("WPS provisioning step") | |
823 | pin = dev[0].wps_read_pin() | |
6645ff50 | 824 | hapd.request("WPS_PIN any " + pin) |
33d0b157 | 825 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
6645ff50 JM |
826 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30) |
827 | if ev is None: | |
828 | raise Exception("WPS success was not reported") | |
5f35a5e2 | 829 | dev[0].wait_connected(timeout=30) |
6645ff50 | 830 | |
c1cec68b JM |
831 | appin = hapd.request("WPS_AP_PIN random") |
832 | if "FAIL" in appin: | |
833 | raise Exception("Could not generate random AP PIN") | |
834 | ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=10) | |
835 | if ev is None: | |
836 | raise Exception("Failed to unlock AP PIN") | |
837 | ||
33c9b8d8 JM |
838 | def test_ap_wps_setup_locked_timeout(dev, apdev): |
839 | """WPS re-enabling AP PIN after timeout""" | |
840 | ssid = "test-wps-incorrect-ap-pin" | |
841 | appin = "12345670" | |
6f334bf7 JD |
842 | hapd = hostapd.add_ap(apdev[0], |
843 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
844 | "wpa_passphrase": "12345678", "wpa": "2", | |
845 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
846 | "ap_pin": appin}) | |
33c9b8d8 JM |
847 | new_ssid = "wps-new-ssid-test" |
848 | new_passphrase = "1234567890" | |
849 | ||
33d0b157 | 850 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
33c9b8d8 JM |
851 | ap_setup_locked=False |
852 | for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]: | |
853 | dev[0].dump_monitor() | |
854 | logger.info("Try incorrect AP PIN - attempt " + pin) | |
855 | dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK", | |
856 | "CCMP", new_passphrase, no_wait=True) | |
9ed53f5e | 857 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"], timeout=15) |
33c9b8d8 JM |
858 | if ev is None: |
859 | raise Exception("Timeout on receiving WPS operation failure event") | |
860 | if "CTRL-EVENT-CONNECTED" in ev: | |
861 | raise Exception("Unexpected connection") | |
862 | if "config_error=15" in ev: | |
863 | logger.info("AP Setup Locked") | |
864 | ap_setup_locked=True | |
865 | break | |
866 | elif "config_error=18" not in ev: | |
867 | raise Exception("config_error=18 not reported") | |
5f35a5e2 | 868 | dev[0].wait_disconnected(timeout=10) |
33c9b8d8 JM |
869 | time.sleep(0.1) |
870 | if not ap_setup_locked: | |
871 | raise Exception("AP setup was not locked") | |
33c9b8d8 JM |
872 | ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=80) |
873 | if ev is None: | |
874 | raise Exception("AP PIN did not get unlocked on 60 second timeout") | |
875 | ||
4c355e3e JM |
876 | def test_ap_wps_setup_locked_2(dev, apdev): |
877 | """WPS AP configured for special ap_setup_locked=2 mode""" | |
878 | ssid = "test-wps-ap-pin" | |
879 | appin = "12345670" | |
880 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
881 | "wpa_passphrase": "12345678", "wpa": "2", | |
882 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
883 | "ap_pin": appin, "ap_setup_locked": "2" } | |
8b8a1864 | 884 | hapd = hostapd.add_ap(apdev[0], params) |
4c355e3e JM |
885 | new_ssid = "wps-new-ssid-test" |
886 | new_passphrase = "1234567890" | |
887 | ||
888 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
889 | dev[0].wps_reg(apdev[0]['bssid'], appin) | |
890 | dev[0].request("REMOVE_NETWORK all") | |
891 | dev[0].wait_disconnected() | |
892 | ||
893 | hapd.dump_monitor() | |
894 | dev[0].dump_monitor() | |
895 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", | |
896 | "CCMP", new_passphrase, no_wait=True) | |
897 | ||
898 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
899 | if ev is None: | |
900 | raise Exception("hostapd did not report WPS failure") | |
901 | if "msg=12 config_error=15" not in ev: | |
902 | raise Exception("Unexpected failure reason (AP): " + ev) | |
903 | ||
904 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"]) | |
905 | if ev is None: | |
906 | raise Exception("Timeout on receiving WPS operation failure event") | |
907 | if "CTRL-EVENT-CONNECTED" in ev: | |
908 | raise Exception("Unexpected connection") | |
909 | if "config_error=15" not in ev: | |
910 | raise Exception("Unexpected failure reason (STA): " + ev) | |
911 | dev[0].request("WPS_CANCEL") | |
912 | dev[0].wait_disconnected() | |
913 | ||
9fd6804d | 914 | @remote_compatible |
ae3ad328 | 915 | def test_ap_wps_pbc_overlap_2ap(dev, apdev): |
302b7a1b | 916 | """WPS PBC session overlap with two active APs""" |
6f334bf7 JD |
917 | params = { "ssid": "wps1", "eap_server": "1", "wps_state": "2", |
918 | "wpa_passphrase": "12345678", "wpa": "2", | |
919 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
920 | "wps_independent": "1"} | |
921 | hapd = hostapd.add_ap(apdev[0], params) | |
922 | params = { "ssid": "wps2", "eap_server": "1", "wps_state": "2", | |
923 | "wpa_passphrase": "123456789", "wpa": "2", | |
924 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
925 | "wps_independent": "1"} | |
926 | hapd2 = hostapd.add_ap(apdev[1], params) | |
302b7a1b | 927 | hapd.request("WPS_PBC") |
302b7a1b JM |
928 | hapd2.request("WPS_PBC") |
929 | logger.info("WPS provisioning step") | |
84a40841 JM |
930 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
931 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
302b7a1b JM |
932 | dev[0].request("WPS_PBC") |
933 | ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15) | |
934 | if ev is None: | |
935 | raise Exception("PBC session overlap not detected") | |
492c3a91 JM |
936 | hapd.request("DISABLE") |
937 | hapd2.request("DISABLE") | |
938 | dev[0].flush_scan_cache() | |
302b7a1b | 939 | |
9fd6804d | 940 | @remote_compatible |
ae3ad328 | 941 | def test_ap_wps_pbc_overlap_2sta(dev, apdev): |
302b7a1b JM |
942 | """WPS PBC session overlap with two active STAs""" |
943 | ssid = "test-wps-pbc-overlap" | |
6f334bf7 JD |
944 | hapd = hostapd.add_ap(apdev[0], |
945 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
946 | "wpa_passphrase": "12345678", "wpa": "2", | |
947 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
302b7a1b JM |
948 | logger.info("WPS provisioning step") |
949 | hapd.request("WPS_PBC") | |
33d0b157 | 950 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 951 | dev[0].dump_monitor() |
33d0b157 | 952 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 953 | dev[1].dump_monitor() |
33d0b157 JM |
954 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
955 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
302b7a1b JM |
956 | ev = dev[0].wait_event(["WPS-M2D"], timeout=15) |
957 | if ev is None: | |
958 | raise Exception("PBC session overlap not detected (dev0)") | |
959 | if "config_error=12" not in ev: | |
960 | raise Exception("PBC session overlap not correctly reported (dev0)") | |
492c3a91 JM |
961 | dev[0].request("WPS_CANCEL") |
962 | dev[0].request("DISCONNECT") | |
302b7a1b JM |
963 | ev = dev[1].wait_event(["WPS-M2D"], timeout=15) |
964 | if ev is None: | |
965 | raise Exception("PBC session overlap not detected (dev1)") | |
966 | if "config_error=12" not in ev: | |
967 | raise Exception("PBC session overlap not correctly reported (dev1)") | |
492c3a91 JM |
968 | dev[1].request("WPS_CANCEL") |
969 | dev[1].request("DISCONNECT") | |
11e7eeba JM |
970 | hapd.request("WPS_CANCEL") |
971 | ret = hapd.request("WPS_PBC") | |
972 | if "FAIL" not in ret: | |
973 | raise Exception("PBC mode allowed to be started while PBC overlap still active") | |
492c3a91 JM |
974 | hapd.request("DISABLE") |
975 | dev[0].flush_scan_cache() | |
976 | dev[1].flush_scan_cache() | |
6edaee9c | 977 | |
9fd6804d | 978 | @remote_compatible |
71afe834 JM |
979 | def test_ap_wps_cancel(dev, apdev): |
980 | """WPS AP cancelling enabled config method""" | |
981 | ssid = "test-wps-ap-cancel" | |
6f334bf7 JD |
982 | hapd = hostapd.add_ap(apdev[0], |
983 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
984 | "wpa_passphrase": "12345678", "wpa": "2", | |
985 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
71afe834 | 986 | bssid = apdev[0]['bssid'] |
71afe834 JM |
987 | |
988 | logger.info("Verify PBC enable/cancel") | |
989 | hapd.request("WPS_PBC") | |
71afe834 | 990 | dev[0].scan(freq="2412") |
84a40841 | 991 | dev[0].scan(freq="2412") |
71afe834 JM |
992 | bss = dev[0].get_bss(apdev[0]['bssid']) |
993 | if "[WPS-PBC]" not in bss['flags']: | |
994 | raise Exception("WPS-PBC flag missing") | |
995 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
996 | raise Exception("WPS_CANCEL failed") | |
997 | dev[0].scan(freq="2412") | |
84a40841 | 998 | dev[0].scan(freq="2412") |
71afe834 JM |
999 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1000 | if "[WPS-PBC]" in bss['flags']: | |
1001 | raise Exception("WPS-PBC flag not cleared") | |
1002 | ||
1003 | logger.info("Verify PIN enable/cancel") | |
1004 | hapd.request("WPS_PIN any 12345670") | |
1005 | dev[0].scan(freq="2412") | |
84a40841 | 1006 | dev[0].scan(freq="2412") |
71afe834 JM |
1007 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1008 | if "[WPS-AUTH]" not in bss['flags']: | |
1009 | raise Exception("WPS-AUTH flag missing") | |
1010 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
1011 | raise Exception("WPS_CANCEL failed") | |
1012 | dev[0].scan(freq="2412") | |
84a40841 | 1013 | dev[0].scan(freq="2412") |
71afe834 JM |
1014 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1015 | if "[WPS-AUTH]" in bss['flags']: | |
1016 | raise Exception("WPS-AUTH flag not cleared") | |
1017 | ||
6edaee9c JM |
1018 | def test_ap_wps_er_add_enrollee(dev, apdev): |
1019 | """WPS ER configuring AP and adding a new enrollee using PIN""" | |
be9f1562 JM |
1020 | try: |
1021 | _test_ap_wps_er_add_enrollee(dev, apdev) | |
1022 | finally: | |
1023 | dev[0].request("WPS_ER_STOP") | |
1024 | ||
1025 | def _test_ap_wps_er_add_enrollee(dev, apdev): | |
6edaee9c JM |
1026 | ssid = "wps-er-add-enrollee" |
1027 | ap_pin = "12345670" | |
1028 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1029 | hostapd.add_ap(apdev[0], |
6edaee9c JM |
1030 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", |
1031 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1032 | "model_name": "WAP", "model_number": "123", | |
1033 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1034 | "os_version": "01020300", | |
24b7f282 | 1035 | 'friendly_name': "WPS AP - <>&'\" - TEST", |
6edaee9c JM |
1036 | "config_methods": "label push_button", |
1037 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1038 | logger.info("WPS configuration step") | |
1039 | new_passphrase = "1234567890" | |
1040 | dev[0].dump_monitor() | |
33d0b157 | 1041 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c JM |
1042 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP", |
1043 | new_passphrase) | |
1044 | status = dev[0].get_status() | |
1045 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1046 | raise Exception("Not fully connected") | |
1047 | if status['ssid'] != ssid: | |
1048 | raise Exception("Unexpected SSID") | |
1049 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
1050 | raise Exception("Unexpected encryption configuration") | |
1051 | if status['key_mgmt'] != 'WPA2-PSK': | |
1052 | raise Exception("Unexpected key_mgmt") | |
1053 | ||
1054 | logger.info("Start ER") | |
1055 | dev[0].request("WPS_ER_START ifname=lo") | |
1056 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1057 | if ev is None: | |
1058 | raise Exception("AP discovery timed out") | |
1059 | if ap_uuid not in ev: | |
1060 | raise Exception("Expected AP UUID not found") | |
24b7f282 JM |
1061 | if "|WPS AP - <>&'" - TEST|Company|" not in ev: |
1062 | raise Exception("Expected friendly name not found") | |
6edaee9c JM |
1063 | |
1064 | logger.info("Learn AP configuration through UPnP") | |
1065 | dev[0].dump_monitor() | |
1066 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1067 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1068 | if ev is None: | |
1069 | raise Exception("AP learn timed out") | |
1070 | if ap_uuid not in ev: | |
1071 | raise Exception("Expected AP UUID not in settings") | |
1072 | if "ssid=" + ssid not in ev: | |
1073 | raise Exception("Expected SSID not in settings") | |
1074 | if "key=" + new_passphrase not in ev: | |
1075 | raise Exception("Expected passphrase not in settings") | |
33d0b157 JM |
1076 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) |
1077 | if ev is None: | |
1078 | raise Exception("WPS-FAIL after AP learn timed out") | |
1079 | time.sleep(0.1) | |
6edaee9c JM |
1080 | |
1081 | logger.info("Add Enrollee using ER") | |
1082 | pin = dev[1].wps_read_pin() | |
1083 | dev[0].dump_monitor() | |
1084 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
33d0b157 | 1085 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 1086 | dev[1].dump_monitor() |
33d0b157 | 1087 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
846be889 | 1088 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) |
6edaee9c JM |
1089 | if ev is None: |
1090 | raise Exception("Enrollee did not report success") | |
5f35a5e2 | 1091 | dev[1].wait_connected(timeout=15) |
6edaee9c JM |
1092 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1093 | if ev is None: | |
1094 | raise Exception("WPS ER did not report success") | |
1095 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
1096 | ||
11c26f1b JM |
1097 | logger.info("Add a specific Enrollee using ER") |
1098 | pin = dev[2].wps_read_pin() | |
1099 | addr2 = dev[2].p2p_interface_addr() | |
1100 | dev[0].dump_monitor() | |
33d0b157 | 1101 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
11c26f1b | 1102 | dev[2].dump_monitor() |
33d0b157 | 1103 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
11c26f1b JM |
1104 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) |
1105 | if ev is None: | |
1106 | raise Exception("Enrollee not seen") | |
1107 | if addr2 not in ev: | |
1108 | raise Exception("Unexpected Enrollee MAC address") | |
1109 | dev[0].request("WPS_ER_PIN " + addr2 + " " + pin + " " + addr2) | |
5f35a5e2 | 1110 | dev[2].wait_connected(timeout=30) |
11c26f1b JM |
1111 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1112 | if ev is None: | |
1113 | raise Exception("WPS ER did not report success") | |
1114 | ||
38ae43de JM |
1115 | logger.info("Verify registrar selection behavior") |
1116 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
1117 | dev[1].request("DISCONNECT") | |
5f35a5e2 | 1118 | dev[1].wait_disconnected(timeout=10) |
84a40841 | 1119 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
38ae43de JM |
1120 | dev[1].scan(freq="2412") |
1121 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
1122 | if "[WPS-AUTH]" not in bss['flags']: | |
321c7f60 JM |
1123 | # It is possible for scan to miss an update especially when running |
1124 | # tests under load with multiple VMs, so allow another attempt. | |
1125 | dev[1].scan(freq="2412") | |
1126 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
1127 | if "[WPS-AUTH]" not in bss['flags']: | |
1128 | raise Exception("WPS-AUTH flag missing") | |
38ae43de JM |
1129 | |
1130 | logger.info("Stop ER") | |
1131 | dev[0].dump_monitor() | |
1132 | dev[0].request("WPS_ER_STOP") | |
1133 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"]) | |
1134 | if ev is None: | |
1135 | raise Exception("WPS ER unsubscription timed out") | |
8697cbc0 | 1136 | # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait |
befd671c | 1137 | # a bit before verifying that the scan results have changed. |
8697cbc0 | 1138 | time.sleep(0.2) |
38ae43de | 1139 | |
befd671c JM |
1140 | for i in range(0, 10): |
1141 | dev[1].request("BSS_FLUSH 0") | |
1142 | dev[1].scan(freq="2412", only_new=True) | |
1143 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
1144 | if bss and 'flags' in bss and "[WPS-AUTH]" not in bss['flags']: | |
1145 | break | |
1146 | logger.debug("WPS-AUTH flag was still in place - wait a bit longer") | |
1147 | time.sleep(0.1) | |
38ae43de JM |
1148 | if "[WPS-AUTH]" in bss['flags']: |
1149 | raise Exception("WPS-AUTH flag not removed") | |
1150 | ||
c965ae03 JM |
1151 | def test_ap_wps_er_add_enrollee_uuid(dev, apdev): |
1152 | """WPS ER adding a new enrollee identified by UUID""" | |
1153 | try: | |
1154 | _test_ap_wps_er_add_enrollee_uuid(dev, apdev) | |
1155 | finally: | |
1156 | dev[0].request("WPS_ER_STOP") | |
1157 | ||
1158 | def _test_ap_wps_er_add_enrollee_uuid(dev, apdev): | |
1159 | ssid = "wps-er-add-enrollee" | |
1160 | ap_pin = "12345670" | |
1161 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1162 | hostapd.add_ap(apdev[0], |
c965ae03 JM |
1163 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1164 | "wpa_passphrase": "12345678", "wpa": "2", | |
1165 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1166 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1167 | "model_name": "WAP", "model_number": "123", | |
1168 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1169 | "os_version": "01020300", | |
1170 | "config_methods": "label push_button", | |
1171 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1172 | logger.info("WPS configuration step") | |
1173 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1174 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1175 | ||
1176 | logger.info("Start ER") | |
1177 | dev[0].request("WPS_ER_START ifname=lo") | |
1178 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1179 | if ev is None: | |
1180 | raise Exception("AP discovery timed out") | |
1181 | if ap_uuid not in ev: | |
1182 | raise Exception("Expected AP UUID not found") | |
1183 | ||
1184 | logger.info("Learn AP configuration through UPnP") | |
1185 | dev[0].dump_monitor() | |
1186 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1187 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1188 | if ev is None: | |
1189 | raise Exception("AP learn timed out") | |
1190 | if ap_uuid not in ev: | |
1191 | raise Exception("Expected AP UUID not in settings") | |
1192 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1193 | if ev is None: | |
1194 | raise Exception("WPS-FAIL after AP learn timed out") | |
1195 | time.sleep(0.1) | |
1196 | ||
1197 | logger.info("Add a specific Enrollee using ER (PBC/UUID)") | |
1198 | addr1 = dev[1].p2p_interface_addr() | |
1199 | dev[0].dump_monitor() | |
1200 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1201 | dev[1].dump_monitor() | |
1202 | dev[1].request("WPS_PBC %s" % apdev[0]['bssid']) | |
1203 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) | |
1204 | if ev is None: | |
1205 | raise Exception("Enrollee not seen") | |
1206 | if addr1 not in ev: | |
1207 | raise Exception("Unexpected Enrollee MAC address") | |
1208 | uuid = ev.split(' ')[1] | |
1209 | dev[0].request("WPS_ER_PBC " + uuid) | |
1210 | dev[1].wait_connected(timeout=30) | |
1211 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
1212 | if ev is None: | |
1213 | raise Exception("WPS ER did not report success") | |
1214 | ||
1215 | logger.info("Add a specific Enrollee using ER (PIN/UUID)") | |
1216 | pin = dev[2].wps_read_pin() | |
1217 | addr2 = dev[2].p2p_interface_addr() | |
1218 | dev[0].dump_monitor() | |
1219 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1220 | dev[2].dump_monitor() | |
1221 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
1222 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) | |
1223 | if ev is None: | |
1224 | raise Exception("Enrollee not seen") | |
1225 | if addr2 not in ev: | |
1226 | raise Exception("Unexpected Enrollee MAC address") | |
1227 | uuid = ev.split(' ')[1] | |
1228 | dev[0].request("WPS_ER_PIN " + uuid + " " + pin) | |
1229 | dev[2].wait_connected(timeout=30) | |
1230 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
1231 | if ev is None: | |
1232 | raise Exception("WPS ER did not report success") | |
1233 | ||
ea982de1 JM |
1234 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-REMOVE"], timeout=15) |
1235 | if ev is None: | |
1236 | raise Exception("No Enrollee STA entry timeout seen") | |
1237 | ||
c965ae03 JM |
1238 | logger.info("Stop ER") |
1239 | dev[0].dump_monitor() | |
1240 | dev[0].request("WPS_ER_STOP") | |
1241 | ||
61c3d464 JM |
1242 | def test_ap_wps_er_multi_add_enrollee(dev, apdev): |
1243 | """Multiple WPS ERs adding a new enrollee using PIN""" | |
1244 | try: | |
1245 | _test_ap_wps_er_multi_add_enrollee(dev, apdev) | |
1246 | finally: | |
d887ed3f JM |
1247 | for i in range(2): |
1248 | dev[i].request("WPS_ER_STOP") | |
61c3d464 JM |
1249 | |
1250 | def _test_ap_wps_er_multi_add_enrollee(dev, apdev): | |
1251 | ssid = "wps-er-add-enrollee" | |
1252 | ap_pin = "12345670" | |
1253 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1254 | hostapd.add_ap(apdev[0], |
61c3d464 JM |
1255 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1256 | "wpa_passphrase": "12345678", "wpa": "2", | |
1257 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1258 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1259 | "model_name": "WAP", "model_number": "123", | |
1260 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1261 | "os_version": "01020300", | |
1262 | 'friendly_name': "WPS AP", | |
1263 | "config_methods": "label push_button", | |
1264 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1265 | ||
1266 | for i in range(2): | |
1267 | dev[i].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1268 | dev[i].wps_reg(apdev[0]['bssid'], ap_pin) | |
6a5f578c | 1269 | for i in range(2): |
61c3d464 JM |
1270 | dev[i].request("WPS_ER_START ifname=lo") |
1271 | for i in range(2): | |
1272 | ev = dev[i].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1273 | if ev is None: | |
1274 | raise Exception("AP discovery timed out") | |
1275 | dev[i].dump_monitor() | |
6a5f578c | 1276 | for i in range(2): |
61c3d464 | 1277 | dev[i].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) |
6a5f578c | 1278 | for i in range(2): |
61c3d464 JM |
1279 | ev = dev[i].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) |
1280 | if ev is None: | |
1281 | raise Exception("AP learn timed out") | |
1282 | ev = dev[i].wait_event(["WPS-FAIL"], timeout=15) | |
1283 | if ev is None: | |
1284 | raise Exception("WPS-FAIL after AP learn timed out") | |
1285 | ||
1286 | time.sleep(0.1) | |
1287 | ||
1288 | pin = dev[2].wps_read_pin() | |
1289 | addr = dev[2].own_addr() | |
1290 | dev[0].dump_monitor() | |
1291 | dev[0].request("WPS_ER_PIN any " + pin + " " + addr) | |
1292 | dev[1].dump_monitor() | |
1293 | dev[1].request("WPS_ER_PIN any " + pin + " " + addr) | |
1294 | ||
1295 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1296 | dev[2].dump_monitor() | |
1297 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
1298 | ev = dev[2].wait_event(["WPS-SUCCESS"], timeout=30) | |
1299 | if ev is None: | |
1300 | raise Exception("Enrollee did not report success") | |
1301 | dev[2].wait_connected(timeout=15) | |
1302 | ||
6edaee9c JM |
1303 | def test_ap_wps_er_add_enrollee_pbc(dev, apdev): |
1304 | """WPS ER connected to AP and adding a new enrollee using PBC""" | |
be9f1562 JM |
1305 | try: |
1306 | _test_ap_wps_er_add_enrollee_pbc(dev, apdev) | |
1307 | finally: | |
1308 | dev[0].request("WPS_ER_STOP") | |
1309 | ||
1310 | def _test_ap_wps_er_add_enrollee_pbc(dev, apdev): | |
6edaee9c JM |
1311 | ssid = "wps-er-add-enrollee-pbc" |
1312 | ap_pin = "12345670" | |
1313 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1314 | hostapd.add_ap(apdev[0], |
6edaee9c JM |
1315 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1316 | "wpa_passphrase": "12345678", "wpa": "2", | |
1317 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1318 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1319 | "model_name": "WAP", "model_number": "123", | |
1320 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1321 | "os_version": "01020300", | |
1322 | "config_methods": "label push_button", | |
1323 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1324 | logger.info("Learn AP configuration") | |
33d0b157 | 1325 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 1326 | dev[0].dump_monitor() |
6edaee9c JM |
1327 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) |
1328 | status = dev[0].get_status() | |
1329 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1330 | raise Exception("Not fully connected") | |
1331 | ||
1332 | logger.info("Start ER") | |
1333 | dev[0].request("WPS_ER_START ifname=lo") | |
1334 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1335 | if ev is None: | |
1336 | raise Exception("AP discovery timed out") | |
1337 | if ap_uuid not in ev: | |
1338 | raise Exception("Expected AP UUID not found") | |
1339 | ||
d6b916c9 JM |
1340 | enrollee = dev[1].p2p_interface_addr() |
1341 | ||
1342 | if "FAIL-UNKNOWN-UUID" not in dev[0].request("WPS_ER_PBC " + enrollee): | |
1343 | raise Exception("Unknown UUID not reported") | |
6edaee9c JM |
1344 | |
1345 | logger.info("Add Enrollee using ER and PBC") | |
1346 | dev[0].dump_monitor() | |
6edaee9c JM |
1347 | dev[1].dump_monitor() |
1348 | dev[1].request("WPS_PBC") | |
1349 | ||
8674c022 JM |
1350 | for i in range(0, 2): |
1351 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) | |
1352 | if ev is None: | |
1353 | raise Exception("Enrollee discovery timed out") | |
1354 | if enrollee in ev: | |
1355 | break | |
1356 | if i == 1: | |
1357 | raise Exception("Expected Enrollee not found") | |
d6b916c9 JM |
1358 | if "FAIL-NO-AP-SETTINGS" not in dev[0].request("WPS_ER_PBC " + enrollee): |
1359 | raise Exception("Unknown UUID not reported") | |
1360 | logger.info("Use learned network configuration on ER") | |
1361 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0") | |
1362 | if "OK" not in dev[0].request("WPS_ER_PBC " + enrollee): | |
1363 | raise Exception("WPS_ER_PBC failed") | |
6edaee9c JM |
1364 | |
1365 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15) | |
1366 | if ev is None: | |
1367 | raise Exception("Enrollee did not report success") | |
5f35a5e2 | 1368 | dev[1].wait_connected(timeout=15) |
6edaee9c JM |
1369 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1370 | if ev is None: | |
1371 | raise Exception("WPS ER did not report success") | |
1372 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
bff3ac5b | 1373 | |
d6b916c9 JM |
1374 | def test_ap_wps_er_pbc_overlap(dev, apdev): |
1375 | """WPS ER connected to AP and PBC session overlap""" | |
be9f1562 JM |
1376 | try: |
1377 | _test_ap_wps_er_pbc_overlap(dev, apdev) | |
1378 | finally: | |
1379 | dev[0].request("WPS_ER_STOP") | |
1380 | ||
1381 | def _test_ap_wps_er_pbc_overlap(dev, apdev): | |
d6b916c9 JM |
1382 | ssid = "wps-er-add-enrollee-pbc" |
1383 | ap_pin = "12345670" | |
1384 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1385 | hostapd.add_ap(apdev[0], |
d6b916c9 JM |
1386 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1387 | "wpa_passphrase": "12345678", "wpa": "2", | |
1388 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1389 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1390 | "model_name": "WAP", "model_number": "123", | |
1391 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1392 | "os_version": "01020300", | |
1393 | "config_methods": "label push_button", | |
1394 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1395 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1396 | dev[0].dump_monitor() | |
1397 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1398 | ||
fba25c99 JM |
1399 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
1400 | dev[2].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
1401 | # avoid leaving dev 1 or 2 as the last Probe Request to the AP | |
1402 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True) | |
1403 | ||
d6b916c9 JM |
1404 | dev[0].dump_monitor() |
1405 | dev[0].request("WPS_ER_START ifname=lo") | |
1406 | ||
1407 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1408 | if ev is None: | |
1409 | raise Exception("AP discovery timed out") | |
1410 | if ap_uuid not in ev: | |
1411 | raise Exception("Expected AP UUID not found") | |
1412 | ||
800bcf4e JM |
1413 | # verify BSSID selection of the AP instead of UUID |
1414 | if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"): | |
1415 | raise Exception("Could not select AP based on BSSID") | |
1416 | ||
fba25c99 | 1417 | dev[0].dump_monitor() |
d6b916c9 JM |
1418 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) |
1419 | dev[2].request("WPS_PBC " + apdev[0]['bssid']) | |
1420 | ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
1421 | if ev is None: | |
1422 | raise Exception("PBC scan failed") | |
1423 | ev = dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
1424 | if ev is None: | |
1425 | raise Exception("PBC scan failed") | |
fba25c99 JM |
1426 | found1 = False |
1427 | found2 = False | |
1428 | addr1 = dev[1].own_addr() | |
1429 | addr2 = dev[2].own_addr() | |
1430 | for i in range(3): | |
d6b916c9 JM |
1431 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) |
1432 | if ev is None: | |
1433 | raise Exception("Enrollee discovery timed out") | |
fba25c99 JM |
1434 | if addr1 in ev: |
1435 | found1 = True | |
1436 | if found2: | |
1437 | break | |
1438 | if addr2 in ev: | |
1439 | found2 = True | |
1440 | if found1: | |
1441 | break | |
d6b916c9 JM |
1442 | if dev[0].request("WPS_ER_PBC " + ap_uuid) != "FAIL-PBC-OVERLAP\n": |
1443 | raise Exception("PBC overlap not reported") | |
1444 | dev[1].request("WPS_CANCEL") | |
1445 | dev[2].request("WPS_CANCEL") | |
1446 | if dev[0].request("WPS_ER_PBC foo") != "FAIL\n": | |
1447 | raise Exception("Invalid WPS_ER_PBC accepted") | |
1448 | ||
1f020f5e JM |
1449 | def test_ap_wps_er_v10_add_enrollee_pin(dev, apdev): |
1450 | """WPS v1.0 ER connected to AP and adding a new enrollee using PIN""" | |
be9f1562 JM |
1451 | try: |
1452 | _test_ap_wps_er_v10_add_enrollee_pin(dev, apdev) | |
1453 | finally: | |
1454 | dev[0].request("WPS_ER_STOP") | |
1455 | ||
1456 | def _test_ap_wps_er_v10_add_enrollee_pin(dev, apdev): | |
1f020f5e JM |
1457 | ssid = "wps-er-add-enrollee-pbc" |
1458 | ap_pin = "12345670" | |
1459 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1460 | hostapd.add_ap(apdev[0], |
1f020f5e JM |
1461 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1462 | "wpa_passphrase": "12345678", "wpa": "2", | |
1463 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1464 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1465 | "model_name": "WAP", "model_number": "123", | |
1466 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1467 | "os_version": "01020300", | |
1468 | "config_methods": "label push_button", | |
1469 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1470 | logger.info("Learn AP configuration") | |
1471 | dev[0].request("SET wps_version_number 0x10") | |
33d0b157 | 1472 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1f020f5e JM |
1473 | dev[0].dump_monitor() |
1474 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1475 | status = dev[0].get_status() | |
1476 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1477 | raise Exception("Not fully connected") | |
1478 | ||
1479 | logger.info("Start ER") | |
1480 | dev[0].request("WPS_ER_START ifname=lo") | |
1481 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1482 | if ev is None: | |
1483 | raise Exception("AP discovery timed out") | |
1484 | if ap_uuid not in ev: | |
1485 | raise Exception("Expected AP UUID not found") | |
1486 | ||
1487 | logger.info("Use learned network configuration on ER") | |
1488 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0") | |
1489 | ||
1490 | logger.info("Add Enrollee using ER and PIN") | |
1491 | enrollee = dev[1].p2p_interface_addr() | |
1492 | pin = dev[1].wps_read_pin() | |
1493 | dev[0].dump_monitor() | |
1494 | dev[0].request("WPS_ER_PIN any " + pin + " " + enrollee) | |
33d0b157 | 1495 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1f020f5e | 1496 | dev[1].dump_monitor() |
33d0b157 | 1497 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 1498 | dev[1].wait_connected(timeout=30) |
1f020f5e JM |
1499 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1500 | if ev is None: | |
1501 | raise Exception("WPS ER did not report success") | |
1502 | ||
9fd6804d | 1503 | @remote_compatible |
be923570 JM |
1504 | def test_ap_wps_er_config_ap(dev, apdev): |
1505 | """WPS ER configuring AP over UPnP""" | |
be9f1562 JM |
1506 | try: |
1507 | _test_ap_wps_er_config_ap(dev, apdev) | |
1508 | finally: | |
1509 | dev[0].request("WPS_ER_STOP") | |
1510 | ||
1511 | def _test_ap_wps_er_config_ap(dev, apdev): | |
be923570 JM |
1512 | ssid = "wps-er-ap-config" |
1513 | ap_pin = "12345670" | |
1514 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1515 | hostapd.add_ap(apdev[0], |
be923570 JM |
1516 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1517 | "wpa_passphrase": "12345678", "wpa": "2", | |
1518 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1519 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1520 | "model_name": "WAP", "model_number": "123", | |
1521 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1522 | "os_version": "01020300", | |
1523 | "config_methods": "label push_button", | |
1524 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1525 | ||
1526 | logger.info("Connect ER to the AP") | |
1527 | dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
1528 | ||
1529 | logger.info("WPS configuration step") | |
1530 | dev[0].request("WPS_ER_START ifname=lo") | |
1531 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1532 | if ev is None: | |
1533 | raise Exception("AP discovery timed out") | |
1534 | if ap_uuid not in ev: | |
1535 | raise Exception("Expected AP UUID not found") | |
1536 | new_passphrase = "1234567890" | |
1537 | dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " + | |
1538 | ssid.encode("hex") + " WPA2PSK CCMP " + | |
1539 | new_passphrase.encode("hex")) | |
1540 | ev = dev[0].wait_event(["WPS-SUCCESS"]) | |
1541 | if ev is None: | |
1542 | raise Exception("WPS ER configuration operation timed out") | |
5f35a5e2 | 1543 | dev[0].wait_disconnected(timeout=10) |
be923570 JM |
1544 | dev[0].connect(ssid, psk="1234567890", scan_freq="2412") |
1545 | ||
8f8c2fe8 JM |
1546 | logger.info("WPS ER restart") |
1547 | dev[0].request("WPS_ER_START") | |
1548 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1549 | if ev is None: | |
1550 | raise Exception("AP discovery timed out on ER restart") | |
1551 | if ap_uuid not in ev: | |
1552 | raise Exception("Expected AP UUID not found on ER restart") | |
1553 | if "OK" not in dev[0].request("WPS_ER_STOP"): | |
1554 | raise Exception("WPS_ER_STOP failed") | |
1555 | if "OK" not in dev[0].request("WPS_ER_STOP"): | |
1556 | raise Exception("WPS_ER_STOP failed") | |
1557 | ||
9fd6804d | 1558 | @remote_compatible |
6aaa661a JM |
1559 | def test_ap_wps_er_cache_ap_settings(dev, apdev): |
1560 | """WPS ER caching AP settings""" | |
1561 | try: | |
1562 | _test_ap_wps_er_cache_ap_settings(dev, apdev) | |
1563 | finally: | |
1564 | dev[0].request("WPS_ER_STOP") | |
1565 | ||
1566 | def _test_ap_wps_er_cache_ap_settings(dev, apdev): | |
1567 | ssid = "wps-er-add-enrollee" | |
1568 | ap_pin = "12345670" | |
1569 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1570 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1571 | "wpa_passphrase": "12345678", "wpa": "2", | |
1572 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1573 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1574 | "model_name": "WAP", "model_number": "123", | |
1575 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1576 | "os_version": "01020300", | |
1577 | "config_methods": "label push_button", | |
1578 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1579 | hapd = hostapd.add_ap(apdev[0], params) |
6aaa661a JM |
1580 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1581 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1582 | id = int(dev[0].list_networks()[0]['id']) | |
1583 | dev[0].set_network(id, "scan_freq", "2412") | |
1584 | ||
1585 | dev[0].request("WPS_ER_START ifname=lo") | |
1586 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1587 | if ev is None: | |
1588 | raise Exception("AP discovery timed out") | |
1589 | if ap_uuid not in ev: | |
1590 | raise Exception("Expected AP UUID not found") | |
1591 | ||
1592 | dev[0].dump_monitor() | |
1593 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1594 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1595 | if ev is None: | |
1596 | raise Exception("AP learn timed out") | |
1597 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1598 | if ev is None: | |
1599 | raise Exception("WPS-FAIL after AP learn timed out") | |
1600 | time.sleep(0.1) | |
1601 | ||
1602 | hapd.disable() | |
1603 | ||
1604 | for i in range(2): | |
1605 | ev = dev[0].wait_event([ "WPS-ER-AP-REMOVE", | |
1606 | "CTRL-EVENT-DISCONNECTED" ], | |
1607 | timeout=15) | |
1608 | if ev is None: | |
1609 | raise Exception("AP removal or disconnection timed out") | |
1610 | ||
8b8a1864 | 1611 | hapd = hostapd.add_ap(apdev[0], params) |
6aaa661a JM |
1612 | for i in range(2): |
1613 | ev = dev[0].wait_event([ "WPS-ER-AP-ADD", "CTRL-EVENT-CONNECTED" ], | |
1614 | timeout=15) | |
1615 | if ev is None: | |
1616 | raise Exception("AP discovery or connection timed out") | |
1617 | ||
1618 | pin = dev[1].wps_read_pin() | |
1619 | dev[0].dump_monitor() | |
1620 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
1621 | ||
1622 | time.sleep(0.2) | |
1623 | ||
1624 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1625 | dev[1].dump_monitor() | |
1626 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
1627 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) | |
1628 | if ev is None: | |
1629 | raise Exception("Enrollee did not report success") | |
1630 | dev[1].wait_connected(timeout=15) | |
1631 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
1632 | if ev is None: | |
1633 | raise Exception("WPS ER did not report success") | |
1634 | ||
1635 | dev[0].dump_monitor() | |
1636 | dev[0].request("WPS_ER_STOP") | |
1637 | ||
d840350a JM |
1638 | def test_ap_wps_er_cache_ap_settings_oom(dev, apdev): |
1639 | """WPS ER caching AP settings (OOM)""" | |
1640 | try: | |
1641 | _test_ap_wps_er_cache_ap_settings_oom(dev, apdev) | |
1642 | finally: | |
1643 | dev[0].request("WPS_ER_STOP") | |
1644 | ||
1645 | def _test_ap_wps_er_cache_ap_settings_oom(dev, apdev): | |
1646 | ssid = "wps-er-add-enrollee" | |
1647 | ap_pin = "12345670" | |
1648 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1649 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1650 | "wpa_passphrase": "12345678", "wpa": "2", | |
1651 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1652 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1653 | "model_name": "WAP", "model_number": "123", | |
1654 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1655 | "os_version": "01020300", | |
1656 | "config_methods": "label push_button", | |
1657 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1658 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1659 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1660 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1661 | id = int(dev[0].list_networks()[0]['id']) | |
1662 | dev[0].set_network(id, "scan_freq", "2412") | |
1663 | ||
1664 | dev[0].request("WPS_ER_START ifname=lo") | |
1665 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1666 | if ev is None: | |
1667 | raise Exception("AP discovery timed out") | |
1668 | if ap_uuid not in ev: | |
1669 | raise Exception("Expected AP UUID not found") | |
1670 | ||
1671 | dev[0].dump_monitor() | |
1672 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1673 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1674 | if ev is None: | |
1675 | raise Exception("AP learn timed out") | |
1676 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1677 | if ev is None: | |
1678 | raise Exception("WPS-FAIL after AP learn timed out") | |
1679 | time.sleep(0.1) | |
1680 | ||
1681 | with alloc_fail(dev[0], 1, "=wps_er_ap_use_cached_settings"): | |
1682 | hapd.disable() | |
1683 | ||
1684 | for i in range(2): | |
1685 | ev = dev[0].wait_event([ "WPS-ER-AP-REMOVE", | |
1686 | "CTRL-EVENT-DISCONNECTED" ], | |
1687 | timeout=15) | |
1688 | if ev is None: | |
1689 | raise Exception("AP removal or disconnection timed out") | |
1690 | ||
8b8a1864 | 1691 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1692 | for i in range(2): |
1693 | ev = dev[0].wait_event([ "WPS-ER-AP-ADD", "CTRL-EVENT-CONNECTED" ], | |
1694 | timeout=15) | |
1695 | if ev is None: | |
1696 | raise Exception("AP discovery or connection timed out") | |
1697 | ||
1698 | dev[0].request("WPS_ER_STOP") | |
1699 | ||
1700 | def test_ap_wps_er_cache_ap_settings_oom2(dev, apdev): | |
1701 | """WPS ER caching AP settings (OOM 2)""" | |
1702 | try: | |
1703 | _test_ap_wps_er_cache_ap_settings_oom2(dev, apdev) | |
1704 | finally: | |
1705 | dev[0].request("WPS_ER_STOP") | |
1706 | ||
1707 | def _test_ap_wps_er_cache_ap_settings_oom2(dev, apdev): | |
1708 | ssid = "wps-er-add-enrollee" | |
1709 | ap_pin = "12345670" | |
1710 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1711 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1712 | "wpa_passphrase": "12345678", "wpa": "2", | |
1713 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1714 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1715 | "model_name": "WAP", "model_number": "123", | |
1716 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1717 | "os_version": "01020300", | |
1718 | "config_methods": "label push_button", | |
1719 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1720 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1721 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1722 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1723 | id = int(dev[0].list_networks()[0]['id']) | |
1724 | dev[0].set_network(id, "scan_freq", "2412") | |
1725 | ||
1726 | dev[0].request("WPS_ER_START ifname=lo") | |
1727 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1728 | if ev is None: | |
1729 | raise Exception("AP discovery timed out") | |
1730 | if ap_uuid not in ev: | |
1731 | raise Exception("Expected AP UUID not found") | |
1732 | ||
1733 | dev[0].dump_monitor() | |
1734 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1735 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1736 | if ev is None: | |
1737 | raise Exception("AP learn timed out") | |
1738 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1739 | if ev is None: | |
1740 | raise Exception("WPS-FAIL after AP learn timed out") | |
1741 | time.sleep(0.1) | |
1742 | ||
1743 | with alloc_fail(dev[0], 1, "=wps_er_ap_cache_settings"): | |
1744 | hapd.disable() | |
1745 | ||
1746 | for i in range(2): | |
1747 | ev = dev[0].wait_event([ "WPS-ER-AP-REMOVE", | |
1748 | "CTRL-EVENT-DISCONNECTED" ], | |
1749 | timeout=15) | |
1750 | if ev is None: | |
1751 | raise Exception("AP removal or disconnection timed out") | |
1752 | ||
8b8a1864 | 1753 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1754 | for i in range(2): |
1755 | ev = dev[0].wait_event([ "WPS-ER-AP-ADD", "CTRL-EVENT-CONNECTED" ], | |
1756 | timeout=15) | |
1757 | if ev is None: | |
1758 | raise Exception("AP discovery or connection timed out") | |
1759 | ||
1760 | dev[0].request("WPS_ER_STOP") | |
1761 | ||
eb95ced2 JM |
1762 | def test_ap_wps_er_subscribe_oom(dev, apdev): |
1763 | """WPS ER subscribe OOM""" | |
1764 | try: | |
1765 | _test_ap_wps_er_subscribe_oom(dev, apdev) | |
1766 | finally: | |
1767 | dev[0].request("WPS_ER_STOP") | |
1768 | ||
1769 | def _test_ap_wps_er_subscribe_oom(dev, apdev): | |
1770 | ssid = "wps-er-add-enrollee" | |
1771 | ap_pin = "12345670" | |
1772 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1773 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1774 | "wpa_passphrase": "12345678", "wpa": "2", | |
1775 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1776 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1777 | "model_name": "WAP", "model_number": "123", | |
1778 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1779 | "os_version": "01020300", | |
1780 | "config_methods": "label push_button", | |
1781 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1782 | hapd = hostapd.add_ap(apdev[0], params) |
eb95ced2 JM |
1783 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1784 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1785 | id = int(dev[0].list_networks()[0]['id']) | |
1786 | dev[0].set_network(id, "scan_freq", "2412") | |
1787 | ||
1788 | with alloc_fail(dev[0], 1, "http_client_addr;wps_er_subscribe"): | |
1789 | dev[0].request("WPS_ER_START ifname=lo") | |
1790 | for i in range(50): | |
1791 | res = dev[0].request("GET_ALLOC_FAIL") | |
1792 | if res.startswith("0:"): | |
1793 | break | |
1794 | time.sleep(0.1) | |
1795 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=0) | |
1796 | if ev: | |
1797 | raise Exception("Unexpected AP discovery during OOM") | |
1798 | ||
1799 | dev[0].request("WPS_ER_STOP") | |
1800 | ||
db9c88eb JM |
1801 | def test_ap_wps_er_set_sel_reg_oom(dev, apdev): |
1802 | """WPS ER SetSelectedRegistrar OOM""" | |
1803 | try: | |
1804 | _test_ap_wps_er_set_sel_reg_oom(dev, apdev) | |
1805 | finally: | |
1806 | dev[0].request("WPS_ER_STOP") | |
1807 | ||
1808 | def _test_ap_wps_er_set_sel_reg_oom(dev, apdev): | |
1809 | ssid = "wps-er-add-enrollee" | |
1810 | ap_pin = "12345670" | |
1811 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1812 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1813 | "wpa_passphrase": "12345678", "wpa": "2", | |
1814 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1815 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1816 | "model_name": "WAP", "model_number": "123", | |
1817 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1818 | "os_version": "01020300", | |
1819 | "config_methods": "label push_button", | |
1820 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1821 | hapd = hostapd.add_ap(apdev[0], params) |
db9c88eb JM |
1822 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1823 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1824 | ||
1825 | dev[0].request("WPS_ER_START ifname=lo") | |
1826 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
1827 | if ev is None: | |
1828 | raise Exception("AP not discovered") | |
1829 | ||
1830 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1831 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1832 | if ev is None: | |
1833 | raise Exception("AP learn timed out") | |
1834 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1835 | if ev is None: | |
1836 | raise Exception("WPS-FAIL timed out") | |
1837 | time.sleep(0.1) | |
1838 | ||
1839 | for func in [ "http_client_url_parse;wps_er_send_set_sel_reg", | |
1840 | "wps_er_soap_hdr;wps_er_send_set_sel_reg", | |
1841 | "http_client_addr;wps_er_send_set_sel_reg", | |
1842 | "wpabuf_alloc;wps_er_set_sel_reg" ]: | |
1843 | with alloc_fail(dev[0], 1, func): | |
1844 | if "OK" not in dev[0].request("WPS_ER_PBC " + ap_uuid): | |
1845 | raise Exception("WPS_ER_PBC failed") | |
1846 | ev = dev[0].wait_event(["WPS-PBC-ACTIVE"], timeout=3) | |
1847 | if ev is None: | |
1848 | raise Exception("WPS-PBC-ACTIVE not seen") | |
1849 | ||
1850 | dev[0].request("WPS_ER_STOP") | |
1851 | ||
9fd6804d | 1852 | @remote_compatible |
ae3eacf7 JM |
1853 | def test_ap_wps_er_learn_oom(dev, apdev): |
1854 | """WPS ER learn OOM""" | |
1855 | try: | |
1856 | _test_ap_wps_er_learn_oom(dev, apdev) | |
1857 | finally: | |
1858 | dev[0].request("WPS_ER_STOP") | |
1859 | ||
1860 | def _test_ap_wps_er_learn_oom(dev, apdev): | |
1861 | ssid = "wps-er-add-enrollee" | |
1862 | ap_pin = "12345670" | |
1863 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1864 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1865 | "wpa_passphrase": "12345678", "wpa": "2", | |
1866 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1867 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1868 | "model_name": "WAP", "model_number": "123", | |
1869 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1870 | "os_version": "01020300", | |
1871 | "config_methods": "label push_button", | |
1872 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1873 | hapd = hostapd.add_ap(apdev[0], params) |
ae3eacf7 JM |
1874 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1875 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1876 | ||
1877 | dev[0].request("WPS_ER_START ifname=lo") | |
1878 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
1879 | if ev is None: | |
1880 | raise Exception("AP not discovered") | |
1881 | ||
1882 | for func in [ "wps_er_http_put_message_cb", | |
1883 | "xml_get_base64_item;wps_er_http_put_message_cb", | |
1884 | "http_client_url_parse;wps_er_ap_put_message", | |
1885 | "wps_er_soap_hdr;wps_er_ap_put_message", | |
1886 | "http_client_addr;wps_er_ap_put_message" ]: | |
1887 | with alloc_fail(dev[0], 1, func): | |
1888 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1889 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=1) | |
1890 | if ev is not None: | |
1891 | raise Exception("AP learn succeeded during OOM") | |
1892 | ||
1893 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1894 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=10) | |
1895 | if ev is None: | |
1896 | raise Exception("AP learn did not succeed") | |
1897 | ||
1898 | if "FAIL" not in dev[0].request("WPS_ER_LEARN 00000000-9e5c-4e73-bd82-f89cbcd10d7e " + ap_pin): | |
1899 | raise Exception("WPS_ER_LEARN for unknown AP accepted") | |
1900 | ||
1901 | dev[0].request("WPS_ER_STOP") | |
1902 | ||
bff3ac5b JM |
1903 | def test_ap_wps_fragmentation(dev, apdev): |
1904 | """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2""" | |
1905 | ssid = "test-wps-fragmentation" | |
9602b355 | 1906 | appin = "12345670" |
6f334bf7 JD |
1907 | hapd = hostapd.add_ap(apdev[0], |
1908 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1909 | "wpa_passphrase": "12345678", "wpa": "3", | |
1910 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1911 | "wpa_pairwise": "TKIP", "ap_pin": appin, | |
1912 | "fragment_size": "50" }) | |
9602b355 | 1913 | logger.info("WPS provisioning step (PBC)") |
bff3ac5b | 1914 | hapd.request("WPS_PBC") |
33d0b157 | 1915 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
bff3ac5b JM |
1916 | dev[0].dump_monitor() |
1917 | dev[0].request("SET wps_fragment_size 50") | |
33d0b157 | 1918 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1919 | dev[0].wait_connected(timeout=30) |
bff3ac5b JM |
1920 | status = dev[0].get_status() |
1921 | if status['wpa_state'] != 'COMPLETED': | |
9602b355 JM |
1922 | raise Exception("Not fully connected") |
1923 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1924 | raise Exception("Unexpected encryption configuration") | |
1925 | if status['key_mgmt'] != 'WPA2-PSK': | |
1926 | raise Exception("Unexpected key_mgmt") | |
1927 | ||
1928 | logger.info("WPS provisioning step (PIN)") | |
1929 | pin = dev[1].wps_read_pin() | |
1930 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 1931 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9602b355 | 1932 | dev[1].request("SET wps_fragment_size 50") |
33d0b157 | 1933 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 1934 | dev[1].wait_connected(timeout=30) |
9602b355 JM |
1935 | status = dev[1].get_status() |
1936 | if status['wpa_state'] != 'COMPLETED': | |
1937 | raise Exception("Not fully connected") | |
1938 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1939 | raise Exception("Unexpected encryption configuration") | |
1940 | if status['key_mgmt'] != 'WPA2-PSK': | |
1941 | raise Exception("Unexpected key_mgmt") | |
1942 | ||
1943 | logger.info("WPS connection as registrar") | |
33d0b157 | 1944 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9602b355 JM |
1945 | dev[2].request("SET wps_fragment_size 50") |
1946 | dev[2].wps_reg(apdev[0]['bssid'], appin) | |
1947 | status = dev[2].get_status() | |
1948 | if status['wpa_state'] != 'COMPLETED': | |
bff3ac5b JM |
1949 | raise Exception("Not fully connected") |
1950 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1951 | raise Exception("Unexpected encryption configuration") | |
1952 | if status['key_mgmt'] != 'WPA2-PSK': | |
1953 | raise Exception("Unexpected key_mgmt") | |
10ea6848 | 1954 | |
9fd6804d | 1955 | @remote_compatible |
10ea6848 JM |
1956 | def test_ap_wps_new_version_sta(dev, apdev): |
1957 | """WPS compatibility with new version number on the station""" | |
1958 | ssid = "test-wps-ver" | |
6f334bf7 JD |
1959 | hapd = hostapd.add_ap(apdev[0], |
1960 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1961 | "wpa_passphrase": "12345678", "wpa": "2", | |
1962 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
10ea6848 JM |
1963 | logger.info("WPS provisioning step") |
1964 | hapd.request("WPS_PBC") | |
33d0b157 | 1965 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
10ea6848 JM |
1966 | dev[0].dump_monitor() |
1967 | dev[0].request("SET wps_version_number 0x43") | |
dccafedb | 1968 | dev[0].request("SET wps_vendor_ext_m1 000137100100020001") |
33d0b157 | 1969 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1970 | dev[0].wait_connected(timeout=30) |
10ea6848 | 1971 | |
9fd6804d | 1972 | @remote_compatible |
10ea6848 JM |
1973 | def test_ap_wps_new_version_ap(dev, apdev): |
1974 | """WPS compatibility with new version number on the AP""" | |
1975 | ssid = "test-wps-ver" | |
6f334bf7 JD |
1976 | hapd = hostapd.add_ap(apdev[0], |
1977 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1978 | "wpa_passphrase": "12345678", "wpa": "2", | |
1979 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
10ea6848 JM |
1980 | logger.info("WPS provisioning step") |
1981 | if "FAIL" in hapd.request("SET wps_version_number 0x43"): | |
1982 | raise Exception("Failed to enable test functionality") | |
1983 | hapd.request("WPS_PBC") | |
33d0b157 | 1984 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
10ea6848 | 1985 | dev[0].dump_monitor() |
33d0b157 | 1986 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1987 | dev[0].wait_connected(timeout=30) |
10ea6848 | 1988 | hapd.request("SET wps_version_number 0x20") |
3bdf7d7f | 1989 | |
9fd6804d | 1990 | @remote_compatible |
3bdf7d7f JM |
1991 | def test_ap_wps_check_pin(dev, apdev): |
1992 | """Verify PIN checking through control interface""" | |
6f334bf7 JD |
1993 | hapd = hostapd.add_ap(apdev[0], |
1994 | { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
1995 | "wpa_passphrase": "12345678", "wpa": "2", | |
1996 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
3bdf7d7f JM |
1997 | for t in [ ("12345670", "12345670"), |
1998 | ("12345678", "FAIL-CHECKSUM"), | |
df58939c | 1999 | ("12345", "FAIL"), |
6e12eaa4 | 2000 | ("123456789", "FAIL"), |
3bdf7d7f JM |
2001 | ("1234-5670", "12345670"), |
2002 | ("1234 5670", "12345670"), | |
2003 | ("1-2.3:4 5670", "12345670") ]: | |
2004 | res = hapd.request("WPS_CHECK_PIN " + t[0]).rstrip('\n') | |
2005 | res2 = dev[0].request("WPS_CHECK_PIN " + t[0]).rstrip('\n') | |
2006 | if res != res2: | |
2007 | raise Exception("Unexpected difference in WPS_CHECK_PIN responses") | |
2008 | if res != t[1]: | |
2009 | raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res, t[1])) | |
9ba1fcb0 | 2010 | |
ac786d67 JM |
2011 | if "FAIL" not in hapd.request("WPS_CHECK_PIN 12345"): |
2012 | raise Exception("Unexpected WPS_CHECK_PIN success") | |
2013 | if "FAIL" not in hapd.request("WPS_CHECK_PIN 123456789"): | |
2014 | raise Exception("Unexpected WPS_CHECK_PIN success") | |
2015 | ||
acd9b45a JM |
2016 | for i in range(0, 10): |
2017 | pin = dev[0].request("WPS_PIN get") | |
2018 | rpin = dev[0].request("WPS_CHECK_PIN " + pin).rstrip('\n') | |
2019 | if pin != rpin: | |
2020 | raise Exception("Random PIN validation failed for " + pin) | |
2021 | ||
9ba1fcb0 JM |
2022 | def test_ap_wps_wep_config(dev, apdev): |
2023 | """WPS 2.0 AP rejecting WEP configuration""" | |
2024 | ssid = "test-wps-config" | |
2025 | appin = "12345670" | |
6f334bf7 JD |
2026 | hapd = hostapd.add_ap(apdev[0], |
2027 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2028 | "ap_pin": appin}) | |
33d0b157 | 2029 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9ba1fcb0 JM |
2030 | dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-new-ssid-wep", "OPEN", "WEP", |
2031 | "hello", no_wait=True) | |
2032 | ev = hapd.wait_event(["WPS-FAIL"], timeout=15) | |
2033 | if ev is None: | |
2034 | raise Exception("WPS-FAIL timed out") | |
2035 | if "reason=2" not in ev: | |
2036 | raise Exception("Unexpected reason code in WPS-FAIL") | |
2037 | status = hapd.request("WPS_GET_STATUS") | |
2038 | if "Last WPS result: Failed" not in status: | |
2039 | raise Exception("WPS failure result not shown correctly") | |
2040 | if "Failure Reason: WEP Prohibited" not in status: | |
2041 | raise Exception("Failure reason not reported correctly") | |
2042 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
2043 | raise Exception("Peer address not shown correctly") | |
1013a576 | 2044 | |
11d78bb1 JM |
2045 | def test_ap_wps_wep_enroll(dev, apdev): |
2046 | """WPS 2.0 STA rejecting WEP configuration""" | |
2047 | ssid = "test-wps-wep" | |
6f334bf7 JD |
2048 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
2049 | "skip_cred_build": "1", "extra_cred": "wps-wep-cred" } | |
2050 | hapd = hostapd.add_ap(apdev[0], params) | |
11d78bb1 | 2051 | hapd.request("WPS_PBC") |
33d0b157 JM |
2052 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2053 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
11d78bb1 JM |
2054 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) |
2055 | if ev is None: | |
2056 | raise Exception("WPS-FAIL event timed out") | |
2057 | if "msg=12" not in ev or "reason=2 (WEP Prohibited)" not in ev: | |
2058 | raise Exception("Unexpected WPS-FAIL event: " + ev) | |
2059 | ||
9fd6804d | 2060 | @remote_compatible |
1013a576 JM |
2061 | def test_ap_wps_ie_fragmentation(dev, apdev): |
2062 | """WPS AP using fragmented WPS IE""" | |
2063 | ssid = "test-wps-ie-fragmentation" | |
2064 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2065 | "wpa_passphrase": "12345678", "wpa": "2", | |
2066 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
2067 | "device_name": "1234567890abcdef1234567890abcdef", | |
2068 | "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | |
2069 | "model_name": "1234567890abcdef1234567890abcdef", | |
2070 | "model_number": "1234567890abcdef1234567890abcdef", | |
2071 | "serial_number": "1234567890abcdef1234567890abcdef" } | |
6f334bf7 | 2072 | hapd = hostapd.add_ap(apdev[0], params) |
1013a576 | 2073 | hapd.request("WPS_PBC") |
33d0b157 JM |
2074 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2075 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2076 | dev[0].wait_connected(timeout=30) |
1013a576 JM |
2077 | bss = dev[0].get_bss(apdev[0]['bssid']) |
2078 | if "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef": | |
cf3f0ec8 | 2079 | logger.info("Device Name not received correctly") |
d7a68ad6 | 2080 | logger.info(bss) |
cf3f0ec8 JM |
2081 | # This can fail if Probe Response frame is missed and Beacon frame was |
2082 | # used to fill in the BSS entry. This can happen, e.g., during heavy | |
2083 | # load every now and then and is not really an error, so try to | |
2084 | # workaround by runnign another scan. | |
2085 | dev[0].scan(freq="2412", only_new=True) | |
2086 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
84a40841 | 2087 | if not bss or "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef": |
cf3f0ec8 JM |
2088 | logger.info(bss) |
2089 | raise Exception("Device Name not received correctly") | |
1013a576 JM |
2090 | if len(re.findall("dd..0050f204", bss['ie'])) != 2: |
2091 | raise Exception("Unexpected number of WPS IEs") | |
44ff0400 | 2092 | |
2035b170 JM |
2093 | def get_psk(pskfile): |
2094 | psks = {} | |
2095 | with open(pskfile, "r") as f: | |
2096 | lines = f.read().splitlines() | |
2097 | for l in lines: | |
2098 | if l == "# WPA PSKs": | |
2099 | continue | |
2100 | (addr,psk) = l.split(' ') | |
2101 | psks[addr] = psk | |
2102 | return psks | |
2103 | ||
2104 | def test_ap_wps_per_station_psk(dev, apdev): | |
2105 | """WPS PBC provisioning with per-station PSK""" | |
1d21a5be B |
2106 | addr0 = dev[0].own_addr() |
2107 | addr1 = dev[1].own_addr() | |
2108 | addr2 = dev[2].own_addr() | |
2035b170 JM |
2109 | ssid = "wps" |
2110 | appin = "12345670" | |
2111 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
2112 | try: | |
2113 | os.remove(pskfile) | |
2114 | except: | |
2115 | pass | |
2116 | ||
4f524e99 | 2117 | hapd = None |
2035b170 JM |
2118 | try: |
2119 | with open(pskfile, "w") as f: | |
2120 | f.write("# WPA PSKs\n") | |
2121 | ||
2122 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2123 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
2124 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
2125 | "wpa_psk_file": pskfile } | |
8b8a1864 | 2126 | hapd = hostapd.add_ap(apdev[0], params) |
2035b170 JM |
2127 | |
2128 | logger.info("First enrollee") | |
2129 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2130 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2131 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2132 | dev[0].wait_connected(timeout=30) |
2035b170 JM |
2133 | |
2134 | logger.info("Second enrollee") | |
2135 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2136 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2137 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2138 | dev[1].wait_connected(timeout=30) |
2035b170 JM |
2139 | |
2140 | logger.info("External registrar") | |
33d0b157 | 2141 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2035b170 JM |
2142 | dev[2].wps_reg(apdev[0]['bssid'], appin) |
2143 | ||
2144 | logger.info("Verifying PSK results") | |
2145 | psks = get_psk(pskfile) | |
2146 | if addr0 not in psks: | |
2147 | raise Exception("No PSK recorded for sta0") | |
2148 | if addr1 not in psks: | |
2149 | raise Exception("No PSK recorded for sta1") | |
2150 | if addr2 not in psks: | |
2151 | raise Exception("No PSK recorded for sta2") | |
2152 | if psks[addr0] == psks[addr1]: | |
2153 | raise Exception("Same PSK recorded for sta0 and sta1") | |
2154 | if psks[addr0] == psks[addr2]: | |
2155 | raise Exception("Same PSK recorded for sta0 and sta2") | |
2156 | if psks[addr1] == psks[addr2]: | |
2157 | raise Exception("Same PSK recorded for sta1 and sta2") | |
2158 | ||
2159 | dev[0].request("REMOVE_NETWORK all") | |
2160 | logger.info("Second external registrar") | |
33d0b157 | 2161 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2035b170 JM |
2162 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
2163 | psks2 = get_psk(pskfile) | |
2164 | if addr0 not in psks2: | |
2165 | raise Exception("No PSK recorded for sta0(reg)") | |
2166 | if psks[addr0] == psks2[addr0]: | |
2167 | raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)") | |
2168 | finally: | |
2169 | os.remove(pskfile) | |
4f524e99 JM |
2170 | if hapd: |
2171 | dev[0].request("DISCONNECT") | |
2172 | dev[1].request("DISCONNECT") | |
2173 | dev[2].request("DISCONNECT") | |
2174 | hapd.disable() | |
2175 | dev[0].flush_scan_cache() | |
2176 | dev[1].flush_scan_cache() | |
2177 | dev[2].flush_scan_cache() | |
2035b170 | 2178 | |
373cce55 JM |
2179 | def test_ap_wps_per_station_psk_failure(dev, apdev): |
2180 | """WPS PBC provisioning with per-station PSK (file not writable)""" | |
2181 | addr0 = dev[0].p2p_dev_addr() | |
2182 | addr1 = dev[1].p2p_dev_addr() | |
2183 | addr2 = dev[2].p2p_dev_addr() | |
2184 | ssid = "wps" | |
2185 | appin = "12345670" | |
2186 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
2187 | try: | |
2188 | os.remove(pskfile) | |
2189 | except: | |
2190 | pass | |
2191 | ||
3615bde6 | 2192 | hapd = None |
373cce55 JM |
2193 | try: |
2194 | with open(pskfile, "w") as f: | |
2195 | f.write("# WPA PSKs\n") | |
2196 | ||
2197 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2198 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
2199 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
2200 | "wpa_psk_file": pskfile } | |
8b8a1864 | 2201 | hapd = hostapd.add_ap(apdev[0], params) |
373cce55 JM |
2202 | if "FAIL" in hapd.request("SET wpa_psk_file /tmp/does/not/exists/ap_wps_per_enrollee_psk_failure.psk_file"): |
2203 | raise Exception("Failed to set wpa_psk_file") | |
2204 | ||
2205 | logger.info("First enrollee") | |
2206 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2207 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2208 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2209 | dev[0].wait_connected(timeout=30) |
373cce55 JM |
2210 | |
2211 | logger.info("Second enrollee") | |
2212 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2213 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2214 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2215 | dev[1].wait_connected(timeout=30) |
373cce55 JM |
2216 | |
2217 | logger.info("External registrar") | |
33d0b157 | 2218 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
373cce55 JM |
2219 | dev[2].wps_reg(apdev[0]['bssid'], appin) |
2220 | ||
2221 | logger.info("Verifying PSK results") | |
2222 | psks = get_psk(pskfile) | |
2223 | if len(psks) > 0: | |
2224 | raise Exception("PSK recorded unexpectedly") | |
2225 | finally: | |
3615bde6 JM |
2226 | if hapd: |
2227 | for i in range(3): | |
2228 | dev[i].request("DISCONNECT") | |
2229 | hapd.disable() | |
2230 | for i in range(3): | |
2231 | dev[i].flush_scan_cache() | |
373cce55 JM |
2232 | os.remove(pskfile) |
2233 | ||
e8518757 JM |
2234 | def test_ap_wps_pin_request_file(dev, apdev): |
2235 | """WPS PIN provisioning with configured AP""" | |
2236 | ssid = "wps" | |
2237 | pinfile = "/tmp/ap_wps_pin_request_file.log" | |
2238 | if os.path.exists(pinfile): | |
b638f703 | 2239 | os.remove(pinfile) |
6f334bf7 JD |
2240 | hapd = hostapd.add_ap(apdev[0], |
2241 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2242 | "wps_pin_requests": pinfile, | |
2243 | "wpa_passphrase": "12345678", "wpa": "2", | |
2244 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e8518757 JM |
2245 | uuid = dev[0].get_status_field("uuid") |
2246 | pin = dev[0].wps_read_pin() | |
2247 | try: | |
33d0b157 JM |
2248 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2249 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
e8518757 JM |
2250 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=15) |
2251 | if ev is None: | |
2252 | raise Exception("PIN needed event not shown") | |
2253 | if uuid not in ev: | |
2254 | raise Exception("UUID mismatch") | |
2255 | dev[0].request("WPS_CANCEL") | |
2256 | success = False | |
2257 | with open(pinfile, "r") as f: | |
2258 | lines = f.readlines() | |
2259 | for l in lines: | |
2260 | if uuid in l: | |
2261 | success = True | |
2262 | break | |
2263 | if not success: | |
2264 | raise Exception("PIN request entry not in the log file") | |
2265 | finally: | |
b638f703 JM |
2266 | try: |
2267 | os.remove(pinfile) | |
2268 | except: | |
2269 | pass | |
e8518757 | 2270 | |
56887c35 JM |
2271 | def test_ap_wps_auto_setup_with_config_file(dev, apdev): |
2272 | """WPS auto-setup with configuration file""" | |
2273 | conffile = "/tmp/ap_wps_auto_setup_with_config_file.conf" | |
2274 | ifname = apdev[0]['ifname'] | |
2275 | try: | |
2276 | with open(conffile, "w") as f: | |
2277 | f.write("driver=nl80211\n") | |
2278 | f.write("hw_mode=g\n") | |
2279 | f.write("channel=1\n") | |
2280 | f.write("ieee80211n=1\n") | |
2281 | f.write("interface=%s\n" % ifname) | |
2282 | f.write("ctrl_interface=/var/run/hostapd\n") | |
2283 | f.write("ssid=wps\n") | |
2284 | f.write("eap_server=1\n") | |
2285 | f.write("wps_state=1\n") | |
5148b392 | 2286 | hapd = hostapd.add_bss(apdev[0], ifname, conffile) |
56887c35 | 2287 | hapd.request("WPS_PBC") |
33d0b157 JM |
2288 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2289 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2290 | dev[0].wait_connected(timeout=30) |
56887c35 JM |
2291 | with open(conffile, "r") as f: |
2292 | lines = f.read().splitlines() | |
2293 | vals = dict() | |
2294 | for l in lines: | |
2295 | try: | |
2296 | [name,value] = l.split('=', 1) | |
2297 | vals[name] = value | |
2298 | except ValueError, e: | |
2299 | if "# WPS configuration" in l: | |
2300 | pass | |
2301 | else: | |
2302 | raise Exception("Unexpected configuration line: " + l) | |
2303 | if vals['ieee80211n'] != '1' or vals['wps_state'] != '2' or "WPA-PSK" not in vals['wpa_key_mgmt']: | |
2304 | raise Exception("Incorrect configuration: " + str(vals)) | |
2305 | finally: | |
b638f703 JM |
2306 | try: |
2307 | os.remove(conffile) | |
2308 | except: | |
2309 | pass | |
56887c35 | 2310 | |
91f3cf69 | 2311 | def test_ap_wps_pbc_timeout(dev, apdev, params): |
31e56b95 | 2312 | """wpa_supplicant PBC walk time and WPS ER SelReg timeout [long]""" |
91f3cf69 | 2313 | if not params['long']: |
81e787b7 | 2314 | raise HwsimSkip("Skip test case with long duration due to --long not specified") |
31e56b95 | 2315 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" |
21aa8b7e | 2316 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
31e56b95 JM |
2317 | |
2318 | location = ssdp_get_location(ap_uuid) | |
2319 | urls = upnp_get_urls(location) | |
2320 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
2321 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
2322 | ||
2323 | url = urlparse.urlparse(location) | |
2324 | conn = httplib.HTTPConnection(url.netloc) | |
2325 | ||
2326 | class WPSERHTTPServer(SocketServer.StreamRequestHandler): | |
2327 | def handle(self): | |
2328 | data = self.rfile.readline().strip() | |
2329 | logger.debug(data) | |
2330 | self.wfile.write(gen_wps_event()) | |
2331 | ||
2332 | server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) | |
2333 | server.timeout = 1 | |
2334 | ||
2335 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2336 | "NT": "upnp:event", | |
2337 | "timeout": "Second-1234" } | |
2338 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2339 | resp = conn.getresponse() | |
2340 | if resp.status != 200: | |
2341 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
2342 | sid = resp.getheader("sid") | |
2343 | logger.debug("Subscription SID " + sid) | |
2344 | ||
2345 | msg = '''<?xml version="1.0"?> | |
2346 | <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> | |
2347 | <s:Body> | |
2348 | <u:SetSelectedRegistrar xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1"> | |
2349 | <NewMessage>EEoAARAQQQABARASAAIAABBTAAIxSBBJAA4ANyoAASABBv///////xBIABA2LbR7pTpRkYj7 | |
2350 | VFi5hrLk | |
2351 | </NewMessage> | |
2352 | </u:SetSelectedRegistrar> | |
2353 | </s:Body> | |
2354 | </s:Envelope>''' | |
2355 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
2356 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % "SetSelectedRegistrar" | |
2357 | conn.request("POST", ctrlurl.path, msg, headers) | |
2358 | resp = conn.getresponse() | |
2359 | if resp.status != 200: | |
2360 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
2361 | ||
2362 | server.handle_request() | |
2363 | ||
91f3cf69 JM |
2364 | logger.info("Start WPS_PBC and wait for PBC walk time expiration") |
2365 | if "OK" not in dev[0].request("WPS_PBC"): | |
2366 | raise Exception("WPS_PBC failed") | |
31e56b95 JM |
2367 | |
2368 | start = os.times()[4] | |
2369 | ||
2370 | server.handle_request() | |
2371 | dev[1].request("BSS_FLUSH 0") | |
2372 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True, | |
2373 | only_new=True) | |
2374 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
2375 | logger.debug("BSS: " + str(bss)) | |
2376 | if '[WPS-AUTH]' not in bss['flags']: | |
2377 | raise Exception("WPS not indicated authorized") | |
2378 | ||
2379 | server.handle_request() | |
2380 | ||
2381 | wps_timeout_seen = False | |
2382 | ||
2383 | while True: | |
2384 | hapd.dump_monitor() | |
2385 | dev[1].dump_monitor() | |
2386 | if not wps_timeout_seen: | |
2387 | ev = dev[0].wait_event(["WPS-TIMEOUT"], timeout=0) | |
2388 | if ev is not None: | |
2389 | logger.info("PBC timeout seen") | |
2390 | wps_timeout_seen = True | |
2391 | else: | |
2392 | dev[0].dump_monitor() | |
2393 | now = os.times()[4] | |
2394 | if now - start > 130: | |
2395 | raise Exception("Selected registration information not removed") | |
2396 | dev[1].request("BSS_FLUSH 0") | |
2397 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True, | |
2398 | only_new=True) | |
2399 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
2400 | logger.debug("BSS: " + str(bss)) | |
2401 | if '[WPS-AUTH]' not in bss['flags']: | |
2402 | break | |
2403 | server.handle_request() | |
2404 | ||
2405 | server.server_close() | |
2406 | ||
2407 | if wps_timeout_seen: | |
2408 | return | |
2409 | ||
2410 | now = os.times()[4] | |
2411 | if now < start + 150: | |
2412 | dur = start + 150 - now | |
2413 | else: | |
2414 | dur = 1 | |
2415 | logger.info("Continue waiting for PBC timeout (%d sec)" % dur) | |
2416 | ev = dev[0].wait_event(["WPS-TIMEOUT"], timeout=dur) | |
91f3cf69 JM |
2417 | if ev is None: |
2418 | raise Exception("WPS-TIMEOUT not reported") | |
2419 | ||
21aa8b7e | 2420 | def add_ssdp_ap(ap, ap_uuid): |
44ff0400 JM |
2421 | ssid = "wps-ssdp" |
2422 | ap_pin = "12345670" | |
24b7f282 JM |
2423 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
2424 | "wpa_passphrase": "12345678", "wpa": "2", | |
2425 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
2426 | "device_name": "Wireless AP", "manufacturer": "Company", | |
2427 | "model_name": "WAP", "model_number": "123", | |
2428 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
2429 | "os_version": "01020300", | |
2430 | "config_methods": "label push_button", | |
2431 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo", | |
2432 | "friendly_name": "WPS Access Point", | |
2433 | "manufacturer_url": "http://www.example.com/", | |
2434 | "model_description": "Wireless Access Point", | |
2435 | "model_url": "http://www.example.com/model/", | |
2436 | "upc": "123456789012" } | |
21aa8b7e | 2437 | return hostapd.add_ap(ap, params) |
44ff0400 JM |
2438 | |
2439 | def ssdp_send(msg, no_recv=False): | |
2440 | socket.setdefaulttimeout(1) | |
2441 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2442 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2443 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2444 | sock.bind(("127.0.0.1", 0)) | |
2445 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2446 | if no_recv: | |
2447 | return None | |
2448 | return sock.recv(1000) | |
2449 | ||
96038a5f | 2450 | def ssdp_send_msearch(st, no_recv=False): |
44ff0400 JM |
2451 | msg = '\r\n'.join([ |
2452 | 'M-SEARCH * HTTP/1.1', | |
2453 | 'HOST: 239.255.255.250:1900', | |
2454 | 'MX: 1', | |
2455 | 'MAN: "ssdp:discover"', | |
2456 | 'ST: ' + st, | |
2457 | '', '']) | |
96038a5f | 2458 | return ssdp_send(msg, no_recv=no_recv) |
44ff0400 JM |
2459 | |
2460 | def test_ap_wps_ssdp_msearch(dev, apdev): | |
2461 | """WPS AP and SSDP M-SEARCH messages""" | |
2462 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2463 | add_ssdp_ap(apdev[0], ap_uuid) |
44ff0400 JM |
2464 | |
2465 | msg = '\r\n'.join([ | |
2466 | 'M-SEARCH * HTTP/1.1', | |
2467 | 'Host: 239.255.255.250:1900', | |
2468 | 'Mx: 1', | |
2469 | 'Man: "ssdp:discover"', | |
2470 | 'St: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2471 | '', '']) | |
2472 | ssdp_send(msg) | |
2473 | ||
2474 | msg = '\r\n'.join([ | |
2475 | 'M-SEARCH * HTTP/1.1', | |
2476 | 'host:\t239.255.255.250:1900\t\t\t\t \t\t', | |
2477 | 'mx: \t1\t\t ', | |
2478 | 'man: \t \t "ssdp:discover" ', | |
2479 | 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t', | |
2480 | '', '']) | |
2481 | ssdp_send(msg) | |
2482 | ||
2483 | ssdp_send_msearch("ssdp:all") | |
2484 | ssdp_send_msearch("upnp:rootdevice") | |
2485 | ssdp_send_msearch("uuid:" + ap_uuid) | |
2486 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1") | |
bc6e3288 | 2487 | ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1") |
44ff0400 JM |
2488 | |
2489 | msg = '\r\n'.join([ | |
2490 | 'M-SEARCH * HTTP/1.1', | |
2491 | 'HOST:\t239.255.255.250:1900', | |
2492 | 'MAN: "ssdp:discover"', | |
2493 | 'MX: 130', | |
2494 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2495 | '', '']) | |
2496 | ssdp_send(msg, no_recv=True) | |
2497 | ||
2498 | def test_ap_wps_ssdp_invalid_msearch(dev, apdev): | |
2499 | """WPS AP and invalid SSDP M-SEARCH messages""" | |
2500 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2501 | add_ssdp_ap(apdev[0], ap_uuid) |
44ff0400 JM |
2502 | |
2503 | socket.setdefaulttimeout(1) | |
2504 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2505 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2506 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2507 | sock.bind(("127.0.0.1", 0)) | |
2508 | ||
2509 | logger.debug("Missing MX") | |
2510 | msg = '\r\n'.join([ | |
2511 | 'M-SEARCH * HTTP/1.1', | |
2512 | 'HOST: 239.255.255.250:1900', | |
2513 | 'MAN: "ssdp:discover"', | |
2514 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2515 | '', '']) | |
2516 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2517 | ||
2518 | logger.debug("Negative MX") | |
2519 | msg = '\r\n'.join([ | |
2520 | 'M-SEARCH * HTTP/1.1', | |
2521 | 'HOST: 239.255.255.250:1900', | |
2522 | 'MX: -1', | |
2523 | 'MAN: "ssdp:discover"', | |
2524 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2525 | '', '']) | |
2526 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2527 | ||
2528 | logger.debug("Invalid MX") | |
2529 | msg = '\r\n'.join([ | |
2530 | 'M-SEARCH * HTTP/1.1', | |
2531 | 'HOST: 239.255.255.250:1900', | |
2532 | 'MX; 1', | |
2533 | 'MAN: "ssdp:discover"', | |
2534 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2535 | '', '']) | |
2536 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2537 | ||
2538 | logger.debug("Missing MAN") | |
2539 | msg = '\r\n'.join([ | |
2540 | 'M-SEARCH * HTTP/1.1', | |
2541 | 'HOST: 239.255.255.250:1900', | |
2542 | 'MX: 1', | |
2543 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2544 | '', '']) | |
2545 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2546 | ||
2547 | logger.debug("Invalid MAN") | |
2548 | msg = '\r\n'.join([ | |
2549 | 'M-SEARCH * HTTP/1.1', | |
2550 | 'HOST: 239.255.255.250:1900', | |
2551 | 'MX: 1', | |
2552 | 'MAN: foo', | |
2553 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2554 | '', '']) | |
2555 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2556 | msg = '\r\n'.join([ | |
2557 | 'M-SEARCH * HTTP/1.1', | |
2558 | 'HOST: 239.255.255.250:1900', | |
2559 | 'MX: 1', | |
2560 | 'MAN; "ssdp:discover"', | |
2561 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2562 | '', '']) | |
2563 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2564 | ||
2565 | logger.debug("Missing HOST") | |
2566 | msg = '\r\n'.join([ | |
2567 | 'M-SEARCH * HTTP/1.1', | |
2568 | 'MAN: "ssdp:discover"', | |
2569 | 'MX: 1', | |
2570 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2571 | '', '']) | |
2572 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2573 | ||
2574 | logger.debug("Missing ST") | |
2575 | msg = '\r\n'.join([ | |
2576 | 'M-SEARCH * HTTP/1.1', | |
2577 | 'HOST: 239.255.255.250:1900', | |
2578 | 'MAN: "ssdp:discover"', | |
2579 | 'MX: 1', | |
2580 | '', '']) | |
2581 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2582 | ||
2583 | logger.debug("Mismatching ST") | |
2584 | msg = '\r\n'.join([ | |
2585 | 'M-SEARCH * HTTP/1.1', | |
2586 | 'HOST: 239.255.255.250:1900', | |
2587 | 'MAN: "ssdp:discover"', | |
2588 | 'MX: 1', | |
2589 | 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d', | |
2590 | '', '']) | |
2591 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2592 | msg = '\r\n'.join([ | |
2593 | 'M-SEARCH * HTTP/1.1', | |
2594 | 'HOST: 239.255.255.250:1900', | |
2595 | 'MAN: "ssdp:discover"', | |
2596 | 'MX: 1', | |
2597 | 'ST: foo:bar', | |
2598 | '', '']) | |
2599 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2600 | msg = '\r\n'.join([ | |
2601 | 'M-SEARCH * HTTP/1.1', | |
2602 | 'HOST: 239.255.255.250:1900', | |
2603 | 'MAN: "ssdp:discover"', | |
2604 | 'MX: 1', | |
2605 | 'ST: foobar', | |
2606 | '', '']) | |
2607 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2608 | ||
2609 | logger.debug("Invalid ST") | |
2610 | msg = '\r\n'.join([ | |
2611 | 'M-SEARCH * HTTP/1.1', | |
2612 | 'HOST: 239.255.255.250:1900', | |
2613 | 'MAN: "ssdp:discover"', | |
2614 | 'MX: 1', | |
2615 | 'ST; urn:schemas-wifialliance-org:device:WFADevice:1', | |
2616 | '', '']) | |
2617 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2618 | ||
2619 | logger.debug("Invalid M-SEARCH") | |
2620 | msg = '\r\n'.join([ | |
2621 | 'M+SEARCH * HTTP/1.1', | |
2622 | 'HOST: 239.255.255.250:1900', | |
2623 | 'MAN: "ssdp:discover"', | |
2624 | 'MX: 1', | |
2625 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2626 | '', '']) | |
2627 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2628 | msg = '\r\n'.join([ | |
2629 | 'M-SEARCH-* HTTP/1.1', | |
2630 | 'HOST: 239.255.255.250:1900', | |
2631 | 'MAN: "ssdp:discover"', | |
2632 | 'MX: 1', | |
2633 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2634 | '', '']) | |
2635 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2636 | ||
2637 | logger.debug("Invalid message format") | |
2638 | sock.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900)) | |
2639 | msg = '\r'.join([ | |
2640 | 'M-SEARCH * HTTP/1.1', | |
2641 | 'HOST: 239.255.255.250:1900', | |
2642 | 'MAN: "ssdp:discover"', | |
2643 | 'MX: 1', | |
2644 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2645 | '', '']) | |
2646 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2647 | ||
2648 | try: | |
2649 | r = sock.recv(1000) | |
2650 | raise Exception("Unexpected M-SEARCH response: " + r) | |
2651 | except socket.timeout: | |
2652 | pass | |
2653 | ||
2654 | logger.debug("Valid M-SEARCH") | |
2655 | msg = '\r\n'.join([ | |
2656 | 'M-SEARCH * HTTP/1.1', | |
2657 | 'HOST: 239.255.255.250:1900', | |
2658 | 'MAN: "ssdp:discover"', | |
2659 | 'MX: 1', | |
2660 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2661 | '', '']) | |
2662 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2663 | ||
2664 | try: | |
2665 | r = sock.recv(1000) | |
2666 | pass | |
2667 | except socket.timeout: | |
2668 | raise Exception("No SSDP response") | |
2669 | ||
2670 | def test_ap_wps_ssdp_burst(dev, apdev): | |
2671 | """WPS AP and SSDP burst""" | |
2672 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2673 | add_ssdp_ap(apdev[0], ap_uuid) |
44ff0400 JM |
2674 | |
2675 | msg = '\r\n'.join([ | |
2676 | 'M-SEARCH * HTTP/1.1', | |
2677 | 'HOST: 239.255.255.250:1900', | |
2678 | 'MAN: "ssdp:discover"', | |
2679 | 'MX: 1', | |
2680 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2681 | '', '']) | |
2682 | socket.setdefaulttimeout(1) | |
2683 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2684 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2685 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2686 | sock.bind(("127.0.0.1", 0)) | |
2687 | for i in range(0, 25): | |
2688 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2689 | resp = 0 | |
2690 | while True: | |
2691 | try: | |
2692 | r = sock.recv(1000) | |
2693 | if not r.startswith("HTTP/1.1 200 OK\r\n"): | |
2694 | raise Exception("Unexpected message: " + r) | |
2695 | resp += 1 | |
2696 | except socket.timeout: | |
2697 | break | |
2698 | if resp < 20: | |
2699 | raise Exception("Too few SSDP responses") | |
2700 | ||
2701 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2702 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2703 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2704 | sock.bind(("127.0.0.1", 0)) | |
2705 | for i in range(0, 25): | |
2706 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2707 | while True: | |
2708 | try: | |
2709 | r = sock.recv(1000) | |
2710 | if ap_uuid in r: | |
2711 | break | |
2712 | except socket.timeout: | |
2713 | raise Exception("No SSDP response") | |
47c549fd JM |
2714 | |
2715 | def ssdp_get_location(uuid): | |
2716 | res = ssdp_send_msearch("uuid:" + uuid) | |
2717 | location = None | |
2718 | for l in res.splitlines(): | |
2719 | if l.lower().startswith("location:"): | |
2720 | location = l.split(':', 1)[1].strip() | |
2721 | break | |
2722 | if location is None: | |
2723 | raise Exception("No UPnP location found") | |
2724 | return location | |
2725 | ||
2726 | def upnp_get_urls(location): | |
aa713e71 | 2727 | conn = urllib.urlopen(location, proxies={}) |
47c549fd JM |
2728 | tree = ET.parse(conn) |
2729 | root = tree.getroot() | |
2730 | urn = '{urn:schemas-upnp-org:device-1-0}' | |
2731 | service = root.find("./" + urn + "device/" + urn + "serviceList/" + urn + "service") | |
2732 | res = {} | |
2733 | res['scpd_url'] = urlparse.urljoin(location, service.find(urn + 'SCPDURL').text) | |
2734 | res['control_url'] = urlparse.urljoin(location, service.find(urn + 'controlURL').text) | |
2735 | res['event_sub_url'] = urlparse.urljoin(location, service.find(urn + 'eventSubURL').text) | |
2736 | return res | |
2737 | ||
dd124ee8 JM |
2738 | def upnp_soap_action(conn, path, action, include_soap_action=True, |
2739 | soap_action_override=None, newmsg=None, neweventtype=None, | |
2740 | neweventmac=None): | |
47c549fd JM |
2741 | soapns = 'http://schemas.xmlsoap.org/soap/envelope/' |
2742 | wpsns = 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1' | |
2743 | ET.register_namespace('soapenv', soapns) | |
2744 | ET.register_namespace('wfa', wpsns) | |
2745 | attrib = {} | |
2746 | attrib['{%s}encodingStyle' % soapns] = 'http://schemas.xmlsoap.org/soap/encoding/' | |
2747 | root = ET.Element("{%s}Envelope" % soapns, attrib=attrib) | |
2748 | body = ET.SubElement(root, "{%s}Body" % soapns) | |
2749 | act = ET.SubElement(body, "{%s}%s" % (wpsns, action)) | |
dd124ee8 JM |
2750 | if newmsg: |
2751 | msg = ET.SubElement(act, "NewMessage") | |
2752 | msg.text = base64.b64encode(newmsg) | |
2753 | if neweventtype: | |
2754 | msg = ET.SubElement(act, "NewWLANEventType") | |
2755 | msg.text = neweventtype | |
2756 | if neweventmac: | |
2757 | msg = ET.SubElement(act, "NewWLANEventMAC") | |
2758 | msg.text = neweventmac | |
47c549fd JM |
2759 | tree = ET.ElementTree(root) |
2760 | soap = StringIO.StringIO() | |
2761 | tree.write(soap, xml_declaration=True, encoding='utf-8') | |
2762 | ||
2763 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
2764 | if include_soap_action: | |
2765 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action | |
2766 | elif soap_action_override: | |
2767 | headers["SOAPAction"] = soap_action_override | |
2768 | conn.request("POST", path, soap.getvalue(), headers) | |
2769 | return conn.getresponse() | |
2770 | ||
2771 | def test_ap_wps_upnp(dev, apdev): | |
2772 | """WPS AP and UPnP operations""" | |
2773 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2774 | add_ssdp_ap(apdev[0], ap_uuid) |
47c549fd JM |
2775 | |
2776 | location = ssdp_get_location(ap_uuid) | |
2777 | urls = upnp_get_urls(location) | |
2778 | ||
aa713e71 | 2779 | conn = urllib.urlopen(urls['scpd_url'], proxies={}) |
47c549fd JM |
2780 | scpd = conn.read() |
2781 | ||
aa713e71 AO |
2782 | conn = urllib.urlopen(urlparse.urljoin(location, "unknown.html"), |
2783 | proxies={}) | |
47c549fd JM |
2784 | if conn.getcode() != 404: |
2785 | raise Exception("Unexpected HTTP response to GET unknown URL") | |
2786 | ||
2787 | url = urlparse.urlparse(location) | |
2788 | conn = httplib.HTTPConnection(url.netloc) | |
2789 | #conn.set_debuglevel(1) | |
2790 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
2791 | "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' } | |
2792 | conn.request("POST", "hello", "\r\n\r\n", headers) | |
2793 | resp = conn.getresponse() | |
2794 | if resp.status != 404: | |
5c267d71 | 2795 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2796 | |
2797 | conn.request("UNKNOWN", "hello", "\r\n\r\n", headers) | |
2798 | resp = conn.getresponse() | |
2799 | if resp.status != 501: | |
5c267d71 | 2800 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2801 | |
2802 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
2803 | "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' } | |
2804 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
2805 | conn.request("POST", ctrlurl.path, "\r\n\r\n", headers) | |
2806 | resp = conn.getresponse() | |
2807 | if resp.status != 401: | |
5c267d71 | 2808 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2809 | |
2810 | logger.debug("GetDeviceInfo without SOAPAction header") | |
2811 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo", | |
2812 | include_soap_action=False) | |
2813 | if resp.status != 401: | |
5c267d71 | 2814 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2815 | |
2816 | logger.debug("GetDeviceInfo with invalid SOAPAction header") | |
2817 | for act in [ "foo", | |
2818 | "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo", | |
2819 | '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"', | |
2820 | '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']: | |
2821 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo", | |
2822 | include_soap_action=False, | |
2823 | soap_action_override=act) | |
2824 | if resp.status != 401: | |
5c267d71 | 2825 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2826 | |
2827 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
2828 | if resp.status != 200: | |
5c267d71 | 2829 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2830 | dev = resp.read() |
2831 | if "NewDeviceInfo" not in dev: | |
2832 | raise Exception("Unexpected GetDeviceInfo response") | |
2833 | ||
2834 | logger.debug("PutMessage without required parameters") | |
2835 | resp = upnp_soap_action(conn, ctrlurl.path, "PutMessage") | |
2836 | if resp.status != 600: | |
5c267d71 | 2837 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2838 | |
2839 | logger.debug("PutWLANResponse without required parameters") | |
2840 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse") | |
2841 | if resp.status != 600: | |
5c267d71 | 2842 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2843 | |
2844 | logger.debug("SetSelectedRegistrar from unregistered ER") | |
2845 | resp = upnp_soap_action(conn, ctrlurl.path, "SetSelectedRegistrar") | |
2846 | if resp.status != 501: | |
5c267d71 | 2847 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2848 | |
2849 | logger.debug("Unknown action") | |
2850 | resp = upnp_soap_action(conn, ctrlurl.path, "Unknown") | |
2851 | if resp.status != 401: | |
5c267d71 | 2852 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2853 | |
2854 | def test_ap_wps_upnp_subscribe(dev, apdev): | |
2855 | """WPS AP and UPnP event subscription""" | |
2856 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2857 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
47c549fd JM |
2858 | |
2859 | location = ssdp_get_location(ap_uuid) | |
2860 | urls = upnp_get_urls(location) | |
2861 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
2862 | ||
2863 | url = urlparse.urlparse(location) | |
2864 | conn = httplib.HTTPConnection(url.netloc) | |
2865 | #conn.set_debuglevel(1) | |
2866 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2867 | "timeout": "Second-1234" } | |
2868 | conn.request("SUBSCRIBE", "hello", "\r\n\r\n", headers) | |
2869 | resp = conn.getresponse() | |
2870 | if resp.status != 412: | |
5c267d71 | 2871 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2872 | |
2873 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2874 | resp = conn.getresponse() | |
2875 | if resp.status != 412: | |
5c267d71 | 2876 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2877 | |
2878 | headers = { "NT": "upnp:event", | |
2879 | "timeout": "Second-1234" } | |
2880 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2881 | resp = conn.getresponse() | |
2882 | if resp.status != 412: | |
5c267d71 | 2883 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2884 | |
2885 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2886 | "NT": "upnp:foobar", | |
2887 | "timeout": "Second-1234" } | |
2888 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2889 | resp = conn.getresponse() | |
2890 | if resp.status != 400: | |
5c267d71 | 2891 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2892 | |
2893 | logger.debug("Valid subscription") | |
2894 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2895 | "NT": "upnp:event", | |
2896 | "timeout": "Second-1234" } | |
2897 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2898 | resp = conn.getresponse() | |
2899 | if resp.status != 200: | |
5c267d71 | 2900 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2901 | sid = resp.getheader("sid") |
2902 | logger.debug("Subscription SID " + sid) | |
2903 | ||
2904 | logger.debug("Invalid re-subscription") | |
2905 | headers = { "NT": "upnp:event", | |
2906 | "sid": "123456734567854", | |
2907 | "timeout": "Second-1234" } | |
2908 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2909 | resp = conn.getresponse() | |
2910 | if resp.status != 400: | |
5c267d71 | 2911 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2912 | |
2913 | logger.debug("Invalid re-subscription") | |
2914 | headers = { "NT": "upnp:event", | |
2915 | "sid": "uuid:123456734567854", | |
2916 | "timeout": "Second-1234" } | |
2917 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2918 | resp = conn.getresponse() | |
2919 | if resp.status != 400: | |
5c267d71 | 2920 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2921 | |
2922 | logger.debug("Invalid re-subscription") | |
2923 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2924 | "NT": "upnp:event", | |
2925 | "sid": sid, | |
2926 | "timeout": "Second-1234" } | |
2927 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2928 | resp = conn.getresponse() | |
2929 | if resp.status != 400: | |
5c267d71 | 2930 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2931 | |
2932 | logger.debug("SID mismatch in re-subscription") | |
2933 | headers = { "NT": "upnp:event", | |
2934 | "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb", | |
2935 | "timeout": "Second-1234" } | |
2936 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2937 | resp = conn.getresponse() | |
2938 | if resp.status != 412: | |
5c267d71 | 2939 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2940 | |
2941 | logger.debug("Valid re-subscription") | |
2942 | headers = { "NT": "upnp:event", | |
2943 | "sid": sid, | |
2944 | "timeout": "Second-1234" } | |
2945 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2946 | resp = conn.getresponse() | |
2947 | if resp.status != 200: | |
5c267d71 | 2948 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2949 | sid2 = resp.getheader("sid") |
2950 | logger.debug("Subscription SID " + sid2) | |
2951 | ||
2952 | if sid != sid2: | |
2953 | raise Exception("Unexpected SID change") | |
2954 | ||
2955 | logger.debug("Valid re-subscription") | |
2956 | headers = { "NT": "upnp:event", | |
2957 | "sid": "uuid: \t \t" + sid.split(':')[1], | |
2958 | "timeout": "Second-1234" } | |
2959 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2960 | resp = conn.getresponse() | |
2961 | if resp.status != 200: | |
5c267d71 | 2962 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2963 | |
2964 | logger.debug("Invalid unsubscription") | |
2965 | headers = { "sid": sid } | |
2966 | conn.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers) | |
2967 | resp = conn.getresponse() | |
2968 | if resp.status != 412: | |
5c267d71 | 2969 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2970 | headers = { "foo": "bar" } |
2971 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2972 | resp = conn.getresponse() | |
2973 | if resp.status != 412: | |
5c267d71 | 2974 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2975 | |
2976 | logger.debug("Valid unsubscription") | |
2977 | headers = { "sid": sid } | |
2978 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2979 | resp = conn.getresponse() | |
2980 | if resp.status != 200: | |
5c267d71 | 2981 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2982 | |
2983 | logger.debug("Unsubscription for not existing SID") | |
2984 | headers = { "sid": sid } | |
2985 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2986 | resp = conn.getresponse() | |
2987 | if resp.status != 412: | |
5c267d71 | 2988 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2989 | |
2990 | logger.debug("Invalid unsubscription") | |
2991 | headers = { "sid": " \t \tfoo" } | |
2992 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2993 | resp = conn.getresponse() | |
2994 | if resp.status != 400: | |
5c267d71 | 2995 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2996 | |
2997 | logger.debug("Invalid unsubscription") | |
2998 | headers = { "sid": "uuid:\t \tfoo" } | |
2999 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3000 | resp = conn.getresponse() | |
3001 | if resp.status != 400: | |
5c267d71 | 3002 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3003 | |
3004 | logger.debug("Invalid unsubscription") | |
3005 | headers = { "NT": "upnp:event", | |
3006 | "sid": sid } | |
3007 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3008 | resp = conn.getresponse() | |
3009 | if resp.status != 400: | |
5c267d71 | 3010 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3011 | headers = { "callback": '<http://127.0.0.1:12345/event>', |
3012 | "sid": sid } | |
3013 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3014 | resp = conn.getresponse() | |
3015 | if resp.status != 400: | |
5c267d71 | 3016 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3017 | |
3018 | logger.debug("Valid subscription with multiple callbacks") | |
3019 | headers = { "callback": '<http://127.0.0.1:12345/event> <http://127.0.0.1:12345/event>\t<http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event>', | |
3020 | "NT": "upnp:event", | |
3021 | "timeout": "Second-1234" } | |
3022 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3023 | resp = conn.getresponse() | |
3024 | if resp.status != 200: | |
5c267d71 | 3025 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3026 | sid = resp.getheader("sid") |
3027 | logger.debug("Subscription SID " + sid) | |
d352c407 | 3028 | |
24b7f282 JM |
3029 | # Force subscription to be deleted due to errors |
3030 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3031 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3032 | with alloc_fail(hapd, 1, "event_build_message"): | |
3033 | for i in range(10): | |
3034 | dev[1].dump_monitor() | |
3035 | dev[2].dump_monitor() | |
3036 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3037 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3038 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3039 | dev[1].request("WPS_CANCEL") | |
3040 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3041 | dev[2].request("WPS_CANCEL") | |
3042 | if i % 4 == 1: | |
3043 | time.sleep(1) | |
3044 | else: | |
3045 | time.sleep(0.1) | |
3046 | time.sleep(0.2) | |
3047 | ||
3048 | headers = { "sid": sid } | |
3049 | conn.request("UNSUBSCRIBE", eventurl.path, "", headers) | |
3050 | resp = conn.getresponse() | |
3051 | if resp.status != 200 and resp.status != 412: | |
3052 | raise Exception("Unexpected HTTP response for UNSUBSCRIBE: %d" % resp.status) | |
3053 | ||
3054 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3055 | "NT": "upnp:event", | |
3056 | "timeout": "Second-1234" } | |
3057 | with alloc_fail(hapd, 1, "http_client_addr;event_send_start"): | |
3058 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3059 | resp = conn.getresponse() | |
3060 | if resp.status != 200: | |
3061 | raise Exception("Unexpected HTTP response for SUBSCRIBE: %d" % resp.status) | |
3062 | sid = resp.getheader("sid") | |
3063 | logger.debug("Subscription SID " + sid) | |
3064 | ||
3065 | headers = { "sid": sid } | |
3066 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3067 | resp = conn.getresponse() | |
3068 | if resp.status != 200: | |
3069 | raise Exception("Unexpected HTTP response for UNSUBSCRIBE: %d" % resp.status) | |
3070 | ||
3071 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3072 | "NT": "upnp:event", | |
3073 | "timeout": "Second-1234" } | |
3074 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3075 | resp = conn.getresponse() | |
3076 | if resp.status != 200: | |
3077 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3078 | sid = resp.getheader("sid") | |
3079 | logger.debug("Subscription SID " + sid) | |
3080 | ||
3081 | with alloc_fail(hapd, 1, "=event_add"): | |
3082 | for i in range(2): | |
3083 | dev[1].dump_monitor() | |
3084 | dev[2].dump_monitor() | |
3085 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3086 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3087 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3088 | dev[1].request("WPS_CANCEL") | |
3089 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3090 | dev[2].request("WPS_CANCEL") | |
3091 | if i == 0: | |
3092 | time.sleep(1) | |
3093 | else: | |
3094 | time.sleep(0.1) | |
3095 | ||
3096 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3097 | resp = conn.getresponse() | |
3098 | if resp.status != 200: | |
3099 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3100 | ||
3101 | with alloc_fail(hapd, 1, "wpabuf_dup;event_add"): | |
3102 | dev[1].dump_monitor() | |
3103 | dev[2].dump_monitor() | |
3104 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3105 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3106 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3107 | dev[1].request("WPS_CANCEL") | |
3108 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3109 | dev[2].request("WPS_CANCEL") | |
3110 | time.sleep(0.1) | |
3111 | ||
3112 | with fail_test(hapd, 1, "os_get_random;uuid_make;subscription_start"): | |
3113 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3114 | resp = conn.getresponse() | |
3115 | if resp.status != 500: | |
3116 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3117 | ||
3118 | with alloc_fail(hapd, 1, "=subscription_start"): | |
3119 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3120 | resp = conn.getresponse() | |
3121 | if resp.status != 500: | |
3122 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3123 | ||
3124 | headers = { "callback": '', | |
3125 | "NT": "upnp:event", | |
3126 | "timeout": "Second-1234" } | |
3127 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3128 | resp = conn.getresponse() | |
3129 | if resp.status != 500: | |
3130 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3131 | ||
3132 | headers = { "callback": ' <', | |
3133 | "NT": "upnp:event", | |
3134 | "timeout": "Second-1234" } | |
3135 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3136 | resp = conn.getresponse() | |
3137 | if resp.status != 500: | |
3138 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3139 | ||
3140 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3141 | "NT": "upnp:event", | |
3142 | "timeout": "Second-1234" } | |
3143 | with alloc_fail(hapd, 1, "wpabuf_alloc;subscription_first_event"): | |
3144 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3145 | resp = conn.getresponse() | |
3146 | if resp.status != 500: | |
3147 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3148 | ||
3149 | with alloc_fail(hapd, 1, "event_add;subscription_first_event"): | |
3150 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3151 | resp = conn.getresponse() | |
3152 | if resp.status != 500: | |
3153 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3154 | ||
3155 | with alloc_fail(hapd, 1, "subscr_addr_add_url"): | |
3156 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3157 | resp = conn.getresponse() | |
3158 | if resp.status != 500: | |
3159 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3160 | ||
3161 | with alloc_fail(hapd, 2, "subscr_addr_add_url"): | |
3162 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3163 | resp = conn.getresponse() | |
3164 | if resp.status != 500: | |
3165 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3166 | ||
3167 | for i in range(6): | |
3168 | headers = { "callback": '<http://127.0.0.1:%d/event>' % (12345 + i), | |
3169 | "NT": "upnp:event", | |
3170 | "timeout": "Second-1234" } | |
3171 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3172 | resp = conn.getresponse() | |
3173 | if resp.status != 200: | |
3174 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3175 | ||
3176 | with alloc_fail(hapd, 1, "=upnp_wps_device_send_wlan_event"): | |
3177 | dev[1].dump_monitor() | |
3178 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3179 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3180 | dev[1].request("WPS_CANCEL") | |
3181 | time.sleep(0.1) | |
3182 | ||
3183 | with alloc_fail(hapd, 1, "wpabuf_alloc;upnp_wps_device_send_event"): | |
3184 | dev[1].dump_monitor() | |
3185 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3186 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3187 | dev[1].request("WPS_CANCEL") | |
3188 | time.sleep(0.1) | |
3189 | ||
3190 | with alloc_fail(hapd, 1, "base64_encode;upnp_wps_device_send_wlan_event"): | |
3191 | dev[1].dump_monitor() | |
3192 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3193 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3194 | dev[1].request("WPS_CANCEL") | |
3195 | time.sleep(0.1) | |
3196 | ||
3197 | hapd.disable() | |
3198 | with alloc_fail(hapd, 1, "get_netif_info"): | |
3199 | if "FAIL" not in hapd.request("ENABLE"): | |
3200 | raise Exception("ENABLE succeeded during OOM") | |
3201 | ||
d91a64c4 JM |
3202 | def test_ap_wps_upnp_subscribe_events(dev, apdev): |
3203 | """WPS AP and UPnP event subscription and many events""" | |
3204 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 3205 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
d91a64c4 JM |
3206 | |
3207 | location = ssdp_get_location(ap_uuid) | |
3208 | urls = upnp_get_urls(location) | |
3209 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
3210 | ||
3211 | class WPSERHTTPServer(SocketServer.StreamRequestHandler): | |
3212 | def handle(self): | |
3213 | data = self.rfile.readline().strip() | |
3214 | logger.debug(data) | |
3215 | self.wfile.write(gen_wps_event()) | |
3216 | ||
3217 | server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) | |
3218 | server.timeout = 1 | |
3219 | ||
3220 | url = urlparse.urlparse(location) | |
3221 | conn = httplib.HTTPConnection(url.netloc) | |
3222 | ||
3223 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3224 | "NT": "upnp:event", | |
3225 | "timeout": "Second-1234" } | |
3226 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3227 | resp = conn.getresponse() | |
3228 | if resp.status != 200: | |
3229 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3230 | sid = resp.getheader("sid") | |
3231 | logger.debug("Subscription SID " + sid) | |
3232 | ||
3233 | # Fetch the first event message | |
3234 | server.handle_request() | |
3235 | ||
3236 | # Force subscription event queue to reach the maximum length by generating | |
3237 | # new proxied events without the ER fetching any of the pending events. | |
3238 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3239 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3240 | for i in range(16): | |
3241 | dev[1].dump_monitor() | |
3242 | dev[2].dump_monitor() | |
3243 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3244 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3245 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3246 | dev[1].request("WPS_CANCEL") | |
3247 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3248 | dev[2].request("WPS_CANCEL") | |
3249 | if i % 4 == 1: | |
3250 | time.sleep(1) | |
3251 | else: | |
3252 | time.sleep(0.1) | |
3253 | ||
3254 | hapd.request("WPS_PIN any 12345670") | |
3255 | dev[1].dump_monitor() | |
3256 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3257 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=10) | |
3258 | if ev is None: | |
3259 | raise Exception("WPS success not reported") | |
3260 | ||
3261 | # Close the WPS ER HTTP server without fetching all the pending events. | |
3262 | # This tests hostapd code path that clears subscription and the remaining | |
3263 | # event queue when the interface is deinitialized. | |
3264 | server.handle_request() | |
3265 | server.server_close() | |
3266 | ||
3267 | dev[1].wait_connected() | |
3268 | ||
b2047531 JM |
3269 | def test_ap_wps_upnp_http_proto(dev, apdev): |
3270 | """WPS AP and UPnP/HTTP protocol testing""" | |
3271 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 3272 | add_ssdp_ap(apdev[0], ap_uuid) |
b2047531 JM |
3273 | |
3274 | location = ssdp_get_location(ap_uuid) | |
3275 | ||
3276 | url = urlparse.urlparse(location) | |
81f8e7e9 | 3277 | conn = httplib.HTTPConnection(url.netloc, timeout=0.2) |
b2047531 JM |
3278 | #conn.set_debuglevel(1) |
3279 | ||
3280 | conn.request("HEAD", "hello") | |
3281 | resp = conn.getresponse() | |
3282 | if resp.status != 501: | |
3283 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3284 | conn.close() | |
3285 | ||
3286 | for cmd in [ "PUT", "DELETE", "TRACE", "CONNECT", "M-SEARCH", "M-POST" ]: | |
3287 | try: | |
3288 | conn.request(cmd, "hello") | |
3289 | resp = conn.getresponse() | |
3290 | except Exception, e: | |
3291 | pass | |
3292 | conn.close() | |
3293 | ||
3294 | headers = { "Content-Length": 'abc' } | |
3295 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3296 | try: | |
3297 | resp = conn.getresponse() | |
3298 | except Exception, e: | |
3299 | pass | |
3300 | conn.close() | |
3301 | ||
3302 | headers = { "Content-Length": '-10' } | |
3303 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3304 | try: | |
3305 | resp = conn.getresponse() | |
3306 | except Exception, e: | |
3307 | pass | |
3308 | conn.close() | |
3309 | ||
3310 | headers = { "Content-Length": '10000000000000' } | |
3311 | conn.request("HEAD", "hello", "\r\n\r\nhello", headers) | |
3312 | try: | |
3313 | resp = conn.getresponse() | |
3314 | except Exception, e: | |
3315 | pass | |
3316 | conn.close() | |
3317 | ||
3318 | headers = { "Transfer-Encoding": 'abc' } | |
3319 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3320 | resp = conn.getresponse() | |
3321 | if resp.status != 501: | |
3322 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3323 | conn.close() | |
3324 | ||
3325 | headers = { "Transfer-Encoding": 'chunked' } | |
3326 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3327 | resp = conn.getresponse() | |
3328 | if resp.status != 501: | |
3329 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3330 | conn.close() | |
3331 | ||
3332 | # Too long a header | |
3333 | conn.request("HEAD", 5000 * 'A') | |
3334 | try: | |
3335 | resp = conn.getresponse() | |
3336 | except Exception, e: | |
3337 | pass | |
3338 | conn.close() | |
3339 | ||
3340 | # Long URL but within header length limits | |
3341 | conn.request("HEAD", 3000 * 'A') | |
3342 | resp = conn.getresponse() | |
3343 | if resp.status != 501: | |
3344 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3345 | conn.close() | |
3346 | ||
3347 | headers = { "Content-Length": '20' } | |
3348 | conn.request("POST", "hello", 10 * 'A' + "\r\n\r\n", headers) | |
3349 | try: | |
3350 | resp = conn.getresponse() | |
3351 | except Exception, e: | |
3352 | pass | |
3353 | conn.close() | |
3354 | ||
3355 | conn.request("POST", "hello", 5000 * 'A' + "\r\n\r\n") | |
3356 | resp = conn.getresponse() | |
3357 | if resp.status != 404: | |
5c267d71 | 3358 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
b2047531 JM |
3359 | conn.close() |
3360 | ||
3361 | conn.request("POST", "hello", 60000 * 'A' + "\r\n\r\n") | |
3362 | try: | |
3363 | resp = conn.getresponse() | |
3364 | except Exception, e: | |
3365 | pass | |
3366 | conn.close() | |
3367 | ||
3368 | def test_ap_wps_upnp_http_proto_chunked(dev, apdev): | |
3369 | """WPS AP and UPnP/HTTP protocol testing for chunked encoding""" | |
3370 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 3371 | add_ssdp_ap(apdev[0], ap_uuid) |
b2047531 JM |
3372 | |
3373 | location = ssdp_get_location(ap_uuid) | |
3374 | ||
3375 | url = urlparse.urlparse(location) | |
3376 | conn = httplib.HTTPConnection(url.netloc) | |
3377 | #conn.set_debuglevel(1) | |
3378 | ||
3379 | headers = { "Transfer-Encoding": 'chunked' } | |
3380 | conn.request("POST", "hello", | |
3381 | "a\r\nabcdefghij\r\n" + "2\r\nkl\r\n" + "0\r\n\r\n", | |
3382 | headers) | |
3383 | resp = conn.getresponse() | |
3384 | if resp.status != 404: | |
5c267d71 | 3385 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
b2047531 JM |
3386 | conn.close() |
3387 | ||
3388 | conn.putrequest("POST", "hello") | |
3389 | conn.putheader('Transfer-Encoding', 'chunked') | |
3390 | conn.endheaders() | |
3391 | conn.send("a\r\nabcdefghij\r\n") | |
3392 | time.sleep(0.1) | |
3393 | conn.send("2\r\nkl\r\n") | |
3394 | conn.send("0\r\n\r\n") | |
3395 | resp = conn.getresponse() | |
3396 | if resp.status != 404: | |
5c267d71 | 3397 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
b2047531 JM |
3398 | conn.close() |
3399 | ||
3400 | conn.putrequest("POST", "hello") | |
3401 | conn.putheader('Transfer-Encoding', 'chunked') | |
3402 | conn.endheaders() | |
3403 | completed = False | |
3404 | try: | |
3405 | for i in range(20000): | |
3406 | conn.send("1\r\nZ\r\n") | |
3407 | conn.send("0\r\n\r\n") | |
3408 | resp = conn.getresponse() | |
3409 | completed = True | |
3410 | except Exception, e: | |
3411 | pass | |
3412 | conn.close() | |
3413 | if completed: | |
3414 | raise Exception("Too long chunked request did not result in connection reset") | |
3415 | ||
3416 | headers = { "Transfer-Encoding": 'chunked' } | |
3417 | conn.request("POST", "hello", "80000000\r\na", headers) | |
3418 | try: | |
3419 | resp = conn.getresponse() | |
3420 | except Exception, e: | |
3421 | pass | |
3422 | conn.close() | |
3423 | ||
3424 | conn.request("POST", "hello", "10000000\r\na", headers) | |
3425 | try: | |
3426 | resp = conn.getresponse() | |
3427 | except Exception, e: | |
3428 | pass | |
3429 | conn.close() | |
3430 | ||
9fd6804d | 3431 | @remote_compatible |
d352c407 JM |
3432 | def test_ap_wps_disabled(dev, apdev): |
3433 | """WPS operations while WPS is disabled""" | |
3434 | ssid = "test-wps-disabled" | |
6f334bf7 | 3435 | hapd = hostapd.add_ap(apdev[0], { "ssid": ssid }) |
d352c407 JM |
3436 | if "FAIL" not in hapd.request("WPS_PBC"): |
3437 | raise Exception("WPS_PBC succeeded unexpectedly") | |
3438 | if "FAIL" not in hapd.request("WPS_CANCEL"): | |
3439 | raise Exception("WPS_CANCEL succeeded unexpectedly") | |
a0fd2ae6 JM |
3440 | |
3441 | def test_ap_wps_mixed_cred(dev, apdev): | |
3442 | """WPS 2.0 STA merging mixed mode WPA/WPA2 credentials""" | |
3443 | ssid = "test-wps-wep" | |
6f334bf7 JD |
3444 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3445 | "skip_cred_build": "1", "extra_cred": "wps-mixed-cred" } | |
3446 | hapd = hostapd.add_ap(apdev[0], params) | |
a0fd2ae6 | 3447 | hapd.request("WPS_PBC") |
33d0b157 JM |
3448 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
3449 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
9ed53f5e | 3450 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30) |
a0fd2ae6 JM |
3451 | if ev is None: |
3452 | raise Exception("WPS-SUCCESS event timed out") | |
3453 | nets = dev[0].list_networks() | |
3454 | if len(nets) != 1: | |
3455 | raise Exception("Unexpected number of network blocks") | |
3456 | id = nets[0]['id'] | |
3457 | proto = dev[0].get_network(id, "proto") | |
3458 | if proto != "WPA RSN": | |
3459 | raise Exception("Unexpected merged proto field value: " + proto) | |
3460 | pairwise = dev[0].get_network(id, "pairwise") | |
72a8e30b | 3461 | if pairwise != "CCMP TKIP" and pairwise != "CCMP GCMP TKIP": |
a0fd2ae6 | 3462 | raise Exception("Unexpected merged pairwise field value: " + pairwise) |
e5a79e3f | 3463 | |
9fd6804d | 3464 | @remote_compatible |
e5a79e3f JM |
3465 | def test_ap_wps_while_connected(dev, apdev): |
3466 | """WPS PBC provisioning while connected to another AP""" | |
3467 | ssid = "test-wps-conf" | |
6f334bf7 JD |
3468 | hapd = hostapd.add_ap(apdev[0], |
3469 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3470 | "wpa_passphrase": "12345678", "wpa": "2", | |
3471 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e5a79e3f | 3472 | |
8b8a1864 | 3473 | hostapd.add_ap(apdev[1], { "ssid": "open" }) |
e5a79e3f JM |
3474 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") |
3475 | ||
3476 | logger.info("WPS provisioning step") | |
3477 | hapd.request("WPS_PBC") | |
3478 | dev[0].dump_monitor() | |
33d0b157 | 3479 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 3480 | dev[0].wait_connected(timeout=30) |
e5a79e3f JM |
3481 | status = dev[0].get_status() |
3482 | if status['bssid'] != apdev[0]['bssid']: | |
3483 | raise Exception("Unexpected BSSID") | |
3484 | ||
9fd6804d | 3485 | @remote_compatible |
e5a79e3f JM |
3486 | def test_ap_wps_while_connected_no_autoconnect(dev, apdev): |
3487 | """WPS PBC provisioning while connected to another AP and STA_AUTOCONNECT disabled""" | |
3488 | ssid = "test-wps-conf" | |
6f334bf7 JD |
3489 | hapd = hostapd.add_ap(apdev[0], |
3490 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3491 | "wpa_passphrase": "12345678", "wpa": "2", | |
3492 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e5a79e3f | 3493 | |
8b8a1864 | 3494 | hostapd.add_ap(apdev[1], { "ssid": "open" }) |
e5a79e3f JM |
3495 | |
3496 | try: | |
3497 | dev[0].request("STA_AUTOCONNECT 0") | |
3498 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") | |
3499 | ||
3500 | logger.info("WPS provisioning step") | |
3501 | hapd.request("WPS_PBC") | |
3502 | dev[0].dump_monitor() | |
33d0b157 | 3503 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 3504 | dev[0].wait_connected(timeout=30) |
e5a79e3f JM |
3505 | status = dev[0].get_status() |
3506 | if status['bssid'] != apdev[0]['bssid']: | |
3507 | raise Exception("Unexpected BSSID") | |
3508 | finally: | |
3509 | dev[0].request("STA_AUTOCONNECT 1") | |
3f08d1cd | 3510 | |
9fd6804d | 3511 | @remote_compatible |
3f08d1cd JM |
3512 | def test_ap_wps_from_event(dev, apdev): |
3513 | """WPS PBC event on AP to enable PBC""" | |
3514 | ssid = "test-wps-conf" | |
8b8a1864 | 3515 | hapd = hostapd.add_ap(apdev[0], |
3f08d1cd JM |
3516 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3517 | "wpa_passphrase": "12345678", "wpa": "2", | |
3518 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
33d0b157 | 3519 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
3f08d1cd | 3520 | dev[0].dump_monitor() |
33d0b157 JM |
3521 | hapd.dump_monitor() |
3522 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
3f08d1cd JM |
3523 | |
3524 | ev = hapd.wait_event(['WPS-ENROLLEE-SEEN'], timeout=15) | |
3525 | if ev is None: | |
3526 | raise Exception("No WPS-ENROLLEE-SEEN event on AP") | |
3527 | vals = ev.split(' ') | |
3528 | if vals[1] != dev[0].p2p_interface_addr(): | |
3529 | raise Exception("Unexpected enrollee address: " + vals[1]) | |
3530 | if vals[5] != '4': | |
3531 | raise Exception("Unexpected Device Password Id: " + vals[5]) | |
3532 | hapd.request("WPS_PBC") | |
5f35a5e2 | 3533 | dev[0].wait_connected(timeout=30) |
1531402e JM |
3534 | |
3535 | def test_ap_wps_ap_scan_2(dev, apdev): | |
3536 | """AP_SCAN 2 for WPS""" | |
3537 | ssid = "test-wps-conf" | |
8b8a1864 | 3538 | hapd = hostapd.add_ap(apdev[0], |
1531402e JM |
3539 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3540 | "wpa_passphrase": "12345678", "wpa": "2", | |
3541 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
3542 | hapd.request("WPS_PBC") | |
3543 | ||
3544 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
3545 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
4b9d79b6 | 3546 | wpas.dump_monitor() |
1531402e JM |
3547 | |
3548 | if "OK" not in wpas.request("AP_SCAN 2"): | |
3549 | raise Exception("Failed to set AP_SCAN 2") | |
3550 | ||
e51c8b2e | 3551 | wpas.flush_scan_cache() |
33d0b157 | 3552 | wpas.scan_for_bss(apdev[0]['bssid'], freq="2412") |
4b9d79b6 | 3553 | wpas.dump_monitor() |
33d0b157 | 3554 | wpas.request("WPS_PBC " + apdev[0]['bssid']) |
1531402e JM |
3555 | ev = wpas.wait_event(["WPS-SUCCESS"], timeout=15) |
3556 | if ev is None: | |
3557 | raise Exception("WPS-SUCCESS event timed out") | |
5f35a5e2 | 3558 | wpas.wait_connected(timeout=30) |
4b9d79b6 | 3559 | wpas.dump_monitor() |
1531402e JM |
3560 | wpas.request("DISCONNECT") |
3561 | wpas.request("BSS_FLUSH 0") | |
3562 | wpas.dump_monitor() | |
3563 | wpas.request("REASSOCIATE") | |
5f35a5e2 | 3564 | wpas.wait_connected(timeout=30) |
4b9d79b6 | 3565 | wpas.dump_monitor() |
a08fdb17 | 3566 | |
9fd6804d | 3567 | @remote_compatible |
a08fdb17 JM |
3568 | def test_ap_wps_eapol_workaround(dev, apdev): |
3569 | """EAPOL workaround code path for 802.1X header length mismatch""" | |
3570 | ssid = "test-wps" | |
6f334bf7 JD |
3571 | hapd = hostapd.add_ap(apdev[0], |
3572 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
a08fdb17 JM |
3573 | bssid = apdev[0]['bssid'] |
3574 | hapd.request("SET ext_eapol_frame_io 1") | |
3575 | dev[0].request("SET ext_eapol_frame_io 1") | |
3576 | hapd.request("WPS_PBC") | |
3577 | dev[0].request("WPS_PBC") | |
3578 | ||
3579 | ev = hapd.wait_event(["EAPOL-TX"], timeout=15) | |
3580 | if ev is None: | |
3581 | raise Exception("Timeout on EAPOL-TX from hostapd") | |
3582 | ||
3583 | res = dev[0].request("EAPOL_RX " + bssid + " 020000040193000501FFFF") | |
3584 | if "OK" not in res: | |
3585 | raise Exception("EAPOL_RX to wpa_supplicant failed") | |
46dea617 JM |
3586 | |
3587 | def test_ap_wps_iteration(dev, apdev): | |
3588 | """WPS PIN and iterate through APs without selected registrar""" | |
3589 | ssid = "test-wps-conf" | |
8b8a1864 | 3590 | hapd = hostapd.add_ap(apdev[0], |
46dea617 JM |
3591 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3592 | "wpa_passphrase": "12345678", "wpa": "2", | |
3593 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
3594 | ||
3595 | ssid2 = "test-wps-conf2" | |
8b8a1864 | 3596 | hapd2 = hostapd.add_ap(apdev[1], |
46dea617 JM |
3597 | { "ssid": ssid2, "eap_server": "1", "wps_state": "2", |
3598 | "wpa_passphrase": "12345678", "wpa": "2", | |
3599 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
3600 | ||
3601 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3602 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
3603 | dev[0].dump_monitor() | |
3604 | pin = dev[0].request("WPS_PIN any") | |
3605 | ||
3606 | # Wait for iteration through all WPS APs to happen before enabling any | |
3607 | # Registrar. | |
3608 | for i in range(2): | |
3609 | ev = dev[0].wait_event(["Associated with"], timeout=30) | |
3610 | if ev is None: | |
3611 | raise Exception("No association seen") | |
3612 | ev = dev[0].wait_event(["WPS-M2D"], timeout=10) | |
3613 | if ev is None: | |
3614 | raise Exception("No M2D from AP") | |
3615 | dev[0].wait_disconnected() | |
3616 | ||
3617 | # Verify that each AP requested PIN | |
3618 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=1) | |
3619 | if ev is None: | |
3620 | raise Exception("No WPS-PIN-NEEDED event from AP") | |
3621 | ev = hapd2.wait_event(["WPS-PIN-NEEDED"], timeout=1) | |
3622 | if ev is None: | |
3623 | raise Exception("No WPS-PIN-NEEDED event from AP2") | |
3624 | ||
3625 | # Provide PIN to one of the APs and verify that connection gets formed | |
3626 | hapd.request("WPS_PIN any " + pin) | |
3627 | dev[0].wait_connected(timeout=30) | |
2272f5aa JM |
3628 | |
3629 | def test_ap_wps_iteration_error(dev, apdev): | |
3630 | """WPS AP iteration on no Selected Registrar and error case with an AP""" | |
3631 | ssid = "test-wps-conf-pin" | |
8b8a1864 | 3632 | hapd = hostapd.add_ap(apdev[0], |
2272f5aa JM |
3633 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3634 | "wpa_passphrase": "12345678", "wpa": "2", | |
3635 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
3636 | "wps_independent": "1" }) | |
3637 | hapd.request("SET ext_eapol_frame_io 1") | |
3638 | bssid = apdev[0]['bssid'] | |
3639 | pin = dev[0].wps_read_pin() | |
3640 | dev[0].request("WPS_PIN any " + pin) | |
3641 | ||
3642 | ev = hapd.wait_event(["EAPOL-TX"], timeout=15) | |
3643 | if ev is None: | |
3644 | raise Exception("No EAPOL-TX (EAP-Request/Identity) from hostapd") | |
3645 | dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2]) | |
3646 | ||
3647 | ev = hapd.wait_event(["EAPOL-TX"], timeout=15) | |
3648 | if ev is None: | |
3649 | raise Exception("No EAPOL-TX (EAP-WSC/Start) from hostapd") | |
3650 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5) | |
3651 | if ev is None: | |
3652 | raise Exception("No CTRL-EVENT-EAP-STARTED") | |
3653 | ||
3654 | # Do not forward any more EAPOL frames to test wpa_supplicant behavior for | |
3655 | # a case with an incorrectly behaving WPS AP. | |
3656 | ||
3657 | # Start the real target AP and activate registrar on it. | |
8b8a1864 | 3658 | hapd2 = hostapd.add_ap(apdev[1], |
2272f5aa JM |
3659 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3660 | "wpa_passphrase": "12345678", "wpa": "2", | |
3661 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
3662 | "wps_independent": "1" }) | |
3663 | hapd2.request("WPS_PIN any " + pin) | |
3664 | ||
3665 | dev[0].wait_disconnected(timeout=15) | |
3666 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=15) | |
3667 | if ev is None: | |
3668 | raise Exception("No CTRL-EVENT-EAP-STARTED for the second AP") | |
3669 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=15) | |
3670 | if ev is None: | |
3671 | raise Exception("No WPS-CRED-RECEIVED for the second AP") | |
3672 | dev[0].wait_connected(timeout=15) | |
d6f6a86a | 3673 | |
9fd6804d | 3674 | @remote_compatible |
d6f6a86a JM |
3675 | def test_ap_wps_priority(dev, apdev): |
3676 | """WPS PIN provisioning with configured AP and wps_priority""" | |
3677 | ssid = "test-wps-conf-pin" | |
6f334bf7 JD |
3678 | hapd = hostapd.add_ap(apdev[0], |
3679 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3680 | "wpa_passphrase": "12345678", "wpa": "2", | |
3681 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
d6f6a86a JM |
3682 | logger.info("WPS provisioning step") |
3683 | pin = dev[0].wps_read_pin() | |
3684 | hapd.request("WPS_PIN any " + pin) | |
3685 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3686 | dev[0].dump_monitor() | |
3687 | try: | |
3688 | dev[0].request("SET wps_priority 6") | |
3689 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
3690 | dev[0].wait_connected(timeout=30) | |
3691 | netw = dev[0].list_networks() | |
3692 | prio = dev[0].get_network(netw[0]['id'], 'priority') | |
3693 | if prio != '6': | |
3694 | raise Exception("Unexpected network priority: " + prio) | |
3695 | finally: | |
3696 | dev[0].request("SET wps_priority 0") | |
2c3a0190 | 3697 | |
9fd6804d | 3698 | @remote_compatible |
df1d01cf JM |
3699 | def test_ap_wps_and_non_wps(dev, apdev): |
3700 | """WPS and non-WPS AP in single hostapd process""" | |
3701 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" } | |
8b8a1864 | 3702 | hapd = hostapd.add_ap(apdev[0], params) |
df1d01cf JM |
3703 | |
3704 | params = { "ssid": "no wps" } | |
8b8a1864 | 3705 | hapd2 = hostapd.add_ap(apdev[1], params) |
df1d01cf JM |
3706 | |
3707 | appin = hapd.request("WPS_AP_PIN random") | |
3708 | if "FAIL" in appin: | |
3709 | raise Exception("Could not generate random AP PIN") | |
3710 | if appin not in hapd.request("WPS_AP_PIN get"): | |
3711 | raise Exception("Could not fetch current AP PIN") | |
3712 | ||
3713 | if "FAIL" in hapd.request("WPS_PBC"): | |
3714 | raise Exception("WPS_PBC failed") | |
3715 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
3716 | raise Exception("WPS_CANCEL failed") | |
3717 | ||
2c3a0190 JM |
3718 | def test_ap_wps_init_oom(dev, apdev): |
3719 | """Initial AP configuration and OOM during PSK generation""" | |
3720 | ssid = "test-wps" | |
3721 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" } | |
8b8a1864 | 3722 | hapd = hostapd.add_ap(apdev[0], params) |
2c3a0190 JM |
3723 | |
3724 | with alloc_fail(hapd, 1, "base64_encode;wps_build_cred"): | |
3725 | pin = dev[0].wps_read_pin() | |
3726 | hapd.request("WPS_PIN any " + pin) | |
3727 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3728 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
3729 | dev[0].wait_disconnected() | |
3730 | ||
3731 | hapd.request("WPS_PIN any " + pin) | |
3732 | dev[0].wait_connected(timeout=30) | |
ccf4d764 | 3733 | |
9fd6804d | 3734 | @remote_compatible |
ccf4d764 JM |
3735 | def test_ap_wps_er_oom(dev, apdev): |
3736 | """WPS ER OOM in XML processing""" | |
3737 | try: | |
3738 | _test_ap_wps_er_oom(dev, apdev) | |
3739 | finally: | |
3740 | dev[0].request("WPS_ER_STOP") | |
3741 | dev[1].request("WPS_CANCEL") | |
3742 | dev[0].request("DISCONNECT") | |
3743 | ||
3744 | def _test_ap_wps_er_oom(dev, apdev): | |
3745 | ssid = "wps-er-ap-config" | |
3746 | ap_pin = "12345670" | |
3747 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 3748 | hostapd.add_ap(apdev[0], |
ccf4d764 JM |
3749 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3750 | "wpa_passphrase": "12345678", "wpa": "2", | |
3751 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
3752 | "device_name": "Wireless AP", "manufacturer": "Company", | |
3753 | "model_name": "WAP", "model_number": "123", | |
3754 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
3755 | "os_version": "01020300", | |
3756 | "config_methods": "label push_button", | |
3757 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
3758 | ||
3759 | dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
3760 | ||
3761 | with alloc_fail(dev[0], 1, "base64_decode;xml_get_base64_item"): | |
3762 | dev[0].request("WPS_ER_START ifname=lo") | |
3763 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=3) | |
3764 | if ev is not None: | |
3765 | raise Exception("Unexpected AP discovery") | |
3766 | ||
3767 | dev[0].request("WPS_ER_STOP") | |
3768 | dev[0].request("WPS_ER_START ifname=lo") | |
3769 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
3770 | if ev is None: | |
3771 | raise Exception("AP discovery timed out") | |
3772 | ||
3773 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3774 | with alloc_fail(dev[0], 1, "base64_decode;xml_get_base64_item"): | |
3775 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
3776 | ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
3777 | if ev is None: | |
3778 | raise Exception("PBC scan failed") | |
3779 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) | |
3780 | if ev is None: | |
3781 | raise Exception("Enrollee discovery timed out") | |
2602a2ff | 3782 | |
9fd6804d | 3783 | @remote_compatible |
c965ae03 JM |
3784 | def test_ap_wps_er_init_oom(dev, apdev): |
3785 | """WPS ER and OOM during init""" | |
3786 | try: | |
3787 | _test_ap_wps_er_init_oom(dev, apdev) | |
3788 | finally: | |
3789 | dev[0].request("WPS_ER_STOP") | |
3790 | ||
3791 | def _test_ap_wps_er_init_oom(dev, apdev): | |
3792 | with alloc_fail(dev[0], 1, "wps_er_init"): | |
3793 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3794 | raise Exception("WPS_ER_START succeeded during OOM") | |
3795 | with alloc_fail(dev[0], 1, "http_server_init"): | |
3796 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3797 | raise Exception("WPS_ER_START succeeded during OOM") | |
3798 | with alloc_fail(dev[0], 2, "http_server_init"): | |
3799 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3800 | raise Exception("WPS_ER_START succeeded during OOM") | |
9b35afd6 | 3801 | with alloc_fail(dev[0], 1, "eloop_sock_table_add_sock;?eloop_register_sock;wps_er_ssdp_init"): |
c965ae03 JM |
3802 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): |
3803 | raise Exception("WPS_ER_START succeeded during OOM") | |
3804 | with fail_test(dev[0], 1, "os_get_random;wps_er_init"): | |
3805 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3806 | raise Exception("WPS_ER_START succeeded during os_get_random failure") | |
3807 | ||
9fd6804d | 3808 | @remote_compatible |
07536b18 JM |
3809 | def test_ap_wps_er_init_fail(dev, apdev): |
3810 | """WPS ER init failure""" | |
3811 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=does-not-exist"): | |
3812 | dev[0].request("WPS_ER_STOP") | |
3813 | raise Exception("WPS_ER_START with non-existing ifname succeeded") | |
3814 | ||
2602a2ff JM |
3815 | def test_ap_wps_wpa_cli_action(dev, apdev, test_params): |
3816 | """WPS events and wpa_cli action script""" | |
8936b095 JM |
3817 | logdir = os.path.abspath(test_params['logdir']) |
3818 | pidfile = os.path.join(logdir, 'ap_wps_wpa_cli_action.wpa_cli.pid') | |
3819 | logfile = os.path.join(logdir, 'ap_wps_wpa_cli_action.wpa_cli.res') | |
3820 | actionfile = os.path.join(logdir, 'ap_wps_wpa_cli_action.wpa_cli.action.sh') | |
2602a2ff JM |
3821 | |
3822 | with open(actionfile, 'w') as f: | |
3823 | f.write('#!/bin/sh\n') | |
3824 | f.write('echo $* >> %s\n' % logfile) | |
3825 | # Kill the process and wait some time before returning to allow all the | |
3826 | # pending events to be processed with some of this happening after the | |
3827 | # eloop SIGALRM signal has been scheduled. | |
3828 | f.write('if [ $2 = "WPS-SUCCESS" -a -r %s ]; then kill `cat %s`; sleep 1; fi\n' % (pidfile, pidfile)) | |
3829 | ||
8936b095 JM |
3830 | os.chmod(actionfile, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | |
3831 | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) | |
2602a2ff JM |
3832 | |
3833 | ssid = "test-wps-conf" | |
6f334bf7 JD |
3834 | hapd = hostapd.add_ap(apdev[0], |
3835 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3836 | "wpa_passphrase": "12345678", "wpa": "2", | |
3837 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
2602a2ff JM |
3838 | |
3839 | prg = os.path.join(test_params['logdir'], | |
3840 | 'alt-wpa_supplicant/wpa_supplicant/wpa_cli') | |
3841 | if not os.path.exists(prg): | |
3842 | prg = '../../wpa_supplicant/wpa_cli' | |
3843 | arg = [ prg, '-P', pidfile, '-B', '-i', dev[0].ifname, '-a', actionfile ] | |
3844 | subprocess.call(arg) | |
3845 | ||
3846 | arg = [ 'ps', 'ax' ] | |
3847 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE) | |
3848 | out = cmd.communicate()[0] | |
3849 | cmd.wait() | |
3850 | logger.debug("Processes:\n" + out) | |
3851 | if "wpa_cli -P %s -B -i %s" % (pidfile, dev[0].ifname) not in out: | |
3852 | raise Exception("Did not see wpa_cli running") | |
3853 | ||
3854 | hapd.request("WPS_PIN any 12345670") | |
3855 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3856 | dev[0].dump_monitor() | |
3857 | dev[0].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3858 | dev[0].wait_connected(timeout=30) | |
3859 | ||
3860 | for i in range(30): | |
3861 | if not os.path.exists(pidfile): | |
3862 | break | |
3863 | time.sleep(0.1) | |
3864 | ||
3865 | if not os.path.exists(logfile): | |
3866 | raise Exception("wpa_cli action results file not found") | |
3867 | with open(logfile, 'r') as f: | |
3868 | res = f.read() | |
3869 | if "WPS-SUCCESS" not in res: | |
3870 | raise Exception("WPS-SUCCESS event not seen in action file") | |
3871 | ||
3872 | arg = [ 'ps', 'ax' ] | |
3873 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE) | |
3874 | out = cmd.communicate()[0] | |
3875 | cmd.wait() | |
3876 | logger.debug("Remaining processes:\n" + out) | |
3877 | if "wpa_cli -P %s -B -i %s" % (pidfile, dev[0].ifname) in out: | |
3878 | raise Exception("wpa_cli still running") | |
3879 | ||
3880 | if os.path.exists(pidfile): | |
3881 | raise Exception("PID file not removed") | |
c965ae03 JM |
3882 | |
3883 | def test_ap_wps_er_ssdp_proto(dev, apdev): | |
3884 | """WPS ER SSDP protocol testing""" | |
3885 | try: | |
3886 | _test_ap_wps_er_ssdp_proto(dev, apdev) | |
3887 | finally: | |
3888 | dev[0].request("WPS_ER_STOP") | |
3889 | ||
3890 | def _test_ap_wps_er_ssdp_proto(dev, apdev): | |
3891 | socket.setdefaulttimeout(1) | |
3892 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
3893 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
3894 | sock.bind(("239.255.255.250", 1900)) | |
3895 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo foo"): | |
3896 | raise Exception("Invalid filter accepted") | |
3897 | if "OK" not in dev[0].request("WPS_ER_START ifname=lo 1.2.3.4"): | |
3898 | raise Exception("WPS_ER_START with filter failed") | |
3899 | (msg,addr) = sock.recvfrom(1000) | |
3900 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
3901 | if "M-SEARCH" not in msg: | |
3902 | raise Exception("Not an M-SEARCH") | |
3903 | sock.sendto("FOO", addr) | |
3904 | time.sleep(0.1) | |
3905 | dev[0].request("WPS_ER_STOP") | |
3906 | ||
3907 | dev[0].request("WPS_ER_START ifname=lo") | |
3908 | (msg,addr) = sock.recvfrom(1000) | |
3909 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
3910 | if "M-SEARCH" not in msg: | |
3911 | raise Exception("Not an M-SEARCH") | |
3912 | sock.sendto("FOO", addr) | |
3913 | sock.sendto("HTTP/1.1 200 OK\r\nFOO\r\n\r\n", addr) | |
3914 | sock.sendto("HTTP/1.1 200 OK\r\nNTS:foo\r\n\r\n", addr) | |
3915 | sock.sendto("HTTP/1.1 200 OK\r\nNTS:ssdp:byebye\r\n\r\n", addr) | |
3916 | sock.sendto("HTTP/1.1 200 OK\r\ncache-control: foo=1\r\n\r\n", addr) | |
3917 | sock.sendto("HTTP/1.1 200 OK\r\ncache-control: max-age=1\r\n\r\n", addr) | |
3918 | sock.sendto("HTTP/1.1 200 OK\r\nusn:\r\n\r\n", addr) | |
3919 | sock.sendto("HTTP/1.1 200 OK\r\nusn:foo\r\n\r\n", addr) | |
3920 | sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid:\r\n\r\n", addr) | |
3921 | sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid: \r\n\r\n", addr) | |
3922 | sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid: foo\r\n\r\n", addr) | |
3923 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\n\r\n", addr) | |
3924 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nNTS:ssdp:byebye\r\n\r\n", addr) | |
3925 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\n\r\n", addr) | |
3926 | with alloc_fail(dev[0], 1, "wps_er_ap_add"): | |
3927 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr) | |
3928 | time.sleep(0.1) | |
3929 | with alloc_fail(dev[0], 2, "wps_er_ap_add"): | |
3930 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr) | |
3931 | time.sleep(0.1) | |
3932 | ||
3933 | # Add an AP with bogus URL | |
3934 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr) | |
3935 | # Update timeout on AP without updating URL | |
3936 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1:12345/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr) | |
3937 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5) | |
3938 | if ev is None: | |
3939 | raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout") | |
3940 | ||
3941 | # Add an AP with a valid URL (but no server listing to it) | |
3942 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1:12345/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr) | |
3943 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5) | |
3944 | if ev is None: | |
3945 | raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout") | |
3946 | ||
3947 | sock.close() | |
3948 | ||
3949 | wps_event_url = None | |
3950 | ||
6aaa661a JM |
3951 | def gen_upnp_info(eventSubURL='wps_event', controlURL='wps_control', |
3952 | udn='uuid:27ea801a-9e5c-4e73-bd82-f89cbcd10d7e'): | |
4c3ae1c0 | 3953 | payload = '''<?xml version="1.0"?> |
c965ae03 JM |
3954 | <root xmlns="urn:schemas-upnp-org:device-1-0"> |
3955 | <specVersion> | |
3956 | <major>1</major> | |
3957 | <minor>0</minor> | |
3958 | </specVersion> | |
3959 | <device> | |
3960 | <deviceType>urn:schemas-wifialliance-org:device:WFADevice:1</deviceType> | |
3961 | <friendlyName>WPS Access Point</friendlyName> | |
3962 | <manufacturer>Company</manufacturer> | |
3963 | <modelName>WAP</modelName> | |
3964 | <modelNumber>123</modelNumber> | |
3965 | <serialNumber>12345</serialNumber> | |
6aaa661a JM |
3966 | ''' |
3967 | if udn: | |
3968 | payload += '<UDN>' + udn + '</UDN>' | |
3969 | payload += '''<serviceList> | |
c965ae03 JM |
3970 | <service> |
3971 | <serviceType>urn:schemas-wifialliance-org:service:WFAWLANConfig:1</serviceType> | |
3972 | <serviceId>urn:wifialliance-org:serviceId:WFAWLANConfig1</serviceId> | |
3973 | <SCPDURL>wps_scpd.xml</SCPDURL> | |
4c3ae1c0 | 3974 | ''' |
6aaa661a JM |
3975 | if controlURL: |
3976 | payload += '<controlURL>' + controlURL + '</controlURL>\n' | |
4c3ae1c0 | 3977 | if eventSubURL: |
6aaa661a | 3978 | payload += '<eventSubURL>' + eventSubURL + '</eventSubURL>\n' |
4c3ae1c0 | 3979 | payload += '''</service> |
c965ae03 JM |
3980 | </serviceList> |
3981 | </device> | |
3982 | </root> | |
3983 | ''' | |
4c3ae1c0 JM |
3984 | hdr = 'HTTP/1.1 200 OK\r\n' + \ |
3985 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
3986 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
3987 | 'Connection: close\r\n' + \ | |
3988 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
3989 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
3990 | return hdr + payload | |
3991 | ||
6aaa661a | 3992 | def gen_wps_control(payload_override=None): |
4c3ae1c0 | 3993 | payload = '''<?xml version="1.0"?> |
c965ae03 JM |
3994 | <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
3995 | <s:Body> | |
3996 | <u:GetDeviceInfoResponse xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1"> | |
3997 | <NewDeviceInfo>EEoAARAQIgABBBBHABAn6oAanlxOc72C+Jy80Q1+ECAABgIAAAADABAaABCJZ7DPtbU3Ust9 | |
3998 | Z3wJF07WEDIAwH45D3i1OqB7eJGwTzqeapS71h3KyXncK2xJZ+xqScrlorNEg6LijBJzG2Ca | |
3999 | +FZli0iliDJd397yAx/jk4nFXco3q5ylBSvSw9dhJ5u1xBKSnTilKGlUHPhLP75PUqM3fot9 | |
4000 | 7zwtFZ4bx6x1sBA6oEe2d0aUJmLumQGCiKEIWlnxs44zego/2tAe81bDzdPBM7o5HH/FUhD+ | |
4001 | KoGzFXp51atP+1n9Vta6AkI0Vye99JKLcC6Md9dMJltSVBgd4Xc4lRAEAAIAIxAQAAIADRAN | |
4002 | AAEBEAgAAgAEEEQAAQIQIQAHQ29tcGFueRAjAANXQVAQJAADMTIzEEIABTEyMzQ1EFQACAAG | |
4003 | AFDyBAABEBEAC1dpcmVsZXNzIEFQEDwAAQEQAgACAAAQEgACAAAQCQACAAAQLQAEgQIDABBJ | |
4004 | AAYANyoAASA= | |
4005 | </NewDeviceInfo> | |
4006 | </u:GetDeviceInfoResponse> | |
4007 | </s:Body> | |
4008 | </s:Envelope> | |
4009 | ''' | |
6aaa661a JM |
4010 | if payload_override: |
4011 | payload = payload_override | |
4c3ae1c0 JM |
4012 | hdr = 'HTTP/1.1 200 OK\r\n' + \ |
4013 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4014 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4015 | 'Connection: close\r\n' + \ | |
4016 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4017 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4018 | return hdr + payload | |
4019 | ||
6aaa661a | 4020 | def gen_wps_event(sid='uuid:7eb3342a-8a5f-47fe-a585-0785bfec6d8a'): |
4c3ae1c0 JM |
4021 | payload = "" |
4022 | hdr = 'HTTP/1.1 200 OK\r\n' + \ | |
4023 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4024 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4025 | 'Connection: close\r\n' + \ | |
6aaa661a JM |
4026 | 'Content-Length: ' + str(len(payload)) + '\r\n' |
4027 | if sid: | |
4028 | hdr += 'SID: ' + sid + '\r\n' | |
4029 | hdr += 'Timeout: Second-1801\r\n' + \ | |
4c3ae1c0 JM |
4030 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' |
4031 | return hdr + payload | |
4032 | ||
4033 | class WPSAPHTTPServer(SocketServer.StreamRequestHandler): | |
4034 | def handle(self): | |
4035 | data = self.rfile.readline().strip() | |
4036 | logger.info("HTTP server received: " + data) | |
4037 | while True: | |
4038 | hdr = self.rfile.readline().strip() | |
4039 | if len(hdr) == 0: | |
4040 | break | |
4041 | logger.info("HTTP header: " + hdr) | |
4042 | if "CALLBACK:" in hdr: | |
4043 | global wps_event_url | |
4044 | wps_event_url = hdr.split(' ')[1].strip('<>') | |
4045 | ||
4046 | if "GET /foo.xml" in data: | |
6aaa661a JM |
4047 | self.handle_upnp_info() |
4048 | elif "POST /wps_control" in data: | |
4049 | self.handle_wps_control() | |
4050 | elif "SUBSCRIBE /wps_event" in data: | |
4051 | self.handle_wps_event() | |
24b7f282 JM |
4052 | else: |
4053 | self.handle_others(data) | |
6aaa661a JM |
4054 | |
4055 | def handle_upnp_info(self): | |
4056 | self.wfile.write(gen_upnp_info()) | |
4c3ae1c0 | 4057 | |
6aaa661a JM |
4058 | def handle_wps_control(self): |
4059 | self.wfile.write(gen_wps_control()) | |
c965ae03 | 4060 | |
6aaa661a JM |
4061 | def handle_wps_event(self): |
4062 | self.wfile.write(gen_wps_event()) | |
c965ae03 | 4063 | |
24b7f282 JM |
4064 | def handle_others(self, data): |
4065 | logger.info("Ignore HTTP request: " + data) | |
4066 | ||
4c3ae1c0 JM |
4067 | class MyTCPServer(SocketServer.TCPServer): |
4068 | def __init__(self, addr, handler): | |
4069 | self.allow_reuse_address = True | |
4070 | SocketServer.TCPServer.__init__(self, addr, handler) | |
c965ae03 | 4071 | |
24b7f282 JM |
4072 | def wps_er_start(dev, http_server, max_age=1, wait_m_search=False, |
4073 | location_url=None): | |
c965ae03 JM |
4074 | socket.setdefaulttimeout(1) |
4075 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
4076 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
4077 | sock.bind(("239.255.255.250", 1900)) | |
4c3ae1c0 | 4078 | dev.request("WPS_ER_START ifname=lo") |
24b7f282 JM |
4079 | for i in range(100): |
4080 | (msg,addr) = sock.recvfrom(1000) | |
4081 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
4082 | if "M-SEARCH" in msg: | |
4083 | break | |
4084 | if not wait_m_search: | |
4085 | raise Exception("Not an M-SEARCH") | |
4086 | if i == 99: | |
4087 | raise Exception("No M-SEARCH seen") | |
c965ae03 JM |
4088 | |
4089 | # Add an AP with a valid URL and server listing to it | |
4c3ae1c0 | 4090 | server = MyTCPServer(("127.0.0.1", 12345), http_server) |
24b7f282 JM |
4091 | if not location_url: |
4092 | location_url = 'http://127.0.0.1:12345/foo.xml' | |
4093 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:%s\r\ncache-control:max-age=%d\r\n\r\n" % (location_url, max_age), addr) | |
c965ae03 | 4094 | server.timeout = 1 |
4c3ae1c0 JM |
4095 | return server,sock |
4096 | ||
4097 | def wps_er_stop(dev, sock, server, on_alloc_fail=False): | |
4098 | sock.close() | |
4099 | server.server_close() | |
4100 | ||
4101 | if on_alloc_fail: | |
4102 | done = False | |
4103 | for i in range(50): | |
4104 | res = dev.request("GET_ALLOC_FAIL") | |
4105 | if res.startswith("0:"): | |
4106 | done = True | |
4107 | break | |
4108 | time.sleep(0.1) | |
4109 | if not done: | |
4110 | raise Exception("No allocation failure reported") | |
4111 | else: | |
4112 | ev = dev.wait_event(["WPS-ER-AP-REMOVE"], timeout=5) | |
4113 | if ev is None: | |
4114 | raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout") | |
4115 | dev.request("WPS_ER_STOP") | |
4116 | ||
24b7f282 | 4117 | def run_wps_er_proto_test(dev, handler, no_event_url=False, location_url=None): |
6aaa661a JM |
4118 | try: |
4119 | uuid = '27ea801a-9e5c-4e73-bd82-f89cbcd10d7e' | |
24b7f282 | 4120 | server,sock = wps_er_start(dev, handler, location_url=location_url) |
6aaa661a JM |
4121 | global wps_event_url |
4122 | wps_event_url = None | |
4123 | server.handle_request() | |
4124 | server.handle_request() | |
4125 | server.handle_request() | |
4126 | server.server_close() | |
4127 | if no_event_url: | |
4128 | if wps_event_url: | |
4129 | raise Exception("Received event URL unexpectedly") | |
4130 | return | |
4131 | if wps_event_url is None: | |
4132 | raise Exception("Did not get event URL") | |
4133 | logger.info("Event URL: " + wps_event_url) | |
4134 | finally: | |
24b7f282 | 4135 | dev.request("WPS_ER_STOP") |
6aaa661a | 4136 | |
18478107 | 4137 | def send_wlanevent(url, uuid, data, no_response=False): |
6aaa661a JM |
4138 | conn = httplib.HTTPConnection(url.netloc) |
4139 | payload = '''<?xml version="1.0" encoding="utf-8"?> | |
4140 | <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> | |
4141 | <e:property><STAStatus>1</STAStatus></e:property> | |
4142 | <e:property><APStatus>1</APStatus></e:property> | |
4143 | <e:property><WLANEvent>''' | |
4144 | payload += base64.b64encode(data) | |
4145 | payload += '</WLANEvent></e:property></e:propertyset>' | |
4146 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4147 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4148 | "HOST": url.netloc, | |
4149 | "NT": "upnp:event", | |
4150 | "SID": "uuid:" + uuid, | |
4151 | "SEQ": "0", | |
4152 | "Content-Length": str(len(payload)) } | |
4153 | conn.request("NOTIFY", url.path, payload, headers) | |
18478107 JM |
4154 | if no_response: |
4155 | try: | |
4156 | conn.getresponse() | |
4157 | except Exception, e: | |
4158 | pass | |
4159 | return | |
6aaa661a JM |
4160 | resp = conn.getresponse() |
4161 | if resp.status != 200: | |
4162 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4163 | ||
4c3ae1c0 JM |
4164 | def test_ap_wps_er_http_proto(dev, apdev): |
4165 | """WPS ER HTTP protocol testing""" | |
4166 | try: | |
4167 | _test_ap_wps_er_http_proto(dev, apdev) | |
4168 | finally: | |
4169 | dev[0].request("WPS_ER_STOP") | |
4170 | ||
4171 | def _test_ap_wps_er_http_proto(dev, apdev): | |
4172 | uuid = '27ea801a-9e5c-4e73-bd82-f89cbcd10d7e' | |
6aaa661a | 4173 | server,sock = wps_er_start(dev[0], WPSAPHTTPServer, max_age=15) |
c965ae03 JM |
4174 | global wps_event_url |
4175 | wps_event_url = None | |
4176 | server.handle_request() | |
4177 | server.handle_request() | |
4178 | server.handle_request() | |
4179 | server.server_close() | |
4180 | if wps_event_url is None: | |
4181 | raise Exception("Did not get event URL") | |
4182 | logger.info("Event URL: " + wps_event_url) | |
4183 | ||
4184 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
4185 | if ev is None: | |
4186 | raise Exception("No WPS-ER-AP-ADD event") | |
4187 | if uuid not in ev: | |
4188 | raise Exception("UUID mismatch") | |
4189 | ||
4190 | sock.close() | |
4191 | ||
4192 | logger.info("Valid Probe Request notification") | |
4193 | url = urlparse.urlparse(wps_event_url) | |
4194 | conn = httplib.HTTPConnection(url.netloc) | |
4195 | payload = '''<?xml version="1.0" encoding="utf-8"?> | |
4196 | <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> | |
4197 | <e:property><STAStatus>1</STAStatus></e:property> | |
4198 | <e:property><APStatus>1</APStatus></e:property> | |
4199 | <e:property><WLANEvent>ATAyOjAwOjAwOjAwOjAwOjAwEEoAARAQOgABAhAIAAIxSBBHABA2LbR7pTpRkYj7VFi5hrLk | |
4200 | EFQACAAAAAAAAAAAEDwAAQMQAgACAAAQCQACAAAQEgACAAAQIQABIBAjAAEgECQAASAQEQAI | |
4201 | RGV2aWNlIEEQSQAGADcqAAEg | |
4202 | </WLANEvent></e:property> | |
4203 | </e:propertyset> | |
4204 | ''' | |
4205 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4206 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4207 | "HOST": url.netloc, | |
4208 | "NT": "upnp:event", | |
4209 | "SID": "uuid:" + uuid, | |
4210 | "SEQ": "0", | |
4211 | "Content-Length": str(len(payload)) } | |
4212 | conn.request("NOTIFY", url.path, payload, headers) | |
4213 | resp = conn.getresponse() | |
4214 | if resp.status != 200: | |
4215 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4216 | ||
4217 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=5) | |
4218 | if ev is None: | |
4219 | raise Exception("No WPS-ER-ENROLLEE-ADD event") | |
4220 | if "362db47b-a53a-5191-88fb-5458b986b2e4" not in ev: | |
4221 | raise Exception("No Enrollee UUID match") | |
4222 | ||
4223 | logger.info("Incorrect event URL AP id") | |
4224 | conn = httplib.HTTPConnection(url.netloc) | |
4225 | conn.request("NOTIFY", url.path + '123', payload, headers) | |
4226 | resp = conn.getresponse() | |
4227 | if resp.status != 404: | |
4228 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4229 | ||
4230 | logger.info("Missing AP id") | |
4231 | conn = httplib.HTTPConnection(url.netloc) | |
4232 | conn.request("NOTIFY", '/event/' + url.path.split('/')[2], | |
4233 | payload, headers) | |
4234 | time.sleep(0.1) | |
4235 | ||
4236 | logger.info("Incorrect event URL event id") | |
4237 | conn = httplib.HTTPConnection(url.netloc) | |
4238 | conn.request("NOTIFY", '/event/123456789/123', payload, headers) | |
4239 | time.sleep(0.1) | |
4240 | ||
4241 | logger.info("Incorrect event URL prefix") | |
4242 | conn = httplib.HTTPConnection(url.netloc) | |
4243 | conn.request("NOTIFY", '/foobar/123456789/123', payload, headers) | |
4244 | resp = conn.getresponse() | |
4245 | if resp.status != 404: | |
4246 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4247 | ||
4248 | logger.info("Unsupported request") | |
4249 | conn = httplib.HTTPConnection(url.netloc) | |
4250 | conn.request("FOOBAR", '/foobar/123456789/123', payload, headers) | |
4251 | resp = conn.getresponse() | |
4252 | if resp.status != 501: | |
4253 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4254 | ||
4255 | logger.info("Unsupported request and OOM") | |
4256 | with alloc_fail(dev[0], 1, "wps_er_http_req"): | |
4257 | conn = httplib.HTTPConnection(url.netloc) | |
4258 | conn.request("FOOBAR", '/foobar/123456789/123', payload, headers) | |
4259 | time.sleep(0.5) | |
4c3ae1c0 | 4260 | |
6aaa661a JM |
4261 | logger.info("Too short WLANEvent") |
4262 | data = '\x00' | |
4263 | send_wlanevent(url, uuid, data) | |
4264 | ||
4265 | logger.info("Invalid WLANEventMAC") | |
4266 | data = '\x00qwertyuiopasdfghjklzxcvbnm' | |
4267 | send_wlanevent(url, uuid, data) | |
4268 | ||
4269 | logger.info("Unknown WLANEventType") | |
4270 | data = '\xff02:00:00:00:00:00' | |
4271 | send_wlanevent(url, uuid, data) | |
4272 | ||
4273 | logger.info("Probe Request notification without any attributes") | |
4274 | data = '\x0102:00:00:00:00:00' | |
4275 | send_wlanevent(url, uuid, data) | |
4276 | ||
4277 | logger.info("Probe Request notification with invalid attribute") | |
4278 | data = '\x0102:00:00:00:00:00\xff' | |
4279 | send_wlanevent(url, uuid, data) | |
4280 | ||
4281 | logger.info("EAP message without any attributes") | |
4282 | data = '\x0202:00:00:00:00:00' | |
4283 | send_wlanevent(url, uuid, data) | |
4284 | ||
4285 | logger.info("EAP message with invalid attribute") | |
4286 | data = '\x0202:00:00:00:00:00\xff' | |
4287 | send_wlanevent(url, uuid, data) | |
4288 | ||
4289 | logger.info("EAP message from new STA and not M1") | |
4290 | data = '\x0202:ff:ff:ff:ff:ff' + '\x10\x22\x00\x01\x05' | |
4291 | send_wlanevent(url, uuid, data) | |
4292 | ||
4293 | logger.info("EAP message: M1") | |
4294 | data = '\x0202:00:00:00:00:00' | |
4295 | data += '\x10\x22\x00\x01\x04' | |
4296 | data += '\x10\x47\x00\x10' + 16*'\x00' | |
4297 | data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' | |
4298 | data += '\x10\x1a\x00\x10' + 16*'\x00' | |
4299 | data += '\x10\x32\x00\xc0' + 192*'\x00' | |
4300 | data += '\x10\x04\x00\x02\x00\x00' | |
4301 | data += '\x10\x10\x00\x02\x00\x00' | |
4302 | data += '\x10\x0d\x00\x01\x00' | |
4303 | data += '\x10\x08\x00\x02\x00\x00' | |
4304 | data += '\x10\x44\x00\x01\x00' | |
4305 | data += '\x10\x21\x00\x00' | |
4306 | data += '\x10\x23\x00\x00' | |
4307 | data += '\x10\x24\x00\x00' | |
4308 | data += '\x10\x42\x00\x00' | |
4309 | data += '\x10\x54\x00\x08' + 8*'\x00' | |
4310 | data += '\x10\x11\x00\x00' | |
4311 | data += '\x10\x3c\x00\x01\x00' | |
4312 | data += '\x10\x02\x00\x02\x00\x00' | |
4313 | data += '\x10\x12\x00\x02\x00\x00' | |
4314 | data += '\x10\x09\x00\x02\x00\x00' | |
4315 | data += '\x10\x2d\x00\x04\x00\x00\x00\x00' | |
4316 | m1 = data | |
4317 | send_wlanevent(url, uuid, data) | |
4318 | ||
4319 | logger.info("EAP message: WSC_ACK") | |
4320 | data = '\x0202:00:00:00:00:00' + '\x10\x22\x00\x01\x0d' | |
4321 | send_wlanevent(url, uuid, data) | |
4322 | ||
4323 | logger.info("EAP message: M1") | |
4324 | send_wlanevent(url, uuid, m1) | |
4325 | ||
4326 | logger.info("EAP message: WSC_NACK") | |
4327 | data = '\x0202:00:00:00:00:00' + '\x10\x22\x00\x01\x0e' | |
4328 | send_wlanevent(url, uuid, data) | |
4329 | ||
4330 | logger.info("EAP message: M1 - Too long attribute values") | |
4331 | data = '\x0202:00:00:00:00:00' | |
4332 | data += '\x10\x11\x00\x21' + 33*'\x00' | |
4333 | data += '\x10\x45\x00\x21' + 33*'\x00' | |
4334 | data += '\x10\x42\x00\x21' + 33*'\x00' | |
4335 | data += '\x10\x24\x00\x21' + 33*'\x00' | |
4336 | data += '\x10\x23\x00\x21' + 33*'\x00' | |
4337 | data += '\x10\x21\x00\x41' + 65*'\x00' | |
4338 | data += '\x10\x49\x00\x09\x00\x37\x2a\x05\x02\x00\x00\x05\x00' | |
4339 | send_wlanevent(url, uuid, data) | |
4340 | ||
4341 | logger.info("EAP message: M1 missing UUID-E") | |
4342 | data = '\x0202:00:00:00:00:00' | |
4343 | data += '\x10\x22\x00\x01\x04' | |
4344 | send_wlanevent(url, uuid, data) | |
4345 | ||
4346 | logger.info("EAP message: M1 missing MAC Address") | |
4347 | data += '\x10\x47\x00\x10' + 16*'\x00' | |
4348 | send_wlanevent(url, uuid, data) | |
4349 | ||
4350 | logger.info("EAP message: M1 missing Enrollee Nonce") | |
4351 | data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' | |
4352 | send_wlanevent(url, uuid, data) | |
4353 | ||
4354 | logger.info("EAP message: M1 missing Public Key") | |
4355 | data += '\x10\x1a\x00\x10' + 16*'\x00' | |
4356 | send_wlanevent(url, uuid, data) | |
4357 | ||
4358 | logger.info("EAP message: M1 missing Authentication Type flags") | |
4359 | data += '\x10\x32\x00\xc0' + 192*'\x00' | |
4360 | send_wlanevent(url, uuid, data) | |
4361 | ||
4362 | logger.info("EAP message: M1 missing Encryption Type Flags") | |
4363 | data += '\x10\x04\x00\x02\x00\x00' | |
4364 | send_wlanevent(url, uuid, data) | |
4365 | ||
4366 | logger.info("EAP message: M1 missing Connection Type flags") | |
4367 | data += '\x10\x10\x00\x02\x00\x00' | |
4368 | send_wlanevent(url, uuid, data) | |
4369 | ||
4370 | logger.info("EAP message: M1 missing Config Methods") | |
4371 | data += '\x10\x0d\x00\x01\x00' | |
4372 | send_wlanevent(url, uuid, data) | |
4373 | ||
4374 | logger.info("EAP message: M1 missing Wi-Fi Protected Setup State") | |
4375 | data += '\x10\x08\x00\x02\x00\x00' | |
4376 | send_wlanevent(url, uuid, data) | |
4377 | ||
4378 | logger.info("EAP message: M1 missing Manufacturer") | |
4379 | data += '\x10\x44\x00\x01\x00' | |
4380 | send_wlanevent(url, uuid, data) | |
4381 | ||
4382 | logger.info("EAP message: M1 missing Model Name") | |
4383 | data += '\x10\x21\x00\x00' | |
4384 | send_wlanevent(url, uuid, data) | |
4385 | ||
4386 | logger.info("EAP message: M1 missing Model Number") | |
4387 | data += '\x10\x23\x00\x00' | |
4388 | send_wlanevent(url, uuid, data) | |
4389 | ||
4390 | logger.info("EAP message: M1 missing Serial Number") | |
4391 | data += '\x10\x24\x00\x00' | |
4392 | send_wlanevent(url, uuid, data) | |
4393 | ||
4394 | logger.info("EAP message: M1 missing Primary Device Type") | |
4395 | data += '\x10\x42\x00\x00' | |
4396 | send_wlanevent(url, uuid, data) | |
4397 | ||
4398 | logger.info("EAP message: M1 missing Device Name") | |
4399 | data += '\x10\x54\x00\x08' + 8*'\x00' | |
4400 | send_wlanevent(url, uuid, data) | |
4401 | ||
4402 | logger.info("EAP message: M1 missing RF Bands") | |
4403 | data += '\x10\x11\x00\x00' | |
4404 | send_wlanevent(url, uuid, data) | |
4405 | ||
4406 | logger.info("EAP message: M1 missing Association State") | |
4407 | data += '\x10\x3c\x00\x01\x00' | |
4408 | send_wlanevent(url, uuid, data) | |
4409 | ||
4410 | logger.info("EAP message: M1 missing Device Password ID") | |
4411 | data += '\x10\x02\x00\x02\x00\x00' | |
4412 | send_wlanevent(url, uuid, data) | |
4413 | ||
4414 | logger.info("EAP message: M1 missing Configuration Error") | |
4415 | data += '\x10\x12\x00\x02\x00\x00' | |
4416 | send_wlanevent(url, uuid, data) | |
4417 | ||
4418 | logger.info("EAP message: M1 missing OS Version") | |
4419 | data += '\x10\x09\x00\x02\x00\x00' | |
4420 | send_wlanevent(url, uuid, data) | |
4c3ae1c0 | 4421 | |
24b7f282 JM |
4422 | logger.info("Check max concurrent requests") |
4423 | addr = (url.hostname, url.port) | |
4424 | socks = {} | |
4425 | for i in range(20): | |
4426 | socks[i] = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4427 | socket.IPPROTO_TCP) | |
e5d3e13a JM |
4428 | socks[i].settimeout(10) |
4429 | socks[i].connect(addr) | |
24b7f282 JM |
4430 | for i in range(20): |
4431 | socks[i].send("GET / HTTP/1.1\r\n\r\n") | |
4432 | count = 0 | |
4433 | for i in range(20): | |
4434 | try: | |
4435 | res = socks[i].recv(100) | |
4436 | if "HTTP/1" in res: | |
4437 | count += 1 | |
4438 | except: | |
4439 | pass | |
4440 | socks[i].close() | |
4441 | logger.info("%d concurrent HTTP GET operations returned response" % count) | |
4442 | if count < 10: | |
4443 | raise Exception("Too few concurrent HTTP connections accepted") | |
4444 | ||
4445 | logger.info("OOM in HTTP server") | |
4446 | for func in [ "http_request_init", "httpread_create", | |
4447 | "eloop_register_timeout;httpread_create", | |
9b35afd6 | 4448 | "eloop_sock_table_add_sock;?eloop_register_sock;httpread_create", |
24b7f282 JM |
4449 | "httpread_hdr_analyze" ]: |
4450 | with alloc_fail(dev[0], 1, func): | |
4451 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4452 | socket.IPPROTO_TCP) | |
4453 | sock.connect(addr) | |
4454 | sock.send("GET / HTTP/1.1\r\n\r\n") | |
4455 | try: | |
4456 | sock.recv(100) | |
4457 | except: | |
4458 | pass | |
4459 | sock.close() | |
4460 | ||
4461 | logger.info("Invalid HTTP header") | |
4462 | for req in [ " GET / HTTP/1.1\r\n\r\n", | |
4463 | "HTTP/1.1 200 OK\r\n\r\n", | |
4464 | "HTTP/\r\n\r\n", | |
4465 | "GET %%a%aa% HTTP/1.1\r\n\r\n", | |
4466 | "GET / HTTP/1.1\r\n FOO\r\n\r\n", | |
4467 | "NOTIFY / HTTP/1.1\r\n" + 4097*'a' + '\r\n\r\n', | |
4468 | "NOTIFY / HTTP/1.1\r\n\r\n" + 8193*'a', | |
4469 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n foo\r\n", | |
4470 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n1\r\nfoo\r\n", | |
4471 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n0\r\n", | |
4472 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n0\r\naa\ra\r\n\ra" ]: | |
4473 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4474 | socket.IPPROTO_TCP) | |
4475 | sock.settimeout(0.1) | |
4476 | sock.connect(addr) | |
4477 | sock.send(req) | |
4478 | try: | |
4479 | sock.recv(100) | |
4480 | except: | |
4481 | pass | |
4482 | sock.close() | |
4483 | ||
4484 | with alloc_fail(dev[0], 2, "httpread_read_handler"): | |
4485 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4486 | socket.IPPROTO_TCP) | |
4487 | sock.connect(addr) | |
4488 | sock.send("NOTIFY / HTTP/1.1\r\n\r\n" + 4500*'a') | |
4489 | try: | |
4490 | sock.recv(100) | |
4491 | except: | |
4492 | pass | |
4493 | sock.close() | |
4494 | ||
4495 | conn = httplib.HTTPConnection(url.netloc) | |
4496 | payload = '<foo' | |
4497 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4498 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4499 | "HOST": url.netloc, | |
4500 | "NT": "upnp:event", | |
4501 | "SID": "uuid:" + uuid, | |
4502 | "SEQ": "0", | |
4503 | "Content-Length": str(len(payload)) } | |
4504 | conn.request("NOTIFY", url.path, payload, headers) | |
4505 | resp = conn.getresponse() | |
4506 | if resp.status != 200: | |
4507 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4508 | ||
4509 | conn = httplib.HTTPConnection(url.netloc) | |
4510 | payload = '<WLANEvent foo></WLANEvent>' | |
4511 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4512 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4513 | "HOST": url.netloc, | |
4514 | "NT": "upnp:event", | |
4515 | "SID": "uuid:" + uuid, | |
4516 | "SEQ": "0", | |
4517 | "Content-Length": str(len(payload)) } | |
4518 | conn.request("NOTIFY", url.path, payload, headers) | |
4519 | resp = conn.getresponse() | |
4520 | if resp.status != 200: | |
4521 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4522 | ||
4523 | with alloc_fail(dev[0], 1, "xml_get_first_item"): | |
4524 | send_wlanevent(url, uuid, '') | |
4525 | ||
4526 | with alloc_fail(dev[0], 1, "wpabuf_alloc_ext_data;xml_get_base64_item"): | |
4527 | send_wlanevent(url, uuid, 'foo') | |
4528 | ||
4529 | for func in [ "wps_init", | |
4530 | "wps_process_manufacturer", | |
4531 | "wps_process_model_name", | |
4532 | "wps_process_model_number", | |
4533 | "wps_process_serial_number", | |
4534 | "wps_process_dev_name" ]: | |
4535 | with alloc_fail(dev[0], 1, func): | |
4536 | send_wlanevent(url, uuid, m1) | |
4537 | ||
18478107 JM |
4538 | with alloc_fail(dev[0], 1, "wps_er_http_resp_ok"): |
4539 | send_wlanevent(url, uuid, m1, no_response=True) | |
4540 | ||
4541 | with alloc_fail(dev[0], 1, "wps_er_http_resp_not_found"): | |
4542 | url2 = urlparse.urlparse(wps_event_url.replace('/event/', '/notfound/')) | |
4543 | send_wlanevent(url2, uuid, m1, no_response=True) | |
4544 | ||
3d105cdf JM |
4545 | logger.info("EAP message: M1") |
4546 | data = '\x0202:11:22:00:00:00' | |
4547 | data += '\x10\x22\x00\x01\x04' | |
4548 | data += '\x10\x47\x00\x10' + 16*'\x00' | |
4549 | data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' | |
4550 | data += '\x10\x1a\x00\x10' + 16*'\x00' | |
4551 | data += '\x10\x32\x00\xc0' + 192*'\x00' | |
4552 | data += '\x10\x04\x00\x02\x00\x00' | |
4553 | data += '\x10\x10\x00\x02\x00\x00' | |
4554 | data += '\x10\x0d\x00\x01\x00' | |
4555 | data += '\x10\x08\x00\x02\x00\x00' | |
4556 | data += '\x10\x44\x00\x01\x00' | |
4557 | data += '\x10\x21\x00\x00' | |
4558 | data += '\x10\x23\x00\x00' | |
4559 | data += '\x10\x24\x00\x00' | |
4560 | data += '\x10\x42\x00\x00' | |
4561 | data += '\x10\x54\x00\x08' + 8*'\x00' | |
4562 | data += '\x10\x11\x00\x00' | |
4563 | data += '\x10\x3c\x00\x01\x00' | |
4564 | data += '\x10\x02\x00\x02\x00\x00' | |
4565 | data += '\x10\x12\x00\x02\x00\x00' | |
4566 | data += '\x10\x09\x00\x02\x00\x00' | |
4567 | data += '\x10\x2d\x00\x04\x00\x00\x00\x00' | |
4568 | dev[0].dump_monitor() | |
4569 | with alloc_fail(dev[0], 1, "wps_er_add_sta_data"): | |
4570 | send_wlanevent(url, uuid, data) | |
4571 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=0.1) | |
4572 | if ev is not None: | |
4573 | raise Exception("Unexpected enrollee add event") | |
4574 | send_wlanevent(url, uuid, data) | |
4575 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=2) | |
4576 | if ev is None: | |
4577 | raise Exception("Enrollee add event not seen") | |
4578 | ||
fe67b945 JM |
4579 | with alloc_fail(dev[0], 1, "base64_encode;wps_er_soap_hdr"): |
4580 | send_wlanevent(url, uuid, data) | |
4581 | ||
4582 | with alloc_fail(dev[0], 1, "wpabuf_alloc;wps_er_soap_hdr"): | |
4583 | send_wlanevent(url, uuid, data) | |
4584 | ||
4585 | with alloc_fail(dev[0], 1, "http_client_url_parse;wps_er_sta_send_msg"): | |
4586 | send_wlanevent(url, uuid, data) | |
4587 | ||
4588 | with alloc_fail(dev[0], 1, "http_client_addr;wps_er_sta_send_msg"): | |
4589 | send_wlanevent(url, uuid, data) | |
4590 | ||
4c3ae1c0 JM |
4591 | def test_ap_wps_er_http_proto_no_event_sub_url(dev, apdev): |
4592 | """WPS ER HTTP protocol testing - no eventSubURL""" | |
6aaa661a JM |
4593 | class WPSAPHTTPServer_no_event_sub_url(WPSAPHTTPServer): |
4594 | def handle_upnp_info(self): | |
4595 | self.wfile.write(gen_upnp_info(eventSubURL=None)) | |
4596 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_event_sub_url, | |
4597 | no_event_url=True) | |
4c3ae1c0 JM |
4598 | |
4599 | def test_ap_wps_er_http_proto_event_sub_url_dns(dev, apdev): | |
4600 | """WPS ER HTTP protocol testing - DNS name in eventSubURL""" | |
6aaa661a JM |
4601 | class WPSAPHTTPServer_event_sub_url_dns(WPSAPHTTPServer): |
4602 | def handle_upnp_info(self): | |
4603 | self.wfile.write(gen_upnp_info(eventSubURL='http://example.com/wps_event')) | |
4604 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_event_sub_url_dns, | |
4605 | no_event_url=True) | |
4c3ae1c0 JM |
4606 | |
4607 | def test_ap_wps_er_http_proto_subscribe_oom(dev, apdev): | |
4608 | """WPS ER HTTP protocol testing - subscribe OOM""" | |
4609 | try: | |
4610 | _test_ap_wps_er_http_proto_subscribe_oom(dev, apdev) | |
4611 | finally: | |
4612 | dev[0].request("WPS_ER_STOP") | |
4613 | ||
4614 | def _test_ap_wps_er_http_proto_subscribe_oom(dev, apdev): | |
4615 | tests = [ (1, "http_client_url_parse"), | |
4616 | (1, "wpabuf_alloc;wps_er_subscribe"), | |
4617 | (1, "http_client_addr"), | |
9b35afd6 | 4618 | (1, "eloop_sock_table_add_sock;?eloop_register_sock;http_client_addr"), |
4c3ae1c0 JM |
4619 | (1, "eloop_register_timeout;http_client_addr") ] |
4620 | for count,func in tests: | |
4621 | with alloc_fail(dev[0], count, func): | |
4622 | server,sock = wps_er_start(dev[0], WPSAPHTTPServer) | |
4623 | server.handle_request() | |
4624 | server.handle_request() | |
4625 | wps_er_stop(dev[0], sock, server, on_alloc_fail=True) | |
6aaa661a JM |
4626 | |
4627 | def test_ap_wps_er_http_proto_no_sid(dev, apdev): | |
4628 | """WPS ER HTTP protocol testing - no SID""" | |
4629 | class WPSAPHTTPServer_no_sid(WPSAPHTTPServer): | |
4630 | def handle_wps_event(self): | |
4631 | self.wfile.write(gen_wps_event(sid=None)) | |
4632 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_sid) | |
4633 | ||
4634 | def test_ap_wps_er_http_proto_invalid_sid_no_uuid(dev, apdev): | |
4635 | """WPS ER HTTP protocol testing - invalid SID - no UUID""" | |
4636 | class WPSAPHTTPServer_invalid_sid_no_uuid(WPSAPHTTPServer): | |
4637 | def handle_wps_event(self): | |
4638 | self.wfile.write(gen_wps_event(sid='FOO')) | |
4639 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_sid_no_uuid) | |
4640 | ||
4641 | def test_ap_wps_er_http_proto_invalid_sid_uuid(dev, apdev): | |
4642 | """WPS ER HTTP protocol testing - invalid SID UUID""" | |
4643 | class WPSAPHTTPServer_invalid_sid_uuid(WPSAPHTTPServer): | |
4644 | def handle_wps_event(self): | |
4645 | self.wfile.write(gen_wps_event(sid='uuid:FOO')) | |
4646 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_sid_uuid) | |
4647 | ||
4648 | def test_ap_wps_er_http_proto_subscribe_failing(dev, apdev): | |
4649 | """WPS ER HTTP protocol testing - SUBSCRIBE failing""" | |
4650 | class WPSAPHTTPServer_fail_subscribe(WPSAPHTTPServer): | |
4651 | def handle_wps_event(self): | |
4652 | payload = "" | |
4653 | hdr = 'HTTP/1.1 404 Not Found\r\n' + \ | |
4654 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4655 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4656 | 'Connection: close\r\n' + \ | |
4657 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4658 | 'Timeout: Second-1801\r\n' + \ | |
4659 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4660 | self.wfile.write(hdr + payload) | |
4661 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_fail_subscribe) | |
4662 | ||
4663 | def test_ap_wps_er_http_proto_subscribe_invalid_response(dev, apdev): | |
4664 | """WPS ER HTTP protocol testing - SUBSCRIBE and invalid response""" | |
4665 | class WPSAPHTTPServer_subscribe_invalid_response(WPSAPHTTPServer): | |
4666 | def handle_wps_event(self): | |
4667 | payload = "" | |
4668 | hdr = 'HTTP/1.1 FOO\r\n' + \ | |
4669 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4670 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4671 | 'Connection: close\r\n' + \ | |
4672 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4673 | 'Timeout: Second-1801\r\n' + \ | |
4674 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4675 | self.wfile.write(hdr + payload) | |
4676 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_subscribe_invalid_response) | |
4677 | ||
4678 | def test_ap_wps_er_http_proto_subscribe_invalid_response(dev, apdev): | |
4679 | """WPS ER HTTP protocol testing - SUBSCRIBE and invalid response""" | |
4680 | class WPSAPHTTPServer_invalid_m1(WPSAPHTTPServer): | |
4681 | def handle_wps_control(self): | |
4682 | payload = '''<?xml version="1.0"?> | |
4683 | <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> | |
4684 | <s:Body> | |
4685 | <u:GetDeviceInfoResponse xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1"> | |
4686 | <NewDeviceInfo>Rk9P</NewDeviceInfo> | |
4687 | </u:GetDeviceInfoResponse> | |
4688 | </s:Body> | |
4689 | </s:Envelope> | |
4690 | ''' | |
4691 | self.wfile.write(gen_wps_control(payload_override=payload)) | |
4692 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_m1, no_event_url=True) | |
4693 | ||
4694 | def test_ap_wps_er_http_proto_upnp_info_no_device(dev, apdev): | |
4695 | """WPS ER HTTP protocol testing - No device in UPnP info""" | |
4696 | class WPSAPHTTPServer_no_device(WPSAPHTTPServer): | |
4697 | def handle_upnp_info(self): | |
4698 | payload = '''<?xml version="1.0"?> | |
4699 | <root xmlns="urn:schemas-upnp-org:device-1-0"> | |
4700 | <specVersion> | |
4701 | <major>1</major> | |
4702 | <minor>0</minor> | |
4703 | </specVersion> | |
4704 | </root> | |
4705 | ''' | |
4706 | hdr = 'HTTP/1.1 200 OK\r\n' + \ | |
4707 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4708 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4709 | 'Connection: close\r\n' + \ | |
4710 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4711 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4712 | self.wfile.write(hdr + payload) | |
4713 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_device, no_event_url=True) | |
4714 | ||
4715 | def test_ap_wps_er_http_proto_upnp_info_no_device_type(dev, apdev): | |
4716 | """WPS ER HTTP protocol testing - No deviceType in UPnP info""" | |
4717 | class WPSAPHTTPServer_no_device(WPSAPHTTPServer): | |
4718 | def handle_upnp_info(self): | |
4719 | payload = '''<?xml version="1.0"?> | |
4720 | <root xmlns="urn:schemas-upnp-org:device-1-0"> | |
4721 | <specVersion> | |
4722 | <major>1</major> | |
4723 | <minor>0</minor> | |
4724 | </specVersion> | |
4725 | <device> | |
4726 | </device> | |
4727 | </root> | |
4728 | ''' | |
4729 | hdr = 'HTTP/1.1 200 OK\r\n' + \ | |
4730 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4731 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4732 | 'Connection: close\r\n' + \ | |
4733 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4734 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4735 | self.wfile.write(hdr + payload) | |
4736 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_device, no_event_url=True) | |
4737 | ||
4738 | def test_ap_wps_er_http_proto_upnp_info_invalid_udn_uuid(dev, apdev): | |
4739 | """WPS ER HTTP protocol testing - Invalid UDN UUID""" | |
4740 | class WPSAPHTTPServer_invalid_udn_uuid(WPSAPHTTPServer): | |
4741 | def handle_upnp_info(self): | |
4742 | self.wfile.write(gen_upnp_info(udn='uuid:foo')) | |
4743 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_udn_uuid) | |
4744 | ||
4745 | def test_ap_wps_er_http_proto_no_control_url(dev, apdev): | |
4746 | """WPS ER HTTP protocol testing - no controlURL""" | |
4747 | class WPSAPHTTPServer_no_control_url(WPSAPHTTPServer): | |
4748 | def handle_upnp_info(self): | |
4749 | self.wfile.write(gen_upnp_info(controlURL=None)) | |
4750 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_control_url, | |
4751 | no_event_url=True) | |
4752 | ||
4753 | def test_ap_wps_er_http_proto_control_url_dns(dev, apdev): | |
4754 | """WPS ER HTTP protocol testing - DNS name in controlURL""" | |
4755 | class WPSAPHTTPServer_control_url_dns(WPSAPHTTPServer): | |
4756 | def handle_upnp_info(self): | |
4757 | self.wfile.write(gen_upnp_info(controlURL='http://example.com/wps_control')) | |
4758 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_control_url_dns, | |
4759 | no_event_url=True) | |
24b7f282 JM |
4760 | |
4761 | def test_ap_wps_http_timeout(dev, apdev): | |
4762 | """WPS AP/ER and HTTP timeout""" | |
4763 | try: | |
4764 | _test_ap_wps_http_timeout(dev, apdev) | |
4765 | finally: | |
4766 | dev[0].request("WPS_ER_STOP") | |
4767 | ||
4768 | def _test_ap_wps_http_timeout(dev, apdev): | |
4769 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 4770 | add_ssdp_ap(apdev[0], ap_uuid) |
24b7f282 JM |
4771 | |
4772 | location = ssdp_get_location(ap_uuid) | |
4773 | url = urlparse.urlparse(location) | |
4774 | addr = (url.hostname, url.port) | |
4775 | logger.debug("Open HTTP connection to hostapd, but do not complete request") | |
4776 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4777 | socket.IPPROTO_TCP) | |
4778 | sock.connect(addr) | |
4779 | sock.send("G") | |
4780 | ||
4781 | class DummyServer(SocketServer.StreamRequestHandler): | |
4782 | def handle(self): | |
4783 | logger.debug("DummyServer - start 31 sec wait") | |
4784 | time.sleep(31) | |
4785 | logger.debug("DummyServer - wait done") | |
4786 | ||
4787 | logger.debug("Start WPS ER") | |
4788 | server,sock2 = wps_er_start(dev[0], DummyServer, max_age=40, | |
4789 | wait_m_search=True) | |
4790 | ||
4791 | logger.debug("Start server to accept, but not complete, HTTP connection from WPS ER") | |
4792 | # This will wait for 31 seconds.. | |
4793 | server.handle_request() | |
4794 | ||
4795 | logger.debug("Complete HTTP connection with hostapd (that should have already closed the connection)") | |
4796 | try: | |
4797 | sock.send("ET / HTTP/1.1\r\n\r\n") | |
4798 | res = sock.recv(100) | |
4799 | sock.close() | |
4800 | except: | |
4801 | pass | |
4802 | ||
4803 | def test_ap_wps_er_url_parse(dev, apdev): | |
4804 | """WPS ER and URL parsing special cases""" | |
4805 | try: | |
4806 | _test_ap_wps_er_url_parse(dev, apdev) | |
4807 | finally: | |
4808 | dev[0].request("WPS_ER_STOP") | |
4809 | ||
4810 | def _test_ap_wps_er_url_parse(dev, apdev): | |
4811 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
4812 | sock.settimeout(1) | |
4813 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
4814 | sock.bind(("239.255.255.250", 1900)) | |
4815 | dev[0].request("WPS_ER_START ifname=lo") | |
4816 | (msg,addr) = sock.recvfrom(1000) | |
4817 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
4818 | if "M-SEARCH" not in msg: | |
4819 | raise Exception("Not an M-SEARCH") | |
4820 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1\r\ncache-control:max-age=1\r\n\r\n", addr) | |
4821 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2) | |
4822 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1/:foo\r\ncache-control:max-age=1\r\n\r\n", addr) | |
4823 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2) | |
4824 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://255.255.255.255:0/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr) | |
4825 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2) | |
4826 | ||
4827 | sock.close() | |
4828 | ||
4829 | def test_ap_wps_er_link_update(dev, apdev): | |
4830 | """WPS ER and link update special cases""" | |
4831 | class WPSAPHTTPServer_link_update(WPSAPHTTPServer): | |
4832 | def handle_upnp_info(self): | |
4833 | self.wfile.write(gen_upnp_info(controlURL='/wps_control')) | |
4834 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_link_update) | |
4835 | ||
4836 | class WPSAPHTTPServer_link_update2(WPSAPHTTPServer): | |
4837 | def handle_others(self, data): | |
4838 | if "GET / " in data: | |
4839 | self.wfile.write(gen_upnp_info(controlURL='/wps_control')) | |
4840 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_link_update2, | |
4841 | location_url='http://127.0.0.1:12345') | |
4842 | ||
4843 | def test_ap_wps_er_http_client(dev, apdev): | |
4844 | """WPS ER and HTTP client special cases""" | |
4845 | with alloc_fail(dev[0], 1, "http_link_update"): | |
4846 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer) | |
4847 | ||
4848 | with alloc_fail(dev[0], 1, "wpabuf_alloc;http_client_url"): | |
4849 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer, no_event_url=True) | |
4850 | ||
4851 | with alloc_fail(dev[0], 1, "httpread_create;http_client_tx_ready"): | |
4852 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer, no_event_url=True) | |
4853 | ||
4854 | class WPSAPHTTPServer_req_as_resp(WPSAPHTTPServer): | |
4855 | def handle_upnp_info(self): | |
4856 | self.wfile.write("GET / HTTP/1.1\r\n\r\n") | |
4857 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_req_as_resp, | |
4858 | no_event_url=True) | |
4859 | ||
4860 | def test_ap_wps_init_oom(dev, apdev): | |
4861 | """wps_init OOM cases""" | |
4862 | ssid = "test-wps" | |
4863 | appin = "12345670" | |
4864 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
4865 | "ap_pin": appin } | |
8b8a1864 | 4866 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4867 | pin = dev[0].wps_read_pin() |
4868 | ||
4869 | with alloc_fail(hapd, 1, "wps_init"): | |
4870 | hapd.request("WPS_PIN any " + pin) | |
4871 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4872 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4873 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4874 | if ev is None: | |
4875 | raise Exception("No EAP failure reported") | |
4876 | dev[0].request("WPS_CANCEL") | |
4877 | ||
4878 | with alloc_fail(dev[0], 2, "wps_init"): | |
4879 | hapd.request("WPS_PIN any " + pin) | |
4880 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4881 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4882 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4883 | if ev is None: | |
4884 | raise Exception("No EAP failure reported") | |
4885 | dev[0].request("WPS_CANCEL") | |
4886 | ||
4887 | with alloc_fail(dev[0], 2, "wps_init"): | |
4888 | hapd.request("WPS_PBC") | |
4889 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4890 | dev[0].request("WPS_PBC %s" % (apdev[0]['bssid'])) | |
4891 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4892 | if ev is None: | |
4893 | raise Exception("No EAP failure reported") | |
4894 | dev[0].request("WPS_CANCEL") | |
4895 | ||
4896 | dev[0].dump_monitor() | |
4897 | new_ssid = "wps-new-ssid" | |
4898 | new_passphrase = "1234567890" | |
4899 | with alloc_fail(dev[0], 3, "wps_init"): | |
4900 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", | |
4901 | new_passphrase, no_wait=True) | |
4902 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4903 | if ev is None: | |
4904 | raise Exception("No EAP failure reported") | |
4905 | ||
4906 | dev[0].flush_scan_cache() | |
4907 | ||
9fd6804d | 4908 | @remote_compatible |
24b7f282 JM |
4909 | def test_ap_wps_invalid_assoc_req_elem(dev, apdev): |
4910 | """WPS and invalid IE in Association Request frame""" | |
4911 | ssid = "test-wps" | |
4912 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4913 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4914 | pin = "12345670" |
4915 | hapd.request("WPS_PIN any " + pin) | |
4916 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4917 | try: | |
4918 | dev[0].request("VENDOR_ELEM_ADD 13 dd050050f20410") | |
4919 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4920 | for i in range(5): | |
4921 | ev = hapd.wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10) | |
4922 | if ev and "vendor=14122" in ev: | |
4923 | break | |
4924 | if ev is None or "vendor=14122" not in ev: | |
4925 | raise Exception("EAP-WSC not started") | |
4926 | dev[0].request("WPS_CANCEL") | |
4927 | finally: | |
4928 | dev[0].request("VENDOR_ELEM_REMOVE 13 *") | |
4929 | ||
4930 | def test_ap_wps_pbc_pin_mismatch(dev, apdev): | |
4931 | """WPS PBC/PIN mismatch""" | |
4932 | ssid = "test-wps" | |
4933 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4934 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4935 | hapd.request("SET wps_version_number 0x10") |
4936 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4937 | hapd.request("WPS_PBC") | |
4938 | pin = dev[0].wps_read_pin() | |
4939 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4940 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
4941 | if ev is None: | |
4942 | raise Exception("Scan did not complete") | |
4943 | dev[0].request("WPS_CANCEL") | |
4944 | ||
4945 | hapd.request("WPS_CANCEL") | |
4946 | dev[0].flush_scan_cache() | |
4947 | ||
9fd6804d | 4948 | @remote_compatible |
24b7f282 JM |
4949 | def test_ap_wps_ie_invalid(dev, apdev): |
4950 | """WPS PIN attempt with AP that has invalid WSC IE""" | |
4951 | ssid = "test-wps" | |
4952 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
4953 | "vendor_elements": "dd050050f20410" } | |
8b8a1864 | 4954 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 | 4955 | params = { 'ssid': "another", "vendor_elements": "dd050050f20410" } |
8b8a1864 | 4956 | hostapd.add_ap(apdev[1], params) |
24b7f282 JM |
4957 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
4958 | pin = dev[0].wps_read_pin() | |
4959 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4960 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
4961 | if ev is None: | |
4962 | raise Exception("Scan did not complete") | |
4963 | dev[0].request("WPS_CANCEL") | |
4964 | ||
9fd6804d | 4965 | @remote_compatible |
24b7f282 JM |
4966 | def test_ap_wps_scan_prio_order(dev, apdev): |
4967 | """WPS scan priority ordering""" | |
4968 | ssid = "test-wps" | |
4969 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4970 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 | 4971 | params = { 'ssid': "another", "vendor_elements": "dd050050f20410" } |
8b8a1864 | 4972 | hostapd.add_ap(apdev[1], params) |
24b7f282 JM |
4973 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
4974 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
4975 | pin = dev[0].wps_read_pin() | |
4976 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4977 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
4978 | if ev is None: | |
4979 | raise Exception("Scan did not complete") | |
4980 | dev[0].request("WPS_CANCEL") | |
4981 | ||
4982 | def test_ap_wps_probe_req_ie_oom(dev, apdev): | |
4983 | """WPS ProbeReq IE OOM""" | |
4984 | ssid = "test-wps" | |
4985 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4986 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4987 | pin = dev[0].wps_read_pin() |
4988 | hapd.request("WPS_PIN any " + pin) | |
4989 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4990 | with alloc_fail(dev[0], 1, "wps_build_probe_req_ie"): | |
4991 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4992 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
4993 | if ev is None: | |
4994 | raise Exception("Association not seen") | |
4995 | dev[0].request("WPS_CANCEL") | |
161c8515 | 4996 | dev[0].wait_disconnected() |
24b7f282 JM |
4997 | |
4998 | with alloc_fail(dev[0], 1, "wps_ie_encapsulate"): | |
4999 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5000 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
5001 | if ev is None: | |
5002 | raise Exception("Association not seen") | |
5003 | dev[0].request("WPS_CANCEL") | |
161c8515 JM |
5004 | hapd.disable() |
5005 | dev[0].request("REMOVE_NETWORK all") | |
5006 | dev[0].wait_disconnected() | |
5007 | time.sleep(0.2) | |
5008 | dev[0].flush_scan_cache() | |
24b7f282 JM |
5009 | |
5010 | def test_ap_wps_assoc_req_ie_oom(dev, apdev): | |
5011 | """WPS AssocReq IE OOM""" | |
5012 | ssid = "test-wps" | |
5013 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 5014 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5015 | pin = dev[0].wps_read_pin() |
5016 | hapd.request("WPS_PIN any " + pin) | |
5017 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5018 | with alloc_fail(dev[0], 1, "wps_build_assoc_req_ie"): | |
5019 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5020 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
5021 | if ev is None: | |
5022 | raise Exception("Association not seen") | |
5023 | dev[0].request("WPS_CANCEL") | |
5024 | ||
5025 | def test_ap_wps_assoc_resp_ie_oom(dev, apdev): | |
5026 | """WPS AssocResp IE OOM""" | |
5027 | ssid = "test-wps" | |
5028 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 5029 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5030 | pin = dev[0].wps_read_pin() |
5031 | hapd.request("WPS_PIN any " + pin) | |
5032 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5033 | with alloc_fail(hapd, 1, "wps_build_assoc_resp_ie"): | |
5034 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5035 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
5036 | if ev is None: | |
5037 | raise Exception("Association not seen") | |
5038 | dev[0].request("WPS_CANCEL") | |
5039 | ||
9fd6804d | 5040 | @remote_compatible |
24b7f282 JM |
5041 | def test_ap_wps_bss_info_errors(dev, apdev): |
5042 | """WPS BSS info errors""" | |
5043 | params = { "ssid": "1", | |
5044 | "vendor_elements": "dd0e0050f20410440001ff101100010a" } | |
8b8a1864 | 5045 | hostapd.add_ap(apdev[0], params) |
24b7f282 | 5046 | params = { 'ssid': "2", "vendor_elements": "dd050050f20410" } |
8b8a1864 | 5047 | hostapd.add_ap(apdev[1], params) |
24b7f282 JM |
5048 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
5049 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
5050 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
5051 | logger.info("BSS: " + str(bss)) | |
5052 | if "wps_state" in bss: | |
5053 | raise Exception("Unexpected wps_state in BSS info") | |
5054 | if 'wps_device_name' not in bss: | |
5055 | raise Exception("No wps_device_name in BSS info") | |
5056 | if bss['wps_device_name'] != '_': | |
5057 | raise Exception("Unexpected wps_device_name value") | |
5058 | bss = dev[0].get_bss(apdev[1]['bssid']) | |
5059 | logger.info("BSS: " + str(bss)) | |
5060 | ||
5061 | with alloc_fail(dev[0], 1, "=wps_attr_text"): | |
5062 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
5063 | logger.info("BSS(OOM): " + str(bss)) | |
5064 | ||
5065 | def wps_run_pbc_fail_ap(apdev, dev, hapd): | |
5066 | hapd.request("WPS_PBC") | |
5067 | dev.scan_for_bss(apdev['bssid'], freq="2412") | |
5068 | dev.request("WPS_PBC " + apdev['bssid']) | |
5069 | ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5070 | if ev is None: | |
5071 | raise Exception("No EAP failure reported") | |
5072 | dev.request("WPS_CANCEL") | |
5073 | dev.wait_disconnected() | |
5074 | for i in range(5): | |
5075 | try: | |
5076 | dev.flush_scan_cache() | |
5077 | break | |
5078 | except Exception, e: | |
5079 | if str(e).startswith("Failed to trigger scan"): | |
5080 | # Try again | |
5081 | time.sleep(1) | |
5082 | else: | |
5083 | raise | |
5084 | ||
5085 | def wps_run_pbc_fail(apdev, dev): | |
5086 | hapd = wps_start_ap(apdev) | |
5087 | wps_run_pbc_fail_ap(apdev, dev, hapd) | |
5088 | ||
9fd6804d | 5089 | @remote_compatible |
24b7f282 JM |
5090 | def test_ap_wps_pk_oom(dev, apdev): |
5091 | """WPS and public key OOM""" | |
5092 | with alloc_fail(dev[0], 1, "wps_build_public_key"): | |
5093 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5094 | ||
9fd6804d | 5095 | @remote_compatible |
24b7f282 JM |
5096 | def test_ap_wps_pk_oom_ap(dev, apdev): |
5097 | """WPS and public key OOM on AP""" | |
5098 | hapd = wps_start_ap(apdev[0]) | |
5099 | with alloc_fail(hapd, 1, "wps_build_public_key"): | |
5100 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5101 | ||
9fd6804d | 5102 | @remote_compatible |
24b7f282 JM |
5103 | def test_ap_wps_encr_oom_ap(dev, apdev): |
5104 | """WPS and encrypted settings decryption OOM on AP""" | |
5105 | hapd = wps_start_ap(apdev[0]) | |
5106 | pin = dev[0].wps_read_pin() | |
5107 | hapd.request("WPS_PIN any " + pin) | |
5108 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5109 | with alloc_fail(hapd, 1, "wps_decrypt_encr_settings"): | |
5110 | dev[0].request("WPS_PIN " + apdev[0]['bssid'] + " " + pin) | |
5111 | ev = hapd.wait_event(["WPS-FAIL"], timeout=10) | |
5112 | if ev is None: | |
5113 | raise Exception("No WPS-FAIL reported") | |
5114 | dev[0].request("WPS_CANCEL") | |
5115 | dev[0].wait_disconnected() | |
5116 | ||
9fd6804d | 5117 | @remote_compatible |
24b7f282 JM |
5118 | def test_ap_wps_encr_no_random_ap(dev, apdev): |
5119 | """WPS and no random data available for encryption on AP""" | |
5120 | hapd = wps_start_ap(apdev[0]) | |
5121 | with fail_test(hapd, 1, "os_get_random;wps_build_encr_settings"): | |
5122 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5123 | ||
9fd6804d | 5124 | @remote_compatible |
24b7f282 JM |
5125 | def test_ap_wps_e_hash_no_random_sta(dev, apdev): |
5126 | """WPS and no random data available for e-hash on STA""" | |
5127 | with fail_test(dev[0], 1, "os_get_random;wps_build_e_hash"): | |
5128 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5129 | ||
9fd6804d | 5130 | @remote_compatible |
24b7f282 JM |
5131 | def test_ap_wps_m1_no_random(dev, apdev): |
5132 | """WPS and no random for M1 on STA""" | |
5133 | with fail_test(dev[0], 1, "os_get_random;wps_build_m1"): | |
5134 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5135 | ||
9fd6804d | 5136 | @remote_compatible |
24b7f282 JM |
5137 | def test_ap_wps_m1_oom(dev, apdev): |
5138 | """WPS and OOM for M1 on STA""" | |
5139 | with alloc_fail(dev[0], 1, "wps_build_m1"): | |
5140 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5141 | ||
9fd6804d | 5142 | @remote_compatible |
24b7f282 JM |
5143 | def test_ap_wps_m3_oom(dev, apdev): |
5144 | """WPS and OOM for M3 on STA""" | |
5145 | with alloc_fail(dev[0], 1, "wps_build_m3"): | |
5146 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5147 | ||
9fd6804d | 5148 | @remote_compatible |
24b7f282 JM |
5149 | def test_ap_wps_m5_oom(dev, apdev): |
5150 | """WPS and OOM for M5 on STA""" | |
5151 | hapd = wps_start_ap(apdev[0]) | |
5152 | hapd.request("WPS_PBC") | |
5153 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5154 | for i in range(1, 3): | |
5155 | with alloc_fail(dev[0], i, "wps_build_m5"): | |
5156 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5157 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5158 | if ev is None: | |
5159 | raise Exception("No EAP failure reported") | |
5160 | dev[0].request("WPS_CANCEL") | |
5161 | dev[0].wait_disconnected() | |
5162 | dev[0].flush_scan_cache() | |
5163 | ||
9fd6804d | 5164 | @remote_compatible |
24b7f282 JM |
5165 | def test_ap_wps_m5_no_random(dev, apdev): |
5166 | """WPS and no random for M5 on STA""" | |
5167 | with fail_test(dev[0], 1, | |
5168 | "os_get_random;wps_build_encr_settings;wps_build_m5"): | |
5169 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5170 | ||
9fd6804d | 5171 | @remote_compatible |
24b7f282 JM |
5172 | def test_ap_wps_m7_oom(dev, apdev): |
5173 | """WPS and OOM for M7 on STA""" | |
5174 | hapd = wps_start_ap(apdev[0]) | |
5175 | hapd.request("WPS_PBC") | |
5176 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5177 | for i in range(1, 3): | |
5178 | with alloc_fail(dev[0], i, "wps_build_m7"): | |
5179 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5180 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5181 | if ev is None: | |
5182 | raise Exception("No EAP failure reported") | |
5183 | dev[0].request("WPS_CANCEL") | |
5184 | dev[0].wait_disconnected() | |
5185 | dev[0].flush_scan_cache() | |
5186 | ||
9fd6804d | 5187 | @remote_compatible |
24b7f282 JM |
5188 | def test_ap_wps_m7_no_random(dev, apdev): |
5189 | """WPS and no random for M7 on STA""" | |
5190 | with fail_test(dev[0], 1, | |
5191 | "os_get_random;wps_build_encr_settings;wps_build_m7"): | |
5192 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5193 | ||
9fd6804d | 5194 | @remote_compatible |
24b7f282 JM |
5195 | def test_ap_wps_wsc_done_oom(dev, apdev): |
5196 | """WPS and OOM for WSC_Done on STA""" | |
5197 | with alloc_fail(dev[0], 1, "wps_build_wsc_done"): | |
5198 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5199 | ||
5200 | def test_ap_wps_random_psk_fail(dev, apdev): | |
5201 | """WPS and no random for PSK on AP""" | |
5202 | ssid = "test-wps" | |
5203 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
5204 | appin = "12345670" | |
5205 | try: | |
5206 | os.remove(pskfile) | |
5207 | except: | |
5208 | pass | |
5209 | ||
5210 | try: | |
5211 | with open(pskfile, "w") as f: | |
5212 | f.write("# WPA PSKs\n") | |
5213 | ||
5214 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
5215 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
5216 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
5217 | "wpa_psk_file": pskfile } | |
8b8a1864 | 5218 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5219 | |
5220 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5221 | with fail_test(hapd, 1, "os_get_random;wps_build_cred_network_key"): | |
5222 | dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin) | |
5223 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5224 | if ev is None: | |
5225 | raise Exception("No EAP failure reported") | |
5226 | dev[0].request("WPS_CANCEL") | |
5227 | dev[0].wait_disconnected() | |
5228 | ||
5229 | with fail_test(hapd, 1, "os_get_random;wps_build_cred"): | |
5230 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5231 | ||
5232 | with alloc_fail(hapd, 1, "wps_build_cred"): | |
5233 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5234 | ||
5235 | with alloc_fail(hapd, 2, "wps_build_cred"): | |
5236 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5237 | finally: | |
5238 | os.remove(pskfile) | |
5239 | ||
5240 | def wps_ext_eap_identity_req(dev, hapd, bssid): | |
5241 | logger.debug("EAP-Identity/Request") | |
5242 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5243 | if ev is None: | |
5244 | raise Exception("Timeout on EAPOL-TX from hostapd") | |
5245 | res = dev.request("EAPOL_RX " + bssid + " " + ev.split(' ')[2]) | |
5246 | if "OK" not in res: | |
5247 | raise Exception("EAPOL_RX to wpa_supplicant failed") | |
5248 | ||
5249 | def wps_ext_eap_identity_resp(hapd, dev, addr): | |
5250 | ev = dev.wait_event(["EAPOL-TX"], timeout=10) | |
5251 | if ev is None: | |
5252 | raise Exception("Timeout on EAPOL-TX from wpa_supplicant") | |
5253 | res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2]) | |
5254 | if "OK" not in res: | |
5255 | raise Exception("EAPOL_RX to hostapd failed") | |
5256 | ||
5257 | def wps_ext_eap_wsc(dst, src, src_addr, msg): | |
5258 | logger.debug(msg) | |
5259 | ev = src.wait_event(["EAPOL-TX"], timeout=10) | |
5260 | if ev is None: | |
5261 | raise Exception("Timeout on EAPOL-TX") | |
5262 | res = dst.request("EAPOL_RX " + src_addr + " " + ev.split(' ')[2]) | |
5263 | if "OK" not in res: | |
5264 | raise Exception("EAPOL_RX failed") | |
5265 | ||
7511ead0 | 5266 | def wps_start_ext(apdev, dev, pbc=False, pin=None): |
24b7f282 JM |
5267 | addr = dev.own_addr() |
5268 | bssid = apdev['bssid'] | |
5269 | ssid = "test-wps-conf" | |
5270 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
5271 | "wpa_passphrase": "12345678", "wpa": "2", | |
5272 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"} | |
afc26df2 | 5273 | hapd = hostapd.add_ap(apdev, params) |
24b7f282 | 5274 | |
d1883671 JM |
5275 | if pbc: |
5276 | hapd.request("WPS_PBC") | |
5277 | else: | |
7511ead0 JM |
5278 | if pin is None: |
5279 | pin = dev.wps_read_pin() | |
d1883671 | 5280 | hapd.request("WPS_PIN any " + pin) |
24b7f282 JM |
5281 | dev.scan_for_bss(bssid, freq="2412") |
5282 | hapd.request("SET ext_eapol_frame_io 1") | |
5283 | dev.request("SET ext_eapol_frame_io 1") | |
5284 | ||
d1883671 JM |
5285 | if pbc: |
5286 | dev.request("WPS_PBC " + bssid) | |
5287 | else: | |
5288 | dev.request("WPS_PIN " + bssid + " " + pin) | |
24b7f282 JM |
5289 | return addr,bssid,hapd |
5290 | ||
5291 | def wps_auth_corrupt(dst, src, addr): | |
5292 | ev = src.wait_event(["EAPOL-TX"], timeout=10) | |
5293 | if ev is None: | |
5294 | raise Exception("Timeout on EAPOL-TX") | |
5295 | src.request("SET ext_eapol_frame_io 0") | |
5296 | dst.request("SET ext_eapol_frame_io 0") | |
5297 | msg = ev.split(' ')[2] | |
5298 | if msg[-24:-16] != '10050008': | |
5299 | raise Exception("Could not find Authenticator attribute") | |
5300 | # Corrupt Authenticator value | |
5301 | msg = msg[:-1] + '%x' % ((int(msg[-1], 16) + 1) % 16) | |
5302 | res = dst.request("EAPOL_RX " + addr + " " + msg) | |
5303 | if "OK" not in res: | |
5304 | raise Exception("EAPOL_RX failed") | |
5305 | ||
5306 | def wps_fail_finish(hapd, dev, fail_str): | |
5307 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
5308 | if ev is None: | |
5309 | raise Exception("WPS-FAIL not indicated") | |
5310 | if fail_str not in ev: | |
5311 | raise Exception("Unexpected WPS-FAIL value: " + ev) | |
5312 | dev.request("WPS_CANCEL") | |
5313 | dev.wait_disconnected() | |
5314 | ||
5315 | def wps_auth_corrupt_from_ap(dev, hapd, bssid, fail_str): | |
5316 | wps_auth_corrupt(dev, hapd, bssid) | |
5317 | wps_fail_finish(hapd, dev, fail_str) | |
5318 | ||
5319 | def wps_auth_corrupt_to_ap(dev, hapd, addr, fail_str): | |
5320 | wps_auth_corrupt(hapd, dev, addr) | |
5321 | wps_fail_finish(hapd, dev, fail_str) | |
5322 | ||
5323 | def test_ap_wps_authenticator_mismatch_m2(dev, apdev): | |
5324 | """WPS and Authenticator attribute mismatch in M2""" | |
5325 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5326 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5327 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5328 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5329 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5330 | logger.debug("M2") | |
5331 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=5") | |
5332 | ||
5333 | def test_ap_wps_authenticator_mismatch_m3(dev, apdev): | |
5334 | """WPS and Authenticator attribute mismatch in M3""" | |
5335 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5336 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5337 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5338 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5339 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5340 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5341 | logger.debug("M3") | |
5342 | wps_auth_corrupt_to_ap(dev[0], hapd, addr, "msg=7") | |
5343 | ||
5344 | def test_ap_wps_authenticator_mismatch_m4(dev, apdev): | |
5345 | """WPS and Authenticator attribute mismatch in M4""" | |
5346 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5347 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5348 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5349 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5350 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5351 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5352 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5353 | logger.debug("M4") | |
5354 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=8") | |
5355 | ||
5356 | def test_ap_wps_authenticator_mismatch_m5(dev, apdev): | |
5357 | """WPS and Authenticator attribute mismatch in M5""" | |
5358 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5359 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5360 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5361 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5362 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5363 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5364 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5365 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5366 | logger.debug("M5") | |
5367 | wps_auth_corrupt_to_ap(dev[0], hapd, addr, "msg=9") | |
5368 | ||
5369 | def test_ap_wps_authenticator_mismatch_m6(dev, apdev): | |
5370 | """WPS and Authenticator attribute mismatch in M6""" | |
5371 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5372 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5373 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5374 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5375 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5376 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5377 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5378 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5379 | wps_ext_eap_wsc(hapd, dev[0], addr, "M5") | |
5380 | logger.debug("M6") | |
5381 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=10") | |
5382 | ||
5383 | def test_ap_wps_authenticator_mismatch_m7(dev, apdev): | |
5384 | """WPS and Authenticator attribute mismatch in M7""" | |
5385 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5386 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5387 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5388 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5389 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5390 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5391 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5392 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5393 | wps_ext_eap_wsc(hapd, dev[0], addr, "M5") | |
5394 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M6") | |
5395 | logger.debug("M7") | |
5396 | wps_auth_corrupt_to_ap(dev[0], hapd, addr, "msg=11") | |
5397 | ||
5398 | def test_ap_wps_authenticator_mismatch_m8(dev, apdev): | |
5399 | """WPS and Authenticator attribute mismatch in M8""" | |
5400 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5401 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5402 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5403 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5404 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5405 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5406 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5407 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5408 | wps_ext_eap_wsc(hapd, dev[0], addr, "M5") | |
5409 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M6") | |
5410 | wps_ext_eap_wsc(hapd, dev[0], addr, "M7") | |
5411 | logger.debug("M8") | |
5412 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=12") | |
5413 | ||
5414 | def test_ap_wps_authenticator_missing_m2(dev, apdev): | |
5415 | """WPS and Authenticator attribute missing from M2""" | |
5416 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5417 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5418 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5419 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5420 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5421 | logger.debug("M2") | |
5422 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5423 | if ev is None: | |
5424 | raise Exception("Timeout on EAPOL-TX") | |
5425 | hapd.request("SET ext_eapol_frame_io 0") | |
5426 | dev[0].request("SET ext_eapol_frame_io 0") | |
5427 | msg = ev.split(' ')[2] | |
5428 | if msg[-24:-16] != '10050008': | |
5429 | raise Exception("Could not find Authenticator attribute") | |
5430 | # Remove Authenticator value | |
5431 | msg = msg[:-24] | |
5432 | mlen = "%04x" % (int(msg[4:8], 16) - 12) | |
5433 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:] | |
5434 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5435 | if "OK" not in res: | |
5436 | raise Exception("EAPOL_RX failed") | |
5437 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5438 | ||
d1883671 JM |
5439 | def test_ap_wps_m2_dev_passwd_id_p2p(dev, apdev): |
5440 | """WPS and M2 with different Device Password ID (P2P)""" | |
5441 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5442 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5443 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5444 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5445 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5446 | logger.debug("M2") | |
5447 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5448 | if ev is None: | |
5449 | raise Exception("Timeout on EAPOL-TX") | |
5450 | hapd.request("SET ext_eapol_frame_io 0") | |
5451 | dev[0].request("SET ext_eapol_frame_io 0") | |
5452 | msg = ev.split(' ')[2] | |
5453 | if msg[722:730] != '10120002': | |
5454 | raise Exception("Could not find Device Password ID attribute") | |
5455 | # Replace Device Password ID value. This will fail Authenticator check, but | |
5456 | # allows the code path in wps_process_dev_pw_id() to be checked from debug | |
5457 | # log. | |
5458 | msg = msg[0:730] + "0005" + msg[734:] | |
5459 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5460 | if "OK" not in res: | |
5461 | raise Exception("EAPOL_RX failed") | |
5462 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5463 | ||
5464 | def test_ap_wps_m2_dev_passwd_id_change_pin_to_pbc(dev, apdev): | |
5465 | """WPS and M2 with different Device Password ID (PIN to PBC)""" | |
5466 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5467 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5468 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5469 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5470 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5471 | logger.debug("M2") | |
5472 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5473 | if ev is None: | |
5474 | raise Exception("Timeout on EAPOL-TX") | |
5475 | hapd.request("SET ext_eapol_frame_io 0") | |
5476 | dev[0].request("SET ext_eapol_frame_io 0") | |
5477 | msg = ev.split(' ')[2] | |
5478 | if msg[722:730] != '10120002': | |
5479 | raise Exception("Could not find Device Password ID attribute") | |
5480 | # Replace Device Password ID value (PIN --> PBC). This will be rejected. | |
5481 | msg = msg[0:730] + "0004" + msg[734:] | |
5482 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5483 | if "OK" not in res: | |
5484 | raise Exception("EAPOL_RX failed") | |
5485 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5486 | ||
5487 | def test_ap_wps_m2_dev_passwd_id_change_pbc_to_pin(dev, apdev): | |
5488 | """WPS and M2 with different Device Password ID (PBC to PIN)""" | |
5489 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5490 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5491 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5492 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5493 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5494 | logger.debug("M2") | |
5495 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5496 | if ev is None: | |
5497 | raise Exception("Timeout on EAPOL-TX") | |
5498 | hapd.request("SET ext_eapol_frame_io 0") | |
5499 | dev[0].request("SET ext_eapol_frame_io 0") | |
5500 | msg = ev.split(' ')[2] | |
5501 | if msg[722:730] != '10120002': | |
5502 | raise Exception("Could not find Device Password ID attribute") | |
5503 | # Replace Device Password ID value. This will fail Authenticator check, but | |
5504 | # allows the code path in wps_process_dev_pw_id() to be checked from debug | |
5505 | # log. | |
5506 | msg = msg[0:730] + "0000" + msg[734:] | |
5507 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5508 | if "OK" not in res: | |
5509 | raise Exception("EAPOL_RX failed") | |
5510 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5511 | dev[0].flush_scan_cache() | |
5512 | ||
5513 | def test_ap_wps_m2_missing_dev_passwd_id(dev, apdev): | |
5514 | """WPS and M2 without Device Password ID""" | |
5515 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5516 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5517 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5518 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5519 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5520 | logger.debug("M2") | |
5521 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5522 | if ev is None: | |
5523 | raise Exception("Timeout on EAPOL-TX") | |
5524 | hapd.request("SET ext_eapol_frame_io 0") | |
5525 | dev[0].request("SET ext_eapol_frame_io 0") | |
5526 | msg = ev.split(' ')[2] | |
5527 | if msg[722:730] != '10120002': | |
5528 | raise Exception("Could not find Device Password ID attribute") | |
5529 | # Remove Device Password ID value. This will fail Authenticator check, but | |
5530 | # allows the code path in wps_process_dev_pw_id() to be checked from debug | |
5531 | # log. | |
5532 | mlen = "%04x" % (int(msg[4:8], 16) - 6) | |
5533 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:722] + msg[734:] | |
5534 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5535 | if "OK" not in res: | |
5536 | raise Exception("EAPOL_RX failed") | |
5537 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5538 | ||
5539 | def test_ap_wps_m2_missing_registrar_nonce(dev, apdev): | |
5540 | """WPS and M2 without Registrar Nonce""" | |
5541 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5542 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5543 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5544 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5545 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5546 | logger.debug("M2") | |
5547 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5548 | if ev is None: | |
5549 | raise Exception("Timeout on EAPOL-TX") | |
5550 | hapd.request("SET ext_eapol_frame_io 0") | |
5551 | dev[0].request("SET ext_eapol_frame_io 0") | |
5552 | msg = ev.split(' ')[2] | |
5553 | if msg[96:104] != '10390010': | |
5554 | raise Exception("Could not find Registrar Nonce attribute") | |
5555 | # Remove Registrar Nonce. This will fail Authenticator check, but | |
5556 | # allows the code path in wps_process_registrar_nonce() to be checked from | |
5557 | # the debug log. | |
5558 | mlen = "%04x" % (int(msg[4:8], 16) - 20) | |
5559 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:96] + msg[136:] | |
5560 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5561 | if "OK" not in res: | |
5562 | raise Exception("EAPOL_RX failed") | |
5563 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5564 | if ev is None: | |
5565 | raise Exception("Disconnect event not seen") | |
5566 | dev[0].request("WPS_CANCEL") | |
5567 | dev[0].flush_scan_cache() | |
5568 | ||
5569 | def test_ap_wps_m2_missing_enrollee_nonce(dev, apdev): | |
5570 | """WPS and M2 without Enrollee Nonce""" | |
5571 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5572 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5573 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5574 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5575 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5576 | logger.debug("M2") | |
5577 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5578 | if ev is None: | |
5579 | raise Exception("Timeout on EAPOL-TX") | |
5580 | hapd.request("SET ext_eapol_frame_io 0") | |
5581 | dev[0].request("SET ext_eapol_frame_io 0") | |
5582 | msg = ev.split(' ')[2] | |
5583 | if msg[56:64] != '101a0010': | |
5584 | raise Exception("Could not find enrollee Nonce attribute") | |
5585 | # Remove Enrollee Nonce. This will fail Authenticator check, but | |
5586 | # allows the code path in wps_process_enrollee_nonce() to be checked from | |
5587 | # the debug log. | |
5588 | mlen = "%04x" % (int(msg[4:8], 16) - 20) | |
5589 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:56] + msg[96:] | |
5590 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5591 | if "OK" not in res: | |
5592 | raise Exception("EAPOL_RX failed") | |
5593 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5594 | if ev is None: | |
5595 | raise Exception("Disconnect event not seen") | |
5596 | dev[0].request("WPS_CANCEL") | |
5597 | dev[0].flush_scan_cache() | |
5598 | ||
5599 | def test_ap_wps_m2_missing_uuid_r(dev, apdev): | |
5600 | """WPS and M2 without UUID-R""" | |
5601 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5602 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5603 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5604 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5605 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5606 | logger.debug("M2") | |
5607 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5608 | if ev is None: | |
5609 | raise Exception("Timeout on EAPOL-TX") | |
5610 | hapd.request("SET ext_eapol_frame_io 0") | |
5611 | dev[0].request("SET ext_eapol_frame_io 0") | |
5612 | msg = ev.split(' ')[2] | |
5613 | if msg[136:144] != '10480010': | |
5614 | raise Exception("Could not find enrollee Nonce attribute") | |
5615 | # Remove UUID-R. This will fail Authenticator check, but allows the code | |
5616 | # path in wps_process_uuid_r() to be checked from the debug log. | |
5617 | mlen = "%04x" % (int(msg[4:8], 16) - 20) | |
5618 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:136] + msg[176:] | |
5619 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5620 | if "OK" not in res: | |
5621 | raise Exception("EAPOL_RX failed") | |
5622 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5623 | if ev is None: | |
5624 | raise Exception("Disconnect event not seen") | |
5625 | dev[0].request("WPS_CANCEL") | |
5626 | dev[0].flush_scan_cache() | |
5627 | ||
5628 | def test_ap_wps_m2_invalid(dev, apdev): | |
5629 | """WPS and M2 parsing failure""" | |
5630 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5631 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5632 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5633 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5634 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5635 | logger.debug("M2") | |
5636 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5637 | if ev is None: | |
5638 | raise Exception("Timeout on EAPOL-TX") | |
5639 | hapd.request("SET ext_eapol_frame_io 0") | |
5640 | dev[0].request("SET ext_eapol_frame_io 0") | |
5641 | msg = ev.split(' ')[2] | |
5642 | if msg[136:144] != '10480010': | |
5643 | raise Exception("Could not find enrollee Nonce attribute") | |
5644 | # Remove UUID-R. This will fail Authenticator check, but allows the code | |
5645 | # path in wps_process_uuid_r() to be checked from the debug log. | |
5646 | mlen = "%04x" % (int(msg[4:8], 16) - 1) | |
5647 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:-2] | |
5648 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5649 | if "OK" not in res: | |
5650 | raise Exception("EAPOL_RX failed") | |
5651 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5652 | if ev is None: | |
5653 | raise Exception("Disconnect event not seen") | |
5654 | dev[0].request("WPS_CANCEL") | |
5655 | dev[0].flush_scan_cache() | |
5656 | ||
5657 | def test_ap_wps_m2_missing_msg_type(dev, apdev): | |
5658 | """WPS and M2 without Message Type""" | |
5659 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5660 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5661 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5662 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5663 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5664 | logger.debug("M2") | |
5665 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5666 | if ev is None: | |
5667 | raise Exception("Timeout on EAPOL-TX") | |
5668 | hapd.request("SET ext_eapol_frame_io 0") | |
5669 | dev[0].request("SET ext_eapol_frame_io 0") | |
5670 | msg = ev.split(' ')[2] | |
5671 | if msg[46:54] != '10220001': | |
5672 | raise Exception("Could not find Message Type attribute") | |
5673 | # Remove Message Type. This will fail Authenticator check, but allows the | |
5674 | # code path in wps_process_wsc_msg() to be checked from the debug log. | |
5675 | mlen = "%04x" % (int(msg[4:8], 16) - 5) | |
5676 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:46] + msg[56:] | |
5677 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5678 | if "OK" not in res: | |
5679 | raise Exception("EAPOL_RX failed") | |
5680 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5681 | if ev is None: | |
5682 | raise Exception("Disconnect event not seen") | |
5683 | dev[0].request("WPS_CANCEL") | |
5684 | dev[0].flush_scan_cache() | |
5685 | ||
5686 | def test_ap_wps_m2_unknown_msg_type(dev, apdev): | |
5687 | """WPS and M2 but unknown Message Type""" | |
5688 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5689 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5690 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5691 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5692 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5693 | logger.debug("M2") | |
5694 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5695 | if ev is None: | |
5696 | raise Exception("Timeout on EAPOL-TX") | |
5697 | hapd.request("SET ext_eapol_frame_io 0") | |
5698 | dev[0].request("SET ext_eapol_frame_io 0") | |
5699 | msg = ev.split(' ')[2] | |
5700 | if msg[46:54] != '10220001': | |
5701 | raise Exception("Could not find Message Type attribute") | |
5702 | # Replace Message Type value. This will be rejected. | |
5703 | msg = msg[0:54] + "00" + msg[56:] | |
5704 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5705 | if "OK" not in res: | |
5706 | raise Exception("EAPOL_RX failed") | |
5707 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5708 | if ev is None: | |
5709 | raise Exception("Disconnect event not seen") | |
5710 | dev[0].request("WPS_CANCEL") | |
5711 | dev[0].flush_scan_cache() | |
5712 | ||
5713 | def test_ap_wps_m2_unknown_opcode(dev, apdev): | |
5714 | """WPS and M2 but unknown opcode""" | |
5715 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5716 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5717 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5718 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5719 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5720 | logger.debug("M2") | |
5721 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5722 | if ev is None: | |
5723 | raise Exception("Timeout on EAPOL-TX") | |
5724 | hapd.request("SET ext_eapol_frame_io 0") | |
5725 | dev[0].request("SET ext_eapol_frame_io 0") | |
5726 | msg = ev.split(' ')[2] | |
5727 | # Replace opcode. This will be discarded in EAP-WSC processing. | |
5728 | msg = msg[0:32] + "00" + msg[34:] | |
5729 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5730 | if "OK" not in res: | |
5731 | raise Exception("EAPOL_RX failed") | |
5732 | dev[0].request("WPS_CANCEL") | |
5733 | dev[0].wait_disconnected() | |
5734 | dev[0].flush_scan_cache() | |
5735 | ||
5736 | def test_ap_wps_m2_unknown_opcode2(dev, apdev): | |
5737 | """WPS and M2 but unknown opcode (WSC_Start)""" | |
5738 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5739 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5740 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5741 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5742 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5743 | logger.debug("M2") | |
5744 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5745 | if ev is None: | |
5746 | raise Exception("Timeout on EAPOL-TX") | |
5747 | hapd.request("SET ext_eapol_frame_io 0") | |
5748 | dev[0].request("SET ext_eapol_frame_io 0") | |
5749 | msg = ev.split(' ')[2] | |
5750 | # Replace opcode. This will be discarded in EAP-WSC processing. | |
5751 | msg = msg[0:32] + "01" + msg[34:] | |
5752 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5753 | if "OK" not in res: | |
5754 | raise Exception("EAPOL_RX failed") | |
5755 | dev[0].request("WPS_CANCEL") | |
5756 | dev[0].wait_disconnected() | |
5757 | dev[0].flush_scan_cache() | |
5758 | ||
5759 | def test_ap_wps_m2_unknown_opcode3(dev, apdev): | |
5760 | """WPS and M2 but unknown opcode (WSC_Done)""" | |
5761 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5762 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5763 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5764 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5765 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5766 | logger.debug("M2") | |
5767 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5768 | if ev is None: | |
5769 | raise Exception("Timeout on EAPOL-TX") | |
5770 | hapd.request("SET ext_eapol_frame_io 0") | |
5771 | dev[0].request("SET ext_eapol_frame_io 0") | |
5772 | msg = ev.split(' ')[2] | |
5773 | # Replace opcode. This will be discarded in WPS Enrollee processing. | |
5774 | msg = msg[0:32] + "05" + msg[34:] | |
5775 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5776 | if "OK" not in res: | |
5777 | raise Exception("EAPOL_RX failed") | |
5778 | dev[0].request("WPS_CANCEL") | |
5779 | dev[0].wait_disconnected() | |
5780 | dev[0].flush_scan_cache() | |
5781 | ||
5782 | def wps_m2_but_other(dev, apdev, title, msgtype): | |
5783 | addr,bssid,hapd = wps_start_ext(apdev, dev) | |
5784 | wps_ext_eap_identity_req(dev, hapd, bssid) | |
5785 | wps_ext_eap_identity_resp(hapd, dev, addr) | |
5786 | wps_ext_eap_wsc(dev, hapd, bssid, "EAP-WSC/Start") | |
5787 | wps_ext_eap_wsc(hapd, dev, addr, "M1") | |
5788 | logger.debug(title) | |
5789 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5790 | if ev is None: | |
5791 | raise Exception("Timeout on EAPOL-TX") | |
5792 | hapd.request("SET ext_eapol_frame_io 0") | |
5793 | dev.request("SET ext_eapol_frame_io 0") | |
5794 | msg = ev.split(' ')[2] | |
5795 | if msg[46:54] != '10220001': | |
5796 | raise Exception("Could not find Message Type attribute") | |
5797 | # Replace Message Type value. This will be rejected. | |
5798 | msg = msg[0:54] + msgtype + msg[56:] | |
5799 | res = dev.request("EAPOL_RX " + bssid + " " + msg) | |
5800 | if "OK" not in res: | |
5801 | raise Exception("EAPOL_RX failed") | |
5802 | ev = dev.wait_event(["WPS-FAIL"], timeout=5) | |
5803 | if ev is None: | |
5804 | raise Exception("WPS-FAIL event not seen") | |
5805 | dev.request("WPS_CANCEL") | |
5806 | dev.wait_disconnected() | |
5807 | ||
5808 | def wps_m4_but_other(dev, apdev, title, msgtype): | |
5809 | addr,bssid,hapd = wps_start_ext(apdev, dev) | |
5810 | wps_ext_eap_identity_req(dev, hapd, bssid) | |
5811 | wps_ext_eap_identity_resp(hapd, dev, addr) | |
5812 | wps_ext_eap_wsc(dev, hapd, bssid, "EAP-WSC/Start") | |
5813 | wps_ext_eap_wsc(hapd, dev, addr, "M1") | |
5814 | wps_ext_eap_wsc(dev, hapd, bssid, "M2") | |
5815 | wps_ext_eap_wsc(hapd, dev, addr, "M3") | |
5816 | logger.debug(title) | |
5817 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5818 | if ev is None: | |
5819 | raise Exception("Timeout on EAPOL-TX") | |
5820 | hapd.request("SET ext_eapol_frame_io 0") | |
5821 | dev.request("SET ext_eapol_frame_io 0") | |
5822 | msg = ev.split(' ')[2] | |
5823 | if msg[46:54] != '10220001': | |
5824 | raise Exception("Could not find Message Type attribute") | |
5825 | # Replace Message Type value. This will be rejected. | |
5826 | msg = msg[0:54] + msgtype + msg[56:] | |
5827 | res = dev.request("EAPOL_RX " + bssid + " " + msg) | |
5828 | if "OK" not in res: | |
5829 | raise Exception("EAPOL_RX failed") | |
5830 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
5831 | if ev is None: | |
5832 | raise Exception("WPS-FAIL event not seen") | |
5833 | dev.request("WPS_CANCEL") | |
5834 | dev.wait_disconnected() | |
5835 | ||
5836 | def test_ap_wps_m2_msg_type_m4(dev, apdev): | |
5837 | """WPS and M2 but Message Type M4""" | |
5838 | wps_m2_but_other(dev[0], apdev[0], "M2/M4", "08") | |
5839 | ||
5840 | def test_ap_wps_m2_msg_type_m6(dev, apdev): | |
5841 | """WPS and M2 but Message Type M6""" | |
5842 | wps_m2_but_other(dev[0], apdev[0], "M2/M6", "0a") | |
5843 | ||
5844 | def test_ap_wps_m2_msg_type_m8(dev, apdev): | |
5845 | """WPS and M2 but Message Type M8""" | |
5846 | wps_m2_but_other(dev[0], apdev[0], "M2/M8", "0c") | |
5847 | ||
5848 | def test_ap_wps_m4_msg_type_m2(dev, apdev): | |
5849 | """WPS and M4 but Message Type M2""" | |
5850 | wps_m4_but_other(dev[0], apdev[0], "M4/M2", "05") | |
5851 | ||
5852 | def test_ap_wps_m4_msg_type_m2d(dev, apdev): | |
5853 | """WPS and M4 but Message Type M2D""" | |
5854 | wps_m4_but_other(dev[0], apdev[0], "M4/M2D", "06") | |
5855 | ||
9fd6804d | 5856 | @remote_compatible |
24b7f282 JM |
5857 | def test_ap_wps_config_methods(dev, apdev): |
5858 | """WPS configuration method parsing""" | |
5859 | ssid = "test-wps-conf" | |
5860 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
5861 | "wpa_passphrase": "12345678", "wpa": "2", | |
5862 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
5863 | "config_methods": "ethernet display ext_nfc_token int_nfc_token physical_display physical_push_button" } | |
8b8a1864 | 5864 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5865 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
5866 | "wpa_passphrase": "12345678", "wpa": "2", | |
5867 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
5868 | "config_methods": "display push_button" } | |
8b8a1864 | 5869 | hapd2 = hostapd.add_ap(apdev[1], params) |
476daa05 JM |
5870 | |
5871 | def test_ap_wps_set_selected_registrar_proto(dev, apdev): | |
5872 | """WPS UPnP SetSelectedRegistrar protocol testing""" | |
5873 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 5874 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
476daa05 JM |
5875 | |
5876 | location = ssdp_get_location(ap_uuid) | |
5877 | urls = upnp_get_urls(location) | |
5878 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
5879 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
5880 | url = urlparse.urlparse(location) | |
5881 | conn = httplib.HTTPConnection(url.netloc) | |
5882 | ||
5883 | class WPSERHTTPServer(SocketServer.StreamRequestHandler): | |
5884 | def handle(self): | |
5885 | data = self.rfile.readline().strip() | |
5886 | logger.debug(data) | |
5887 | self.wfile.write(gen_wps_event()) | |
5888 | ||
5889 | server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) | |
5890 | server.timeout = 1 | |
5891 | ||
5892 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
5893 | "NT": "upnp:event", | |
5894 | "timeout": "Second-1234" } | |
5895 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
5896 | resp = conn.getresponse() | |
5897 | if resp.status != 200: | |
5898 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
5899 | sid = resp.getheader("sid") | |
5900 | logger.debug("Subscription SID " + sid) | |
5901 | server.handle_request() | |
5902 | ||
5903 | tests = [ (500, "10"), | |
5904 | (200, "104a000110" + "1041000101" + "101200020000" + | |
5905 | "105300023148" + | |
5906 | "1049002c00372a0001200124111111111111222222222222333333333333444444444444555555555555666666666666" + | |
5907 | "10480010362db47ba53a519188fb5458b986b2e4"), | |
5908 | (200, "104a000110" + "1041000100" + "101200020000" + | |
5909 | "105300020000"), | |
5910 | (200, "104a000110" + "1041000100"), | |
5911 | (200, "104a000110") ] | |
5912 | for status,test in tests: | |
5913 | tlvs = binascii.unhexlify(test) | |
5914 | newmsg = base64.b64encode(tlvs) | |
5915 | msg = '<?xml version="1.0"?>\n' | |
5916 | msg += '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' | |
5917 | msg += '<s:Body>' | |
5918 | msg += '<u:SetSelectedRegistrar xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1">' | |
5919 | msg += '<NewMessage>' | |
5920 | msg += newmsg | |
5921 | msg += "</NewMessage></u:SetSelectedRegistrar></s:Body></s:Envelope>" | |
5922 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
5923 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % "SetSelectedRegistrar" | |
5924 | conn.request("POST", ctrlurl.path, msg, headers) | |
5925 | resp = conn.getresponse() | |
5926 | if resp.status != status: | |
5927 | raise Exception("Unexpected HTTP response: %d (expected %d)" % (resp.status, status)) | |
96038a5f JM |
5928 | |
5929 | def test_ap_wps_adv_oom(dev, apdev): | |
5930 | """WPS AP and advertisement OOM""" | |
5931 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 5932 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
96038a5f JM |
5933 | |
5934 | with alloc_fail(hapd, 1, "=msearchreply_state_machine_start"): | |
5935 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1", | |
5936 | no_recv=True) | |
5937 | time.sleep(0.2) | |
5938 | ||
5939 | with alloc_fail(hapd, 1, "eloop_register_timeout;msearchreply_state_machine_start"): | |
5940 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1", | |
5941 | no_recv=True) | |
5942 | time.sleep(0.2) | |
5943 | ||
5944 | with alloc_fail(hapd, 1, | |
5945 | "next_advertisement;advertisement_state_machine_stop"): | |
5946 | hapd.disable() | |
5947 | ||
5948 | with alloc_fail(hapd, 1, "ssdp_listener_start"): | |
5949 | if "FAIL" not in hapd.request("ENABLE"): | |
5950 | raise Exception("ENABLE succeeded during OOM") | |
926404a6 JM |
5951 | |
5952 | def test_wps_config_methods(dev): | |
5953 | """WPS config method update""" | |
5954 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
5955 | wpas.interface_add("wlan5") | |
5956 | if "OK" not in wpas.request("SET config_methods display label"): | |
5957 | raise Exception("Failed to set config_methods") | |
5958 | if wpas.request("GET config_methods").strip() != "display label": | |
5959 | raise Exception("config_methods were not updated") | |
5960 | if "OK" not in wpas.request("SET config_methods "): | |
5961 | raise Exception("Failed to clear config_methods") | |
5962 | if wpas.request("GET config_methods").strip() != "": | |
5963 | raise Exception("config_methods were not cleared") | |
7511ead0 JM |
5964 | |
5965 | WPS_VENDOR_ID_WFA = 14122 | |
5966 | WPS_VENDOR_TYPE = 1 | |
5967 | ||
5968 | # EAP-WSC Op-Code values | |
5969 | WSC_Start = 0x01 | |
5970 | WSC_ACK = 0x02 | |
5971 | WSC_NACK = 0x03 | |
5972 | WSC_MSG = 0x04 | |
5973 | WSC_Done = 0x05 | |
5974 | WSC_FRAG_ACK = 0x06 | |
5975 | ||
5976 | ATTR_AP_CHANNEL = 0x1001 | |
5977 | ATTR_ASSOC_STATE = 0x1002 | |
5978 | ATTR_AUTH_TYPE = 0x1003 | |
5979 | ATTR_AUTH_TYPE_FLAGS = 0x1004 | |
5980 | ATTR_AUTHENTICATOR = 0x1005 | |
5981 | ATTR_CONFIG_METHODS = 0x1008 | |
5982 | ATTR_CONFIG_ERROR = 0x1009 | |
5983 | ATTR_CONFIRM_URL4 = 0x100a | |
5984 | ATTR_CONFIRM_URL6 = 0x100b | |
5985 | ATTR_CONN_TYPE = 0x100c | |
5986 | ATTR_CONN_TYPE_FLAGS = 0x100d | |
5987 | ATTR_CRED = 0x100e | |
5988 | ATTR_ENCR_TYPE = 0x100f | |
5989 | ATTR_ENCR_TYPE_FLAGS = 0x1010 | |
5990 | ATTR_DEV_NAME = 0x1011 | |
5991 | ATTR_DEV_PASSWORD_ID = 0x1012 | |
5992 | ATTR_E_HASH1 = 0x1014 | |
5993 | ATTR_E_HASH2 = 0x1015 | |
5994 | ATTR_E_SNONCE1 = 0x1016 | |
5995 | ATTR_E_SNONCE2 = 0x1017 | |
5996 | ATTR_ENCR_SETTINGS = 0x1018 | |
5997 | ATTR_ENROLLEE_NONCE = 0x101a | |
5998 | ATTR_FEATURE_ID = 0x101b | |
5999 | ATTR_IDENTITY = 0x101c | |
6000 | ATTR_IDENTITY_PROOF = 0x101d | |
6001 | ATTR_KEY_WRAP_AUTH = 0x101e | |
6002 | ATTR_KEY_ID = 0x101f | |
6003 | ATTR_MAC_ADDR = 0x1020 | |
6004 | ATTR_MANUFACTURER = 0x1021 | |
6005 | ATTR_MSG_TYPE = 0x1022 | |
6006 | ATTR_MODEL_NAME = 0x1023 | |
6007 | ATTR_MODEL_NUMBER = 0x1024 | |
6008 | ATTR_NETWORK_INDEX = 0x1026 | |
6009 | ATTR_NETWORK_KEY = 0x1027 | |
6010 | ATTR_NETWORK_KEY_INDEX = 0x1028 | |
6011 | ATTR_NEW_DEVICE_NAME = 0x1029 | |
6012 | ATTR_NEW_PASSWORD = 0x102a | |
6013 | ATTR_OOB_DEVICE_PASSWORD = 0x102c | |
6014 | ATTR_OS_VERSION = 0x102d | |
6015 | ATTR_POWER_LEVEL = 0x102f | |
6016 | ATTR_PSK_CURRENT = 0x1030 | |
6017 | ATTR_PSK_MAX = 0x1031 | |
6018 | ATTR_PUBLIC_KEY = 0x1032 | |
6019 | ATTR_RADIO_ENABLE = 0x1033 | |
6020 | ATTR_REBOOT = 0x1034 | |
6021 | ATTR_REGISTRAR_CURRENT = 0x1035 | |
6022 | ATTR_REGISTRAR_ESTABLISHED = 0x1036 | |
6023 | ATTR_REGISTRAR_LIST = 0x1037 | |
6024 | ATTR_REGISTRAR_MAX = 0x1038 | |
6025 | ATTR_REGISTRAR_NONCE = 0x1039 | |
6026 | ATTR_REQUEST_TYPE = 0x103a | |
6027 | ATTR_RESPONSE_TYPE = 0x103b | |
6028 | ATTR_RF_BANDS = 0x103c | |
6029 | ATTR_R_HASH1 = 0x103d | |
6030 | ATTR_R_HASH2 = 0x103e | |
6031 | ATTR_R_SNONCE1 = 0x103f | |
6032 | ATTR_R_SNONCE2 = 0x1040 | |
6033 | ATTR_SELECTED_REGISTRAR = 0x1041 | |
6034 | ATTR_SERIAL_NUMBER = 0x1042 | |
6035 | ATTR_WPS_STATE = 0x1044 | |
6036 | ATTR_SSID = 0x1045 | |
6037 | ATTR_TOTAL_NETWORKS = 0x1046 | |
6038 | ATTR_UUID_E = 0x1047 | |
6039 | ATTR_UUID_R = 0x1048 | |
6040 | ATTR_VENDOR_EXT = 0x1049 | |
6041 | ATTR_VERSION = 0x104a | |
6042 | ATTR_X509_CERT_REQ = 0x104b | |
6043 | ATTR_X509_CERT = 0x104c | |
6044 | ATTR_EAP_IDENTITY = 0x104d | |
6045 | ATTR_MSG_COUNTER = 0x104e | |
6046 | ATTR_PUBKEY_HASH = 0x104f | |
6047 | ATTR_REKEY_KEY = 0x1050 | |
6048 | ATTR_KEY_LIFETIME = 0x1051 | |
6049 | ATTR_PERMITTED_CFG_METHODS = 0x1052 | |
6050 | ATTR_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053 | |
6051 | ATTR_PRIMARY_DEV_TYPE = 0x1054 | |
6052 | ATTR_SECONDARY_DEV_TYPE_LIST = 0x1055 | |
6053 | ATTR_PORTABLE_DEV = 0x1056 | |
6054 | ATTR_AP_SETUP_LOCKED = 0x1057 | |
6055 | ATTR_APPLICATION_EXT = 0x1058 | |
6056 | ATTR_EAP_TYPE = 0x1059 | |
6057 | ATTR_IV = 0x1060 | |
6058 | ATTR_KEY_PROVIDED_AUTO = 0x1061 | |
6059 | ATTR_802_1X_ENABLED = 0x1062 | |
6060 | ATTR_APPSESSIONKEY = 0x1063 | |
6061 | ATTR_WEPTRANSMITKEY = 0x1064 | |
6062 | ATTR_REQUESTED_DEV_TYPE = 0x106a | |
6063 | ||
6064 | # Message Type | |
6065 | WPS_Beacon = 0x01 | |
6066 | WPS_ProbeRequest = 0x02 | |
6067 | WPS_ProbeResponse = 0x03 | |
6068 | WPS_M1 = 0x04 | |
6069 | WPS_M2 = 0x05 | |
6070 | WPS_M2D = 0x06 | |
6071 | WPS_M3 = 0x07 | |
6072 | WPS_M4 = 0x08 | |
6073 | WPS_M5 = 0x09 | |
6074 | WPS_M6 = 0x0a | |
6075 | WPS_M7 = 0x0b | |
6076 | WPS_M8 = 0x0c | |
6077 | WPS_WSC_ACK = 0x0d | |
6078 | WPS_WSC_NACK = 0x0e | |
6079 | WPS_WSC_DONE = 0x0f | |
6080 | ||
6081 | def get_wsc_msg(dev): | |
6082 | ev = dev.wait_event(["EAPOL-TX"], timeout=10) | |
6083 | if ev is None: | |
6084 | raise Exception("Timeout on EAPOL-TX") | |
6085 | data = binascii.unhexlify(ev.split(' ')[2]) | |
6086 | msg = {} | |
6087 | ||
6088 | # Parse EAPOL header | |
6089 | if len(data) < 4: | |
6090 | raise Exception("No room for EAPOL header") | |
6091 | version,type,length = struct.unpack('>BBH', data[0:4]) | |
6092 | msg['eapol_version'] = version | |
6093 | msg['eapol_type'] = type | |
6094 | msg['eapol_length'] = length | |
6095 | data = data[4:] | |
6096 | if length != len(data): | |
6097 | raise Exception("EAPOL header length mismatch (%d != %d)" % (length, len(data))) | |
6098 | if type != 0: | |
6099 | raise Exception("Unexpected EAPOL header type: %d" % type) | |
6100 | ||
6101 | # Parse EAP header | |
6102 | if len(data) < 4: | |
6103 | raise Exception("No room for EAP header") | |
6104 | code,identifier,length = struct.unpack('>BBH', data[0:4]) | |
6105 | msg['eap_code'] = code | |
6106 | msg['eap_identifier'] = identifier | |
6107 | msg['eap_length'] = length | |
6108 | data = data[4:] | |
6109 | if msg['eapol_length'] != msg['eap_length']: | |
6110 | raise Exception("EAP header length mismatch (%d != %d)" % (msg['eapol_length'], length)) | |
6111 | ||
6112 | # Parse EAP expanded header | |
6113 | if len(data) < 1: | |
6114 | raise Exception("No EAP type included") | |
6115 | msg['eap_type'], = struct.unpack('B', data[0]) | |
6116 | data = data[1:] | |
6117 | ||
6118 | if msg['eap_type'] == 254: | |
6119 | if len(data) < 3 + 4: | |
6120 | raise Exception("Truncated EAP expanded header") | |
6121 | msg['eap_vendor_id'], msg['eap_vendor_type'] = struct.unpack('>LL', '\0' + data[0:7]) | |
6122 | data = data[7:] | |
6123 | else: | |
6124 | raise Exception("Unexpected EAP type") | |
6125 | ||
6126 | if msg['eap_vendor_id'] != WPS_VENDOR_ID_WFA: | |
6127 | raise Exception("Unexpected Vendor-Id") | |
6128 | if msg['eap_vendor_type'] != WPS_VENDOR_TYPE: | |
6129 | raise Exception("Unexpected Vendor-Type") | |
6130 | ||
6131 | # Parse EAP-WSC header | |
6132 | if len(data) < 2: | |
6133 | raise Exception("Truncated EAP-WSC header") | |
6134 | msg['wsc_opcode'], msg['wsc_flags'] = struct.unpack('BB', data[0:2]) | |
6135 | data = data[2:] | |
6136 | ||
6137 | # Parse WSC attributes | |
6138 | msg['raw_attrs'] = data | |
6139 | attrs = {} | |
6140 | while len(data) > 0: | |
6141 | if len(data) < 4: | |
6142 | raise Exception("Truncated attribute header") | |
6143 | attr,length = struct.unpack('>HH', data[0:4]) | |
6144 | data = data[4:] | |
6145 | if length > len(data): | |
6146 | raise Exception("Truncated attribute 0x%04x" % attr) | |
6147 | attrs[attr] = data[0:length] | |
6148 | data = data[length:] | |
6149 | msg['wsc_attrs'] = attrs | |
6150 | ||
6151 | if ATTR_MSG_TYPE in attrs: | |
6152 | msg['wsc_msg_type'], = struct.unpack('B', attrs[ATTR_MSG_TYPE]) | |
6153 | ||
6154 | return msg | |
6155 | ||
6156 | def recv_wsc_msg(dev, opcode, msg_type): | |
6157 | msg = get_wsc_msg(dev) | |
6158 | if msg['wsc_opcode'] != opcode or msg['wsc_msg_type'] != msg_type: | |
6159 | raise Exception("Unexpected Op-Code/MsgType") | |
6160 | return msg, msg['wsc_attrs'], msg['raw_attrs'] | |
6161 | ||
6162 | def build_wsc_attr(attr, payload): | |
6163 | return struct.pack('>HH', attr, len(payload)) + payload | |
6164 | ||
6165 | def build_attr_msg_type(msg_type): | |
6166 | return build_wsc_attr(ATTR_MSG_TYPE, struct.pack('B', msg_type)) | |
6167 | ||
6168 | def build_eap_wsc(eap_code, eap_id, payload, opcode=WSC_MSG): | |
6169 | length = 4 + 8 + 2 + len(payload) | |
6170 | # EAPOL header | |
6171 | msg = struct.pack('>BBH', 2, 0, length) | |
6172 | # EAP header | |
6173 | msg += struct.pack('>BBH', eap_code, eap_id, length) | |
6174 | # EAP expanded header for EAP-WSC | |
6175 | msg += struct.pack('B', 254) | |
6176 | msg += struct.pack('>L', WPS_VENDOR_ID_WFA)[1:4] | |
6177 | msg += struct.pack('>L', WPS_VENDOR_TYPE) | |
6178 | # EAP-WSC header | |
6179 | msg += struct.pack('BB', opcode, 0) | |
6180 | # WSC attributes | |
6181 | msg += payload | |
6182 | return msg | |
6183 | ||
6184 | def build_eap_success(eap_id): | |
6185 | length = 4 | |
6186 | # EAPOL header | |
6187 | msg = struct.pack('>BBH', 2, 0, length) | |
6188 | # EAP header | |
6189 | msg += struct.pack('>BBH', 3, eap_id, length) | |
6190 | return msg | |
6191 | ||
6192 | def build_eap_failure(eap_id): | |
6193 | length = 4 | |
6194 | # EAPOL header | |
6195 | msg = struct.pack('>BBH', 2, 0, length) | |
6196 | # EAP header | |
6197 | msg += struct.pack('>BBH', 4, eap_id, length) | |
6198 | return msg | |
6199 | ||
6200 | def send_wsc_msg(dev, src, msg): | |
6201 | res = dev.request("EAPOL_RX " + src + " " + binascii.hexlify(msg)) | |
6202 | if "OK" not in res: | |
6203 | raise Exception("EAPOL_RX failed") | |
6204 | ||
6205 | group_5_prime = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF | |
6206 | group_5_generator = 2 | |
6207 | ||
6208 | def wsc_kdf(key, label, bits): | |
6209 | result = '' | |
6210 | i = 1 | |
6211 | while len(result) * 8 < bits: | |
6212 | data = struct.pack('>L', i) + label + struct.pack('>L', bits) | |
6213 | m = hmac.new(key, data, hashlib.sha256) | |
6214 | result += m.digest() | |
6215 | i += 1 | |
6216 | return result[0:bits / 8] | |
6217 | ||
6218 | def wsc_keys(kdk): | |
6219 | keys = wsc_kdf(kdk, "Wi-Fi Easy and Secure Key Derivation", 640) | |
6220 | authkey = keys[0:32] | |
6221 | keywrapkey = keys[32:48] | |
6222 | emsk = keys[48:80] | |
6223 | return authkey,keywrapkey,emsk | |
6224 | ||
6225 | def wsc_dev_pw_half_psk(authkey, dev_pw): | |
6226 | m = hmac.new(authkey, dev_pw, hashlib.sha256) | |
6227 | return m.digest()[0:16] | |
6228 | ||
6229 | def wsc_dev_pw_psk(authkey, dev_pw): | |
6230 | dev_pw_1 = dev_pw[0:len(dev_pw) / 2] | |
6231 | dev_pw_2 = dev_pw[len(dev_pw) / 2:] | |
6232 | psk1 = wsc_dev_pw_half_psk(authkey, dev_pw_1) | |
6233 | psk2 = wsc_dev_pw_half_psk(authkey, dev_pw_2) | |
6234 | return psk1,psk2 | |
6235 | ||
6236 | def build_attr_authenticator(authkey, prev_msg, curr_msg): | |
6237 | m = hmac.new(authkey, prev_msg + curr_msg, hashlib.sha256) | |
6238 | auth = m.digest()[0:8] | |
6239 | return build_wsc_attr(ATTR_AUTHENTICATOR, auth) | |
6240 | ||
6241 | def build_attr_encr_settings(authkey, keywrapkey, data): | |
6242 | m = hmac.new(authkey, data, hashlib.sha256) | |
6243 | kwa = m.digest()[0:8] | |
6244 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
6245 | iv = 16*'\x99' | |
6246 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6247 | pad_len = 16 - len(data) % 16 | |
6248 | ps = pad_len * struct.pack('B', pad_len) | |
6249 | data += ps | |
6250 | wrapped = aes.encrypt(data) | |
6251 | return build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6252 | ||
6253 | def decrypt_attr_encr_settings(authkey, keywrapkey, data): | |
6254 | if len(data) < 32 or len(data) % 16 != 0: | |
6255 | raise Exception("Unexpected Encrypted Settings length: %d" % len(data)) | |
6256 | iv = data[0:16] | |
6257 | encr = data[16:] | |
6258 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6259 | decrypted = aes.decrypt(encr) | |
6260 | pad_len, = struct.unpack('B', decrypted[-1]) | |
6261 | if pad_len > len(decrypted): | |
6262 | raise Exception("Invalid padding in Encrypted Settings") | |
6263 | for i in range(-pad_len, -1): | |
6264 | if decrypted[i] != decrypted[-1]: | |
6265 | raise Exception("Invalid PS value in Encrypted Settings") | |
6266 | ||
6267 | decrypted = decrypted[0:len(decrypted) - pad_len] | |
6268 | if len(decrypted) < 12: | |
6269 | raise Exception("Truncated Encrypted Settings plaintext") | |
6270 | kwa = decrypted[-12:] | |
6271 | attr,length = struct.unpack(">HH", kwa[0:4]) | |
6272 | if attr != ATTR_KEY_WRAP_AUTH or length != 8: | |
6273 | raise Exception("Invalid KWA header") | |
6274 | kwa = kwa[4:] | |
6275 | decrypted = decrypted[0:len(decrypted) - 12] | |
6276 | ||
6277 | m = hmac.new(authkey, decrypted, hashlib.sha256) | |
6278 | calc_kwa = m.digest()[0:8] | |
6279 | if kwa != calc_kwa: | |
6280 | raise Exception("KWA mismatch") | |
6281 | ||
6282 | return decrypted | |
6283 | ||
6284 | def zeropad_str(val, pad_len): | |
6285 | while len(val) < pad_len * 2: | |
6286 | val = '0' + val | |
6287 | return val | |
6288 | ||
6289 | def wsc_dh_init(): | |
6290 | # For now, use a hardcoded private key. In theory, this is supposed to be | |
6291 | # randomly selected. | |
6292 | own_private = 0x123456789 | |
6293 | own_public = pow(group_5_generator, own_private, group_5_prime) | |
6294 | pk = binascii.unhexlify(zeropad_str(format(own_public, '02x'), 192)) | |
6295 | return own_private, pk | |
6296 | ||
6297 | def wsc_dh_kdf(peer_pk, own_private, mac_addr, e_nonce, r_nonce): | |
6298 | peer_public = long(binascii.hexlify(peer_pk), 16) | |
6299 | if peer_public < 2 or peer_public >= group_5_prime: | |
6300 | raise Exception("Invalid peer public key") | |
6301 | if pow(peer_public, (group_5_prime - 1) / 2, group_5_prime) != 1: | |
6302 | raise Exception("Unexpected Legendre symbol for peer public key") | |
6303 | ||
6304 | shared_secret = pow(peer_public, own_private, group_5_prime) | |
6305 | ss = zeropad_str(format(shared_secret, "02x"), 192) | |
6306 | logger.debug("DH shared secret: " + ss) | |
6307 | ||
6308 | dhkey = hashlib.sha256(binascii.unhexlify(ss)).digest() | |
6309 | logger.debug("DHKey: " + binascii.hexlify(dhkey)) | |
6310 | ||
6311 | m = hmac.new(dhkey, e_nonce + mac_addr + r_nonce, hashlib.sha256) | |
6312 | kdk = m.digest() | |
6313 | logger.debug("KDK: " + binascii.hexlify(kdk)) | |
6314 | authkey,keywrapkey,emsk = wsc_keys(kdk) | |
6315 | logger.debug("AuthKey: " + binascii.hexlify(authkey)) | |
6316 | logger.debug("KeyWrapKey: " + binascii.hexlify(keywrapkey)) | |
6317 | logger.debug("EMSK: " + binascii.hexlify(emsk)) | |
6318 | return authkey,keywrapkey | |
6319 | ||
6320 | def wsc_dev_pw_hash(authkey, dev_pw, e_pk, r_pk): | |
6321 | psk1,psk2 = wsc_dev_pw_psk(authkey, dev_pw) | |
6322 | logger.debug("PSK1: " + binascii.hexlify(psk1)) | |
6323 | logger.debug("PSK2: " + binascii.hexlify(psk2)) | |
6324 | ||
6325 | # Note: Secret values are supposed to be random, but hardcoded values are | |
6326 | # fine for testing. | |
6327 | s1 = 16*'\x77' | |
6328 | m = hmac.new(authkey, s1 + psk1 + e_pk + r_pk, hashlib.sha256) | |
6329 | hash1 = m.digest() | |
6330 | logger.debug("Hash1: " + binascii.hexlify(hash1)) | |
6331 | ||
6332 | s2 = 16*'\x88' | |
6333 | m = hmac.new(authkey, s2 + psk2 + e_pk + r_pk, hashlib.sha256) | |
6334 | hash2 = m.digest() | |
6335 | logger.debug("Hash2: " + binascii.hexlify(hash2)) | |
6336 | return s1,s2,hash1,hash2 | |
6337 | ||
6338 | def build_m1(eap_id, uuid_e, mac_addr, e_nonce, e_pk, | |
6339 | manufacturer='', model_name='', config_methods='\x00\x00'): | |
6340 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6341 | attrs += build_attr_msg_type(WPS_M1) | |
6342 | attrs += build_wsc_attr(ATTR_UUID_E, uuid_e) | |
6343 | attrs += build_wsc_attr(ATTR_MAC_ADDR, mac_addr) | |
6344 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6345 | attrs += build_wsc_attr(ATTR_PUBLIC_KEY, e_pk) | |
6346 | attrs += build_wsc_attr(ATTR_AUTH_TYPE_FLAGS, '\x00\x00') | |
6347 | attrs += build_wsc_attr(ATTR_ENCR_TYPE_FLAGS, '\x00\x00') | |
6348 | attrs += build_wsc_attr(ATTR_CONN_TYPE_FLAGS, '\x00') | |
6349 | attrs += build_wsc_attr(ATTR_CONFIG_METHODS, config_methods) | |
6350 | attrs += build_wsc_attr(ATTR_WPS_STATE, '\x00') | |
6351 | attrs += build_wsc_attr(ATTR_MANUFACTURER, manufacturer) | |
6352 | attrs += build_wsc_attr(ATTR_MODEL_NAME, model_name) | |
6353 | attrs += build_wsc_attr(ATTR_MODEL_NUMBER, '') | |
6354 | attrs += build_wsc_attr(ATTR_SERIAL_NUMBER, '') | |
6355 | attrs += build_wsc_attr(ATTR_PRIMARY_DEV_TYPE, 8*'\x00') | |
6356 | attrs += build_wsc_attr(ATTR_DEV_NAME, '') | |
6357 | attrs += build_wsc_attr(ATTR_RF_BANDS, '\x00') | |
6358 | attrs += build_wsc_attr(ATTR_ASSOC_STATE, '\x00\x00') | |
6359 | attrs += build_wsc_attr(ATTR_DEV_PASSWORD_ID, '\x00\x00') | |
6360 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, '\x00\x00') | |
6361 | attrs += build_wsc_attr(ATTR_OS_VERSION, '\x00\x00\x00\x00') | |
6362 | m1 = build_eap_wsc(2, eap_id, attrs) | |
6363 | return m1, attrs | |
6364 | ||
6365 | def build_m2(authkey, m1, eap_id, e_nonce, r_nonce, uuid_r, r_pk, | |
6366 | dev_pw_id='\x00\x00', eap_code=1): | |
6367 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6368 | attrs += build_attr_msg_type(WPS_M2) | |
6369 | if e_nonce: | |
6370 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6371 | if r_nonce: | |
6372 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6373 | attrs += build_wsc_attr(ATTR_UUID_R, uuid_r) | |
6374 | if r_pk: | |
6375 | attrs += build_wsc_attr(ATTR_PUBLIC_KEY, r_pk) | |
6376 | attrs += build_wsc_attr(ATTR_AUTH_TYPE_FLAGS, '\x00\x00') | |
6377 | attrs += build_wsc_attr(ATTR_ENCR_TYPE_FLAGS, '\x00\x00') | |
6378 | attrs += build_wsc_attr(ATTR_CONN_TYPE_FLAGS, '\x00') | |
6379 | attrs += build_wsc_attr(ATTR_CONFIG_METHODS, '\x00\x00') | |
6380 | attrs += build_wsc_attr(ATTR_MANUFACTURER, '') | |
6381 | attrs += build_wsc_attr(ATTR_MODEL_NAME, '') | |
6382 | attrs += build_wsc_attr(ATTR_MODEL_NUMBER, '') | |
6383 | attrs += build_wsc_attr(ATTR_SERIAL_NUMBER, '') | |
6384 | attrs += build_wsc_attr(ATTR_PRIMARY_DEV_TYPE, 8*'\x00') | |
6385 | attrs += build_wsc_attr(ATTR_DEV_NAME, '') | |
6386 | attrs += build_wsc_attr(ATTR_RF_BANDS, '\x00') | |
6387 | attrs += build_wsc_attr(ATTR_ASSOC_STATE, '\x00\x00') | |
6388 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, '\x00\x00') | |
6389 | attrs += build_wsc_attr(ATTR_DEV_PASSWORD_ID, dev_pw_id) | |
6390 | attrs += build_wsc_attr(ATTR_OS_VERSION, '\x00\x00\x00\x00') | |
6391 | attrs += build_attr_authenticator(authkey, m1, attrs) | |
6392 | m2 = build_eap_wsc(eap_code, eap_id, attrs) | |
6393 | return m2, attrs | |
6394 | ||
6395 | def build_m2d(m1, eap_id, e_nonce, r_nonce, uuid_r, dev_pw_id=None, eap_code=1): | |
6396 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6397 | attrs += build_attr_msg_type(WPS_M2D) | |
6398 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6399 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6400 | attrs += build_wsc_attr(ATTR_UUID_R, uuid_r) | |
6401 | attrs += build_wsc_attr(ATTR_AUTH_TYPE_FLAGS, '\x00\x00') | |
6402 | attrs += build_wsc_attr(ATTR_ENCR_TYPE_FLAGS, '\x00\x00') | |
6403 | attrs += build_wsc_attr(ATTR_CONN_TYPE_FLAGS, '\x00') | |
6404 | attrs += build_wsc_attr(ATTR_CONFIG_METHODS, '\x00\x00') | |
6405 | attrs += build_wsc_attr(ATTR_MANUFACTURER, '') | |
6406 | attrs += build_wsc_attr(ATTR_MODEL_NAME, '') | |
6407 | #attrs += build_wsc_attr(ATTR_MODEL_NUMBER, '') | |
6408 | attrs += build_wsc_attr(ATTR_SERIAL_NUMBER, '') | |
6409 | attrs += build_wsc_attr(ATTR_PRIMARY_DEV_TYPE, 8*'\x00') | |
6410 | attrs += build_wsc_attr(ATTR_DEV_NAME, '') | |
6411 | attrs += build_wsc_attr(ATTR_RF_BANDS, '\x00') | |
6412 | attrs += build_wsc_attr(ATTR_ASSOC_STATE, '\x00\x00') | |
6413 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, '\x00\x00') | |
6414 | attrs += build_wsc_attr(ATTR_OS_VERSION, '\x00\x00\x00\x00') | |
6415 | if dev_pw_id: | |
6416 | attrs += build_wsc_attr(ATTR_DEV_PASSWORD_ID, dev_pw_id) | |
6417 | m2d = build_eap_wsc(eap_code, eap_id, attrs) | |
6418 | return m2d, attrs | |
6419 | ||
6420 | def build_ack(eap_id, e_nonce, r_nonce, msg_type=WPS_WSC_ACK, eap_code=1): | |
6421 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6422 | if msg_type is not None: | |
6423 | attrs += build_attr_msg_type(msg_type) | |
6424 | if e_nonce: | |
6425 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6426 | if r_nonce: | |
6427 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6428 | msg = build_eap_wsc(eap_code, eap_id, attrs, opcode=WSC_ACK) | |
6429 | return msg, attrs | |
6430 | ||
6431 | def build_nack(eap_id, e_nonce, r_nonce, config_error='\x00\x00', | |
6432 | msg_type=WPS_WSC_NACK, eap_code=1): | |
6433 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6434 | if msg_type is not None: | |
6435 | attrs += build_attr_msg_type(msg_type) | |
6436 | if e_nonce: | |
6437 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6438 | if r_nonce: | |
6439 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6440 | if config_error: | |
6441 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, config_error) | |
6442 | msg = build_eap_wsc(eap_code, eap_id, attrs, opcode=WSC_NACK) | |
6443 | return msg, attrs | |
6444 | ||
6445 | def test_wps_ext(dev, apdev): | |
6446 | """WPS against external implementation""" | |
6447 | pin = "12345670" | |
6448 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6449 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6450 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6451 | ||
6452 | logger.debug("Receive WSC/Start from AP") | |
6453 | msg = get_wsc_msg(hapd) | |
6454 | if msg['wsc_opcode'] != WSC_Start: | |
6455 | raise Exception("Unexpected Op-Code for WSC/Start") | |
6456 | wsc_start_id = msg['eap_identifier'] | |
6457 | ||
6458 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6459 | uuid_e = 16*'\x11' | |
6460 | e_nonce = 16*'\x22' | |
6461 | own_private, e_pk = wsc_dh_init() | |
6462 | ||
6463 | logger.debug("Send M1 to AP") | |
6464 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
6465 | e_nonce, e_pk) | |
6466 | send_wsc_msg(hapd, addr, m1) | |
6467 | ||
6468 | logger.debug("Receive M2 from AP") | |
6469 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
6470 | ||
6471 | authkey,keywrapkey = wsc_dh_kdf(m2_attrs[ATTR_PUBLIC_KEY], own_private, | |
6472 | mac_addr, e_nonce, | |
6473 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6474 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, | |
6475 | m2_attrs[ATTR_PUBLIC_KEY]) | |
6476 | ||
6477 | logger.debug("Send M3 to AP") | |
6478 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6479 | attrs += build_attr_msg_type(WPS_M3) | |
6480 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6481 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6482 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
6483 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
6484 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
6485 | raw_m3_attrs = attrs | |
6486 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
6487 | send_wsc_msg(hapd, addr, m3) | |
6488 | ||
6489 | logger.debug("Receive M4 from AP") | |
6490 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
6491 | ||
6492 | logger.debug("Send M5 to AP") | |
6493 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6494 | attrs += build_attr_msg_type(WPS_M5) | |
6495 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6496 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6497 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
6498 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6499 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
6500 | raw_m5_attrs = attrs | |
6501 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
6502 | send_wsc_msg(hapd, addr, m5) | |
6503 | ||
6504 | logger.debug("Receive M6 from AP") | |
6505 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
6506 | ||
6507 | logger.debug("Send M7 to AP") | |
6508 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6509 | attrs += build_attr_msg_type(WPS_M7) | |
6510 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6511 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6512 | data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
6513 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6514 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
6515 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
6516 | raw_m7_attrs = attrs | |
6517 | send_wsc_msg(hapd, addr, m7) | |
6518 | ||
6519 | logger.debug("Receive M8 from AP") | |
6520 | msg, m8_attrs, raw_m8_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M8) | |
6521 | m8_cred = decrypt_attr_encr_settings(authkey, keywrapkey, | |
6522 | m8_attrs[ATTR_ENCR_SETTINGS]) | |
6523 | logger.debug("M8 Credential: " + binascii.hexlify(m8_cred)) | |
6524 | ||
6525 | logger.debug("Prepare WSC_Done") | |
6526 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6527 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
6528 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6529 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6530 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6531 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
6532 | # Do not send WSC_Done yet to allow exchangw with STA complete before the | |
6533 | # AP disconnects. | |
6534 | ||
6535 | uuid_r = 16*'\x33' | |
6536 | r_nonce = 16*'\x44' | |
6537 | ||
6538 | eap_id = wsc_start_id | |
6539 | logger.debug("Send WSC/Start to STA") | |
6540 | wsc_start = build_eap_wsc(1, eap_id, "", opcode=WSC_Start) | |
6541 | send_wsc_msg(dev[0], bssid, wsc_start) | |
6542 | eap_id = (eap_id + 1) % 256 | |
6543 | ||
6544 | logger.debug("Receive M1 from STA") | |
6545 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6546 | ||
6547 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6548 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6549 | r_nonce) | |
6550 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6551 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6552 | ||
6553 | logger.debug("Send M2 to STA") | |
6554 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6555 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6556 | r_nonce, uuid_r, e_pk) | |
6557 | send_wsc_msg(dev[0], bssid, m2) | |
6558 | eap_id = (eap_id + 1) % 256 | |
6559 | ||
6560 | logger.debug("Receive M3 from STA") | |
6561 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
6562 | ||
6563 | logger.debug("Send M4 to STA") | |
6564 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6565 | attrs += build_attr_msg_type(WPS_M4) | |
6566 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6567 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
6568 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
6569 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6570 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6571 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
6572 | raw_m4_attrs = attrs | |
6573 | m4 = build_eap_wsc(1, eap_id, attrs) | |
6574 | send_wsc_msg(dev[0], bssid, m4) | |
6575 | eap_id = (eap_id + 1) % 256 | |
6576 | ||
6577 | logger.debug("Receive M5 from STA") | |
6578 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
6579 | ||
6580 | logger.debug("Send M6 to STA") | |
6581 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6582 | attrs += build_attr_msg_type(WPS_M6) | |
6583 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6584 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6585 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
6586 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6587 | attrs += build_attr_authenticator(authkey, raw_m5_attrs, attrs) | |
6588 | raw_m6_attrs = attrs | |
6589 | m6 = build_eap_wsc(1, eap_id, attrs) | |
6590 | send_wsc_msg(dev[0], bssid, m6) | |
6591 | eap_id = (eap_id + 1) % 256 | |
6592 | ||
6593 | logger.debug("Receive M7 from STA") | |
6594 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M7) | |
6595 | ||
6596 | logger.debug("Send M8 to STA") | |
6597 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6598 | attrs += build_attr_msg_type(WPS_M8) | |
6599 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6600 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6601 | attrs += build_attr_encr_settings(authkey, keywrapkey, m8_cred) | |
6602 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
6603 | raw_m8_attrs = attrs | |
6604 | m8 = build_eap_wsc(1, eap_id, attrs) | |
6605 | send_wsc_msg(dev[0], bssid, m8) | |
6606 | eap_id = (eap_id + 1) % 256 | |
6607 | ||
6608 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=5) | |
6609 | if ev is None: | |
6610 | raise Exception("wpa_supplicant did not report credential") | |
6611 | ||
6612 | logger.debug("Receive WSC_Done from STA") | |
6613 | msg = get_wsc_msg(dev[0]) | |
6614 | if msg['wsc_opcode'] != WSC_Done or msg['wsc_msg_type'] != WPS_WSC_DONE: | |
6615 | raise Exception("Unexpected Op-Code/MsgType for WSC_Done") | |
6616 | ||
6617 | logger.debug("Send WSC_Done to AP") | |
6618 | hapd.request("SET ext_eapol_frame_io 0") | |
6619 | dev[0].request("SET ext_eapol_frame_io 0") | |
6620 | send_wsc_msg(hapd, addr, wsc_done) | |
6621 | ||
6622 | ev = hapd.wait_event(["WPS-REG-SUCCESS"], timeout=5) | |
6623 | if ev is None: | |
6624 | raise Exception("hostapd did not report WPS success") | |
6625 | ||
6626 | dev[0].wait_connected() | |
6627 | ||
6628 | def wps_start_kwa(dev, apdev): | |
6629 | pin = "12345670" | |
6630 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6631 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6632 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6633 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6634 | ||
6635 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6636 | uuid_r = 16*'\x33' | |
6637 | r_nonce = 16*'\x44' | |
6638 | own_private, e_pk = wsc_dh_init() | |
6639 | ||
6640 | logger.debug("Receive M1 from STA") | |
6641 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6642 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6643 | ||
6644 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6645 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6646 | r_nonce) | |
6647 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6648 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6649 | ||
6650 | logger.debug("Send M2 to STA") | |
6651 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6652 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6653 | r_nonce, uuid_r, e_pk) | |
6654 | send_wsc_msg(dev[0], bssid, m2) | |
6655 | eap_id = (eap_id + 1) % 256 | |
6656 | ||
6657 | logger.debug("Receive M3 from STA") | |
6658 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
6659 | ||
6660 | logger.debug("Send M4 to STA") | |
6661 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6662 | attrs += build_attr_msg_type(WPS_M4) | |
6663 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6664 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
6665 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
6666 | ||
6667 | return r_s1, keywrapkey, authkey, raw_m3_attrs, eap_id, bssid, attrs | |
6668 | ||
6669 | def wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id): | |
6670 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
6671 | m4 = build_eap_wsc(1, eap_id, attrs) | |
6672 | send_wsc_msg(dev[0], bssid, m4) | |
6673 | eap_id = (eap_id + 1) % 256 | |
6674 | ||
6675 | logger.debug("Receive M5 from STA") | |
6676 | msg = get_wsc_msg(dev[0]) | |
6677 | if msg['wsc_opcode'] != WSC_NACK: | |
6678 | raise Exception("Unexpected message - expected WSC_Nack") | |
6679 | ||
6680 | dev[0].request("WPS_CANCEL") | |
6681 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6682 | dev[0].wait_disconnected() | |
6683 | ||
6684 | def test_wps_ext_kwa_proto_no_kwa(dev, apdev): | |
6685 | """WPS and KWA error: No KWA attribute""" | |
6686 | r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) | |
6687 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6688 | # Encrypted Settings without KWA | |
6689 | iv = 16*'\x99' | |
6690 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6691 | pad_len = 16 - len(data) % 16 | |
6692 | ps = pad_len * struct.pack('B', pad_len) | |
6693 | data += ps | |
6694 | wrapped = aes.encrypt(data) | |
6695 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6696 | wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id) | |
6697 | ||
6698 | def test_wps_ext_kwa_proto_data_after_kwa(dev, apdev): | |
6699 | """WPS and KWA error: Data after KWA""" | |
6700 | r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) | |
6701 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6702 | # Encrypted Settings and data after KWA | |
6703 | m = hmac.new(authkey, data, hashlib.sha256) | |
6704 | kwa = m.digest()[0:8] | |
6705 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
6706 | data += build_wsc_attr(ATTR_VENDOR_EXT, "1234567890") | |
6707 | iv = 16*'\x99' | |
6708 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6709 | pad_len = 16 - len(data) % 16 | |
6710 | ps = pad_len * struct.pack('B', pad_len) | |
6711 | data += ps | |
6712 | wrapped = aes.encrypt(data) | |
6713 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6714 | wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id) | |
6715 | ||
6716 | def test_wps_ext_kwa_proto_kwa_mismatch(dev, apdev): | |
6717 | """WPS and KWA error: KWA mismatch""" | |
6718 | r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) | |
6719 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6720 | # Encrypted Settings and KWA with incorrect value | |
6721 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, 8*'\x00') | |
6722 | iv = 16*'\x99' | |
6723 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6724 | pad_len = 16 - len(data) % 16 | |
6725 | ps = pad_len * struct.pack('B', pad_len) | |
6726 | data += ps | |
6727 | wrapped = aes.encrypt(data) | |
6728 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6729 | wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id) | |
6730 | ||
6731 | def wps_run_cred_proto(dev, apdev, m8_cred, connect=False, no_connect=False): | |
6732 | pin = "12345670" | |
6733 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6734 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6735 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6736 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6737 | ||
6738 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6739 | uuid_r = 16*'\x33' | |
6740 | r_nonce = 16*'\x44' | |
6741 | own_private, e_pk = wsc_dh_init() | |
6742 | ||
6743 | logger.debug("Receive M1 from STA") | |
6744 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6745 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6746 | ||
6747 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6748 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6749 | r_nonce) | |
6750 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6751 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6752 | ||
6753 | logger.debug("Send M2 to STA") | |
6754 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6755 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6756 | r_nonce, uuid_r, e_pk) | |
6757 | send_wsc_msg(dev[0], bssid, m2) | |
6758 | eap_id = (eap_id + 1) % 256 | |
6759 | ||
6760 | logger.debug("Receive M3 from STA") | |
6761 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
6762 | ||
6763 | logger.debug("Send M4 to STA") | |
6764 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6765 | attrs += build_attr_msg_type(WPS_M4) | |
6766 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6767 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
6768 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
6769 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6770 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6771 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
6772 | raw_m4_attrs = attrs | |
6773 | m4 = build_eap_wsc(1, eap_id, attrs) | |
6774 | send_wsc_msg(dev[0], bssid, m4) | |
6775 | eap_id = (eap_id + 1) % 256 | |
6776 | ||
6777 | logger.debug("Receive M5 from STA") | |
6778 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
6779 | ||
6780 | logger.debug("Send M6 to STA") | |
6781 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6782 | attrs += build_attr_msg_type(WPS_M6) | |
6783 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6784 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6785 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
6786 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6787 | attrs += build_attr_authenticator(authkey, raw_m5_attrs, attrs) | |
6788 | raw_m6_attrs = attrs | |
6789 | m6 = build_eap_wsc(1, eap_id, attrs) | |
6790 | send_wsc_msg(dev[0], bssid, m6) | |
6791 | eap_id = (eap_id + 1) % 256 | |
6792 | ||
6793 | logger.debug("Receive M7 from STA") | |
6794 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M7) | |
6795 | ||
6796 | logger.debug("Send M8 to STA") | |
6797 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6798 | attrs += build_attr_msg_type(WPS_M8) | |
6799 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6800 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6801 | attrs += build_attr_encr_settings(authkey, keywrapkey, m8_cred) | |
6802 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
6803 | raw_m8_attrs = attrs | |
6804 | m8 = build_eap_wsc(1, eap_id, attrs) | |
6805 | send_wsc_msg(dev[0], bssid, m8) | |
6806 | eap_id = (eap_id + 1) % 256 | |
6807 | ||
6808 | if no_connect: | |
6809 | logger.debug("Receive WSC_Done from STA") | |
6810 | msg = get_wsc_msg(dev[0]) | |
6811 | if msg['wsc_opcode'] != WSC_Done or msg['wsc_msg_type'] != WPS_WSC_DONE: | |
6812 | raise Exception("Unexpected Op-Code/MsgType for WSC_Done") | |
6813 | ||
6814 | hapd.request("SET ext_eapol_frame_io 0") | |
6815 | dev[0].request("SET ext_eapol_frame_io 0") | |
6816 | ||
6817 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6818 | ||
6819 | dev[0].wait_disconnected() | |
6820 | dev[0].request("REMOVE_NETWORK all") | |
6821 | elif connect: | |
6822 | logger.debug("Receive WSC_Done from STA") | |
6823 | msg = get_wsc_msg(dev[0]) | |
6824 | if msg['wsc_opcode'] != WSC_Done or msg['wsc_msg_type'] != WPS_WSC_DONE: | |
6825 | raise Exception("Unexpected Op-Code/MsgType for WSC_Done") | |
6826 | ||
6827 | hapd.request("SET ext_eapol_frame_io 0") | |
6828 | dev[0].request("SET ext_eapol_frame_io 0") | |
6829 | ||
6830 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6831 | ||
6832 | dev[0].wait_connected() | |
6833 | else: | |
6834 | # Verify STA NACK's the credential | |
6835 | msg = get_wsc_msg(dev[0]) | |
6836 | if msg['wsc_opcode'] != WSC_NACK: | |
6837 | raise Exception("Unexpected message - expected WSC_Nack") | |
6838 | dev[0].request("WPS_CANCEL") | |
6839 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6840 | dev[0].wait_disconnected() | |
6841 | ||
6842 | def build_cred(nw_idx='\x01', ssid='test-wps-conf', auth_type='\x00\x20', | |
6843 | encr_type='\x00\x08', nw_key="12345678", | |
6844 | mac_addr='\x00\x00\x00\x00\x00\x00'): | |
6845 | attrs = '' | |
6846 | if nw_idx is not None: | |
6847 | attrs += build_wsc_attr(ATTR_NETWORK_INDEX, nw_idx) | |
6848 | if ssid is not None: | |
6849 | attrs += build_wsc_attr(ATTR_SSID, ssid) | |
6850 | if auth_type is not None: | |
6851 | attrs += build_wsc_attr(ATTR_AUTH_TYPE, auth_type) | |
6852 | if encr_type is not None: | |
6853 | attrs += build_wsc_attr(ATTR_ENCR_TYPE, encr_type) | |
6854 | if nw_key is not None: | |
6855 | attrs += build_wsc_attr(ATTR_NETWORK_KEY, nw_key) | |
6856 | if mac_addr is not None: | |
6857 | attrs += build_wsc_attr(ATTR_MAC_ADDR, mac_addr) | |
6858 | return build_wsc_attr(ATTR_CRED, attrs) | |
6859 | ||
6860 | def test_wps_ext_cred_proto_success(dev, apdev): | |
6861 | """WPS and Credential: success""" | |
6862 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6863 | m8_cred = build_cred(mac_addr=mac_addr) | |
6864 | wps_run_cred_proto(dev, apdev, m8_cred, connect=True) | |
6865 | ||
6866 | def test_wps_ext_cred_proto_mac_addr_mismatch(dev, apdev): | |
6867 | """WPS and Credential: MAC Address mismatch""" | |
6868 | m8_cred = build_cred() | |
6869 | wps_run_cred_proto(dev, apdev, m8_cred, connect=True) | |
6870 | ||
6871 | def test_wps_ext_cred_proto_zero_padding(dev, apdev): | |
6872 | """WPS and Credential: zeropadded attributes""" | |
6873 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6874 | m8_cred = build_cred(mac_addr=mac_addr, ssid='test-wps-conf\x00', | |
6875 | nw_key="12345678\x00") | |
6876 | wps_run_cred_proto(dev, apdev, m8_cred, connect=True) | |
6877 | ||
6878 | def test_wps_ext_cred_proto_ssid_missing(dev, apdev): | |
6879 | """WPS and Credential: SSID missing""" | |
6880 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6881 | m8_cred = build_cred(mac_addr=mac_addr, ssid=None) | |
6882 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6883 | ||
6884 | def test_wps_ext_cred_proto_ssid_zero_len(dev, apdev): | |
6885 | """WPS and Credential: Zero-length SSID""" | |
6886 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6887 | m8_cred = build_cred(mac_addr=mac_addr, ssid="") | |
6888 | wps_run_cred_proto(dev, apdev, m8_cred, no_connect=True) | |
6889 | ||
6890 | def test_wps_ext_cred_proto_auth_type_missing(dev, apdev): | |
6891 | """WPS and Credential: Auth Type missing""" | |
6892 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6893 | m8_cred = build_cred(mac_addr=mac_addr, auth_type=None) | |
6894 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6895 | ||
6896 | def test_wps_ext_cred_proto_encr_type_missing(dev, apdev): | |
6897 | """WPS and Credential: Encr Type missing""" | |
6898 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6899 | m8_cred = build_cred(mac_addr=mac_addr, encr_type=None) | |
6900 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6901 | ||
6902 | def test_wps_ext_cred_proto_network_key_missing(dev, apdev): | |
6903 | """WPS and Credential: Network Key missing""" | |
6904 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6905 | m8_cred = build_cred(mac_addr=mac_addr, nw_key=None) | |
6906 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6907 | ||
6908 | def test_wps_ext_cred_proto_network_key_missing_open(dev, apdev): | |
6909 | """WPS and Credential: Network Key missing (open)""" | |
6910 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6911 | m8_cred = build_cred(mac_addr=mac_addr, auth_type='\x00\x01', | |
6912 | encr_type='\x00\x01', nw_key=None, ssid="foo") | |
6913 | wps_run_cred_proto(dev, apdev, m8_cred, no_connect=True) | |
6914 | ||
6915 | def test_wps_ext_cred_proto_mac_addr_missing(dev, apdev): | |
6916 | """WPS and Credential: MAC Address missing""" | |
6917 | m8_cred = build_cred(mac_addr=None) | |
6918 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6919 | ||
6920 | def test_wps_ext_cred_proto_invalid_encr_type(dev, apdev): | |
6921 | """WPS and Credential: Invalid Encr Type""" | |
6922 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6923 | m8_cred = build_cred(mac_addr=mac_addr, encr_type='\x00\x00') | |
6924 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6925 | ||
6926 | def test_wps_ext_cred_proto_missing_cred(dev, apdev): | |
6927 | """WPS and Credential: Missing Credential""" | |
6928 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6929 | m8_cred = '' | |
6930 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6931 | ||
6932 | def test_wps_ext_proto_m2_no_public_key(dev, apdev): | |
6933 | """WPS and no Public Key in M2""" | |
6934 | pin = "12345670" | |
6935 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6936 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6937 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6938 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6939 | ||
6940 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6941 | uuid_r = 16*'\x33' | |
6942 | r_nonce = 16*'\x44' | |
6943 | own_private, e_pk = wsc_dh_init() | |
6944 | ||
6945 | logger.debug("Receive M1 from STA") | |
6946 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6947 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6948 | ||
6949 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6950 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6951 | r_nonce) | |
6952 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6953 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6954 | ||
6955 | logger.debug("Send M2 to STA") | |
6956 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6957 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6958 | r_nonce, uuid_r, None) | |
6959 | send_wsc_msg(dev[0], bssid, m2) | |
6960 | eap_id = (eap_id + 1) % 256 | |
6961 | ||
6962 | # Verify STA NACK's the credential | |
6963 | msg = get_wsc_msg(dev[0]) | |
6964 | if msg['wsc_opcode'] != WSC_NACK: | |
6965 | raise Exception("Unexpected message - expected WSC_Nack") | |
6966 | dev[0].request("WPS_CANCEL") | |
6967 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6968 | dev[0].wait_disconnected() | |
6969 | ||
6970 | def test_wps_ext_proto_m2_invalid_public_key(dev, apdev): | |
6971 | """WPS and invalid Public Key in M2""" | |
6972 | pin = "12345670" | |
6973 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6974 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6975 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6976 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6977 | ||
6978 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6979 | uuid_r = 16*'\x33' | |
6980 | r_nonce = 16*'\x44' | |
6981 | own_private, e_pk = wsc_dh_init() | |
6982 | ||
6983 | logger.debug("Receive M1 from STA") | |
6984 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6985 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6986 | ||
6987 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6988 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6989 | r_nonce) | |
6990 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6991 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6992 | ||
6993 | logger.debug("Send M2 to STA") | |
6994 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6995 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6996 | r_nonce, uuid_r, 192*'\xff') | |
6997 | send_wsc_msg(dev[0], bssid, m2) | |
6998 | eap_id = (eap_id + 1) % 256 | |
6999 | ||
7000 | # Verify STA NACK's the credential | |
7001 | msg = get_wsc_msg(dev[0]) | |
7002 | if msg['wsc_opcode'] != WSC_NACK: | |
7003 | raise Exception("Unexpected message - expected WSC_Nack") | |
7004 | dev[0].request("WPS_CANCEL") | |
7005 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7006 | dev[0].wait_disconnected() | |
7007 | ||
7008 | def test_wps_ext_proto_m2_public_key_oom(dev, apdev): | |
7009 | """WPS and Public Key OOM in M2""" | |
7010 | pin = "12345670" | |
7011 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7012 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7013 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7014 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7015 | ||
7016 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7017 | uuid_r = 16*'\x33' | |
7018 | r_nonce = 16*'\x44' | |
7019 | own_private, e_pk = wsc_dh_init() | |
7020 | ||
7021 | logger.debug("Receive M1 from STA") | |
7022 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7023 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7024 | ||
7025 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7026 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7027 | r_nonce) | |
7028 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7029 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7030 | ||
7031 | logger.debug("Send M2 to STA") | |
7032 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7033 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7034 | r_nonce, uuid_r, e_pk) | |
7035 | with alloc_fail(dev[0], 1, "wpabuf_alloc_copy;wps_process_pubkey"): | |
7036 | send_wsc_msg(dev[0], bssid, m2) | |
7037 | eap_id = (eap_id + 1) % 256 | |
7038 | ||
7039 | # Verify STA NACK's the credential | |
7040 | msg = get_wsc_msg(dev[0]) | |
7041 | if msg['wsc_opcode'] != WSC_NACK: | |
7042 | raise Exception("Unexpected message - expected WSC_Nack") | |
7043 | dev[0].request("WPS_CANCEL") | |
7044 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7045 | dev[0].wait_disconnected() | |
7046 | ||
7047 | def test_wps_ext_proto_nack_m3(dev, apdev): | |
7048 | """WPS and NACK M3""" | |
7049 | pin = "12345670" | |
7050 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7051 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7052 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7053 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7054 | ||
7055 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7056 | uuid_r = 16*'\x33' | |
7057 | r_nonce = 16*'\x44' | |
7058 | own_private, e_pk = wsc_dh_init() | |
7059 | ||
7060 | logger.debug("Receive M1 from STA") | |
7061 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7062 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7063 | ||
7064 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7065 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7066 | r_nonce) | |
7067 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7068 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7069 | ||
7070 | logger.debug("Send M2 to STA") | |
7071 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7072 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7073 | r_nonce, uuid_r, e_pk) | |
7074 | send_wsc_msg(dev[0], bssid, m2) | |
7075 | eap_id = (eap_id + 1) % 256 | |
7076 | ||
7077 | logger.debug("Receive M3 from STA") | |
7078 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7079 | ||
7080 | logger.debug("Send NACK to STA") | |
7081 | msg, attrs = build_nack(eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7082 | r_nonce, config_error='\x01\x23') | |
7083 | send_wsc_msg(dev[0], bssid, msg) | |
7084 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=5) | |
7085 | if ev is None: | |
7086 | raise Exception("Failure not reported") | |
7087 | if "msg=7 config_error=291" not in ev: | |
7088 | raise Exception("Unexpected failure reason: " + ev) | |
7089 | ||
7090 | def test_wps_ext_proto_nack_m5(dev, apdev): | |
7091 | """WPS and NACK M5""" | |
7092 | pin = "12345670" | |
7093 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7094 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7095 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7096 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7097 | ||
7098 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7099 | uuid_r = 16*'\x33' | |
7100 | r_nonce = 16*'\x44' | |
7101 | own_private, e_pk = wsc_dh_init() | |
7102 | ||
7103 | logger.debug("Receive M1 from STA") | |
7104 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7105 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7106 | ||
7107 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7108 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7109 | r_nonce) | |
7110 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7111 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7112 | ||
7113 | logger.debug("Send M2 to STA") | |
7114 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7115 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7116 | r_nonce, uuid_r, e_pk) | |
7117 | send_wsc_msg(dev[0], bssid, m2) | |
7118 | eap_id = (eap_id + 1) % 256 | |
7119 | ||
7120 | logger.debug("Receive M3 from STA") | |
7121 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7122 | ||
7123 | logger.debug("Send M4 to STA") | |
7124 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7125 | attrs += build_attr_msg_type(WPS_M4) | |
7126 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
7127 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7128 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7129 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7130 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7131 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
7132 | raw_m4_attrs = attrs | |
7133 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7134 | send_wsc_msg(dev[0], bssid, m4) | |
7135 | eap_id = (eap_id + 1) % 256 | |
7136 | ||
7137 | logger.debug("Receive M5 from STA") | |
7138 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
7139 | ||
7140 | logger.debug("Send NACK to STA") | |
7141 | msg, attrs = build_nack(eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7142 | r_nonce, config_error='\x01\x24') | |
7143 | send_wsc_msg(dev[0], bssid, msg) | |
7144 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=5) | |
7145 | if ev is None: | |
7146 | raise Exception("Failure not reported") | |
7147 | if "msg=9 config_error=292" not in ev: | |
7148 | raise Exception("Unexpected failure reason: " + ev) | |
7149 | ||
7150 | def wps_nack_m3(dev, apdev): | |
7151 | pin = "00000000" | |
7152 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
7153 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7154 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7155 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7156 | ||
7157 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7158 | uuid_r = 16*'\x33' | |
7159 | r_nonce = 16*'\x44' | |
7160 | own_private, e_pk = wsc_dh_init() | |
7161 | ||
7162 | logger.debug("Receive M1 from STA") | |
7163 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7164 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7165 | ||
7166 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7167 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7168 | r_nonce) | |
7169 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7170 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7171 | ||
7172 | logger.debug("Send M2 to STA") | |
7173 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7174 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7175 | r_nonce, uuid_r, e_pk, dev_pw_id='\x00\x04') | |
7176 | send_wsc_msg(dev[0], bssid, m2) | |
7177 | eap_id = (eap_id + 1) % 256 | |
7178 | ||
7179 | logger.debug("Receive M3 from STA") | |
7180 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7181 | return eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], r_nonce, bssid | |
7182 | ||
7183 | def test_wps_ext_proto_nack_m3_no_config_error(dev, apdev): | |
7184 | """WPS and NACK M3 missing Config Error""" | |
7185 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7186 | logger.debug("Send NACK to STA") | |
7187 | msg, attrs = build_nack(eap_id, e_nonce, r_nonce, config_error=None) | |
7188 | send_wsc_msg(dev[0], bssid, msg) | |
7189 | dev[0].request("WPS_CANCEL") | |
7190 | dev[0].wait_disconnected() | |
7191 | dev[0].flush_scan_cache() | |
7192 | ||
7193 | def test_wps_ext_proto_nack_m3_no_e_nonce(dev, apdev): | |
7194 | """WPS and NACK M3 missing E-Nonce""" | |
7195 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7196 | logger.debug("Send NACK to STA") | |
7197 | msg, attrs = build_nack(eap_id, None, r_nonce) | |
7198 | send_wsc_msg(dev[0], bssid, msg) | |
7199 | dev[0].request("WPS_CANCEL") | |
7200 | dev[0].wait_disconnected() | |
7201 | dev[0].flush_scan_cache() | |
7202 | ||
7203 | def test_wps_ext_proto_nack_m3_e_nonce_mismatch(dev, apdev): | |
7204 | """WPS and NACK M3 E-Nonce mismatch""" | |
7205 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7206 | logger.debug("Send NACK to STA") | |
7207 | msg, attrs = build_nack(eap_id, 16*'\x00', r_nonce) | |
7208 | send_wsc_msg(dev[0], bssid, msg) | |
7209 | dev[0].request("WPS_CANCEL") | |
7210 | dev[0].wait_disconnected() | |
7211 | dev[0].flush_scan_cache() | |
7212 | ||
7213 | def test_wps_ext_proto_nack_m3_no_r_nonce(dev, apdev): | |
7214 | """WPS and NACK M3 missing R-Nonce""" | |
7215 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7216 | logger.debug("Send NACK to STA") | |
7217 | msg, attrs = build_nack(eap_id, e_nonce, None) | |
7218 | send_wsc_msg(dev[0], bssid, msg) | |
7219 | dev[0].request("WPS_CANCEL") | |
7220 | dev[0].wait_disconnected() | |
7221 | dev[0].flush_scan_cache() | |
7222 | ||
7223 | def test_wps_ext_proto_nack_m3_r_nonce_mismatch(dev, apdev): | |
7224 | """WPS and NACK M3 R-Nonce mismatch""" | |
7225 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7226 | logger.debug("Send NACK to STA") | |
7227 | msg, attrs = build_nack(eap_id, e_nonce, 16*'\x00') | |
7228 | send_wsc_msg(dev[0], bssid, msg) | |
7229 | dev[0].request("WPS_CANCEL") | |
7230 | dev[0].wait_disconnected() | |
7231 | dev[0].flush_scan_cache() | |
7232 | ||
7233 | def test_wps_ext_proto_nack_m3_no_msg_type(dev, apdev): | |
7234 | """WPS and NACK M3 no Message Type""" | |
7235 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7236 | logger.debug("Send NACK to STA") | |
7237 | msg, attrs = build_nack(eap_id, e_nonce, r_nonce, msg_type=None) | |
7238 | send_wsc_msg(dev[0], bssid, msg) | |
7239 | dev[0].request("WPS_CANCEL") | |
7240 | dev[0].wait_disconnected() | |
7241 | dev[0].flush_scan_cache() | |
7242 | ||
7243 | def test_wps_ext_proto_nack_m3_invalid_msg_type(dev, apdev): | |
7244 | """WPS and NACK M3 invalid Message Type""" | |
7245 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7246 | logger.debug("Send NACK to STA") | |
7247 | msg, attrs = build_nack(eap_id, e_nonce, r_nonce, msg_type=123) | |
7248 | send_wsc_msg(dev[0], bssid, msg) | |
7249 | dev[0].request("WPS_CANCEL") | |
7250 | dev[0].wait_disconnected() | |
7251 | dev[0].flush_scan_cache() | |
7252 | ||
7253 | def test_wps_ext_proto_nack_m3_invalid_attr(dev, apdev): | |
7254 | """WPS and NACK M3 invalid attribute""" | |
7255 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7256 | logger.debug("Send NACK to STA") | |
7257 | attrs = '\x10\x10\x00' | |
7258 | msg = build_eap_wsc(1, eap_id, attrs, opcode=WSC_NACK) | |
7259 | send_wsc_msg(dev[0], bssid, msg) | |
7260 | dev[0].request("WPS_CANCEL") | |
7261 | dev[0].wait_disconnected() | |
7262 | dev[0].flush_scan_cache() | |
7263 | ||
7264 | def test_wps_ext_proto_ack_m3_no_e_nonce(dev, apdev): | |
7265 | """WPS and ACK M3 missing E-Nonce""" | |
7266 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7267 | logger.debug("Send NACK to STA") | |
7268 | msg, attrs = build_ack(eap_id, None, r_nonce) | |
7269 | send_wsc_msg(dev[0], bssid, msg) | |
7270 | dev[0].request("WPS_CANCEL") | |
7271 | dev[0].wait_disconnected() | |
7272 | dev[0].flush_scan_cache() | |
7273 | ||
7274 | def test_wps_ext_proto_ack_m3_e_nonce_mismatch(dev, apdev): | |
7275 | """WPS and ACK M3 E-Nonce mismatch""" | |
7276 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7277 | logger.debug("Send NACK to STA") | |
7278 | msg, attrs = build_ack(eap_id, 16*'\x00', r_nonce) | |
7279 | send_wsc_msg(dev[0], bssid, msg) | |
7280 | dev[0].request("WPS_CANCEL") | |
7281 | dev[0].wait_disconnected() | |
7282 | dev[0].flush_scan_cache() | |
7283 | ||
7284 | def test_wps_ext_proto_ack_m3_no_r_nonce(dev, apdev): | |
7285 | """WPS and ACK M3 missing R-Nonce""" | |
7286 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7287 | logger.debug("Send NACK to STA") | |
7288 | msg, attrs = build_ack(eap_id, e_nonce, None) | |
7289 | send_wsc_msg(dev[0], bssid, msg) | |
7290 | dev[0].request("WPS_CANCEL") | |
7291 | dev[0].wait_disconnected() | |
7292 | dev[0].flush_scan_cache() | |
7293 | ||
7294 | def test_wps_ext_proto_ack_m3_r_nonce_mismatch(dev, apdev): | |
7295 | """WPS and ACK M3 R-Nonce mismatch""" | |
7296 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7297 | logger.debug("Send NACK to STA") | |
7298 | msg, attrs = build_ack(eap_id, e_nonce, 16*'\x00') | |
7299 | send_wsc_msg(dev[0], bssid, msg) | |
7300 | dev[0].request("WPS_CANCEL") | |
7301 | dev[0].wait_disconnected() | |
7302 | dev[0].flush_scan_cache() | |
7303 | ||
7304 | def test_wps_ext_proto_ack_m3_no_msg_type(dev, apdev): | |
7305 | """WPS and ACK M3 no Message Type""" | |
7306 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7307 | logger.debug("Send NACK to STA") | |
7308 | msg, attrs = build_ack(eap_id, e_nonce, r_nonce, msg_type=None) | |
7309 | send_wsc_msg(dev[0], bssid, msg) | |
7310 | dev[0].request("WPS_CANCEL") | |
7311 | dev[0].wait_disconnected() | |
7312 | dev[0].flush_scan_cache() | |
7313 | ||
7314 | def test_wps_ext_proto_ack_m3_invalid_msg_type(dev, apdev): | |
7315 | """WPS and ACK M3 invalid Message Type""" | |
7316 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7317 | logger.debug("Send NACK to STA") | |
7318 | msg, attrs = build_ack(eap_id, e_nonce, r_nonce, msg_type=123) | |
7319 | send_wsc_msg(dev[0], bssid, msg) | |
7320 | dev[0].request("WPS_CANCEL") | |
7321 | dev[0].wait_disconnected() | |
7322 | dev[0].flush_scan_cache() | |
7323 | ||
7324 | def test_wps_ext_proto_ack_m3_invalid_attr(dev, apdev): | |
7325 | """WPS and ACK M3 invalid attribute""" | |
7326 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7327 | logger.debug("Send ACK to STA") | |
7328 | attrs = '\x10\x10\x00' | |
7329 | msg = build_eap_wsc(1, eap_id, attrs, opcode=WSC_ACK) | |
7330 | send_wsc_msg(dev[0], bssid, msg) | |
7331 | dev[0].request("WPS_CANCEL") | |
7332 | dev[0].wait_disconnected() | |
7333 | dev[0].flush_scan_cache() | |
7334 | ||
7335 | def test_wps_ext_proto_ack_m3(dev, apdev): | |
7336 | """WPS and ACK M3""" | |
7337 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7338 | logger.debug("Send ACK to STA") | |
7339 | msg, attrs = build_ack(eap_id, e_nonce, r_nonce) | |
7340 | send_wsc_msg(dev[0], bssid, msg) | |
7341 | dev[0].request("WPS_CANCEL") | |
7342 | dev[0].wait_disconnected() | |
7343 | dev[0].flush_scan_cache() | |
7344 | ||
7345 | def wps_to_m3_helper(dev, apdev): | |
7346 | pin = "12345670" | |
7347 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7348 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7349 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7350 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7351 | ||
7352 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7353 | uuid_r = 16*'\x33' | |
7354 | r_nonce = 16*'\x44' | |
7355 | own_private, e_pk = wsc_dh_init() | |
7356 | ||
7357 | logger.debug("Receive M1 from STA") | |
7358 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7359 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7360 | ||
7361 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7362 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7363 | r_nonce) | |
7364 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7365 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7366 | ||
7367 | logger.debug("Send M2 to STA") | |
7368 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7369 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7370 | r_nonce, uuid_r, e_pk) | |
7371 | send_wsc_msg(dev[0], bssid, m2) | |
7372 | eap_id = (eap_id + 1) % 256 | |
7373 | ||
7374 | logger.debug("Receive M3 from STA") | |
7375 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7376 | return eap_id, m1_attrs, r_nonce, bssid, r_hash1, r_hash2, r_s1, r_s2, raw_m3_attrs, authkey, keywrapkey | |
7377 | ||
7378 | def wps_to_m3(dev, apdev): | |
7379 | eap_id, m1_attrs, r_nonce, bssid, r_hash1, r_hash2, r_s1, r_s2, raw_m3_attrs, authkey, keywrapkey = wps_to_m3_helper(dev, apdev) | |
7380 | return eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], r_nonce, bssid, r_hash1, r_hash2, r_s1, raw_m3_attrs, authkey, keywrapkey | |
7381 | ||
7382 | def wps_to_m5(dev, apdev): | |
7383 | eap_id, m1_attrs, r_nonce, bssid, r_hash1, r_hash2, r_s1, r_s2, raw_m3_attrs, authkey, keywrapkey = wps_to_m3_helper(dev, apdev) | |
7384 | ||
7385 | logger.debug("Send M4 to STA") | |
7386 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7387 | attrs += build_attr_msg_type(WPS_M4) | |
7388 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
7389 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7390 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7391 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7392 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7393 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
7394 | raw_m4_attrs = attrs | |
7395 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7396 | send_wsc_msg(dev[0], bssid, m4) | |
7397 | eap_id = (eap_id + 1) % 256 | |
7398 | ||
7399 | logger.debug("Receive M5 from STA") | |
7400 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
7401 | ||
7402 | return eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], r_nonce, bssid, r_hash1, r_hash2, r_s2, raw_m5_attrs, authkey, keywrapkey | |
7403 | ||
7404 | def test_wps_ext_proto_m4_missing_r_hash1(dev, apdev): | |
7405 | """WPS and no R-Hash1 in M4""" | |
7406 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7407 | ||
7408 | logger.debug("Send M4 to STA") | |
7409 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7410 | attrs += build_attr_msg_type(WPS_M4) | |
7411 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7412 | #attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7413 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7414 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7415 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7416 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7417 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7418 | send_wsc_msg(dev[0], bssid, m4) | |
7419 | eap_id = (eap_id + 1) % 256 | |
7420 | ||
7421 | logger.debug("Receive M5 (NACK) from STA") | |
7422 | msg = get_wsc_msg(dev[0]) | |
7423 | if msg['wsc_opcode'] != WSC_NACK: | |
7424 | raise Exception("Unexpected message - expected WSC_Nack") | |
7425 | ||
7426 | dev[0].request("WPS_CANCEL") | |
7427 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7428 | dev[0].wait_disconnected() | |
7429 | ||
7430 | def test_wps_ext_proto_m4_missing_r_hash2(dev, apdev): | |
7431 | """WPS and no R-Hash2 in M4""" | |
7432 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7433 | ||
7434 | logger.debug("Send M4 to STA") | |
7435 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7436 | attrs += build_attr_msg_type(WPS_M4) | |
7437 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7438 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7439 | #attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7440 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7441 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7442 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7443 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7444 | send_wsc_msg(dev[0], bssid, m4) | |
7445 | eap_id = (eap_id + 1) % 256 | |
7446 | ||
7447 | logger.debug("Receive M5 (NACK) from STA") | |
7448 | msg = get_wsc_msg(dev[0]) | |
7449 | if msg['wsc_opcode'] != WSC_NACK: | |
7450 | raise Exception("Unexpected message - expected WSC_Nack") | |
7451 | ||
7452 | dev[0].request("WPS_CANCEL") | |
7453 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7454 | dev[0].wait_disconnected() | |
7455 | ||
7456 | def test_wps_ext_proto_m4_missing_r_snonce1(dev, apdev): | |
7457 | """WPS and no R-SNonce1 in M4""" | |
7458 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7459 | ||
7460 | logger.debug("Send M4 to STA") | |
7461 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7462 | attrs += build_attr_msg_type(WPS_M4) | |
7463 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7464 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7465 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7466 | #data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7467 | data = '' | |
7468 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7469 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7470 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7471 | send_wsc_msg(dev[0], bssid, m4) | |
7472 | eap_id = (eap_id + 1) % 256 | |
7473 | ||
7474 | logger.debug("Receive M5 (NACK) from STA") | |
7475 | msg = get_wsc_msg(dev[0]) | |
7476 | if msg['wsc_opcode'] != WSC_NACK: | |
7477 | raise Exception("Unexpected message - expected WSC_Nack") | |
7478 | ||
7479 | dev[0].request("WPS_CANCEL") | |
7480 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7481 | dev[0].wait_disconnected() | |
7482 | ||
7483 | def test_wps_ext_proto_m4_invalid_pad_string(dev, apdev): | |
7484 | """WPS and invalid pad string in M4""" | |
7485 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7486 | ||
7487 | logger.debug("Send M4 to STA") | |
7488 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7489 | attrs += build_attr_msg_type(WPS_M4) | |
7490 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7491 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7492 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7493 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7494 | ||
7495 | m = hmac.new(authkey, data, hashlib.sha256) | |
7496 | kwa = m.digest()[0:8] | |
7497 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
7498 | iv = 16*'\x99' | |
7499 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
7500 | pad_len = 16 - len(data) % 16 | |
7501 | ps = (pad_len - 1) * struct.pack('B', pad_len) + struct.pack('B', pad_len - 1) | |
7502 | data += ps | |
7503 | wrapped = aes.encrypt(data) | |
7504 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
7505 | ||
7506 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7507 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7508 | send_wsc_msg(dev[0], bssid, m4) | |
7509 | eap_id = (eap_id + 1) % 256 | |
7510 | ||
7511 | logger.debug("Receive M5 (NACK) from STA") | |
7512 | msg = get_wsc_msg(dev[0]) | |
7513 | if msg['wsc_opcode'] != WSC_NACK: | |
7514 | raise Exception("Unexpected message - expected WSC_Nack") | |
7515 | ||
7516 | dev[0].request("WPS_CANCEL") | |
7517 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7518 | dev[0].wait_disconnected() | |
7519 | ||
7520 | def test_wps_ext_proto_m4_invalid_pad_value(dev, apdev): | |
7521 | """WPS and invalid pad value in M4""" | |
7522 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7523 | ||
7524 | logger.debug("Send M4 to STA") | |
7525 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7526 | attrs += build_attr_msg_type(WPS_M4) | |
7527 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7528 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7529 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7530 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7531 | ||
7532 | m = hmac.new(authkey, data, hashlib.sha256) | |
7533 | kwa = m.digest()[0:8] | |
7534 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
7535 | iv = 16*'\x99' | |
7536 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
7537 | pad_len = 16 - len(data) % 16 | |
7538 | ps = (pad_len - 1) * struct.pack('B', pad_len) + struct.pack('B', 255) | |
7539 | data += ps | |
7540 | wrapped = aes.encrypt(data) | |
7541 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
7542 | ||
7543 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7544 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7545 | send_wsc_msg(dev[0], bssid, m4) | |
7546 | eap_id = (eap_id + 1) % 256 | |
7547 | ||
7548 | logger.debug("Receive M5 (NACK) from STA") | |
7549 | msg = get_wsc_msg(dev[0]) | |
7550 | if msg['wsc_opcode'] != WSC_NACK: | |
7551 | raise Exception("Unexpected message - expected WSC_Nack") | |
7552 | ||
7553 | dev[0].request("WPS_CANCEL") | |
7554 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7555 | dev[0].wait_disconnected() | |
7556 | ||
7557 | def test_wps_ext_proto_m4_no_encr_settings(dev, apdev): | |
7558 | """WPS and no Encr Settings in M4""" | |
7559 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7560 | ||
7561 | logger.debug("Send M4 to STA") | |
7562 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7563 | attrs += build_attr_msg_type(WPS_M4) | |
7564 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7565 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7566 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7567 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7568 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7569 | send_wsc_msg(dev[0], bssid, m4) | |
7570 | eap_id = (eap_id + 1) % 256 | |
7571 | ||
7572 | logger.debug("Receive M5 (NACK) from STA") | |
7573 | msg = get_wsc_msg(dev[0]) | |
7574 | if msg['wsc_opcode'] != WSC_NACK: | |
7575 | raise Exception("Unexpected message - expected WSC_Nack") | |
7576 | ||
7577 | dev[0].request("WPS_CANCEL") | |
7578 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7579 | dev[0].wait_disconnected() | |
7580 | ||
7581 | def test_wps_ext_proto_m6_missing_r_snonce2(dev, apdev): | |
7582 | """WPS and no R-SNonce2 in M6""" | |
7583 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s2, m5, authkey, keywrapkey = wps_to_m5(dev, apdev) | |
7584 | ||
7585 | logger.debug("Send M6 to STA") | |
7586 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7587 | attrs += build_attr_msg_type(WPS_M6) | |
7588 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7589 | #data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7590 | data = '' | |
7591 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7592 | attrs += build_attr_authenticator(authkey, m5, attrs) | |
7593 | m6 = build_eap_wsc(1, eap_id, attrs) | |
7594 | send_wsc_msg(dev[0], bssid, m6) | |
7595 | eap_id = (eap_id + 1) % 256 | |
7596 | ||
7597 | logger.debug("Receive M7 (NACK) from STA") | |
7598 | msg = get_wsc_msg(dev[0]) | |
7599 | if msg['wsc_opcode'] != WSC_NACK: | |
7600 | raise Exception("Unexpected message - expected WSC_Nack") | |
7601 | ||
7602 | dev[0].request("WPS_CANCEL") | |
7603 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7604 | dev[0].wait_disconnected() | |
7605 | ||
7606 | def test_wps_ext_proto_m6_no_encr_settings(dev, apdev): | |
7607 | """WPS and no Encr Settings in M6""" | |
7608 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s2, m5, authkey, keywrapkey = wps_to_m5(dev, apdev) | |
7609 | ||
7610 | logger.debug("Send M6 to STA") | |
7611 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7612 | attrs += build_attr_msg_type(WPS_M6) | |
7613 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7614 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7615 | #attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7616 | attrs += build_attr_authenticator(authkey, m5, attrs) | |
7617 | m6 = build_eap_wsc(1, eap_id, attrs) | |
7618 | send_wsc_msg(dev[0], bssid, m6) | |
7619 | eap_id = (eap_id + 1) % 256 | |
7620 | ||
7621 | logger.debug("Receive M7 (NACK) from STA") | |
7622 | msg = get_wsc_msg(dev[0]) | |
7623 | if msg['wsc_opcode'] != WSC_NACK: | |
7624 | raise Exception("Unexpected message - expected WSC_Nack") | |
7625 | ||
7626 | dev[0].request("WPS_CANCEL") | |
7627 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7628 | dev[0].wait_disconnected() | |
7629 | ||
7630 | def test_wps_ext_proto_m8_no_encr_settings(dev, apdev): | |
7631 | """WPS and no Encr Settings in M6""" | |
7632 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s2, m5, authkey, keywrapkey = wps_to_m5(dev, apdev) | |
7633 | ||
7634 | logger.debug("Send M6 to STA") | |
7635 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7636 | attrs += build_attr_msg_type(WPS_M6) | |
7637 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7638 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7639 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7640 | attrs += build_attr_authenticator(authkey, m5, attrs) | |
7641 | raw_m6_attrs = attrs | |
7642 | m6 = build_eap_wsc(1, eap_id, attrs) | |
7643 | send_wsc_msg(dev[0], bssid, m6) | |
7644 | eap_id = (eap_id + 1) % 256 | |
7645 | ||
7646 | logger.debug("Receive M7 from STA") | |
7647 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M7) | |
7648 | ||
7649 | logger.debug("Send M8 to STA") | |
7650 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7651 | attrs += build_attr_msg_type(WPS_M8) | |
7652 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7653 | #attrs += build_attr_encr_settings(authkey, keywrapkey, m8_cred) | |
7654 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
7655 | raw_m8_attrs = attrs | |
7656 | m8 = build_eap_wsc(1, eap_id, attrs) | |
7657 | send_wsc_msg(dev[0], bssid, m8) | |
7658 | ||
7659 | logger.debug("Receive WSC_Done (NACK) from STA") | |
7660 | msg = get_wsc_msg(dev[0]) | |
7661 | if msg['wsc_opcode'] != WSC_NACK: | |
7662 | raise Exception("Unexpected message - expected WSC_Nack") | |
7663 | ||
7664 | dev[0].request("WPS_CANCEL") | |
7665 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7666 | dev[0].wait_disconnected() | |
7667 | ||
7668 | def wps_start_ext_reg(apdev, dev): | |
7669 | addr = dev.own_addr() | |
7670 | bssid = apdev['bssid'] | |
7671 | ssid = "test-wps-conf" | |
7672 | appin = "12345670" | |
7673 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
7674 | "wpa_passphrase": "12345678", "wpa": "2", | |
7675 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
7676 | "ap_pin": appin } | |
afc26df2 | 7677 | hapd = hostapd.add_ap(apdev, params) |
7511ead0 JM |
7678 | |
7679 | dev.scan_for_bss(bssid, freq="2412") | |
7680 | hapd.request("SET ext_eapol_frame_io 1") | |
7681 | dev.request("SET ext_eapol_frame_io 1") | |
7682 | ||
7683 | dev.request("WPS_REG " + bssid + " " + appin) | |
7684 | ||
7685 | return addr,bssid,hapd | |
7686 | ||
7687 | def wps_run_ap_settings_proto(dev, apdev, ap_settings, success): | |
7688 | addr,bssid,hapd = wps_start_ext_reg(apdev[0], dev[0]) | |
7689 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7690 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7691 | ||
7692 | logger.debug("Receive M1 from AP") | |
7693 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M1) | |
7694 | mac_addr = m1_attrs[ATTR_MAC_ADDR] | |
7695 | e_nonce = m1_attrs[ATTR_ENROLLEE_NONCE] | |
7696 | e_pk = m1_attrs[ATTR_PUBLIC_KEY] | |
7697 | ||
7698 | appin = '12345670' | |
7699 | uuid_r = 16*'\x33' | |
7700 | r_nonce = 16*'\x44' | |
7701 | own_private, r_pk = wsc_dh_init() | |
7702 | authkey,keywrapkey = wsc_dh_kdf(e_pk, own_private, mac_addr, e_nonce, | |
7703 | r_nonce) | |
7704 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, appin, e_pk, r_pk) | |
7705 | ||
7706 | logger.debug("Send M2 to AP") | |
7707 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, msg['eap_identifier'], | |
7708 | e_nonce, r_nonce, uuid_r, r_pk, eap_code=2) | |
7709 | send_wsc_msg(hapd, addr, m2) | |
7710 | ||
7711 | logger.debug("Receive M3 from AP") | |
7712 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M3) | |
7713 | ||
7714 | logger.debug("Send M4 to AP") | |
7715 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7716 | attrs += build_attr_msg_type(WPS_M4) | |
7717 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7718 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7719 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7720 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7721 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7722 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
7723 | raw_m4_attrs = attrs | |
7724 | m4 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7725 | send_wsc_msg(hapd, addr, m4) | |
7726 | ||
7727 | logger.debug("Receive M5 from AP") | |
7728 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M5) | |
7729 | ||
7730 | logger.debug("Send M6 to STA") | |
7731 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7732 | attrs += build_attr_msg_type(WPS_M6) | |
7733 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7734 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7735 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7736 | attrs += build_attr_authenticator(authkey, raw_m5_attrs, attrs) | |
7737 | raw_m6_attrs = attrs | |
7738 | m6 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7739 | send_wsc_msg(hapd, addr, m6) | |
7740 | ||
7741 | logger.debug("Receive M7 from AP") | |
7742 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M7) | |
7743 | ||
7744 | logger.debug("Send M8 to STA") | |
7745 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7746 | attrs += build_attr_msg_type(WPS_M8) | |
7747 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7748 | if ap_settings: | |
7749 | attrs += build_attr_encr_settings(authkey, keywrapkey, ap_settings) | |
7750 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
7751 | raw_m8_attrs = attrs | |
7752 | m8 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7753 | send_wsc_msg(hapd, addr, m8) | |
7754 | ||
7755 | if success: | |
7756 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5) | |
7757 | if ev is None: | |
7758 | raise Exception("New AP settings not reported") | |
7759 | logger.debug("Receive WSC_Done from AP") | |
7760 | msg = get_wsc_msg(hapd) | |
7761 | if msg['wsc_opcode'] != WSC_Done: | |
7762 | raise Exception("Unexpected message - expected WSC_Done") | |
7763 | ||
7764 | logger.debug("Send WSC_ACK to AP") | |
7765 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, | |
7766 | eap_code=2) | |
7767 | send_wsc_msg(hapd, addr, ack) | |
7768 | dev[0].wait_disconnected() | |
7769 | else: | |
7770 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
7771 | if ev is None: | |
7772 | raise Exception("WPS failure not reported") | |
7773 | logger.debug("Receive WSC_NACK from AP") | |
7774 | msg = get_wsc_msg(hapd) | |
7775 | if msg['wsc_opcode'] != WSC_NACK: | |
7776 | raise Exception("Unexpected message - expected WSC_NACK") | |
7777 | ||
7778 | logger.debug("Send WSC_NACK to AP") | |
7779 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
7780 | eap_code=2) | |
7781 | send_wsc_msg(hapd, addr, nack) | |
7782 | dev[0].wait_disconnected() | |
7783 | ||
7784 | def test_wps_ext_ap_settings_success(dev, apdev): | |
7785 | """WPS and AP Settings: success""" | |
7786 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7787 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7788 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7789 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
7790 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7791 | ap_settings += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[0]['bssid'].replace(':', ''))) | |
7792 | wps_run_ap_settings_proto(dev, apdev, ap_settings, True) | |
7793 | ||
9fd6804d | 7794 | @remote_compatible |
7511ead0 JM |
7795 | def test_wps_ext_ap_settings_missing(dev, apdev): |
7796 | """WPS and AP Settings: missing""" | |
7797 | wps_run_ap_settings_proto(dev, apdev, None, False) | |
7798 | ||
9fd6804d | 7799 | @remote_compatible |
7511ead0 JM |
7800 | def test_wps_ext_ap_settings_mac_addr_mismatch(dev, apdev): |
7801 | """WPS and AP Settings: MAC Address mismatch""" | |
7802 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7803 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7804 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7805 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
7806 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7807 | ap_settings += build_wsc_attr(ATTR_MAC_ADDR, '\x00\x00\x00\x00\x00\x00') | |
7808 | wps_run_ap_settings_proto(dev, apdev, ap_settings, True) | |
7809 | ||
9fd6804d | 7810 | @remote_compatible |
7511ead0 JM |
7811 | def test_wps_ext_ap_settings_mac_addr_missing(dev, apdev): |
7812 | """WPS and AP Settings: missing MAC Address""" | |
7813 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7814 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7815 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7816 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
7817 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7818 | wps_run_ap_settings_proto(dev, apdev, ap_settings, False) | |
7819 | ||
9fd6804d | 7820 | @remote_compatible |
7511ead0 JM |
7821 | def test_wps_ext_ap_settings_reject_encr_type(dev, apdev): |
7822 | """WPS and AP Settings: reject Encr Type""" | |
7823 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7824 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7825 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7826 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x00') | |
7827 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7828 | ap_settings += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[0]['bssid'].replace(':', ''))) | |
7829 | wps_run_ap_settings_proto(dev, apdev, ap_settings, False) | |
7830 | ||
9fd6804d | 7831 | @remote_compatible |
7511ead0 JM |
7832 | def test_wps_ext_ap_settings_m2d(dev, apdev): |
7833 | """WPS and AP Settings: M2D""" | |
7834 | addr,bssid,hapd = wps_start_ext_reg(apdev[0], dev[0]) | |
7835 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7836 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7837 | ||
7838 | logger.debug("Receive M1 from AP") | |
7839 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M1) | |
7840 | e_nonce = m1_attrs[ATTR_ENROLLEE_NONCE] | |
7841 | ||
7842 | r_nonce = 16*'\x44' | |
7843 | uuid_r = 16*'\x33' | |
7844 | ||
7845 | logger.debug("Send M2D to AP") | |
7846 | m2d, raw_m2d_attrs = build_m2d(raw_m1_attrs, msg['eap_identifier'], | |
7847 | e_nonce, r_nonce, uuid_r, | |
7848 | dev_pw_id='\x00\x00', eap_code=2) | |
7849 | send_wsc_msg(hapd, addr, m2d) | |
7850 | ||
7851 | ev = hapd.wait_event(["WPS-M2D"], timeout=5) | |
7852 | if ev is None: | |
7853 | raise Exception("M2D not reported") | |
7854 | ||
7855 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
7856 | ||
7857 | def wps_wait_ap_nack(hapd, dev, e_nonce, r_nonce): | |
7858 | logger.debug("Receive WSC_NACK from AP") | |
7859 | msg = get_wsc_msg(hapd) | |
7860 | if msg['wsc_opcode'] != WSC_NACK: | |
7861 | raise Exception("Unexpected message - expected WSC_NACK") | |
7862 | ||
7863 | logger.debug("Send WSC_NACK to AP") | |
7864 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
7865 | eap_code=2) | |
7866 | send_wsc_msg(hapd, dev.own_addr(), nack) | |
7867 | dev.wait_disconnected() | |
7868 | ||
9fd6804d | 7869 | @remote_compatible |
7511ead0 JM |
7870 | def test_wps_ext_m3_missing_e_hash1(dev, apdev): |
7871 | """WPS proto: M3 missing E-Hash1""" | |
7872 | pin = "12345670" | |
7873 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7874 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7875 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7876 | ||
7877 | logger.debug("Receive WSC/Start from AP") | |
7878 | msg = get_wsc_msg(hapd) | |
7879 | if msg['wsc_opcode'] != WSC_Start: | |
7880 | raise Exception("Unexpected Op-Code for WSC/Start") | |
7881 | ||
7882 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7883 | uuid_e = 16*'\x11' | |
7884 | e_nonce = 16*'\x22' | |
7885 | own_private, e_pk = wsc_dh_init() | |
7886 | ||
7887 | logger.debug("Send M1 to AP") | |
7888 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
7889 | e_nonce, e_pk) | |
7890 | send_wsc_msg(hapd, addr, m1) | |
7891 | ||
7892 | logger.debug("Receive M2 from AP") | |
7893 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
7894 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
7895 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
7896 | ||
7897 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
7898 | r_nonce) | |
7899 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
7900 | ||
7901 | logger.debug("Send M3 to AP") | |
7902 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7903 | attrs += build_attr_msg_type(WPS_M3) | |
7904 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
7905 | #attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
7906 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
7907 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
7908 | raw_m3_attrs = attrs | |
7909 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7910 | send_wsc_msg(hapd, addr, m3) | |
7911 | ||
7912 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
7913 | ||
9fd6804d | 7914 | @remote_compatible |
7511ead0 JM |
7915 | def test_wps_ext_m3_missing_e_hash2(dev, apdev): |
7916 | """WPS proto: M3 missing E-Hash2""" | |
7917 | pin = "12345670" | |
7918 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7919 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7920 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7921 | ||
7922 | logger.debug("Receive WSC/Start from AP") | |
7923 | msg = get_wsc_msg(hapd) | |
7924 | if msg['wsc_opcode'] != WSC_Start: | |
7925 | raise Exception("Unexpected Op-Code for WSC/Start") | |
7926 | ||
7927 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7928 | uuid_e = 16*'\x11' | |
7929 | e_nonce = 16*'\x22' | |
7930 | own_private, e_pk = wsc_dh_init() | |
7931 | ||
7932 | logger.debug("Send M1 to AP") | |
7933 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
7934 | e_nonce, e_pk) | |
7935 | send_wsc_msg(hapd, addr, m1) | |
7936 | ||
7937 | logger.debug("Receive M2 from AP") | |
7938 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
7939 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
7940 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
7941 | ||
7942 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
7943 | r_nonce) | |
7944 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
7945 | ||
7946 | logger.debug("Send M3 to AP") | |
7947 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7948 | attrs += build_attr_msg_type(WPS_M3) | |
7949 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
7950 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
7951 | #attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
7952 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
7953 | raw_m3_attrs = attrs | |
7954 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7955 | send_wsc_msg(hapd, addr, m3) | |
7956 | ||
7957 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
7958 | ||
9fd6804d | 7959 | @remote_compatible |
7511ead0 JM |
7960 | def test_wps_ext_m5_missing_e_snonce1(dev, apdev): |
7961 | """WPS proto: M5 missing E-SNonce1""" | |
7962 | pin = "12345670" | |
7963 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7964 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7965 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7966 | ||
7967 | logger.debug("Receive WSC/Start from AP") | |
7968 | msg = get_wsc_msg(hapd) | |
7969 | if msg['wsc_opcode'] != WSC_Start: | |
7970 | raise Exception("Unexpected Op-Code for WSC/Start") | |
7971 | ||
7972 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7973 | uuid_e = 16*'\x11' | |
7974 | e_nonce = 16*'\x22' | |
7975 | own_private, e_pk = wsc_dh_init() | |
7976 | ||
7977 | logger.debug("Send M1 to AP") | |
7978 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
7979 | e_nonce, e_pk) | |
7980 | send_wsc_msg(hapd, addr, m1) | |
7981 | ||
7982 | logger.debug("Receive M2 from AP") | |
7983 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
7984 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
7985 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
7986 | ||
7987 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
7988 | r_nonce) | |
7989 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
7990 | ||
7991 | logger.debug("Send M3 to AP") | |
7992 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7993 | attrs += build_attr_msg_type(WPS_M3) | |
7994 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
7995 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
7996 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
7997 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
7998 | raw_m3_attrs = attrs | |
7999 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8000 | send_wsc_msg(hapd, addr, m3) | |
8001 | ||
8002 | logger.debug("Receive M4 from AP") | |
8003 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8004 | ||
8005 | logger.debug("Send M5 to AP") | |
8006 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8007 | attrs += build_attr_msg_type(WPS_M5) | |
8008 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8009 | #data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8010 | data = '' | |
8011 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8012 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8013 | raw_m5_attrs = attrs | |
8014 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8015 | send_wsc_msg(hapd, addr, m5) | |
8016 | ||
8017 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8018 | ||
9fd6804d | 8019 | @remote_compatible |
7511ead0 JM |
8020 | def test_wps_ext_m5_e_snonce1_mismatch(dev, apdev): |
8021 | """WPS proto: M5 E-SNonce1 mismatch""" | |
8022 | pin = "12345670" | |
8023 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8024 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8025 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8026 | ||
8027 | logger.debug("Receive WSC/Start from AP") | |
8028 | msg = get_wsc_msg(hapd) | |
8029 | if msg['wsc_opcode'] != WSC_Start: | |
8030 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8031 | ||
8032 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8033 | uuid_e = 16*'\x11' | |
8034 | e_nonce = 16*'\x22' | |
8035 | own_private, e_pk = wsc_dh_init() | |
8036 | ||
8037 | logger.debug("Send M1 to AP") | |
8038 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8039 | e_nonce, e_pk) | |
8040 | send_wsc_msg(hapd, addr, m1) | |
8041 | ||
8042 | logger.debug("Receive M2 from AP") | |
8043 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8044 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8045 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8046 | ||
8047 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8048 | r_nonce) | |
8049 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8050 | ||
8051 | logger.debug("Send M3 to AP") | |
8052 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8053 | attrs += build_attr_msg_type(WPS_M3) | |
8054 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8055 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8056 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8057 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8058 | raw_m3_attrs = attrs | |
8059 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8060 | send_wsc_msg(hapd, addr, m3) | |
8061 | ||
8062 | logger.debug("Receive M4 from AP") | |
8063 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8064 | ||
8065 | logger.debug("Send M5 to AP") | |
8066 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8067 | attrs += build_attr_msg_type(WPS_M5) | |
8068 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8069 | data = build_wsc_attr(ATTR_E_SNONCE1, 16*'\x00') | |
8070 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8071 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8072 | raw_m5_attrs = attrs | |
8073 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8074 | send_wsc_msg(hapd, addr, m5) | |
8075 | ||
8076 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8077 | ||
8078 | def test_wps_ext_m7_missing_e_snonce2(dev, apdev): | |
8079 | """WPS proto: M7 missing E-SNonce2""" | |
8080 | pin = "12345670" | |
8081 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8082 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8083 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8084 | ||
8085 | logger.debug("Receive WSC/Start from AP") | |
8086 | msg = get_wsc_msg(hapd) | |
8087 | if msg['wsc_opcode'] != WSC_Start: | |
8088 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8089 | ||
8090 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8091 | uuid_e = 16*'\x11' | |
8092 | e_nonce = 16*'\x22' | |
8093 | own_private, e_pk = wsc_dh_init() | |
8094 | ||
8095 | logger.debug("Send M1 to AP") | |
8096 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8097 | e_nonce, e_pk) | |
8098 | send_wsc_msg(hapd, addr, m1) | |
8099 | ||
8100 | logger.debug("Receive M2 from AP") | |
8101 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8102 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8103 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8104 | ||
8105 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8106 | r_nonce) | |
8107 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8108 | ||
8109 | logger.debug("Send M3 to AP") | |
8110 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8111 | attrs += build_attr_msg_type(WPS_M3) | |
8112 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8113 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8114 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8115 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8116 | raw_m3_attrs = attrs | |
8117 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8118 | send_wsc_msg(hapd, addr, m3) | |
8119 | ||
8120 | logger.debug("Receive M4 from AP") | |
8121 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8122 | ||
8123 | logger.debug("Send M5 to AP") | |
8124 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8125 | attrs += build_attr_msg_type(WPS_M5) | |
8126 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8127 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8128 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8129 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8130 | raw_m5_attrs = attrs | |
8131 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8132 | send_wsc_msg(hapd, addr, m5) | |
8133 | ||
8134 | logger.debug("Receive M6 from AP") | |
8135 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
8136 | ||
8137 | logger.debug("Send M7 to AP") | |
8138 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8139 | attrs += build_attr_msg_type(WPS_M7) | |
8140 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8141 | #data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
8142 | data = '' | |
8143 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8144 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
8145 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8146 | raw_m7_attrs = attrs | |
8147 | send_wsc_msg(hapd, addr, m7) | |
8148 | ||
8149 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8150 | ||
9fd6804d | 8151 | @remote_compatible |
7511ead0 JM |
8152 | def test_wps_ext_m7_e_snonce2_mismatch(dev, apdev): |
8153 | """WPS proto: M7 E-SNonce2 mismatch""" | |
8154 | pin = "12345670" | |
8155 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8156 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8157 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8158 | ||
8159 | logger.debug("Receive WSC/Start from AP") | |
8160 | msg = get_wsc_msg(hapd) | |
8161 | if msg['wsc_opcode'] != WSC_Start: | |
8162 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8163 | ||
8164 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8165 | uuid_e = 16*'\x11' | |
8166 | e_nonce = 16*'\x22' | |
8167 | own_private, e_pk = wsc_dh_init() | |
8168 | ||
8169 | logger.debug("Send M1 to AP") | |
8170 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8171 | e_nonce, e_pk) | |
8172 | send_wsc_msg(hapd, addr, m1) | |
8173 | ||
8174 | logger.debug("Receive M2 from AP") | |
8175 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8176 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8177 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8178 | ||
8179 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8180 | r_nonce) | |
8181 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8182 | ||
8183 | logger.debug("Send M3 to AP") | |
8184 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8185 | attrs += build_attr_msg_type(WPS_M3) | |
8186 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8187 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8188 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8189 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8190 | raw_m3_attrs = attrs | |
8191 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8192 | send_wsc_msg(hapd, addr, m3) | |
8193 | ||
8194 | logger.debug("Receive M4 from AP") | |
8195 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8196 | ||
8197 | logger.debug("Send M5 to AP") | |
8198 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8199 | attrs += build_attr_msg_type(WPS_M5) | |
8200 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8201 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8202 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8203 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8204 | raw_m5_attrs = attrs | |
8205 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8206 | send_wsc_msg(hapd, addr, m5) | |
8207 | ||
8208 | logger.debug("Receive M6 from AP") | |
8209 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
8210 | ||
8211 | logger.debug("Send M7 to AP") | |
8212 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8213 | attrs += build_attr_msg_type(WPS_M7) | |
8214 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8215 | data = build_wsc_attr(ATTR_E_SNONCE2, 16*'\x00') | |
8216 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8217 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
8218 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8219 | raw_m7_attrs = attrs | |
8220 | send_wsc_msg(hapd, addr, m7) | |
8221 | ||
8222 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8223 | ||
9fd6804d | 8224 | @remote_compatible |
7511ead0 JM |
8225 | def test_wps_ext_m1_pubkey_oom(dev, apdev): |
8226 | """WPS proto: M1 PubKey OOM""" | |
8227 | pin = "12345670" | |
8228 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8229 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8230 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8231 | ||
8232 | logger.debug("Receive WSC/Start from AP") | |
8233 | msg = get_wsc_msg(hapd) | |
8234 | if msg['wsc_opcode'] != WSC_Start: | |
8235 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8236 | ||
8237 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8238 | uuid_e = 16*'\x11' | |
8239 | e_nonce = 16*'\x22' | |
8240 | own_private, e_pk = wsc_dh_init() | |
8241 | ||
8242 | logger.debug("Send M1 to AP") | |
8243 | with alloc_fail(hapd, 1, "wpabuf_alloc_copy;wps_process_pubkey"): | |
8244 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8245 | e_nonce, e_pk) | |
8246 | send_wsc_msg(hapd, addr, m1) | |
8247 | wps_wait_eap_failure(hapd, dev[0]) | |
8248 | ||
8249 | def wps_wait_eap_failure(hapd, dev): | |
8250 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
8251 | if ev is None: | |
8252 | raise Exception("EAP-Failure not reported") | |
8253 | dev.wait_disconnected() | |
8254 | ||
9fd6804d | 8255 | @remote_compatible |
7511ead0 JM |
8256 | def test_wps_ext_m3_m1(dev, apdev): |
8257 | """WPS proto: M3 replaced with M1""" | |
8258 | pin = "12345670" | |
8259 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8260 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8261 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8262 | ||
8263 | logger.debug("Receive WSC/Start from AP") | |
8264 | msg = get_wsc_msg(hapd) | |
8265 | if msg['wsc_opcode'] != WSC_Start: | |
8266 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8267 | ||
8268 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8269 | uuid_e = 16*'\x11' | |
8270 | e_nonce = 16*'\x22' | |
8271 | own_private, e_pk = wsc_dh_init() | |
8272 | ||
8273 | logger.debug("Send M1 to AP") | |
8274 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8275 | e_nonce, e_pk) | |
8276 | send_wsc_msg(hapd, addr, m1) | |
8277 | ||
8278 | logger.debug("Receive M2 from AP") | |
8279 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8280 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8281 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8282 | ||
8283 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8284 | r_nonce) | |
8285 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8286 | ||
8287 | logger.debug("Send M3(M1) to AP") | |
8288 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8289 | attrs += build_attr_msg_type(WPS_M1) | |
8290 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8291 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8292 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8293 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8294 | raw_m3_attrs = attrs | |
8295 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8296 | send_wsc_msg(hapd, addr, m3) | |
8297 | ||
8298 | wps_wait_eap_failure(hapd, dev[0]) | |
8299 | ||
9fd6804d | 8300 | @remote_compatible |
7511ead0 JM |
8301 | def test_wps_ext_m5_m3(dev, apdev): |
8302 | """WPS proto: M5 replaced with M3""" | |
8303 | pin = "12345670" | |
8304 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8305 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8306 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8307 | ||
8308 | logger.debug("Receive WSC/Start from AP") | |
8309 | msg = get_wsc_msg(hapd) | |
8310 | if msg['wsc_opcode'] != WSC_Start: | |
8311 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8312 | ||
8313 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8314 | uuid_e = 16*'\x11' | |
8315 | e_nonce = 16*'\x22' | |
8316 | own_private, e_pk = wsc_dh_init() | |
8317 | ||
8318 | logger.debug("Send M1 to AP") | |
8319 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8320 | e_nonce, e_pk) | |
8321 | send_wsc_msg(hapd, addr, m1) | |
8322 | ||
8323 | logger.debug("Receive M2 from AP") | |
8324 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8325 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8326 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8327 | ||
8328 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8329 | r_nonce) | |
8330 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8331 | ||
8332 | logger.debug("Send M3 to AP") | |
8333 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8334 | attrs += build_attr_msg_type(WPS_M3) | |
8335 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8336 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8337 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8338 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8339 | raw_m3_attrs = attrs | |
8340 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8341 | send_wsc_msg(hapd, addr, m3) | |
8342 | ||
8343 | logger.debug("Receive M4 from AP") | |
8344 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8345 | ||
8346 | logger.debug("Send M5(M3) to AP") | |
8347 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8348 | attrs += build_attr_msg_type(WPS_M3) | |
8349 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8350 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8351 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8352 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8353 | raw_m5_attrs = attrs | |
8354 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8355 | send_wsc_msg(hapd, addr, m5) | |
8356 | ||
8357 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8358 | ||
9fd6804d | 8359 | @remote_compatible |
7511ead0 JM |
8360 | def test_wps_ext_m3_m2(dev, apdev): |
8361 | """WPS proto: M3 replaced with M2""" | |
8362 | pin = "12345670" | |
8363 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8364 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8365 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8366 | ||
8367 | logger.debug("Receive WSC/Start from AP") | |
8368 | msg = get_wsc_msg(hapd) | |
8369 | if msg['wsc_opcode'] != WSC_Start: | |
8370 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8371 | ||
8372 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8373 | uuid_e = 16*'\x11' | |
8374 | e_nonce = 16*'\x22' | |
8375 | own_private, e_pk = wsc_dh_init() | |
8376 | ||
8377 | logger.debug("Send M1 to AP") | |
8378 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8379 | e_nonce, e_pk) | |
8380 | send_wsc_msg(hapd, addr, m1) | |
8381 | ||
8382 | logger.debug("Receive M2 from AP") | |
8383 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8384 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8385 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8386 | ||
8387 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8388 | r_nonce) | |
8389 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8390 | ||
8391 | logger.debug("Send M3(M2) to AP") | |
8392 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8393 | attrs += build_attr_msg_type(WPS_M2) | |
8394 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8395 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8396 | raw_m3_attrs = attrs | |
8397 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8398 | send_wsc_msg(hapd, addr, m3) | |
8399 | ||
8400 | wps_wait_eap_failure(hapd, dev[0]) | |
8401 | ||
9fd6804d | 8402 | @remote_compatible |
7511ead0 JM |
8403 | def test_wps_ext_m3_m5(dev, apdev): |
8404 | """WPS proto: M3 replaced with M5""" | |
8405 | pin = "12345670" | |
8406 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8407 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8408 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8409 | ||
8410 | logger.debug("Receive WSC/Start from AP") | |
8411 | msg = get_wsc_msg(hapd) | |
8412 | if msg['wsc_opcode'] != WSC_Start: | |
8413 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8414 | ||
8415 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8416 | uuid_e = 16*'\x11' | |
8417 | e_nonce = 16*'\x22' | |
8418 | own_private, e_pk = wsc_dh_init() | |
8419 | ||
8420 | logger.debug("Send M1 to AP") | |
8421 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8422 | e_nonce, e_pk) | |
8423 | send_wsc_msg(hapd, addr, m1) | |
8424 | ||
8425 | logger.debug("Receive M2 from AP") | |
8426 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8427 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8428 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8429 | ||
8430 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8431 | r_nonce) | |
8432 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8433 | ||
8434 | logger.debug("Send M3(M5) to AP") | |
8435 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8436 | attrs += build_attr_msg_type(WPS_M5) | |
8437 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8438 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8439 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8440 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8441 | raw_m3_attrs = attrs | |
8442 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8443 | send_wsc_msg(hapd, addr, m3) | |
8444 | ||
8445 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8446 | ||
9fd6804d | 8447 | @remote_compatible |
7511ead0 JM |
8448 | def test_wps_ext_m3_m7(dev, apdev): |
8449 | """WPS proto: M3 replaced with M7""" | |
8450 | pin = "12345670" | |
8451 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8452 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8453 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8454 | ||
8455 | logger.debug("Receive WSC/Start from AP") | |
8456 | msg = get_wsc_msg(hapd) | |
8457 | if msg['wsc_opcode'] != WSC_Start: | |
8458 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8459 | ||
8460 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8461 | uuid_e = 16*'\x11' | |
8462 | e_nonce = 16*'\x22' | |
8463 | own_private, e_pk = wsc_dh_init() | |
8464 | ||
8465 | logger.debug("Send M1 to AP") | |
8466 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8467 | e_nonce, e_pk) | |
8468 | send_wsc_msg(hapd, addr, m1) | |
8469 | ||
8470 | logger.debug("Receive M2 from AP") | |
8471 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8472 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8473 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8474 | ||
8475 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8476 | r_nonce) | |
8477 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8478 | ||
8479 | logger.debug("Send M3(M7) to AP") | |
8480 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8481 | attrs += build_attr_msg_type(WPS_M7) | |
8482 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8483 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8484 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8485 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8486 | raw_m3_attrs = attrs | |
8487 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8488 | send_wsc_msg(hapd, addr, m3) | |
8489 | ||
8490 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8491 | ||
9fd6804d | 8492 | @remote_compatible |
7511ead0 JM |
8493 | def test_wps_ext_m3_done(dev, apdev): |
8494 | """WPS proto: M3 replaced with WSC_Done""" | |
8495 | pin = "12345670" | |
8496 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8497 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8498 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8499 | ||
8500 | logger.debug("Receive WSC/Start from AP") | |
8501 | msg = get_wsc_msg(hapd) | |
8502 | if msg['wsc_opcode'] != WSC_Start: | |
8503 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8504 | ||
8505 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8506 | uuid_e = 16*'\x11' | |
8507 | e_nonce = 16*'\x22' | |
8508 | own_private, e_pk = wsc_dh_init() | |
8509 | ||
8510 | logger.debug("Send M1 to AP") | |
8511 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8512 | e_nonce, e_pk) | |
8513 | send_wsc_msg(hapd, addr, m1) | |
8514 | ||
8515 | logger.debug("Receive M2 from AP") | |
8516 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8517 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8518 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8519 | ||
8520 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8521 | r_nonce) | |
8522 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8523 | ||
8524 | logger.debug("Send M3(WSC_Done) to AP") | |
8525 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8526 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
8527 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8528 | raw_m3_attrs = attrs | |
8529 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
8530 | send_wsc_msg(hapd, addr, m3) | |
8531 | ||
8532 | wps_wait_eap_failure(hapd, dev[0]) | |
8533 | ||
9fd6804d | 8534 | @remote_compatible |
7511ead0 JM |
8535 | def test_wps_ext_m2_nack_invalid(dev, apdev): |
8536 | """WPS proto: M2 followed by invalid NACK""" | |
8537 | pin = "12345670" | |
8538 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8539 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8540 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8541 | ||
8542 | logger.debug("Receive WSC/Start from AP") | |
8543 | msg = get_wsc_msg(hapd) | |
8544 | if msg['wsc_opcode'] != WSC_Start: | |
8545 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8546 | ||
8547 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8548 | uuid_e = 16*'\x11' | |
8549 | e_nonce = 16*'\x22' | |
8550 | own_private, e_pk = wsc_dh_init() | |
8551 | ||
8552 | logger.debug("Send M1 to AP") | |
8553 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8554 | e_nonce, e_pk) | |
8555 | send_wsc_msg(hapd, addr, m1) | |
8556 | ||
8557 | logger.debug("Receive M2 from AP") | |
8558 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8559 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8560 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8561 | ||
8562 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8563 | r_nonce) | |
8564 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8565 | ||
8566 | logger.debug("Send WSC_NACK to AP") | |
8567 | attrs = '\x10\x00\x00' | |
8568 | nack = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_NACK) | |
8569 | send_wsc_msg(hapd, addr, nack) | |
8570 | ||
8571 | wps_wait_eap_failure(hapd, dev[0]) | |
8572 | ||
9fd6804d | 8573 | @remote_compatible |
7511ead0 JM |
8574 | def test_wps_ext_m2_nack_no_msg_type(dev, apdev): |
8575 | """WPS proto: M2 followed by NACK without Msg Type""" | |
8576 | pin = "12345670" | |
8577 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8578 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8579 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8580 | ||
8581 | logger.debug("Receive WSC/Start from AP") | |
8582 | msg = get_wsc_msg(hapd) | |
8583 | if msg['wsc_opcode'] != WSC_Start: | |
8584 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8585 | ||
8586 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8587 | uuid_e = 16*'\x11' | |
8588 | e_nonce = 16*'\x22' | |
8589 | own_private, e_pk = wsc_dh_init() | |
8590 | ||
8591 | logger.debug("Send M1 to AP") | |
8592 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8593 | e_nonce, e_pk) | |
8594 | send_wsc_msg(hapd, addr, m1) | |
8595 | ||
8596 | logger.debug("Receive M2 from AP") | |
8597 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8598 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8599 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8600 | ||
8601 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8602 | r_nonce) | |
8603 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8604 | ||
8605 | logger.debug("Send WSC_NACK to AP") | |
8606 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
8607 | msg_type=None, eap_code=2) | |
8608 | send_wsc_msg(hapd, addr, nack) | |
8609 | ||
8610 | wps_wait_eap_failure(hapd, dev[0]) | |
8611 | ||
9fd6804d | 8612 | @remote_compatible |
7511ead0 JM |
8613 | def test_wps_ext_m2_nack_invalid_msg_type(dev, apdev): |
8614 | """WPS proto: M2 followed by NACK with invalid Msg Type""" | |
8615 | pin = "12345670" | |
8616 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8617 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8618 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8619 | ||
8620 | logger.debug("Receive WSC/Start from AP") | |
8621 | msg = get_wsc_msg(hapd) | |
8622 | if msg['wsc_opcode'] != WSC_Start: | |
8623 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8624 | ||
8625 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8626 | uuid_e = 16*'\x11' | |
8627 | e_nonce = 16*'\x22' | |
8628 | own_private, e_pk = wsc_dh_init() | |
8629 | ||
8630 | logger.debug("Send M1 to AP") | |
8631 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8632 | e_nonce, e_pk) | |
8633 | send_wsc_msg(hapd, addr, m1) | |
8634 | ||
8635 | logger.debug("Receive M2 from AP") | |
8636 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8637 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8638 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8639 | ||
8640 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8641 | r_nonce) | |
8642 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8643 | ||
8644 | logger.debug("Send WSC_NACK to AP") | |
8645 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
8646 | msg_type=WPS_WSC_ACK, eap_code=2) | |
8647 | send_wsc_msg(hapd, addr, nack) | |
8648 | ||
8649 | wps_wait_eap_failure(hapd, dev[0]) | |
8650 | ||
9fd6804d | 8651 | @remote_compatible |
7511ead0 JM |
8652 | def test_wps_ext_m2_nack_e_nonce_mismatch(dev, apdev): |
8653 | """WPS proto: M2 followed by NACK with e-nonce mismatch""" | |
8654 | pin = "12345670" | |
8655 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8656 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8657 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8658 | ||
8659 | logger.debug("Receive WSC/Start from AP") | |
8660 | msg = get_wsc_msg(hapd) | |
8661 | if msg['wsc_opcode'] != WSC_Start: | |
8662 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8663 | ||
8664 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8665 | uuid_e = 16*'\x11' | |
8666 | e_nonce = 16*'\x22' | |
8667 | own_private, e_pk = wsc_dh_init() | |
8668 | ||
8669 | logger.debug("Send M1 to AP") | |
8670 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8671 | e_nonce, e_pk) | |
8672 | send_wsc_msg(hapd, addr, m1) | |
8673 | ||
8674 | logger.debug("Receive M2 from AP") | |
8675 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8676 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8677 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8678 | ||
8679 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8680 | r_nonce) | |
8681 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8682 | ||
8683 | logger.debug("Send WSC_NACK to AP") | |
8684 | nack,attrs = build_nack(msg['eap_identifier'], 16*'\x00', r_nonce, | |
8685 | eap_code=2) | |
8686 | send_wsc_msg(hapd, addr, nack) | |
8687 | ||
8688 | wps_wait_eap_failure(hapd, dev[0]) | |
8689 | ||
9fd6804d | 8690 | @remote_compatible |
7511ead0 JM |
8691 | def test_wps_ext_m2_nack_no_config_error(dev, apdev): |
8692 | """WPS proto: M2 followed by NACK without Config Error""" | |
8693 | pin = "12345670" | |
8694 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8695 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8696 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8697 | ||
8698 | logger.debug("Receive WSC/Start from AP") | |
8699 | msg = get_wsc_msg(hapd) | |
8700 | if msg['wsc_opcode'] != WSC_Start: | |
8701 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8702 | ||
8703 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8704 | uuid_e = 16*'\x11' | |
8705 | e_nonce = 16*'\x22' | |
8706 | own_private, e_pk = wsc_dh_init() | |
8707 | ||
8708 | logger.debug("Send M1 to AP") | |
8709 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8710 | e_nonce, e_pk) | |
8711 | send_wsc_msg(hapd, addr, m1) | |
8712 | ||
8713 | logger.debug("Receive M2 from AP") | |
8714 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8715 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8716 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8717 | ||
8718 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8719 | r_nonce) | |
8720 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8721 | ||
8722 | logger.debug("Send WSC_NACK to AP") | |
8723 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
8724 | config_error=None, eap_code=2) | |
8725 | send_wsc_msg(hapd, addr, nack) | |
8726 | ||
8727 | wps_wait_eap_failure(hapd, dev[0]) | |
8728 | ||
9fd6804d | 8729 | @remote_compatible |
7511ead0 JM |
8730 | def test_wps_ext_m2_ack_invalid(dev, apdev): |
8731 | """WPS proto: M2 followed by invalid ACK""" | |
8732 | pin = "12345670" | |
8733 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8734 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8735 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8736 | ||
8737 | logger.debug("Receive WSC/Start from AP") | |
8738 | msg = get_wsc_msg(hapd) | |
8739 | if msg['wsc_opcode'] != WSC_Start: | |
8740 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8741 | ||
8742 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8743 | uuid_e = 16*'\x11' | |
8744 | e_nonce = 16*'\x22' | |
8745 | own_private, e_pk = wsc_dh_init() | |
8746 | ||
8747 | logger.debug("Send M1 to AP") | |
8748 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8749 | e_nonce, e_pk) | |
8750 | send_wsc_msg(hapd, addr, m1) | |
8751 | ||
8752 | logger.debug("Receive M2 from AP") | |
8753 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8754 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8755 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8756 | ||
8757 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8758 | r_nonce) | |
8759 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8760 | ||
8761 | logger.debug("Send WSC_ACK to AP") | |
8762 | attrs = '\x10\x00\x00' | |
8763 | ack = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_ACK) | |
8764 | send_wsc_msg(hapd, addr, ack) | |
8765 | ||
8766 | wps_wait_eap_failure(hapd, dev[0]) | |
8767 | ||
9fd6804d | 8768 | @remote_compatible |
7511ead0 JM |
8769 | def test_wps_ext_m2_ack(dev, apdev): |
8770 | """WPS proto: M2 followed by ACK""" | |
8771 | pin = "12345670" | |
8772 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8773 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8774 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8775 | ||
8776 | logger.debug("Receive WSC/Start from AP") | |
8777 | msg = get_wsc_msg(hapd) | |
8778 | if msg['wsc_opcode'] != WSC_Start: | |
8779 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8780 | ||
8781 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8782 | uuid_e = 16*'\x11' | |
8783 | e_nonce = 16*'\x22' | |
8784 | own_private, e_pk = wsc_dh_init() | |
8785 | ||
8786 | logger.debug("Send M1 to AP") | |
8787 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8788 | e_nonce, e_pk) | |
8789 | send_wsc_msg(hapd, addr, m1) | |
8790 | ||
8791 | logger.debug("Receive M2 from AP") | |
8792 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8793 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8794 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8795 | ||
8796 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8797 | r_nonce) | |
8798 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8799 | ||
8800 | logger.debug("Send WSC_ACK to AP") | |
8801 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, eap_code=2) | |
8802 | send_wsc_msg(hapd, addr, ack) | |
8803 | ||
8804 | wps_wait_eap_failure(hapd, dev[0]) | |
8805 | ||
9fd6804d | 8806 | @remote_compatible |
7511ead0 JM |
8807 | def test_wps_ext_m2_ack_no_msg_type(dev, apdev): |
8808 | """WPS proto: M2 followed by ACK missing Msg Type""" | |
8809 | pin = "12345670" | |
8810 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8811 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8812 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8813 | ||
8814 | logger.debug("Receive WSC/Start from AP") | |
8815 | msg = get_wsc_msg(hapd) | |
8816 | if msg['wsc_opcode'] != WSC_Start: | |
8817 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8818 | ||
8819 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8820 | uuid_e = 16*'\x11' | |
8821 | e_nonce = 16*'\x22' | |
8822 | own_private, e_pk = wsc_dh_init() | |
8823 | ||
8824 | logger.debug("Send M1 to AP") | |
8825 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8826 | e_nonce, e_pk) | |
8827 | send_wsc_msg(hapd, addr, m1) | |
8828 | ||
8829 | logger.debug("Receive M2 from AP") | |
8830 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8831 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8832 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8833 | ||
8834 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8835 | r_nonce) | |
8836 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8837 | ||
8838 | logger.debug("Send WSC_ACK to AP") | |
8839 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, | |
8840 | msg_type=None, eap_code=2) | |
8841 | send_wsc_msg(hapd, addr, ack) | |
8842 | ||
8843 | wps_wait_eap_failure(hapd, dev[0]) | |
8844 | ||
9fd6804d | 8845 | @remote_compatible |
7511ead0 JM |
8846 | def test_wps_ext_m2_ack_invalid_msg_type(dev, apdev): |
8847 | """WPS proto: M2 followed by ACK with invalid Msg Type""" | |
8848 | pin = "12345670" | |
8849 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8850 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8851 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8852 | ||
8853 | logger.debug("Receive WSC/Start from AP") | |
8854 | msg = get_wsc_msg(hapd) | |
8855 | if msg['wsc_opcode'] != WSC_Start: | |
8856 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8857 | ||
8858 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8859 | uuid_e = 16*'\x11' | |
8860 | e_nonce = 16*'\x22' | |
8861 | own_private, e_pk = wsc_dh_init() | |
8862 | ||
8863 | logger.debug("Send M1 to AP") | |
8864 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8865 | e_nonce, e_pk) | |
8866 | send_wsc_msg(hapd, addr, m1) | |
8867 | ||
8868 | logger.debug("Receive M2 from AP") | |
8869 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8870 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8871 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8872 | ||
8873 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8874 | r_nonce) | |
8875 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8876 | ||
8877 | logger.debug("Send WSC_ACK to AP") | |
8878 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, | |
8879 | msg_type=WPS_WSC_NACK, eap_code=2) | |
8880 | send_wsc_msg(hapd, addr, ack) | |
8881 | ||
8882 | wps_wait_eap_failure(hapd, dev[0]) | |
8883 | ||
9fd6804d | 8884 | @remote_compatible |
7511ead0 JM |
8885 | def test_wps_ext_m2_ack_e_nonce_mismatch(dev, apdev): |
8886 | """WPS proto: M2 followed by ACK with e-nonce mismatch""" | |
8887 | pin = "12345670" | |
8888 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8889 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8890 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8891 | ||
8892 | logger.debug("Receive WSC/Start from AP") | |
8893 | msg = get_wsc_msg(hapd) | |
8894 | if msg['wsc_opcode'] != WSC_Start: | |
8895 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8896 | ||
8897 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8898 | uuid_e = 16*'\x11' | |
8899 | e_nonce = 16*'\x22' | |
8900 | own_private, e_pk = wsc_dh_init() | |
8901 | ||
8902 | logger.debug("Send M1 to AP") | |
8903 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8904 | e_nonce, e_pk) | |
8905 | send_wsc_msg(hapd, addr, m1) | |
8906 | ||
8907 | logger.debug("Receive M2 from AP") | |
8908 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8909 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8910 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8911 | ||
8912 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8913 | r_nonce) | |
8914 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8915 | ||
8916 | logger.debug("Send WSC_ACK to AP") | |
8917 | ack,attrs = build_ack(msg['eap_identifier'], 16*'\x00', r_nonce, | |
8918 | eap_code=2) | |
8919 | send_wsc_msg(hapd, addr, ack) | |
8920 | ||
8921 | wps_wait_eap_failure(hapd, dev[0]) | |
8922 | ||
9fd6804d | 8923 | @remote_compatible |
7511ead0 JM |
8924 | def test_wps_ext_m1_invalid(dev, apdev): |
8925 | """WPS proto: M1 failing parsing""" | |
8926 | pin = "12345670" | |
8927 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8928 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8929 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8930 | ||
8931 | logger.debug("Receive WSC/Start from AP") | |
8932 | msg = get_wsc_msg(hapd) | |
8933 | if msg['wsc_opcode'] != WSC_Start: | |
8934 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8935 | ||
8936 | logger.debug("Send M1 to AP") | |
8937 | attrs = '\x10\x00\x00' | |
8938 | m1 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8939 | send_wsc_msg(hapd, addr, m1) | |
8940 | ||
8941 | wps_wait_eap_failure(hapd, dev[0]) | |
8942 | ||
8943 | def test_wps_ext_m1_missing_msg_type(dev, apdev): | |
8944 | """WPS proto: M1 missing Msg Type""" | |
8945 | pin = "12345670" | |
8946 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8947 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8948 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8949 | ||
8950 | logger.debug("Receive WSC/Start from AP") | |
8951 | msg = get_wsc_msg(hapd) | |
8952 | if msg['wsc_opcode'] != WSC_Start: | |
8953 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8954 | ||
8955 | logger.debug("Send M1 to AP") | |
8956 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8957 | m1 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8958 | send_wsc_msg(hapd, addr, m1) | |
8959 | ||
8960 | wps_wait_ap_nack(hapd, dev[0], 16*'\x00', 16*'\x00') | |
8961 | ||
8962 | def wps_ext_wsc_done(dev, apdev): | |
8963 | pin = "12345670" | |
8964 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8965 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8966 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8967 | ||
8968 | logger.debug("Receive WSC/Start from AP") | |
8969 | msg = get_wsc_msg(hapd) | |
8970 | if msg['wsc_opcode'] != WSC_Start: | |
8971 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8972 | ||
8973 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8974 | uuid_e = 16*'\x11' | |
8975 | e_nonce = 16*'\x22' | |
8976 | own_private, e_pk = wsc_dh_init() | |
8977 | ||
8978 | logger.debug("Send M1 to AP") | |
8979 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8980 | e_nonce, e_pk) | |
8981 | send_wsc_msg(hapd, addr, m1) | |
8982 | ||
8983 | logger.debug("Receive M2 from AP") | |
8984 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8985 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8986 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8987 | ||
8988 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8989 | r_nonce) | |
8990 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8991 | ||
8992 | logger.debug("Send M3 to AP") | |
8993 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8994 | attrs += build_attr_msg_type(WPS_M3) | |
8995 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8996 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8997 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8998 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8999 | raw_m3_attrs = attrs | |
9000 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9001 | send_wsc_msg(hapd, addr, m3) | |
9002 | ||
9003 | logger.debug("Receive M4 from AP") | |
9004 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
9005 | ||
9006 | logger.debug("Send M5 to AP") | |
9007 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9008 | attrs += build_attr_msg_type(WPS_M5) | |
9009 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9010 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
9011 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9012 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
9013 | raw_m5_attrs = attrs | |
9014 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9015 | send_wsc_msg(hapd, addr, m5) | |
9016 | ||
9017 | logger.debug("Receive M6 from AP") | |
9018 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
9019 | ||
9020 | logger.debug("Send M7 to AP") | |
9021 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9022 | attrs += build_attr_msg_type(WPS_M7) | |
9023 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9024 | data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
9025 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9026 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
9027 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9028 | raw_m7_attrs = attrs | |
9029 | send_wsc_msg(hapd, addr, m7) | |
9030 | ||
9031 | logger.debug("Receive M8 from AP") | |
9032 | msg, m8_attrs, raw_m8_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M8) | |
9033 | return hapd, msg, e_nonce, r_nonce | |
9034 | ||
9fd6804d | 9035 | @remote_compatible |
7511ead0 JM |
9036 | def test_wps_ext_wsc_done_invalid(dev, apdev): |
9037 | """WPS proto: invalid WSC_Done""" | |
9038 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9039 | ||
9040 | logger.debug("Send WSC_Done to AP") | |
9041 | attrs = '\x10\x00\x00' | |
9042 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9043 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9044 | ||
9045 | wps_wait_eap_failure(hapd, dev[0]) | |
9046 | ||
9fd6804d | 9047 | @remote_compatible |
7511ead0 JM |
9048 | def test_wps_ext_wsc_done_no_msg_type(dev, apdev): |
9049 | """WPS proto: invalid WSC_Done""" | |
9050 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9051 | ||
9052 | logger.debug("Send WSC_Done to AP") | |
9053 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9054 | #attrs += build_attr_msg_type(WPS_WSC_DONE) | |
9055 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
9056 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9057 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9058 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9059 | ||
9060 | wps_wait_eap_failure(hapd, dev[0]) | |
9061 | ||
9fd6804d | 9062 | @remote_compatible |
7511ead0 JM |
9063 | def test_wps_ext_wsc_done_wrong_msg_type(dev, apdev): |
9064 | """WPS proto: WSC_Done with wrong Msg Type""" | |
9065 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9066 | ||
9067 | logger.debug("Send WSC_Done to AP") | |
9068 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9069 | attrs += build_attr_msg_type(WPS_WSC_ACK) | |
9070 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
9071 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9072 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9073 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9074 | ||
9075 | wps_wait_eap_failure(hapd, dev[0]) | |
9076 | ||
9fd6804d | 9077 | @remote_compatible |
7511ead0 JM |
9078 | def test_wps_ext_wsc_done_no_e_nonce(dev, apdev): |
9079 | """WPS proto: WSC_Done without e_nonce""" | |
9080 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9081 | ||
9082 | logger.debug("Send WSC_Done to AP") | |
9083 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9084 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
9085 | #attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
9086 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9087 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9088 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9089 | ||
9090 | wps_wait_eap_failure(hapd, dev[0]) | |
9091 | ||
9092 | def test_wps_ext_wsc_done_no_r_nonce(dev, apdev): | |
9093 | """WPS proto: WSC_Done without r_nonce""" | |
9094 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9095 | ||
9096 | logger.debug("Send WSC_Done to AP") | |
9097 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9098 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
9099 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
9100 | #attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9101 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9102 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9103 | ||
9104 | wps_wait_eap_failure(hapd, dev[0]) | |
9105 | ||
9fd6804d | 9106 | @remote_compatible |
7511ead0 JM |
9107 | def test_wps_ext_m7_no_encr_settings(dev, apdev): |
9108 | """WPS proto: M7 without Encr Settings""" | |
9109 | pin = "12345670" | |
9110 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
9111 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
9112 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
9113 | ||
9114 | logger.debug("Receive WSC/Start from AP") | |
9115 | msg = get_wsc_msg(hapd) | |
9116 | if msg['wsc_opcode'] != WSC_Start: | |
9117 | raise Exception("Unexpected Op-Code for WSC/Start") | |
9118 | ||
9119 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
9120 | uuid_e = 16*'\x11' | |
9121 | e_nonce = 16*'\x22' | |
9122 | own_private, e_pk = wsc_dh_init() | |
9123 | ||
9124 | logger.debug("Send M1 to AP") | |
9125 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
9126 | e_nonce, e_pk) | |
9127 | send_wsc_msg(hapd, addr, m1) | |
9128 | ||
9129 | logger.debug("Receive M2 from AP") | |
9130 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
9131 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
9132 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
9133 | ||
9134 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
9135 | r_nonce) | |
9136 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
9137 | ||
9138 | logger.debug("Send M3 to AP") | |
9139 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9140 | attrs += build_attr_msg_type(WPS_M3) | |
9141 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9142 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
9143 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
9144 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
9145 | raw_m3_attrs = attrs | |
9146 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9147 | send_wsc_msg(hapd, addr, m3) | |
9148 | ||
9149 | logger.debug("Receive M4 from AP") | |
9150 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
9151 | ||
9152 | logger.debug("Send M5 to AP") | |
9153 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9154 | attrs += build_attr_msg_type(WPS_M5) | |
9155 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9156 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
9157 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9158 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
9159 | raw_m5_attrs = attrs | |
9160 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9161 | send_wsc_msg(hapd, addr, m5) | |
9162 | ||
9163 | logger.debug("Receive M6 from AP") | |
9164 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
9165 | ||
9166 | logger.debug("Send M7 to AP") | |
9167 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9168 | attrs += build_attr_msg_type(WPS_M7) | |
9169 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9170 | #data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
9171 | #attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9172 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
9173 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9174 | raw_m7_attrs = attrs | |
9175 | send_wsc_msg(hapd, addr, m7) | |
9176 | ||
9177 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
9178 | ||
9fd6804d | 9179 | @remote_compatible |
7511ead0 JM |
9180 | def test_wps_ext_m1_workaround(dev, apdev): |
9181 | """WPS proto: M1 Manufacturer/Model workaround""" | |
9182 | pin = "12345670" | |
9183 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
9184 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
9185 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
9186 | ||
9187 | logger.debug("Receive WSC/Start from AP") | |
9188 | msg = get_wsc_msg(hapd) | |
9189 | if msg['wsc_opcode'] != WSC_Start: | |
9190 | raise Exception("Unexpected Op-Code for WSC/Start") | |
9191 | ||
9192 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
9193 | uuid_e = 16*'\x11' | |
9194 | e_nonce = 16*'\x22' | |
9195 | own_private, e_pk = wsc_dh_init() | |
9196 | ||
9197 | logger.debug("Send M1 to AP") | |
9198 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
9199 | e_nonce, e_pk, manufacturer='Apple TEST', | |
9200 | model_name='AirPort', config_methods='\xff\xff') | |
9201 | send_wsc_msg(hapd, addr, m1) | |
9202 | ||
9203 | logger.debug("Receive M2 from AP") | |
9204 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
53bd8653 | 9205 | |
9fd6804d | 9206 | @remote_compatible |
53bd8653 JM |
9207 | def test_ap_wps_disable_enable(dev, apdev): |
9208 | """WPS and DISABLE/ENABLE AP""" | |
9209 | hapd = wps_start_ap(apdev[0]) | |
9210 | hapd.disable() | |
9211 | hapd.enable() | |
9212 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
dd124ee8 JM |
9213 | |
9214 | def test_ap_wps_upnp_web_oom(dev, apdev, params): | |
9215 | """hostapd WPS UPnP web OOM""" | |
9216 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 9217 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
dd124ee8 JM |
9218 | |
9219 | location = ssdp_get_location(ap_uuid) | |
9220 | url = urlparse.urlparse(location) | |
9221 | urls = upnp_get_urls(location) | |
9222 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
9223 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
9224 | ||
9225 | conn = httplib.HTTPConnection(url.netloc) | |
9226 | with alloc_fail(hapd, 1, "web_connection_parse_get"): | |
9227 | conn.request("GET", "/wps_device.xml") | |
9228 | try: | |
9229 | resp = conn.getresponse() | |
9230 | except: | |
9231 | pass | |
9232 | ||
9233 | conn = httplib.HTTPConnection(url.netloc) | |
9234 | conn.request("GET", "/unknown") | |
9235 | resp = conn.getresponse() | |
9236 | if resp.status != 404: | |
9237 | raise Exception("Unexpected HTTP result for unknown URL: %d" + resp.status) | |
9238 | ||
9239 | with alloc_fail(hapd, 1, "web_connection_parse_get"): | |
9240 | conn.request("GET", "/unknown") | |
9241 | try: | |
9242 | resp = conn.getresponse() | |
9243 | print resp.status | |
9244 | except: | |
9245 | pass | |
9246 | ||
9247 | conn = httplib.HTTPConnection(url.netloc) | |
9248 | conn.request("GET", "/wps_device.xml") | |
9249 | resp = conn.getresponse() | |
9250 | if resp.status != 200: | |
9251 | raise Exception("GET /wps_device.xml failed") | |
9252 | ||
9253 | conn = httplib.HTTPConnection(url.netloc) | |
9254 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9255 | if resp.status != 200: | |
9256 | raise Exception("GetDeviceInfo failed") | |
9257 | ||
9258 | with alloc_fail(hapd, 1, "web_process_get_device_info"): | |
9259 | conn = httplib.HTTPConnection(url.netloc) | |
9260 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9261 | if resp.status != 500: | |
9262 | raise Exception("Internal error not reported from GetDeviceInfo OOM") | |
9263 | ||
9264 | with alloc_fail(hapd, 1, "wps_build_m1;web_process_get_device_info"): | |
9265 | conn = httplib.HTTPConnection(url.netloc) | |
9266 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9267 | if resp.status != 500: | |
9268 | raise Exception("Internal error not reported from GetDeviceInfo OOM") | |
9269 | ||
9270 | with alloc_fail(hapd, 1, "wpabuf_alloc;web_connection_send_reply"): | |
9271 | conn = httplib.HTTPConnection(url.netloc) | |
9272 | try: | |
9273 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9274 | except: | |
9275 | pass | |
9276 | ||
9277 | conn = httplib.HTTPConnection(url.netloc) | |
9278 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9279 | if resp.status != 200: | |
9280 | raise Exception("GetDeviceInfo failed") | |
9281 | ||
9282 | # No NewWLANEventType in PutWLANResponse NewMessage | |
9283 | conn = httplib.HTTPConnection(url.netloc) | |
9284 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo") | |
9285 | if resp.status != 600: | |
9286 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9287 | ||
9288 | # No NewWLANEventMAC in PutWLANResponse NewMessage | |
9289 | conn = httplib.HTTPConnection(url.netloc) | |
9290 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9291 | newmsg="foo", neweventtype="1") | |
9292 | if resp.status != 600: | |
9293 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9294 | ||
9295 | # Invalid NewWLANEventMAC in PutWLANResponse NewMessage | |
9296 | conn = httplib.HTTPConnection(url.netloc) | |
9297 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9298 | newmsg="foo", neweventtype="1", | |
9299 | neweventmac="foo") | |
9300 | if resp.status != 600: | |
9301 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9302 | ||
9303 | # Workaround for NewWLANEventMAC in PutWLANResponse NewMessage | |
9304 | # Ignored unexpected PutWLANResponse WLANEventType 1 | |
9305 | conn = httplib.HTTPConnection(url.netloc) | |
9306 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9307 | newmsg="foo", neweventtype="1", | |
9308 | neweventmac="00.11.22.33.44.55") | |
9309 | if resp.status != 500: | |
9310 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9311 | ||
9312 | # PutWLANResponse NewMessage with invalid EAP message | |
9313 | conn = httplib.HTTPConnection(url.netloc) | |
9314 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9315 | newmsg="foo", neweventtype="2", | |
9316 | neweventmac="00:11:22:33:44:55") | |
9317 | if resp.status != 200: | |
9318 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9319 | ||
9320 | with alloc_fail(hapd, 1, "web_connection_parse_subscribe"): | |
9321 | conn = httplib.HTTPConnection(url.netloc) | |
9322 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
9323 | "NT": "upnp:event", | |
9324 | "timeout": "Second-1234" } | |
9325 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
9326 | try: | |
9327 | resp = conn.getresponse() | |
9328 | except: | |
9329 | pass | |
9330 | ||
9331 | with alloc_fail(hapd, 1, "dup_binstr;web_connection_parse_subscribe"): | |
9332 | conn = httplib.HTTPConnection(url.netloc) | |
9333 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
9334 | "NT": "upnp:event", | |
9335 | "timeout": "Second-1234" } | |
9336 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
9337 | resp = conn.getresponse() | |
9338 | if resp.status != 500: | |
9339 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9340 | ||
9341 | with alloc_fail(hapd, 1, "wpabuf_alloc;web_connection_parse_unsubscribe"): | |
9342 | conn = httplib.HTTPConnection(url.netloc) | |
9343 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
9344 | "NT": "upnp:event", | |
9345 | "timeout": "Second-1234" } | |
9346 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
9347 | try: | |
9348 | resp = conn.getresponse() | |
9349 | except: | |
9350 | pass | |
9351 | ||
9352 | with alloc_fail(hapd, 1, "web_connection_unimplemented"): | |
9353 | conn = httplib.HTTPConnection(url.netloc) | |
9354 | conn.request("HEAD", "/wps_device.xml") | |
9355 | try: | |
9356 | resp = conn.getresponse() | |
9357 | except: | |
9358 | pass | |
d1341917 JM |
9359 | |
9360 | def test_ap_wps_frag_ack_oom(dev, apdev): | |
9361 | """WPS and fragment ack OOM""" | |
9362 | dev[0].request("SET wps_fragment_size 50") | |
9363 | hapd = wps_start_ap(apdev[0]) | |
9364 | with alloc_fail(hapd, 1, "eap_wsc_build_frag_ack"): | |
9365 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
1e35aa15 JM |
9366 | |
9367 | def wait_scan_stopped(dev): | |
9368 | dev.request("ABORT_SCAN") | |
9369 | for i in range(50): | |
9370 | res = dev.get_driver_status_field("scan_state") | |
9371 | if "SCAN_STARTED" not in res and "SCAN_REQUESTED" not in res: | |
9372 | break | |
9373 | logger.debug("Waiting for scan to complete") | |
9374 | time.sleep(0.1) | |
9375 | ||
9fd6804d | 9376 | @remote_compatible |
1e35aa15 JM |
9377 | def test_ap_wps_eap_wsc_errors(dev, apdev): |
9378 | """WPS and EAP-WSC error cases""" | |
9379 | ssid = "test-wps-conf-pin" | |
9380 | appin = "12345670" | |
9381 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9382 | "wpa_passphrase": "12345678", "wpa": "2", | |
9383 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9384 | "fragment_size": "300", "ap_pin": appin } | |
8b8a1864 | 9385 | hapd = hostapd.add_ap(apdev[0], params) |
1e35aa15 JM |
9386 | bssid = apdev[0]['bssid'] |
9387 | ||
9388 | pin = dev[0].wps_read_pin() | |
9389 | hapd.request("WPS_PIN any " + pin) | |
9390 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
9391 | dev[0].dump_monitor() | |
9392 | ||
9393 | dev[0].wps_reg(bssid, appin + " new_ssid=a", "new ssid", "WPA2PSK", "CCMP", | |
9394 | "new passphrase", no_wait=True) | |
9395 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9396 | if ev is None: | |
9397 | raise Exception("WPS-FAIL not reported") | |
9398 | dev[0].request("WPS_CANCEL") | |
9399 | dev[0].wait_disconnected() | |
9400 | wait_scan_stopped(dev[0]) | |
9401 | dev[0].dump_monitor() | |
9402 | ||
9403 | dev[0].wps_reg(bssid, appin, "new ssid", "FOO", "CCMP", | |
9404 | "new passphrase", no_wait=True) | |
9405 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9406 | if ev is None: | |
9407 | raise Exception("WPS-FAIL not reported") | |
9408 | dev[0].request("WPS_CANCEL") | |
9409 | dev[0].wait_disconnected() | |
9410 | wait_scan_stopped(dev[0]) | |
9411 | dev[0].dump_monitor() | |
9412 | ||
9413 | dev[0].wps_reg(bssid, appin, "new ssid", "WPA2PSK", "FOO", | |
9414 | "new passphrase", no_wait=True) | |
9415 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9416 | if ev is None: | |
9417 | raise Exception("WPS-FAIL not reported") | |
9418 | dev[0].request("WPS_CANCEL") | |
9419 | dev[0].wait_disconnected() | |
9420 | wait_scan_stopped(dev[0]) | |
9421 | dev[0].dump_monitor() | |
9422 | ||
9423 | dev[0].wps_reg(bssid, appin + "new_key=a", "new ssid", "WPA2PSK", "CCMP", | |
9424 | "new passphrase", no_wait=True) | |
9425 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9426 | if ev is None: | |
9427 | raise Exception("WPS-FAIL not reported") | |
9428 | dev[0].request("WPS_CANCEL") | |
9429 | dev[0].wait_disconnected() | |
9430 | wait_scan_stopped(dev[0]) | |
9431 | dev[0].dump_monitor() | |
9432 | ||
9433 | tests = [ "eap_wsc_init", | |
9434 | "eap_msg_alloc;eap_wsc_build_msg", | |
9435 | "wpabuf_alloc;eap_wsc_process_fragment" ] | |
9436 | for func in tests: | |
9437 | with alloc_fail(dev[0], 1, func): | |
9438 | dev[0].request("WPS_PIN %s %s" % (bssid, pin)) | |
9439 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
9440 | dev[0].request("WPS_CANCEL") | |
9441 | dev[0].wait_disconnected() | |
9442 | wait_scan_stopped(dev[0]) | |
9443 | dev[0].dump_monitor() | |
d8e5a55f | 9444 | |
bd3948c0 JM |
9445 | with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_sm_build_expanded_nak"): |
9446 | dev[0].wps_reg(bssid, appin + " new_ssid=a", "new ssid", "WPA2PSK", | |
9447 | "CCMP", "new passphrase", no_wait=True) | |
9448 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
9449 | dev[0].request("WPS_CANCEL") | |
9450 | dev[0].wait_disconnected() | |
9451 | wait_scan_stopped(dev[0]) | |
9452 | dev[0].dump_monitor() | |
9453 | ||
d8e5a55f JM |
9454 | def test_ap_wps_eap_wsc(dev, apdev): |
9455 | """WPS and EAP-WSC in network profile""" | |
9456 | params = int_eap_server_params() | |
9457 | params["wps_state"] = "2" | |
8b8a1864 | 9458 | hapd = hostapd.add_ap(apdev[0], params) |
d8e5a55f JM |
9459 | bssid = apdev[0]['bssid'] |
9460 | ||
9461 | logger.info("Unexpected identity") | |
9462 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9463 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-unexpected", | |
9464 | wait_connect=False) | |
9465 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9466 | if ev is None: | |
9467 | raise Exception("No EAP-Failure seen") | |
9468 | dev[0].request("REMOVE_NETWORK all") | |
9469 | dev[0].wait_disconnected() | |
9470 | ||
9471 | logger.info("No phase1 parameter") | |
9472 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9473 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9474 | wait_connect=False) | |
9475 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9476 | if ev is None: | |
9477 | raise Exception("Timeout on EAP method start") | |
9478 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9479 | if ev is None: | |
9480 | raise Exception("No EAP-Failure seen") | |
9481 | dev[0].request("REMOVE_NETWORK all") | |
9482 | dev[0].wait_disconnected() | |
9483 | ||
9484 | logger.info("No PIN/PBC in phase1") | |
9485 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9486 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9487 | phase1="foo", wait_connect=False) | |
9488 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9489 | if ev is None: | |
9490 | raise Exception("Timeout on EAP method start") | |
9491 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9492 | if ev is None: | |
9493 | raise Exception("No EAP-Failure seen") | |
9494 | dev[0].request("REMOVE_NETWORK all") | |
9495 | dev[0].wait_disconnected() | |
9496 | ||
9497 | logger.info("Invalid pkhash in phase1") | |
9498 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9499 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9500 | phase1="foo pkhash=q pbc=1", wait_connect=False) | |
9501 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9502 | if ev is None: | |
9503 | raise Exception("Timeout on EAP method start") | |
9504 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9505 | if ev is None: | |
9506 | raise Exception("No EAP-Failure seen") | |
9507 | dev[0].request("REMOVE_NETWORK all") | |
9508 | dev[0].wait_disconnected() | |
9509 | ||
9510 | logger.info("Zero fragment_size") | |
9511 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9512 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9513 | fragment_size="0", phase1="pin=12345670", wait_connect=False) | |
9514 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9515 | if ev is None: | |
9516 | raise Exception("Timeout on EAP method start") | |
9517 | ev = dev[0].wait_event(["WPS-M2D"], timeout=5) | |
9518 | if ev is None: | |
9519 | raise Exception("No M2D seen") | |
9520 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9521 | if ev is None: | |
9522 | raise Exception("No EAP-Failure seen") | |
9523 | dev[0].request("REMOVE_NETWORK all") | |
9524 | dev[0].wait_disconnected() | |
9525 | ||
9526 | logger.info("Missing new_auth") | |
9527 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9528 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9529 | phase1="pin=12345670 new_ssid=aa", wait_connect=False) | |
9530 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9531 | if ev is None: | |
9532 | raise Exception("Timeout on EAP method start") | |
9533 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9534 | if ev is None: | |
9535 | raise Exception("No EAP-Failure seen") | |
9536 | dev[0].request("REMOVE_NETWORK all") | |
9537 | dev[0].wait_disconnected() | |
9538 | ||
9539 | logger.info("Missing new_encr") | |
9540 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9541 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9542 | phase1="pin=12345670 new_auth=WPA2PSK new_ssid=aa", wait_connect=False) | |
9543 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9544 | if ev is None: | |
9545 | raise Exception("Timeout on EAP method start") | |
9546 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9547 | if ev is None: | |
9548 | raise Exception("No EAP-Failure seen") | |
9549 | dev[0].request("REMOVE_NETWORK all") | |
9550 | dev[0].wait_disconnected() | |
9551 | ||
9552 | logger.info("Missing new_key") | |
9553 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9554 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9555 | phase1="pin=12345670 new_auth=WPA2PSK new_ssid=aa new_encr=CCMP", | |
9556 | wait_connect=False) | |
9557 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9558 | if ev is None: | |
9559 | raise Exception("Timeout on EAP method start") | |
9560 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9561 | if ev is None: | |
9562 | raise Exception("No EAP-Failure seen") | |
9563 | dev[0].request("REMOVE_NETWORK all") | |
9564 | dev[0].wait_disconnected() | |
4425b1ed JM |
9565 | |
9566 | def test_ap_wps_and_bss_limit(dev, apdev): | |
9567 | """WPS and wpa_supplicant BSS entry limit""" | |
9568 | try: | |
9569 | _test_ap_wps_and_bss_limit(dev, apdev) | |
9570 | finally: | |
9571 | dev[0].request("SET bss_max_count 200") | |
9572 | pass | |
9573 | ||
9574 | def _test_ap_wps_and_bss_limit(dev, apdev): | |
9575 | params = { "ssid": "test-wps", "eap_server": "1", "wps_state": "2", | |
9576 | "wpa_passphrase": "12345678", "wpa": "2", | |
9577 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
9578 | hapd = hostapd.add_ap(apdev[0], params) | |
9579 | ||
9580 | params = { "ssid": "test-wps-2", "eap_server": "1", "wps_state": "2", | |
9581 | "wpa_passphrase": "1234567890", "wpa": "2", | |
9582 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
9583 | hapd2 = hostapd.add_ap(apdev[1], params) | |
9584 | ||
9585 | id = dev[1].add_network() | |
9586 | dev[1].set_network(id, "mode", "2") | |
9587 | dev[1].set_network_quoted(id, "ssid", "wpas-ap-no-wps") | |
9588 | dev[1].set_network_quoted(id, "psk", "12345678") | |
9589 | dev[1].set_network(id, "frequency", "2462") | |
9590 | dev[1].set_network(id, "scan_freq", "2462") | |
9591 | dev[1].set_network(id, "wps_disabled", "1") | |
9592 | dev[1].select_network(id) | |
9593 | ||
9594 | id = dev[2].add_network() | |
9595 | dev[2].set_network(id, "mode", "2") | |
9596 | dev[2].set_network_quoted(id, "ssid", "wpas-ap") | |
9597 | dev[2].set_network_quoted(id, "psk", "12345678") | |
9598 | dev[2].set_network(id, "frequency", "2437") | |
9599 | dev[2].set_network(id, "scan_freq", "2437") | |
9600 | dev[2].select_network(id) | |
9601 | ||
9602 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
9603 | wpas.interface_add("wlan5") | |
9604 | id = wpas.add_network() | |
9605 | wpas.set_network(id, "mode", "2") | |
9606 | wpas.set_network_quoted(id, "ssid", "wpas-ap") | |
9607 | wpas.set_network_quoted(id, "psk", "12345678") | |
9608 | wpas.set_network(id, "frequency", "2437") | |
9609 | wpas.set_network(id, "scan_freq", "2437") | |
9610 | wpas.select_network(id) | |
9611 | ||
9612 | dev[1].wait_connected() | |
9613 | dev[2].wait_connected() | |
9614 | wpas.wait_connected() | |
9615 | wpas.request("WPS_PIN any 12345670") | |
9616 | ||
9617 | hapd.request("WPS_PBC") | |
9618 | hapd2.request("WPS_PBC") | |
9619 | ||
9620 | dev[0].request("SET bss_max_count 1") | |
9621 | ||
9622 | id = dev[0].add_network() | |
9623 | dev[0].set_network_quoted(id, "ssid", "testing") | |
9624 | ||
9625 | id = dev[0].add_network() | |
9626 | dev[0].set_network_quoted(id, "ssid", "testing") | |
9627 | dev[0].set_network(id, "key_mgmt", "WPS") | |
9628 | ||
9629 | dev[0].request("WPS_PBC") | |
9630 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
9631 | dev[0].request("WPS_CANCEL") | |
9632 | ||
9633 | id = dev[0].add_network() | |
9634 | dev[0].set_network_quoted(id, "ssid", "testing") | |
9635 | dev[0].set_network(id, "key_mgmt", "WPS") | |
9636 | ||
9637 | dev[0].scan(freq="2412") | |
74b23faf JM |
9638 | |
9639 | def test_ap_wps_pbc_2ap(dev, apdev): | |
9640 | """WPS PBC with two APs advertising same SSID""" | |
9641 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
9642 | "wpa_passphrase": "12345678", "wpa": "2", | |
9643 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9644 | "wps_independent": "1"} | |
9645 | hapd = hostapd.add_ap(apdev[0], params) | |
9646 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
9647 | "wpa_passphrase": "123456789", "wpa": "2", | |
9648 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9649 | "wps_independent": "1"} | |
9650 | hapd2 = hostapd.add_ap(apdev[1], params) | |
9651 | hapd.request("WPS_PBC") | |
9652 | ||
9653 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
9654 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
9655 | wpas.dump_monitor() | |
9656 | ||
9657 | wpas.scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) | |
9658 | wpas.scan_for_bss(apdev[1]['bssid'], freq="2412") | |
9659 | wpas.request("WPS_PBC") | |
9660 | wpas.wait_connected() | |
9661 | wpas.request("DISCONNECT") | |
9662 | hapd.request("DISABLE") | |
9663 | hapd2.request("DISABLE") | |
9664 | wpas.flush_scan_cache() | |
aed9e23a JM |
9665 | |
9666 | def test_ap_wps_er_enrollee_to_conf_ap(dev, apdev): | |
9667 | """WPS ER enrolling a new device to a configured AP""" | |
9668 | try: | |
9669 | _test_ap_wps_er_enrollee_to_conf_ap(dev, apdev) | |
9670 | finally: | |
9671 | dev[0].request("WPS_ER_STOP") | |
9672 | ||
9673 | def _test_ap_wps_er_enrollee_to_conf_ap(dev, apdev): | |
9674 | ssid = "wps-er-enrollee-to-conf-ap" | |
9675 | ap_pin = "12345670" | |
9676 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
9677 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9678 | "wpa_passphrase": "12345678", "wpa": "2", | |
9679 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9680 | "device_name": "Wireless AP", "manufacturer": "Company", | |
9681 | "model_name": "WAP", "model_number": "123", | |
9682 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
9683 | "os_version": "01020300", | |
9684 | "config_methods": "label push_button", | |
9685 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"} | |
9686 | hapd = hostapd.add_ap(apdev[0], params) | |
9687 | bssid = hapd.own_addr() | |
9688 | ||
9689 | id = dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
9690 | dev[0].dump_monitor() | |
9691 | ||
9692 | dev[0].request("WPS_ER_START ifname=lo") | |
9693 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
9694 | if ev is None: | |
9695 | raise Exception("AP discovery timed out") | |
9696 | if ap_uuid not in ev: | |
9697 | raise Exception("Expected AP UUID not found") | |
9698 | ||
9699 | pin = dev[2].wps_read_pin() | |
9700 | addr2 = dev[2].own_addr() | |
9701 | dev[0].dump_monitor() | |
9702 | dev[2].scan_for_bss(bssid, freq=2412) | |
9703 | dev[2].dump_monitor() | |
9704 | dev[2].request("WPS_PIN %s %s" % (bssid, pin)) | |
9705 | ||
9706 | for i in range(3): | |
9707 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) | |
9708 | if ev is None: | |
9709 | raise Exception("Enrollee not seen") | |
9710 | if addr2 in ev: | |
9711 | break | |
9712 | if addr2 not in ev: | |
9713 | raise Exception("Unexpected Enrollee MAC address") | |
9714 | dev[0].dump_monitor() | |
9715 | ||
9716 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " " + str(id)) | |
9717 | dev[0].request("WPS_ER_PIN " + addr2 + " " + pin + " " + addr2) | |
9718 | dev[2].wait_connected(timeout=30) | |
9719 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
9720 | if ev is None: | |
9721 | raise Exception("WPS ER did not report success") | |
9722 | ||
9723 | def test_ap_wps_er_enrollee_to_conf_ap2(dev, apdev): | |
9724 | """WPS ER enrolling a new device to a configured AP (2)""" | |
9725 | try: | |
9726 | _test_ap_wps_er_enrollee_to_conf_ap2(dev, apdev) | |
9727 | finally: | |
9728 | dev[0].request("WPS_ER_STOP") | |
9729 | ||
9730 | def _test_ap_wps_er_enrollee_to_conf_ap2(dev, apdev): | |
9731 | ssid = "wps-er-enrollee-to-conf-ap" | |
9732 | ap_pin = "12345670" | |
9733 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
9734 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9735 | "wpa_passphrase": "12345678", "wpa": "2", | |
9736 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9737 | "device_name": "Wireless AP", "manufacturer": "Company", | |
9738 | "model_name": "WAP", "model_number": "123", | |
9739 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
9740 | "os_version": "01020300", | |
9741 | "config_methods": "label push_button", | |
9742 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"} | |
9743 | hapd = hostapd.add_ap(apdev[0], params) | |
9744 | bssid = hapd.own_addr() | |
9745 | ||
9746 | id = dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
9747 | dev[0].dump_monitor() | |
9748 | ||
9749 | dev[0].request("WPS_ER_START ifname=lo") | |
9750 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
9751 | if ev is None: | |
9752 | raise Exception("AP discovery timed out") | |
9753 | if ap_uuid not in ev: | |
9754 | raise Exception("Expected AP UUID not found") | |
9755 | ||
9756 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
9757 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
9758 | if ev is None: | |
9759 | raise Exception("AP learn timed out") | |
9760 | if ap_uuid not in ev: | |
9761 | raise Exception("Expected AP UUID not in settings") | |
9762 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
9763 | if ev is None: | |
9764 | raise Exception("WPS-FAIL after AP learn timed out") | |
9765 | time.sleep(0.1) | |
9766 | ||
9767 | pin = dev[1].wps_read_pin() | |
9768 | addr1 = dev[1].own_addr() | |
9769 | dev[0].dump_monitor() | |
9770 | dev[0].request("WPS_ER_PIN any " + pin) | |
9771 | time.sleep(0.1) | |
9772 | dev[1].scan_for_bss(bssid, freq=2412) | |
9773 | dev[1].request("WPS_PIN any %s" % pin) | |
9774 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) | |
9775 | if ev is None: | |
9776 | raise Exception("Enrollee did not report success") | |
9777 | dev[1].wait_connected(timeout=15) | |
9778 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
9779 | if ev is None: | |
9780 | raise Exception("WPS ER did not report success") |