]>
Commit | Line | Data |
---|---|---|
302b7a1b | 1 | # WPS tests |
3381d324 | 2 | # Copyright (c) 2013-2017, 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 | ||
82358a2a JM |
183 | if "FAIL" not in hapd.request("WPS_CONFIG foo"): |
184 | raise Exception("Invalid WPS_CONFIG accepted") | |
185 | ||
9fd6804d | 186 | @remote_compatible |
fbf6b717 JM |
187 | def test_ap_wps_init_through_wps_config_2(dev, apdev): |
188 | """AP configuration using wps_config and wps_cred_processing=2""" | |
189 | ssid = "test-wps-init-config" | |
6f334bf7 JD |
190 | hapd = hostapd.add_ap(apdev[0], |
191 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
192 | "wps_cred_processing": "2" }) | |
fbf6b717 JM |
193 | if "FAIL" in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")): |
194 | raise Exception("WPS_CONFIG command failed") | |
195 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5) | |
196 | if ev is None: | |
197 | raise Exception("Timeout on WPS-NEW-AP-SETTINGS events") | |
198 | if "100e" not in ev: | |
199 | raise Exception("WPS-NEW-AP-SETTINGS did not include Credential") | |
200 | ||
9fd6804d | 201 | @remote_compatible |
e1eb0e9e JM |
202 | def test_ap_wps_invalid_wps_config_passphrase(dev, apdev): |
203 | """AP configuration using wps_config command with invalid passphrase""" | |
204 | ssid = "test-wps-init-config" | |
6f334bf7 JD |
205 | hapd = hostapd.add_ap(apdev[0], |
206 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
e1eb0e9e JM |
207 | if "FAIL" not in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "1234567".encode("hex")): |
208 | raise Exception("Invalid WPS_CONFIG command accepted") | |
209 | ||
ae3ad328 | 210 | def test_ap_wps_conf(dev, apdev): |
302b7a1b JM |
211 | """WPS PBC provisioning with configured AP""" |
212 | ssid = "test-wps-conf" | |
6f334bf7 JD |
213 | hapd = hostapd.add_ap(apdev[0], |
214 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
215 | "wpa_passphrase": "12345678", "wpa": "2", | |
216 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
302b7a1b JM |
217 | logger.info("WPS provisioning step") |
218 | hapd.request("WPS_PBC") | |
33d0b157 | 219 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 220 | dev[0].dump_monitor() |
33d0b157 | 221 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 222 | dev[0].wait_connected(timeout=30) |
302b7a1b | 223 | status = dev[0].get_status() |
ae3ad328 | 224 | if status['wpa_state'] != 'COMPLETED': |
302b7a1b | 225 | raise Exception("Not fully connected") |
ae3ad328 JM |
226 | if status['bssid'] != apdev[0]['bssid']: |
227 | raise Exception("Unexpected BSSID") | |
302b7a1b JM |
228 | if status['ssid'] != ssid: |
229 | raise Exception("Unexpected SSID") | |
230 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
231 | raise Exception("Unexpected encryption configuration") | |
232 | if status['key_mgmt'] != 'WPA2-PSK': | |
233 | raise Exception("Unexpected key_mgmt") | |
234 | ||
097cd9cd JM |
235 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) |
236 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
237 | raise Exception("Device name not available in STA command") | |
238 | ||
daad14cc JM |
239 | def test_ap_wps_conf_5ghz(dev, apdev): |
240 | """WPS PBC provisioning with configured AP on 5 GHz band""" | |
241 | try: | |
9d7fdac5 | 242 | hapd = None |
daad14cc JM |
243 | ssid = "test-wps-conf" |
244 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
245 | "wpa_passphrase": "12345678", "wpa": "2", | |
246 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
247 | "country_code": "FI", "hw_mode": "a", "channel": "36" } | |
8b8a1864 | 248 | hapd = hostapd.add_ap(apdev[0], params) |
daad14cc JM |
249 | logger.info("WPS provisioning step") |
250 | hapd.request("WPS_PBC") | |
33d0b157 JM |
251 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="5180") |
252 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 253 | dev[0].wait_connected(timeout=30) |
daad14cc JM |
254 | |
255 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) | |
256 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
257 | raise Exception("Device name not available in STA command") | |
258 | finally: | |
9d7fdac5 JM |
259 | dev[0].request("DISCONNECT") |
260 | if hapd: | |
261 | hapd.request("DISABLE") | |
c4668009 | 262 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 263 | dev[0].flush_scan_cache() |
daad14cc JM |
264 | |
265 | def test_ap_wps_conf_chan14(dev, apdev): | |
266 | """WPS PBC provisioning with configured AP on channel 14""" | |
267 | try: | |
9d7fdac5 | 268 | hapd = None |
daad14cc JM |
269 | ssid = "test-wps-conf" |
270 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
271 | "wpa_passphrase": "12345678", "wpa": "2", | |
272 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
273 | "country_code": "JP", "hw_mode": "b", "channel": "14" } | |
8b8a1864 | 274 | hapd = hostapd.add_ap(apdev[0], params) |
daad14cc JM |
275 | logger.info("WPS provisioning step") |
276 | hapd.request("WPS_PBC") | |
277 | dev[0].request("WPS_PBC") | |
5f35a5e2 | 278 | dev[0].wait_connected(timeout=30) |
daad14cc JM |
279 | |
280 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) | |
281 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
282 | raise Exception("Device name not available in STA command") | |
283 | finally: | |
9d7fdac5 JM |
284 | dev[0].request("DISCONNECT") |
285 | if hapd: | |
286 | hapd.request("DISABLE") | |
c4668009 | 287 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 288 | dev[0].flush_scan_cache() |
daad14cc | 289 | |
9fd6804d | 290 | @remote_compatible |
04e62788 JM |
291 | def test_ap_wps_twice(dev, apdev): |
292 | """WPS provisioning with twice to change passphrase""" | |
293 | ssid = "test-wps-twice" | |
294 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
295 | "wpa_passphrase": "12345678", "wpa": "2", | |
296 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
01703a9f | 297 | hapd = hostapd.add_ap(apdev[0], params) |
04e62788 JM |
298 | logger.info("WPS provisioning step") |
299 | hapd.request("WPS_PBC") | |
33d0b157 | 300 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
04e62788 | 301 | dev[0].dump_monitor() |
33d0b157 | 302 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 303 | dev[0].wait_connected(timeout=30) |
04e62788 JM |
304 | dev[0].request("DISCONNECT") |
305 | ||
306 | logger.info("Restart AP with different passphrase and re-run WPS") | |
01703a9f | 307 | hostapd.remove_bss(apdev[0]) |
04e62788 | 308 | params['wpa_passphrase'] = 'another passphrase' |
01703a9f | 309 | hapd = hostapd.add_ap(apdev[0], params) |
04e62788 JM |
310 | logger.info("WPS provisioning step") |
311 | hapd.request("WPS_PBC") | |
312 | dev[0].dump_monitor() | |
33d0b157 | 313 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 314 | dev[0].wait_connected(timeout=30) |
04e62788 JM |
315 | networks = dev[0].list_networks() |
316 | if len(networks) > 1: | |
317 | raise Exception("Unexpected duplicated network block present") | |
318 | ||
9fd6804d | 319 | @remote_compatible |
d658205a JM |
320 | def test_ap_wps_incorrect_pin(dev, apdev): |
321 | """WPS PIN provisioning with incorrect PIN""" | |
322 | ssid = "test-wps-incorrect-pin" | |
6f334bf7 JD |
323 | hapd = hostapd.add_ap(apdev[0], |
324 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
325 | "wpa_passphrase": "12345678", "wpa": "2", | |
326 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
d658205a JM |
327 | |
328 | logger.info("WPS provisioning attempt 1") | |
329 | hapd.request("WPS_PIN any 12345670") | |
33d0b157 | 330 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
d658205a | 331 | dev[0].dump_monitor() |
33d0b157 | 332 | dev[0].request("WPS_PIN %s 55554444" % apdev[0]['bssid']) |
d658205a JM |
333 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=30) |
334 | if ev is None: | |
335 | raise Exception("WPS operation timed out") | |
336 | if "config_error=18" not in ev: | |
337 | raise Exception("Incorrect config_error reported") | |
338 | if "msg=8" not in ev: | |
339 | raise Exception("PIN error detected on incorrect message") | |
5f35a5e2 | 340 | dev[0].wait_disconnected(timeout=10) |
d658205a JM |
341 | dev[0].request("WPS_CANCEL") |
342 | # if a scan was in progress, wait for it to complete before trying WPS again | |
343 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
344 | ||
d671a420 JM |
345 | status = hapd.request("WPS_GET_STATUS") |
346 | if "Last WPS result: Failed" not in status: | |
347 | raise Exception("WPS failure result not shown correctly") | |
348 | ||
d658205a JM |
349 | logger.info("WPS provisioning attempt 2") |
350 | hapd.request("WPS_PIN any 12345670") | |
351 | dev[0].dump_monitor() | |
33d0b157 | 352 | dev[0].request("WPS_PIN %s 12344444" % apdev[0]['bssid']) |
d658205a JM |
353 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=30) |
354 | if ev is None: | |
355 | raise Exception("WPS operation timed out") | |
356 | if "config_error=18" not in ev: | |
357 | raise Exception("Incorrect config_error reported") | |
358 | if "msg=10" not in ev: | |
359 | raise Exception("PIN error detected on incorrect message") | |
5f35a5e2 | 360 | dev[0].wait_disconnected(timeout=10) |
d658205a | 361 | |
9fd6804d | 362 | @remote_compatible |
ae3ad328 | 363 | def test_ap_wps_conf_pin(dev, apdev): |
302b7a1b JM |
364 | """WPS PIN provisioning with configured AP""" |
365 | ssid = "test-wps-conf-pin" | |
6f334bf7 JD |
366 | hapd = hostapd.add_ap(apdev[0], |
367 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
368 | "wpa_passphrase": "12345678", "wpa": "2", | |
369 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
302b7a1b JM |
370 | logger.info("WPS provisioning step") |
371 | pin = dev[0].wps_read_pin() | |
372 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 373 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 374 | dev[0].dump_monitor() |
33d0b157 | 375 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 376 | dev[0].wait_connected(timeout=30) |
302b7a1b | 377 | status = dev[0].get_status() |
ae3ad328 | 378 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
379 | raise Exception("Not fully connected") |
380 | if status['ssid'] != ssid: | |
381 | raise Exception("Unexpected SSID") | |
382 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
383 | raise Exception("Unexpected encryption configuration") | |
384 | if status['key_mgmt'] != 'WPA2-PSK': | |
385 | raise Exception("Unexpected key_mgmt") | |
386 | ||
84a40841 | 387 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
362ba6de JM |
388 | bss = dev[1].get_bss(apdev[0]['bssid']) |
389 | if "[WPS-AUTH]" in bss['flags']: | |
390 | raise Exception("WPS-AUTH flag not cleared") | |
a60a6d6b | 391 | logger.info("Try to connect from another station using the same PIN") |
33d0b157 | 392 | pin = dev[1].request("WPS_PIN " + apdev[0]['bssid']) |
a60a6d6b JM |
393 | ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30) |
394 | if ev is None: | |
395 | raise Exception("Operation timed out") | |
396 | if "WPS-M2D" not in ev: | |
397 | raise Exception("Unexpected WPS operation started") | |
6e12eaa4 | 398 | hapd.request("WPS_PIN any " + pin) |
5f35a5e2 | 399 | dev[1].wait_connected(timeout=30) |
362ba6de | 400 | |
ff518fbd JM |
401 | def test_ap_wps_conf_pin_mixed_mode(dev, apdev): |
402 | """WPS PIN provisioning with configured AP (WPA+WPA2)""" | |
403 | ssid = "test-wps-conf-pin-mixed" | |
6f334bf7 JD |
404 | hapd = hostapd.add_ap(apdev[0], |
405 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
406 | "wpa_passphrase": "12345678", "wpa": "3", | |
407 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
408 | "wpa_pairwise": "TKIP" }) | |
ff518fbd JM |
409 | |
410 | logger.info("WPS provisioning step") | |
411 | pin = dev[0].wps_read_pin() | |
412 | hapd.request("WPS_PIN any " + pin) | |
413 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
414 | dev[0].dump_monitor() | |
415 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
416 | dev[0].wait_connected(timeout=30) | |
417 | status = dev[0].get_status() | |
418 | dev[0].request("REMOVE_NETWORK all") | |
419 | dev[0].wait_disconnected() | |
420 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP' or status['key_mgmt'] != 'WPA2-PSK': | |
421 | raise Exception("Unexpected encryption/key_mgmt configuration: pairwise=%s group=%s key_mgmt=%s" % (status['pairwise_cipher'], status['group_cipher'], status['key_mgmt'])) | |
422 | ||
423 | logger.info("WPS provisioning step (auth_types=0x1b)") | |
424 | if "OK" not in dev[0].request("SET wps_force_auth_types 0x1b"): | |
425 | raise Exception("Failed to set wps_force_auth_types 0x1b") | |
426 | pin = dev[0].wps_read_pin() | |
427 | hapd.request("WPS_PIN any " + pin) | |
428 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
429 | dev[0].dump_monitor() | |
430 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
431 | dev[0].wait_connected(timeout=30) | |
432 | status = dev[0].get_status() | |
433 | dev[0].request("REMOVE_NETWORK all") | |
434 | dev[0].wait_disconnected() | |
435 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP' or status['key_mgmt'] != 'WPA2-PSK': | |
436 | raise Exception("Unexpected encryption/key_mgmt configuration: pairwise=%s group=%s key_mgmt=%s" % (status['pairwise_cipher'], status['group_cipher'], status['key_mgmt'])) | |
437 | ||
438 | logger.info("WPS provisioning step (auth_types=0 encr_types=0)") | |
439 | if "OK" not in dev[0].request("SET wps_force_auth_types 0"): | |
440 | raise Exception("Failed to set wps_force_auth_types 0") | |
441 | if "OK" not in dev[0].request("SET wps_force_encr_types 0"): | |
442 | raise Exception("Failed to set wps_force_encr_types 0") | |
443 | pin = dev[0].wps_read_pin() | |
444 | hapd.request("WPS_PIN any " + pin) | |
445 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
446 | dev[0].dump_monitor() | |
447 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
448 | dev[0].wait_connected(timeout=30) | |
449 | status = dev[0].get_status() | |
450 | dev[0].request("REMOVE_NETWORK all") | |
451 | dev[0].wait_disconnected() | |
452 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP' or status['key_mgmt'] != 'WPA2-PSK': | |
453 | raise Exception("Unexpected encryption/key_mgmt configuration: pairwise=%s group=%s key_mgmt=%s" % (status['pairwise_cipher'], status['group_cipher'], status['key_mgmt'])) | |
454 | ||
455 | dev[0].request("SET wps_force_auth_types ") | |
456 | dev[0].request("SET wps_force_encr_types ") | |
457 | ||
9fd6804d | 458 | @remote_compatible |
6257f9c0 JM |
459 | def test_ap_wps_conf_pin_v1(dev, apdev): |
460 | """WPS PIN provisioning with configured WPS v1.0 AP""" | |
461 | ssid = "test-wps-conf-pin-v1" | |
6f334bf7 JD |
462 | hapd = hostapd.add_ap(apdev[0], |
463 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
464 | "wpa_passphrase": "12345678", "wpa": "2", | |
465 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
6257f9c0 JM |
466 | logger.info("WPS provisioning step") |
467 | pin = dev[0].wps_read_pin() | |
468 | hapd.request("SET wps_version_number 0x10") | |
469 | hapd.request("WPS_PIN any " + pin) | |
470 | found = False | |
471 | for i in range(0, 10): | |
472 | dev[0].scan(freq="2412") | |
473 | if "[WPS-PIN]" in dev[0].request("SCAN_RESULTS"): | |
474 | found = True | |
475 | break | |
476 | if not found: | |
477 | hapd.request("SET wps_version_number 0x20") | |
478 | raise Exception("WPS-PIN flag not seen in scan results") | |
479 | dev[0].dump_monitor() | |
33d0b157 | 480 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 481 | dev[0].wait_connected(timeout=30) |
6257f9c0 | 482 | hapd.request("SET wps_version_number 0x20") |
6257f9c0 | 483 | |
9fd6804d | 484 | @remote_compatible |
e9129860 JM |
485 | def test_ap_wps_conf_pin_2sta(dev, apdev): |
486 | """Two stations trying to use WPS PIN at the same time""" | |
487 | ssid = "test-wps-conf-pin2" | |
6f334bf7 JD |
488 | hapd = hostapd.add_ap(apdev[0], |
489 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
490 | "wpa_passphrase": "12345678", "wpa": "2", | |
491 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e9129860 JM |
492 | logger.info("WPS provisioning step") |
493 | pin = "12345670" | |
494 | pin2 = "55554444" | |
495 | hapd.request("WPS_PIN " + dev[0].get_status_field("uuid") + " " + pin) | |
496 | hapd.request("WPS_PIN " + dev[1].get_status_field("uuid") + " " + pin) | |
e9129860 | 497 | dev[0].dump_monitor() |
e9129860 | 498 | dev[1].dump_monitor() |
33d0b157 JM |
499 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
500 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
501 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
502 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5f35a5e2 JM |
503 | dev[0].wait_connected(timeout=30) |
504 | dev[1].wait_connected(timeout=30) | |
0489e880 | 505 | |
9fd6804d | 506 | @remote_compatible |
0489e880 JM |
507 | def test_ap_wps_conf_pin_timeout(dev, apdev): |
508 | """WPS PIN provisioning with configured AP timing out PIN""" | |
509 | ssid = "test-wps-conf-pin" | |
6f334bf7 JD |
510 | hapd = hostapd.add_ap(apdev[0], |
511 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
512 | "wpa_passphrase": "12345678", "wpa": "2", | |
513 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
0489e880 JM |
514 | addr = dev[0].p2p_interface_addr() |
515 | pin = dev[0].wps_read_pin() | |
516 | if "FAIL" not in hapd.request("WPS_PIN "): | |
517 | raise Exception("Unexpected success on invalid WPS_PIN") | |
518 | hapd.request("WPS_PIN any " + pin + " 1") | |
33d0b157 | 519 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
0489e880 | 520 | time.sleep(1.1) |
33d0b157 | 521 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
0489e880 JM |
522 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=20) |
523 | if ev is None: | |
524 | raise Exception("WPS-PIN-NEEDED event timed out") | |
525 | ev = dev[0].wait_event(["WPS-M2D"]) | |
526 | if ev is None: | |
527 | raise Exception("M2D not reported") | |
528 | dev[0].request("WPS_CANCEL") | |
529 | ||
530 | hapd.request("WPS_PIN any " + pin + " 20 " + addr) | |
33d0b157 | 531 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 532 | dev[0].wait_connected(timeout=30) |
e9129860 | 533 | |
ae3ad328 | 534 | def test_ap_wps_reg_connect(dev, apdev): |
302b7a1b | 535 | """WPS registrar using AP PIN to connect""" |
803edd1c | 536 | ssid = "test-wps-reg-ap-pin" |
302b7a1b | 537 | appin = "12345670" |
8b8a1864 | 538 | hostapd.add_ap(apdev[0], |
302b7a1b JM |
539 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
540 | "wpa_passphrase": "12345678", "wpa": "2", | |
541 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
542 | "ap_pin": appin}) | |
543 | logger.info("WPS provisioning step") | |
302b7a1b | 544 | dev[0].dump_monitor() |
33d0b157 | 545 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 546 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
302b7a1b | 547 | status = dev[0].get_status() |
ae3ad328 | 548 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
549 | raise Exception("Not fully connected") |
550 | if status['ssid'] != ssid: | |
551 | raise Exception("Unexpected SSID") | |
552 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
553 | raise Exception("Unexpected encryption configuration") | |
554 | if status['key_mgmt'] != 'WPA2-PSK': | |
555 | raise Exception("Unexpected key_mgmt") | |
556 | ||
e60be3b3 JM |
557 | def test_ap_wps_reg_connect_mixed_mode(dev, apdev): |
558 | """WPS registrar using AP PIN to connect (WPA+WPA2)""" | |
559 | ssid = "test-wps-reg-ap-pin" | |
560 | appin = "12345670" | |
8b8a1864 | 561 | hostapd.add_ap(apdev[0], |
e60be3b3 JM |
562 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
563 | "wpa_passphrase": "12345678", "wpa": "3", | |
564 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
565 | "wpa_pairwise": "TKIP", "ap_pin": appin}) | |
566 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
567 | dev[0].wps_reg(apdev[0]['bssid'], appin) | |
568 | status = dev[0].get_status() | |
569 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
570 | raise Exception("Not fully connected") | |
571 | if status['ssid'] != ssid: | |
572 | raise Exception("Unexpected SSID") | |
573 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
574 | raise Exception("Unexpected encryption configuration") | |
575 | if status['key_mgmt'] != 'WPA2-PSK': | |
576 | raise Exception("Unexpected key_mgmt") | |
577 | ||
7511ead0 JM |
578 | def test_ap_wps_reg_override_ap_settings(dev, apdev): |
579 | """WPS registrar and ap_settings override""" | |
580 | ap_settings = "/tmp/ap_wps_reg_override_ap_settings" | |
581 | try: | |
582 | os.remove(ap_settings) | |
583 | except: | |
584 | pass | |
585 | # Override AP Settings with values that point to another AP | |
586 | data = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
587 | data += build_wsc_attr(ATTR_SSID, "test") | |
588 | data += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
589 | data += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
590 | data += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
591 | data += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[1]['bssid'].replace(':', ''))) | |
592 | with open(ap_settings, "w") as f: | |
593 | f.write(data) | |
594 | ssid = "test-wps-reg-ap-pin" | |
595 | appin = "12345670" | |
8b8a1864 | 596 | hostapd.add_ap(apdev[0], |
7511ead0 JM |
597 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
598 | "wpa_passphrase": "12345678", "wpa": "2", | |
599 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
600 | "ap_pin": appin, "ap_settings": ap_settings }) | |
8b8a1864 | 601 | hapd2 = hostapd.add_ap(apdev[1], { "ssid": "test" }) |
7511ead0 JM |
602 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
603 | dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412) | |
604 | dev[0].wps_reg(apdev[0]['bssid'], appin) | |
605 | ev = hapd2.wait_event(['AP-STA-CONNECTED'], timeout=10) | |
606 | os.remove(ap_settings) | |
607 | if ev is None: | |
608 | raise Exception("No connection with the other AP") | |
609 | ||
9488858f JM |
610 | def check_wps_reg_failure(dev, ap, appin): |
611 | dev.request("WPS_REG " + ap['bssid'] + " " + appin) | |
612 | ev = dev.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout=15) | |
613 | if ev is None: | |
614 | raise Exception("WPS operation timed out") | |
615 | if "WPS-SUCCESS" in ev: | |
616 | raise Exception("WPS operation succeeded unexpectedly") | |
617 | if "config_error=15" not in ev: | |
618 | raise Exception("WPS setup locked state was not reported correctly") | |
619 | ||
e4357b19 JM |
620 | def test_ap_wps_random_ap_pin(dev, apdev): |
621 | """WPS registrar using random AP PIN""" | |
622 | ssid = "test-wps-reg-random-ap-pin" | |
623 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
6f334bf7 JD |
624 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
625 | "wpa_passphrase": "12345678", "wpa": "2", | |
626 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
627 | "device_name": "Wireless AP", "manufacturer": "Company", | |
628 | "model_name": "WAP", "model_number": "123", | |
629 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
630 | "os_version": "01020300", | |
631 | "config_methods": "label push_button", | |
632 | "uuid": ap_uuid, "upnp_iface": "lo" } | |
633 | hapd = hostapd.add_ap(apdev[0], params) | |
e4357b19 JM |
634 | appin = hapd.request("WPS_AP_PIN random") |
635 | if "FAIL" in appin: | |
636 | raise Exception("Could not generate random AP PIN") | |
637 | if appin not in hapd.request("WPS_AP_PIN get"): | |
638 | raise Exception("Could not fetch current AP PIN") | |
639 | logger.info("WPS provisioning step") | |
33d0b157 | 640 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
e4357b19 JM |
641 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
642 | ||
643 | hapd.request("WPS_AP_PIN disable") | |
644 | logger.info("WPS provisioning step with AP PIN disabled") | |
33d0b157 | 645 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9488858f JM |
646 | check_wps_reg_failure(dev[1], apdev[0], appin) |
647 | ||
648 | logger.info("WPS provisioning step with AP PIN reset") | |
649 | appin = "12345670" | |
650 | hapd.request("WPS_AP_PIN set " + appin) | |
651 | dev[1].wps_reg(apdev[0]['bssid'], appin) | |
652 | dev[0].request("REMOVE_NETWORK all") | |
653 | dev[1].request("REMOVE_NETWORK all") | |
5f35a5e2 JM |
654 | dev[0].wait_disconnected(timeout=10) |
655 | dev[1].wait_disconnected(timeout=10) | |
9488858f JM |
656 | |
657 | logger.info("WPS provisioning step after AP PIN timeout") | |
658 | hapd.request("WPS_AP_PIN disable") | |
659 | appin = hapd.request("WPS_AP_PIN random 1") | |
660 | time.sleep(1.1) | |
661 | if "FAIL" not in hapd.request("WPS_AP_PIN get"): | |
662 | raise Exception("AP PIN unexpectedly still enabled") | |
663 | check_wps_reg_failure(dev[0], apdev[0], appin) | |
664 | ||
665 | logger.info("WPS provisioning step after AP PIN timeout(2)") | |
666 | hapd.request("WPS_AP_PIN disable") | |
667 | appin = "12345670" | |
668 | hapd.request("WPS_AP_PIN set " + appin + " 1") | |
669 | time.sleep(1.1) | |
670 | if "FAIL" not in hapd.request("WPS_AP_PIN get"): | |
671 | raise Exception("AP PIN unexpectedly still enabled") | |
672 | check_wps_reg_failure(dev[1], apdev[0], appin) | |
e4357b19 | 673 | |
24b7f282 | 674 | with fail_test(hapd, 1, "os_get_random;wps_generate_pin"): |
20c48fd9 | 675 | hapd.request("WPS_AP_PIN random 1") |
24b7f282 JM |
676 | hapd.request("WPS_AP_PIN disable") |
677 | ||
678 | with alloc_fail(hapd, 1, "upnp_wps_set_ap_pin"): | |
679 | hapd.request("WPS_AP_PIN set 12345670") | |
680 | hapd.request("WPS_AP_PIN disable") | |
681 | ||
82358a2a JM |
682 | if "FAIL" not in hapd.request("WPS_AP_PIN set"): |
683 | raise Exception("Invalid WPS_AP_PIN accepted") | |
684 | if "FAIL" not in hapd.request("WPS_AP_PIN foo"): | |
685 | raise Exception("Invalid WPS_AP_PIN accepted") | |
686 | ||
ae3ad328 | 687 | def test_ap_wps_reg_config(dev, apdev): |
4b727c5c | 688 | """WPS registrar configuring an AP using AP PIN""" |
302b7a1b JM |
689 | ssid = "test-wps-init-ap-pin" |
690 | appin = "12345670" | |
8b8a1864 | 691 | hostapd.add_ap(apdev[0], |
302b7a1b JM |
692 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
693 | "ap_pin": appin}) | |
694 | logger.info("WPS configuration step") | |
33d0b157 | 695 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
302b7a1b JM |
696 | dev[0].dump_monitor() |
697 | new_ssid = "wps-new-ssid" | |
698 | new_passphrase = "1234567890" | |
6edaee9c JM |
699 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", |
700 | new_passphrase) | |
302b7a1b | 701 | status = dev[0].get_status() |
ae3ad328 | 702 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
703 | raise Exception("Not fully connected") |
704 | if status['ssid'] != new_ssid: | |
705 | raise Exception("Unexpected SSID") | |
706 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
707 | raise Exception("Unexpected encryption configuration") | |
708 | if status['key_mgmt'] != 'WPA2-PSK': | |
709 | raise Exception("Unexpected key_mgmt") | |
710 | ||
375afd7c JM |
711 | logger.info("Re-configure back to open") |
712 | dev[0].request("REMOVE_NETWORK all") | |
243dcc4a | 713 | dev[0].flush_scan_cache() |
375afd7c JM |
714 | dev[0].dump_monitor() |
715 | dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-open", "OPEN", "NONE", "") | |
716 | status = dev[0].get_status() | |
717 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
718 | raise Exception("Not fully connected") | |
719 | if status['ssid'] != "wps-open": | |
720 | raise Exception("Unexpected SSID") | |
721 | if status['key_mgmt'] != 'NONE': | |
722 | raise Exception("Unexpected key_mgmt") | |
723 | ||
4b727c5c JM |
724 | def test_ap_wps_reg_config_ext_processing(dev, apdev): |
725 | """WPS registrar configuring an AP with external config processing""" | |
726 | ssid = "test-wps-init-ap-pin" | |
727 | appin = "12345670" | |
728 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
729 | "wps_cred_processing": "1", "ap_pin": appin} | |
8b8a1864 | 730 | hapd = hostapd.add_ap(apdev[0], params) |
33d0b157 | 731 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
4b727c5c JM |
732 | new_ssid = "wps-new-ssid" |
733 | new_passphrase = "1234567890" | |
734 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", | |
735 | new_passphrase, no_wait=True) | |
736 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
737 | if ev is None: | |
738 | raise Exception("WPS registrar operation timed out") | |
739 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=15) | |
740 | if ev is None: | |
741 | raise Exception("WPS configuration timed out") | |
742 | if "1026" not in ev: | |
743 | raise Exception("AP Settings missing from event") | |
744 | hapd.request("SET wps_cred_processing 0") | |
745 | if "FAIL" in hapd.request("WPS_CONFIG " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex")): | |
746 | raise Exception("WPS_CONFIG command failed") | |
5f35a5e2 | 747 | dev[0].wait_connected(timeout=15) |
4b727c5c | 748 | |
eeefe187 JM |
749 | def test_ap_wps_reg_config_tkip(dev, apdev): |
750 | """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP""" | |
a1eabc74 | 751 | skip_with_fips(dev[0]) |
eeefe187 JM |
752 | ssid = "test-wps-init-ap" |
753 | appin = "12345670" | |
8b8a1864 | 754 | hostapd.add_ap(apdev[0], |
eeefe187 JM |
755 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", |
756 | "ap_pin": appin}) | |
757 | logger.info("WPS configuration step") | |
eeefe187 | 758 | dev[0].request("SET wps_version_number 0x10") |
33d0b157 | 759 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
eeefe187 JM |
760 | dev[0].dump_monitor() |
761 | new_ssid = "wps-new-ssid-with-tkip" | |
762 | new_passphrase = "1234567890" | |
763 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP", | |
764 | new_passphrase) | |
765 | logger.info("Re-connect to verify WPA2 mixed mode") | |
766 | dev[0].request("DISCONNECT") | |
767 | id = 0 | |
768 | dev[0].set_network(id, "pairwise", "CCMP") | |
769 | dev[0].set_network(id, "proto", "RSN") | |
770 | dev[0].connect_network(id) | |
771 | status = dev[0].get_status() | |
772 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
3c086180 | 773 | raise Exception("Not fully connected: wpa_state={} bssid={}".format(status['wpa_state'], status['bssid'])) |
eeefe187 JM |
774 | if status['ssid'] != new_ssid: |
775 | raise Exception("Unexpected SSID") | |
776 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
777 | raise Exception("Unexpected encryption configuration") | |
778 | if status['key_mgmt'] != 'WPA2-PSK': | |
779 | raise Exception("Unexpected key_mgmt") | |
780 | ||
6645ff50 JM |
781 | def test_ap_wps_setup_locked(dev, apdev): |
782 | """WPS registrar locking up AP setup on AP PIN failures""" | |
783 | ssid = "test-wps-incorrect-ap-pin" | |
784 | appin = "12345670" | |
6f334bf7 JD |
785 | hapd = hostapd.add_ap(apdev[0], |
786 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
787 | "wpa_passphrase": "12345678", "wpa": "2", | |
788 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
789 | "ap_pin": appin}) | |
6645ff50 JM |
790 | new_ssid = "wps-new-ssid-test" |
791 | new_passphrase = "1234567890" | |
792 | ||
33d0b157 | 793 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6645ff50 JM |
794 | ap_setup_locked=False |
795 | for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]: | |
796 | dev[0].dump_monitor() | |
797 | logger.info("Try incorrect AP PIN - attempt " + pin) | |
798 | dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK", | |
799 | "CCMP", new_passphrase, no_wait=True) | |
800 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"]) | |
801 | if ev is None: | |
802 | raise Exception("Timeout on receiving WPS operation failure event") | |
803 | if "CTRL-EVENT-CONNECTED" in ev: | |
804 | raise Exception("Unexpected connection") | |
805 | if "config_error=15" in ev: | |
806 | logger.info("AP Setup Locked") | |
807 | ap_setup_locked=True | |
808 | elif "config_error=18" not in ev: | |
809 | raise Exception("config_error=18 not reported") | |
5f35a5e2 | 810 | dev[0].wait_disconnected(timeout=10) |
6645ff50 JM |
811 | time.sleep(0.1) |
812 | if not ap_setup_locked: | |
813 | raise Exception("AP setup was not locked") | |
24b7f282 JM |
814 | dev[0].request("WPS_CANCEL") |
815 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True, | |
816 | only_new=True) | |
817 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
818 | if 'wps_ap_setup_locked' not in bss or bss['wps_ap_setup_locked'] != '1': | |
819 | logger.info("BSS: " + str(bss)) | |
820 | raise Exception("AP Setup Locked not indicated in scan results") | |
6645ff50 | 821 | |
d671a420 JM |
822 | status = hapd.request("WPS_GET_STATUS") |
823 | if "Last WPS result: Failed" not in status: | |
824 | raise Exception("WPS failure result not shown correctly") | |
825 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
826 | raise Exception("Peer address not shown correctly") | |
827 | ||
6645ff50 JM |
828 | time.sleep(0.5) |
829 | dev[0].dump_monitor() | |
830 | logger.info("WPS provisioning step") | |
831 | pin = dev[0].wps_read_pin() | |
6645ff50 | 832 | hapd.request("WPS_PIN any " + pin) |
33d0b157 | 833 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
6645ff50 JM |
834 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30) |
835 | if ev is None: | |
836 | raise Exception("WPS success was not reported") | |
5f35a5e2 | 837 | dev[0].wait_connected(timeout=30) |
6645ff50 | 838 | |
c1cec68b JM |
839 | appin = hapd.request("WPS_AP_PIN random") |
840 | if "FAIL" in appin: | |
841 | raise Exception("Could not generate random AP PIN") | |
842 | ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=10) | |
843 | if ev is None: | |
844 | raise Exception("Failed to unlock AP PIN") | |
845 | ||
33c9b8d8 JM |
846 | def test_ap_wps_setup_locked_timeout(dev, apdev): |
847 | """WPS re-enabling AP PIN after timeout""" | |
848 | ssid = "test-wps-incorrect-ap-pin" | |
849 | appin = "12345670" | |
6f334bf7 JD |
850 | hapd = hostapd.add_ap(apdev[0], |
851 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
852 | "wpa_passphrase": "12345678", "wpa": "2", | |
853 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
854 | "ap_pin": appin}) | |
33c9b8d8 JM |
855 | new_ssid = "wps-new-ssid-test" |
856 | new_passphrase = "1234567890" | |
857 | ||
33d0b157 | 858 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
33c9b8d8 JM |
859 | ap_setup_locked=False |
860 | for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]: | |
861 | dev[0].dump_monitor() | |
862 | logger.info("Try incorrect AP PIN - attempt " + pin) | |
863 | dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK", | |
864 | "CCMP", new_passphrase, no_wait=True) | |
9ed53f5e | 865 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"], timeout=15) |
33c9b8d8 JM |
866 | if ev is None: |
867 | raise Exception("Timeout on receiving WPS operation failure event") | |
868 | if "CTRL-EVENT-CONNECTED" in ev: | |
869 | raise Exception("Unexpected connection") | |
870 | if "config_error=15" in ev: | |
871 | logger.info("AP Setup Locked") | |
872 | ap_setup_locked=True | |
873 | break | |
874 | elif "config_error=18" not in ev: | |
875 | raise Exception("config_error=18 not reported") | |
5f35a5e2 | 876 | dev[0].wait_disconnected(timeout=10) |
33c9b8d8 JM |
877 | time.sleep(0.1) |
878 | if not ap_setup_locked: | |
879 | raise Exception("AP setup was not locked") | |
33c9b8d8 JM |
880 | ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=80) |
881 | if ev is None: | |
882 | raise Exception("AP PIN did not get unlocked on 60 second timeout") | |
883 | ||
4c355e3e JM |
884 | def test_ap_wps_setup_locked_2(dev, apdev): |
885 | """WPS AP configured for special ap_setup_locked=2 mode""" | |
886 | ssid = "test-wps-ap-pin" | |
887 | appin = "12345670" | |
888 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
889 | "wpa_passphrase": "12345678", "wpa": "2", | |
890 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
891 | "ap_pin": appin, "ap_setup_locked": "2" } | |
8b8a1864 | 892 | hapd = hostapd.add_ap(apdev[0], params) |
4c355e3e JM |
893 | new_ssid = "wps-new-ssid-test" |
894 | new_passphrase = "1234567890" | |
895 | ||
896 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
897 | dev[0].wps_reg(apdev[0]['bssid'], appin) | |
898 | dev[0].request("REMOVE_NETWORK all") | |
899 | dev[0].wait_disconnected() | |
900 | ||
901 | hapd.dump_monitor() | |
902 | dev[0].dump_monitor() | |
903 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", | |
904 | "CCMP", new_passphrase, no_wait=True) | |
905 | ||
906 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
907 | if ev is None: | |
908 | raise Exception("hostapd did not report WPS failure") | |
909 | if "msg=12 config_error=15" not in ev: | |
910 | raise Exception("Unexpected failure reason (AP): " + ev) | |
911 | ||
912 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"]) | |
913 | if ev is None: | |
914 | raise Exception("Timeout on receiving WPS operation failure event") | |
915 | if "CTRL-EVENT-CONNECTED" in ev: | |
916 | raise Exception("Unexpected connection") | |
917 | if "config_error=15" not in ev: | |
918 | raise Exception("Unexpected failure reason (STA): " + ev) | |
919 | dev[0].request("WPS_CANCEL") | |
920 | dev[0].wait_disconnected() | |
921 | ||
9fd6804d | 922 | @remote_compatible |
ae3ad328 | 923 | def test_ap_wps_pbc_overlap_2ap(dev, apdev): |
302b7a1b | 924 | """WPS PBC session overlap with two active APs""" |
6f334bf7 JD |
925 | params = { "ssid": "wps1", "eap_server": "1", "wps_state": "2", |
926 | "wpa_passphrase": "12345678", "wpa": "2", | |
927 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
928 | "wps_independent": "1"} | |
929 | hapd = hostapd.add_ap(apdev[0], params) | |
930 | params = { "ssid": "wps2", "eap_server": "1", "wps_state": "2", | |
931 | "wpa_passphrase": "123456789", "wpa": "2", | |
932 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
933 | "wps_independent": "1"} | |
934 | hapd2 = hostapd.add_ap(apdev[1], params) | |
302b7a1b | 935 | hapd.request("WPS_PBC") |
302b7a1b JM |
936 | hapd2.request("WPS_PBC") |
937 | logger.info("WPS provisioning step") | |
84a40841 JM |
938 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
939 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
302b7a1b JM |
940 | dev[0].request("WPS_PBC") |
941 | ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15) | |
942 | if ev is None: | |
943 | raise Exception("PBC session overlap not detected") | |
492c3a91 JM |
944 | hapd.request("DISABLE") |
945 | hapd2.request("DISABLE") | |
946 | dev[0].flush_scan_cache() | |
302b7a1b | 947 | |
9fd6804d | 948 | @remote_compatible |
ae3ad328 | 949 | def test_ap_wps_pbc_overlap_2sta(dev, apdev): |
302b7a1b JM |
950 | """WPS PBC session overlap with two active STAs""" |
951 | ssid = "test-wps-pbc-overlap" | |
6f334bf7 JD |
952 | hapd = hostapd.add_ap(apdev[0], |
953 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
954 | "wpa_passphrase": "12345678", "wpa": "2", | |
955 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
302b7a1b JM |
956 | logger.info("WPS provisioning step") |
957 | hapd.request("WPS_PBC") | |
33d0b157 | 958 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 959 | dev[0].dump_monitor() |
33d0b157 | 960 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 961 | dev[1].dump_monitor() |
33d0b157 JM |
962 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
963 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
302b7a1b JM |
964 | ev = dev[0].wait_event(["WPS-M2D"], timeout=15) |
965 | if ev is None: | |
966 | raise Exception("PBC session overlap not detected (dev0)") | |
967 | if "config_error=12" not in ev: | |
968 | raise Exception("PBC session overlap not correctly reported (dev0)") | |
492c3a91 JM |
969 | dev[0].request("WPS_CANCEL") |
970 | dev[0].request("DISCONNECT") | |
302b7a1b JM |
971 | ev = dev[1].wait_event(["WPS-M2D"], timeout=15) |
972 | if ev is None: | |
973 | raise Exception("PBC session overlap not detected (dev1)") | |
974 | if "config_error=12" not in ev: | |
975 | raise Exception("PBC session overlap not correctly reported (dev1)") | |
492c3a91 JM |
976 | dev[1].request("WPS_CANCEL") |
977 | dev[1].request("DISCONNECT") | |
11e7eeba JM |
978 | hapd.request("WPS_CANCEL") |
979 | ret = hapd.request("WPS_PBC") | |
980 | if "FAIL" not in ret: | |
981 | raise Exception("PBC mode allowed to be started while PBC overlap still active") | |
492c3a91 JM |
982 | hapd.request("DISABLE") |
983 | dev[0].flush_scan_cache() | |
984 | dev[1].flush_scan_cache() | |
6edaee9c | 985 | |
9fd6804d | 986 | @remote_compatible |
71afe834 JM |
987 | def test_ap_wps_cancel(dev, apdev): |
988 | """WPS AP cancelling enabled config method""" | |
989 | ssid = "test-wps-ap-cancel" | |
6f334bf7 JD |
990 | hapd = hostapd.add_ap(apdev[0], |
991 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
992 | "wpa_passphrase": "12345678", "wpa": "2", | |
993 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
71afe834 | 994 | bssid = apdev[0]['bssid'] |
71afe834 JM |
995 | |
996 | logger.info("Verify PBC enable/cancel") | |
997 | hapd.request("WPS_PBC") | |
71afe834 | 998 | dev[0].scan(freq="2412") |
84a40841 | 999 | dev[0].scan(freq="2412") |
71afe834 JM |
1000 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1001 | if "[WPS-PBC]" not in bss['flags']: | |
1002 | raise Exception("WPS-PBC flag missing") | |
1003 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
1004 | raise Exception("WPS_CANCEL failed") | |
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-PBC]" in bss['flags']: | |
1009 | raise Exception("WPS-PBC flag not cleared") | |
1010 | ||
1011 | logger.info("Verify PIN enable/cancel") | |
1012 | hapd.request("WPS_PIN any 12345670") | |
1013 | dev[0].scan(freq="2412") | |
84a40841 | 1014 | dev[0].scan(freq="2412") |
71afe834 JM |
1015 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1016 | if "[WPS-AUTH]" not in bss['flags']: | |
1017 | raise Exception("WPS-AUTH flag missing") | |
1018 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
1019 | raise Exception("WPS_CANCEL failed") | |
1020 | dev[0].scan(freq="2412") | |
84a40841 | 1021 | dev[0].scan(freq="2412") |
71afe834 JM |
1022 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1023 | if "[WPS-AUTH]" in bss['flags']: | |
1024 | raise Exception("WPS-AUTH flag not cleared") | |
1025 | ||
6edaee9c JM |
1026 | def test_ap_wps_er_add_enrollee(dev, apdev): |
1027 | """WPS ER configuring AP and adding a new enrollee using PIN""" | |
be9f1562 JM |
1028 | try: |
1029 | _test_ap_wps_er_add_enrollee(dev, apdev) | |
1030 | finally: | |
1031 | dev[0].request("WPS_ER_STOP") | |
1032 | ||
1033 | def _test_ap_wps_er_add_enrollee(dev, apdev): | |
6edaee9c JM |
1034 | ssid = "wps-er-add-enrollee" |
1035 | ap_pin = "12345670" | |
1036 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1037 | hostapd.add_ap(apdev[0], |
6edaee9c JM |
1038 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", |
1039 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1040 | "model_name": "WAP", "model_number": "123", | |
1041 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1042 | "os_version": "01020300", | |
24b7f282 | 1043 | 'friendly_name': "WPS AP - <>&'\" - TEST", |
6edaee9c JM |
1044 | "config_methods": "label push_button", |
1045 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1046 | logger.info("WPS configuration step") | |
1047 | new_passphrase = "1234567890" | |
1048 | dev[0].dump_monitor() | |
33d0b157 | 1049 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c JM |
1050 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP", |
1051 | new_passphrase) | |
1052 | status = dev[0].get_status() | |
1053 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1054 | raise Exception("Not fully connected") | |
1055 | if status['ssid'] != ssid: | |
1056 | raise Exception("Unexpected SSID") | |
1057 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
1058 | raise Exception("Unexpected encryption configuration") | |
1059 | if status['key_mgmt'] != 'WPA2-PSK': | |
1060 | raise Exception("Unexpected key_mgmt") | |
1061 | ||
1062 | logger.info("Start ER") | |
1063 | dev[0].request("WPS_ER_START ifname=lo") | |
1064 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1065 | if ev is None: | |
1066 | raise Exception("AP discovery timed out") | |
1067 | if ap_uuid not in ev: | |
1068 | raise Exception("Expected AP UUID not found") | |
24b7f282 JM |
1069 | if "|WPS AP - <>&'" - TEST|Company|" not in ev: |
1070 | raise Exception("Expected friendly name not found") | |
6edaee9c JM |
1071 | |
1072 | logger.info("Learn AP configuration through UPnP") | |
1073 | dev[0].dump_monitor() | |
1074 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1075 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1076 | if ev is None: | |
1077 | raise Exception("AP learn timed out") | |
1078 | if ap_uuid not in ev: | |
1079 | raise Exception("Expected AP UUID not in settings") | |
1080 | if "ssid=" + ssid not in ev: | |
1081 | raise Exception("Expected SSID not in settings") | |
1082 | if "key=" + new_passphrase not in ev: | |
1083 | raise Exception("Expected passphrase not in settings") | |
33d0b157 JM |
1084 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) |
1085 | if ev is None: | |
1086 | raise Exception("WPS-FAIL after AP learn timed out") | |
1087 | time.sleep(0.1) | |
6edaee9c JM |
1088 | |
1089 | logger.info("Add Enrollee using ER") | |
1090 | pin = dev[1].wps_read_pin() | |
1091 | dev[0].dump_monitor() | |
1092 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
33d0b157 | 1093 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 1094 | dev[1].dump_monitor() |
33d0b157 | 1095 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
846be889 | 1096 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) |
6edaee9c JM |
1097 | if ev is None: |
1098 | raise Exception("Enrollee did not report success") | |
5f35a5e2 | 1099 | dev[1].wait_connected(timeout=15) |
6edaee9c JM |
1100 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1101 | if ev is None: | |
1102 | raise Exception("WPS ER did not report success") | |
1103 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
1104 | ||
11c26f1b JM |
1105 | logger.info("Add a specific Enrollee using ER") |
1106 | pin = dev[2].wps_read_pin() | |
1107 | addr2 = dev[2].p2p_interface_addr() | |
1108 | dev[0].dump_monitor() | |
33d0b157 | 1109 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
11c26f1b | 1110 | dev[2].dump_monitor() |
33d0b157 | 1111 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
11c26f1b JM |
1112 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) |
1113 | if ev is None: | |
1114 | raise Exception("Enrollee not seen") | |
1115 | if addr2 not in ev: | |
1116 | raise Exception("Unexpected Enrollee MAC address") | |
1117 | dev[0].request("WPS_ER_PIN " + addr2 + " " + pin + " " + addr2) | |
5f35a5e2 | 1118 | dev[2].wait_connected(timeout=30) |
11c26f1b JM |
1119 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1120 | if ev is None: | |
1121 | raise Exception("WPS ER did not report success") | |
1122 | ||
38ae43de JM |
1123 | logger.info("Verify registrar selection behavior") |
1124 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
1125 | dev[1].request("DISCONNECT") | |
5f35a5e2 | 1126 | dev[1].wait_disconnected(timeout=10) |
84a40841 | 1127 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
38ae43de JM |
1128 | dev[1].scan(freq="2412") |
1129 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
1130 | if "[WPS-AUTH]" not in bss['flags']: | |
321c7f60 JM |
1131 | # It is possible for scan to miss an update especially when running |
1132 | # tests under load with multiple VMs, so allow another attempt. | |
1133 | dev[1].scan(freq="2412") | |
1134 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
1135 | if "[WPS-AUTH]" not in bss['flags']: | |
1136 | raise Exception("WPS-AUTH flag missing") | |
38ae43de JM |
1137 | |
1138 | logger.info("Stop ER") | |
1139 | dev[0].dump_monitor() | |
1140 | dev[0].request("WPS_ER_STOP") | |
1141 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"]) | |
1142 | if ev is None: | |
1143 | raise Exception("WPS ER unsubscription timed out") | |
8697cbc0 | 1144 | # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait |
befd671c | 1145 | # a bit before verifying that the scan results have changed. |
8697cbc0 | 1146 | time.sleep(0.2) |
38ae43de | 1147 | |
befd671c JM |
1148 | for i in range(0, 10): |
1149 | dev[1].request("BSS_FLUSH 0") | |
1150 | dev[1].scan(freq="2412", only_new=True) | |
1151 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
1152 | if bss and 'flags' in bss and "[WPS-AUTH]" not in bss['flags']: | |
1153 | break | |
1154 | logger.debug("WPS-AUTH flag was still in place - wait a bit longer") | |
1155 | time.sleep(0.1) | |
38ae43de JM |
1156 | if "[WPS-AUTH]" in bss['flags']: |
1157 | raise Exception("WPS-AUTH flag not removed") | |
1158 | ||
c965ae03 JM |
1159 | def test_ap_wps_er_add_enrollee_uuid(dev, apdev): |
1160 | """WPS ER adding a new enrollee identified by UUID""" | |
1161 | try: | |
1162 | _test_ap_wps_er_add_enrollee_uuid(dev, apdev) | |
1163 | finally: | |
1164 | dev[0].request("WPS_ER_STOP") | |
1165 | ||
1166 | def _test_ap_wps_er_add_enrollee_uuid(dev, apdev): | |
1167 | ssid = "wps-er-add-enrollee" | |
1168 | ap_pin = "12345670" | |
1169 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1170 | hostapd.add_ap(apdev[0], |
c965ae03 JM |
1171 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1172 | "wpa_passphrase": "12345678", "wpa": "2", | |
1173 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1174 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1175 | "model_name": "WAP", "model_number": "123", | |
1176 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1177 | "os_version": "01020300", | |
1178 | "config_methods": "label push_button", | |
1179 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1180 | logger.info("WPS configuration step") | |
1181 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1182 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1183 | ||
1184 | logger.info("Start ER") | |
1185 | dev[0].request("WPS_ER_START ifname=lo") | |
1186 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1187 | if ev is None: | |
1188 | raise Exception("AP discovery timed out") | |
1189 | if ap_uuid not in ev: | |
1190 | raise Exception("Expected AP UUID not found") | |
1191 | ||
1192 | logger.info("Learn AP configuration through UPnP") | |
1193 | dev[0].dump_monitor() | |
1194 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1195 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1196 | if ev is None: | |
1197 | raise Exception("AP learn timed out") | |
1198 | if ap_uuid not in ev: | |
1199 | raise Exception("Expected AP UUID not in settings") | |
1200 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1201 | if ev is None: | |
1202 | raise Exception("WPS-FAIL after AP learn timed out") | |
1203 | time.sleep(0.1) | |
1204 | ||
1205 | logger.info("Add a specific Enrollee using ER (PBC/UUID)") | |
1206 | addr1 = dev[1].p2p_interface_addr() | |
1207 | dev[0].dump_monitor() | |
1208 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1209 | dev[1].dump_monitor() | |
1210 | dev[1].request("WPS_PBC %s" % apdev[0]['bssid']) | |
1211 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) | |
1212 | if ev is None: | |
1213 | raise Exception("Enrollee not seen") | |
1214 | if addr1 not in ev: | |
1215 | raise Exception("Unexpected Enrollee MAC address") | |
1216 | uuid = ev.split(' ')[1] | |
1217 | dev[0].request("WPS_ER_PBC " + uuid) | |
1218 | dev[1].wait_connected(timeout=30) | |
1219 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
1220 | if ev is None: | |
1221 | raise Exception("WPS ER did not report success") | |
1222 | ||
1223 | logger.info("Add a specific Enrollee using ER (PIN/UUID)") | |
1224 | pin = dev[2].wps_read_pin() | |
1225 | addr2 = dev[2].p2p_interface_addr() | |
1226 | dev[0].dump_monitor() | |
1227 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1228 | dev[2].dump_monitor() | |
1229 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
1230 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) | |
1231 | if ev is None: | |
1232 | raise Exception("Enrollee not seen") | |
1233 | if addr2 not in ev: | |
1234 | raise Exception("Unexpected Enrollee MAC address") | |
1235 | uuid = ev.split(' ')[1] | |
1236 | dev[0].request("WPS_ER_PIN " + uuid + " " + pin) | |
1237 | dev[2].wait_connected(timeout=30) | |
1238 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
1239 | if ev is None: | |
1240 | raise Exception("WPS ER did not report success") | |
1241 | ||
ea982de1 JM |
1242 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-REMOVE"], timeout=15) |
1243 | if ev is None: | |
1244 | raise Exception("No Enrollee STA entry timeout seen") | |
1245 | ||
c965ae03 JM |
1246 | logger.info("Stop ER") |
1247 | dev[0].dump_monitor() | |
1248 | dev[0].request("WPS_ER_STOP") | |
1249 | ||
61c3d464 JM |
1250 | def test_ap_wps_er_multi_add_enrollee(dev, apdev): |
1251 | """Multiple WPS ERs adding a new enrollee using PIN""" | |
1252 | try: | |
1253 | _test_ap_wps_er_multi_add_enrollee(dev, apdev) | |
1254 | finally: | |
d887ed3f JM |
1255 | for i in range(2): |
1256 | dev[i].request("WPS_ER_STOP") | |
61c3d464 JM |
1257 | |
1258 | def _test_ap_wps_er_multi_add_enrollee(dev, apdev): | |
1259 | ssid = "wps-er-add-enrollee" | |
1260 | ap_pin = "12345670" | |
1261 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1262 | hostapd.add_ap(apdev[0], |
61c3d464 JM |
1263 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1264 | "wpa_passphrase": "12345678", "wpa": "2", | |
1265 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1266 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1267 | "model_name": "WAP", "model_number": "123", | |
1268 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1269 | "os_version": "01020300", | |
1270 | 'friendly_name': "WPS AP", | |
1271 | "config_methods": "label push_button", | |
1272 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1273 | ||
1274 | for i in range(2): | |
1275 | dev[i].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1276 | dev[i].wps_reg(apdev[0]['bssid'], ap_pin) | |
6a5f578c | 1277 | for i in range(2): |
61c3d464 JM |
1278 | dev[i].request("WPS_ER_START ifname=lo") |
1279 | for i in range(2): | |
1280 | ev = dev[i].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1281 | if ev is None: | |
1282 | raise Exception("AP discovery timed out") | |
1283 | dev[i].dump_monitor() | |
6a5f578c | 1284 | for i in range(2): |
61c3d464 | 1285 | dev[i].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) |
6a5f578c | 1286 | for i in range(2): |
61c3d464 JM |
1287 | ev = dev[i].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) |
1288 | if ev is None: | |
1289 | raise Exception("AP learn timed out") | |
1290 | ev = dev[i].wait_event(["WPS-FAIL"], timeout=15) | |
1291 | if ev is None: | |
1292 | raise Exception("WPS-FAIL after AP learn timed out") | |
1293 | ||
1294 | time.sleep(0.1) | |
1295 | ||
1296 | pin = dev[2].wps_read_pin() | |
1297 | addr = dev[2].own_addr() | |
1298 | dev[0].dump_monitor() | |
1299 | dev[0].request("WPS_ER_PIN any " + pin + " " + addr) | |
1300 | dev[1].dump_monitor() | |
1301 | dev[1].request("WPS_ER_PIN any " + pin + " " + addr) | |
1302 | ||
1303 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1304 | dev[2].dump_monitor() | |
1305 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
1306 | ev = dev[2].wait_event(["WPS-SUCCESS"], timeout=30) | |
1307 | if ev is None: | |
1308 | raise Exception("Enrollee did not report success") | |
1309 | dev[2].wait_connected(timeout=15) | |
1310 | ||
6edaee9c JM |
1311 | def test_ap_wps_er_add_enrollee_pbc(dev, apdev): |
1312 | """WPS ER connected to AP and adding a new enrollee using PBC""" | |
be9f1562 JM |
1313 | try: |
1314 | _test_ap_wps_er_add_enrollee_pbc(dev, apdev) | |
1315 | finally: | |
1316 | dev[0].request("WPS_ER_STOP") | |
1317 | ||
1318 | def _test_ap_wps_er_add_enrollee_pbc(dev, apdev): | |
6edaee9c JM |
1319 | ssid = "wps-er-add-enrollee-pbc" |
1320 | ap_pin = "12345670" | |
1321 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1322 | hostapd.add_ap(apdev[0], |
6edaee9c JM |
1323 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1324 | "wpa_passphrase": "12345678", "wpa": "2", | |
1325 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1326 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1327 | "model_name": "WAP", "model_number": "123", | |
1328 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1329 | "os_version": "01020300", | |
1330 | "config_methods": "label push_button", | |
1331 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1332 | logger.info("Learn AP configuration") | |
33d0b157 | 1333 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 1334 | dev[0].dump_monitor() |
6edaee9c JM |
1335 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) |
1336 | status = dev[0].get_status() | |
1337 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1338 | raise Exception("Not fully connected") | |
1339 | ||
1340 | logger.info("Start ER") | |
1341 | dev[0].request("WPS_ER_START ifname=lo") | |
1342 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1343 | if ev is None: | |
1344 | raise Exception("AP discovery timed out") | |
1345 | if ap_uuid not in ev: | |
1346 | raise Exception("Expected AP UUID not found") | |
1347 | ||
d6b916c9 JM |
1348 | enrollee = dev[1].p2p_interface_addr() |
1349 | ||
1350 | if "FAIL-UNKNOWN-UUID" not in dev[0].request("WPS_ER_PBC " + enrollee): | |
1351 | raise Exception("Unknown UUID not reported") | |
6edaee9c JM |
1352 | |
1353 | logger.info("Add Enrollee using ER and PBC") | |
1354 | dev[0].dump_monitor() | |
6edaee9c JM |
1355 | dev[1].dump_monitor() |
1356 | dev[1].request("WPS_PBC") | |
1357 | ||
8674c022 JM |
1358 | for i in range(0, 2): |
1359 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) | |
1360 | if ev is None: | |
1361 | raise Exception("Enrollee discovery timed out") | |
1362 | if enrollee in ev: | |
1363 | break | |
1364 | if i == 1: | |
1365 | raise Exception("Expected Enrollee not found") | |
d6b916c9 JM |
1366 | if "FAIL-NO-AP-SETTINGS" not in dev[0].request("WPS_ER_PBC " + enrollee): |
1367 | raise Exception("Unknown UUID not reported") | |
1368 | logger.info("Use learned network configuration on ER") | |
1369 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0") | |
1370 | if "OK" not in dev[0].request("WPS_ER_PBC " + enrollee): | |
1371 | raise Exception("WPS_ER_PBC failed") | |
6edaee9c JM |
1372 | |
1373 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15) | |
1374 | if ev is None: | |
1375 | raise Exception("Enrollee did not report success") | |
5f35a5e2 | 1376 | dev[1].wait_connected(timeout=15) |
6edaee9c JM |
1377 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1378 | if ev is None: | |
1379 | raise Exception("WPS ER did not report success") | |
1380 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
bff3ac5b | 1381 | |
d6b916c9 JM |
1382 | def test_ap_wps_er_pbc_overlap(dev, apdev): |
1383 | """WPS ER connected to AP and PBC session overlap""" | |
be9f1562 JM |
1384 | try: |
1385 | _test_ap_wps_er_pbc_overlap(dev, apdev) | |
1386 | finally: | |
1387 | dev[0].request("WPS_ER_STOP") | |
1388 | ||
1389 | def _test_ap_wps_er_pbc_overlap(dev, apdev): | |
d6b916c9 JM |
1390 | ssid = "wps-er-add-enrollee-pbc" |
1391 | ap_pin = "12345670" | |
1392 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1393 | hostapd.add_ap(apdev[0], |
d6b916c9 JM |
1394 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1395 | "wpa_passphrase": "12345678", "wpa": "2", | |
1396 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1397 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1398 | "model_name": "WAP", "model_number": "123", | |
1399 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1400 | "os_version": "01020300", | |
1401 | "config_methods": "label push_button", | |
1402 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1403 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1404 | dev[0].dump_monitor() | |
1405 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1406 | ||
fba25c99 JM |
1407 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
1408 | dev[2].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
1409 | # avoid leaving dev 1 or 2 as the last Probe Request to the AP | |
1410 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True) | |
1411 | ||
d6b916c9 JM |
1412 | dev[0].dump_monitor() |
1413 | dev[0].request("WPS_ER_START ifname=lo") | |
1414 | ||
1415 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1416 | if ev is None: | |
1417 | raise Exception("AP discovery timed out") | |
1418 | if ap_uuid not in ev: | |
1419 | raise Exception("Expected AP UUID not found") | |
1420 | ||
800bcf4e JM |
1421 | # verify BSSID selection of the AP instead of UUID |
1422 | if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"): | |
1423 | raise Exception("Could not select AP based on BSSID") | |
1424 | ||
fba25c99 | 1425 | dev[0].dump_monitor() |
d6b916c9 JM |
1426 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) |
1427 | dev[2].request("WPS_PBC " + apdev[0]['bssid']) | |
1428 | ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
1429 | if ev is None: | |
1430 | raise Exception("PBC scan failed") | |
1431 | ev = dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
1432 | if ev is None: | |
1433 | raise Exception("PBC scan failed") | |
fba25c99 JM |
1434 | found1 = False |
1435 | found2 = False | |
1436 | addr1 = dev[1].own_addr() | |
1437 | addr2 = dev[2].own_addr() | |
1438 | for i in range(3): | |
d6b916c9 JM |
1439 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) |
1440 | if ev is None: | |
1441 | raise Exception("Enrollee discovery timed out") | |
fba25c99 JM |
1442 | if addr1 in ev: |
1443 | found1 = True | |
1444 | if found2: | |
1445 | break | |
1446 | if addr2 in ev: | |
1447 | found2 = True | |
1448 | if found1: | |
1449 | break | |
d6b916c9 JM |
1450 | if dev[0].request("WPS_ER_PBC " + ap_uuid) != "FAIL-PBC-OVERLAP\n": |
1451 | raise Exception("PBC overlap not reported") | |
1452 | dev[1].request("WPS_CANCEL") | |
1453 | dev[2].request("WPS_CANCEL") | |
1454 | if dev[0].request("WPS_ER_PBC foo") != "FAIL\n": | |
1455 | raise Exception("Invalid WPS_ER_PBC accepted") | |
1456 | ||
1f020f5e JM |
1457 | def test_ap_wps_er_v10_add_enrollee_pin(dev, apdev): |
1458 | """WPS v1.0 ER connected to AP and adding a new enrollee using PIN""" | |
be9f1562 JM |
1459 | try: |
1460 | _test_ap_wps_er_v10_add_enrollee_pin(dev, apdev) | |
1461 | finally: | |
1462 | dev[0].request("WPS_ER_STOP") | |
1463 | ||
1464 | def _test_ap_wps_er_v10_add_enrollee_pin(dev, apdev): | |
1f020f5e JM |
1465 | ssid = "wps-er-add-enrollee-pbc" |
1466 | ap_pin = "12345670" | |
1467 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1468 | hostapd.add_ap(apdev[0], |
1f020f5e JM |
1469 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1470 | "wpa_passphrase": "12345678", "wpa": "2", | |
1471 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1472 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1473 | "model_name": "WAP", "model_number": "123", | |
1474 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1475 | "os_version": "01020300", | |
1476 | "config_methods": "label push_button", | |
1477 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1478 | logger.info("Learn AP configuration") | |
1479 | dev[0].request("SET wps_version_number 0x10") | |
33d0b157 | 1480 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1f020f5e JM |
1481 | dev[0].dump_monitor() |
1482 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1483 | status = dev[0].get_status() | |
1484 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1485 | raise Exception("Not fully connected") | |
1486 | ||
1487 | logger.info("Start ER") | |
1488 | dev[0].request("WPS_ER_START ifname=lo") | |
1489 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1490 | if ev is None: | |
1491 | raise Exception("AP discovery timed out") | |
1492 | if ap_uuid not in ev: | |
1493 | raise Exception("Expected AP UUID not found") | |
1494 | ||
1495 | logger.info("Use learned network configuration on ER") | |
1496 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0") | |
1497 | ||
1498 | logger.info("Add Enrollee using ER and PIN") | |
1499 | enrollee = dev[1].p2p_interface_addr() | |
1500 | pin = dev[1].wps_read_pin() | |
1501 | dev[0].dump_monitor() | |
1502 | dev[0].request("WPS_ER_PIN any " + pin + " " + enrollee) | |
33d0b157 | 1503 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1f020f5e | 1504 | dev[1].dump_monitor() |
33d0b157 | 1505 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 1506 | dev[1].wait_connected(timeout=30) |
1f020f5e JM |
1507 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1508 | if ev is None: | |
1509 | raise Exception("WPS ER did not report success") | |
1510 | ||
9fd6804d | 1511 | @remote_compatible |
be923570 JM |
1512 | def test_ap_wps_er_config_ap(dev, apdev): |
1513 | """WPS ER configuring AP over UPnP""" | |
be9f1562 JM |
1514 | try: |
1515 | _test_ap_wps_er_config_ap(dev, apdev) | |
1516 | finally: | |
1517 | dev[0].request("WPS_ER_STOP") | |
1518 | ||
1519 | def _test_ap_wps_er_config_ap(dev, apdev): | |
be923570 JM |
1520 | ssid = "wps-er-ap-config" |
1521 | ap_pin = "12345670" | |
1522 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 1523 | hostapd.add_ap(apdev[0], |
be923570 JM |
1524 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
1525 | "wpa_passphrase": "12345678", "wpa": "2", | |
1526 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1527 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1528 | "model_name": "WAP", "model_number": "123", | |
1529 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1530 | "os_version": "01020300", | |
1531 | "config_methods": "label push_button", | |
1532 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1533 | ||
1534 | logger.info("Connect ER to the AP") | |
1535 | dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
1536 | ||
1537 | logger.info("WPS configuration step") | |
1538 | dev[0].request("WPS_ER_START ifname=lo") | |
1539 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1540 | if ev is None: | |
1541 | raise Exception("AP discovery timed out") | |
1542 | if ap_uuid not in ev: | |
1543 | raise Exception("Expected AP UUID not found") | |
1544 | new_passphrase = "1234567890" | |
1545 | dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " + | |
1546 | ssid.encode("hex") + " WPA2PSK CCMP " + | |
1547 | new_passphrase.encode("hex")) | |
1548 | ev = dev[0].wait_event(["WPS-SUCCESS"]) | |
1549 | if ev is None: | |
1550 | raise Exception("WPS ER configuration operation timed out") | |
5f35a5e2 | 1551 | dev[0].wait_disconnected(timeout=10) |
be923570 JM |
1552 | dev[0].connect(ssid, psk="1234567890", scan_freq="2412") |
1553 | ||
8f8c2fe8 JM |
1554 | logger.info("WPS ER restart") |
1555 | dev[0].request("WPS_ER_START") | |
1556 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1557 | if ev is None: | |
1558 | raise Exception("AP discovery timed out on ER restart") | |
1559 | if ap_uuid not in ev: | |
1560 | raise Exception("Expected AP UUID not found on ER restart") | |
1561 | if "OK" not in dev[0].request("WPS_ER_STOP"): | |
1562 | raise Exception("WPS_ER_STOP failed") | |
1563 | if "OK" not in dev[0].request("WPS_ER_STOP"): | |
1564 | raise Exception("WPS_ER_STOP failed") | |
1565 | ||
9fd6804d | 1566 | @remote_compatible |
6aaa661a JM |
1567 | def test_ap_wps_er_cache_ap_settings(dev, apdev): |
1568 | """WPS ER caching AP settings""" | |
1569 | try: | |
1570 | _test_ap_wps_er_cache_ap_settings(dev, apdev) | |
1571 | finally: | |
1572 | dev[0].request("WPS_ER_STOP") | |
1573 | ||
1574 | def _test_ap_wps_er_cache_ap_settings(dev, apdev): | |
1575 | ssid = "wps-er-add-enrollee" | |
1576 | ap_pin = "12345670" | |
1577 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1578 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1579 | "wpa_passphrase": "12345678", "wpa": "2", | |
1580 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1581 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1582 | "model_name": "WAP", "model_number": "123", | |
1583 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1584 | "os_version": "01020300", | |
1585 | "config_methods": "label push_button", | |
1586 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1587 | hapd = hostapd.add_ap(apdev[0], params) |
6aaa661a JM |
1588 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1589 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1590 | id = int(dev[0].list_networks()[0]['id']) | |
1591 | dev[0].set_network(id, "scan_freq", "2412") | |
1592 | ||
1593 | dev[0].request("WPS_ER_START ifname=lo") | |
1594 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1595 | if ev is None: | |
1596 | raise Exception("AP discovery timed out") | |
1597 | if ap_uuid not in ev: | |
1598 | raise Exception("Expected AP UUID not found") | |
1599 | ||
1600 | dev[0].dump_monitor() | |
1601 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1602 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1603 | if ev is None: | |
1604 | raise Exception("AP learn timed out") | |
1605 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1606 | if ev is None: | |
1607 | raise Exception("WPS-FAIL after AP learn timed out") | |
1608 | time.sleep(0.1) | |
1609 | ||
1610 | hapd.disable() | |
1611 | ||
1612 | for i in range(2): | |
1613 | ev = dev[0].wait_event([ "WPS-ER-AP-REMOVE", | |
1614 | "CTRL-EVENT-DISCONNECTED" ], | |
1615 | timeout=15) | |
1616 | if ev is None: | |
1617 | raise Exception("AP removal or disconnection timed out") | |
1618 | ||
8b8a1864 | 1619 | hapd = hostapd.add_ap(apdev[0], params) |
6aaa661a JM |
1620 | for i in range(2): |
1621 | ev = dev[0].wait_event([ "WPS-ER-AP-ADD", "CTRL-EVENT-CONNECTED" ], | |
1622 | timeout=15) | |
1623 | if ev is None: | |
1624 | raise Exception("AP discovery or connection timed out") | |
1625 | ||
1626 | pin = dev[1].wps_read_pin() | |
1627 | dev[0].dump_monitor() | |
1628 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
1629 | ||
1630 | time.sleep(0.2) | |
1631 | ||
1632 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1633 | dev[1].dump_monitor() | |
1634 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
1635 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) | |
1636 | if ev is None: | |
1637 | raise Exception("Enrollee did not report success") | |
1638 | dev[1].wait_connected(timeout=15) | |
1639 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
1640 | if ev is None: | |
1641 | raise Exception("WPS ER did not report success") | |
1642 | ||
1643 | dev[0].dump_monitor() | |
1644 | dev[0].request("WPS_ER_STOP") | |
1645 | ||
d840350a JM |
1646 | def test_ap_wps_er_cache_ap_settings_oom(dev, apdev): |
1647 | """WPS ER caching AP settings (OOM)""" | |
1648 | try: | |
1649 | _test_ap_wps_er_cache_ap_settings_oom(dev, apdev) | |
1650 | finally: | |
1651 | dev[0].request("WPS_ER_STOP") | |
1652 | ||
1653 | def _test_ap_wps_er_cache_ap_settings_oom(dev, apdev): | |
1654 | ssid = "wps-er-add-enrollee" | |
1655 | ap_pin = "12345670" | |
1656 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1657 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1658 | "wpa_passphrase": "12345678", "wpa": "2", | |
1659 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1660 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1661 | "model_name": "WAP", "model_number": "123", | |
1662 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1663 | "os_version": "01020300", | |
1664 | "config_methods": "label push_button", | |
1665 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1666 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1667 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1668 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1669 | id = int(dev[0].list_networks()[0]['id']) | |
1670 | dev[0].set_network(id, "scan_freq", "2412") | |
1671 | ||
1672 | dev[0].request("WPS_ER_START ifname=lo") | |
1673 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1674 | if ev is None: | |
1675 | raise Exception("AP discovery timed out") | |
1676 | if ap_uuid not in ev: | |
1677 | raise Exception("Expected AP UUID not found") | |
1678 | ||
1679 | dev[0].dump_monitor() | |
1680 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1681 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1682 | if ev is None: | |
1683 | raise Exception("AP learn timed out") | |
1684 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1685 | if ev is None: | |
1686 | raise Exception("WPS-FAIL after AP learn timed out") | |
1687 | time.sleep(0.1) | |
1688 | ||
1689 | with alloc_fail(dev[0], 1, "=wps_er_ap_use_cached_settings"): | |
1690 | hapd.disable() | |
1691 | ||
1692 | for i in range(2): | |
1693 | ev = dev[0].wait_event([ "WPS-ER-AP-REMOVE", | |
1694 | "CTRL-EVENT-DISCONNECTED" ], | |
1695 | timeout=15) | |
1696 | if ev is None: | |
1697 | raise Exception("AP removal or disconnection timed out") | |
1698 | ||
8b8a1864 | 1699 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1700 | for i in range(2): |
1701 | ev = dev[0].wait_event([ "WPS-ER-AP-ADD", "CTRL-EVENT-CONNECTED" ], | |
1702 | timeout=15) | |
1703 | if ev is None: | |
1704 | raise Exception("AP discovery or connection timed out") | |
1705 | ||
1706 | dev[0].request("WPS_ER_STOP") | |
1707 | ||
1708 | def test_ap_wps_er_cache_ap_settings_oom2(dev, apdev): | |
1709 | """WPS ER caching AP settings (OOM 2)""" | |
1710 | try: | |
1711 | _test_ap_wps_er_cache_ap_settings_oom2(dev, apdev) | |
1712 | finally: | |
1713 | dev[0].request("WPS_ER_STOP") | |
1714 | ||
1715 | def _test_ap_wps_er_cache_ap_settings_oom2(dev, apdev): | |
1716 | ssid = "wps-er-add-enrollee" | |
1717 | ap_pin = "12345670" | |
1718 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1719 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1720 | "wpa_passphrase": "12345678", "wpa": "2", | |
1721 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1722 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1723 | "model_name": "WAP", "model_number": "123", | |
1724 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1725 | "os_version": "01020300", | |
1726 | "config_methods": "label push_button", | |
1727 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1728 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1729 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1730 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1731 | id = int(dev[0].list_networks()[0]['id']) | |
1732 | dev[0].set_network(id, "scan_freq", "2412") | |
1733 | ||
1734 | dev[0].request("WPS_ER_START ifname=lo") | |
1735 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1736 | if ev is None: | |
1737 | raise Exception("AP discovery timed out") | |
1738 | if ap_uuid not in ev: | |
1739 | raise Exception("Expected AP UUID not found") | |
1740 | ||
1741 | dev[0].dump_monitor() | |
1742 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1743 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1744 | if ev is None: | |
1745 | raise Exception("AP learn timed out") | |
1746 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1747 | if ev is None: | |
1748 | raise Exception("WPS-FAIL after AP learn timed out") | |
1749 | time.sleep(0.1) | |
1750 | ||
1751 | with alloc_fail(dev[0], 1, "=wps_er_ap_cache_settings"): | |
1752 | hapd.disable() | |
1753 | ||
1754 | for i in range(2): | |
1755 | ev = dev[0].wait_event([ "WPS-ER-AP-REMOVE", | |
1756 | "CTRL-EVENT-DISCONNECTED" ], | |
1757 | timeout=15) | |
1758 | if ev is None: | |
1759 | raise Exception("AP removal or disconnection timed out") | |
1760 | ||
8b8a1864 | 1761 | hapd = hostapd.add_ap(apdev[0], params) |
d840350a JM |
1762 | for i in range(2): |
1763 | ev = dev[0].wait_event([ "WPS-ER-AP-ADD", "CTRL-EVENT-CONNECTED" ], | |
1764 | timeout=15) | |
1765 | if ev is None: | |
1766 | raise Exception("AP discovery or connection timed out") | |
1767 | ||
1768 | dev[0].request("WPS_ER_STOP") | |
1769 | ||
eb95ced2 JM |
1770 | def test_ap_wps_er_subscribe_oom(dev, apdev): |
1771 | """WPS ER subscribe OOM""" | |
1772 | try: | |
1773 | _test_ap_wps_er_subscribe_oom(dev, apdev) | |
1774 | finally: | |
1775 | dev[0].request("WPS_ER_STOP") | |
1776 | ||
1777 | def _test_ap_wps_er_subscribe_oom(dev, apdev): | |
1778 | ssid = "wps-er-add-enrollee" | |
1779 | ap_pin = "12345670" | |
1780 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1781 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1782 | "wpa_passphrase": "12345678", "wpa": "2", | |
1783 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1784 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1785 | "model_name": "WAP", "model_number": "123", | |
1786 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1787 | "os_version": "01020300", | |
1788 | "config_methods": "label push_button", | |
1789 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1790 | hapd = hostapd.add_ap(apdev[0], params) |
eb95ced2 JM |
1791 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1792 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1793 | id = int(dev[0].list_networks()[0]['id']) | |
1794 | dev[0].set_network(id, "scan_freq", "2412") | |
1795 | ||
1796 | with alloc_fail(dev[0], 1, "http_client_addr;wps_er_subscribe"): | |
1797 | dev[0].request("WPS_ER_START ifname=lo") | |
1798 | for i in range(50): | |
1799 | res = dev[0].request("GET_ALLOC_FAIL") | |
1800 | if res.startswith("0:"): | |
1801 | break | |
1802 | time.sleep(0.1) | |
1803 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=0) | |
1804 | if ev: | |
1805 | raise Exception("Unexpected AP discovery during OOM") | |
1806 | ||
1807 | dev[0].request("WPS_ER_STOP") | |
1808 | ||
db9c88eb JM |
1809 | def test_ap_wps_er_set_sel_reg_oom(dev, apdev): |
1810 | """WPS ER SetSelectedRegistrar OOM""" | |
1811 | try: | |
1812 | _test_ap_wps_er_set_sel_reg_oom(dev, apdev) | |
1813 | finally: | |
1814 | dev[0].request("WPS_ER_STOP") | |
1815 | ||
1816 | def _test_ap_wps_er_set_sel_reg_oom(dev, apdev): | |
1817 | ssid = "wps-er-add-enrollee" | |
1818 | ap_pin = "12345670" | |
1819 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1820 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1821 | "wpa_passphrase": "12345678", "wpa": "2", | |
1822 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1823 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1824 | "model_name": "WAP", "model_number": "123", | |
1825 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1826 | "os_version": "01020300", | |
1827 | "config_methods": "label push_button", | |
1828 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1829 | hapd = hostapd.add_ap(apdev[0], params) |
db9c88eb JM |
1830 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1831 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1832 | ||
1833 | dev[0].request("WPS_ER_START ifname=lo") | |
1834 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
1835 | if ev is None: | |
1836 | raise Exception("AP not discovered") | |
1837 | ||
1838 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1839 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
1840 | if ev is None: | |
1841 | raise Exception("AP learn timed out") | |
1842 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
1843 | if ev is None: | |
1844 | raise Exception("WPS-FAIL timed out") | |
1845 | time.sleep(0.1) | |
1846 | ||
1847 | for func in [ "http_client_url_parse;wps_er_send_set_sel_reg", | |
1848 | "wps_er_soap_hdr;wps_er_send_set_sel_reg", | |
1849 | "http_client_addr;wps_er_send_set_sel_reg", | |
1850 | "wpabuf_alloc;wps_er_set_sel_reg" ]: | |
1851 | with alloc_fail(dev[0], 1, func): | |
1852 | if "OK" not in dev[0].request("WPS_ER_PBC " + ap_uuid): | |
1853 | raise Exception("WPS_ER_PBC failed") | |
1854 | ev = dev[0].wait_event(["WPS-PBC-ACTIVE"], timeout=3) | |
1855 | if ev is None: | |
1856 | raise Exception("WPS-PBC-ACTIVE not seen") | |
1857 | ||
1858 | dev[0].request("WPS_ER_STOP") | |
1859 | ||
9fd6804d | 1860 | @remote_compatible |
ae3eacf7 JM |
1861 | def test_ap_wps_er_learn_oom(dev, apdev): |
1862 | """WPS ER learn OOM""" | |
1863 | try: | |
1864 | _test_ap_wps_er_learn_oom(dev, apdev) | |
1865 | finally: | |
1866 | dev[0].request("WPS_ER_STOP") | |
1867 | ||
1868 | def _test_ap_wps_er_learn_oom(dev, apdev): | |
1869 | ssid = "wps-er-add-enrollee" | |
1870 | ap_pin = "12345670" | |
1871 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1872 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1873 | "wpa_passphrase": "12345678", "wpa": "2", | |
1874 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1875 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1876 | "model_name": "WAP", "model_number": "123", | |
1877 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1878 | "os_version": "01020300", | |
1879 | "config_methods": "label push_button", | |
1880 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo" } | |
8b8a1864 | 1881 | hapd = hostapd.add_ap(apdev[0], params) |
ae3eacf7 JM |
1882 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1883 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1884 | ||
1885 | dev[0].request("WPS_ER_START ifname=lo") | |
1886 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
1887 | if ev is None: | |
1888 | raise Exception("AP not discovered") | |
1889 | ||
1890 | for func in [ "wps_er_http_put_message_cb", | |
1891 | "xml_get_base64_item;wps_er_http_put_message_cb", | |
1892 | "http_client_url_parse;wps_er_ap_put_message", | |
1893 | "wps_er_soap_hdr;wps_er_ap_put_message", | |
1894 | "http_client_addr;wps_er_ap_put_message" ]: | |
1895 | with alloc_fail(dev[0], 1, func): | |
1896 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1897 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=1) | |
1898 | if ev is not None: | |
1899 | raise Exception("AP learn succeeded during OOM") | |
1900 | ||
1901 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
1902 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=10) | |
1903 | if ev is None: | |
1904 | raise Exception("AP learn did not succeed") | |
1905 | ||
1906 | if "FAIL" not in dev[0].request("WPS_ER_LEARN 00000000-9e5c-4e73-bd82-f89cbcd10d7e " + ap_pin): | |
1907 | raise Exception("WPS_ER_LEARN for unknown AP accepted") | |
1908 | ||
1909 | dev[0].request("WPS_ER_STOP") | |
1910 | ||
bff3ac5b JM |
1911 | def test_ap_wps_fragmentation(dev, apdev): |
1912 | """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2""" | |
1913 | ssid = "test-wps-fragmentation" | |
9602b355 | 1914 | appin = "12345670" |
6f334bf7 JD |
1915 | hapd = hostapd.add_ap(apdev[0], |
1916 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1917 | "wpa_passphrase": "12345678", "wpa": "3", | |
1918 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1919 | "wpa_pairwise": "TKIP", "ap_pin": appin, | |
1920 | "fragment_size": "50" }) | |
9602b355 | 1921 | logger.info("WPS provisioning step (PBC)") |
bff3ac5b | 1922 | hapd.request("WPS_PBC") |
33d0b157 | 1923 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
bff3ac5b JM |
1924 | dev[0].dump_monitor() |
1925 | dev[0].request("SET wps_fragment_size 50") | |
33d0b157 | 1926 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1927 | dev[0].wait_connected(timeout=30) |
bff3ac5b JM |
1928 | status = dev[0].get_status() |
1929 | if status['wpa_state'] != 'COMPLETED': | |
9602b355 JM |
1930 | raise Exception("Not fully connected") |
1931 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1932 | raise Exception("Unexpected encryption configuration") | |
1933 | if status['key_mgmt'] != 'WPA2-PSK': | |
1934 | raise Exception("Unexpected key_mgmt") | |
1935 | ||
1936 | logger.info("WPS provisioning step (PIN)") | |
1937 | pin = dev[1].wps_read_pin() | |
1938 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 1939 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9602b355 | 1940 | dev[1].request("SET wps_fragment_size 50") |
33d0b157 | 1941 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 1942 | dev[1].wait_connected(timeout=30) |
9602b355 JM |
1943 | status = dev[1].get_status() |
1944 | if status['wpa_state'] != 'COMPLETED': | |
1945 | raise Exception("Not fully connected") | |
1946 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1947 | raise Exception("Unexpected encryption configuration") | |
1948 | if status['key_mgmt'] != 'WPA2-PSK': | |
1949 | raise Exception("Unexpected key_mgmt") | |
1950 | ||
1951 | logger.info("WPS connection as registrar") | |
33d0b157 | 1952 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9602b355 JM |
1953 | dev[2].request("SET wps_fragment_size 50") |
1954 | dev[2].wps_reg(apdev[0]['bssid'], appin) | |
1955 | status = dev[2].get_status() | |
1956 | if status['wpa_state'] != 'COMPLETED': | |
bff3ac5b JM |
1957 | raise Exception("Not fully connected") |
1958 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1959 | raise Exception("Unexpected encryption configuration") | |
1960 | if status['key_mgmt'] != 'WPA2-PSK': | |
1961 | raise Exception("Unexpected key_mgmt") | |
10ea6848 | 1962 | |
9fd6804d | 1963 | @remote_compatible |
10ea6848 JM |
1964 | def test_ap_wps_new_version_sta(dev, apdev): |
1965 | """WPS compatibility with new version number on the station""" | |
1966 | ssid = "test-wps-ver" | |
6f334bf7 JD |
1967 | hapd = hostapd.add_ap(apdev[0], |
1968 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1969 | "wpa_passphrase": "12345678", "wpa": "2", | |
1970 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
10ea6848 JM |
1971 | logger.info("WPS provisioning step") |
1972 | hapd.request("WPS_PBC") | |
33d0b157 | 1973 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
10ea6848 JM |
1974 | dev[0].dump_monitor() |
1975 | dev[0].request("SET wps_version_number 0x43") | |
dccafedb | 1976 | dev[0].request("SET wps_vendor_ext_m1 000137100100020001") |
33d0b157 | 1977 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1978 | dev[0].wait_connected(timeout=30) |
10ea6848 | 1979 | |
9fd6804d | 1980 | @remote_compatible |
10ea6848 JM |
1981 | def test_ap_wps_new_version_ap(dev, apdev): |
1982 | """WPS compatibility with new version number on the AP""" | |
1983 | ssid = "test-wps-ver" | |
6f334bf7 JD |
1984 | hapd = hostapd.add_ap(apdev[0], |
1985 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1986 | "wpa_passphrase": "12345678", "wpa": "2", | |
1987 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
10ea6848 JM |
1988 | logger.info("WPS provisioning step") |
1989 | if "FAIL" in hapd.request("SET wps_version_number 0x43"): | |
1990 | raise Exception("Failed to enable test functionality") | |
1991 | hapd.request("WPS_PBC") | |
33d0b157 | 1992 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
10ea6848 | 1993 | dev[0].dump_monitor() |
33d0b157 | 1994 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1995 | dev[0].wait_connected(timeout=30) |
10ea6848 | 1996 | hapd.request("SET wps_version_number 0x20") |
3bdf7d7f | 1997 | |
9fd6804d | 1998 | @remote_compatible |
3bdf7d7f JM |
1999 | def test_ap_wps_check_pin(dev, apdev): |
2000 | """Verify PIN checking through control interface""" | |
6f334bf7 JD |
2001 | hapd = hostapd.add_ap(apdev[0], |
2002 | { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
2003 | "wpa_passphrase": "12345678", "wpa": "2", | |
2004 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
3bdf7d7f JM |
2005 | for t in [ ("12345670", "12345670"), |
2006 | ("12345678", "FAIL-CHECKSUM"), | |
df58939c | 2007 | ("12345", "FAIL"), |
6e12eaa4 | 2008 | ("123456789", "FAIL"), |
3bdf7d7f JM |
2009 | ("1234-5670", "12345670"), |
2010 | ("1234 5670", "12345670"), | |
2011 | ("1-2.3:4 5670", "12345670") ]: | |
2012 | res = hapd.request("WPS_CHECK_PIN " + t[0]).rstrip('\n') | |
2013 | res2 = dev[0].request("WPS_CHECK_PIN " + t[0]).rstrip('\n') | |
2014 | if res != res2: | |
2015 | raise Exception("Unexpected difference in WPS_CHECK_PIN responses") | |
2016 | if res != t[1]: | |
2017 | raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res, t[1])) | |
9ba1fcb0 | 2018 | |
ac786d67 JM |
2019 | if "FAIL" not in hapd.request("WPS_CHECK_PIN 12345"): |
2020 | raise Exception("Unexpected WPS_CHECK_PIN success") | |
2021 | if "FAIL" not in hapd.request("WPS_CHECK_PIN 123456789"): | |
2022 | raise Exception("Unexpected WPS_CHECK_PIN success") | |
2023 | ||
acd9b45a JM |
2024 | for i in range(0, 10): |
2025 | pin = dev[0].request("WPS_PIN get") | |
2026 | rpin = dev[0].request("WPS_CHECK_PIN " + pin).rstrip('\n') | |
2027 | if pin != rpin: | |
2028 | raise Exception("Random PIN validation failed for " + pin) | |
2029 | ||
3381d324 JM |
2030 | def test_ap_wps_pin_get_failure(dev, apdev): |
2031 | """PIN generation failure""" | |
2032 | with fail_test(dev[0], 1, | |
2033 | "os_get_random;wpa_supplicant_ctrl_iface_wps_pin"): | |
2034 | if "FAIL" not in dev[0].request("WPS_PIN get"): | |
2035 | raise Exception("WPS_PIN did not report failure") | |
2036 | ||
9ba1fcb0 JM |
2037 | def test_ap_wps_wep_config(dev, apdev): |
2038 | """WPS 2.0 AP rejecting WEP configuration""" | |
2039 | ssid = "test-wps-config" | |
2040 | appin = "12345670" | |
6f334bf7 JD |
2041 | hapd = hostapd.add_ap(apdev[0], |
2042 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2043 | "ap_pin": appin}) | |
33d0b157 | 2044 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9ba1fcb0 JM |
2045 | dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-new-ssid-wep", "OPEN", "WEP", |
2046 | "hello", no_wait=True) | |
2047 | ev = hapd.wait_event(["WPS-FAIL"], timeout=15) | |
2048 | if ev is None: | |
2049 | raise Exception("WPS-FAIL timed out") | |
2050 | if "reason=2" not in ev: | |
2051 | raise Exception("Unexpected reason code in WPS-FAIL") | |
2052 | status = hapd.request("WPS_GET_STATUS") | |
2053 | if "Last WPS result: Failed" not in status: | |
2054 | raise Exception("WPS failure result not shown correctly") | |
2055 | if "Failure Reason: WEP Prohibited" not in status: | |
2056 | raise Exception("Failure reason not reported correctly") | |
2057 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
2058 | raise Exception("Peer address not shown correctly") | |
1013a576 | 2059 | |
11d78bb1 JM |
2060 | def test_ap_wps_wep_enroll(dev, apdev): |
2061 | """WPS 2.0 STA rejecting WEP configuration""" | |
2062 | ssid = "test-wps-wep" | |
6f334bf7 JD |
2063 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
2064 | "skip_cred_build": "1", "extra_cred": "wps-wep-cred" } | |
2065 | hapd = hostapd.add_ap(apdev[0], params) | |
11d78bb1 | 2066 | hapd.request("WPS_PBC") |
33d0b157 JM |
2067 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2068 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
11d78bb1 JM |
2069 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) |
2070 | if ev is None: | |
2071 | raise Exception("WPS-FAIL event timed out") | |
2072 | if "msg=12" not in ev or "reason=2 (WEP Prohibited)" not in ev: | |
2073 | raise Exception("Unexpected WPS-FAIL event: " + ev) | |
2074 | ||
9fd6804d | 2075 | @remote_compatible |
1013a576 JM |
2076 | def test_ap_wps_ie_fragmentation(dev, apdev): |
2077 | """WPS AP using fragmented WPS IE""" | |
2078 | ssid = "test-wps-ie-fragmentation" | |
2079 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2080 | "wpa_passphrase": "12345678", "wpa": "2", | |
2081 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
2082 | "device_name": "1234567890abcdef1234567890abcdef", | |
2083 | "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | |
2084 | "model_name": "1234567890abcdef1234567890abcdef", | |
2085 | "model_number": "1234567890abcdef1234567890abcdef", | |
2086 | "serial_number": "1234567890abcdef1234567890abcdef" } | |
6f334bf7 | 2087 | hapd = hostapd.add_ap(apdev[0], params) |
1013a576 | 2088 | hapd.request("WPS_PBC") |
33d0b157 JM |
2089 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2090 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2091 | dev[0].wait_connected(timeout=30) |
1013a576 JM |
2092 | bss = dev[0].get_bss(apdev[0]['bssid']) |
2093 | if "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef": | |
cf3f0ec8 | 2094 | logger.info("Device Name not received correctly") |
d7a68ad6 | 2095 | logger.info(bss) |
cf3f0ec8 JM |
2096 | # This can fail if Probe Response frame is missed and Beacon frame was |
2097 | # used to fill in the BSS entry. This can happen, e.g., during heavy | |
2098 | # load every now and then and is not really an error, so try to | |
2099 | # workaround by runnign another scan. | |
2100 | dev[0].scan(freq="2412", only_new=True) | |
2101 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
84a40841 | 2102 | if not bss or "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef": |
cf3f0ec8 JM |
2103 | logger.info(bss) |
2104 | raise Exception("Device Name not received correctly") | |
1013a576 JM |
2105 | if len(re.findall("dd..0050f204", bss['ie'])) != 2: |
2106 | raise Exception("Unexpected number of WPS IEs") | |
44ff0400 | 2107 | |
2035b170 JM |
2108 | def get_psk(pskfile): |
2109 | psks = {} | |
2110 | with open(pskfile, "r") as f: | |
2111 | lines = f.read().splitlines() | |
2112 | for l in lines: | |
2113 | if l == "# WPA PSKs": | |
2114 | continue | |
2115 | (addr,psk) = l.split(' ') | |
2116 | psks[addr] = psk | |
2117 | return psks | |
2118 | ||
2119 | def test_ap_wps_per_station_psk(dev, apdev): | |
2120 | """WPS PBC provisioning with per-station PSK""" | |
1d21a5be B |
2121 | addr0 = dev[0].own_addr() |
2122 | addr1 = dev[1].own_addr() | |
2123 | addr2 = dev[2].own_addr() | |
2035b170 JM |
2124 | ssid = "wps" |
2125 | appin = "12345670" | |
2126 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
2127 | try: | |
2128 | os.remove(pskfile) | |
2129 | except: | |
2130 | pass | |
2131 | ||
4f524e99 | 2132 | hapd = None |
2035b170 JM |
2133 | try: |
2134 | with open(pskfile, "w") as f: | |
2135 | f.write("# WPA PSKs\n") | |
2136 | ||
2137 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2138 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
2139 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
2140 | "wpa_psk_file": pskfile } | |
8b8a1864 | 2141 | hapd = hostapd.add_ap(apdev[0], params) |
2035b170 JM |
2142 | |
2143 | logger.info("First enrollee") | |
2144 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2145 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2146 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2147 | dev[0].wait_connected(timeout=30) |
2035b170 JM |
2148 | |
2149 | logger.info("Second enrollee") | |
2150 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2151 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2152 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2153 | dev[1].wait_connected(timeout=30) |
2035b170 JM |
2154 | |
2155 | logger.info("External registrar") | |
33d0b157 | 2156 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2035b170 JM |
2157 | dev[2].wps_reg(apdev[0]['bssid'], appin) |
2158 | ||
2159 | logger.info("Verifying PSK results") | |
2160 | psks = get_psk(pskfile) | |
2161 | if addr0 not in psks: | |
2162 | raise Exception("No PSK recorded for sta0") | |
2163 | if addr1 not in psks: | |
2164 | raise Exception("No PSK recorded for sta1") | |
2165 | if addr2 not in psks: | |
2166 | raise Exception("No PSK recorded for sta2") | |
2167 | if psks[addr0] == psks[addr1]: | |
2168 | raise Exception("Same PSK recorded for sta0 and sta1") | |
2169 | if psks[addr0] == psks[addr2]: | |
2170 | raise Exception("Same PSK recorded for sta0 and sta2") | |
2171 | if psks[addr1] == psks[addr2]: | |
2172 | raise Exception("Same PSK recorded for sta1 and sta2") | |
2173 | ||
2174 | dev[0].request("REMOVE_NETWORK all") | |
2175 | logger.info("Second external registrar") | |
33d0b157 | 2176 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2035b170 JM |
2177 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
2178 | psks2 = get_psk(pskfile) | |
2179 | if addr0 not in psks2: | |
2180 | raise Exception("No PSK recorded for sta0(reg)") | |
2181 | if psks[addr0] == psks2[addr0]: | |
2182 | raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)") | |
2183 | finally: | |
2184 | os.remove(pskfile) | |
4f524e99 JM |
2185 | if hapd: |
2186 | dev[0].request("DISCONNECT") | |
2187 | dev[1].request("DISCONNECT") | |
2188 | dev[2].request("DISCONNECT") | |
2189 | hapd.disable() | |
2190 | dev[0].flush_scan_cache() | |
2191 | dev[1].flush_scan_cache() | |
2192 | dev[2].flush_scan_cache() | |
2035b170 | 2193 | |
373cce55 JM |
2194 | def test_ap_wps_per_station_psk_failure(dev, apdev): |
2195 | """WPS PBC provisioning with per-station PSK (file not writable)""" | |
2196 | addr0 = dev[0].p2p_dev_addr() | |
2197 | addr1 = dev[1].p2p_dev_addr() | |
2198 | addr2 = dev[2].p2p_dev_addr() | |
2199 | ssid = "wps" | |
2200 | appin = "12345670" | |
2201 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
2202 | try: | |
2203 | os.remove(pskfile) | |
2204 | except: | |
2205 | pass | |
2206 | ||
3615bde6 | 2207 | hapd = None |
373cce55 JM |
2208 | try: |
2209 | with open(pskfile, "w") as f: | |
2210 | f.write("# WPA PSKs\n") | |
2211 | ||
2212 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2213 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
2214 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
2215 | "wpa_psk_file": pskfile } | |
8b8a1864 | 2216 | hapd = hostapd.add_ap(apdev[0], params) |
373cce55 JM |
2217 | if "FAIL" in hapd.request("SET wpa_psk_file /tmp/does/not/exists/ap_wps_per_enrollee_psk_failure.psk_file"): |
2218 | raise Exception("Failed to set wpa_psk_file") | |
2219 | ||
2220 | logger.info("First enrollee") | |
2221 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2222 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2223 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2224 | dev[0].wait_connected(timeout=30) |
373cce55 JM |
2225 | |
2226 | logger.info("Second enrollee") | |
2227 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2228 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2229 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2230 | dev[1].wait_connected(timeout=30) |
373cce55 JM |
2231 | |
2232 | logger.info("External registrar") | |
33d0b157 | 2233 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
373cce55 JM |
2234 | dev[2].wps_reg(apdev[0]['bssid'], appin) |
2235 | ||
2236 | logger.info("Verifying PSK results") | |
2237 | psks = get_psk(pskfile) | |
2238 | if len(psks) > 0: | |
2239 | raise Exception("PSK recorded unexpectedly") | |
2240 | finally: | |
3615bde6 JM |
2241 | if hapd: |
2242 | for i in range(3): | |
2243 | dev[i].request("DISCONNECT") | |
2244 | hapd.disable() | |
2245 | for i in range(3): | |
2246 | dev[i].flush_scan_cache() | |
373cce55 JM |
2247 | os.remove(pskfile) |
2248 | ||
e8518757 JM |
2249 | def test_ap_wps_pin_request_file(dev, apdev): |
2250 | """WPS PIN provisioning with configured AP""" | |
2251 | ssid = "wps" | |
2252 | pinfile = "/tmp/ap_wps_pin_request_file.log" | |
2253 | if os.path.exists(pinfile): | |
b638f703 | 2254 | os.remove(pinfile) |
6f334bf7 JD |
2255 | hapd = hostapd.add_ap(apdev[0], |
2256 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2257 | "wps_pin_requests": pinfile, | |
2258 | "wpa_passphrase": "12345678", "wpa": "2", | |
2259 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e8518757 JM |
2260 | uuid = dev[0].get_status_field("uuid") |
2261 | pin = dev[0].wps_read_pin() | |
2262 | try: | |
33d0b157 JM |
2263 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2264 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
e8518757 JM |
2265 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=15) |
2266 | if ev is None: | |
2267 | raise Exception("PIN needed event not shown") | |
2268 | if uuid not in ev: | |
2269 | raise Exception("UUID mismatch") | |
2270 | dev[0].request("WPS_CANCEL") | |
2271 | success = False | |
2272 | with open(pinfile, "r") as f: | |
2273 | lines = f.readlines() | |
2274 | for l in lines: | |
2275 | if uuid in l: | |
2276 | success = True | |
2277 | break | |
2278 | if not success: | |
2279 | raise Exception("PIN request entry not in the log file") | |
2280 | finally: | |
b638f703 JM |
2281 | try: |
2282 | os.remove(pinfile) | |
2283 | except: | |
2284 | pass | |
e8518757 | 2285 | |
56887c35 JM |
2286 | def test_ap_wps_auto_setup_with_config_file(dev, apdev): |
2287 | """WPS auto-setup with configuration file""" | |
2288 | conffile = "/tmp/ap_wps_auto_setup_with_config_file.conf" | |
2289 | ifname = apdev[0]['ifname'] | |
2290 | try: | |
2291 | with open(conffile, "w") as f: | |
2292 | f.write("driver=nl80211\n") | |
2293 | f.write("hw_mode=g\n") | |
2294 | f.write("channel=1\n") | |
2295 | f.write("ieee80211n=1\n") | |
2296 | f.write("interface=%s\n" % ifname) | |
2297 | f.write("ctrl_interface=/var/run/hostapd\n") | |
2298 | f.write("ssid=wps\n") | |
2299 | f.write("eap_server=1\n") | |
2300 | f.write("wps_state=1\n") | |
5148b392 | 2301 | hapd = hostapd.add_bss(apdev[0], ifname, conffile) |
56887c35 | 2302 | hapd.request("WPS_PBC") |
33d0b157 JM |
2303 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2304 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 2305 | dev[0].wait_connected(timeout=30) |
56887c35 JM |
2306 | with open(conffile, "r") as f: |
2307 | lines = f.read().splitlines() | |
2308 | vals = dict() | |
2309 | for l in lines: | |
2310 | try: | |
2311 | [name,value] = l.split('=', 1) | |
2312 | vals[name] = value | |
2313 | except ValueError, e: | |
2314 | if "# WPS configuration" in l: | |
2315 | pass | |
2316 | else: | |
2317 | raise Exception("Unexpected configuration line: " + l) | |
2318 | if vals['ieee80211n'] != '1' or vals['wps_state'] != '2' or "WPA-PSK" not in vals['wpa_key_mgmt']: | |
2319 | raise Exception("Incorrect configuration: " + str(vals)) | |
2320 | finally: | |
b638f703 JM |
2321 | try: |
2322 | os.remove(conffile) | |
2323 | except: | |
2324 | pass | |
56887c35 | 2325 | |
91f3cf69 | 2326 | def test_ap_wps_pbc_timeout(dev, apdev, params): |
31e56b95 | 2327 | """wpa_supplicant PBC walk time and WPS ER SelReg timeout [long]""" |
91f3cf69 | 2328 | if not params['long']: |
81e787b7 | 2329 | raise HwsimSkip("Skip test case with long duration due to --long not specified") |
31e56b95 | 2330 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" |
21aa8b7e | 2331 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
31e56b95 JM |
2332 | |
2333 | location = ssdp_get_location(ap_uuid) | |
2334 | urls = upnp_get_urls(location) | |
2335 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
2336 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
2337 | ||
2338 | url = urlparse.urlparse(location) | |
2339 | conn = httplib.HTTPConnection(url.netloc) | |
2340 | ||
2341 | class WPSERHTTPServer(SocketServer.StreamRequestHandler): | |
2342 | def handle(self): | |
2343 | data = self.rfile.readline().strip() | |
2344 | logger.debug(data) | |
2345 | self.wfile.write(gen_wps_event()) | |
2346 | ||
2347 | server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) | |
2348 | server.timeout = 1 | |
2349 | ||
2350 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2351 | "NT": "upnp:event", | |
2352 | "timeout": "Second-1234" } | |
2353 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2354 | resp = conn.getresponse() | |
2355 | if resp.status != 200: | |
2356 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
2357 | sid = resp.getheader("sid") | |
2358 | logger.debug("Subscription SID " + sid) | |
2359 | ||
2360 | msg = '''<?xml version="1.0"?> | |
2361 | <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> | |
2362 | <s:Body> | |
2363 | <u:SetSelectedRegistrar xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1"> | |
2364 | <NewMessage>EEoAARAQQQABARASAAIAABBTAAIxSBBJAA4ANyoAASABBv///////xBIABA2LbR7pTpRkYj7 | |
2365 | VFi5hrLk | |
2366 | </NewMessage> | |
2367 | </u:SetSelectedRegistrar> | |
2368 | </s:Body> | |
2369 | </s:Envelope>''' | |
2370 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
2371 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % "SetSelectedRegistrar" | |
2372 | conn.request("POST", ctrlurl.path, msg, headers) | |
2373 | resp = conn.getresponse() | |
2374 | if resp.status != 200: | |
2375 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
2376 | ||
2377 | server.handle_request() | |
2378 | ||
91f3cf69 JM |
2379 | logger.info("Start WPS_PBC and wait for PBC walk time expiration") |
2380 | if "OK" not in dev[0].request("WPS_PBC"): | |
2381 | raise Exception("WPS_PBC failed") | |
31e56b95 JM |
2382 | |
2383 | start = os.times()[4] | |
2384 | ||
2385 | server.handle_request() | |
2386 | dev[1].request("BSS_FLUSH 0") | |
2387 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True, | |
2388 | only_new=True) | |
2389 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
2390 | logger.debug("BSS: " + str(bss)) | |
2391 | if '[WPS-AUTH]' not in bss['flags']: | |
2392 | raise Exception("WPS not indicated authorized") | |
2393 | ||
2394 | server.handle_request() | |
2395 | ||
2396 | wps_timeout_seen = False | |
2397 | ||
2398 | while True: | |
2399 | hapd.dump_monitor() | |
2400 | dev[1].dump_monitor() | |
2401 | if not wps_timeout_seen: | |
2402 | ev = dev[0].wait_event(["WPS-TIMEOUT"], timeout=0) | |
2403 | if ev is not None: | |
2404 | logger.info("PBC timeout seen") | |
2405 | wps_timeout_seen = True | |
2406 | else: | |
2407 | dev[0].dump_monitor() | |
2408 | now = os.times()[4] | |
2409 | if now - start > 130: | |
2410 | raise Exception("Selected registration information not removed") | |
2411 | dev[1].request("BSS_FLUSH 0") | |
2412 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True, | |
2413 | only_new=True) | |
2414 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
2415 | logger.debug("BSS: " + str(bss)) | |
2416 | if '[WPS-AUTH]' not in bss['flags']: | |
2417 | break | |
2418 | server.handle_request() | |
2419 | ||
2420 | server.server_close() | |
2421 | ||
2422 | if wps_timeout_seen: | |
2423 | return | |
2424 | ||
2425 | now = os.times()[4] | |
2426 | if now < start + 150: | |
2427 | dur = start + 150 - now | |
2428 | else: | |
2429 | dur = 1 | |
2430 | logger.info("Continue waiting for PBC timeout (%d sec)" % dur) | |
2431 | ev = dev[0].wait_event(["WPS-TIMEOUT"], timeout=dur) | |
91f3cf69 JM |
2432 | if ev is None: |
2433 | raise Exception("WPS-TIMEOUT not reported") | |
2434 | ||
21aa8b7e | 2435 | def add_ssdp_ap(ap, ap_uuid): |
44ff0400 JM |
2436 | ssid = "wps-ssdp" |
2437 | ap_pin = "12345670" | |
24b7f282 JM |
2438 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
2439 | "wpa_passphrase": "12345678", "wpa": "2", | |
2440 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
2441 | "device_name": "Wireless AP", "manufacturer": "Company", | |
2442 | "model_name": "WAP", "model_number": "123", | |
2443 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
2444 | "os_version": "01020300", | |
2445 | "config_methods": "label push_button", | |
2446 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo", | |
2447 | "friendly_name": "WPS Access Point", | |
2448 | "manufacturer_url": "http://www.example.com/", | |
2449 | "model_description": "Wireless Access Point", | |
2450 | "model_url": "http://www.example.com/model/", | |
2451 | "upc": "123456789012" } | |
21aa8b7e | 2452 | return hostapd.add_ap(ap, params) |
44ff0400 JM |
2453 | |
2454 | def ssdp_send(msg, no_recv=False): | |
2455 | socket.setdefaulttimeout(1) | |
2456 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2457 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2458 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2459 | sock.bind(("127.0.0.1", 0)) | |
2460 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2461 | if no_recv: | |
2462 | return None | |
2463 | return sock.recv(1000) | |
2464 | ||
96038a5f | 2465 | def ssdp_send_msearch(st, no_recv=False): |
44ff0400 JM |
2466 | msg = '\r\n'.join([ |
2467 | 'M-SEARCH * HTTP/1.1', | |
2468 | 'HOST: 239.255.255.250:1900', | |
2469 | 'MX: 1', | |
2470 | 'MAN: "ssdp:discover"', | |
2471 | 'ST: ' + st, | |
2472 | '', '']) | |
96038a5f | 2473 | return ssdp_send(msg, no_recv=no_recv) |
44ff0400 JM |
2474 | |
2475 | def test_ap_wps_ssdp_msearch(dev, apdev): | |
2476 | """WPS AP and SSDP M-SEARCH messages""" | |
2477 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2478 | add_ssdp_ap(apdev[0], ap_uuid) |
44ff0400 JM |
2479 | |
2480 | msg = '\r\n'.join([ | |
2481 | 'M-SEARCH * HTTP/1.1', | |
2482 | 'Host: 239.255.255.250:1900', | |
2483 | 'Mx: 1', | |
2484 | 'Man: "ssdp:discover"', | |
2485 | 'St: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2486 | '', '']) | |
2487 | ssdp_send(msg) | |
2488 | ||
2489 | msg = '\r\n'.join([ | |
2490 | 'M-SEARCH * HTTP/1.1', | |
2491 | 'host:\t239.255.255.250:1900\t\t\t\t \t\t', | |
2492 | 'mx: \t1\t\t ', | |
2493 | 'man: \t \t "ssdp:discover" ', | |
2494 | 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t', | |
2495 | '', '']) | |
2496 | ssdp_send(msg) | |
2497 | ||
2498 | ssdp_send_msearch("ssdp:all") | |
2499 | ssdp_send_msearch("upnp:rootdevice") | |
2500 | ssdp_send_msearch("uuid:" + ap_uuid) | |
2501 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1") | |
bc6e3288 | 2502 | ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1") |
44ff0400 JM |
2503 | |
2504 | msg = '\r\n'.join([ | |
2505 | 'M-SEARCH * HTTP/1.1', | |
2506 | 'HOST:\t239.255.255.250:1900', | |
2507 | 'MAN: "ssdp:discover"', | |
2508 | 'MX: 130', | |
2509 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2510 | '', '']) | |
2511 | ssdp_send(msg, no_recv=True) | |
2512 | ||
2513 | def test_ap_wps_ssdp_invalid_msearch(dev, apdev): | |
2514 | """WPS AP and invalid SSDP M-SEARCH messages""" | |
2515 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2516 | add_ssdp_ap(apdev[0], ap_uuid) |
44ff0400 JM |
2517 | |
2518 | socket.setdefaulttimeout(1) | |
2519 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2520 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2521 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2522 | sock.bind(("127.0.0.1", 0)) | |
2523 | ||
2524 | logger.debug("Missing MX") | |
2525 | msg = '\r\n'.join([ | |
2526 | 'M-SEARCH * HTTP/1.1', | |
2527 | 'HOST: 239.255.255.250:1900', | |
2528 | 'MAN: "ssdp:discover"', | |
2529 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2530 | '', '']) | |
2531 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2532 | ||
2533 | logger.debug("Negative MX") | |
2534 | msg = '\r\n'.join([ | |
2535 | 'M-SEARCH * HTTP/1.1', | |
2536 | 'HOST: 239.255.255.250:1900', | |
2537 | 'MX: -1', | |
2538 | 'MAN: "ssdp:discover"', | |
2539 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2540 | '', '']) | |
2541 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2542 | ||
2543 | logger.debug("Invalid MX") | |
2544 | msg = '\r\n'.join([ | |
2545 | 'M-SEARCH * HTTP/1.1', | |
2546 | 'HOST: 239.255.255.250:1900', | |
2547 | 'MX; 1', | |
2548 | 'MAN: "ssdp:discover"', | |
2549 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2550 | '', '']) | |
2551 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2552 | ||
2553 | logger.debug("Missing MAN") | |
2554 | msg = '\r\n'.join([ | |
2555 | 'M-SEARCH * HTTP/1.1', | |
2556 | 'HOST: 239.255.255.250:1900', | |
2557 | 'MX: 1', | |
2558 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2559 | '', '']) | |
2560 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2561 | ||
2562 | logger.debug("Invalid MAN") | |
2563 | msg = '\r\n'.join([ | |
2564 | 'M-SEARCH * HTTP/1.1', | |
2565 | 'HOST: 239.255.255.250:1900', | |
2566 | 'MX: 1', | |
2567 | 'MAN: foo', | |
2568 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2569 | '', '']) | |
2570 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2571 | msg = '\r\n'.join([ | |
2572 | 'M-SEARCH * HTTP/1.1', | |
2573 | 'HOST: 239.255.255.250:1900', | |
2574 | 'MX: 1', | |
2575 | 'MAN; "ssdp:discover"', | |
2576 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2577 | '', '']) | |
2578 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2579 | ||
2580 | logger.debug("Missing HOST") | |
2581 | msg = '\r\n'.join([ | |
2582 | 'M-SEARCH * HTTP/1.1', | |
2583 | 'MAN: "ssdp:discover"', | |
2584 | 'MX: 1', | |
2585 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2586 | '', '']) | |
2587 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2588 | ||
2589 | logger.debug("Missing ST") | |
2590 | msg = '\r\n'.join([ | |
2591 | 'M-SEARCH * HTTP/1.1', | |
2592 | 'HOST: 239.255.255.250:1900', | |
2593 | 'MAN: "ssdp:discover"', | |
2594 | 'MX: 1', | |
2595 | '', '']) | |
2596 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2597 | ||
2598 | logger.debug("Mismatching ST") | |
2599 | msg = '\r\n'.join([ | |
2600 | 'M-SEARCH * HTTP/1.1', | |
2601 | 'HOST: 239.255.255.250:1900', | |
2602 | 'MAN: "ssdp:discover"', | |
2603 | 'MX: 1', | |
2604 | 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d', | |
2605 | '', '']) | |
2606 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2607 | msg = '\r\n'.join([ | |
2608 | 'M-SEARCH * HTTP/1.1', | |
2609 | 'HOST: 239.255.255.250:1900', | |
2610 | 'MAN: "ssdp:discover"', | |
2611 | 'MX: 1', | |
2612 | 'ST: foo:bar', | |
2613 | '', '']) | |
2614 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2615 | msg = '\r\n'.join([ | |
2616 | 'M-SEARCH * HTTP/1.1', | |
2617 | 'HOST: 239.255.255.250:1900', | |
2618 | 'MAN: "ssdp:discover"', | |
2619 | 'MX: 1', | |
2620 | 'ST: foobar', | |
2621 | '', '']) | |
2622 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2623 | ||
2624 | logger.debug("Invalid ST") | |
2625 | msg = '\r\n'.join([ | |
2626 | 'M-SEARCH * HTTP/1.1', | |
2627 | 'HOST: 239.255.255.250:1900', | |
2628 | 'MAN: "ssdp:discover"', | |
2629 | 'MX: 1', | |
2630 | 'ST; urn:schemas-wifialliance-org:device:WFADevice:1', | |
2631 | '', '']) | |
2632 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2633 | ||
2634 | logger.debug("Invalid M-SEARCH") | |
2635 | msg = '\r\n'.join([ | |
2636 | 'M+SEARCH * HTTP/1.1', | |
2637 | 'HOST: 239.255.255.250:1900', | |
2638 | 'MAN: "ssdp:discover"', | |
2639 | 'MX: 1', | |
2640 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2641 | '', '']) | |
2642 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2643 | msg = '\r\n'.join([ | |
2644 | 'M-SEARCH-* HTTP/1.1', | |
2645 | 'HOST: 239.255.255.250:1900', | |
2646 | 'MAN: "ssdp:discover"', | |
2647 | 'MX: 1', | |
2648 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2649 | '', '']) | |
2650 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2651 | ||
2652 | logger.debug("Invalid message format") | |
2653 | sock.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900)) | |
2654 | msg = '\r'.join([ | |
2655 | 'M-SEARCH * HTTP/1.1', | |
2656 | 'HOST: 239.255.255.250:1900', | |
2657 | 'MAN: "ssdp:discover"', | |
2658 | 'MX: 1', | |
2659 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2660 | '', '']) | |
2661 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2662 | ||
2663 | try: | |
2664 | r = sock.recv(1000) | |
2665 | raise Exception("Unexpected M-SEARCH response: " + r) | |
2666 | except socket.timeout: | |
2667 | pass | |
2668 | ||
2669 | logger.debug("Valid M-SEARCH") | |
2670 | msg = '\r\n'.join([ | |
2671 | 'M-SEARCH * HTTP/1.1', | |
2672 | 'HOST: 239.255.255.250:1900', | |
2673 | 'MAN: "ssdp:discover"', | |
2674 | 'MX: 1', | |
2675 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2676 | '', '']) | |
2677 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2678 | ||
2679 | try: | |
2680 | r = sock.recv(1000) | |
2681 | pass | |
2682 | except socket.timeout: | |
2683 | raise Exception("No SSDP response") | |
2684 | ||
2685 | def test_ap_wps_ssdp_burst(dev, apdev): | |
2686 | """WPS AP and SSDP burst""" | |
2687 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2688 | add_ssdp_ap(apdev[0], ap_uuid) |
44ff0400 JM |
2689 | |
2690 | msg = '\r\n'.join([ | |
2691 | 'M-SEARCH * HTTP/1.1', | |
2692 | 'HOST: 239.255.255.250:1900', | |
2693 | 'MAN: "ssdp:discover"', | |
2694 | 'MX: 1', | |
2695 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
2696 | '', '']) | |
2697 | socket.setdefaulttimeout(1) | |
2698 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2699 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2700 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2701 | sock.bind(("127.0.0.1", 0)) | |
2702 | for i in range(0, 25): | |
2703 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2704 | resp = 0 | |
2705 | while True: | |
2706 | try: | |
2707 | r = sock.recv(1000) | |
2708 | if not r.startswith("HTTP/1.1 200 OK\r\n"): | |
2709 | raise Exception("Unexpected message: " + r) | |
2710 | resp += 1 | |
2711 | except socket.timeout: | |
2712 | break | |
2713 | if resp < 20: | |
2714 | raise Exception("Too few SSDP responses") | |
2715 | ||
2716 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
2717 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
2718 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
2719 | sock.bind(("127.0.0.1", 0)) | |
2720 | for i in range(0, 25): | |
2721 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
2722 | while True: | |
2723 | try: | |
2724 | r = sock.recv(1000) | |
2725 | if ap_uuid in r: | |
2726 | break | |
2727 | except socket.timeout: | |
2728 | raise Exception("No SSDP response") | |
47c549fd JM |
2729 | |
2730 | def ssdp_get_location(uuid): | |
2731 | res = ssdp_send_msearch("uuid:" + uuid) | |
2732 | location = None | |
2733 | for l in res.splitlines(): | |
2734 | if l.lower().startswith("location:"): | |
2735 | location = l.split(':', 1)[1].strip() | |
2736 | break | |
2737 | if location is None: | |
2738 | raise Exception("No UPnP location found") | |
2739 | return location | |
2740 | ||
2741 | def upnp_get_urls(location): | |
aa713e71 | 2742 | conn = urllib.urlopen(location, proxies={}) |
47c549fd JM |
2743 | tree = ET.parse(conn) |
2744 | root = tree.getroot() | |
2745 | urn = '{urn:schemas-upnp-org:device-1-0}' | |
2746 | service = root.find("./" + urn + "device/" + urn + "serviceList/" + urn + "service") | |
2747 | res = {} | |
2748 | res['scpd_url'] = urlparse.urljoin(location, service.find(urn + 'SCPDURL').text) | |
2749 | res['control_url'] = urlparse.urljoin(location, service.find(urn + 'controlURL').text) | |
2750 | res['event_sub_url'] = urlparse.urljoin(location, service.find(urn + 'eventSubURL').text) | |
2751 | return res | |
2752 | ||
dd124ee8 JM |
2753 | def upnp_soap_action(conn, path, action, include_soap_action=True, |
2754 | soap_action_override=None, newmsg=None, neweventtype=None, | |
2755 | neweventmac=None): | |
47c549fd JM |
2756 | soapns = 'http://schemas.xmlsoap.org/soap/envelope/' |
2757 | wpsns = 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1' | |
2758 | ET.register_namespace('soapenv', soapns) | |
2759 | ET.register_namespace('wfa', wpsns) | |
2760 | attrib = {} | |
2761 | attrib['{%s}encodingStyle' % soapns] = 'http://schemas.xmlsoap.org/soap/encoding/' | |
2762 | root = ET.Element("{%s}Envelope" % soapns, attrib=attrib) | |
2763 | body = ET.SubElement(root, "{%s}Body" % soapns) | |
2764 | act = ET.SubElement(body, "{%s}%s" % (wpsns, action)) | |
dd124ee8 JM |
2765 | if newmsg: |
2766 | msg = ET.SubElement(act, "NewMessage") | |
2767 | msg.text = base64.b64encode(newmsg) | |
2768 | if neweventtype: | |
2769 | msg = ET.SubElement(act, "NewWLANEventType") | |
2770 | msg.text = neweventtype | |
2771 | if neweventmac: | |
2772 | msg = ET.SubElement(act, "NewWLANEventMAC") | |
2773 | msg.text = neweventmac | |
47c549fd JM |
2774 | tree = ET.ElementTree(root) |
2775 | soap = StringIO.StringIO() | |
2776 | tree.write(soap, xml_declaration=True, encoding='utf-8') | |
2777 | ||
2778 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
2779 | if include_soap_action: | |
2780 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action | |
2781 | elif soap_action_override: | |
2782 | headers["SOAPAction"] = soap_action_override | |
2783 | conn.request("POST", path, soap.getvalue(), headers) | |
2784 | return conn.getresponse() | |
2785 | ||
2786 | def test_ap_wps_upnp(dev, apdev): | |
2787 | """WPS AP and UPnP operations""" | |
2788 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2789 | add_ssdp_ap(apdev[0], ap_uuid) |
47c549fd JM |
2790 | |
2791 | location = ssdp_get_location(ap_uuid) | |
2792 | urls = upnp_get_urls(location) | |
2793 | ||
aa713e71 | 2794 | conn = urllib.urlopen(urls['scpd_url'], proxies={}) |
47c549fd JM |
2795 | scpd = conn.read() |
2796 | ||
aa713e71 AO |
2797 | conn = urllib.urlopen(urlparse.urljoin(location, "unknown.html"), |
2798 | proxies={}) | |
47c549fd JM |
2799 | if conn.getcode() != 404: |
2800 | raise Exception("Unexpected HTTP response to GET unknown URL") | |
2801 | ||
2802 | url = urlparse.urlparse(location) | |
2803 | conn = httplib.HTTPConnection(url.netloc) | |
2804 | #conn.set_debuglevel(1) | |
2805 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
2806 | "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' } | |
2807 | conn.request("POST", "hello", "\r\n\r\n", headers) | |
2808 | resp = conn.getresponse() | |
2809 | if resp.status != 404: | |
5c267d71 | 2810 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2811 | |
2812 | conn.request("UNKNOWN", "hello", "\r\n\r\n", headers) | |
2813 | resp = conn.getresponse() | |
2814 | if resp.status != 501: | |
5c267d71 | 2815 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2816 | |
2817 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
2818 | "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' } | |
2819 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
2820 | conn.request("POST", ctrlurl.path, "\r\n\r\n", headers) | |
2821 | resp = conn.getresponse() | |
2822 | if resp.status != 401: | |
5c267d71 | 2823 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2824 | |
2825 | logger.debug("GetDeviceInfo without SOAPAction header") | |
2826 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo", | |
2827 | include_soap_action=False) | |
2828 | if resp.status != 401: | |
5c267d71 | 2829 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2830 | |
2831 | logger.debug("GetDeviceInfo with invalid SOAPAction header") | |
2832 | for act in [ "foo", | |
2833 | "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo", | |
2834 | '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"', | |
2835 | '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']: | |
2836 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo", | |
2837 | include_soap_action=False, | |
2838 | soap_action_override=act) | |
2839 | if resp.status != 401: | |
5c267d71 | 2840 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2841 | |
2842 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
2843 | if resp.status != 200: | |
5c267d71 | 2844 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2845 | dev = resp.read() |
2846 | if "NewDeviceInfo" not in dev: | |
2847 | raise Exception("Unexpected GetDeviceInfo response") | |
2848 | ||
2849 | logger.debug("PutMessage without required parameters") | |
2850 | resp = upnp_soap_action(conn, ctrlurl.path, "PutMessage") | |
2851 | if resp.status != 600: | |
5c267d71 | 2852 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2853 | |
2854 | logger.debug("PutWLANResponse without required parameters") | |
2855 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse") | |
2856 | if resp.status != 600: | |
5c267d71 | 2857 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2858 | |
2859 | logger.debug("SetSelectedRegistrar from unregistered ER") | |
2860 | resp = upnp_soap_action(conn, ctrlurl.path, "SetSelectedRegistrar") | |
2861 | if resp.status != 501: | |
5c267d71 | 2862 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2863 | |
2864 | logger.debug("Unknown action") | |
2865 | resp = upnp_soap_action(conn, ctrlurl.path, "Unknown") | |
2866 | if resp.status != 401: | |
5c267d71 | 2867 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2868 | |
2869 | def test_ap_wps_upnp_subscribe(dev, apdev): | |
2870 | """WPS AP and UPnP event subscription""" | |
2871 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 2872 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
47c549fd JM |
2873 | |
2874 | location = ssdp_get_location(ap_uuid) | |
2875 | urls = upnp_get_urls(location) | |
2876 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
2877 | ||
2878 | url = urlparse.urlparse(location) | |
2879 | conn = httplib.HTTPConnection(url.netloc) | |
2880 | #conn.set_debuglevel(1) | |
2881 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2882 | "timeout": "Second-1234" } | |
2883 | conn.request("SUBSCRIBE", "hello", "\r\n\r\n", headers) | |
2884 | resp = conn.getresponse() | |
2885 | if resp.status != 412: | |
5c267d71 | 2886 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2887 | |
2888 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2889 | resp = conn.getresponse() | |
2890 | if resp.status != 412: | |
5c267d71 | 2891 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2892 | |
2893 | headers = { "NT": "upnp:event", | |
2894 | "timeout": "Second-1234" } | |
2895 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2896 | resp = conn.getresponse() | |
2897 | if resp.status != 412: | |
5c267d71 | 2898 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2899 | |
2900 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2901 | "NT": "upnp:foobar", | |
2902 | "timeout": "Second-1234" } | |
2903 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2904 | resp = conn.getresponse() | |
2905 | if resp.status != 400: | |
5c267d71 | 2906 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2907 | |
2908 | logger.debug("Valid subscription") | |
2909 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2910 | "NT": "upnp:event", | |
2911 | "timeout": "Second-1234" } | |
2912 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2913 | resp = conn.getresponse() | |
2914 | if resp.status != 200: | |
5c267d71 | 2915 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2916 | sid = resp.getheader("sid") |
2917 | logger.debug("Subscription SID " + sid) | |
2918 | ||
2919 | logger.debug("Invalid re-subscription") | |
2920 | headers = { "NT": "upnp:event", | |
2921 | "sid": "123456734567854", | |
2922 | "timeout": "Second-1234" } | |
2923 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2924 | resp = conn.getresponse() | |
2925 | if resp.status != 400: | |
5c267d71 | 2926 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2927 | |
2928 | logger.debug("Invalid re-subscription") | |
2929 | headers = { "NT": "upnp:event", | |
2930 | "sid": "uuid:123456734567854", | |
2931 | "timeout": "Second-1234" } | |
2932 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2933 | resp = conn.getresponse() | |
2934 | if resp.status != 400: | |
5c267d71 | 2935 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2936 | |
2937 | logger.debug("Invalid re-subscription") | |
2938 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2939 | "NT": "upnp:event", | |
2940 | "sid": sid, | |
2941 | "timeout": "Second-1234" } | |
2942 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2943 | resp = conn.getresponse() | |
2944 | if resp.status != 400: | |
5c267d71 | 2945 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2946 | |
2947 | logger.debug("SID mismatch in re-subscription") | |
2948 | headers = { "NT": "upnp:event", | |
2949 | "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb", | |
2950 | "timeout": "Second-1234" } | |
2951 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2952 | resp = conn.getresponse() | |
2953 | if resp.status != 412: | |
5c267d71 | 2954 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2955 | |
2956 | logger.debug("Valid re-subscription") | |
2957 | headers = { "NT": "upnp:event", | |
2958 | "sid": sid, | |
2959 | "timeout": "Second-1234" } | |
2960 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2961 | resp = conn.getresponse() | |
2962 | if resp.status != 200: | |
5c267d71 | 2963 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2964 | sid2 = resp.getheader("sid") |
2965 | logger.debug("Subscription SID " + sid2) | |
2966 | ||
2967 | if sid != sid2: | |
2968 | raise Exception("Unexpected SID change") | |
2969 | ||
2970 | logger.debug("Valid re-subscription") | |
2971 | headers = { "NT": "upnp:event", | |
2972 | "sid": "uuid: \t \t" + sid.split(':')[1], | |
2973 | "timeout": "Second-1234" } | |
2974 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2975 | resp = conn.getresponse() | |
2976 | if resp.status != 200: | |
5c267d71 | 2977 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2978 | |
2979 | logger.debug("Invalid unsubscription") | |
2980 | headers = { "sid": sid } | |
2981 | conn.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers) | |
2982 | resp = conn.getresponse() | |
2983 | if resp.status != 412: | |
5c267d71 | 2984 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2985 | headers = { "foo": "bar" } |
2986 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2987 | resp = conn.getresponse() | |
2988 | if resp.status != 412: | |
5c267d71 | 2989 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2990 | |
2991 | logger.debug("Valid unsubscription") | |
2992 | headers = { "sid": sid } | |
2993 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2994 | resp = conn.getresponse() | |
2995 | if resp.status != 200: | |
5c267d71 | 2996 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
2997 | |
2998 | logger.debug("Unsubscription for not existing SID") | |
2999 | headers = { "sid": sid } | |
3000 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3001 | resp = conn.getresponse() | |
3002 | if resp.status != 412: | |
5c267d71 | 3003 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3004 | |
3005 | logger.debug("Invalid unsubscription") | |
3006 | headers = { "sid": " \t \tfoo" } | |
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 | |
3012 | logger.debug("Invalid unsubscription") | |
3013 | headers = { "sid": "uuid:\t \tfoo" } | |
3014 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3015 | resp = conn.getresponse() | |
3016 | if resp.status != 400: | |
5c267d71 | 3017 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3018 | |
3019 | logger.debug("Invalid unsubscription") | |
3020 | headers = { "NT": "upnp:event", | |
3021 | "sid": sid } | |
3022 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3023 | resp = conn.getresponse() | |
3024 | if resp.status != 400: | |
5c267d71 | 3025 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3026 | headers = { "callback": '<http://127.0.0.1:12345/event>', |
3027 | "sid": sid } | |
3028 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3029 | resp = conn.getresponse() | |
3030 | if resp.status != 400: | |
5c267d71 | 3031 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3032 | |
3033 | logger.debug("Valid subscription with multiple callbacks") | |
3034 | 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>', | |
3035 | "NT": "upnp:event", | |
3036 | "timeout": "Second-1234" } | |
3037 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3038 | resp = conn.getresponse() | |
3039 | if resp.status != 200: | |
5c267d71 | 3040 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
47c549fd JM |
3041 | sid = resp.getheader("sid") |
3042 | logger.debug("Subscription SID " + sid) | |
d352c407 | 3043 | |
24b7f282 JM |
3044 | # Force subscription to be deleted due to errors |
3045 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3046 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3047 | with alloc_fail(hapd, 1, "event_build_message"): | |
3048 | for i in range(10): | |
3049 | dev[1].dump_monitor() | |
3050 | dev[2].dump_monitor() | |
3051 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3052 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3053 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3054 | dev[1].request("WPS_CANCEL") | |
3055 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3056 | dev[2].request("WPS_CANCEL") | |
3057 | if i % 4 == 1: | |
3058 | time.sleep(1) | |
3059 | else: | |
3060 | time.sleep(0.1) | |
3061 | time.sleep(0.2) | |
3062 | ||
3063 | headers = { "sid": sid } | |
3064 | conn.request("UNSUBSCRIBE", eventurl.path, "", headers) | |
3065 | resp = conn.getresponse() | |
3066 | if resp.status != 200 and resp.status != 412: | |
3067 | raise Exception("Unexpected HTTP response for UNSUBSCRIBE: %d" % resp.status) | |
3068 | ||
3069 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3070 | "NT": "upnp:event", | |
3071 | "timeout": "Second-1234" } | |
3072 | with alloc_fail(hapd, 1, "http_client_addr;event_send_start"): | |
3073 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3074 | resp = conn.getresponse() | |
3075 | if resp.status != 200: | |
3076 | raise Exception("Unexpected HTTP response for SUBSCRIBE: %d" % resp.status) | |
3077 | sid = resp.getheader("sid") | |
3078 | logger.debug("Subscription SID " + sid) | |
3079 | ||
3080 | headers = { "sid": sid } | |
3081 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3082 | resp = conn.getresponse() | |
3083 | if resp.status != 200: | |
3084 | raise Exception("Unexpected HTTP response for UNSUBSCRIBE: %d" % resp.status) | |
3085 | ||
3086 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3087 | "NT": "upnp:event", | |
3088 | "timeout": "Second-1234" } | |
3089 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3090 | resp = conn.getresponse() | |
3091 | if resp.status != 200: | |
3092 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3093 | sid = resp.getheader("sid") | |
3094 | logger.debug("Subscription SID " + sid) | |
3095 | ||
3096 | with alloc_fail(hapd, 1, "=event_add"): | |
3097 | for i in range(2): | |
3098 | dev[1].dump_monitor() | |
3099 | dev[2].dump_monitor() | |
3100 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3101 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3102 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3103 | dev[1].request("WPS_CANCEL") | |
3104 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3105 | dev[2].request("WPS_CANCEL") | |
3106 | if i == 0: | |
3107 | time.sleep(1) | |
3108 | else: | |
3109 | time.sleep(0.1) | |
3110 | ||
3111 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3112 | resp = conn.getresponse() | |
3113 | if resp.status != 200: | |
3114 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3115 | ||
3116 | with alloc_fail(hapd, 1, "wpabuf_dup;event_add"): | |
3117 | dev[1].dump_monitor() | |
3118 | dev[2].dump_monitor() | |
3119 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3120 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3121 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3122 | dev[1].request("WPS_CANCEL") | |
3123 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3124 | dev[2].request("WPS_CANCEL") | |
3125 | time.sleep(0.1) | |
3126 | ||
3127 | with fail_test(hapd, 1, "os_get_random;uuid_make;subscription_start"): | |
3128 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3129 | resp = conn.getresponse() | |
3130 | if resp.status != 500: | |
3131 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3132 | ||
3133 | with alloc_fail(hapd, 1, "=subscription_start"): | |
3134 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3135 | resp = conn.getresponse() | |
3136 | if resp.status != 500: | |
3137 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3138 | ||
3139 | headers = { "callback": '', | |
3140 | "NT": "upnp:event", | |
3141 | "timeout": "Second-1234" } | |
3142 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3143 | resp = conn.getresponse() | |
3144 | if resp.status != 500: | |
3145 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3146 | ||
3147 | headers = { "callback": ' <', | |
3148 | "NT": "upnp:event", | |
3149 | "timeout": "Second-1234" } | |
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 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3156 | "NT": "upnp:event", | |
3157 | "timeout": "Second-1234" } | |
3158 | with alloc_fail(hapd, 1, "wpabuf_alloc;subscription_first_event"): | |
3159 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3160 | resp = conn.getresponse() | |
3161 | if resp.status != 500: | |
3162 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3163 | ||
3164 | with alloc_fail(hapd, 1, "event_add;subscription_first_event"): | |
3165 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3166 | resp = conn.getresponse() | |
3167 | if resp.status != 500: | |
3168 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3169 | ||
3170 | with alloc_fail(hapd, 1, "subscr_addr_add_url"): | |
3171 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3172 | resp = conn.getresponse() | |
3173 | if resp.status != 500: | |
3174 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3175 | ||
3176 | with alloc_fail(hapd, 2, "subscr_addr_add_url"): | |
3177 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3178 | resp = conn.getresponse() | |
3179 | if resp.status != 500: | |
3180 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3181 | ||
3182 | for i in range(6): | |
3183 | headers = { "callback": '<http://127.0.0.1:%d/event>' % (12345 + i), | |
3184 | "NT": "upnp:event", | |
3185 | "timeout": "Second-1234" } | |
3186 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3187 | resp = conn.getresponse() | |
3188 | if resp.status != 200: | |
3189 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3190 | ||
3191 | with alloc_fail(hapd, 1, "=upnp_wps_device_send_wlan_event"): | |
3192 | dev[1].dump_monitor() | |
3193 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3194 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3195 | dev[1].request("WPS_CANCEL") | |
3196 | time.sleep(0.1) | |
3197 | ||
3198 | with alloc_fail(hapd, 1, "wpabuf_alloc;upnp_wps_device_send_event"): | |
3199 | dev[1].dump_monitor() | |
3200 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3201 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3202 | dev[1].request("WPS_CANCEL") | |
3203 | time.sleep(0.1) | |
3204 | ||
3205 | with alloc_fail(hapd, 1, "base64_encode;upnp_wps_device_send_wlan_event"): | |
3206 | dev[1].dump_monitor() | |
3207 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3208 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3209 | dev[1].request("WPS_CANCEL") | |
3210 | time.sleep(0.1) | |
3211 | ||
3212 | hapd.disable() | |
3213 | with alloc_fail(hapd, 1, "get_netif_info"): | |
3214 | if "FAIL" not in hapd.request("ENABLE"): | |
3215 | raise Exception("ENABLE succeeded during OOM") | |
3216 | ||
d91a64c4 JM |
3217 | def test_ap_wps_upnp_subscribe_events(dev, apdev): |
3218 | """WPS AP and UPnP event subscription and many events""" | |
3219 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 3220 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
d91a64c4 JM |
3221 | |
3222 | location = ssdp_get_location(ap_uuid) | |
3223 | urls = upnp_get_urls(location) | |
3224 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
3225 | ||
3226 | class WPSERHTTPServer(SocketServer.StreamRequestHandler): | |
3227 | def handle(self): | |
3228 | data = self.rfile.readline().strip() | |
3229 | logger.debug(data) | |
3230 | self.wfile.write(gen_wps_event()) | |
3231 | ||
3232 | server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) | |
3233 | server.timeout = 1 | |
3234 | ||
3235 | url = urlparse.urlparse(location) | |
3236 | conn = httplib.HTTPConnection(url.netloc) | |
3237 | ||
3238 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
3239 | "NT": "upnp:event", | |
3240 | "timeout": "Second-1234" } | |
3241 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
3242 | resp = conn.getresponse() | |
3243 | if resp.status != 200: | |
3244 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
3245 | sid = resp.getheader("sid") | |
3246 | logger.debug("Subscription SID " + sid) | |
3247 | ||
3248 | # Fetch the first event message | |
3249 | server.handle_request() | |
3250 | ||
3251 | # Force subscription event queue to reach the maximum length by generating | |
3252 | # new proxied events without the ER fetching any of the pending events. | |
3253 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3254 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3255 | for i in range(16): | |
3256 | dev[1].dump_monitor() | |
3257 | dev[2].dump_monitor() | |
3258 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3259 | dev[2].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3260 | dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3261 | dev[1].request("WPS_CANCEL") | |
3262 | dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
3263 | dev[2].request("WPS_CANCEL") | |
3264 | if i % 4 == 1: | |
3265 | time.sleep(1) | |
3266 | else: | |
3267 | time.sleep(0.1) | |
3268 | ||
3269 | hapd.request("WPS_PIN any 12345670") | |
3270 | dev[1].dump_monitor() | |
3271 | dev[1].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3272 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=10) | |
3273 | if ev is None: | |
3274 | raise Exception("WPS success not reported") | |
3275 | ||
3276 | # Close the WPS ER HTTP server without fetching all the pending events. | |
3277 | # This tests hostapd code path that clears subscription and the remaining | |
3278 | # event queue when the interface is deinitialized. | |
3279 | server.handle_request() | |
3280 | server.server_close() | |
3281 | ||
3282 | dev[1].wait_connected() | |
3283 | ||
b2047531 JM |
3284 | def test_ap_wps_upnp_http_proto(dev, apdev): |
3285 | """WPS AP and UPnP/HTTP protocol testing""" | |
3286 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 3287 | add_ssdp_ap(apdev[0], ap_uuid) |
b2047531 JM |
3288 | |
3289 | location = ssdp_get_location(ap_uuid) | |
3290 | ||
3291 | url = urlparse.urlparse(location) | |
81f8e7e9 | 3292 | conn = httplib.HTTPConnection(url.netloc, timeout=0.2) |
b2047531 JM |
3293 | #conn.set_debuglevel(1) |
3294 | ||
3295 | conn.request("HEAD", "hello") | |
3296 | resp = conn.getresponse() | |
3297 | if resp.status != 501: | |
3298 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3299 | conn.close() | |
3300 | ||
3301 | for cmd in [ "PUT", "DELETE", "TRACE", "CONNECT", "M-SEARCH", "M-POST" ]: | |
3302 | try: | |
3303 | conn.request(cmd, "hello") | |
3304 | resp = conn.getresponse() | |
3305 | except Exception, e: | |
3306 | pass | |
3307 | conn.close() | |
3308 | ||
3309 | headers = { "Content-Length": 'abc' } | |
3310 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3311 | try: | |
3312 | resp = conn.getresponse() | |
3313 | except Exception, e: | |
3314 | pass | |
3315 | conn.close() | |
3316 | ||
3317 | headers = { "Content-Length": '-10' } | |
3318 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3319 | try: | |
3320 | resp = conn.getresponse() | |
3321 | except Exception, e: | |
3322 | pass | |
3323 | conn.close() | |
3324 | ||
3325 | headers = { "Content-Length": '10000000000000' } | |
3326 | conn.request("HEAD", "hello", "\r\n\r\nhello", headers) | |
3327 | try: | |
3328 | resp = conn.getresponse() | |
3329 | except Exception, e: | |
3330 | pass | |
3331 | conn.close() | |
3332 | ||
3333 | headers = { "Transfer-Encoding": 'abc' } | |
3334 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3335 | resp = conn.getresponse() | |
3336 | if resp.status != 501: | |
3337 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3338 | conn.close() | |
3339 | ||
3340 | headers = { "Transfer-Encoding": 'chunked' } | |
3341 | conn.request("HEAD", "hello", "\r\n\r\n", headers) | |
3342 | resp = conn.getresponse() | |
3343 | if resp.status != 501: | |
3344 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3345 | conn.close() | |
3346 | ||
3347 | # Too long a header | |
3348 | conn.request("HEAD", 5000 * 'A') | |
3349 | try: | |
3350 | resp = conn.getresponse() | |
3351 | except Exception, e: | |
3352 | pass | |
3353 | conn.close() | |
3354 | ||
3355 | # Long URL but within header length limits | |
3356 | conn.request("HEAD", 3000 * 'A') | |
3357 | resp = conn.getresponse() | |
3358 | if resp.status != 501: | |
3359 | raise Exception("Unexpected response to HEAD: " + str(resp.status)) | |
3360 | conn.close() | |
3361 | ||
3362 | headers = { "Content-Length": '20' } | |
3363 | conn.request("POST", "hello", 10 * 'A' + "\r\n\r\n", headers) | |
3364 | try: | |
3365 | resp = conn.getresponse() | |
3366 | except Exception, e: | |
3367 | pass | |
3368 | conn.close() | |
3369 | ||
3370 | conn.request("POST", "hello", 5000 * 'A' + "\r\n\r\n") | |
3371 | resp = conn.getresponse() | |
3372 | if resp.status != 404: | |
5c267d71 | 3373 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
b2047531 JM |
3374 | conn.close() |
3375 | ||
3376 | conn.request("POST", "hello", 60000 * 'A' + "\r\n\r\n") | |
3377 | try: | |
3378 | resp = conn.getresponse() | |
3379 | except Exception, e: | |
3380 | pass | |
3381 | conn.close() | |
3382 | ||
3383 | def test_ap_wps_upnp_http_proto_chunked(dev, apdev): | |
3384 | """WPS AP and UPnP/HTTP protocol testing for chunked encoding""" | |
3385 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 3386 | add_ssdp_ap(apdev[0], ap_uuid) |
b2047531 JM |
3387 | |
3388 | location = ssdp_get_location(ap_uuid) | |
3389 | ||
3390 | url = urlparse.urlparse(location) | |
3391 | conn = httplib.HTTPConnection(url.netloc) | |
3392 | #conn.set_debuglevel(1) | |
3393 | ||
3394 | headers = { "Transfer-Encoding": 'chunked' } | |
3395 | conn.request("POST", "hello", | |
3396 | "a\r\nabcdefghij\r\n" + "2\r\nkl\r\n" + "0\r\n\r\n", | |
3397 | headers) | |
3398 | resp = conn.getresponse() | |
3399 | if resp.status != 404: | |
5c267d71 | 3400 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
b2047531 JM |
3401 | conn.close() |
3402 | ||
3403 | conn.putrequest("POST", "hello") | |
3404 | conn.putheader('Transfer-Encoding', 'chunked') | |
3405 | conn.endheaders() | |
3406 | conn.send("a\r\nabcdefghij\r\n") | |
3407 | time.sleep(0.1) | |
3408 | conn.send("2\r\nkl\r\n") | |
3409 | conn.send("0\r\n\r\n") | |
3410 | resp = conn.getresponse() | |
3411 | if resp.status != 404: | |
5c267d71 | 3412 | raise Exception("Unexpected HTTP response: %d" % resp.status) |
b2047531 JM |
3413 | conn.close() |
3414 | ||
3415 | conn.putrequest("POST", "hello") | |
3416 | conn.putheader('Transfer-Encoding', 'chunked') | |
3417 | conn.endheaders() | |
3418 | completed = False | |
3419 | try: | |
3420 | for i in range(20000): | |
3421 | conn.send("1\r\nZ\r\n") | |
3422 | conn.send("0\r\n\r\n") | |
3423 | resp = conn.getresponse() | |
3424 | completed = True | |
3425 | except Exception, e: | |
3426 | pass | |
3427 | conn.close() | |
3428 | if completed: | |
3429 | raise Exception("Too long chunked request did not result in connection reset") | |
3430 | ||
3431 | headers = { "Transfer-Encoding": 'chunked' } | |
3432 | conn.request("POST", "hello", "80000000\r\na", headers) | |
3433 | try: | |
3434 | resp = conn.getresponse() | |
3435 | except Exception, e: | |
3436 | pass | |
3437 | conn.close() | |
3438 | ||
3439 | conn.request("POST", "hello", "10000000\r\na", headers) | |
3440 | try: | |
3441 | resp = conn.getresponse() | |
3442 | except Exception, e: | |
3443 | pass | |
3444 | conn.close() | |
3445 | ||
9fd6804d | 3446 | @remote_compatible |
d352c407 JM |
3447 | def test_ap_wps_disabled(dev, apdev): |
3448 | """WPS operations while WPS is disabled""" | |
3449 | ssid = "test-wps-disabled" | |
6f334bf7 | 3450 | hapd = hostapd.add_ap(apdev[0], { "ssid": ssid }) |
d352c407 JM |
3451 | if "FAIL" not in hapd.request("WPS_PBC"): |
3452 | raise Exception("WPS_PBC succeeded unexpectedly") | |
3453 | if "FAIL" not in hapd.request("WPS_CANCEL"): | |
3454 | raise Exception("WPS_CANCEL succeeded unexpectedly") | |
a0fd2ae6 JM |
3455 | |
3456 | def test_ap_wps_mixed_cred(dev, apdev): | |
3457 | """WPS 2.0 STA merging mixed mode WPA/WPA2 credentials""" | |
3458 | ssid = "test-wps-wep" | |
6f334bf7 JD |
3459 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3460 | "skip_cred_build": "1", "extra_cred": "wps-mixed-cred" } | |
3461 | hapd = hostapd.add_ap(apdev[0], params) | |
a0fd2ae6 | 3462 | hapd.request("WPS_PBC") |
33d0b157 JM |
3463 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
3464 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
9ed53f5e | 3465 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30) |
a0fd2ae6 JM |
3466 | if ev is None: |
3467 | raise Exception("WPS-SUCCESS event timed out") | |
3468 | nets = dev[0].list_networks() | |
3469 | if len(nets) != 1: | |
3470 | raise Exception("Unexpected number of network blocks") | |
3471 | id = nets[0]['id'] | |
3472 | proto = dev[0].get_network(id, "proto") | |
3473 | if proto != "WPA RSN": | |
3474 | raise Exception("Unexpected merged proto field value: " + proto) | |
3475 | pairwise = dev[0].get_network(id, "pairwise") | |
72a8e30b | 3476 | if pairwise != "CCMP TKIP" and pairwise != "CCMP GCMP TKIP": |
a0fd2ae6 | 3477 | raise Exception("Unexpected merged pairwise field value: " + pairwise) |
e5a79e3f | 3478 | |
9fd6804d | 3479 | @remote_compatible |
e5a79e3f JM |
3480 | def test_ap_wps_while_connected(dev, apdev): |
3481 | """WPS PBC provisioning while connected to another AP""" | |
3482 | ssid = "test-wps-conf" | |
6f334bf7 JD |
3483 | hapd = hostapd.add_ap(apdev[0], |
3484 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3485 | "wpa_passphrase": "12345678", "wpa": "2", | |
3486 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e5a79e3f | 3487 | |
8b8a1864 | 3488 | hostapd.add_ap(apdev[1], { "ssid": "open" }) |
e5a79e3f JM |
3489 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") |
3490 | ||
3491 | logger.info("WPS provisioning step") | |
3492 | hapd.request("WPS_PBC") | |
3493 | dev[0].dump_monitor() | |
33d0b157 | 3494 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 3495 | dev[0].wait_connected(timeout=30) |
e5a79e3f JM |
3496 | status = dev[0].get_status() |
3497 | if status['bssid'] != apdev[0]['bssid']: | |
3498 | raise Exception("Unexpected BSSID") | |
3499 | ||
9fd6804d | 3500 | @remote_compatible |
e5a79e3f JM |
3501 | def test_ap_wps_while_connected_no_autoconnect(dev, apdev): |
3502 | """WPS PBC provisioning while connected to another AP and STA_AUTOCONNECT disabled""" | |
3503 | ssid = "test-wps-conf" | |
6f334bf7 JD |
3504 | hapd = hostapd.add_ap(apdev[0], |
3505 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3506 | "wpa_passphrase": "12345678", "wpa": "2", | |
3507 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
e5a79e3f | 3508 | |
8b8a1864 | 3509 | hostapd.add_ap(apdev[1], { "ssid": "open" }) |
e5a79e3f JM |
3510 | |
3511 | try: | |
3512 | dev[0].request("STA_AUTOCONNECT 0") | |
3513 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") | |
3514 | ||
3515 | logger.info("WPS provisioning step") | |
3516 | hapd.request("WPS_PBC") | |
3517 | dev[0].dump_monitor() | |
33d0b157 | 3518 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 3519 | dev[0].wait_connected(timeout=30) |
e5a79e3f JM |
3520 | status = dev[0].get_status() |
3521 | if status['bssid'] != apdev[0]['bssid']: | |
3522 | raise Exception("Unexpected BSSID") | |
3523 | finally: | |
3524 | dev[0].request("STA_AUTOCONNECT 1") | |
3f08d1cd | 3525 | |
9fd6804d | 3526 | @remote_compatible |
3f08d1cd JM |
3527 | def test_ap_wps_from_event(dev, apdev): |
3528 | """WPS PBC event on AP to enable PBC""" | |
3529 | ssid = "test-wps-conf" | |
8b8a1864 | 3530 | hapd = hostapd.add_ap(apdev[0], |
3f08d1cd JM |
3531 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3532 | "wpa_passphrase": "12345678", "wpa": "2", | |
3533 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
33d0b157 | 3534 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
3f08d1cd | 3535 | dev[0].dump_monitor() |
33d0b157 JM |
3536 | hapd.dump_monitor() |
3537 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
3f08d1cd JM |
3538 | |
3539 | ev = hapd.wait_event(['WPS-ENROLLEE-SEEN'], timeout=15) | |
3540 | if ev is None: | |
3541 | raise Exception("No WPS-ENROLLEE-SEEN event on AP") | |
3542 | vals = ev.split(' ') | |
3543 | if vals[1] != dev[0].p2p_interface_addr(): | |
3544 | raise Exception("Unexpected enrollee address: " + vals[1]) | |
3545 | if vals[5] != '4': | |
3546 | raise Exception("Unexpected Device Password Id: " + vals[5]) | |
3547 | hapd.request("WPS_PBC") | |
5f35a5e2 | 3548 | dev[0].wait_connected(timeout=30) |
1531402e JM |
3549 | |
3550 | def test_ap_wps_ap_scan_2(dev, apdev): | |
3551 | """AP_SCAN 2 for WPS""" | |
3552 | ssid = "test-wps-conf" | |
8b8a1864 | 3553 | hapd = hostapd.add_ap(apdev[0], |
1531402e JM |
3554 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3555 | "wpa_passphrase": "12345678", "wpa": "2", | |
3556 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
3557 | hapd.request("WPS_PBC") | |
3558 | ||
3559 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
3560 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
4b9d79b6 | 3561 | wpas.dump_monitor() |
1531402e JM |
3562 | |
3563 | if "OK" not in wpas.request("AP_SCAN 2"): | |
3564 | raise Exception("Failed to set AP_SCAN 2") | |
3565 | ||
e51c8b2e | 3566 | wpas.flush_scan_cache() |
33d0b157 | 3567 | wpas.scan_for_bss(apdev[0]['bssid'], freq="2412") |
4b9d79b6 | 3568 | wpas.dump_monitor() |
33d0b157 | 3569 | wpas.request("WPS_PBC " + apdev[0]['bssid']) |
1531402e JM |
3570 | ev = wpas.wait_event(["WPS-SUCCESS"], timeout=15) |
3571 | if ev is None: | |
3572 | raise Exception("WPS-SUCCESS event timed out") | |
5f35a5e2 | 3573 | wpas.wait_connected(timeout=30) |
4b9d79b6 | 3574 | wpas.dump_monitor() |
1531402e JM |
3575 | wpas.request("DISCONNECT") |
3576 | wpas.request("BSS_FLUSH 0") | |
3577 | wpas.dump_monitor() | |
3578 | wpas.request("REASSOCIATE") | |
5f35a5e2 | 3579 | wpas.wait_connected(timeout=30) |
4b9d79b6 | 3580 | wpas.dump_monitor() |
a08fdb17 | 3581 | |
9fd6804d | 3582 | @remote_compatible |
a08fdb17 JM |
3583 | def test_ap_wps_eapol_workaround(dev, apdev): |
3584 | """EAPOL workaround code path for 802.1X header length mismatch""" | |
3585 | ssid = "test-wps" | |
6f334bf7 JD |
3586 | hapd = hostapd.add_ap(apdev[0], |
3587 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
a08fdb17 JM |
3588 | bssid = apdev[0]['bssid'] |
3589 | hapd.request("SET ext_eapol_frame_io 1") | |
3590 | dev[0].request("SET ext_eapol_frame_io 1") | |
3591 | hapd.request("WPS_PBC") | |
3592 | dev[0].request("WPS_PBC") | |
3593 | ||
3594 | ev = hapd.wait_event(["EAPOL-TX"], timeout=15) | |
3595 | if ev is None: | |
3596 | raise Exception("Timeout on EAPOL-TX from hostapd") | |
3597 | ||
3598 | res = dev[0].request("EAPOL_RX " + bssid + " 020000040193000501FFFF") | |
3599 | if "OK" not in res: | |
3600 | raise Exception("EAPOL_RX to wpa_supplicant failed") | |
46dea617 JM |
3601 | |
3602 | def test_ap_wps_iteration(dev, apdev): | |
3603 | """WPS PIN and iterate through APs without selected registrar""" | |
3604 | ssid = "test-wps-conf" | |
8b8a1864 | 3605 | hapd = hostapd.add_ap(apdev[0], |
46dea617 JM |
3606 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3607 | "wpa_passphrase": "12345678", "wpa": "2", | |
3608 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
3609 | ||
3610 | ssid2 = "test-wps-conf2" | |
8b8a1864 | 3611 | hapd2 = hostapd.add_ap(apdev[1], |
46dea617 JM |
3612 | { "ssid": ssid2, "eap_server": "1", "wps_state": "2", |
3613 | "wpa_passphrase": "12345678", "wpa": "2", | |
3614 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
3615 | ||
3616 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3617 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
3618 | dev[0].dump_monitor() | |
3619 | pin = dev[0].request("WPS_PIN any") | |
3620 | ||
3621 | # Wait for iteration through all WPS APs to happen before enabling any | |
3622 | # Registrar. | |
3623 | for i in range(2): | |
3624 | ev = dev[0].wait_event(["Associated with"], timeout=30) | |
3625 | if ev is None: | |
3626 | raise Exception("No association seen") | |
3627 | ev = dev[0].wait_event(["WPS-M2D"], timeout=10) | |
3628 | if ev is None: | |
3629 | raise Exception("No M2D from AP") | |
3630 | dev[0].wait_disconnected() | |
3631 | ||
3632 | # Verify that each AP requested PIN | |
3633 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=1) | |
3634 | if ev is None: | |
3635 | raise Exception("No WPS-PIN-NEEDED event from AP") | |
3636 | ev = hapd2.wait_event(["WPS-PIN-NEEDED"], timeout=1) | |
3637 | if ev is None: | |
3638 | raise Exception("No WPS-PIN-NEEDED event from AP2") | |
3639 | ||
3640 | # Provide PIN to one of the APs and verify that connection gets formed | |
3641 | hapd.request("WPS_PIN any " + pin) | |
3642 | dev[0].wait_connected(timeout=30) | |
2272f5aa JM |
3643 | |
3644 | def test_ap_wps_iteration_error(dev, apdev): | |
3645 | """WPS AP iteration on no Selected Registrar and error case with an AP""" | |
3646 | ssid = "test-wps-conf-pin" | |
8b8a1864 | 3647 | hapd = hostapd.add_ap(apdev[0], |
2272f5aa JM |
3648 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3649 | "wpa_passphrase": "12345678", "wpa": "2", | |
3650 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
3651 | "wps_independent": "1" }) | |
3652 | hapd.request("SET ext_eapol_frame_io 1") | |
3653 | bssid = apdev[0]['bssid'] | |
3654 | pin = dev[0].wps_read_pin() | |
3655 | dev[0].request("WPS_PIN any " + pin) | |
3656 | ||
3657 | ev = hapd.wait_event(["EAPOL-TX"], timeout=15) | |
3658 | if ev is None: | |
3659 | raise Exception("No EAPOL-TX (EAP-Request/Identity) from hostapd") | |
3660 | dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2]) | |
3661 | ||
3662 | ev = hapd.wait_event(["EAPOL-TX"], timeout=15) | |
3663 | if ev is None: | |
3664 | raise Exception("No EAPOL-TX (EAP-WSC/Start) from hostapd") | |
3665 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5) | |
3666 | if ev is None: | |
3667 | raise Exception("No CTRL-EVENT-EAP-STARTED") | |
3668 | ||
3669 | # Do not forward any more EAPOL frames to test wpa_supplicant behavior for | |
3670 | # a case with an incorrectly behaving WPS AP. | |
3671 | ||
3672 | # Start the real target AP and activate registrar on it. | |
8b8a1864 | 3673 | hapd2 = hostapd.add_ap(apdev[1], |
2272f5aa JM |
3674 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3675 | "wpa_passphrase": "12345678", "wpa": "2", | |
3676 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
3677 | "wps_independent": "1" }) | |
3678 | hapd2.request("WPS_PIN any " + pin) | |
3679 | ||
3680 | dev[0].wait_disconnected(timeout=15) | |
3681 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=15) | |
3682 | if ev is None: | |
3683 | raise Exception("No CTRL-EVENT-EAP-STARTED for the second AP") | |
3684 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=15) | |
3685 | if ev is None: | |
3686 | raise Exception("No WPS-CRED-RECEIVED for the second AP") | |
3687 | dev[0].wait_connected(timeout=15) | |
d6f6a86a | 3688 | |
9fd6804d | 3689 | @remote_compatible |
d6f6a86a JM |
3690 | def test_ap_wps_priority(dev, apdev): |
3691 | """WPS PIN provisioning with configured AP and wps_priority""" | |
3692 | ssid = "test-wps-conf-pin" | |
6f334bf7 JD |
3693 | hapd = hostapd.add_ap(apdev[0], |
3694 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3695 | "wpa_passphrase": "12345678", "wpa": "2", | |
3696 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
d6f6a86a JM |
3697 | logger.info("WPS provisioning step") |
3698 | pin = dev[0].wps_read_pin() | |
3699 | hapd.request("WPS_PIN any " + pin) | |
3700 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3701 | dev[0].dump_monitor() | |
3702 | try: | |
3703 | dev[0].request("SET wps_priority 6") | |
3704 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
3705 | dev[0].wait_connected(timeout=30) | |
3706 | netw = dev[0].list_networks() | |
3707 | prio = dev[0].get_network(netw[0]['id'], 'priority') | |
3708 | if prio != '6': | |
3709 | raise Exception("Unexpected network priority: " + prio) | |
3710 | finally: | |
3711 | dev[0].request("SET wps_priority 0") | |
2c3a0190 | 3712 | |
9fd6804d | 3713 | @remote_compatible |
df1d01cf JM |
3714 | def test_ap_wps_and_non_wps(dev, apdev): |
3715 | """WPS and non-WPS AP in single hostapd process""" | |
3716 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "1" } | |
8b8a1864 | 3717 | hapd = hostapd.add_ap(apdev[0], params) |
df1d01cf JM |
3718 | |
3719 | params = { "ssid": "no wps" } | |
8b8a1864 | 3720 | hapd2 = hostapd.add_ap(apdev[1], params) |
df1d01cf JM |
3721 | |
3722 | appin = hapd.request("WPS_AP_PIN random") | |
3723 | if "FAIL" in appin: | |
3724 | raise Exception("Could not generate random AP PIN") | |
3725 | if appin not in hapd.request("WPS_AP_PIN get"): | |
3726 | raise Exception("Could not fetch current AP PIN") | |
3727 | ||
3728 | if "FAIL" in hapd.request("WPS_PBC"): | |
3729 | raise Exception("WPS_PBC failed") | |
3730 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
3731 | raise Exception("WPS_CANCEL failed") | |
3732 | ||
2c3a0190 JM |
3733 | def test_ap_wps_init_oom(dev, apdev): |
3734 | """Initial AP configuration and OOM during PSK generation""" | |
3735 | ssid = "test-wps" | |
3736 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" } | |
8b8a1864 | 3737 | hapd = hostapd.add_ap(apdev[0], params) |
2c3a0190 JM |
3738 | |
3739 | with alloc_fail(hapd, 1, "base64_encode;wps_build_cred"): | |
3740 | pin = dev[0].wps_read_pin() | |
3741 | hapd.request("WPS_PIN any " + pin) | |
3742 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3743 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
3744 | dev[0].wait_disconnected() | |
3745 | ||
3746 | hapd.request("WPS_PIN any " + pin) | |
3747 | dev[0].wait_connected(timeout=30) | |
ccf4d764 | 3748 | |
9fd6804d | 3749 | @remote_compatible |
ccf4d764 JM |
3750 | def test_ap_wps_er_oom(dev, apdev): |
3751 | """WPS ER OOM in XML processing""" | |
3752 | try: | |
3753 | _test_ap_wps_er_oom(dev, apdev) | |
3754 | finally: | |
3755 | dev[0].request("WPS_ER_STOP") | |
3756 | dev[1].request("WPS_CANCEL") | |
3757 | dev[0].request("DISCONNECT") | |
3758 | ||
3759 | def _test_ap_wps_er_oom(dev, apdev): | |
3760 | ssid = "wps-er-ap-config" | |
3761 | ap_pin = "12345670" | |
3762 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
8b8a1864 | 3763 | hostapd.add_ap(apdev[0], |
ccf4d764 JM |
3764 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
3765 | "wpa_passphrase": "12345678", "wpa": "2", | |
3766 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
3767 | "device_name": "Wireless AP", "manufacturer": "Company", | |
3768 | "model_name": "WAP", "model_number": "123", | |
3769 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
3770 | "os_version": "01020300", | |
3771 | "config_methods": "label push_button", | |
3772 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
3773 | ||
3774 | dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
3775 | ||
3776 | with alloc_fail(dev[0], 1, "base64_decode;xml_get_base64_item"): | |
3777 | dev[0].request("WPS_ER_START ifname=lo") | |
3778 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=3) | |
3779 | if ev is not None: | |
3780 | raise Exception("Unexpected AP discovery") | |
3781 | ||
3782 | dev[0].request("WPS_ER_STOP") | |
3783 | dev[0].request("WPS_ER_START ifname=lo") | |
3784 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
3785 | if ev is None: | |
3786 | raise Exception("AP discovery timed out") | |
3787 | ||
3788 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
3789 | with alloc_fail(dev[0], 1, "base64_decode;xml_get_base64_item"): | |
3790 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
3791 | ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
3792 | if ev is None: | |
3793 | raise Exception("PBC scan failed") | |
3794 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) | |
3795 | if ev is None: | |
3796 | raise Exception("Enrollee discovery timed out") | |
2602a2ff | 3797 | |
9fd6804d | 3798 | @remote_compatible |
c965ae03 JM |
3799 | def test_ap_wps_er_init_oom(dev, apdev): |
3800 | """WPS ER and OOM during init""" | |
3801 | try: | |
3802 | _test_ap_wps_er_init_oom(dev, apdev) | |
3803 | finally: | |
3804 | dev[0].request("WPS_ER_STOP") | |
3805 | ||
3806 | def _test_ap_wps_er_init_oom(dev, apdev): | |
3807 | with alloc_fail(dev[0], 1, "wps_er_init"): | |
3808 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3809 | raise Exception("WPS_ER_START succeeded during OOM") | |
3810 | with alloc_fail(dev[0], 1, "http_server_init"): | |
3811 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3812 | raise Exception("WPS_ER_START succeeded during OOM") | |
3813 | with alloc_fail(dev[0], 2, "http_server_init"): | |
3814 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3815 | raise Exception("WPS_ER_START succeeded during OOM") | |
9b35afd6 | 3816 | with alloc_fail(dev[0], 1, "eloop_sock_table_add_sock;?eloop_register_sock;wps_er_ssdp_init"): |
c965ae03 JM |
3817 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): |
3818 | raise Exception("WPS_ER_START succeeded during OOM") | |
3819 | with fail_test(dev[0], 1, "os_get_random;wps_er_init"): | |
3820 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo"): | |
3821 | raise Exception("WPS_ER_START succeeded during os_get_random failure") | |
3822 | ||
9fd6804d | 3823 | @remote_compatible |
07536b18 JM |
3824 | def test_ap_wps_er_init_fail(dev, apdev): |
3825 | """WPS ER init failure""" | |
3826 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=does-not-exist"): | |
3827 | dev[0].request("WPS_ER_STOP") | |
3828 | raise Exception("WPS_ER_START with non-existing ifname succeeded") | |
3829 | ||
2602a2ff JM |
3830 | def test_ap_wps_wpa_cli_action(dev, apdev, test_params): |
3831 | """WPS events and wpa_cli action script""" | |
8936b095 JM |
3832 | logdir = os.path.abspath(test_params['logdir']) |
3833 | pidfile = os.path.join(logdir, 'ap_wps_wpa_cli_action.wpa_cli.pid') | |
3834 | logfile = os.path.join(logdir, 'ap_wps_wpa_cli_action.wpa_cli.res') | |
3835 | actionfile = os.path.join(logdir, 'ap_wps_wpa_cli_action.wpa_cli.action.sh') | |
2602a2ff JM |
3836 | |
3837 | with open(actionfile, 'w') as f: | |
3838 | f.write('#!/bin/sh\n') | |
3839 | f.write('echo $* >> %s\n' % logfile) | |
3840 | # Kill the process and wait some time before returning to allow all the | |
3841 | # pending events to be processed with some of this happening after the | |
3842 | # eloop SIGALRM signal has been scheduled. | |
3843 | f.write('if [ $2 = "WPS-SUCCESS" -a -r %s ]; then kill `cat %s`; sleep 1; fi\n' % (pidfile, pidfile)) | |
3844 | ||
8936b095 JM |
3845 | os.chmod(actionfile, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | |
3846 | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) | |
2602a2ff JM |
3847 | |
3848 | ssid = "test-wps-conf" | |
6f334bf7 JD |
3849 | hapd = hostapd.add_ap(apdev[0], |
3850 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
3851 | "wpa_passphrase": "12345678", "wpa": "2", | |
3852 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
2602a2ff JM |
3853 | |
3854 | prg = os.path.join(test_params['logdir'], | |
3855 | 'alt-wpa_supplicant/wpa_supplicant/wpa_cli') | |
3856 | if not os.path.exists(prg): | |
3857 | prg = '../../wpa_supplicant/wpa_cli' | |
3858 | arg = [ prg, '-P', pidfile, '-B', '-i', dev[0].ifname, '-a', actionfile ] | |
3859 | subprocess.call(arg) | |
3860 | ||
3861 | arg = [ 'ps', 'ax' ] | |
3862 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE) | |
3863 | out = cmd.communicate()[0] | |
3864 | cmd.wait() | |
3865 | logger.debug("Processes:\n" + out) | |
3866 | if "wpa_cli -P %s -B -i %s" % (pidfile, dev[0].ifname) not in out: | |
3867 | raise Exception("Did not see wpa_cli running") | |
3868 | ||
3869 | hapd.request("WPS_PIN any 12345670") | |
3870 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
3871 | dev[0].dump_monitor() | |
3872 | dev[0].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
3873 | dev[0].wait_connected(timeout=30) | |
3874 | ||
3875 | for i in range(30): | |
3876 | if not os.path.exists(pidfile): | |
3877 | break | |
3878 | time.sleep(0.1) | |
3879 | ||
3880 | if not os.path.exists(logfile): | |
3881 | raise Exception("wpa_cli action results file not found") | |
3882 | with open(logfile, 'r') as f: | |
3883 | res = f.read() | |
3884 | if "WPS-SUCCESS" not in res: | |
3885 | raise Exception("WPS-SUCCESS event not seen in action file") | |
3886 | ||
3887 | arg = [ 'ps', 'ax' ] | |
3888 | cmd = subprocess.Popen(arg, stdout=subprocess.PIPE) | |
3889 | out = cmd.communicate()[0] | |
3890 | cmd.wait() | |
3891 | logger.debug("Remaining processes:\n" + out) | |
3892 | if "wpa_cli -P %s -B -i %s" % (pidfile, dev[0].ifname) in out: | |
3893 | raise Exception("wpa_cli still running") | |
3894 | ||
3895 | if os.path.exists(pidfile): | |
3896 | raise Exception("PID file not removed") | |
c965ae03 JM |
3897 | |
3898 | def test_ap_wps_er_ssdp_proto(dev, apdev): | |
3899 | """WPS ER SSDP protocol testing""" | |
3900 | try: | |
3901 | _test_ap_wps_er_ssdp_proto(dev, apdev) | |
3902 | finally: | |
3903 | dev[0].request("WPS_ER_STOP") | |
3904 | ||
3905 | def _test_ap_wps_er_ssdp_proto(dev, apdev): | |
3906 | socket.setdefaulttimeout(1) | |
3907 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
3908 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
3909 | sock.bind(("239.255.255.250", 1900)) | |
3910 | if "FAIL" not in dev[0].request("WPS_ER_START ifname=lo foo"): | |
3911 | raise Exception("Invalid filter accepted") | |
3912 | if "OK" not in dev[0].request("WPS_ER_START ifname=lo 1.2.3.4"): | |
3913 | raise Exception("WPS_ER_START with filter failed") | |
3914 | (msg,addr) = sock.recvfrom(1000) | |
3915 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
3916 | if "M-SEARCH" not in msg: | |
3917 | raise Exception("Not an M-SEARCH") | |
3918 | sock.sendto("FOO", addr) | |
3919 | time.sleep(0.1) | |
3920 | dev[0].request("WPS_ER_STOP") | |
3921 | ||
3922 | dev[0].request("WPS_ER_START ifname=lo") | |
3923 | (msg,addr) = sock.recvfrom(1000) | |
3924 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
3925 | if "M-SEARCH" not in msg: | |
3926 | raise Exception("Not an M-SEARCH") | |
3927 | sock.sendto("FOO", addr) | |
3928 | sock.sendto("HTTP/1.1 200 OK\r\nFOO\r\n\r\n", addr) | |
3929 | sock.sendto("HTTP/1.1 200 OK\r\nNTS:foo\r\n\r\n", addr) | |
3930 | sock.sendto("HTTP/1.1 200 OK\r\nNTS:ssdp:byebye\r\n\r\n", addr) | |
3931 | sock.sendto("HTTP/1.1 200 OK\r\ncache-control: foo=1\r\n\r\n", addr) | |
3932 | sock.sendto("HTTP/1.1 200 OK\r\ncache-control: max-age=1\r\n\r\n", addr) | |
3933 | sock.sendto("HTTP/1.1 200 OK\r\nusn:\r\n\r\n", addr) | |
3934 | sock.sendto("HTTP/1.1 200 OK\r\nusn:foo\r\n\r\n", addr) | |
3935 | sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid:\r\n\r\n", addr) | |
3936 | sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid: \r\n\r\n", addr) | |
3937 | sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid: foo\r\n\r\n", addr) | |
3938 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\n\r\n", addr) | |
3939 | 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) | |
3940 | sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\n\r\n", addr) | |
3941 | with alloc_fail(dev[0], 1, "wps_er_ap_add"): | |
3942 | 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) | |
3943 | time.sleep(0.1) | |
3944 | with alloc_fail(dev[0], 2, "wps_er_ap_add"): | |
3945 | 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) | |
3946 | time.sleep(0.1) | |
3947 | ||
3948 | # Add an AP with bogus URL | |
3949 | 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) | |
3950 | # Update timeout on AP without updating URL | |
3951 | 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) | |
3952 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5) | |
3953 | if ev is None: | |
3954 | raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout") | |
3955 | ||
3956 | # Add an AP with a valid URL (but no server listing to it) | |
3957 | 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) | |
3958 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5) | |
3959 | if ev is None: | |
3960 | raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout") | |
3961 | ||
3962 | sock.close() | |
3963 | ||
3964 | wps_event_url = None | |
3965 | ||
6aaa661a JM |
3966 | def gen_upnp_info(eventSubURL='wps_event', controlURL='wps_control', |
3967 | udn='uuid:27ea801a-9e5c-4e73-bd82-f89cbcd10d7e'): | |
4c3ae1c0 | 3968 | payload = '''<?xml version="1.0"?> |
c965ae03 JM |
3969 | <root xmlns="urn:schemas-upnp-org:device-1-0"> |
3970 | <specVersion> | |
3971 | <major>1</major> | |
3972 | <minor>0</minor> | |
3973 | </specVersion> | |
3974 | <device> | |
3975 | <deviceType>urn:schemas-wifialliance-org:device:WFADevice:1</deviceType> | |
3976 | <friendlyName>WPS Access Point</friendlyName> | |
3977 | <manufacturer>Company</manufacturer> | |
3978 | <modelName>WAP</modelName> | |
3979 | <modelNumber>123</modelNumber> | |
3980 | <serialNumber>12345</serialNumber> | |
6aaa661a JM |
3981 | ''' |
3982 | if udn: | |
3983 | payload += '<UDN>' + udn + '</UDN>' | |
3984 | payload += '''<serviceList> | |
c965ae03 JM |
3985 | <service> |
3986 | <serviceType>urn:schemas-wifialliance-org:service:WFAWLANConfig:1</serviceType> | |
3987 | <serviceId>urn:wifialliance-org:serviceId:WFAWLANConfig1</serviceId> | |
3988 | <SCPDURL>wps_scpd.xml</SCPDURL> | |
4c3ae1c0 | 3989 | ''' |
6aaa661a JM |
3990 | if controlURL: |
3991 | payload += '<controlURL>' + controlURL + '</controlURL>\n' | |
4c3ae1c0 | 3992 | if eventSubURL: |
6aaa661a | 3993 | payload += '<eventSubURL>' + eventSubURL + '</eventSubURL>\n' |
4c3ae1c0 | 3994 | payload += '''</service> |
c965ae03 JM |
3995 | </serviceList> |
3996 | </device> | |
3997 | </root> | |
3998 | ''' | |
4c3ae1c0 JM |
3999 | hdr = 'HTTP/1.1 200 OK\r\n' + \ |
4000 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4001 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4002 | 'Connection: close\r\n' + \ | |
4003 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4004 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4005 | return hdr + payload | |
4006 | ||
6aaa661a | 4007 | def gen_wps_control(payload_override=None): |
4c3ae1c0 | 4008 | payload = '''<?xml version="1.0"?> |
c965ae03 JM |
4009 | <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
4010 | <s:Body> | |
4011 | <u:GetDeviceInfoResponse xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1"> | |
4012 | <NewDeviceInfo>EEoAARAQIgABBBBHABAn6oAanlxOc72C+Jy80Q1+ECAABgIAAAADABAaABCJZ7DPtbU3Ust9 | |
4013 | Z3wJF07WEDIAwH45D3i1OqB7eJGwTzqeapS71h3KyXncK2xJZ+xqScrlorNEg6LijBJzG2Ca | |
4014 | +FZli0iliDJd397yAx/jk4nFXco3q5ylBSvSw9dhJ5u1xBKSnTilKGlUHPhLP75PUqM3fot9 | |
4015 | 7zwtFZ4bx6x1sBA6oEe2d0aUJmLumQGCiKEIWlnxs44zego/2tAe81bDzdPBM7o5HH/FUhD+ | |
4016 | KoGzFXp51atP+1n9Vta6AkI0Vye99JKLcC6Md9dMJltSVBgd4Xc4lRAEAAIAIxAQAAIADRAN | |
4017 | AAEBEAgAAgAEEEQAAQIQIQAHQ29tcGFueRAjAANXQVAQJAADMTIzEEIABTEyMzQ1EFQACAAG | |
4018 | AFDyBAABEBEAC1dpcmVsZXNzIEFQEDwAAQEQAgACAAAQEgACAAAQCQACAAAQLQAEgQIDABBJ | |
4019 | AAYANyoAASA= | |
4020 | </NewDeviceInfo> | |
4021 | </u:GetDeviceInfoResponse> | |
4022 | </s:Body> | |
4023 | </s:Envelope> | |
4024 | ''' | |
6aaa661a JM |
4025 | if payload_override: |
4026 | payload = payload_override | |
4c3ae1c0 JM |
4027 | hdr = 'HTTP/1.1 200 OK\r\n' + \ |
4028 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4029 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4030 | 'Connection: close\r\n' + \ | |
4031 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4032 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4033 | return hdr + payload | |
4034 | ||
6aaa661a | 4035 | def gen_wps_event(sid='uuid:7eb3342a-8a5f-47fe-a585-0785bfec6d8a'): |
4c3ae1c0 JM |
4036 | payload = "" |
4037 | hdr = 'HTTP/1.1 200 OK\r\n' + \ | |
4038 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4039 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4040 | 'Connection: close\r\n' + \ | |
6aaa661a JM |
4041 | 'Content-Length: ' + str(len(payload)) + '\r\n' |
4042 | if sid: | |
4043 | hdr += 'SID: ' + sid + '\r\n' | |
4044 | hdr += 'Timeout: Second-1801\r\n' + \ | |
4c3ae1c0 JM |
4045 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' |
4046 | return hdr + payload | |
4047 | ||
4048 | class WPSAPHTTPServer(SocketServer.StreamRequestHandler): | |
4049 | def handle(self): | |
4050 | data = self.rfile.readline().strip() | |
4051 | logger.info("HTTP server received: " + data) | |
4052 | while True: | |
4053 | hdr = self.rfile.readline().strip() | |
4054 | if len(hdr) == 0: | |
4055 | break | |
4056 | logger.info("HTTP header: " + hdr) | |
4057 | if "CALLBACK:" in hdr: | |
4058 | global wps_event_url | |
4059 | wps_event_url = hdr.split(' ')[1].strip('<>') | |
4060 | ||
4061 | if "GET /foo.xml" in data: | |
6aaa661a JM |
4062 | self.handle_upnp_info() |
4063 | elif "POST /wps_control" in data: | |
4064 | self.handle_wps_control() | |
4065 | elif "SUBSCRIBE /wps_event" in data: | |
4066 | self.handle_wps_event() | |
24b7f282 JM |
4067 | else: |
4068 | self.handle_others(data) | |
6aaa661a JM |
4069 | |
4070 | def handle_upnp_info(self): | |
4071 | self.wfile.write(gen_upnp_info()) | |
4c3ae1c0 | 4072 | |
6aaa661a JM |
4073 | def handle_wps_control(self): |
4074 | self.wfile.write(gen_wps_control()) | |
c965ae03 | 4075 | |
6aaa661a JM |
4076 | def handle_wps_event(self): |
4077 | self.wfile.write(gen_wps_event()) | |
c965ae03 | 4078 | |
24b7f282 JM |
4079 | def handle_others(self, data): |
4080 | logger.info("Ignore HTTP request: " + data) | |
4081 | ||
4c3ae1c0 JM |
4082 | class MyTCPServer(SocketServer.TCPServer): |
4083 | def __init__(self, addr, handler): | |
4084 | self.allow_reuse_address = True | |
4085 | SocketServer.TCPServer.__init__(self, addr, handler) | |
c965ae03 | 4086 | |
24b7f282 JM |
4087 | def wps_er_start(dev, http_server, max_age=1, wait_m_search=False, |
4088 | location_url=None): | |
c965ae03 JM |
4089 | socket.setdefaulttimeout(1) |
4090 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
4091 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
4092 | sock.bind(("239.255.255.250", 1900)) | |
4c3ae1c0 | 4093 | dev.request("WPS_ER_START ifname=lo") |
24b7f282 JM |
4094 | for i in range(100): |
4095 | (msg,addr) = sock.recvfrom(1000) | |
4096 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
4097 | if "M-SEARCH" in msg: | |
4098 | break | |
4099 | if not wait_m_search: | |
4100 | raise Exception("Not an M-SEARCH") | |
4101 | if i == 99: | |
4102 | raise Exception("No M-SEARCH seen") | |
c965ae03 JM |
4103 | |
4104 | # Add an AP with a valid URL and server listing to it | |
4c3ae1c0 | 4105 | server = MyTCPServer(("127.0.0.1", 12345), http_server) |
24b7f282 JM |
4106 | if not location_url: |
4107 | location_url = 'http://127.0.0.1:12345/foo.xml' | |
4108 | 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 | 4109 | server.timeout = 1 |
4c3ae1c0 JM |
4110 | return server,sock |
4111 | ||
4112 | def wps_er_stop(dev, sock, server, on_alloc_fail=False): | |
4113 | sock.close() | |
4114 | server.server_close() | |
4115 | ||
4116 | if on_alloc_fail: | |
4117 | done = False | |
4118 | for i in range(50): | |
4119 | res = dev.request("GET_ALLOC_FAIL") | |
4120 | if res.startswith("0:"): | |
4121 | done = True | |
4122 | break | |
4123 | time.sleep(0.1) | |
4124 | if not done: | |
4125 | raise Exception("No allocation failure reported") | |
4126 | else: | |
4127 | ev = dev.wait_event(["WPS-ER-AP-REMOVE"], timeout=5) | |
4128 | if ev is None: | |
4129 | raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout") | |
4130 | dev.request("WPS_ER_STOP") | |
4131 | ||
24b7f282 | 4132 | def run_wps_er_proto_test(dev, handler, no_event_url=False, location_url=None): |
6aaa661a JM |
4133 | try: |
4134 | uuid = '27ea801a-9e5c-4e73-bd82-f89cbcd10d7e' | |
24b7f282 | 4135 | server,sock = wps_er_start(dev, handler, location_url=location_url) |
6aaa661a JM |
4136 | global wps_event_url |
4137 | wps_event_url = None | |
4138 | server.handle_request() | |
4139 | server.handle_request() | |
4140 | server.handle_request() | |
4141 | server.server_close() | |
4142 | if no_event_url: | |
4143 | if wps_event_url: | |
4144 | raise Exception("Received event URL unexpectedly") | |
4145 | return | |
4146 | if wps_event_url is None: | |
4147 | raise Exception("Did not get event URL") | |
4148 | logger.info("Event URL: " + wps_event_url) | |
4149 | finally: | |
24b7f282 | 4150 | dev.request("WPS_ER_STOP") |
6aaa661a | 4151 | |
18478107 | 4152 | def send_wlanevent(url, uuid, data, no_response=False): |
6aaa661a JM |
4153 | conn = httplib.HTTPConnection(url.netloc) |
4154 | payload = '''<?xml version="1.0" encoding="utf-8"?> | |
4155 | <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> | |
4156 | <e:property><STAStatus>1</STAStatus></e:property> | |
4157 | <e:property><APStatus>1</APStatus></e:property> | |
4158 | <e:property><WLANEvent>''' | |
4159 | payload += base64.b64encode(data) | |
4160 | payload += '</WLANEvent></e:property></e:propertyset>' | |
4161 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4162 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4163 | "HOST": url.netloc, | |
4164 | "NT": "upnp:event", | |
4165 | "SID": "uuid:" + uuid, | |
4166 | "SEQ": "0", | |
4167 | "Content-Length": str(len(payload)) } | |
4168 | conn.request("NOTIFY", url.path, payload, headers) | |
18478107 JM |
4169 | if no_response: |
4170 | try: | |
4171 | conn.getresponse() | |
4172 | except Exception, e: | |
4173 | pass | |
4174 | return | |
6aaa661a JM |
4175 | resp = conn.getresponse() |
4176 | if resp.status != 200: | |
4177 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4178 | ||
4c3ae1c0 JM |
4179 | def test_ap_wps_er_http_proto(dev, apdev): |
4180 | """WPS ER HTTP protocol testing""" | |
4181 | try: | |
4182 | _test_ap_wps_er_http_proto(dev, apdev) | |
4183 | finally: | |
4184 | dev[0].request("WPS_ER_STOP") | |
4185 | ||
4186 | def _test_ap_wps_er_http_proto(dev, apdev): | |
4187 | uuid = '27ea801a-9e5c-4e73-bd82-f89cbcd10d7e' | |
6aaa661a | 4188 | server,sock = wps_er_start(dev[0], WPSAPHTTPServer, max_age=15) |
c965ae03 JM |
4189 | global wps_event_url |
4190 | wps_event_url = None | |
4191 | server.handle_request() | |
4192 | server.handle_request() | |
4193 | server.handle_request() | |
4194 | server.server_close() | |
4195 | if wps_event_url is None: | |
4196 | raise Exception("Did not get event URL") | |
4197 | logger.info("Event URL: " + wps_event_url) | |
4198 | ||
4199 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=10) | |
4200 | if ev is None: | |
4201 | raise Exception("No WPS-ER-AP-ADD event") | |
4202 | if uuid not in ev: | |
4203 | raise Exception("UUID mismatch") | |
4204 | ||
4205 | sock.close() | |
4206 | ||
4207 | logger.info("Valid Probe Request notification") | |
4208 | url = urlparse.urlparse(wps_event_url) | |
4209 | conn = httplib.HTTPConnection(url.netloc) | |
4210 | payload = '''<?xml version="1.0" encoding="utf-8"?> | |
4211 | <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> | |
4212 | <e:property><STAStatus>1</STAStatus></e:property> | |
4213 | <e:property><APStatus>1</APStatus></e:property> | |
4214 | <e:property><WLANEvent>ATAyOjAwOjAwOjAwOjAwOjAwEEoAARAQOgABAhAIAAIxSBBHABA2LbR7pTpRkYj7VFi5hrLk | |
4215 | EFQACAAAAAAAAAAAEDwAAQMQAgACAAAQCQACAAAQEgACAAAQIQABIBAjAAEgECQAASAQEQAI | |
4216 | RGV2aWNlIEEQSQAGADcqAAEg | |
4217 | </WLANEvent></e:property> | |
4218 | </e:propertyset> | |
4219 | ''' | |
4220 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4221 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4222 | "HOST": url.netloc, | |
4223 | "NT": "upnp:event", | |
4224 | "SID": "uuid:" + uuid, | |
4225 | "SEQ": "0", | |
4226 | "Content-Length": str(len(payload)) } | |
4227 | conn.request("NOTIFY", url.path, payload, headers) | |
4228 | resp = conn.getresponse() | |
4229 | if resp.status != 200: | |
4230 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4231 | ||
4232 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=5) | |
4233 | if ev is None: | |
4234 | raise Exception("No WPS-ER-ENROLLEE-ADD event") | |
4235 | if "362db47b-a53a-5191-88fb-5458b986b2e4" not in ev: | |
4236 | raise Exception("No Enrollee UUID match") | |
4237 | ||
4238 | logger.info("Incorrect event URL AP id") | |
4239 | conn = httplib.HTTPConnection(url.netloc) | |
4240 | conn.request("NOTIFY", url.path + '123', payload, headers) | |
4241 | resp = conn.getresponse() | |
4242 | if resp.status != 404: | |
4243 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4244 | ||
4245 | logger.info("Missing AP id") | |
4246 | conn = httplib.HTTPConnection(url.netloc) | |
4247 | conn.request("NOTIFY", '/event/' + url.path.split('/')[2], | |
4248 | payload, headers) | |
4249 | time.sleep(0.1) | |
4250 | ||
4251 | logger.info("Incorrect event URL event id") | |
4252 | conn = httplib.HTTPConnection(url.netloc) | |
4253 | conn.request("NOTIFY", '/event/123456789/123', payload, headers) | |
4254 | time.sleep(0.1) | |
4255 | ||
4256 | logger.info("Incorrect event URL prefix") | |
4257 | conn = httplib.HTTPConnection(url.netloc) | |
4258 | conn.request("NOTIFY", '/foobar/123456789/123', payload, headers) | |
4259 | resp = conn.getresponse() | |
4260 | if resp.status != 404: | |
4261 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4262 | ||
4263 | logger.info("Unsupported request") | |
4264 | conn = httplib.HTTPConnection(url.netloc) | |
4265 | conn.request("FOOBAR", '/foobar/123456789/123', payload, headers) | |
4266 | resp = conn.getresponse() | |
4267 | if resp.status != 501: | |
4268 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4269 | ||
4270 | logger.info("Unsupported request and OOM") | |
4271 | with alloc_fail(dev[0], 1, "wps_er_http_req"): | |
4272 | conn = httplib.HTTPConnection(url.netloc) | |
4273 | conn.request("FOOBAR", '/foobar/123456789/123', payload, headers) | |
4274 | time.sleep(0.5) | |
4c3ae1c0 | 4275 | |
6aaa661a JM |
4276 | logger.info("Too short WLANEvent") |
4277 | data = '\x00' | |
4278 | send_wlanevent(url, uuid, data) | |
4279 | ||
4280 | logger.info("Invalid WLANEventMAC") | |
4281 | data = '\x00qwertyuiopasdfghjklzxcvbnm' | |
4282 | send_wlanevent(url, uuid, data) | |
4283 | ||
4284 | logger.info("Unknown WLANEventType") | |
4285 | data = '\xff02:00:00:00:00:00' | |
4286 | send_wlanevent(url, uuid, data) | |
4287 | ||
4288 | logger.info("Probe Request notification without any attributes") | |
4289 | data = '\x0102:00:00:00:00:00' | |
4290 | send_wlanevent(url, uuid, data) | |
4291 | ||
4292 | logger.info("Probe Request notification with invalid attribute") | |
4293 | data = '\x0102:00:00:00:00:00\xff' | |
4294 | send_wlanevent(url, uuid, data) | |
4295 | ||
4296 | logger.info("EAP message without any attributes") | |
4297 | data = '\x0202:00:00:00:00:00' | |
4298 | send_wlanevent(url, uuid, data) | |
4299 | ||
4300 | logger.info("EAP message with invalid attribute") | |
4301 | data = '\x0202:00:00:00:00:00\xff' | |
4302 | send_wlanevent(url, uuid, data) | |
4303 | ||
4304 | logger.info("EAP message from new STA and not M1") | |
4305 | data = '\x0202:ff:ff:ff:ff:ff' + '\x10\x22\x00\x01\x05' | |
4306 | send_wlanevent(url, uuid, data) | |
4307 | ||
4308 | logger.info("EAP message: M1") | |
4309 | data = '\x0202:00:00:00:00:00' | |
4310 | data += '\x10\x22\x00\x01\x04' | |
4311 | data += '\x10\x47\x00\x10' + 16*'\x00' | |
4312 | data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' | |
4313 | data += '\x10\x1a\x00\x10' + 16*'\x00' | |
4314 | data += '\x10\x32\x00\xc0' + 192*'\x00' | |
4315 | data += '\x10\x04\x00\x02\x00\x00' | |
4316 | data += '\x10\x10\x00\x02\x00\x00' | |
4317 | data += '\x10\x0d\x00\x01\x00' | |
4318 | data += '\x10\x08\x00\x02\x00\x00' | |
4319 | data += '\x10\x44\x00\x01\x00' | |
4320 | data += '\x10\x21\x00\x00' | |
4321 | data += '\x10\x23\x00\x00' | |
4322 | data += '\x10\x24\x00\x00' | |
4323 | data += '\x10\x42\x00\x00' | |
4324 | data += '\x10\x54\x00\x08' + 8*'\x00' | |
4325 | data += '\x10\x11\x00\x00' | |
4326 | data += '\x10\x3c\x00\x01\x00' | |
4327 | data += '\x10\x02\x00\x02\x00\x00' | |
4328 | data += '\x10\x12\x00\x02\x00\x00' | |
4329 | data += '\x10\x09\x00\x02\x00\x00' | |
4330 | data += '\x10\x2d\x00\x04\x00\x00\x00\x00' | |
4331 | m1 = data | |
4332 | send_wlanevent(url, uuid, data) | |
4333 | ||
4334 | logger.info("EAP message: WSC_ACK") | |
4335 | data = '\x0202:00:00:00:00:00' + '\x10\x22\x00\x01\x0d' | |
4336 | send_wlanevent(url, uuid, data) | |
4337 | ||
4338 | logger.info("EAP message: M1") | |
4339 | send_wlanevent(url, uuid, m1) | |
4340 | ||
4341 | logger.info("EAP message: WSC_NACK") | |
4342 | data = '\x0202:00:00:00:00:00' + '\x10\x22\x00\x01\x0e' | |
4343 | send_wlanevent(url, uuid, data) | |
4344 | ||
4345 | logger.info("EAP message: M1 - Too long attribute values") | |
4346 | data = '\x0202:00:00:00:00:00' | |
4347 | data += '\x10\x11\x00\x21' + 33*'\x00' | |
4348 | data += '\x10\x45\x00\x21' + 33*'\x00' | |
4349 | data += '\x10\x42\x00\x21' + 33*'\x00' | |
4350 | data += '\x10\x24\x00\x21' + 33*'\x00' | |
4351 | data += '\x10\x23\x00\x21' + 33*'\x00' | |
4352 | data += '\x10\x21\x00\x41' + 65*'\x00' | |
4353 | data += '\x10\x49\x00\x09\x00\x37\x2a\x05\x02\x00\x00\x05\x00' | |
4354 | send_wlanevent(url, uuid, data) | |
4355 | ||
4356 | logger.info("EAP message: M1 missing UUID-E") | |
4357 | data = '\x0202:00:00:00:00:00' | |
4358 | data += '\x10\x22\x00\x01\x04' | |
4359 | send_wlanevent(url, uuid, data) | |
4360 | ||
4361 | logger.info("EAP message: M1 missing MAC Address") | |
4362 | data += '\x10\x47\x00\x10' + 16*'\x00' | |
4363 | send_wlanevent(url, uuid, data) | |
4364 | ||
4365 | logger.info("EAP message: M1 missing Enrollee Nonce") | |
4366 | data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' | |
4367 | send_wlanevent(url, uuid, data) | |
4368 | ||
4369 | logger.info("EAP message: M1 missing Public Key") | |
4370 | data += '\x10\x1a\x00\x10' + 16*'\x00' | |
4371 | send_wlanevent(url, uuid, data) | |
4372 | ||
4373 | logger.info("EAP message: M1 missing Authentication Type flags") | |
4374 | data += '\x10\x32\x00\xc0' + 192*'\x00' | |
4375 | send_wlanevent(url, uuid, data) | |
4376 | ||
4377 | logger.info("EAP message: M1 missing Encryption Type Flags") | |
4378 | data += '\x10\x04\x00\x02\x00\x00' | |
4379 | send_wlanevent(url, uuid, data) | |
4380 | ||
4381 | logger.info("EAP message: M1 missing Connection Type flags") | |
4382 | data += '\x10\x10\x00\x02\x00\x00' | |
4383 | send_wlanevent(url, uuid, data) | |
4384 | ||
4385 | logger.info("EAP message: M1 missing Config Methods") | |
4386 | data += '\x10\x0d\x00\x01\x00' | |
4387 | send_wlanevent(url, uuid, data) | |
4388 | ||
4389 | logger.info("EAP message: M1 missing Wi-Fi Protected Setup State") | |
4390 | data += '\x10\x08\x00\x02\x00\x00' | |
4391 | send_wlanevent(url, uuid, data) | |
4392 | ||
4393 | logger.info("EAP message: M1 missing Manufacturer") | |
4394 | data += '\x10\x44\x00\x01\x00' | |
4395 | send_wlanevent(url, uuid, data) | |
4396 | ||
4397 | logger.info("EAP message: M1 missing Model Name") | |
4398 | data += '\x10\x21\x00\x00' | |
4399 | send_wlanevent(url, uuid, data) | |
4400 | ||
4401 | logger.info("EAP message: M1 missing Model Number") | |
4402 | data += '\x10\x23\x00\x00' | |
4403 | send_wlanevent(url, uuid, data) | |
4404 | ||
4405 | logger.info("EAP message: M1 missing Serial Number") | |
4406 | data += '\x10\x24\x00\x00' | |
4407 | send_wlanevent(url, uuid, data) | |
4408 | ||
4409 | logger.info("EAP message: M1 missing Primary Device Type") | |
4410 | data += '\x10\x42\x00\x00' | |
4411 | send_wlanevent(url, uuid, data) | |
4412 | ||
4413 | logger.info("EAP message: M1 missing Device Name") | |
4414 | data += '\x10\x54\x00\x08' + 8*'\x00' | |
4415 | send_wlanevent(url, uuid, data) | |
4416 | ||
4417 | logger.info("EAP message: M1 missing RF Bands") | |
4418 | data += '\x10\x11\x00\x00' | |
4419 | send_wlanevent(url, uuid, data) | |
4420 | ||
4421 | logger.info("EAP message: M1 missing Association State") | |
4422 | data += '\x10\x3c\x00\x01\x00' | |
4423 | send_wlanevent(url, uuid, data) | |
4424 | ||
4425 | logger.info("EAP message: M1 missing Device Password ID") | |
4426 | data += '\x10\x02\x00\x02\x00\x00' | |
4427 | send_wlanevent(url, uuid, data) | |
4428 | ||
4429 | logger.info("EAP message: M1 missing Configuration Error") | |
4430 | data += '\x10\x12\x00\x02\x00\x00' | |
4431 | send_wlanevent(url, uuid, data) | |
4432 | ||
4433 | logger.info("EAP message: M1 missing OS Version") | |
4434 | data += '\x10\x09\x00\x02\x00\x00' | |
4435 | send_wlanevent(url, uuid, data) | |
4c3ae1c0 | 4436 | |
24b7f282 JM |
4437 | logger.info("Check max concurrent requests") |
4438 | addr = (url.hostname, url.port) | |
4439 | socks = {} | |
4440 | for i in range(20): | |
4441 | socks[i] = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4442 | socket.IPPROTO_TCP) | |
e5d3e13a JM |
4443 | socks[i].settimeout(10) |
4444 | socks[i].connect(addr) | |
24b7f282 JM |
4445 | for i in range(20): |
4446 | socks[i].send("GET / HTTP/1.1\r\n\r\n") | |
4447 | count = 0 | |
4448 | for i in range(20): | |
4449 | try: | |
4450 | res = socks[i].recv(100) | |
4451 | if "HTTP/1" in res: | |
4452 | count += 1 | |
4453 | except: | |
4454 | pass | |
4455 | socks[i].close() | |
4456 | logger.info("%d concurrent HTTP GET operations returned response" % count) | |
4457 | if count < 10: | |
4458 | raise Exception("Too few concurrent HTTP connections accepted") | |
4459 | ||
4460 | logger.info("OOM in HTTP server") | |
4461 | for func in [ "http_request_init", "httpread_create", | |
4462 | "eloop_register_timeout;httpread_create", | |
9b35afd6 | 4463 | "eloop_sock_table_add_sock;?eloop_register_sock;httpread_create", |
24b7f282 JM |
4464 | "httpread_hdr_analyze" ]: |
4465 | with alloc_fail(dev[0], 1, func): | |
4466 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4467 | socket.IPPROTO_TCP) | |
4468 | sock.connect(addr) | |
4469 | sock.send("GET / HTTP/1.1\r\n\r\n") | |
4470 | try: | |
4471 | sock.recv(100) | |
4472 | except: | |
4473 | pass | |
4474 | sock.close() | |
4475 | ||
4476 | logger.info("Invalid HTTP header") | |
4477 | for req in [ " GET / HTTP/1.1\r\n\r\n", | |
4478 | "HTTP/1.1 200 OK\r\n\r\n", | |
4479 | "HTTP/\r\n\r\n", | |
4480 | "GET %%a%aa% HTTP/1.1\r\n\r\n", | |
4481 | "GET / HTTP/1.1\r\n FOO\r\n\r\n", | |
4482 | "NOTIFY / HTTP/1.1\r\n" + 4097*'a' + '\r\n\r\n', | |
4483 | "NOTIFY / HTTP/1.1\r\n\r\n" + 8193*'a', | |
4484 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n foo\r\n", | |
4485 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n1\r\nfoo\r\n", | |
4486 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n0\r\n", | |
4487 | "POST / HTTP/1.1\r\nTransfer-Encoding: CHUNKED\r\n\r\n0\r\naa\ra\r\n\ra" ]: | |
4488 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4489 | socket.IPPROTO_TCP) | |
4490 | sock.settimeout(0.1) | |
4491 | sock.connect(addr) | |
4492 | sock.send(req) | |
4493 | try: | |
4494 | sock.recv(100) | |
4495 | except: | |
4496 | pass | |
4497 | sock.close() | |
4498 | ||
4499 | with alloc_fail(dev[0], 2, "httpread_read_handler"): | |
4500 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4501 | socket.IPPROTO_TCP) | |
4502 | sock.connect(addr) | |
4503 | sock.send("NOTIFY / HTTP/1.1\r\n\r\n" + 4500*'a') | |
4504 | try: | |
4505 | sock.recv(100) | |
4506 | except: | |
4507 | pass | |
4508 | sock.close() | |
4509 | ||
4510 | conn = httplib.HTTPConnection(url.netloc) | |
4511 | payload = '<foo' | |
4512 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4513 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4514 | "HOST": url.netloc, | |
4515 | "NT": "upnp:event", | |
4516 | "SID": "uuid:" + uuid, | |
4517 | "SEQ": "0", | |
4518 | "Content-Length": str(len(payload)) } | |
4519 | conn.request("NOTIFY", url.path, payload, headers) | |
4520 | resp = conn.getresponse() | |
4521 | if resp.status != 200: | |
4522 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4523 | ||
4524 | conn = httplib.HTTPConnection(url.netloc) | |
4525 | payload = '<WLANEvent foo></WLANEvent>' | |
4526 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
4527 | "Server": "Unspecified, UPnP/1.0, Unspecified", | |
4528 | "HOST": url.netloc, | |
4529 | "NT": "upnp:event", | |
4530 | "SID": "uuid:" + uuid, | |
4531 | "SEQ": "0", | |
4532 | "Content-Length": str(len(payload)) } | |
4533 | conn.request("NOTIFY", url.path, payload, headers) | |
4534 | resp = conn.getresponse() | |
4535 | if resp.status != 200: | |
4536 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
4537 | ||
4538 | with alloc_fail(dev[0], 1, "xml_get_first_item"): | |
4539 | send_wlanevent(url, uuid, '') | |
4540 | ||
4541 | with alloc_fail(dev[0], 1, "wpabuf_alloc_ext_data;xml_get_base64_item"): | |
4542 | send_wlanevent(url, uuid, 'foo') | |
4543 | ||
4544 | for func in [ "wps_init", | |
4545 | "wps_process_manufacturer", | |
4546 | "wps_process_model_name", | |
4547 | "wps_process_model_number", | |
4548 | "wps_process_serial_number", | |
4549 | "wps_process_dev_name" ]: | |
4550 | with alloc_fail(dev[0], 1, func): | |
4551 | send_wlanevent(url, uuid, m1) | |
4552 | ||
18478107 JM |
4553 | with alloc_fail(dev[0], 1, "wps_er_http_resp_ok"): |
4554 | send_wlanevent(url, uuid, m1, no_response=True) | |
4555 | ||
4556 | with alloc_fail(dev[0], 1, "wps_er_http_resp_not_found"): | |
4557 | url2 = urlparse.urlparse(wps_event_url.replace('/event/', '/notfound/')) | |
4558 | send_wlanevent(url2, uuid, m1, no_response=True) | |
4559 | ||
3d105cdf JM |
4560 | logger.info("EAP message: M1") |
4561 | data = '\x0202:11:22:00:00:00' | |
4562 | data += '\x10\x22\x00\x01\x04' | |
4563 | data += '\x10\x47\x00\x10' + 16*'\x00' | |
4564 | data += '\x10\x20\x00\x06\x02\x00\x00\x00\x00\x00' | |
4565 | data += '\x10\x1a\x00\x10' + 16*'\x00' | |
4566 | data += '\x10\x32\x00\xc0' + 192*'\x00' | |
4567 | data += '\x10\x04\x00\x02\x00\x00' | |
4568 | data += '\x10\x10\x00\x02\x00\x00' | |
4569 | data += '\x10\x0d\x00\x01\x00' | |
4570 | data += '\x10\x08\x00\x02\x00\x00' | |
4571 | data += '\x10\x44\x00\x01\x00' | |
4572 | data += '\x10\x21\x00\x00' | |
4573 | data += '\x10\x23\x00\x00' | |
4574 | data += '\x10\x24\x00\x00' | |
4575 | data += '\x10\x42\x00\x00' | |
4576 | data += '\x10\x54\x00\x08' + 8*'\x00' | |
4577 | data += '\x10\x11\x00\x00' | |
4578 | data += '\x10\x3c\x00\x01\x00' | |
4579 | data += '\x10\x02\x00\x02\x00\x00' | |
4580 | data += '\x10\x12\x00\x02\x00\x00' | |
4581 | data += '\x10\x09\x00\x02\x00\x00' | |
4582 | data += '\x10\x2d\x00\x04\x00\x00\x00\x00' | |
4583 | dev[0].dump_monitor() | |
4584 | with alloc_fail(dev[0], 1, "wps_er_add_sta_data"): | |
4585 | send_wlanevent(url, uuid, data) | |
4586 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=0.1) | |
4587 | if ev is not None: | |
4588 | raise Exception("Unexpected enrollee add event") | |
4589 | send_wlanevent(url, uuid, data) | |
4590 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=2) | |
4591 | if ev is None: | |
4592 | raise Exception("Enrollee add event not seen") | |
4593 | ||
fe67b945 JM |
4594 | with alloc_fail(dev[0], 1, "base64_encode;wps_er_soap_hdr"): |
4595 | send_wlanevent(url, uuid, data) | |
4596 | ||
4597 | with alloc_fail(dev[0], 1, "wpabuf_alloc;wps_er_soap_hdr"): | |
4598 | send_wlanevent(url, uuid, data) | |
4599 | ||
4600 | with alloc_fail(dev[0], 1, "http_client_url_parse;wps_er_sta_send_msg"): | |
4601 | send_wlanevent(url, uuid, data) | |
4602 | ||
4603 | with alloc_fail(dev[0], 1, "http_client_addr;wps_er_sta_send_msg"): | |
4604 | send_wlanevent(url, uuid, data) | |
4605 | ||
4c3ae1c0 JM |
4606 | def test_ap_wps_er_http_proto_no_event_sub_url(dev, apdev): |
4607 | """WPS ER HTTP protocol testing - no eventSubURL""" | |
6aaa661a JM |
4608 | class WPSAPHTTPServer_no_event_sub_url(WPSAPHTTPServer): |
4609 | def handle_upnp_info(self): | |
4610 | self.wfile.write(gen_upnp_info(eventSubURL=None)) | |
4611 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_event_sub_url, | |
4612 | no_event_url=True) | |
4c3ae1c0 JM |
4613 | |
4614 | def test_ap_wps_er_http_proto_event_sub_url_dns(dev, apdev): | |
4615 | """WPS ER HTTP protocol testing - DNS name in eventSubURL""" | |
6aaa661a JM |
4616 | class WPSAPHTTPServer_event_sub_url_dns(WPSAPHTTPServer): |
4617 | def handle_upnp_info(self): | |
4618 | self.wfile.write(gen_upnp_info(eventSubURL='http://example.com/wps_event')) | |
4619 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_event_sub_url_dns, | |
4620 | no_event_url=True) | |
4c3ae1c0 JM |
4621 | |
4622 | def test_ap_wps_er_http_proto_subscribe_oom(dev, apdev): | |
4623 | """WPS ER HTTP protocol testing - subscribe OOM""" | |
4624 | try: | |
4625 | _test_ap_wps_er_http_proto_subscribe_oom(dev, apdev) | |
4626 | finally: | |
4627 | dev[0].request("WPS_ER_STOP") | |
4628 | ||
4629 | def _test_ap_wps_er_http_proto_subscribe_oom(dev, apdev): | |
4630 | tests = [ (1, "http_client_url_parse"), | |
4631 | (1, "wpabuf_alloc;wps_er_subscribe"), | |
4632 | (1, "http_client_addr"), | |
9b35afd6 | 4633 | (1, "eloop_sock_table_add_sock;?eloop_register_sock;http_client_addr"), |
4c3ae1c0 JM |
4634 | (1, "eloop_register_timeout;http_client_addr") ] |
4635 | for count,func in tests: | |
4636 | with alloc_fail(dev[0], count, func): | |
4637 | server,sock = wps_er_start(dev[0], WPSAPHTTPServer) | |
4638 | server.handle_request() | |
4639 | server.handle_request() | |
4640 | wps_er_stop(dev[0], sock, server, on_alloc_fail=True) | |
6aaa661a JM |
4641 | |
4642 | def test_ap_wps_er_http_proto_no_sid(dev, apdev): | |
4643 | """WPS ER HTTP protocol testing - no SID""" | |
4644 | class WPSAPHTTPServer_no_sid(WPSAPHTTPServer): | |
4645 | def handle_wps_event(self): | |
4646 | self.wfile.write(gen_wps_event(sid=None)) | |
4647 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_sid) | |
4648 | ||
4649 | def test_ap_wps_er_http_proto_invalid_sid_no_uuid(dev, apdev): | |
4650 | """WPS ER HTTP protocol testing - invalid SID - no UUID""" | |
4651 | class WPSAPHTTPServer_invalid_sid_no_uuid(WPSAPHTTPServer): | |
4652 | def handle_wps_event(self): | |
4653 | self.wfile.write(gen_wps_event(sid='FOO')) | |
4654 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_sid_no_uuid) | |
4655 | ||
4656 | def test_ap_wps_er_http_proto_invalid_sid_uuid(dev, apdev): | |
4657 | """WPS ER HTTP protocol testing - invalid SID UUID""" | |
4658 | class WPSAPHTTPServer_invalid_sid_uuid(WPSAPHTTPServer): | |
4659 | def handle_wps_event(self): | |
4660 | self.wfile.write(gen_wps_event(sid='uuid:FOO')) | |
4661 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_sid_uuid) | |
4662 | ||
4663 | def test_ap_wps_er_http_proto_subscribe_failing(dev, apdev): | |
4664 | """WPS ER HTTP protocol testing - SUBSCRIBE failing""" | |
4665 | class WPSAPHTTPServer_fail_subscribe(WPSAPHTTPServer): | |
4666 | def handle_wps_event(self): | |
4667 | payload = "" | |
4668 | hdr = 'HTTP/1.1 404 Not Found\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_fail_subscribe) | |
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_subscribe_invalid_response(WPSAPHTTPServer): | |
4681 | def handle_wps_event(self): | |
4682 | payload = "" | |
4683 | hdr = 'HTTP/1.1 FOO\r\n' + \ | |
4684 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4685 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4686 | 'Connection: close\r\n' + \ | |
4687 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4688 | 'Timeout: Second-1801\r\n' + \ | |
4689 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4690 | self.wfile.write(hdr + payload) | |
4691 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_subscribe_invalid_response) | |
4692 | ||
4693 | def test_ap_wps_er_http_proto_subscribe_invalid_response(dev, apdev): | |
4694 | """WPS ER HTTP protocol testing - SUBSCRIBE and invalid response""" | |
4695 | class WPSAPHTTPServer_invalid_m1(WPSAPHTTPServer): | |
4696 | def handle_wps_control(self): | |
4697 | payload = '''<?xml version="1.0"?> | |
4698 | <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> | |
4699 | <s:Body> | |
4700 | <u:GetDeviceInfoResponse xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1"> | |
4701 | <NewDeviceInfo>Rk9P</NewDeviceInfo> | |
4702 | </u:GetDeviceInfoResponse> | |
4703 | </s:Body> | |
4704 | </s:Envelope> | |
4705 | ''' | |
4706 | self.wfile.write(gen_wps_control(payload_override=payload)) | |
4707 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_m1, no_event_url=True) | |
4708 | ||
4709 | def test_ap_wps_er_http_proto_upnp_info_no_device(dev, apdev): | |
4710 | """WPS ER HTTP protocol testing - No device in UPnP info""" | |
4711 | class WPSAPHTTPServer_no_device(WPSAPHTTPServer): | |
4712 | def handle_upnp_info(self): | |
4713 | payload = '''<?xml version="1.0"?> | |
4714 | <root xmlns="urn:schemas-upnp-org:device-1-0"> | |
4715 | <specVersion> | |
4716 | <major>1</major> | |
4717 | <minor>0</minor> | |
4718 | </specVersion> | |
4719 | </root> | |
4720 | ''' | |
4721 | hdr = 'HTTP/1.1 200 OK\r\n' + \ | |
4722 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4723 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4724 | 'Connection: close\r\n' + \ | |
4725 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4726 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4727 | self.wfile.write(hdr + payload) | |
4728 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_device, no_event_url=True) | |
4729 | ||
4730 | def test_ap_wps_er_http_proto_upnp_info_no_device_type(dev, apdev): | |
4731 | """WPS ER HTTP protocol testing - No deviceType in UPnP info""" | |
4732 | class WPSAPHTTPServer_no_device(WPSAPHTTPServer): | |
4733 | def handle_upnp_info(self): | |
4734 | payload = '''<?xml version="1.0"?> | |
4735 | <root xmlns="urn:schemas-upnp-org:device-1-0"> | |
4736 | <specVersion> | |
4737 | <major>1</major> | |
4738 | <minor>0</minor> | |
4739 | </specVersion> | |
4740 | <device> | |
4741 | </device> | |
4742 | </root> | |
4743 | ''' | |
4744 | hdr = 'HTTP/1.1 200 OK\r\n' + \ | |
4745 | 'Content-Type: text/xml; charset="utf-8"\r\n' + \ | |
4746 | 'Server: Unspecified, UPnP/1.0, Unspecified\r\n' + \ | |
4747 | 'Connection: close\r\n' + \ | |
4748 | 'Content-Length: ' + str(len(payload)) + '\r\n' + \ | |
4749 | 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' | |
4750 | self.wfile.write(hdr + payload) | |
4751 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_device, no_event_url=True) | |
4752 | ||
4753 | def test_ap_wps_er_http_proto_upnp_info_invalid_udn_uuid(dev, apdev): | |
4754 | """WPS ER HTTP protocol testing - Invalid UDN UUID""" | |
4755 | class WPSAPHTTPServer_invalid_udn_uuid(WPSAPHTTPServer): | |
4756 | def handle_upnp_info(self): | |
4757 | self.wfile.write(gen_upnp_info(udn='uuid:foo')) | |
4758 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_invalid_udn_uuid) | |
4759 | ||
4760 | def test_ap_wps_er_http_proto_no_control_url(dev, apdev): | |
4761 | """WPS ER HTTP protocol testing - no controlURL""" | |
4762 | class WPSAPHTTPServer_no_control_url(WPSAPHTTPServer): | |
4763 | def handle_upnp_info(self): | |
4764 | self.wfile.write(gen_upnp_info(controlURL=None)) | |
4765 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_no_control_url, | |
4766 | no_event_url=True) | |
4767 | ||
4768 | def test_ap_wps_er_http_proto_control_url_dns(dev, apdev): | |
4769 | """WPS ER HTTP protocol testing - DNS name in controlURL""" | |
4770 | class WPSAPHTTPServer_control_url_dns(WPSAPHTTPServer): | |
4771 | def handle_upnp_info(self): | |
4772 | self.wfile.write(gen_upnp_info(controlURL='http://example.com/wps_control')) | |
4773 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_control_url_dns, | |
4774 | no_event_url=True) | |
24b7f282 JM |
4775 | |
4776 | def test_ap_wps_http_timeout(dev, apdev): | |
4777 | """WPS AP/ER and HTTP timeout""" | |
4778 | try: | |
4779 | _test_ap_wps_http_timeout(dev, apdev) | |
4780 | finally: | |
4781 | dev[0].request("WPS_ER_STOP") | |
4782 | ||
4783 | def _test_ap_wps_http_timeout(dev, apdev): | |
4784 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 4785 | add_ssdp_ap(apdev[0], ap_uuid) |
24b7f282 JM |
4786 | |
4787 | location = ssdp_get_location(ap_uuid) | |
4788 | url = urlparse.urlparse(location) | |
4789 | addr = (url.hostname, url.port) | |
4790 | logger.debug("Open HTTP connection to hostapd, but do not complete request") | |
4791 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, | |
4792 | socket.IPPROTO_TCP) | |
4793 | sock.connect(addr) | |
4794 | sock.send("G") | |
4795 | ||
4796 | class DummyServer(SocketServer.StreamRequestHandler): | |
4797 | def handle(self): | |
4798 | logger.debug("DummyServer - start 31 sec wait") | |
4799 | time.sleep(31) | |
4800 | logger.debug("DummyServer - wait done") | |
4801 | ||
4802 | logger.debug("Start WPS ER") | |
4803 | server,sock2 = wps_er_start(dev[0], DummyServer, max_age=40, | |
4804 | wait_m_search=True) | |
4805 | ||
4806 | logger.debug("Start server to accept, but not complete, HTTP connection from WPS ER") | |
4807 | # This will wait for 31 seconds.. | |
4808 | server.handle_request() | |
4809 | ||
4810 | logger.debug("Complete HTTP connection with hostapd (that should have already closed the connection)") | |
4811 | try: | |
4812 | sock.send("ET / HTTP/1.1\r\n\r\n") | |
4813 | res = sock.recv(100) | |
4814 | sock.close() | |
4815 | except: | |
4816 | pass | |
4817 | ||
4818 | def test_ap_wps_er_url_parse(dev, apdev): | |
4819 | """WPS ER and URL parsing special cases""" | |
4820 | try: | |
4821 | _test_ap_wps_er_url_parse(dev, apdev) | |
4822 | finally: | |
4823 | dev[0].request("WPS_ER_STOP") | |
4824 | ||
4825 | def _test_ap_wps_er_url_parse(dev, apdev): | |
4826 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
4827 | sock.settimeout(1) | |
4828 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
4829 | sock.bind(("239.255.255.250", 1900)) | |
4830 | dev[0].request("WPS_ER_START ifname=lo") | |
4831 | (msg,addr) = sock.recvfrom(1000) | |
4832 | logger.debug("Received SSDP message from %s: %s" % (str(addr), msg)) | |
4833 | if "M-SEARCH" not in msg: | |
4834 | raise Exception("Not an M-SEARCH") | |
4835 | 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) | |
4836 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2) | |
4837 | 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) | |
4838 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2) | |
4839 | 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) | |
4840 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2) | |
4841 | ||
4842 | sock.close() | |
4843 | ||
4844 | def test_ap_wps_er_link_update(dev, apdev): | |
4845 | """WPS ER and link update special cases""" | |
4846 | class WPSAPHTTPServer_link_update(WPSAPHTTPServer): | |
4847 | def handle_upnp_info(self): | |
4848 | self.wfile.write(gen_upnp_info(controlURL='/wps_control')) | |
4849 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_link_update) | |
4850 | ||
4851 | class WPSAPHTTPServer_link_update2(WPSAPHTTPServer): | |
4852 | def handle_others(self, data): | |
4853 | if "GET / " in data: | |
4854 | self.wfile.write(gen_upnp_info(controlURL='/wps_control')) | |
4855 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_link_update2, | |
4856 | location_url='http://127.0.0.1:12345') | |
4857 | ||
4858 | def test_ap_wps_er_http_client(dev, apdev): | |
4859 | """WPS ER and HTTP client special cases""" | |
4860 | with alloc_fail(dev[0], 1, "http_link_update"): | |
4861 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer) | |
4862 | ||
4863 | with alloc_fail(dev[0], 1, "wpabuf_alloc;http_client_url"): | |
4864 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer, no_event_url=True) | |
4865 | ||
4866 | with alloc_fail(dev[0], 1, "httpread_create;http_client_tx_ready"): | |
4867 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer, no_event_url=True) | |
4868 | ||
4869 | class WPSAPHTTPServer_req_as_resp(WPSAPHTTPServer): | |
4870 | def handle_upnp_info(self): | |
4871 | self.wfile.write("GET / HTTP/1.1\r\n\r\n") | |
4872 | run_wps_er_proto_test(dev[0], WPSAPHTTPServer_req_as_resp, | |
4873 | no_event_url=True) | |
4874 | ||
4875 | def test_ap_wps_init_oom(dev, apdev): | |
4876 | """wps_init OOM cases""" | |
4877 | ssid = "test-wps" | |
4878 | appin = "12345670" | |
4879 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
4880 | "ap_pin": appin } | |
8b8a1864 | 4881 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4882 | pin = dev[0].wps_read_pin() |
4883 | ||
4884 | with alloc_fail(hapd, 1, "wps_init"): | |
4885 | hapd.request("WPS_PIN any " + pin) | |
4886 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4887 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4888 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4889 | if ev is None: | |
4890 | raise Exception("No EAP failure reported") | |
4891 | dev[0].request("WPS_CANCEL") | |
4892 | ||
4893 | with alloc_fail(dev[0], 2, "wps_init"): | |
4894 | hapd.request("WPS_PIN any " + pin) | |
4895 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4896 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4897 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4898 | if ev is None: | |
4899 | raise Exception("No EAP failure reported") | |
4900 | dev[0].request("WPS_CANCEL") | |
4901 | ||
4902 | with alloc_fail(dev[0], 2, "wps_init"): | |
4903 | hapd.request("WPS_PBC") | |
4904 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4905 | dev[0].request("WPS_PBC %s" % (apdev[0]['bssid'])) | |
4906 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4907 | if ev is None: | |
4908 | raise Exception("No EAP failure reported") | |
4909 | dev[0].request("WPS_CANCEL") | |
4910 | ||
4911 | dev[0].dump_monitor() | |
4912 | new_ssid = "wps-new-ssid" | |
4913 | new_passphrase = "1234567890" | |
4914 | with alloc_fail(dev[0], 3, "wps_init"): | |
4915 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", | |
4916 | new_passphrase, no_wait=True) | |
4917 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
4918 | if ev is None: | |
4919 | raise Exception("No EAP failure reported") | |
4920 | ||
4921 | dev[0].flush_scan_cache() | |
4922 | ||
9fd6804d | 4923 | @remote_compatible |
24b7f282 JM |
4924 | def test_ap_wps_invalid_assoc_req_elem(dev, apdev): |
4925 | """WPS and invalid IE in Association Request frame""" | |
4926 | ssid = "test-wps" | |
4927 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4928 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4929 | pin = "12345670" |
4930 | hapd.request("WPS_PIN any " + pin) | |
4931 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4932 | try: | |
4933 | dev[0].request("VENDOR_ELEM_ADD 13 dd050050f20410") | |
4934 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4935 | for i in range(5): | |
4936 | ev = hapd.wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10) | |
4937 | if ev and "vendor=14122" in ev: | |
4938 | break | |
4939 | if ev is None or "vendor=14122" not in ev: | |
4940 | raise Exception("EAP-WSC not started") | |
4941 | dev[0].request("WPS_CANCEL") | |
4942 | finally: | |
4943 | dev[0].request("VENDOR_ELEM_REMOVE 13 *") | |
4944 | ||
4945 | def test_ap_wps_pbc_pin_mismatch(dev, apdev): | |
4946 | """WPS PBC/PIN mismatch""" | |
4947 | ssid = "test-wps" | |
4948 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4949 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
4950 | hapd.request("SET wps_version_number 0x10") |
4951 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
4952 | hapd.request("WPS_PBC") | |
4953 | pin = dev[0].wps_read_pin() | |
4954 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4955 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
4956 | if ev is None: | |
4957 | raise Exception("Scan did not complete") | |
4958 | dev[0].request("WPS_CANCEL") | |
4959 | ||
4960 | hapd.request("WPS_CANCEL") | |
4961 | dev[0].flush_scan_cache() | |
4962 | ||
9fd6804d | 4963 | @remote_compatible |
24b7f282 JM |
4964 | def test_ap_wps_ie_invalid(dev, apdev): |
4965 | """WPS PIN attempt with AP that has invalid WSC IE""" | |
4966 | ssid = "test-wps" | |
4967 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
4968 | "vendor_elements": "dd050050f20410" } | |
8b8a1864 | 4969 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 | 4970 | params = { 'ssid': "another", "vendor_elements": "dd050050f20410" } |
8b8a1864 | 4971 | hostapd.add_ap(apdev[1], params) |
24b7f282 JM |
4972 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
4973 | pin = dev[0].wps_read_pin() | |
4974 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4975 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
4976 | if ev is None: | |
4977 | raise Exception("Scan did not complete") | |
4978 | dev[0].request("WPS_CANCEL") | |
4979 | ||
9fd6804d | 4980 | @remote_compatible |
24b7f282 JM |
4981 | def test_ap_wps_scan_prio_order(dev, apdev): |
4982 | """WPS scan priority ordering""" | |
4983 | ssid = "test-wps" | |
4984 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 4985 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 | 4986 | params = { 'ssid': "another", "vendor_elements": "dd050050f20410" } |
8b8a1864 | 4987 | hostapd.add_ap(apdev[1], params) |
24b7f282 JM |
4988 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
4989 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
4990 | pin = dev[0].wps_read_pin() | |
4991 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
4992 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
4993 | if ev is None: | |
4994 | raise Exception("Scan did not complete") | |
4995 | dev[0].request("WPS_CANCEL") | |
4996 | ||
4997 | def test_ap_wps_probe_req_ie_oom(dev, apdev): | |
4998 | """WPS ProbeReq IE OOM""" | |
4999 | ssid = "test-wps" | |
5000 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 5001 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5002 | pin = dev[0].wps_read_pin() |
5003 | hapd.request("WPS_PIN any " + pin) | |
5004 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5005 | with alloc_fail(dev[0], 1, "wps_build_probe_req_ie"): | |
5006 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5007 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
5008 | if ev is None: | |
5009 | raise Exception("Association not seen") | |
5010 | dev[0].request("WPS_CANCEL") | |
161c8515 | 5011 | dev[0].wait_disconnected() |
24b7f282 JM |
5012 | |
5013 | with alloc_fail(dev[0], 1, "wps_ie_encapsulate"): | |
5014 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5015 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
5016 | if ev is None: | |
5017 | raise Exception("Association not seen") | |
5018 | dev[0].request("WPS_CANCEL") | |
161c8515 JM |
5019 | hapd.disable() |
5020 | dev[0].request("REMOVE_NETWORK all") | |
5021 | dev[0].wait_disconnected() | |
5022 | time.sleep(0.2) | |
5023 | dev[0].flush_scan_cache() | |
24b7f282 JM |
5024 | |
5025 | def test_ap_wps_assoc_req_ie_oom(dev, apdev): | |
5026 | """WPS AssocReq 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(dev[0], 1, "wps_build_assoc_req_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 | ||
5040 | def test_ap_wps_assoc_resp_ie_oom(dev, apdev): | |
5041 | """WPS AssocResp IE OOM""" | |
5042 | ssid = "test-wps" | |
5043 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2" } | |
8b8a1864 | 5044 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5045 | pin = dev[0].wps_read_pin() |
5046 | hapd.request("WPS_PIN any " + pin) | |
5047 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5048 | with alloc_fail(hapd, 1, "wps_build_assoc_resp_ie"): | |
5049 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5050 | ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=10) | |
5051 | if ev is None: | |
5052 | raise Exception("Association not seen") | |
5053 | dev[0].request("WPS_CANCEL") | |
5054 | ||
9fd6804d | 5055 | @remote_compatible |
24b7f282 JM |
5056 | def test_ap_wps_bss_info_errors(dev, apdev): |
5057 | """WPS BSS info errors""" | |
5058 | params = { "ssid": "1", | |
5059 | "vendor_elements": "dd0e0050f20410440001ff101100010a" } | |
8b8a1864 | 5060 | hostapd.add_ap(apdev[0], params) |
24b7f282 | 5061 | params = { 'ssid': "2", "vendor_elements": "dd050050f20410" } |
8b8a1864 | 5062 | hostapd.add_ap(apdev[1], params) |
24b7f282 JM |
5063 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
5064 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
5065 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
5066 | logger.info("BSS: " + str(bss)) | |
5067 | if "wps_state" in bss: | |
5068 | raise Exception("Unexpected wps_state in BSS info") | |
5069 | if 'wps_device_name' not in bss: | |
5070 | raise Exception("No wps_device_name in BSS info") | |
5071 | if bss['wps_device_name'] != '_': | |
5072 | raise Exception("Unexpected wps_device_name value") | |
5073 | bss = dev[0].get_bss(apdev[1]['bssid']) | |
5074 | logger.info("BSS: " + str(bss)) | |
5075 | ||
5076 | with alloc_fail(dev[0], 1, "=wps_attr_text"): | |
5077 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
5078 | logger.info("BSS(OOM): " + str(bss)) | |
5079 | ||
5080 | def wps_run_pbc_fail_ap(apdev, dev, hapd): | |
5081 | hapd.request("WPS_PBC") | |
5082 | dev.scan_for_bss(apdev['bssid'], freq="2412") | |
5083 | dev.request("WPS_PBC " + apdev['bssid']) | |
5084 | ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5085 | if ev is None: | |
5086 | raise Exception("No EAP failure reported") | |
5087 | dev.request("WPS_CANCEL") | |
5088 | dev.wait_disconnected() | |
5089 | for i in range(5): | |
5090 | try: | |
5091 | dev.flush_scan_cache() | |
5092 | break | |
5093 | except Exception, e: | |
5094 | if str(e).startswith("Failed to trigger scan"): | |
5095 | # Try again | |
5096 | time.sleep(1) | |
5097 | else: | |
5098 | raise | |
5099 | ||
5100 | def wps_run_pbc_fail(apdev, dev): | |
5101 | hapd = wps_start_ap(apdev) | |
5102 | wps_run_pbc_fail_ap(apdev, dev, hapd) | |
5103 | ||
9fd6804d | 5104 | @remote_compatible |
24b7f282 JM |
5105 | def test_ap_wps_pk_oom(dev, apdev): |
5106 | """WPS and public key OOM""" | |
5107 | with alloc_fail(dev[0], 1, "wps_build_public_key"): | |
5108 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5109 | ||
9fd6804d | 5110 | @remote_compatible |
24b7f282 JM |
5111 | def test_ap_wps_pk_oom_ap(dev, apdev): |
5112 | """WPS and public key OOM on AP""" | |
5113 | hapd = wps_start_ap(apdev[0]) | |
5114 | with alloc_fail(hapd, 1, "wps_build_public_key"): | |
5115 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5116 | ||
9fd6804d | 5117 | @remote_compatible |
24b7f282 JM |
5118 | def test_ap_wps_encr_oom_ap(dev, apdev): |
5119 | """WPS and encrypted settings decryption OOM on AP""" | |
5120 | hapd = wps_start_ap(apdev[0]) | |
5121 | pin = dev[0].wps_read_pin() | |
5122 | hapd.request("WPS_PIN any " + pin) | |
5123 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5124 | with alloc_fail(hapd, 1, "wps_decrypt_encr_settings"): | |
5125 | dev[0].request("WPS_PIN " + apdev[0]['bssid'] + " " + pin) | |
5126 | ev = hapd.wait_event(["WPS-FAIL"], timeout=10) | |
5127 | if ev is None: | |
5128 | raise Exception("No WPS-FAIL reported") | |
5129 | dev[0].request("WPS_CANCEL") | |
5130 | dev[0].wait_disconnected() | |
5131 | ||
9fd6804d | 5132 | @remote_compatible |
24b7f282 JM |
5133 | def test_ap_wps_encr_no_random_ap(dev, apdev): |
5134 | """WPS and no random data available for encryption on AP""" | |
5135 | hapd = wps_start_ap(apdev[0]) | |
5136 | with fail_test(hapd, 1, "os_get_random;wps_build_encr_settings"): | |
5137 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5138 | ||
9fd6804d | 5139 | @remote_compatible |
24b7f282 JM |
5140 | def test_ap_wps_e_hash_no_random_sta(dev, apdev): |
5141 | """WPS and no random data available for e-hash on STA""" | |
5142 | with fail_test(dev[0], 1, "os_get_random;wps_build_e_hash"): | |
5143 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5144 | ||
9fd6804d | 5145 | @remote_compatible |
24b7f282 JM |
5146 | def test_ap_wps_m1_no_random(dev, apdev): |
5147 | """WPS and no random for M1 on STA""" | |
5148 | with fail_test(dev[0], 1, "os_get_random;wps_build_m1"): | |
5149 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5150 | ||
9fd6804d | 5151 | @remote_compatible |
24b7f282 JM |
5152 | def test_ap_wps_m1_oom(dev, apdev): |
5153 | """WPS and OOM for M1 on STA""" | |
5154 | with alloc_fail(dev[0], 1, "wps_build_m1"): | |
5155 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5156 | ||
9fd6804d | 5157 | @remote_compatible |
24b7f282 JM |
5158 | def test_ap_wps_m3_oom(dev, apdev): |
5159 | """WPS and OOM for M3 on STA""" | |
5160 | with alloc_fail(dev[0], 1, "wps_build_m3"): | |
5161 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5162 | ||
9fd6804d | 5163 | @remote_compatible |
24b7f282 JM |
5164 | def test_ap_wps_m5_oom(dev, apdev): |
5165 | """WPS and OOM for M5 on STA""" | |
5166 | hapd = wps_start_ap(apdev[0]) | |
5167 | hapd.request("WPS_PBC") | |
5168 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5169 | for i in range(1, 3): | |
5170 | with alloc_fail(dev[0], i, "wps_build_m5"): | |
5171 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5172 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5173 | if ev is None: | |
5174 | raise Exception("No EAP failure reported") | |
5175 | dev[0].request("WPS_CANCEL") | |
5176 | dev[0].wait_disconnected() | |
5177 | dev[0].flush_scan_cache() | |
5178 | ||
9fd6804d | 5179 | @remote_compatible |
24b7f282 JM |
5180 | def test_ap_wps_m5_no_random(dev, apdev): |
5181 | """WPS and no random for M5 on STA""" | |
5182 | with fail_test(dev[0], 1, | |
5183 | "os_get_random;wps_build_encr_settings;wps_build_m5"): | |
5184 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5185 | ||
9fd6804d | 5186 | @remote_compatible |
24b7f282 JM |
5187 | def test_ap_wps_m7_oom(dev, apdev): |
5188 | """WPS and OOM for M7 on STA""" | |
5189 | hapd = wps_start_ap(apdev[0]) | |
5190 | hapd.request("WPS_PBC") | |
5191 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5192 | for i in range(1, 3): | |
5193 | with alloc_fail(dev[0], i, "wps_build_m7"): | |
5194 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5195 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5196 | if ev is None: | |
5197 | raise Exception("No EAP failure reported") | |
5198 | dev[0].request("WPS_CANCEL") | |
5199 | dev[0].wait_disconnected() | |
5200 | dev[0].flush_scan_cache() | |
5201 | ||
9fd6804d | 5202 | @remote_compatible |
24b7f282 JM |
5203 | def test_ap_wps_m7_no_random(dev, apdev): |
5204 | """WPS and no random for M7 on STA""" | |
5205 | with fail_test(dev[0], 1, | |
5206 | "os_get_random;wps_build_encr_settings;wps_build_m7"): | |
5207 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5208 | ||
9fd6804d | 5209 | @remote_compatible |
24b7f282 JM |
5210 | def test_ap_wps_wsc_done_oom(dev, apdev): |
5211 | """WPS and OOM for WSC_Done on STA""" | |
5212 | with alloc_fail(dev[0], 1, "wps_build_wsc_done"): | |
5213 | wps_run_pbc_fail(apdev[0], dev[0]) | |
5214 | ||
5215 | def test_ap_wps_random_psk_fail(dev, apdev): | |
5216 | """WPS and no random for PSK on AP""" | |
5217 | ssid = "test-wps" | |
5218 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
5219 | appin = "12345670" | |
5220 | try: | |
5221 | os.remove(pskfile) | |
5222 | except: | |
5223 | pass | |
5224 | ||
5225 | try: | |
5226 | with open(pskfile, "w") as f: | |
5227 | f.write("# WPA PSKs\n") | |
5228 | ||
5229 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
5230 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
5231 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
5232 | "wpa_psk_file": pskfile } | |
8b8a1864 | 5233 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5234 | |
5235 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
5236 | with fail_test(hapd, 1, "os_get_random;wps_build_cred_network_key"): | |
5237 | dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin) | |
5238 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10) | |
5239 | if ev is None: | |
5240 | raise Exception("No EAP failure reported") | |
5241 | dev[0].request("WPS_CANCEL") | |
5242 | dev[0].wait_disconnected() | |
5243 | ||
5244 | with fail_test(hapd, 1, "os_get_random;wps_build_cred"): | |
5245 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5246 | ||
5247 | with alloc_fail(hapd, 1, "wps_build_cred"): | |
5248 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5249 | ||
5250 | with alloc_fail(hapd, 2, "wps_build_cred"): | |
5251 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
5252 | finally: | |
5253 | os.remove(pskfile) | |
5254 | ||
5255 | def wps_ext_eap_identity_req(dev, hapd, bssid): | |
5256 | logger.debug("EAP-Identity/Request") | |
5257 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5258 | if ev is None: | |
5259 | raise Exception("Timeout on EAPOL-TX from hostapd") | |
5260 | res = dev.request("EAPOL_RX " + bssid + " " + ev.split(' ')[2]) | |
5261 | if "OK" not in res: | |
5262 | raise Exception("EAPOL_RX to wpa_supplicant failed") | |
5263 | ||
5264 | def wps_ext_eap_identity_resp(hapd, dev, addr): | |
5265 | ev = dev.wait_event(["EAPOL-TX"], timeout=10) | |
5266 | if ev is None: | |
5267 | raise Exception("Timeout on EAPOL-TX from wpa_supplicant") | |
5268 | res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2]) | |
5269 | if "OK" not in res: | |
5270 | raise Exception("EAPOL_RX to hostapd failed") | |
5271 | ||
5272 | def wps_ext_eap_wsc(dst, src, src_addr, msg): | |
5273 | logger.debug(msg) | |
5274 | ev = src.wait_event(["EAPOL-TX"], timeout=10) | |
5275 | if ev is None: | |
5276 | raise Exception("Timeout on EAPOL-TX") | |
5277 | res = dst.request("EAPOL_RX " + src_addr + " " + ev.split(' ')[2]) | |
5278 | if "OK" not in res: | |
5279 | raise Exception("EAPOL_RX failed") | |
5280 | ||
7511ead0 | 5281 | def wps_start_ext(apdev, dev, pbc=False, pin=None): |
24b7f282 JM |
5282 | addr = dev.own_addr() |
5283 | bssid = apdev['bssid'] | |
5284 | ssid = "test-wps-conf" | |
5285 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
5286 | "wpa_passphrase": "12345678", "wpa": "2", | |
5287 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"} | |
afc26df2 | 5288 | hapd = hostapd.add_ap(apdev, params) |
24b7f282 | 5289 | |
d1883671 JM |
5290 | if pbc: |
5291 | hapd.request("WPS_PBC") | |
5292 | else: | |
7511ead0 JM |
5293 | if pin is None: |
5294 | pin = dev.wps_read_pin() | |
d1883671 | 5295 | hapd.request("WPS_PIN any " + pin) |
24b7f282 JM |
5296 | dev.scan_for_bss(bssid, freq="2412") |
5297 | hapd.request("SET ext_eapol_frame_io 1") | |
5298 | dev.request("SET ext_eapol_frame_io 1") | |
5299 | ||
d1883671 JM |
5300 | if pbc: |
5301 | dev.request("WPS_PBC " + bssid) | |
5302 | else: | |
5303 | dev.request("WPS_PIN " + bssid + " " + pin) | |
24b7f282 JM |
5304 | return addr,bssid,hapd |
5305 | ||
5306 | def wps_auth_corrupt(dst, src, addr): | |
5307 | ev = src.wait_event(["EAPOL-TX"], timeout=10) | |
5308 | if ev is None: | |
5309 | raise Exception("Timeout on EAPOL-TX") | |
5310 | src.request("SET ext_eapol_frame_io 0") | |
5311 | dst.request("SET ext_eapol_frame_io 0") | |
5312 | msg = ev.split(' ')[2] | |
5313 | if msg[-24:-16] != '10050008': | |
5314 | raise Exception("Could not find Authenticator attribute") | |
5315 | # Corrupt Authenticator value | |
5316 | msg = msg[:-1] + '%x' % ((int(msg[-1], 16) + 1) % 16) | |
5317 | res = dst.request("EAPOL_RX " + addr + " " + msg) | |
5318 | if "OK" not in res: | |
5319 | raise Exception("EAPOL_RX failed") | |
5320 | ||
5321 | def wps_fail_finish(hapd, dev, fail_str): | |
5322 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
5323 | if ev is None: | |
5324 | raise Exception("WPS-FAIL not indicated") | |
5325 | if fail_str not in ev: | |
5326 | raise Exception("Unexpected WPS-FAIL value: " + ev) | |
5327 | dev.request("WPS_CANCEL") | |
5328 | dev.wait_disconnected() | |
5329 | ||
5330 | def wps_auth_corrupt_from_ap(dev, hapd, bssid, fail_str): | |
5331 | wps_auth_corrupt(dev, hapd, bssid) | |
5332 | wps_fail_finish(hapd, dev, fail_str) | |
5333 | ||
5334 | def wps_auth_corrupt_to_ap(dev, hapd, addr, fail_str): | |
5335 | wps_auth_corrupt(hapd, dev, addr) | |
5336 | wps_fail_finish(hapd, dev, fail_str) | |
5337 | ||
5338 | def test_ap_wps_authenticator_mismatch_m2(dev, apdev): | |
5339 | """WPS and Authenticator attribute mismatch in M2""" | |
5340 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5341 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5342 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5343 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5344 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5345 | logger.debug("M2") | |
5346 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=5") | |
5347 | ||
5348 | def test_ap_wps_authenticator_mismatch_m3(dev, apdev): | |
5349 | """WPS and Authenticator attribute mismatch in M3""" | |
5350 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5351 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5352 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5353 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5354 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5355 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5356 | logger.debug("M3") | |
5357 | wps_auth_corrupt_to_ap(dev[0], hapd, addr, "msg=7") | |
5358 | ||
5359 | def test_ap_wps_authenticator_mismatch_m4(dev, apdev): | |
5360 | """WPS and Authenticator attribute mismatch in M4""" | |
5361 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5362 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5363 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5364 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5365 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5366 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5367 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5368 | logger.debug("M4") | |
5369 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=8") | |
5370 | ||
5371 | def test_ap_wps_authenticator_mismatch_m5(dev, apdev): | |
5372 | """WPS and Authenticator attribute mismatch in M5""" | |
5373 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5374 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5375 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5376 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5377 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5378 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5379 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5380 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5381 | logger.debug("M5") | |
5382 | wps_auth_corrupt_to_ap(dev[0], hapd, addr, "msg=9") | |
5383 | ||
5384 | def test_ap_wps_authenticator_mismatch_m6(dev, apdev): | |
5385 | """WPS and Authenticator attribute mismatch in M6""" | |
5386 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5387 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5388 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5389 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5390 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5391 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5392 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5393 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5394 | wps_ext_eap_wsc(hapd, dev[0], addr, "M5") | |
5395 | logger.debug("M6") | |
5396 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=10") | |
5397 | ||
5398 | def test_ap_wps_authenticator_mismatch_m7(dev, apdev): | |
5399 | """WPS and Authenticator attribute mismatch in M7""" | |
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 | logger.debug("M7") | |
5411 | wps_auth_corrupt_to_ap(dev[0], hapd, addr, "msg=11") | |
5412 | ||
5413 | def test_ap_wps_authenticator_mismatch_m8(dev, apdev): | |
5414 | """WPS and Authenticator attribute mismatch in M8""" | |
5415 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5416 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5417 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5418 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5419 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5420 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M2") | |
5421 | wps_ext_eap_wsc(hapd, dev[0], addr, "M3") | |
5422 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M4") | |
5423 | wps_ext_eap_wsc(hapd, dev[0], addr, "M5") | |
5424 | wps_ext_eap_wsc(dev[0], hapd, bssid, "M6") | |
5425 | wps_ext_eap_wsc(hapd, dev[0], addr, "M7") | |
5426 | logger.debug("M8") | |
5427 | wps_auth_corrupt_from_ap(dev[0], hapd, bssid, "msg=12") | |
5428 | ||
5429 | def test_ap_wps_authenticator_missing_m2(dev, apdev): | |
5430 | """WPS and Authenticator attribute missing from M2""" | |
5431 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5432 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5433 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5434 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5435 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5436 | logger.debug("M2") | |
5437 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5438 | if ev is None: | |
5439 | raise Exception("Timeout on EAPOL-TX") | |
5440 | hapd.request("SET ext_eapol_frame_io 0") | |
5441 | dev[0].request("SET ext_eapol_frame_io 0") | |
5442 | msg = ev.split(' ')[2] | |
5443 | if msg[-24:-16] != '10050008': | |
5444 | raise Exception("Could not find Authenticator attribute") | |
5445 | # Remove Authenticator value | |
5446 | msg = msg[:-24] | |
5447 | mlen = "%04x" % (int(msg[4:8], 16) - 12) | |
5448 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:] | |
5449 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5450 | if "OK" not in res: | |
5451 | raise Exception("EAPOL_RX failed") | |
5452 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5453 | ||
d1883671 JM |
5454 | def test_ap_wps_m2_dev_passwd_id_p2p(dev, apdev): |
5455 | """WPS and M2 with different Device Password ID (P2P)""" | |
5456 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5457 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5458 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5459 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5460 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5461 | logger.debug("M2") | |
5462 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5463 | if ev is None: | |
5464 | raise Exception("Timeout on EAPOL-TX") | |
5465 | hapd.request("SET ext_eapol_frame_io 0") | |
5466 | dev[0].request("SET ext_eapol_frame_io 0") | |
5467 | msg = ev.split(' ')[2] | |
5468 | if msg[722:730] != '10120002': | |
5469 | raise Exception("Could not find Device Password ID attribute") | |
5470 | # Replace Device Password ID value. This will fail Authenticator check, but | |
5471 | # allows the code path in wps_process_dev_pw_id() to be checked from debug | |
5472 | # log. | |
5473 | msg = msg[0:730] + "0005" + msg[734:] | |
5474 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5475 | if "OK" not in res: | |
5476 | raise Exception("EAPOL_RX failed") | |
5477 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5478 | ||
5479 | def test_ap_wps_m2_dev_passwd_id_change_pin_to_pbc(dev, apdev): | |
5480 | """WPS and M2 with different Device Password ID (PIN to PBC)""" | |
5481 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5482 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5483 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5484 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5485 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5486 | logger.debug("M2") | |
5487 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5488 | if ev is None: | |
5489 | raise Exception("Timeout on EAPOL-TX") | |
5490 | hapd.request("SET ext_eapol_frame_io 0") | |
5491 | dev[0].request("SET ext_eapol_frame_io 0") | |
5492 | msg = ev.split(' ')[2] | |
5493 | if msg[722:730] != '10120002': | |
5494 | raise Exception("Could not find Device Password ID attribute") | |
5495 | # Replace Device Password ID value (PIN --> PBC). This will be rejected. | |
5496 | msg = msg[0:730] + "0004" + msg[734:] | |
5497 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5498 | if "OK" not in res: | |
5499 | raise Exception("EAPOL_RX failed") | |
5500 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5501 | ||
5502 | def test_ap_wps_m2_dev_passwd_id_change_pbc_to_pin(dev, apdev): | |
5503 | """WPS and M2 with different Device Password ID (PBC to PIN)""" | |
5504 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5505 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5506 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5507 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5508 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5509 | logger.debug("M2") | |
5510 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5511 | if ev is None: | |
5512 | raise Exception("Timeout on EAPOL-TX") | |
5513 | hapd.request("SET ext_eapol_frame_io 0") | |
5514 | dev[0].request("SET ext_eapol_frame_io 0") | |
5515 | msg = ev.split(' ')[2] | |
5516 | if msg[722:730] != '10120002': | |
5517 | raise Exception("Could not find Device Password ID attribute") | |
5518 | # Replace Device Password ID value. This will fail Authenticator check, but | |
5519 | # allows the code path in wps_process_dev_pw_id() to be checked from debug | |
5520 | # log. | |
5521 | msg = msg[0:730] + "0000" + msg[734:] | |
5522 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5523 | if "OK" not in res: | |
5524 | raise Exception("EAPOL_RX failed") | |
5525 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5526 | dev[0].flush_scan_cache() | |
5527 | ||
5528 | def test_ap_wps_m2_missing_dev_passwd_id(dev, apdev): | |
5529 | """WPS and M2 without Device Password ID""" | |
5530 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0]) | |
5531 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5532 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5533 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5534 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5535 | logger.debug("M2") | |
5536 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5537 | if ev is None: | |
5538 | raise Exception("Timeout on EAPOL-TX") | |
5539 | hapd.request("SET ext_eapol_frame_io 0") | |
5540 | dev[0].request("SET ext_eapol_frame_io 0") | |
5541 | msg = ev.split(' ')[2] | |
5542 | if msg[722:730] != '10120002': | |
5543 | raise Exception("Could not find Device Password ID attribute") | |
5544 | # Remove Device Password ID value. This will fail Authenticator check, but | |
5545 | # allows the code path in wps_process_dev_pw_id() to be checked from debug | |
5546 | # log. | |
5547 | mlen = "%04x" % (int(msg[4:8], 16) - 6) | |
5548 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:722] + msg[734:] | |
5549 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5550 | if "OK" not in res: | |
5551 | raise Exception("EAPOL_RX failed") | |
5552 | wps_fail_finish(hapd, dev[0], "msg=5") | |
5553 | ||
5554 | def test_ap_wps_m2_missing_registrar_nonce(dev, apdev): | |
5555 | """WPS and M2 without Registrar Nonce""" | |
5556 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5557 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5558 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5559 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5560 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5561 | logger.debug("M2") | |
5562 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5563 | if ev is None: | |
5564 | raise Exception("Timeout on EAPOL-TX") | |
5565 | hapd.request("SET ext_eapol_frame_io 0") | |
5566 | dev[0].request("SET ext_eapol_frame_io 0") | |
5567 | msg = ev.split(' ')[2] | |
5568 | if msg[96:104] != '10390010': | |
5569 | raise Exception("Could not find Registrar Nonce attribute") | |
5570 | # Remove Registrar Nonce. This will fail Authenticator check, but | |
5571 | # allows the code path in wps_process_registrar_nonce() to be checked from | |
5572 | # the debug log. | |
5573 | mlen = "%04x" % (int(msg[4:8], 16) - 20) | |
5574 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:96] + msg[136:] | |
5575 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5576 | if "OK" not in res: | |
5577 | raise Exception("EAPOL_RX failed") | |
5578 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5579 | if ev is None: | |
5580 | raise Exception("Disconnect event not seen") | |
5581 | dev[0].request("WPS_CANCEL") | |
5582 | dev[0].flush_scan_cache() | |
5583 | ||
5584 | def test_ap_wps_m2_missing_enrollee_nonce(dev, apdev): | |
5585 | """WPS and M2 without Enrollee Nonce""" | |
5586 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5587 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5588 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5589 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5590 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5591 | logger.debug("M2") | |
5592 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5593 | if ev is None: | |
5594 | raise Exception("Timeout on EAPOL-TX") | |
5595 | hapd.request("SET ext_eapol_frame_io 0") | |
5596 | dev[0].request("SET ext_eapol_frame_io 0") | |
5597 | msg = ev.split(' ')[2] | |
5598 | if msg[56:64] != '101a0010': | |
5599 | raise Exception("Could not find enrollee Nonce attribute") | |
5600 | # Remove Enrollee Nonce. This will fail Authenticator check, but | |
5601 | # allows the code path in wps_process_enrollee_nonce() to be checked from | |
5602 | # the debug log. | |
5603 | mlen = "%04x" % (int(msg[4:8], 16) - 20) | |
5604 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:56] + msg[96:] | |
5605 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5606 | if "OK" not in res: | |
5607 | raise Exception("EAPOL_RX failed") | |
5608 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5609 | if ev is None: | |
5610 | raise Exception("Disconnect event not seen") | |
5611 | dev[0].request("WPS_CANCEL") | |
5612 | dev[0].flush_scan_cache() | |
5613 | ||
5614 | def test_ap_wps_m2_missing_uuid_r(dev, apdev): | |
5615 | """WPS and M2 without UUID-R""" | |
5616 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5617 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5618 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5619 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5620 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5621 | logger.debug("M2") | |
5622 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5623 | if ev is None: | |
5624 | raise Exception("Timeout on EAPOL-TX") | |
5625 | hapd.request("SET ext_eapol_frame_io 0") | |
5626 | dev[0].request("SET ext_eapol_frame_io 0") | |
5627 | msg = ev.split(' ')[2] | |
5628 | if msg[136:144] != '10480010': | |
5629 | raise Exception("Could not find enrollee Nonce attribute") | |
5630 | # Remove UUID-R. This will fail Authenticator check, but allows the code | |
5631 | # path in wps_process_uuid_r() to be checked from the debug log. | |
5632 | mlen = "%04x" % (int(msg[4:8], 16) - 20) | |
5633 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:136] + msg[176:] | |
5634 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5635 | if "OK" not in res: | |
5636 | raise Exception("EAPOL_RX failed") | |
5637 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5638 | if ev is None: | |
5639 | raise Exception("Disconnect event not seen") | |
5640 | dev[0].request("WPS_CANCEL") | |
5641 | dev[0].flush_scan_cache() | |
5642 | ||
5643 | def test_ap_wps_m2_invalid(dev, apdev): | |
5644 | """WPS and M2 parsing failure""" | |
5645 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5646 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5647 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5648 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5649 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5650 | logger.debug("M2") | |
5651 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5652 | if ev is None: | |
5653 | raise Exception("Timeout on EAPOL-TX") | |
5654 | hapd.request("SET ext_eapol_frame_io 0") | |
5655 | dev[0].request("SET ext_eapol_frame_io 0") | |
5656 | msg = ev.split(' ')[2] | |
5657 | if msg[136:144] != '10480010': | |
5658 | raise Exception("Could not find enrollee Nonce attribute") | |
5659 | # Remove UUID-R. This will fail Authenticator check, but allows the code | |
5660 | # path in wps_process_uuid_r() to be checked from the debug log. | |
5661 | mlen = "%04x" % (int(msg[4:8], 16) - 1) | |
5662 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:-2] | |
5663 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5664 | if "OK" not in res: | |
5665 | raise Exception("EAPOL_RX failed") | |
5666 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5667 | if ev is None: | |
5668 | raise Exception("Disconnect event not seen") | |
5669 | dev[0].request("WPS_CANCEL") | |
5670 | dev[0].flush_scan_cache() | |
5671 | ||
5672 | def test_ap_wps_m2_missing_msg_type(dev, apdev): | |
5673 | """WPS and M2 without Message Type""" | |
5674 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5675 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5676 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5677 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5678 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5679 | logger.debug("M2") | |
5680 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5681 | if ev is None: | |
5682 | raise Exception("Timeout on EAPOL-TX") | |
5683 | hapd.request("SET ext_eapol_frame_io 0") | |
5684 | dev[0].request("SET ext_eapol_frame_io 0") | |
5685 | msg = ev.split(' ')[2] | |
5686 | if msg[46:54] != '10220001': | |
5687 | raise Exception("Could not find Message Type attribute") | |
5688 | # Remove Message Type. This will fail Authenticator check, but allows the | |
5689 | # code path in wps_process_wsc_msg() to be checked from the debug log. | |
5690 | mlen = "%04x" % (int(msg[4:8], 16) - 5) | |
5691 | msg = msg[0:4] + mlen + msg[8:12] + mlen + msg[16:46] + msg[56:] | |
5692 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5693 | if "OK" not in res: | |
5694 | raise Exception("EAPOL_RX failed") | |
5695 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5696 | if ev is None: | |
5697 | raise Exception("Disconnect event not seen") | |
5698 | dev[0].request("WPS_CANCEL") | |
5699 | dev[0].flush_scan_cache() | |
5700 | ||
5701 | def test_ap_wps_m2_unknown_msg_type(dev, apdev): | |
5702 | """WPS and M2 but unknown Message Type""" | |
5703 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5704 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5705 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5706 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5707 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5708 | logger.debug("M2") | |
5709 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5710 | if ev is None: | |
5711 | raise Exception("Timeout on EAPOL-TX") | |
5712 | hapd.request("SET ext_eapol_frame_io 0") | |
5713 | dev[0].request("SET ext_eapol_frame_io 0") | |
5714 | msg = ev.split(' ')[2] | |
5715 | if msg[46:54] != '10220001': | |
5716 | raise Exception("Could not find Message Type attribute") | |
5717 | # Replace Message Type value. This will be rejected. | |
5718 | msg = msg[0:54] + "00" + msg[56:] | |
5719 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5720 | if "OK" not in res: | |
5721 | raise Exception("EAPOL_RX failed") | |
5722 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECT"], timeout=5) | |
5723 | if ev is None: | |
5724 | raise Exception("Disconnect event not seen") | |
5725 | dev[0].request("WPS_CANCEL") | |
5726 | dev[0].flush_scan_cache() | |
5727 | ||
5728 | def test_ap_wps_m2_unknown_opcode(dev, apdev): | |
5729 | """WPS and M2 but unknown opcode""" | |
5730 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5731 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5732 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5733 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5734 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5735 | logger.debug("M2") | |
5736 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5737 | if ev is None: | |
5738 | raise Exception("Timeout on EAPOL-TX") | |
5739 | hapd.request("SET ext_eapol_frame_io 0") | |
5740 | dev[0].request("SET ext_eapol_frame_io 0") | |
5741 | msg = ev.split(' ')[2] | |
5742 | # Replace opcode. This will be discarded in EAP-WSC processing. | |
5743 | msg = msg[0:32] + "00" + msg[34:] | |
5744 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5745 | if "OK" not in res: | |
5746 | raise Exception("EAPOL_RX failed") | |
5747 | dev[0].request("WPS_CANCEL") | |
5748 | dev[0].wait_disconnected() | |
5749 | dev[0].flush_scan_cache() | |
5750 | ||
5751 | def test_ap_wps_m2_unknown_opcode2(dev, apdev): | |
5752 | """WPS and M2 but unknown opcode (WSC_Start)""" | |
5753 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5754 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5755 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5756 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5757 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5758 | logger.debug("M2") | |
5759 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5760 | if ev is None: | |
5761 | raise Exception("Timeout on EAPOL-TX") | |
5762 | hapd.request("SET ext_eapol_frame_io 0") | |
5763 | dev[0].request("SET ext_eapol_frame_io 0") | |
5764 | msg = ev.split(' ')[2] | |
5765 | # Replace opcode. This will be discarded in EAP-WSC processing. | |
5766 | msg = msg[0:32] + "01" + msg[34:] | |
5767 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5768 | if "OK" not in res: | |
5769 | raise Exception("EAPOL_RX failed") | |
5770 | dev[0].request("WPS_CANCEL") | |
5771 | dev[0].wait_disconnected() | |
5772 | dev[0].flush_scan_cache() | |
5773 | ||
5774 | def test_ap_wps_m2_unknown_opcode3(dev, apdev): | |
5775 | """WPS and M2 but unknown opcode (WSC_Done)""" | |
5776 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
5777 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
5778 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
5779 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
5780 | wps_ext_eap_wsc(hapd, dev[0], addr, "M1") | |
5781 | logger.debug("M2") | |
5782 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5783 | if ev is None: | |
5784 | raise Exception("Timeout on EAPOL-TX") | |
5785 | hapd.request("SET ext_eapol_frame_io 0") | |
5786 | dev[0].request("SET ext_eapol_frame_io 0") | |
5787 | msg = ev.split(' ')[2] | |
5788 | # Replace opcode. This will be discarded in WPS Enrollee processing. | |
5789 | msg = msg[0:32] + "05" + msg[34:] | |
5790 | res = dev[0].request("EAPOL_RX " + bssid + " " + msg) | |
5791 | if "OK" not in res: | |
5792 | raise Exception("EAPOL_RX failed") | |
5793 | dev[0].request("WPS_CANCEL") | |
5794 | dev[0].wait_disconnected() | |
5795 | dev[0].flush_scan_cache() | |
5796 | ||
5797 | def wps_m2_but_other(dev, apdev, title, msgtype): | |
5798 | addr,bssid,hapd = wps_start_ext(apdev, dev) | |
5799 | wps_ext_eap_identity_req(dev, hapd, bssid) | |
5800 | wps_ext_eap_identity_resp(hapd, dev, addr) | |
5801 | wps_ext_eap_wsc(dev, hapd, bssid, "EAP-WSC/Start") | |
5802 | wps_ext_eap_wsc(hapd, dev, addr, "M1") | |
5803 | logger.debug(title) | |
5804 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5805 | if ev is None: | |
5806 | raise Exception("Timeout on EAPOL-TX") | |
5807 | hapd.request("SET ext_eapol_frame_io 0") | |
5808 | dev.request("SET ext_eapol_frame_io 0") | |
5809 | msg = ev.split(' ')[2] | |
5810 | if msg[46:54] != '10220001': | |
5811 | raise Exception("Could not find Message Type attribute") | |
5812 | # Replace Message Type value. This will be rejected. | |
5813 | msg = msg[0:54] + msgtype + msg[56:] | |
5814 | res = dev.request("EAPOL_RX " + bssid + " " + msg) | |
5815 | if "OK" not in res: | |
5816 | raise Exception("EAPOL_RX failed") | |
5817 | ev = dev.wait_event(["WPS-FAIL"], timeout=5) | |
5818 | if ev is None: | |
5819 | raise Exception("WPS-FAIL event not seen") | |
5820 | dev.request("WPS_CANCEL") | |
5821 | dev.wait_disconnected() | |
5822 | ||
5823 | def wps_m4_but_other(dev, apdev, title, msgtype): | |
5824 | addr,bssid,hapd = wps_start_ext(apdev, dev) | |
5825 | wps_ext_eap_identity_req(dev, hapd, bssid) | |
5826 | wps_ext_eap_identity_resp(hapd, dev, addr) | |
5827 | wps_ext_eap_wsc(dev, hapd, bssid, "EAP-WSC/Start") | |
5828 | wps_ext_eap_wsc(hapd, dev, addr, "M1") | |
5829 | wps_ext_eap_wsc(dev, hapd, bssid, "M2") | |
5830 | wps_ext_eap_wsc(hapd, dev, addr, "M3") | |
5831 | logger.debug(title) | |
5832 | ev = hapd.wait_event(["EAPOL-TX"], timeout=10) | |
5833 | if ev is None: | |
5834 | raise Exception("Timeout on EAPOL-TX") | |
5835 | hapd.request("SET ext_eapol_frame_io 0") | |
5836 | dev.request("SET ext_eapol_frame_io 0") | |
5837 | msg = ev.split(' ')[2] | |
5838 | if msg[46:54] != '10220001': | |
5839 | raise Exception("Could not find Message Type attribute") | |
5840 | # Replace Message Type value. This will be rejected. | |
5841 | msg = msg[0:54] + msgtype + msg[56:] | |
5842 | res = dev.request("EAPOL_RX " + bssid + " " + msg) | |
5843 | if "OK" not in res: | |
5844 | raise Exception("EAPOL_RX failed") | |
5845 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
5846 | if ev is None: | |
5847 | raise Exception("WPS-FAIL event not seen") | |
5848 | dev.request("WPS_CANCEL") | |
5849 | dev.wait_disconnected() | |
5850 | ||
5851 | def test_ap_wps_m2_msg_type_m4(dev, apdev): | |
5852 | """WPS and M2 but Message Type M4""" | |
5853 | wps_m2_but_other(dev[0], apdev[0], "M2/M4", "08") | |
5854 | ||
5855 | def test_ap_wps_m2_msg_type_m6(dev, apdev): | |
5856 | """WPS and M2 but Message Type M6""" | |
5857 | wps_m2_but_other(dev[0], apdev[0], "M2/M6", "0a") | |
5858 | ||
5859 | def test_ap_wps_m2_msg_type_m8(dev, apdev): | |
5860 | """WPS and M2 but Message Type M8""" | |
5861 | wps_m2_but_other(dev[0], apdev[0], "M2/M8", "0c") | |
5862 | ||
5863 | def test_ap_wps_m4_msg_type_m2(dev, apdev): | |
5864 | """WPS and M4 but Message Type M2""" | |
5865 | wps_m4_but_other(dev[0], apdev[0], "M4/M2", "05") | |
5866 | ||
5867 | def test_ap_wps_m4_msg_type_m2d(dev, apdev): | |
5868 | """WPS and M4 but Message Type M2D""" | |
5869 | wps_m4_but_other(dev[0], apdev[0], "M4/M2D", "06") | |
5870 | ||
9fd6804d | 5871 | @remote_compatible |
24b7f282 JM |
5872 | def test_ap_wps_config_methods(dev, apdev): |
5873 | """WPS configuration method parsing""" | |
5874 | ssid = "test-wps-conf" | |
5875 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
5876 | "wpa_passphrase": "12345678", "wpa": "2", | |
5877 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
5878 | "config_methods": "ethernet display ext_nfc_token int_nfc_token physical_display physical_push_button" } | |
8b8a1864 | 5879 | hapd = hostapd.add_ap(apdev[0], params) |
24b7f282 JM |
5880 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
5881 | "wpa_passphrase": "12345678", "wpa": "2", | |
5882 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
5883 | "config_methods": "display push_button" } | |
8b8a1864 | 5884 | hapd2 = hostapd.add_ap(apdev[1], params) |
476daa05 JM |
5885 | |
5886 | def test_ap_wps_set_selected_registrar_proto(dev, apdev): | |
5887 | """WPS UPnP SetSelectedRegistrar protocol testing""" | |
5888 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 5889 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
476daa05 JM |
5890 | |
5891 | location = ssdp_get_location(ap_uuid) | |
5892 | urls = upnp_get_urls(location) | |
5893 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
5894 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
5895 | url = urlparse.urlparse(location) | |
5896 | conn = httplib.HTTPConnection(url.netloc) | |
5897 | ||
5898 | class WPSERHTTPServer(SocketServer.StreamRequestHandler): | |
5899 | def handle(self): | |
5900 | data = self.rfile.readline().strip() | |
5901 | logger.debug(data) | |
5902 | self.wfile.write(gen_wps_event()) | |
5903 | ||
5904 | server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) | |
5905 | server.timeout = 1 | |
5906 | ||
5907 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
5908 | "NT": "upnp:event", | |
5909 | "timeout": "Second-1234" } | |
5910 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
5911 | resp = conn.getresponse() | |
5912 | if resp.status != 200: | |
5913 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
5914 | sid = resp.getheader("sid") | |
5915 | logger.debug("Subscription SID " + sid) | |
5916 | server.handle_request() | |
5917 | ||
5918 | tests = [ (500, "10"), | |
5919 | (200, "104a000110" + "1041000101" + "101200020000" + | |
5920 | "105300023148" + | |
5921 | "1049002c00372a0001200124111111111111222222222222333333333333444444444444555555555555666666666666" + | |
5922 | "10480010362db47ba53a519188fb5458b986b2e4"), | |
5923 | (200, "104a000110" + "1041000100" + "101200020000" + | |
5924 | "105300020000"), | |
5925 | (200, "104a000110" + "1041000100"), | |
5926 | (200, "104a000110") ] | |
5927 | for status,test in tests: | |
5928 | tlvs = binascii.unhexlify(test) | |
5929 | newmsg = base64.b64encode(tlvs) | |
5930 | msg = '<?xml version="1.0"?>\n' | |
5931 | msg += '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' | |
5932 | msg += '<s:Body>' | |
5933 | msg += '<u:SetSelectedRegistrar xmlns:u="urn:schemas-wifialliance-org:service:WFAWLANConfig:1">' | |
5934 | msg += '<NewMessage>' | |
5935 | msg += newmsg | |
5936 | msg += "</NewMessage></u:SetSelectedRegistrar></s:Body></s:Envelope>" | |
5937 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
5938 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % "SetSelectedRegistrar" | |
5939 | conn.request("POST", ctrlurl.path, msg, headers) | |
5940 | resp = conn.getresponse() | |
5941 | if resp.status != status: | |
5942 | raise Exception("Unexpected HTTP response: %d (expected %d)" % (resp.status, status)) | |
96038a5f JM |
5943 | |
5944 | def test_ap_wps_adv_oom(dev, apdev): | |
5945 | """WPS AP and advertisement OOM""" | |
5946 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 5947 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
96038a5f JM |
5948 | |
5949 | with alloc_fail(hapd, 1, "=msearchreply_state_machine_start"): | |
5950 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1", | |
5951 | no_recv=True) | |
5952 | time.sleep(0.2) | |
5953 | ||
5954 | with alloc_fail(hapd, 1, "eloop_register_timeout;msearchreply_state_machine_start"): | |
5955 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1", | |
5956 | no_recv=True) | |
5957 | time.sleep(0.2) | |
5958 | ||
5959 | with alloc_fail(hapd, 1, | |
5960 | "next_advertisement;advertisement_state_machine_stop"): | |
5961 | hapd.disable() | |
5962 | ||
5963 | with alloc_fail(hapd, 1, "ssdp_listener_start"): | |
5964 | if "FAIL" not in hapd.request("ENABLE"): | |
5965 | raise Exception("ENABLE succeeded during OOM") | |
926404a6 JM |
5966 | |
5967 | def test_wps_config_methods(dev): | |
5968 | """WPS config method update""" | |
5969 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
5970 | wpas.interface_add("wlan5") | |
5971 | if "OK" not in wpas.request("SET config_methods display label"): | |
5972 | raise Exception("Failed to set config_methods") | |
5973 | if wpas.request("GET config_methods").strip() != "display label": | |
5974 | raise Exception("config_methods were not updated") | |
5975 | if "OK" not in wpas.request("SET config_methods "): | |
5976 | raise Exception("Failed to clear config_methods") | |
5977 | if wpas.request("GET config_methods").strip() != "": | |
5978 | raise Exception("config_methods were not cleared") | |
7511ead0 JM |
5979 | |
5980 | WPS_VENDOR_ID_WFA = 14122 | |
5981 | WPS_VENDOR_TYPE = 1 | |
5982 | ||
5983 | # EAP-WSC Op-Code values | |
5984 | WSC_Start = 0x01 | |
5985 | WSC_ACK = 0x02 | |
5986 | WSC_NACK = 0x03 | |
5987 | WSC_MSG = 0x04 | |
5988 | WSC_Done = 0x05 | |
5989 | WSC_FRAG_ACK = 0x06 | |
5990 | ||
5991 | ATTR_AP_CHANNEL = 0x1001 | |
5992 | ATTR_ASSOC_STATE = 0x1002 | |
5993 | ATTR_AUTH_TYPE = 0x1003 | |
5994 | ATTR_AUTH_TYPE_FLAGS = 0x1004 | |
5995 | ATTR_AUTHENTICATOR = 0x1005 | |
5996 | ATTR_CONFIG_METHODS = 0x1008 | |
5997 | ATTR_CONFIG_ERROR = 0x1009 | |
5998 | ATTR_CONFIRM_URL4 = 0x100a | |
5999 | ATTR_CONFIRM_URL6 = 0x100b | |
6000 | ATTR_CONN_TYPE = 0x100c | |
6001 | ATTR_CONN_TYPE_FLAGS = 0x100d | |
6002 | ATTR_CRED = 0x100e | |
6003 | ATTR_ENCR_TYPE = 0x100f | |
6004 | ATTR_ENCR_TYPE_FLAGS = 0x1010 | |
6005 | ATTR_DEV_NAME = 0x1011 | |
6006 | ATTR_DEV_PASSWORD_ID = 0x1012 | |
6007 | ATTR_E_HASH1 = 0x1014 | |
6008 | ATTR_E_HASH2 = 0x1015 | |
6009 | ATTR_E_SNONCE1 = 0x1016 | |
6010 | ATTR_E_SNONCE2 = 0x1017 | |
6011 | ATTR_ENCR_SETTINGS = 0x1018 | |
6012 | ATTR_ENROLLEE_NONCE = 0x101a | |
6013 | ATTR_FEATURE_ID = 0x101b | |
6014 | ATTR_IDENTITY = 0x101c | |
6015 | ATTR_IDENTITY_PROOF = 0x101d | |
6016 | ATTR_KEY_WRAP_AUTH = 0x101e | |
6017 | ATTR_KEY_ID = 0x101f | |
6018 | ATTR_MAC_ADDR = 0x1020 | |
6019 | ATTR_MANUFACTURER = 0x1021 | |
6020 | ATTR_MSG_TYPE = 0x1022 | |
6021 | ATTR_MODEL_NAME = 0x1023 | |
6022 | ATTR_MODEL_NUMBER = 0x1024 | |
6023 | ATTR_NETWORK_INDEX = 0x1026 | |
6024 | ATTR_NETWORK_KEY = 0x1027 | |
6025 | ATTR_NETWORK_KEY_INDEX = 0x1028 | |
6026 | ATTR_NEW_DEVICE_NAME = 0x1029 | |
6027 | ATTR_NEW_PASSWORD = 0x102a | |
6028 | ATTR_OOB_DEVICE_PASSWORD = 0x102c | |
6029 | ATTR_OS_VERSION = 0x102d | |
6030 | ATTR_POWER_LEVEL = 0x102f | |
6031 | ATTR_PSK_CURRENT = 0x1030 | |
6032 | ATTR_PSK_MAX = 0x1031 | |
6033 | ATTR_PUBLIC_KEY = 0x1032 | |
6034 | ATTR_RADIO_ENABLE = 0x1033 | |
6035 | ATTR_REBOOT = 0x1034 | |
6036 | ATTR_REGISTRAR_CURRENT = 0x1035 | |
6037 | ATTR_REGISTRAR_ESTABLISHED = 0x1036 | |
6038 | ATTR_REGISTRAR_LIST = 0x1037 | |
6039 | ATTR_REGISTRAR_MAX = 0x1038 | |
6040 | ATTR_REGISTRAR_NONCE = 0x1039 | |
6041 | ATTR_REQUEST_TYPE = 0x103a | |
6042 | ATTR_RESPONSE_TYPE = 0x103b | |
6043 | ATTR_RF_BANDS = 0x103c | |
6044 | ATTR_R_HASH1 = 0x103d | |
6045 | ATTR_R_HASH2 = 0x103e | |
6046 | ATTR_R_SNONCE1 = 0x103f | |
6047 | ATTR_R_SNONCE2 = 0x1040 | |
6048 | ATTR_SELECTED_REGISTRAR = 0x1041 | |
6049 | ATTR_SERIAL_NUMBER = 0x1042 | |
6050 | ATTR_WPS_STATE = 0x1044 | |
6051 | ATTR_SSID = 0x1045 | |
6052 | ATTR_TOTAL_NETWORKS = 0x1046 | |
6053 | ATTR_UUID_E = 0x1047 | |
6054 | ATTR_UUID_R = 0x1048 | |
6055 | ATTR_VENDOR_EXT = 0x1049 | |
6056 | ATTR_VERSION = 0x104a | |
6057 | ATTR_X509_CERT_REQ = 0x104b | |
6058 | ATTR_X509_CERT = 0x104c | |
6059 | ATTR_EAP_IDENTITY = 0x104d | |
6060 | ATTR_MSG_COUNTER = 0x104e | |
6061 | ATTR_PUBKEY_HASH = 0x104f | |
6062 | ATTR_REKEY_KEY = 0x1050 | |
6063 | ATTR_KEY_LIFETIME = 0x1051 | |
6064 | ATTR_PERMITTED_CFG_METHODS = 0x1052 | |
6065 | ATTR_SELECTED_REGISTRAR_CONFIG_METHODS = 0x1053 | |
6066 | ATTR_PRIMARY_DEV_TYPE = 0x1054 | |
6067 | ATTR_SECONDARY_DEV_TYPE_LIST = 0x1055 | |
6068 | ATTR_PORTABLE_DEV = 0x1056 | |
6069 | ATTR_AP_SETUP_LOCKED = 0x1057 | |
6070 | ATTR_APPLICATION_EXT = 0x1058 | |
6071 | ATTR_EAP_TYPE = 0x1059 | |
6072 | ATTR_IV = 0x1060 | |
6073 | ATTR_KEY_PROVIDED_AUTO = 0x1061 | |
6074 | ATTR_802_1X_ENABLED = 0x1062 | |
6075 | ATTR_APPSESSIONKEY = 0x1063 | |
6076 | ATTR_WEPTRANSMITKEY = 0x1064 | |
6077 | ATTR_REQUESTED_DEV_TYPE = 0x106a | |
6078 | ||
6079 | # Message Type | |
6080 | WPS_Beacon = 0x01 | |
6081 | WPS_ProbeRequest = 0x02 | |
6082 | WPS_ProbeResponse = 0x03 | |
6083 | WPS_M1 = 0x04 | |
6084 | WPS_M2 = 0x05 | |
6085 | WPS_M2D = 0x06 | |
6086 | WPS_M3 = 0x07 | |
6087 | WPS_M4 = 0x08 | |
6088 | WPS_M5 = 0x09 | |
6089 | WPS_M6 = 0x0a | |
6090 | WPS_M7 = 0x0b | |
6091 | WPS_M8 = 0x0c | |
6092 | WPS_WSC_ACK = 0x0d | |
6093 | WPS_WSC_NACK = 0x0e | |
6094 | WPS_WSC_DONE = 0x0f | |
6095 | ||
6096 | def get_wsc_msg(dev): | |
6097 | ev = dev.wait_event(["EAPOL-TX"], timeout=10) | |
6098 | if ev is None: | |
6099 | raise Exception("Timeout on EAPOL-TX") | |
6100 | data = binascii.unhexlify(ev.split(' ')[2]) | |
6101 | msg = {} | |
6102 | ||
6103 | # Parse EAPOL header | |
6104 | if len(data) < 4: | |
6105 | raise Exception("No room for EAPOL header") | |
6106 | version,type,length = struct.unpack('>BBH', data[0:4]) | |
6107 | msg['eapol_version'] = version | |
6108 | msg['eapol_type'] = type | |
6109 | msg['eapol_length'] = length | |
6110 | data = data[4:] | |
6111 | if length != len(data): | |
6112 | raise Exception("EAPOL header length mismatch (%d != %d)" % (length, len(data))) | |
6113 | if type != 0: | |
6114 | raise Exception("Unexpected EAPOL header type: %d" % type) | |
6115 | ||
6116 | # Parse EAP header | |
6117 | if len(data) < 4: | |
6118 | raise Exception("No room for EAP header") | |
6119 | code,identifier,length = struct.unpack('>BBH', data[0:4]) | |
6120 | msg['eap_code'] = code | |
6121 | msg['eap_identifier'] = identifier | |
6122 | msg['eap_length'] = length | |
6123 | data = data[4:] | |
6124 | if msg['eapol_length'] != msg['eap_length']: | |
6125 | raise Exception("EAP header length mismatch (%d != %d)" % (msg['eapol_length'], length)) | |
6126 | ||
6127 | # Parse EAP expanded header | |
6128 | if len(data) < 1: | |
6129 | raise Exception("No EAP type included") | |
6130 | msg['eap_type'], = struct.unpack('B', data[0]) | |
6131 | data = data[1:] | |
6132 | ||
6133 | if msg['eap_type'] == 254: | |
6134 | if len(data) < 3 + 4: | |
6135 | raise Exception("Truncated EAP expanded header") | |
6136 | msg['eap_vendor_id'], msg['eap_vendor_type'] = struct.unpack('>LL', '\0' + data[0:7]) | |
6137 | data = data[7:] | |
6138 | else: | |
6139 | raise Exception("Unexpected EAP type") | |
6140 | ||
6141 | if msg['eap_vendor_id'] != WPS_VENDOR_ID_WFA: | |
6142 | raise Exception("Unexpected Vendor-Id") | |
6143 | if msg['eap_vendor_type'] != WPS_VENDOR_TYPE: | |
6144 | raise Exception("Unexpected Vendor-Type") | |
6145 | ||
6146 | # Parse EAP-WSC header | |
6147 | if len(data) < 2: | |
6148 | raise Exception("Truncated EAP-WSC header") | |
6149 | msg['wsc_opcode'], msg['wsc_flags'] = struct.unpack('BB', data[0:2]) | |
6150 | data = data[2:] | |
6151 | ||
6152 | # Parse WSC attributes | |
6153 | msg['raw_attrs'] = data | |
6154 | attrs = {} | |
6155 | while len(data) > 0: | |
6156 | if len(data) < 4: | |
6157 | raise Exception("Truncated attribute header") | |
6158 | attr,length = struct.unpack('>HH', data[0:4]) | |
6159 | data = data[4:] | |
6160 | if length > len(data): | |
6161 | raise Exception("Truncated attribute 0x%04x" % attr) | |
6162 | attrs[attr] = data[0:length] | |
6163 | data = data[length:] | |
6164 | msg['wsc_attrs'] = attrs | |
6165 | ||
6166 | if ATTR_MSG_TYPE in attrs: | |
6167 | msg['wsc_msg_type'], = struct.unpack('B', attrs[ATTR_MSG_TYPE]) | |
6168 | ||
6169 | return msg | |
6170 | ||
6171 | def recv_wsc_msg(dev, opcode, msg_type): | |
6172 | msg = get_wsc_msg(dev) | |
6173 | if msg['wsc_opcode'] != opcode or msg['wsc_msg_type'] != msg_type: | |
6174 | raise Exception("Unexpected Op-Code/MsgType") | |
6175 | return msg, msg['wsc_attrs'], msg['raw_attrs'] | |
6176 | ||
6177 | def build_wsc_attr(attr, payload): | |
6178 | return struct.pack('>HH', attr, len(payload)) + payload | |
6179 | ||
6180 | def build_attr_msg_type(msg_type): | |
6181 | return build_wsc_attr(ATTR_MSG_TYPE, struct.pack('B', msg_type)) | |
6182 | ||
6183 | def build_eap_wsc(eap_code, eap_id, payload, opcode=WSC_MSG): | |
6184 | length = 4 + 8 + 2 + len(payload) | |
6185 | # EAPOL header | |
6186 | msg = struct.pack('>BBH', 2, 0, length) | |
6187 | # EAP header | |
6188 | msg += struct.pack('>BBH', eap_code, eap_id, length) | |
6189 | # EAP expanded header for EAP-WSC | |
6190 | msg += struct.pack('B', 254) | |
6191 | msg += struct.pack('>L', WPS_VENDOR_ID_WFA)[1:4] | |
6192 | msg += struct.pack('>L', WPS_VENDOR_TYPE) | |
6193 | # EAP-WSC header | |
6194 | msg += struct.pack('BB', opcode, 0) | |
6195 | # WSC attributes | |
6196 | msg += payload | |
6197 | return msg | |
6198 | ||
6199 | def build_eap_success(eap_id): | |
6200 | length = 4 | |
6201 | # EAPOL header | |
6202 | msg = struct.pack('>BBH', 2, 0, length) | |
6203 | # EAP header | |
6204 | msg += struct.pack('>BBH', 3, eap_id, length) | |
6205 | return msg | |
6206 | ||
6207 | def build_eap_failure(eap_id): | |
6208 | length = 4 | |
6209 | # EAPOL header | |
6210 | msg = struct.pack('>BBH', 2, 0, length) | |
6211 | # EAP header | |
6212 | msg += struct.pack('>BBH', 4, eap_id, length) | |
6213 | return msg | |
6214 | ||
6215 | def send_wsc_msg(dev, src, msg): | |
6216 | res = dev.request("EAPOL_RX " + src + " " + binascii.hexlify(msg)) | |
6217 | if "OK" not in res: | |
6218 | raise Exception("EAPOL_RX failed") | |
6219 | ||
6220 | group_5_prime = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF | |
6221 | group_5_generator = 2 | |
6222 | ||
6223 | def wsc_kdf(key, label, bits): | |
6224 | result = '' | |
6225 | i = 1 | |
6226 | while len(result) * 8 < bits: | |
6227 | data = struct.pack('>L', i) + label + struct.pack('>L', bits) | |
6228 | m = hmac.new(key, data, hashlib.sha256) | |
6229 | result += m.digest() | |
6230 | i += 1 | |
6231 | return result[0:bits / 8] | |
6232 | ||
6233 | def wsc_keys(kdk): | |
6234 | keys = wsc_kdf(kdk, "Wi-Fi Easy and Secure Key Derivation", 640) | |
6235 | authkey = keys[0:32] | |
6236 | keywrapkey = keys[32:48] | |
6237 | emsk = keys[48:80] | |
6238 | return authkey,keywrapkey,emsk | |
6239 | ||
6240 | def wsc_dev_pw_half_psk(authkey, dev_pw): | |
6241 | m = hmac.new(authkey, dev_pw, hashlib.sha256) | |
6242 | return m.digest()[0:16] | |
6243 | ||
6244 | def wsc_dev_pw_psk(authkey, dev_pw): | |
6245 | dev_pw_1 = dev_pw[0:len(dev_pw) / 2] | |
6246 | dev_pw_2 = dev_pw[len(dev_pw) / 2:] | |
6247 | psk1 = wsc_dev_pw_half_psk(authkey, dev_pw_1) | |
6248 | psk2 = wsc_dev_pw_half_psk(authkey, dev_pw_2) | |
6249 | return psk1,psk2 | |
6250 | ||
6251 | def build_attr_authenticator(authkey, prev_msg, curr_msg): | |
6252 | m = hmac.new(authkey, prev_msg + curr_msg, hashlib.sha256) | |
6253 | auth = m.digest()[0:8] | |
6254 | return build_wsc_attr(ATTR_AUTHENTICATOR, auth) | |
6255 | ||
6256 | def build_attr_encr_settings(authkey, keywrapkey, data): | |
6257 | m = hmac.new(authkey, data, hashlib.sha256) | |
6258 | kwa = m.digest()[0:8] | |
6259 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
6260 | iv = 16*'\x99' | |
6261 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6262 | pad_len = 16 - len(data) % 16 | |
6263 | ps = pad_len * struct.pack('B', pad_len) | |
6264 | data += ps | |
6265 | wrapped = aes.encrypt(data) | |
6266 | return build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6267 | ||
6268 | def decrypt_attr_encr_settings(authkey, keywrapkey, data): | |
6269 | if len(data) < 32 or len(data) % 16 != 0: | |
6270 | raise Exception("Unexpected Encrypted Settings length: %d" % len(data)) | |
6271 | iv = data[0:16] | |
6272 | encr = data[16:] | |
6273 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6274 | decrypted = aes.decrypt(encr) | |
6275 | pad_len, = struct.unpack('B', decrypted[-1]) | |
6276 | if pad_len > len(decrypted): | |
6277 | raise Exception("Invalid padding in Encrypted Settings") | |
6278 | for i in range(-pad_len, -1): | |
6279 | if decrypted[i] != decrypted[-1]: | |
6280 | raise Exception("Invalid PS value in Encrypted Settings") | |
db98b587 | 6281 | |
7511ead0 JM |
6282 | decrypted = decrypted[0:len(decrypted) - pad_len] |
6283 | if len(decrypted) < 12: | |
6284 | raise Exception("Truncated Encrypted Settings plaintext") | |
6285 | kwa = decrypted[-12:] | |
6286 | attr,length = struct.unpack(">HH", kwa[0:4]) | |
6287 | if attr != ATTR_KEY_WRAP_AUTH or length != 8: | |
6288 | raise Exception("Invalid KWA header") | |
6289 | kwa = kwa[4:] | |
6290 | decrypted = decrypted[0:len(decrypted) - 12] | |
6291 | ||
6292 | m = hmac.new(authkey, decrypted, hashlib.sha256) | |
6293 | calc_kwa = m.digest()[0:8] | |
6294 | if kwa != calc_kwa: | |
6295 | raise Exception("KWA mismatch") | |
6296 | ||
6297 | return decrypted | |
6298 | ||
6299 | def zeropad_str(val, pad_len): | |
6300 | while len(val) < pad_len * 2: | |
6301 | val = '0' + val | |
6302 | return val | |
6303 | ||
6304 | def wsc_dh_init(): | |
6305 | # For now, use a hardcoded private key. In theory, this is supposed to be | |
6306 | # randomly selected. | |
6307 | own_private = 0x123456789 | |
6308 | own_public = pow(group_5_generator, own_private, group_5_prime) | |
6309 | pk = binascii.unhexlify(zeropad_str(format(own_public, '02x'), 192)) | |
6310 | return own_private, pk | |
6311 | ||
6312 | def wsc_dh_kdf(peer_pk, own_private, mac_addr, e_nonce, r_nonce): | |
6313 | peer_public = long(binascii.hexlify(peer_pk), 16) | |
6314 | if peer_public < 2 or peer_public >= group_5_prime: | |
6315 | raise Exception("Invalid peer public key") | |
6316 | if pow(peer_public, (group_5_prime - 1) / 2, group_5_prime) != 1: | |
6317 | raise Exception("Unexpected Legendre symbol for peer public key") | |
6318 | ||
6319 | shared_secret = pow(peer_public, own_private, group_5_prime) | |
6320 | ss = zeropad_str(format(shared_secret, "02x"), 192) | |
6321 | logger.debug("DH shared secret: " + ss) | |
6322 | ||
6323 | dhkey = hashlib.sha256(binascii.unhexlify(ss)).digest() | |
6324 | logger.debug("DHKey: " + binascii.hexlify(dhkey)) | |
6325 | ||
6326 | m = hmac.new(dhkey, e_nonce + mac_addr + r_nonce, hashlib.sha256) | |
6327 | kdk = m.digest() | |
6328 | logger.debug("KDK: " + binascii.hexlify(kdk)) | |
6329 | authkey,keywrapkey,emsk = wsc_keys(kdk) | |
6330 | logger.debug("AuthKey: " + binascii.hexlify(authkey)) | |
6331 | logger.debug("KeyWrapKey: " + binascii.hexlify(keywrapkey)) | |
6332 | logger.debug("EMSK: " + binascii.hexlify(emsk)) | |
6333 | return authkey,keywrapkey | |
6334 | ||
6335 | def wsc_dev_pw_hash(authkey, dev_pw, e_pk, r_pk): | |
6336 | psk1,psk2 = wsc_dev_pw_psk(authkey, dev_pw) | |
6337 | logger.debug("PSK1: " + binascii.hexlify(psk1)) | |
6338 | logger.debug("PSK2: " + binascii.hexlify(psk2)) | |
6339 | ||
6340 | # Note: Secret values are supposed to be random, but hardcoded values are | |
6341 | # fine for testing. | |
6342 | s1 = 16*'\x77' | |
6343 | m = hmac.new(authkey, s1 + psk1 + e_pk + r_pk, hashlib.sha256) | |
6344 | hash1 = m.digest() | |
6345 | logger.debug("Hash1: " + binascii.hexlify(hash1)) | |
6346 | ||
6347 | s2 = 16*'\x88' | |
6348 | m = hmac.new(authkey, s2 + psk2 + e_pk + r_pk, hashlib.sha256) | |
6349 | hash2 = m.digest() | |
6350 | logger.debug("Hash2: " + binascii.hexlify(hash2)) | |
6351 | return s1,s2,hash1,hash2 | |
6352 | ||
6353 | def build_m1(eap_id, uuid_e, mac_addr, e_nonce, e_pk, | |
6354 | manufacturer='', model_name='', config_methods='\x00\x00'): | |
6355 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6356 | attrs += build_attr_msg_type(WPS_M1) | |
6357 | attrs += build_wsc_attr(ATTR_UUID_E, uuid_e) | |
6358 | attrs += build_wsc_attr(ATTR_MAC_ADDR, mac_addr) | |
6359 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6360 | attrs += build_wsc_attr(ATTR_PUBLIC_KEY, e_pk) | |
6361 | attrs += build_wsc_attr(ATTR_AUTH_TYPE_FLAGS, '\x00\x00') | |
6362 | attrs += build_wsc_attr(ATTR_ENCR_TYPE_FLAGS, '\x00\x00') | |
6363 | attrs += build_wsc_attr(ATTR_CONN_TYPE_FLAGS, '\x00') | |
6364 | attrs += build_wsc_attr(ATTR_CONFIG_METHODS, config_methods) | |
6365 | attrs += build_wsc_attr(ATTR_WPS_STATE, '\x00') | |
6366 | attrs += build_wsc_attr(ATTR_MANUFACTURER, manufacturer) | |
6367 | attrs += build_wsc_attr(ATTR_MODEL_NAME, model_name) | |
6368 | attrs += build_wsc_attr(ATTR_MODEL_NUMBER, '') | |
6369 | attrs += build_wsc_attr(ATTR_SERIAL_NUMBER, '') | |
6370 | attrs += build_wsc_attr(ATTR_PRIMARY_DEV_TYPE, 8*'\x00') | |
6371 | attrs += build_wsc_attr(ATTR_DEV_NAME, '') | |
6372 | attrs += build_wsc_attr(ATTR_RF_BANDS, '\x00') | |
6373 | attrs += build_wsc_attr(ATTR_ASSOC_STATE, '\x00\x00') | |
6374 | attrs += build_wsc_attr(ATTR_DEV_PASSWORD_ID, '\x00\x00') | |
6375 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, '\x00\x00') | |
6376 | attrs += build_wsc_attr(ATTR_OS_VERSION, '\x00\x00\x00\x00') | |
6377 | m1 = build_eap_wsc(2, eap_id, attrs) | |
6378 | return m1, attrs | |
6379 | ||
6380 | def build_m2(authkey, m1, eap_id, e_nonce, r_nonce, uuid_r, r_pk, | |
6381 | dev_pw_id='\x00\x00', eap_code=1): | |
6382 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6383 | attrs += build_attr_msg_type(WPS_M2) | |
6384 | if e_nonce: | |
6385 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6386 | if r_nonce: | |
6387 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6388 | attrs += build_wsc_attr(ATTR_UUID_R, uuid_r) | |
6389 | if r_pk: | |
6390 | attrs += build_wsc_attr(ATTR_PUBLIC_KEY, r_pk) | |
6391 | attrs += build_wsc_attr(ATTR_AUTH_TYPE_FLAGS, '\x00\x00') | |
6392 | attrs += build_wsc_attr(ATTR_ENCR_TYPE_FLAGS, '\x00\x00') | |
6393 | attrs += build_wsc_attr(ATTR_CONN_TYPE_FLAGS, '\x00') | |
6394 | attrs += build_wsc_attr(ATTR_CONFIG_METHODS, '\x00\x00') | |
6395 | attrs += build_wsc_attr(ATTR_MANUFACTURER, '') | |
6396 | attrs += build_wsc_attr(ATTR_MODEL_NAME, '') | |
6397 | attrs += build_wsc_attr(ATTR_MODEL_NUMBER, '') | |
6398 | attrs += build_wsc_attr(ATTR_SERIAL_NUMBER, '') | |
6399 | attrs += build_wsc_attr(ATTR_PRIMARY_DEV_TYPE, 8*'\x00') | |
6400 | attrs += build_wsc_attr(ATTR_DEV_NAME, '') | |
6401 | attrs += build_wsc_attr(ATTR_RF_BANDS, '\x00') | |
6402 | attrs += build_wsc_attr(ATTR_ASSOC_STATE, '\x00\x00') | |
6403 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, '\x00\x00') | |
6404 | attrs += build_wsc_attr(ATTR_DEV_PASSWORD_ID, dev_pw_id) | |
6405 | attrs += build_wsc_attr(ATTR_OS_VERSION, '\x00\x00\x00\x00') | |
6406 | attrs += build_attr_authenticator(authkey, m1, attrs) | |
6407 | m2 = build_eap_wsc(eap_code, eap_id, attrs) | |
6408 | return m2, attrs | |
6409 | ||
6410 | def build_m2d(m1, eap_id, e_nonce, r_nonce, uuid_r, dev_pw_id=None, eap_code=1): | |
6411 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6412 | attrs += build_attr_msg_type(WPS_M2D) | |
6413 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6414 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6415 | attrs += build_wsc_attr(ATTR_UUID_R, uuid_r) | |
6416 | attrs += build_wsc_attr(ATTR_AUTH_TYPE_FLAGS, '\x00\x00') | |
6417 | attrs += build_wsc_attr(ATTR_ENCR_TYPE_FLAGS, '\x00\x00') | |
6418 | attrs += build_wsc_attr(ATTR_CONN_TYPE_FLAGS, '\x00') | |
6419 | attrs += build_wsc_attr(ATTR_CONFIG_METHODS, '\x00\x00') | |
6420 | attrs += build_wsc_attr(ATTR_MANUFACTURER, '') | |
6421 | attrs += build_wsc_attr(ATTR_MODEL_NAME, '') | |
6422 | #attrs += build_wsc_attr(ATTR_MODEL_NUMBER, '') | |
6423 | attrs += build_wsc_attr(ATTR_SERIAL_NUMBER, '') | |
6424 | attrs += build_wsc_attr(ATTR_PRIMARY_DEV_TYPE, 8*'\x00') | |
6425 | attrs += build_wsc_attr(ATTR_DEV_NAME, '') | |
6426 | attrs += build_wsc_attr(ATTR_RF_BANDS, '\x00') | |
6427 | attrs += build_wsc_attr(ATTR_ASSOC_STATE, '\x00\x00') | |
6428 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, '\x00\x00') | |
6429 | attrs += build_wsc_attr(ATTR_OS_VERSION, '\x00\x00\x00\x00') | |
6430 | if dev_pw_id: | |
6431 | attrs += build_wsc_attr(ATTR_DEV_PASSWORD_ID, dev_pw_id) | |
6432 | m2d = build_eap_wsc(eap_code, eap_id, attrs) | |
6433 | return m2d, attrs | |
6434 | ||
6435 | def build_ack(eap_id, e_nonce, r_nonce, msg_type=WPS_WSC_ACK, eap_code=1): | |
6436 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6437 | if msg_type is not None: | |
6438 | attrs += build_attr_msg_type(msg_type) | |
6439 | if e_nonce: | |
6440 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6441 | if r_nonce: | |
6442 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6443 | msg = build_eap_wsc(eap_code, eap_id, attrs, opcode=WSC_ACK) | |
6444 | return msg, attrs | |
6445 | ||
6446 | def build_nack(eap_id, e_nonce, r_nonce, config_error='\x00\x00', | |
6447 | msg_type=WPS_WSC_NACK, eap_code=1): | |
6448 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6449 | if msg_type is not None: | |
6450 | attrs += build_attr_msg_type(msg_type) | |
6451 | if e_nonce: | |
6452 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6453 | if r_nonce: | |
6454 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
6455 | if config_error: | |
6456 | attrs += build_wsc_attr(ATTR_CONFIG_ERROR, config_error) | |
6457 | msg = build_eap_wsc(eap_code, eap_id, attrs, opcode=WSC_NACK) | |
6458 | return msg, attrs | |
6459 | ||
6460 | def test_wps_ext(dev, apdev): | |
6461 | """WPS against external implementation""" | |
6462 | pin = "12345670" | |
6463 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6464 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6465 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6466 | ||
6467 | logger.debug("Receive WSC/Start from AP") | |
6468 | msg = get_wsc_msg(hapd) | |
6469 | if msg['wsc_opcode'] != WSC_Start: | |
6470 | raise Exception("Unexpected Op-Code for WSC/Start") | |
6471 | wsc_start_id = msg['eap_identifier'] | |
6472 | ||
6473 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6474 | uuid_e = 16*'\x11' | |
6475 | e_nonce = 16*'\x22' | |
6476 | own_private, e_pk = wsc_dh_init() | |
6477 | ||
6478 | logger.debug("Send M1 to AP") | |
6479 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
6480 | e_nonce, e_pk) | |
6481 | send_wsc_msg(hapd, addr, m1) | |
6482 | ||
6483 | logger.debug("Receive M2 from AP") | |
6484 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
6485 | ||
6486 | authkey,keywrapkey = wsc_dh_kdf(m2_attrs[ATTR_PUBLIC_KEY], own_private, | |
6487 | mac_addr, e_nonce, | |
6488 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6489 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, | |
6490 | m2_attrs[ATTR_PUBLIC_KEY]) | |
6491 | ||
6492 | logger.debug("Send M3 to AP") | |
6493 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6494 | attrs += build_attr_msg_type(WPS_M3) | |
6495 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6496 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6497 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
6498 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
6499 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
6500 | raw_m3_attrs = attrs | |
6501 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
6502 | send_wsc_msg(hapd, addr, m3) | |
6503 | ||
6504 | logger.debug("Receive M4 from AP") | |
6505 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
6506 | ||
6507 | logger.debug("Send M5 to AP") | |
6508 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6509 | attrs += build_attr_msg_type(WPS_M5) | |
6510 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6511 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6512 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
6513 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6514 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
6515 | raw_m5_attrs = attrs | |
6516 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
6517 | send_wsc_msg(hapd, addr, m5) | |
6518 | ||
6519 | logger.debug("Receive M6 from AP") | |
6520 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
6521 | ||
6522 | logger.debug("Send M7 to AP") | |
6523 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6524 | attrs += build_attr_msg_type(WPS_M7) | |
6525 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6526 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6527 | data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
6528 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6529 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
6530 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
6531 | raw_m7_attrs = attrs | |
6532 | send_wsc_msg(hapd, addr, m7) | |
6533 | ||
6534 | logger.debug("Receive M8 from AP") | |
6535 | msg, m8_attrs, raw_m8_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M8) | |
6536 | m8_cred = decrypt_attr_encr_settings(authkey, keywrapkey, | |
6537 | m8_attrs[ATTR_ENCR_SETTINGS]) | |
6538 | logger.debug("M8 Credential: " + binascii.hexlify(m8_cred)) | |
6539 | ||
6540 | logger.debug("Prepare WSC_Done") | |
6541 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6542 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
6543 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
6544 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, | |
6545 | m2_attrs[ATTR_REGISTRAR_NONCE]) | |
6546 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
6547 | # Do not send WSC_Done yet to allow exchangw with STA complete before the | |
6548 | # AP disconnects. | |
6549 | ||
6550 | uuid_r = 16*'\x33' | |
6551 | r_nonce = 16*'\x44' | |
6552 | ||
6553 | eap_id = wsc_start_id | |
6554 | logger.debug("Send WSC/Start to STA") | |
6555 | wsc_start = build_eap_wsc(1, eap_id, "", opcode=WSC_Start) | |
6556 | send_wsc_msg(dev[0], bssid, wsc_start) | |
6557 | eap_id = (eap_id + 1) % 256 | |
6558 | ||
6559 | logger.debug("Receive M1 from STA") | |
6560 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6561 | ||
6562 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6563 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6564 | r_nonce) | |
6565 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6566 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6567 | ||
6568 | logger.debug("Send M2 to STA") | |
6569 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6570 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6571 | r_nonce, uuid_r, e_pk) | |
6572 | send_wsc_msg(dev[0], bssid, m2) | |
6573 | eap_id = (eap_id + 1) % 256 | |
6574 | ||
6575 | logger.debug("Receive M3 from STA") | |
6576 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
6577 | ||
6578 | logger.debug("Send M4 to STA") | |
6579 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6580 | attrs += build_attr_msg_type(WPS_M4) | |
6581 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6582 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
6583 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
6584 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6585 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6586 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
6587 | raw_m4_attrs = attrs | |
6588 | m4 = build_eap_wsc(1, eap_id, attrs) | |
6589 | send_wsc_msg(dev[0], bssid, m4) | |
6590 | eap_id = (eap_id + 1) % 256 | |
6591 | ||
6592 | logger.debug("Receive M5 from STA") | |
6593 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
6594 | ||
6595 | logger.debug("Send M6 to STA") | |
6596 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6597 | attrs += build_attr_msg_type(WPS_M6) | |
6598 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6599 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6600 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
6601 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6602 | attrs += build_attr_authenticator(authkey, raw_m5_attrs, attrs) | |
6603 | raw_m6_attrs = attrs | |
6604 | m6 = build_eap_wsc(1, eap_id, attrs) | |
6605 | send_wsc_msg(dev[0], bssid, m6) | |
6606 | eap_id = (eap_id + 1) % 256 | |
6607 | ||
6608 | logger.debug("Receive M7 from STA") | |
6609 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M7) | |
6610 | ||
6611 | logger.debug("Send M8 to STA") | |
6612 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6613 | attrs += build_attr_msg_type(WPS_M8) | |
6614 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6615 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6616 | attrs += build_attr_encr_settings(authkey, keywrapkey, m8_cred) | |
6617 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
6618 | raw_m8_attrs = attrs | |
6619 | m8 = build_eap_wsc(1, eap_id, attrs) | |
6620 | send_wsc_msg(dev[0], bssid, m8) | |
6621 | eap_id = (eap_id + 1) % 256 | |
6622 | ||
6623 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=5) | |
6624 | if ev is None: | |
6625 | raise Exception("wpa_supplicant did not report credential") | |
6626 | ||
6627 | logger.debug("Receive WSC_Done from STA") | |
6628 | msg = get_wsc_msg(dev[0]) | |
6629 | if msg['wsc_opcode'] != WSC_Done or msg['wsc_msg_type'] != WPS_WSC_DONE: | |
6630 | raise Exception("Unexpected Op-Code/MsgType for WSC_Done") | |
6631 | ||
6632 | logger.debug("Send WSC_Done to AP") | |
6633 | hapd.request("SET ext_eapol_frame_io 0") | |
6634 | dev[0].request("SET ext_eapol_frame_io 0") | |
6635 | send_wsc_msg(hapd, addr, wsc_done) | |
6636 | ||
6637 | ev = hapd.wait_event(["WPS-REG-SUCCESS"], timeout=5) | |
6638 | if ev is None: | |
6639 | raise Exception("hostapd did not report WPS success") | |
6640 | ||
6641 | dev[0].wait_connected() | |
6642 | ||
6643 | def wps_start_kwa(dev, apdev): | |
6644 | pin = "12345670" | |
6645 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6646 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6647 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6648 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6649 | ||
6650 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6651 | uuid_r = 16*'\x33' | |
6652 | r_nonce = 16*'\x44' | |
6653 | own_private, e_pk = wsc_dh_init() | |
6654 | ||
6655 | logger.debug("Receive M1 from STA") | |
6656 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6657 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6658 | ||
6659 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6660 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6661 | r_nonce) | |
6662 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6663 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6664 | ||
6665 | logger.debug("Send M2 to STA") | |
6666 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6667 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6668 | r_nonce, uuid_r, e_pk) | |
6669 | send_wsc_msg(dev[0], bssid, m2) | |
6670 | eap_id = (eap_id + 1) % 256 | |
6671 | ||
6672 | logger.debug("Receive M3 from STA") | |
6673 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
6674 | ||
6675 | logger.debug("Send M4 to STA") | |
6676 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6677 | attrs += build_attr_msg_type(WPS_M4) | |
6678 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6679 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
6680 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
6681 | ||
6682 | return r_s1, keywrapkey, authkey, raw_m3_attrs, eap_id, bssid, attrs | |
6683 | ||
6684 | def wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id): | |
6685 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
6686 | m4 = build_eap_wsc(1, eap_id, attrs) | |
6687 | send_wsc_msg(dev[0], bssid, m4) | |
6688 | eap_id = (eap_id + 1) % 256 | |
6689 | ||
6690 | logger.debug("Receive M5 from STA") | |
6691 | msg = get_wsc_msg(dev[0]) | |
6692 | if msg['wsc_opcode'] != WSC_NACK: | |
6693 | raise Exception("Unexpected message - expected WSC_Nack") | |
6694 | ||
6695 | dev[0].request("WPS_CANCEL") | |
6696 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6697 | dev[0].wait_disconnected() | |
6698 | ||
6699 | def test_wps_ext_kwa_proto_no_kwa(dev, apdev): | |
6700 | """WPS and KWA error: No KWA attribute""" | |
6701 | r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) | |
6702 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6703 | # Encrypted Settings without KWA | |
6704 | iv = 16*'\x99' | |
6705 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6706 | pad_len = 16 - len(data) % 16 | |
6707 | ps = pad_len * struct.pack('B', pad_len) | |
6708 | data += ps | |
6709 | wrapped = aes.encrypt(data) | |
6710 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6711 | wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id) | |
6712 | ||
6713 | def test_wps_ext_kwa_proto_data_after_kwa(dev, apdev): | |
6714 | """WPS and KWA error: Data after KWA""" | |
6715 | r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) | |
6716 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6717 | # Encrypted Settings and data after KWA | |
6718 | m = hmac.new(authkey, data, hashlib.sha256) | |
6719 | kwa = m.digest()[0:8] | |
6720 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
6721 | data += build_wsc_attr(ATTR_VENDOR_EXT, "1234567890") | |
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 test_wps_ext_kwa_proto_kwa_mismatch(dev, apdev): | |
6732 | """WPS and KWA error: KWA mismatch""" | |
6733 | r_s1,keywrapkey,authkey,raw_m3_attrs,eap_id,bssid,attrs = wps_start_kwa(dev, apdev) | |
6734 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6735 | # Encrypted Settings and KWA with incorrect value | |
6736 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, 8*'\x00') | |
6737 | iv = 16*'\x99' | |
6738 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
6739 | pad_len = 16 - len(data) % 16 | |
6740 | ps = pad_len * struct.pack('B', pad_len) | |
6741 | data += ps | |
6742 | wrapped = aes.encrypt(data) | |
6743 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
6744 | wps_stop_kwa(dev, bssid, attrs, authkey, raw_m3_attrs, eap_id) | |
6745 | ||
6746 | def wps_run_cred_proto(dev, apdev, m8_cred, connect=False, no_connect=False): | |
6747 | pin = "12345670" | |
6748 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6749 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6750 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6751 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6752 | ||
6753 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6754 | uuid_r = 16*'\x33' | |
6755 | r_nonce = 16*'\x44' | |
6756 | own_private, e_pk = wsc_dh_init() | |
6757 | ||
6758 | logger.debug("Receive M1 from STA") | |
6759 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6760 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6761 | ||
6762 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6763 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6764 | r_nonce) | |
6765 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6766 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6767 | ||
6768 | logger.debug("Send M2 to STA") | |
6769 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6770 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6771 | r_nonce, uuid_r, e_pk) | |
6772 | send_wsc_msg(dev[0], bssid, m2) | |
6773 | eap_id = (eap_id + 1) % 256 | |
6774 | ||
6775 | logger.debug("Receive M3 from STA") | |
6776 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
6777 | ||
6778 | logger.debug("Send M4 to STA") | |
6779 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6780 | attrs += build_attr_msg_type(WPS_M4) | |
6781 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6782 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
6783 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
6784 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
6785 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6786 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
6787 | raw_m4_attrs = attrs | |
6788 | m4 = build_eap_wsc(1, eap_id, attrs) | |
6789 | send_wsc_msg(dev[0], bssid, m4) | |
6790 | eap_id = (eap_id + 1) % 256 | |
6791 | ||
6792 | logger.debug("Receive M5 from STA") | |
6793 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
6794 | ||
6795 | logger.debug("Send M6 to STA") | |
6796 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6797 | attrs += build_attr_msg_type(WPS_M6) | |
6798 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6799 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6800 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
6801 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
6802 | attrs += build_attr_authenticator(authkey, raw_m5_attrs, attrs) | |
6803 | raw_m6_attrs = attrs | |
6804 | m6 = build_eap_wsc(1, eap_id, attrs) | |
6805 | send_wsc_msg(dev[0], bssid, m6) | |
6806 | eap_id = (eap_id + 1) % 256 | |
6807 | ||
6808 | logger.debug("Receive M7 from STA") | |
6809 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M7) | |
6810 | ||
6811 | logger.debug("Send M8 to STA") | |
6812 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
6813 | attrs += build_attr_msg_type(WPS_M8) | |
6814 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, | |
6815 | m1_attrs[ATTR_ENROLLEE_NONCE]) | |
6816 | attrs += build_attr_encr_settings(authkey, keywrapkey, m8_cred) | |
6817 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
6818 | raw_m8_attrs = attrs | |
6819 | m8 = build_eap_wsc(1, eap_id, attrs) | |
6820 | send_wsc_msg(dev[0], bssid, m8) | |
6821 | eap_id = (eap_id + 1) % 256 | |
6822 | ||
6823 | if no_connect: | |
6824 | logger.debug("Receive WSC_Done from STA") | |
6825 | msg = get_wsc_msg(dev[0]) | |
6826 | if msg['wsc_opcode'] != WSC_Done or msg['wsc_msg_type'] != WPS_WSC_DONE: | |
6827 | raise Exception("Unexpected Op-Code/MsgType for WSC_Done") | |
6828 | ||
6829 | hapd.request("SET ext_eapol_frame_io 0") | |
6830 | dev[0].request("SET ext_eapol_frame_io 0") | |
6831 | ||
6832 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6833 | ||
6834 | dev[0].wait_disconnected() | |
6835 | dev[0].request("REMOVE_NETWORK all") | |
6836 | elif connect: | |
6837 | logger.debug("Receive WSC_Done from STA") | |
6838 | msg = get_wsc_msg(dev[0]) | |
6839 | if msg['wsc_opcode'] != WSC_Done or msg['wsc_msg_type'] != WPS_WSC_DONE: | |
6840 | raise Exception("Unexpected Op-Code/MsgType for WSC_Done") | |
6841 | ||
6842 | hapd.request("SET ext_eapol_frame_io 0") | |
6843 | dev[0].request("SET ext_eapol_frame_io 0") | |
6844 | ||
6845 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6846 | ||
6847 | dev[0].wait_connected() | |
6848 | else: | |
6849 | # Verify STA NACK's the credential | |
6850 | msg = get_wsc_msg(dev[0]) | |
6851 | if msg['wsc_opcode'] != WSC_NACK: | |
6852 | raise Exception("Unexpected message - expected WSC_Nack") | |
6853 | dev[0].request("WPS_CANCEL") | |
6854 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6855 | dev[0].wait_disconnected() | |
6856 | ||
6857 | def build_cred(nw_idx='\x01', ssid='test-wps-conf', auth_type='\x00\x20', | |
6858 | encr_type='\x00\x08', nw_key="12345678", | |
6859 | mac_addr='\x00\x00\x00\x00\x00\x00'): | |
6860 | attrs = '' | |
6861 | if nw_idx is not None: | |
6862 | attrs += build_wsc_attr(ATTR_NETWORK_INDEX, nw_idx) | |
6863 | if ssid is not None: | |
6864 | attrs += build_wsc_attr(ATTR_SSID, ssid) | |
6865 | if auth_type is not None: | |
6866 | attrs += build_wsc_attr(ATTR_AUTH_TYPE, auth_type) | |
6867 | if encr_type is not None: | |
6868 | attrs += build_wsc_attr(ATTR_ENCR_TYPE, encr_type) | |
6869 | if nw_key is not None: | |
6870 | attrs += build_wsc_attr(ATTR_NETWORK_KEY, nw_key) | |
6871 | if mac_addr is not None: | |
6872 | attrs += build_wsc_attr(ATTR_MAC_ADDR, mac_addr) | |
6873 | return build_wsc_attr(ATTR_CRED, attrs) | |
6874 | ||
6875 | def test_wps_ext_cred_proto_success(dev, apdev): | |
6876 | """WPS and Credential: success""" | |
6877 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6878 | m8_cred = build_cred(mac_addr=mac_addr) | |
6879 | wps_run_cred_proto(dev, apdev, m8_cred, connect=True) | |
6880 | ||
6881 | def test_wps_ext_cred_proto_mac_addr_mismatch(dev, apdev): | |
6882 | """WPS and Credential: MAC Address mismatch""" | |
6883 | m8_cred = build_cred() | |
6884 | wps_run_cred_proto(dev, apdev, m8_cred, connect=True) | |
6885 | ||
6886 | def test_wps_ext_cred_proto_zero_padding(dev, apdev): | |
6887 | """WPS and Credential: zeropadded attributes""" | |
6888 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6889 | m8_cred = build_cred(mac_addr=mac_addr, ssid='test-wps-conf\x00', | |
6890 | nw_key="12345678\x00") | |
6891 | wps_run_cred_proto(dev, apdev, m8_cred, connect=True) | |
6892 | ||
6893 | def test_wps_ext_cred_proto_ssid_missing(dev, apdev): | |
6894 | """WPS and Credential: SSID missing""" | |
6895 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6896 | m8_cred = build_cred(mac_addr=mac_addr, ssid=None) | |
6897 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6898 | ||
6899 | def test_wps_ext_cred_proto_ssid_zero_len(dev, apdev): | |
6900 | """WPS and Credential: Zero-length SSID""" | |
6901 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6902 | m8_cred = build_cred(mac_addr=mac_addr, ssid="") | |
6903 | wps_run_cred_proto(dev, apdev, m8_cred, no_connect=True) | |
6904 | ||
6905 | def test_wps_ext_cred_proto_auth_type_missing(dev, apdev): | |
6906 | """WPS and Credential: Auth Type missing""" | |
6907 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6908 | m8_cred = build_cred(mac_addr=mac_addr, auth_type=None) | |
6909 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6910 | ||
6911 | def test_wps_ext_cred_proto_encr_type_missing(dev, apdev): | |
6912 | """WPS and Credential: Encr Type missing""" | |
6913 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6914 | m8_cred = build_cred(mac_addr=mac_addr, encr_type=None) | |
6915 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6916 | ||
6917 | def test_wps_ext_cred_proto_network_key_missing(dev, apdev): | |
6918 | """WPS and Credential: Network Key missing""" | |
6919 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6920 | m8_cred = build_cred(mac_addr=mac_addr, nw_key=None) | |
6921 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6922 | ||
6923 | def test_wps_ext_cred_proto_network_key_missing_open(dev, apdev): | |
6924 | """WPS and Credential: Network Key missing (open)""" | |
6925 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6926 | m8_cred = build_cred(mac_addr=mac_addr, auth_type='\x00\x01', | |
6927 | encr_type='\x00\x01', nw_key=None, ssid="foo") | |
6928 | wps_run_cred_proto(dev, apdev, m8_cred, no_connect=True) | |
6929 | ||
6930 | def test_wps_ext_cred_proto_mac_addr_missing(dev, apdev): | |
6931 | """WPS and Credential: MAC Address missing""" | |
6932 | m8_cred = build_cred(mac_addr=None) | |
6933 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6934 | ||
6935 | def test_wps_ext_cred_proto_invalid_encr_type(dev, apdev): | |
6936 | """WPS and Credential: Invalid Encr Type""" | |
6937 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6938 | m8_cred = build_cred(mac_addr=mac_addr, encr_type='\x00\x00') | |
6939 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6940 | ||
6941 | def test_wps_ext_cred_proto_missing_cred(dev, apdev): | |
6942 | """WPS and Credential: Missing Credential""" | |
6943 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6944 | m8_cred = '' | |
6945 | wps_run_cred_proto(dev, apdev, m8_cred) | |
6946 | ||
6947 | def test_wps_ext_proto_m2_no_public_key(dev, apdev): | |
6948 | """WPS and no Public Key in M2""" | |
6949 | pin = "12345670" | |
6950 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6951 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6952 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6953 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6954 | ||
6955 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6956 | uuid_r = 16*'\x33' | |
6957 | r_nonce = 16*'\x44' | |
6958 | own_private, e_pk = wsc_dh_init() | |
6959 | ||
6960 | logger.debug("Receive M1 from STA") | |
6961 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
6962 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
6963 | ||
6964 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
6965 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
6966 | r_nonce) | |
6967 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
6968 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
6969 | ||
6970 | logger.debug("Send M2 to STA") | |
6971 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
6972 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
6973 | r_nonce, uuid_r, None) | |
6974 | send_wsc_msg(dev[0], bssid, m2) | |
6975 | eap_id = (eap_id + 1) % 256 | |
6976 | ||
6977 | # Verify STA NACK's the credential | |
6978 | msg = get_wsc_msg(dev[0]) | |
6979 | if msg['wsc_opcode'] != WSC_NACK: | |
6980 | raise Exception("Unexpected message - expected WSC_Nack") | |
6981 | dev[0].request("WPS_CANCEL") | |
6982 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
6983 | dev[0].wait_disconnected() | |
6984 | ||
6985 | def test_wps_ext_proto_m2_invalid_public_key(dev, apdev): | |
6986 | """WPS and invalid Public Key in M2""" | |
6987 | pin = "12345670" | |
6988 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
6989 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
6990 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
6991 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
6992 | ||
6993 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
6994 | uuid_r = 16*'\x33' | |
6995 | r_nonce = 16*'\x44' | |
6996 | own_private, e_pk = wsc_dh_init() | |
6997 | ||
6998 | logger.debug("Receive M1 from STA") | |
6999 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7000 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7001 | ||
7002 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7003 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7004 | r_nonce) | |
7005 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7006 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7007 | ||
7008 | logger.debug("Send M2 to STA") | |
7009 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7010 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7011 | r_nonce, uuid_r, 192*'\xff') | |
7012 | send_wsc_msg(dev[0], bssid, m2) | |
7013 | eap_id = (eap_id + 1) % 256 | |
7014 | ||
7015 | # Verify STA NACK's the credential | |
7016 | msg = get_wsc_msg(dev[0]) | |
7017 | if msg['wsc_opcode'] != WSC_NACK: | |
7018 | raise Exception("Unexpected message - expected WSC_Nack") | |
7019 | dev[0].request("WPS_CANCEL") | |
7020 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7021 | dev[0].wait_disconnected() | |
7022 | ||
7023 | def test_wps_ext_proto_m2_public_key_oom(dev, apdev): | |
7024 | """WPS and Public Key OOM in M2""" | |
7025 | pin = "12345670" | |
7026 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7027 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7028 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7029 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7030 | ||
7031 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7032 | uuid_r = 16*'\x33' | |
7033 | r_nonce = 16*'\x44' | |
7034 | own_private, e_pk = wsc_dh_init() | |
7035 | ||
7036 | logger.debug("Receive M1 from STA") | |
7037 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7038 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7039 | ||
7040 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7041 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7042 | r_nonce) | |
7043 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7044 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7045 | ||
7046 | logger.debug("Send M2 to STA") | |
7047 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7048 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7049 | r_nonce, uuid_r, e_pk) | |
7050 | with alloc_fail(dev[0], 1, "wpabuf_alloc_copy;wps_process_pubkey"): | |
7051 | send_wsc_msg(dev[0], bssid, m2) | |
7052 | eap_id = (eap_id + 1) % 256 | |
7053 | ||
7054 | # Verify STA NACK's the credential | |
7055 | msg = get_wsc_msg(dev[0]) | |
7056 | if msg['wsc_opcode'] != WSC_NACK: | |
7057 | raise Exception("Unexpected message - expected WSC_Nack") | |
7058 | dev[0].request("WPS_CANCEL") | |
7059 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7060 | dev[0].wait_disconnected() | |
7061 | ||
7062 | def test_wps_ext_proto_nack_m3(dev, apdev): | |
7063 | """WPS and NACK M3""" | |
7064 | pin = "12345670" | |
7065 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7066 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7067 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7068 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7069 | ||
7070 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7071 | uuid_r = 16*'\x33' | |
7072 | r_nonce = 16*'\x44' | |
7073 | own_private, e_pk = wsc_dh_init() | |
7074 | ||
7075 | logger.debug("Receive M1 from STA") | |
7076 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7077 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7078 | ||
7079 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7080 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7081 | r_nonce) | |
7082 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7083 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7084 | ||
7085 | logger.debug("Send M2 to STA") | |
7086 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7087 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7088 | r_nonce, uuid_r, e_pk) | |
7089 | send_wsc_msg(dev[0], bssid, m2) | |
7090 | eap_id = (eap_id + 1) % 256 | |
7091 | ||
7092 | logger.debug("Receive M3 from STA") | |
7093 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7094 | ||
7095 | logger.debug("Send NACK to STA") | |
7096 | msg, attrs = build_nack(eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7097 | r_nonce, config_error='\x01\x23') | |
7098 | send_wsc_msg(dev[0], bssid, msg) | |
7099 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=5) | |
7100 | if ev is None: | |
7101 | raise Exception("Failure not reported") | |
7102 | if "msg=7 config_error=291" not in ev: | |
7103 | raise Exception("Unexpected failure reason: " + ev) | |
7104 | ||
7105 | def test_wps_ext_proto_nack_m5(dev, apdev): | |
7106 | """WPS and NACK M5""" | |
7107 | pin = "12345670" | |
7108 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7109 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7110 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7111 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7112 | ||
7113 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7114 | uuid_r = 16*'\x33' | |
7115 | r_nonce = 16*'\x44' | |
7116 | own_private, e_pk = wsc_dh_init() | |
7117 | ||
7118 | logger.debug("Receive M1 from STA") | |
7119 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7120 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7121 | ||
7122 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7123 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7124 | r_nonce) | |
7125 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7126 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7127 | ||
7128 | logger.debug("Send M2 to STA") | |
7129 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7130 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7131 | r_nonce, uuid_r, e_pk) | |
7132 | send_wsc_msg(dev[0], bssid, m2) | |
7133 | eap_id = (eap_id + 1) % 256 | |
7134 | ||
7135 | logger.debug("Receive M3 from STA") | |
7136 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7137 | ||
7138 | logger.debug("Send M4 to STA") | |
7139 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7140 | attrs += build_attr_msg_type(WPS_M4) | |
7141 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
7142 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7143 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7144 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7145 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7146 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
7147 | raw_m4_attrs = attrs | |
7148 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7149 | send_wsc_msg(dev[0], bssid, m4) | |
7150 | eap_id = (eap_id + 1) % 256 | |
7151 | ||
7152 | logger.debug("Receive M5 from STA") | |
7153 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
7154 | ||
7155 | logger.debug("Send NACK to STA") | |
7156 | msg, attrs = build_nack(eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7157 | r_nonce, config_error='\x01\x24') | |
7158 | send_wsc_msg(dev[0], bssid, msg) | |
7159 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=5) | |
7160 | if ev is None: | |
7161 | raise Exception("Failure not reported") | |
7162 | if "msg=9 config_error=292" not in ev: | |
7163 | raise Exception("Unexpected failure reason: " + ev) | |
7164 | ||
7165 | def wps_nack_m3(dev, apdev): | |
7166 | pin = "00000000" | |
7167 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pbc=True) | |
7168 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7169 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7170 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7171 | ||
7172 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7173 | uuid_r = 16*'\x33' | |
7174 | r_nonce = 16*'\x44' | |
7175 | own_private, e_pk = wsc_dh_init() | |
7176 | ||
7177 | logger.debug("Receive M1 from STA") | |
7178 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7179 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7180 | ||
7181 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7182 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7183 | r_nonce) | |
7184 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7185 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7186 | ||
7187 | logger.debug("Send M2 to STA") | |
7188 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7189 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7190 | r_nonce, uuid_r, e_pk, dev_pw_id='\x00\x04') | |
7191 | send_wsc_msg(dev[0], bssid, m2) | |
7192 | eap_id = (eap_id + 1) % 256 | |
7193 | ||
7194 | logger.debug("Receive M3 from STA") | |
7195 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7196 | return eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], r_nonce, bssid | |
7197 | ||
7198 | def test_wps_ext_proto_nack_m3_no_config_error(dev, apdev): | |
7199 | """WPS and NACK M3 missing Config Error""" | |
7200 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7201 | logger.debug("Send NACK to STA") | |
7202 | msg, attrs = build_nack(eap_id, e_nonce, r_nonce, config_error=None) | |
7203 | send_wsc_msg(dev[0], bssid, msg) | |
7204 | dev[0].request("WPS_CANCEL") | |
7205 | dev[0].wait_disconnected() | |
7206 | dev[0].flush_scan_cache() | |
7207 | ||
7208 | def test_wps_ext_proto_nack_m3_no_e_nonce(dev, apdev): | |
7209 | """WPS and NACK M3 missing E-Nonce""" | |
7210 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7211 | logger.debug("Send NACK to STA") | |
7212 | msg, attrs = build_nack(eap_id, None, r_nonce) | |
7213 | send_wsc_msg(dev[0], bssid, msg) | |
7214 | dev[0].request("WPS_CANCEL") | |
7215 | dev[0].wait_disconnected() | |
7216 | dev[0].flush_scan_cache() | |
7217 | ||
7218 | def test_wps_ext_proto_nack_m3_e_nonce_mismatch(dev, apdev): | |
7219 | """WPS and NACK M3 E-Nonce mismatch""" | |
7220 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7221 | logger.debug("Send NACK to STA") | |
7222 | msg, attrs = build_nack(eap_id, 16*'\x00', r_nonce) | |
7223 | send_wsc_msg(dev[0], bssid, msg) | |
7224 | dev[0].request("WPS_CANCEL") | |
7225 | dev[0].wait_disconnected() | |
7226 | dev[0].flush_scan_cache() | |
7227 | ||
7228 | def test_wps_ext_proto_nack_m3_no_r_nonce(dev, apdev): | |
7229 | """WPS and NACK M3 missing R-Nonce""" | |
7230 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7231 | logger.debug("Send NACK to STA") | |
7232 | msg, attrs = build_nack(eap_id, e_nonce, None) | |
7233 | send_wsc_msg(dev[0], bssid, msg) | |
7234 | dev[0].request("WPS_CANCEL") | |
7235 | dev[0].wait_disconnected() | |
7236 | dev[0].flush_scan_cache() | |
7237 | ||
7238 | def test_wps_ext_proto_nack_m3_r_nonce_mismatch(dev, apdev): | |
7239 | """WPS and NACK M3 R-Nonce mismatch""" | |
7240 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7241 | logger.debug("Send NACK to STA") | |
7242 | msg, attrs = build_nack(eap_id, e_nonce, 16*'\x00') | |
7243 | send_wsc_msg(dev[0], bssid, msg) | |
7244 | dev[0].request("WPS_CANCEL") | |
7245 | dev[0].wait_disconnected() | |
7246 | dev[0].flush_scan_cache() | |
7247 | ||
7248 | def test_wps_ext_proto_nack_m3_no_msg_type(dev, apdev): | |
7249 | """WPS and NACK M3 no Message Type""" | |
7250 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7251 | logger.debug("Send NACK to STA") | |
7252 | msg, attrs = build_nack(eap_id, e_nonce, r_nonce, msg_type=None) | |
7253 | send_wsc_msg(dev[0], bssid, msg) | |
7254 | dev[0].request("WPS_CANCEL") | |
7255 | dev[0].wait_disconnected() | |
7256 | dev[0].flush_scan_cache() | |
7257 | ||
7258 | def test_wps_ext_proto_nack_m3_invalid_msg_type(dev, apdev): | |
7259 | """WPS and NACK M3 invalid Message Type""" | |
7260 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7261 | logger.debug("Send NACK to STA") | |
7262 | msg, attrs = build_nack(eap_id, e_nonce, r_nonce, msg_type=123) | |
7263 | send_wsc_msg(dev[0], bssid, msg) | |
7264 | dev[0].request("WPS_CANCEL") | |
7265 | dev[0].wait_disconnected() | |
7266 | dev[0].flush_scan_cache() | |
7267 | ||
7268 | def test_wps_ext_proto_nack_m3_invalid_attr(dev, apdev): | |
7269 | """WPS and NACK M3 invalid attribute""" | |
7270 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7271 | logger.debug("Send NACK to STA") | |
7272 | attrs = '\x10\x10\x00' | |
7273 | msg = build_eap_wsc(1, eap_id, attrs, opcode=WSC_NACK) | |
7274 | send_wsc_msg(dev[0], bssid, msg) | |
7275 | dev[0].request("WPS_CANCEL") | |
7276 | dev[0].wait_disconnected() | |
7277 | dev[0].flush_scan_cache() | |
7278 | ||
7279 | def test_wps_ext_proto_ack_m3_no_e_nonce(dev, apdev): | |
7280 | """WPS and ACK M3 missing E-Nonce""" | |
7281 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7282 | logger.debug("Send NACK to STA") | |
7283 | msg, attrs = build_ack(eap_id, None, r_nonce) | |
7284 | send_wsc_msg(dev[0], bssid, msg) | |
7285 | dev[0].request("WPS_CANCEL") | |
7286 | dev[0].wait_disconnected() | |
7287 | dev[0].flush_scan_cache() | |
7288 | ||
7289 | def test_wps_ext_proto_ack_m3_e_nonce_mismatch(dev, apdev): | |
7290 | """WPS and ACK M3 E-Nonce mismatch""" | |
7291 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7292 | logger.debug("Send NACK to STA") | |
7293 | msg, attrs = build_ack(eap_id, 16*'\x00', r_nonce) | |
7294 | send_wsc_msg(dev[0], bssid, msg) | |
7295 | dev[0].request("WPS_CANCEL") | |
7296 | dev[0].wait_disconnected() | |
7297 | dev[0].flush_scan_cache() | |
7298 | ||
7299 | def test_wps_ext_proto_ack_m3_no_r_nonce(dev, apdev): | |
7300 | """WPS and ACK M3 missing R-Nonce""" | |
7301 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7302 | logger.debug("Send NACK to STA") | |
7303 | msg, attrs = build_ack(eap_id, e_nonce, None) | |
7304 | send_wsc_msg(dev[0], bssid, msg) | |
7305 | dev[0].request("WPS_CANCEL") | |
7306 | dev[0].wait_disconnected() | |
7307 | dev[0].flush_scan_cache() | |
7308 | ||
7309 | def test_wps_ext_proto_ack_m3_r_nonce_mismatch(dev, apdev): | |
7310 | """WPS and ACK M3 R-Nonce mismatch""" | |
7311 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7312 | logger.debug("Send NACK to STA") | |
7313 | msg, attrs = build_ack(eap_id, e_nonce, 16*'\x00') | |
7314 | send_wsc_msg(dev[0], bssid, msg) | |
7315 | dev[0].request("WPS_CANCEL") | |
7316 | dev[0].wait_disconnected() | |
7317 | dev[0].flush_scan_cache() | |
7318 | ||
7319 | def test_wps_ext_proto_ack_m3_no_msg_type(dev, apdev): | |
7320 | """WPS and ACK M3 no Message Type""" | |
7321 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7322 | logger.debug("Send NACK to STA") | |
7323 | msg, attrs = build_ack(eap_id, e_nonce, r_nonce, msg_type=None) | |
7324 | send_wsc_msg(dev[0], bssid, msg) | |
7325 | dev[0].request("WPS_CANCEL") | |
7326 | dev[0].wait_disconnected() | |
7327 | dev[0].flush_scan_cache() | |
7328 | ||
7329 | def test_wps_ext_proto_ack_m3_invalid_msg_type(dev, apdev): | |
7330 | """WPS and ACK M3 invalid Message Type""" | |
7331 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7332 | logger.debug("Send NACK to STA") | |
7333 | msg, attrs = build_ack(eap_id, e_nonce, r_nonce, msg_type=123) | |
7334 | send_wsc_msg(dev[0], bssid, msg) | |
7335 | dev[0].request("WPS_CANCEL") | |
7336 | dev[0].wait_disconnected() | |
7337 | dev[0].flush_scan_cache() | |
7338 | ||
7339 | def test_wps_ext_proto_ack_m3_invalid_attr(dev, apdev): | |
7340 | """WPS and ACK M3 invalid attribute""" | |
7341 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7342 | logger.debug("Send ACK to STA") | |
7343 | attrs = '\x10\x10\x00' | |
7344 | msg = build_eap_wsc(1, eap_id, attrs, opcode=WSC_ACK) | |
7345 | send_wsc_msg(dev[0], bssid, msg) | |
7346 | dev[0].request("WPS_CANCEL") | |
7347 | dev[0].wait_disconnected() | |
7348 | dev[0].flush_scan_cache() | |
7349 | ||
7350 | def test_wps_ext_proto_ack_m3(dev, apdev): | |
7351 | """WPS and ACK M3""" | |
7352 | eap_id, e_nonce, r_nonce, bssid = wps_nack_m3(dev, apdev) | |
7353 | logger.debug("Send ACK to STA") | |
7354 | msg, attrs = build_ack(eap_id, e_nonce, r_nonce) | |
7355 | send_wsc_msg(dev[0], bssid, msg) | |
7356 | dev[0].request("WPS_CANCEL") | |
7357 | dev[0].wait_disconnected() | |
7358 | dev[0].flush_scan_cache() | |
7359 | ||
7360 | def wps_to_m3_helper(dev, apdev): | |
7361 | pin = "12345670" | |
7362 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7363 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7364 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7365 | wps_ext_eap_wsc(dev[0], hapd, bssid, "EAP-WSC/Start") | |
7366 | ||
7367 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7368 | uuid_r = 16*'\x33' | |
7369 | r_nonce = 16*'\x44' | |
7370 | own_private, e_pk = wsc_dh_init() | |
7371 | ||
7372 | logger.debug("Receive M1 from STA") | |
7373 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M1) | |
7374 | eap_id = (msg['eap_identifier'] + 1) % 256 | |
7375 | ||
7376 | authkey,keywrapkey = wsc_dh_kdf(m1_attrs[ATTR_PUBLIC_KEY], own_private, | |
7377 | mac_addr, m1_attrs[ATTR_ENROLLEE_NONCE], | |
7378 | r_nonce) | |
7379 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, pin, | |
7380 | m1_attrs[ATTR_PUBLIC_KEY], e_pk) | |
7381 | ||
7382 | logger.debug("Send M2 to STA") | |
7383 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, eap_id, | |
7384 | m1_attrs[ATTR_ENROLLEE_NONCE], | |
7385 | r_nonce, uuid_r, e_pk) | |
7386 | send_wsc_msg(dev[0], bssid, m2) | |
7387 | eap_id = (eap_id + 1) % 256 | |
7388 | ||
7389 | logger.debug("Receive M3 from STA") | |
7390 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M3) | |
7391 | return eap_id, m1_attrs, r_nonce, bssid, r_hash1, r_hash2, r_s1, r_s2, raw_m3_attrs, authkey, keywrapkey | |
7392 | ||
7393 | def wps_to_m3(dev, apdev): | |
7394 | 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) | |
7395 | return eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], r_nonce, bssid, r_hash1, r_hash2, r_s1, raw_m3_attrs, authkey, keywrapkey | |
7396 | ||
7397 | def wps_to_m5(dev, apdev): | |
7398 | 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) | |
7399 | ||
7400 | logger.debug("Send M4 to STA") | |
7401 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7402 | attrs += build_attr_msg_type(WPS_M4) | |
7403 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, m1_attrs[ATTR_ENROLLEE_NONCE]) | |
7404 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7405 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7406 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7407 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7408 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
7409 | raw_m4_attrs = attrs | |
7410 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7411 | send_wsc_msg(dev[0], bssid, m4) | |
7412 | eap_id = (eap_id + 1) % 256 | |
7413 | ||
7414 | logger.debug("Receive M5 from STA") | |
7415 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M5) | |
7416 | ||
7417 | return eap_id, m1_attrs[ATTR_ENROLLEE_NONCE], r_nonce, bssid, r_hash1, r_hash2, r_s2, raw_m5_attrs, authkey, keywrapkey | |
7418 | ||
7419 | def test_wps_ext_proto_m4_missing_r_hash1(dev, apdev): | |
7420 | """WPS and no R-Hash1 in M4""" | |
7421 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7422 | ||
7423 | logger.debug("Send M4 to STA") | |
7424 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7425 | attrs += build_attr_msg_type(WPS_M4) | |
7426 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7427 | #attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7428 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7429 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7430 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7431 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7432 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7433 | send_wsc_msg(dev[0], bssid, m4) | |
7434 | eap_id = (eap_id + 1) % 256 | |
7435 | ||
7436 | logger.debug("Receive M5 (NACK) from STA") | |
7437 | msg = get_wsc_msg(dev[0]) | |
7438 | if msg['wsc_opcode'] != WSC_NACK: | |
7439 | raise Exception("Unexpected message - expected WSC_Nack") | |
7440 | ||
7441 | dev[0].request("WPS_CANCEL") | |
7442 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7443 | dev[0].wait_disconnected() | |
7444 | ||
7445 | def test_wps_ext_proto_m4_missing_r_hash2(dev, apdev): | |
7446 | """WPS and no R-Hash2 in M4""" | |
7447 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7448 | ||
7449 | logger.debug("Send M4 to STA") | |
7450 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7451 | attrs += build_attr_msg_type(WPS_M4) | |
7452 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7453 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7454 | #attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7455 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7456 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7457 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7458 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7459 | send_wsc_msg(dev[0], bssid, m4) | |
7460 | eap_id = (eap_id + 1) % 256 | |
7461 | ||
7462 | logger.debug("Receive M5 (NACK) from STA") | |
7463 | msg = get_wsc_msg(dev[0]) | |
7464 | if msg['wsc_opcode'] != WSC_NACK: | |
7465 | raise Exception("Unexpected message - expected WSC_Nack") | |
7466 | ||
7467 | dev[0].request("WPS_CANCEL") | |
7468 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7469 | dev[0].wait_disconnected() | |
7470 | ||
7471 | def test_wps_ext_proto_m4_missing_r_snonce1(dev, apdev): | |
7472 | """WPS and no R-SNonce1 in M4""" | |
7473 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7474 | ||
7475 | logger.debug("Send M4 to STA") | |
7476 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7477 | attrs += build_attr_msg_type(WPS_M4) | |
7478 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7479 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7480 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7481 | #data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7482 | data = '' | |
7483 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7484 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7485 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7486 | send_wsc_msg(dev[0], bssid, m4) | |
7487 | eap_id = (eap_id + 1) % 256 | |
7488 | ||
7489 | logger.debug("Receive M5 (NACK) from STA") | |
7490 | msg = get_wsc_msg(dev[0]) | |
7491 | if msg['wsc_opcode'] != WSC_NACK: | |
7492 | raise Exception("Unexpected message - expected WSC_Nack") | |
7493 | ||
7494 | dev[0].request("WPS_CANCEL") | |
7495 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7496 | dev[0].wait_disconnected() | |
7497 | ||
7498 | def test_wps_ext_proto_m4_invalid_pad_string(dev, apdev): | |
7499 | """WPS and invalid pad string in M4""" | |
7500 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7501 | ||
7502 | logger.debug("Send M4 to STA") | |
7503 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7504 | attrs += build_attr_msg_type(WPS_M4) | |
7505 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7506 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7507 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7508 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7509 | ||
7510 | m = hmac.new(authkey, data, hashlib.sha256) | |
7511 | kwa = m.digest()[0:8] | |
7512 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
7513 | iv = 16*'\x99' | |
7514 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
7515 | pad_len = 16 - len(data) % 16 | |
7516 | ps = (pad_len - 1) * struct.pack('B', pad_len) + struct.pack('B', pad_len - 1) | |
7517 | data += ps | |
7518 | wrapped = aes.encrypt(data) | |
7519 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
7520 | ||
7521 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7522 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7523 | send_wsc_msg(dev[0], bssid, m4) | |
7524 | eap_id = (eap_id + 1) % 256 | |
7525 | ||
7526 | logger.debug("Receive M5 (NACK) from STA") | |
7527 | msg = get_wsc_msg(dev[0]) | |
7528 | if msg['wsc_opcode'] != WSC_NACK: | |
7529 | raise Exception("Unexpected message - expected WSC_Nack") | |
7530 | ||
7531 | dev[0].request("WPS_CANCEL") | |
7532 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7533 | dev[0].wait_disconnected() | |
7534 | ||
7535 | def test_wps_ext_proto_m4_invalid_pad_value(dev, apdev): | |
7536 | """WPS and invalid pad value in M4""" | |
7537 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7538 | ||
7539 | logger.debug("Send M4 to STA") | |
7540 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7541 | attrs += build_attr_msg_type(WPS_M4) | |
7542 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7543 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7544 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7545 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7546 | ||
7547 | m = hmac.new(authkey, data, hashlib.sha256) | |
7548 | kwa = m.digest()[0:8] | |
7549 | data += build_wsc_attr(ATTR_KEY_WRAP_AUTH, kwa) | |
7550 | iv = 16*'\x99' | |
7551 | aes = AES.new(keywrapkey, AES.MODE_CBC, iv) | |
7552 | pad_len = 16 - len(data) % 16 | |
7553 | ps = (pad_len - 1) * struct.pack('B', pad_len) + struct.pack('B', 255) | |
7554 | data += ps | |
7555 | wrapped = aes.encrypt(data) | |
7556 | attrs += build_wsc_attr(ATTR_ENCR_SETTINGS, iv + wrapped) | |
7557 | ||
7558 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7559 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7560 | send_wsc_msg(dev[0], bssid, m4) | |
7561 | eap_id = (eap_id + 1) % 256 | |
7562 | ||
7563 | logger.debug("Receive M5 (NACK) from STA") | |
7564 | msg = get_wsc_msg(dev[0]) | |
7565 | if msg['wsc_opcode'] != WSC_NACK: | |
7566 | raise Exception("Unexpected message - expected WSC_Nack") | |
7567 | ||
7568 | dev[0].request("WPS_CANCEL") | |
7569 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7570 | dev[0].wait_disconnected() | |
7571 | ||
7572 | def test_wps_ext_proto_m4_no_encr_settings(dev, apdev): | |
7573 | """WPS and no Encr Settings in M4""" | |
7574 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s1, m3, authkey, keywrapkey = wps_to_m3(dev, apdev) | |
7575 | ||
7576 | logger.debug("Send M4 to STA") | |
7577 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7578 | attrs += build_attr_msg_type(WPS_M4) | |
7579 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7580 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7581 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7582 | attrs += build_attr_authenticator(authkey, m3, attrs) | |
7583 | m4 = build_eap_wsc(1, eap_id, attrs) | |
7584 | send_wsc_msg(dev[0], bssid, m4) | |
7585 | eap_id = (eap_id + 1) % 256 | |
7586 | ||
7587 | logger.debug("Receive M5 (NACK) from STA") | |
7588 | msg = get_wsc_msg(dev[0]) | |
7589 | if msg['wsc_opcode'] != WSC_NACK: | |
7590 | raise Exception("Unexpected message - expected WSC_Nack") | |
7591 | ||
7592 | dev[0].request("WPS_CANCEL") | |
7593 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7594 | dev[0].wait_disconnected() | |
7595 | ||
7596 | def test_wps_ext_proto_m6_missing_r_snonce2(dev, apdev): | |
7597 | """WPS and no R-SNonce2 in M6""" | |
7598 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s2, m5, authkey, keywrapkey = wps_to_m5(dev, apdev) | |
7599 | ||
7600 | logger.debug("Send M6 to STA") | |
7601 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7602 | attrs += build_attr_msg_type(WPS_M6) | |
7603 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7604 | #data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7605 | data = '' | |
7606 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7607 | attrs += build_attr_authenticator(authkey, m5, attrs) | |
7608 | m6 = build_eap_wsc(1, eap_id, attrs) | |
7609 | send_wsc_msg(dev[0], bssid, m6) | |
7610 | eap_id = (eap_id + 1) % 256 | |
7611 | ||
7612 | logger.debug("Receive M7 (NACK) from STA") | |
7613 | msg = get_wsc_msg(dev[0]) | |
7614 | if msg['wsc_opcode'] != WSC_NACK: | |
7615 | raise Exception("Unexpected message - expected WSC_Nack") | |
7616 | ||
7617 | dev[0].request("WPS_CANCEL") | |
7618 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7619 | dev[0].wait_disconnected() | |
7620 | ||
7621 | def test_wps_ext_proto_m6_no_encr_settings(dev, apdev): | |
7622 | """WPS and no Encr Settings in M6""" | |
7623 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s2, m5, authkey, keywrapkey = wps_to_m5(dev, apdev) | |
7624 | ||
7625 | logger.debug("Send M6 to STA") | |
7626 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7627 | attrs += build_attr_msg_type(WPS_M6) | |
7628 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7629 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7630 | #attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7631 | attrs += build_attr_authenticator(authkey, m5, attrs) | |
7632 | m6 = build_eap_wsc(1, eap_id, attrs) | |
7633 | send_wsc_msg(dev[0], bssid, m6) | |
7634 | eap_id = (eap_id + 1) % 256 | |
7635 | ||
7636 | logger.debug("Receive M7 (NACK) from STA") | |
7637 | msg = get_wsc_msg(dev[0]) | |
7638 | if msg['wsc_opcode'] != WSC_NACK: | |
7639 | raise Exception("Unexpected message - expected WSC_Nack") | |
7640 | ||
7641 | dev[0].request("WPS_CANCEL") | |
7642 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7643 | dev[0].wait_disconnected() | |
7644 | ||
7645 | def test_wps_ext_proto_m8_no_encr_settings(dev, apdev): | |
7646 | """WPS and no Encr Settings in M6""" | |
7647 | eap_id, e_nonce, r_nonce, bssid, r_hash1, r_hash2, r_s2, m5, authkey, keywrapkey = wps_to_m5(dev, apdev) | |
7648 | ||
7649 | logger.debug("Send M6 to STA") | |
7650 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7651 | attrs += build_attr_msg_type(WPS_M6) | |
7652 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7653 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7654 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7655 | attrs += build_attr_authenticator(authkey, m5, attrs) | |
7656 | raw_m6_attrs = attrs | |
7657 | m6 = build_eap_wsc(1, eap_id, attrs) | |
7658 | send_wsc_msg(dev[0], bssid, m6) | |
7659 | eap_id = (eap_id + 1) % 256 | |
7660 | ||
7661 | logger.debug("Receive M7 from STA") | |
7662 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(dev[0], WSC_MSG, WPS_M7) | |
7663 | ||
7664 | logger.debug("Send M8 to STA") | |
7665 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7666 | attrs += build_attr_msg_type(WPS_M8) | |
7667 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7668 | #attrs += build_attr_encr_settings(authkey, keywrapkey, m8_cred) | |
7669 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
7670 | raw_m8_attrs = attrs | |
7671 | m8 = build_eap_wsc(1, eap_id, attrs) | |
7672 | send_wsc_msg(dev[0], bssid, m8) | |
7673 | ||
7674 | logger.debug("Receive WSC_Done (NACK) from STA") | |
7675 | msg = get_wsc_msg(dev[0]) | |
7676 | if msg['wsc_opcode'] != WSC_NACK: | |
7677 | raise Exception("Unexpected message - expected WSC_Nack") | |
7678 | ||
7679 | dev[0].request("WPS_CANCEL") | |
7680 | send_wsc_msg(dev[0], bssid, build_eap_failure(eap_id)) | |
7681 | dev[0].wait_disconnected() | |
7682 | ||
7683 | def wps_start_ext_reg(apdev, dev): | |
7684 | addr = dev.own_addr() | |
7685 | bssid = apdev['bssid'] | |
7686 | ssid = "test-wps-conf" | |
7687 | appin = "12345670" | |
7688 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
7689 | "wpa_passphrase": "12345678", "wpa": "2", | |
7690 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
7691 | "ap_pin": appin } | |
afc26df2 | 7692 | hapd = hostapd.add_ap(apdev, params) |
7511ead0 JM |
7693 | |
7694 | dev.scan_for_bss(bssid, freq="2412") | |
7695 | hapd.request("SET ext_eapol_frame_io 1") | |
7696 | dev.request("SET ext_eapol_frame_io 1") | |
7697 | ||
7698 | dev.request("WPS_REG " + bssid + " " + appin) | |
7699 | ||
7700 | return addr,bssid,hapd | |
7701 | ||
7702 | def wps_run_ap_settings_proto(dev, apdev, ap_settings, success): | |
7703 | addr,bssid,hapd = wps_start_ext_reg(apdev[0], dev[0]) | |
7704 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7705 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7706 | ||
7707 | logger.debug("Receive M1 from AP") | |
7708 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M1) | |
7709 | mac_addr = m1_attrs[ATTR_MAC_ADDR] | |
7710 | e_nonce = m1_attrs[ATTR_ENROLLEE_NONCE] | |
7711 | e_pk = m1_attrs[ATTR_PUBLIC_KEY] | |
7712 | ||
7713 | appin = '12345670' | |
7714 | uuid_r = 16*'\x33' | |
7715 | r_nonce = 16*'\x44' | |
7716 | own_private, r_pk = wsc_dh_init() | |
7717 | authkey,keywrapkey = wsc_dh_kdf(e_pk, own_private, mac_addr, e_nonce, | |
7718 | r_nonce) | |
7719 | r_s1,r_s2,r_hash1,r_hash2 = wsc_dev_pw_hash(authkey, appin, e_pk, r_pk) | |
7720 | ||
7721 | logger.debug("Send M2 to AP") | |
7722 | m2, raw_m2_attrs = build_m2(authkey, raw_m1_attrs, msg['eap_identifier'], | |
7723 | e_nonce, r_nonce, uuid_r, r_pk, eap_code=2) | |
7724 | send_wsc_msg(hapd, addr, m2) | |
7725 | ||
7726 | logger.debug("Receive M3 from AP") | |
7727 | msg, m3_attrs, raw_m3_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M3) | |
7728 | ||
7729 | logger.debug("Send M4 to AP") | |
7730 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7731 | attrs += build_attr_msg_type(WPS_M4) | |
7732 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7733 | attrs += build_wsc_attr(ATTR_R_HASH1, r_hash1) | |
7734 | attrs += build_wsc_attr(ATTR_R_HASH2, r_hash2) | |
7735 | data = build_wsc_attr(ATTR_R_SNONCE1, r_s1) | |
7736 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7737 | attrs += build_attr_authenticator(authkey, raw_m3_attrs, attrs) | |
7738 | raw_m4_attrs = attrs | |
7739 | m4 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7740 | send_wsc_msg(hapd, addr, m4) | |
7741 | ||
7742 | logger.debug("Receive M5 from AP") | |
7743 | msg, m5_attrs, raw_m5_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M5) | |
7744 | ||
7745 | logger.debug("Send M6 to STA") | |
7746 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7747 | attrs += build_attr_msg_type(WPS_M6) | |
7748 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7749 | data = build_wsc_attr(ATTR_R_SNONCE2, r_s2) | |
7750 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
7751 | attrs += build_attr_authenticator(authkey, raw_m5_attrs, attrs) | |
7752 | raw_m6_attrs = attrs | |
7753 | m6 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7754 | send_wsc_msg(hapd, addr, m6) | |
7755 | ||
7756 | logger.debug("Receive M7 from AP") | |
7757 | msg, m7_attrs, raw_m7_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M7) | |
7758 | ||
7759 | logger.debug("Send M8 to STA") | |
7760 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7761 | attrs += build_attr_msg_type(WPS_M8) | |
7762 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
7763 | if ap_settings: | |
7764 | attrs += build_attr_encr_settings(authkey, keywrapkey, ap_settings) | |
7765 | attrs += build_attr_authenticator(authkey, raw_m7_attrs, attrs) | |
7766 | raw_m8_attrs = attrs | |
7767 | m8 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7768 | send_wsc_msg(hapd, addr, m8) | |
7769 | ||
7770 | if success: | |
7771 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5) | |
7772 | if ev is None: | |
7773 | raise Exception("New AP settings not reported") | |
7774 | logger.debug("Receive WSC_Done from AP") | |
7775 | msg = get_wsc_msg(hapd) | |
7776 | if msg['wsc_opcode'] != WSC_Done: | |
7777 | raise Exception("Unexpected message - expected WSC_Done") | |
7778 | ||
7779 | logger.debug("Send WSC_ACK to AP") | |
7780 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, | |
7781 | eap_code=2) | |
7782 | send_wsc_msg(hapd, addr, ack) | |
7783 | dev[0].wait_disconnected() | |
7784 | else: | |
7785 | ev = hapd.wait_event(["WPS-FAIL"], timeout=5) | |
7786 | if ev is None: | |
7787 | raise Exception("WPS failure not reported") | |
7788 | logger.debug("Receive WSC_NACK from AP") | |
7789 | msg = get_wsc_msg(hapd) | |
7790 | if msg['wsc_opcode'] != WSC_NACK: | |
7791 | raise Exception("Unexpected message - expected WSC_NACK") | |
7792 | ||
7793 | logger.debug("Send WSC_NACK to AP") | |
7794 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
7795 | eap_code=2) | |
7796 | send_wsc_msg(hapd, addr, nack) | |
7797 | dev[0].wait_disconnected() | |
7798 | ||
7799 | def test_wps_ext_ap_settings_success(dev, apdev): | |
7800 | """WPS and AP Settings: success""" | |
7801 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7802 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7803 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7804 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
7805 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7806 | ap_settings += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[0]['bssid'].replace(':', ''))) | |
7807 | wps_run_ap_settings_proto(dev, apdev, ap_settings, True) | |
7808 | ||
9fd6804d | 7809 | @remote_compatible |
7511ead0 JM |
7810 | def test_wps_ext_ap_settings_missing(dev, apdev): |
7811 | """WPS and AP Settings: missing""" | |
7812 | wps_run_ap_settings_proto(dev, apdev, None, False) | |
7813 | ||
9fd6804d | 7814 | @remote_compatible |
7511ead0 JM |
7815 | def test_wps_ext_ap_settings_mac_addr_mismatch(dev, apdev): |
7816 | """WPS and AP Settings: MAC Address mismatch""" | |
7817 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7818 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7819 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7820 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
7821 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7822 | ap_settings += build_wsc_attr(ATTR_MAC_ADDR, '\x00\x00\x00\x00\x00\x00') | |
7823 | wps_run_ap_settings_proto(dev, apdev, ap_settings, True) | |
7824 | ||
9fd6804d | 7825 | @remote_compatible |
7511ead0 JM |
7826 | def test_wps_ext_ap_settings_mac_addr_missing(dev, apdev): |
7827 | """WPS and AP Settings: missing MAC Address""" | |
7828 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7829 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7830 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7831 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x01') | |
7832 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7833 | wps_run_ap_settings_proto(dev, apdev, ap_settings, False) | |
7834 | ||
9fd6804d | 7835 | @remote_compatible |
7511ead0 JM |
7836 | def test_wps_ext_ap_settings_reject_encr_type(dev, apdev): |
7837 | """WPS and AP Settings: reject Encr Type""" | |
7838 | ap_settings = build_wsc_attr(ATTR_NETWORK_INDEX, '\x01') | |
7839 | ap_settings += build_wsc_attr(ATTR_SSID, "test") | |
7840 | ap_settings += build_wsc_attr(ATTR_AUTH_TYPE, '\x00\x01') | |
7841 | ap_settings += build_wsc_attr(ATTR_ENCR_TYPE, '\x00\x00') | |
7842 | ap_settings += build_wsc_attr(ATTR_NETWORK_KEY, '') | |
7843 | ap_settings += build_wsc_attr(ATTR_MAC_ADDR, binascii.unhexlify(apdev[0]['bssid'].replace(':', ''))) | |
7844 | wps_run_ap_settings_proto(dev, apdev, ap_settings, False) | |
7845 | ||
9fd6804d | 7846 | @remote_compatible |
7511ead0 JM |
7847 | def test_wps_ext_ap_settings_m2d(dev, apdev): |
7848 | """WPS and AP Settings: M2D""" | |
7849 | addr,bssid,hapd = wps_start_ext_reg(apdev[0], dev[0]) | |
7850 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7851 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7852 | ||
7853 | logger.debug("Receive M1 from AP") | |
7854 | msg, m1_attrs, raw_m1_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M1) | |
7855 | e_nonce = m1_attrs[ATTR_ENROLLEE_NONCE] | |
7856 | ||
7857 | r_nonce = 16*'\x44' | |
7858 | uuid_r = 16*'\x33' | |
7859 | ||
7860 | logger.debug("Send M2D to AP") | |
7861 | m2d, raw_m2d_attrs = build_m2d(raw_m1_attrs, msg['eap_identifier'], | |
7862 | e_nonce, r_nonce, uuid_r, | |
7863 | dev_pw_id='\x00\x00', eap_code=2) | |
7864 | send_wsc_msg(hapd, addr, m2d) | |
7865 | ||
7866 | ev = hapd.wait_event(["WPS-M2D"], timeout=5) | |
7867 | if ev is None: | |
7868 | raise Exception("M2D not reported") | |
7869 | ||
7870 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
7871 | ||
7872 | def wps_wait_ap_nack(hapd, dev, e_nonce, r_nonce): | |
7873 | logger.debug("Receive WSC_NACK from AP") | |
7874 | msg = get_wsc_msg(hapd) | |
7875 | if msg['wsc_opcode'] != WSC_NACK: | |
7876 | raise Exception("Unexpected message - expected WSC_NACK") | |
7877 | ||
7878 | logger.debug("Send WSC_NACK to AP") | |
7879 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
7880 | eap_code=2) | |
7881 | send_wsc_msg(hapd, dev.own_addr(), nack) | |
7882 | dev.wait_disconnected() | |
7883 | ||
9fd6804d | 7884 | @remote_compatible |
7511ead0 JM |
7885 | def test_wps_ext_m3_missing_e_hash1(dev, apdev): |
7886 | """WPS proto: M3 missing E-Hash1""" | |
7887 | pin = "12345670" | |
7888 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7889 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7890 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7891 | ||
7892 | logger.debug("Receive WSC/Start from AP") | |
7893 | msg = get_wsc_msg(hapd) | |
7894 | if msg['wsc_opcode'] != WSC_Start: | |
7895 | raise Exception("Unexpected Op-Code for WSC/Start") | |
7896 | ||
7897 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7898 | uuid_e = 16*'\x11' | |
7899 | e_nonce = 16*'\x22' | |
7900 | own_private, e_pk = wsc_dh_init() | |
7901 | ||
7902 | logger.debug("Send M1 to AP") | |
7903 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
7904 | e_nonce, e_pk) | |
7905 | send_wsc_msg(hapd, addr, m1) | |
7906 | ||
7907 | logger.debug("Receive M2 from AP") | |
7908 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
7909 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
7910 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
7911 | ||
7912 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
7913 | r_nonce) | |
7914 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
7915 | ||
7916 | logger.debug("Send M3 to AP") | |
7917 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7918 | attrs += build_attr_msg_type(WPS_M3) | |
7919 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
7920 | #attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
7921 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
7922 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
7923 | raw_m3_attrs = attrs | |
7924 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7925 | send_wsc_msg(hapd, addr, m3) | |
7926 | ||
7927 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
7928 | ||
9fd6804d | 7929 | @remote_compatible |
7511ead0 JM |
7930 | def test_wps_ext_m3_missing_e_hash2(dev, apdev): |
7931 | """WPS proto: M3 missing E-Hash2""" | |
7932 | pin = "12345670" | |
7933 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7934 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7935 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7936 | ||
7937 | logger.debug("Receive WSC/Start from AP") | |
7938 | msg = get_wsc_msg(hapd) | |
7939 | if msg['wsc_opcode'] != WSC_Start: | |
7940 | raise Exception("Unexpected Op-Code for WSC/Start") | |
7941 | ||
7942 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7943 | uuid_e = 16*'\x11' | |
7944 | e_nonce = 16*'\x22' | |
7945 | own_private, e_pk = wsc_dh_init() | |
7946 | ||
7947 | logger.debug("Send M1 to AP") | |
7948 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
7949 | e_nonce, e_pk) | |
7950 | send_wsc_msg(hapd, addr, m1) | |
7951 | ||
7952 | logger.debug("Receive M2 from AP") | |
7953 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
7954 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
7955 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
7956 | ||
7957 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
7958 | r_nonce) | |
7959 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
7960 | ||
7961 | logger.debug("Send M3 to AP") | |
7962 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
7963 | attrs += build_attr_msg_type(WPS_M3) | |
7964 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
7965 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
7966 | #attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
7967 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
7968 | raw_m3_attrs = attrs | |
7969 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
7970 | send_wsc_msg(hapd, addr, m3) | |
7971 | ||
7972 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
7973 | ||
9fd6804d | 7974 | @remote_compatible |
7511ead0 JM |
7975 | def test_wps_ext_m5_missing_e_snonce1(dev, apdev): |
7976 | """WPS proto: M5 missing E-SNonce1""" | |
7977 | pin = "12345670" | |
7978 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
7979 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
7980 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
7981 | ||
7982 | logger.debug("Receive WSC/Start from AP") | |
7983 | msg = get_wsc_msg(hapd) | |
7984 | if msg['wsc_opcode'] != WSC_Start: | |
7985 | raise Exception("Unexpected Op-Code for WSC/Start") | |
7986 | ||
7987 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
7988 | uuid_e = 16*'\x11' | |
7989 | e_nonce = 16*'\x22' | |
7990 | own_private, e_pk = wsc_dh_init() | |
7991 | ||
7992 | logger.debug("Send M1 to AP") | |
7993 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
7994 | e_nonce, e_pk) | |
7995 | send_wsc_msg(hapd, addr, m1) | |
7996 | ||
7997 | logger.debug("Receive M2 from AP") | |
7998 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
7999 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8000 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8001 | ||
8002 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8003 | r_nonce) | |
8004 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8005 | ||
8006 | logger.debug("Send M3 to AP") | |
8007 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8008 | attrs += build_attr_msg_type(WPS_M3) | |
8009 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8010 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8011 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8012 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8013 | raw_m3_attrs = attrs | |
8014 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8015 | send_wsc_msg(hapd, addr, m3) | |
8016 | ||
8017 | logger.debug("Receive M4 from AP") | |
8018 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8019 | ||
8020 | logger.debug("Send M5 to AP") | |
8021 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8022 | attrs += build_attr_msg_type(WPS_M5) | |
8023 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8024 | #data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8025 | data = '' | |
8026 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8027 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8028 | raw_m5_attrs = attrs | |
8029 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8030 | send_wsc_msg(hapd, addr, m5) | |
8031 | ||
8032 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8033 | ||
9fd6804d | 8034 | @remote_compatible |
7511ead0 JM |
8035 | def test_wps_ext_m5_e_snonce1_mismatch(dev, apdev): |
8036 | """WPS proto: M5 E-SNonce1 mismatch""" | |
8037 | pin = "12345670" | |
8038 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8039 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8040 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8041 | ||
8042 | logger.debug("Receive WSC/Start from AP") | |
8043 | msg = get_wsc_msg(hapd) | |
8044 | if msg['wsc_opcode'] != WSC_Start: | |
8045 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8046 | ||
8047 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8048 | uuid_e = 16*'\x11' | |
8049 | e_nonce = 16*'\x22' | |
8050 | own_private, e_pk = wsc_dh_init() | |
8051 | ||
8052 | logger.debug("Send M1 to AP") | |
8053 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8054 | e_nonce, e_pk) | |
8055 | send_wsc_msg(hapd, addr, m1) | |
8056 | ||
8057 | logger.debug("Receive M2 from AP") | |
8058 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8059 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8060 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8061 | ||
8062 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8063 | r_nonce) | |
8064 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8065 | ||
8066 | logger.debug("Send M3 to AP") | |
8067 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8068 | attrs += build_attr_msg_type(WPS_M3) | |
8069 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8070 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8071 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8072 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8073 | raw_m3_attrs = attrs | |
8074 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8075 | send_wsc_msg(hapd, addr, m3) | |
8076 | ||
8077 | logger.debug("Receive M4 from AP") | |
8078 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8079 | ||
8080 | logger.debug("Send M5 to AP") | |
8081 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8082 | attrs += build_attr_msg_type(WPS_M5) | |
8083 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8084 | data = build_wsc_attr(ATTR_E_SNONCE1, 16*'\x00') | |
8085 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8086 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8087 | raw_m5_attrs = attrs | |
8088 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8089 | send_wsc_msg(hapd, addr, m5) | |
8090 | ||
8091 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8092 | ||
8093 | def test_wps_ext_m7_missing_e_snonce2(dev, apdev): | |
8094 | """WPS proto: M7 missing E-SNonce2""" | |
8095 | pin = "12345670" | |
8096 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8097 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8098 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8099 | ||
8100 | logger.debug("Receive WSC/Start from AP") | |
8101 | msg = get_wsc_msg(hapd) | |
8102 | if msg['wsc_opcode'] != WSC_Start: | |
8103 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8104 | ||
8105 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8106 | uuid_e = 16*'\x11' | |
8107 | e_nonce = 16*'\x22' | |
8108 | own_private, e_pk = wsc_dh_init() | |
8109 | ||
8110 | logger.debug("Send M1 to AP") | |
8111 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8112 | e_nonce, e_pk) | |
8113 | send_wsc_msg(hapd, addr, m1) | |
8114 | ||
8115 | logger.debug("Receive M2 from AP") | |
8116 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8117 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8118 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8119 | ||
8120 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8121 | r_nonce) | |
8122 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8123 | ||
8124 | logger.debug("Send M3 to AP") | |
8125 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8126 | attrs += build_attr_msg_type(WPS_M3) | |
8127 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8128 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8129 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8130 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8131 | raw_m3_attrs = attrs | |
8132 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8133 | send_wsc_msg(hapd, addr, m3) | |
8134 | ||
8135 | logger.debug("Receive M4 from AP") | |
8136 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8137 | ||
8138 | logger.debug("Send M5 to AP") | |
8139 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8140 | attrs += build_attr_msg_type(WPS_M5) | |
8141 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8142 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8143 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8144 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8145 | raw_m5_attrs = attrs | |
8146 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8147 | send_wsc_msg(hapd, addr, m5) | |
8148 | ||
8149 | logger.debug("Receive M6 from AP") | |
8150 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
8151 | ||
8152 | logger.debug("Send M7 to AP") | |
8153 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8154 | attrs += build_attr_msg_type(WPS_M7) | |
8155 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8156 | #data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
8157 | data = '' | |
8158 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8159 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
8160 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8161 | raw_m7_attrs = attrs | |
8162 | send_wsc_msg(hapd, addr, m7) | |
8163 | ||
8164 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8165 | ||
9fd6804d | 8166 | @remote_compatible |
7511ead0 JM |
8167 | def test_wps_ext_m7_e_snonce2_mismatch(dev, apdev): |
8168 | """WPS proto: M7 E-SNonce2 mismatch""" | |
8169 | pin = "12345670" | |
8170 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8171 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8172 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8173 | ||
8174 | logger.debug("Receive WSC/Start from AP") | |
8175 | msg = get_wsc_msg(hapd) | |
8176 | if msg['wsc_opcode'] != WSC_Start: | |
8177 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8178 | ||
8179 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8180 | uuid_e = 16*'\x11' | |
8181 | e_nonce = 16*'\x22' | |
8182 | own_private, e_pk = wsc_dh_init() | |
8183 | ||
8184 | logger.debug("Send M1 to AP") | |
8185 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8186 | e_nonce, e_pk) | |
8187 | send_wsc_msg(hapd, addr, m1) | |
8188 | ||
8189 | logger.debug("Receive M2 from AP") | |
8190 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8191 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8192 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8193 | ||
8194 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8195 | r_nonce) | |
8196 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8197 | ||
8198 | logger.debug("Send M3 to AP") | |
8199 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8200 | attrs += build_attr_msg_type(WPS_M3) | |
8201 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8202 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8203 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8204 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8205 | raw_m3_attrs = attrs | |
8206 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8207 | send_wsc_msg(hapd, addr, m3) | |
8208 | ||
8209 | logger.debug("Receive M4 from AP") | |
8210 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8211 | ||
8212 | logger.debug("Send M5 to AP") | |
8213 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8214 | attrs += build_attr_msg_type(WPS_M5) | |
8215 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8216 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8217 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8218 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8219 | raw_m5_attrs = attrs | |
8220 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8221 | send_wsc_msg(hapd, addr, m5) | |
8222 | ||
8223 | logger.debug("Receive M6 from AP") | |
8224 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
8225 | ||
8226 | logger.debug("Send M7 to AP") | |
8227 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8228 | attrs += build_attr_msg_type(WPS_M7) | |
8229 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8230 | data = build_wsc_attr(ATTR_E_SNONCE2, 16*'\x00') | |
8231 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8232 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
8233 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8234 | raw_m7_attrs = attrs | |
8235 | send_wsc_msg(hapd, addr, m7) | |
8236 | ||
8237 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8238 | ||
9fd6804d | 8239 | @remote_compatible |
7511ead0 JM |
8240 | def test_wps_ext_m1_pubkey_oom(dev, apdev): |
8241 | """WPS proto: M1 PubKey OOM""" | |
8242 | pin = "12345670" | |
8243 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8244 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8245 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8246 | ||
8247 | logger.debug("Receive WSC/Start from AP") | |
8248 | msg = get_wsc_msg(hapd) | |
8249 | if msg['wsc_opcode'] != WSC_Start: | |
8250 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8251 | ||
8252 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8253 | uuid_e = 16*'\x11' | |
8254 | e_nonce = 16*'\x22' | |
8255 | own_private, e_pk = wsc_dh_init() | |
8256 | ||
8257 | logger.debug("Send M1 to AP") | |
8258 | with alloc_fail(hapd, 1, "wpabuf_alloc_copy;wps_process_pubkey"): | |
8259 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8260 | e_nonce, e_pk) | |
8261 | send_wsc_msg(hapd, addr, m1) | |
8262 | wps_wait_eap_failure(hapd, dev[0]) | |
8263 | ||
8264 | def wps_wait_eap_failure(hapd, dev): | |
8265 | ev = hapd.wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
8266 | if ev is None: | |
8267 | raise Exception("EAP-Failure not reported") | |
8268 | dev.wait_disconnected() | |
8269 | ||
9fd6804d | 8270 | @remote_compatible |
7511ead0 JM |
8271 | def test_wps_ext_m3_m1(dev, apdev): |
8272 | """WPS proto: M3 replaced with M1""" | |
8273 | pin = "12345670" | |
8274 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8275 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8276 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8277 | ||
8278 | logger.debug("Receive WSC/Start from AP") | |
8279 | msg = get_wsc_msg(hapd) | |
8280 | if msg['wsc_opcode'] != WSC_Start: | |
8281 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8282 | ||
8283 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8284 | uuid_e = 16*'\x11' | |
8285 | e_nonce = 16*'\x22' | |
8286 | own_private, e_pk = wsc_dh_init() | |
8287 | ||
8288 | logger.debug("Send M1 to AP") | |
8289 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8290 | e_nonce, e_pk) | |
8291 | send_wsc_msg(hapd, addr, m1) | |
8292 | ||
8293 | logger.debug("Receive M2 from AP") | |
8294 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8295 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8296 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8297 | ||
8298 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8299 | r_nonce) | |
8300 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8301 | ||
8302 | logger.debug("Send M3(M1) to AP") | |
8303 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8304 | attrs += build_attr_msg_type(WPS_M1) | |
8305 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8306 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8307 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8308 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8309 | raw_m3_attrs = attrs | |
8310 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8311 | send_wsc_msg(hapd, addr, m3) | |
8312 | ||
8313 | wps_wait_eap_failure(hapd, dev[0]) | |
8314 | ||
9fd6804d | 8315 | @remote_compatible |
7511ead0 JM |
8316 | def test_wps_ext_m5_m3(dev, apdev): |
8317 | """WPS proto: M5 replaced with M3""" | |
8318 | pin = "12345670" | |
8319 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8320 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8321 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8322 | ||
8323 | logger.debug("Receive WSC/Start from AP") | |
8324 | msg = get_wsc_msg(hapd) | |
8325 | if msg['wsc_opcode'] != WSC_Start: | |
8326 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8327 | ||
8328 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8329 | uuid_e = 16*'\x11' | |
8330 | e_nonce = 16*'\x22' | |
8331 | own_private, e_pk = wsc_dh_init() | |
8332 | ||
8333 | logger.debug("Send M1 to AP") | |
8334 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8335 | e_nonce, e_pk) | |
8336 | send_wsc_msg(hapd, addr, m1) | |
8337 | ||
8338 | logger.debug("Receive M2 from AP") | |
8339 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8340 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8341 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8342 | ||
8343 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8344 | r_nonce) | |
8345 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8346 | ||
8347 | logger.debug("Send M3 to AP") | |
8348 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8349 | attrs += build_attr_msg_type(WPS_M3) | |
8350 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8351 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8352 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8353 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8354 | raw_m3_attrs = attrs | |
8355 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8356 | send_wsc_msg(hapd, addr, m3) | |
8357 | ||
8358 | logger.debug("Receive M4 from AP") | |
8359 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
8360 | ||
8361 | logger.debug("Send M5(M3) to AP") | |
8362 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8363 | attrs += build_attr_msg_type(WPS_M3) | |
8364 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8365 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
8366 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
8367 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
8368 | raw_m5_attrs = attrs | |
8369 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8370 | send_wsc_msg(hapd, addr, m5) | |
8371 | ||
8372 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8373 | ||
9fd6804d | 8374 | @remote_compatible |
7511ead0 JM |
8375 | def test_wps_ext_m3_m2(dev, apdev): |
8376 | """WPS proto: M3 replaced with M2""" | |
8377 | pin = "12345670" | |
8378 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8379 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8380 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8381 | ||
8382 | logger.debug("Receive WSC/Start from AP") | |
8383 | msg = get_wsc_msg(hapd) | |
8384 | if msg['wsc_opcode'] != WSC_Start: | |
8385 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8386 | ||
8387 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8388 | uuid_e = 16*'\x11' | |
8389 | e_nonce = 16*'\x22' | |
8390 | own_private, e_pk = wsc_dh_init() | |
8391 | ||
8392 | logger.debug("Send M1 to AP") | |
8393 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8394 | e_nonce, e_pk) | |
8395 | send_wsc_msg(hapd, addr, m1) | |
8396 | ||
8397 | logger.debug("Receive M2 from AP") | |
8398 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8399 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8400 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8401 | ||
8402 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8403 | r_nonce) | |
8404 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8405 | ||
8406 | logger.debug("Send M3(M2) to AP") | |
8407 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8408 | attrs += build_attr_msg_type(WPS_M2) | |
8409 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8410 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8411 | raw_m3_attrs = attrs | |
8412 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8413 | send_wsc_msg(hapd, addr, m3) | |
8414 | ||
8415 | wps_wait_eap_failure(hapd, dev[0]) | |
8416 | ||
9fd6804d | 8417 | @remote_compatible |
7511ead0 JM |
8418 | def test_wps_ext_m3_m5(dev, apdev): |
8419 | """WPS proto: M3 replaced with M5""" | |
8420 | pin = "12345670" | |
8421 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8422 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8423 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8424 | ||
8425 | logger.debug("Receive WSC/Start from AP") | |
8426 | msg = get_wsc_msg(hapd) | |
8427 | if msg['wsc_opcode'] != WSC_Start: | |
8428 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8429 | ||
8430 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8431 | uuid_e = 16*'\x11' | |
8432 | e_nonce = 16*'\x22' | |
8433 | own_private, e_pk = wsc_dh_init() | |
8434 | ||
8435 | logger.debug("Send M1 to AP") | |
8436 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8437 | e_nonce, e_pk) | |
8438 | send_wsc_msg(hapd, addr, m1) | |
8439 | ||
8440 | logger.debug("Receive M2 from AP") | |
8441 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8442 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8443 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8444 | ||
8445 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8446 | r_nonce) | |
8447 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8448 | ||
8449 | logger.debug("Send M3(M5) to AP") | |
8450 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8451 | attrs += build_attr_msg_type(WPS_M5) | |
8452 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8453 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8454 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8455 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8456 | raw_m3_attrs = attrs | |
8457 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8458 | send_wsc_msg(hapd, addr, m3) | |
8459 | ||
8460 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8461 | ||
9fd6804d | 8462 | @remote_compatible |
7511ead0 JM |
8463 | def test_wps_ext_m3_m7(dev, apdev): |
8464 | """WPS proto: M3 replaced with M7""" | |
8465 | pin = "12345670" | |
8466 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8467 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8468 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8469 | ||
8470 | logger.debug("Receive WSC/Start from AP") | |
8471 | msg = get_wsc_msg(hapd) | |
8472 | if msg['wsc_opcode'] != WSC_Start: | |
8473 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8474 | ||
8475 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8476 | uuid_e = 16*'\x11' | |
8477 | e_nonce = 16*'\x22' | |
8478 | own_private, e_pk = wsc_dh_init() | |
8479 | ||
8480 | logger.debug("Send M1 to AP") | |
8481 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8482 | e_nonce, e_pk) | |
8483 | send_wsc_msg(hapd, addr, m1) | |
8484 | ||
8485 | logger.debug("Receive M2 from AP") | |
8486 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8487 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8488 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8489 | ||
8490 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8491 | r_nonce) | |
8492 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8493 | ||
8494 | logger.debug("Send M3(M7) to AP") | |
8495 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8496 | attrs += build_attr_msg_type(WPS_M7) | |
8497 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
8498 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
8499 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
8500 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8501 | raw_m3_attrs = attrs | |
8502 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8503 | send_wsc_msg(hapd, addr, m3) | |
8504 | ||
8505 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
8506 | ||
9fd6804d | 8507 | @remote_compatible |
7511ead0 JM |
8508 | def test_wps_ext_m3_done(dev, apdev): |
8509 | """WPS proto: M3 replaced with WSC_Done""" | |
8510 | pin = "12345670" | |
8511 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8512 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8513 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8514 | ||
8515 | logger.debug("Receive WSC/Start from AP") | |
8516 | msg = get_wsc_msg(hapd) | |
8517 | if msg['wsc_opcode'] != WSC_Start: | |
8518 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8519 | ||
8520 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8521 | uuid_e = 16*'\x11' | |
8522 | e_nonce = 16*'\x22' | |
8523 | own_private, e_pk = wsc_dh_init() | |
8524 | ||
8525 | logger.debug("Send M1 to AP") | |
8526 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8527 | e_nonce, e_pk) | |
8528 | send_wsc_msg(hapd, addr, m1) | |
8529 | ||
8530 | logger.debug("Receive M2 from AP") | |
8531 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8532 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8533 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8534 | ||
8535 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8536 | r_nonce) | |
8537 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8538 | ||
8539 | logger.debug("Send M3(WSC_Done) to AP") | |
8540 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8541 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
8542 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
8543 | raw_m3_attrs = attrs | |
8544 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
8545 | send_wsc_msg(hapd, addr, m3) | |
8546 | ||
8547 | wps_wait_eap_failure(hapd, dev[0]) | |
8548 | ||
9fd6804d | 8549 | @remote_compatible |
7511ead0 JM |
8550 | def test_wps_ext_m2_nack_invalid(dev, apdev): |
8551 | """WPS proto: M2 followed by invalid NACK""" | |
8552 | pin = "12345670" | |
8553 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8554 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8555 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8556 | ||
8557 | logger.debug("Receive WSC/Start from AP") | |
8558 | msg = get_wsc_msg(hapd) | |
8559 | if msg['wsc_opcode'] != WSC_Start: | |
8560 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8561 | ||
8562 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8563 | uuid_e = 16*'\x11' | |
8564 | e_nonce = 16*'\x22' | |
8565 | own_private, e_pk = wsc_dh_init() | |
8566 | ||
8567 | logger.debug("Send M1 to AP") | |
8568 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8569 | e_nonce, e_pk) | |
8570 | send_wsc_msg(hapd, addr, m1) | |
8571 | ||
8572 | logger.debug("Receive M2 from AP") | |
8573 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8574 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8575 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8576 | ||
8577 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8578 | r_nonce) | |
8579 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8580 | ||
8581 | logger.debug("Send WSC_NACK to AP") | |
8582 | attrs = '\x10\x00\x00' | |
8583 | nack = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_NACK) | |
8584 | send_wsc_msg(hapd, addr, nack) | |
8585 | ||
8586 | wps_wait_eap_failure(hapd, dev[0]) | |
8587 | ||
9fd6804d | 8588 | @remote_compatible |
7511ead0 JM |
8589 | def test_wps_ext_m2_nack_no_msg_type(dev, apdev): |
8590 | """WPS proto: M2 followed by NACK without Msg Type""" | |
8591 | pin = "12345670" | |
8592 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8593 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8594 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8595 | ||
8596 | logger.debug("Receive WSC/Start from AP") | |
8597 | msg = get_wsc_msg(hapd) | |
8598 | if msg['wsc_opcode'] != WSC_Start: | |
8599 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8600 | ||
8601 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8602 | uuid_e = 16*'\x11' | |
8603 | e_nonce = 16*'\x22' | |
8604 | own_private, e_pk = wsc_dh_init() | |
8605 | ||
8606 | logger.debug("Send M1 to AP") | |
8607 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8608 | e_nonce, e_pk) | |
8609 | send_wsc_msg(hapd, addr, m1) | |
8610 | ||
8611 | logger.debug("Receive M2 from AP") | |
8612 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8613 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8614 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8615 | ||
8616 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8617 | r_nonce) | |
8618 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8619 | ||
8620 | logger.debug("Send WSC_NACK to AP") | |
8621 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
8622 | msg_type=None, eap_code=2) | |
8623 | send_wsc_msg(hapd, addr, nack) | |
8624 | ||
8625 | wps_wait_eap_failure(hapd, dev[0]) | |
8626 | ||
9fd6804d | 8627 | @remote_compatible |
7511ead0 JM |
8628 | def test_wps_ext_m2_nack_invalid_msg_type(dev, apdev): |
8629 | """WPS proto: M2 followed by NACK with invalid Msg Type""" | |
8630 | pin = "12345670" | |
8631 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8632 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8633 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8634 | ||
8635 | logger.debug("Receive WSC/Start from AP") | |
8636 | msg = get_wsc_msg(hapd) | |
8637 | if msg['wsc_opcode'] != WSC_Start: | |
8638 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8639 | ||
8640 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8641 | uuid_e = 16*'\x11' | |
8642 | e_nonce = 16*'\x22' | |
8643 | own_private, e_pk = wsc_dh_init() | |
8644 | ||
8645 | logger.debug("Send M1 to AP") | |
8646 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8647 | e_nonce, e_pk) | |
8648 | send_wsc_msg(hapd, addr, m1) | |
8649 | ||
8650 | logger.debug("Receive M2 from AP") | |
8651 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8652 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8653 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8654 | ||
8655 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8656 | r_nonce) | |
8657 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8658 | ||
8659 | logger.debug("Send WSC_NACK to AP") | |
8660 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
8661 | msg_type=WPS_WSC_ACK, eap_code=2) | |
8662 | send_wsc_msg(hapd, addr, nack) | |
8663 | ||
8664 | wps_wait_eap_failure(hapd, dev[0]) | |
8665 | ||
9fd6804d | 8666 | @remote_compatible |
7511ead0 JM |
8667 | def test_wps_ext_m2_nack_e_nonce_mismatch(dev, apdev): |
8668 | """WPS proto: M2 followed by NACK with e-nonce mismatch""" | |
8669 | pin = "12345670" | |
8670 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8671 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8672 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8673 | ||
8674 | logger.debug("Receive WSC/Start from AP") | |
8675 | msg = get_wsc_msg(hapd) | |
8676 | if msg['wsc_opcode'] != WSC_Start: | |
8677 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8678 | ||
8679 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8680 | uuid_e = 16*'\x11' | |
8681 | e_nonce = 16*'\x22' | |
8682 | own_private, e_pk = wsc_dh_init() | |
8683 | ||
8684 | logger.debug("Send M1 to AP") | |
8685 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8686 | e_nonce, e_pk) | |
8687 | send_wsc_msg(hapd, addr, m1) | |
8688 | ||
8689 | logger.debug("Receive M2 from AP") | |
8690 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8691 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8692 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8693 | ||
8694 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8695 | r_nonce) | |
8696 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8697 | ||
8698 | logger.debug("Send WSC_NACK to AP") | |
8699 | nack,attrs = build_nack(msg['eap_identifier'], 16*'\x00', r_nonce, | |
8700 | eap_code=2) | |
8701 | send_wsc_msg(hapd, addr, nack) | |
8702 | ||
8703 | wps_wait_eap_failure(hapd, dev[0]) | |
8704 | ||
9fd6804d | 8705 | @remote_compatible |
7511ead0 JM |
8706 | def test_wps_ext_m2_nack_no_config_error(dev, apdev): |
8707 | """WPS proto: M2 followed by NACK without Config Error""" | |
8708 | pin = "12345670" | |
8709 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8710 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8711 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8712 | ||
8713 | logger.debug("Receive WSC/Start from AP") | |
8714 | msg = get_wsc_msg(hapd) | |
8715 | if msg['wsc_opcode'] != WSC_Start: | |
8716 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8717 | ||
8718 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8719 | uuid_e = 16*'\x11' | |
8720 | e_nonce = 16*'\x22' | |
8721 | own_private, e_pk = wsc_dh_init() | |
8722 | ||
8723 | logger.debug("Send M1 to AP") | |
8724 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8725 | e_nonce, e_pk) | |
8726 | send_wsc_msg(hapd, addr, m1) | |
8727 | ||
8728 | logger.debug("Receive M2 from AP") | |
8729 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8730 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8731 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8732 | ||
8733 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8734 | r_nonce) | |
8735 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8736 | ||
8737 | logger.debug("Send WSC_NACK to AP") | |
8738 | nack,attrs = build_nack(msg['eap_identifier'], e_nonce, r_nonce, | |
8739 | config_error=None, eap_code=2) | |
8740 | send_wsc_msg(hapd, addr, nack) | |
8741 | ||
8742 | wps_wait_eap_failure(hapd, dev[0]) | |
8743 | ||
9fd6804d | 8744 | @remote_compatible |
7511ead0 JM |
8745 | def test_wps_ext_m2_ack_invalid(dev, apdev): |
8746 | """WPS proto: M2 followed by invalid ACK""" | |
8747 | pin = "12345670" | |
8748 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8749 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8750 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8751 | ||
8752 | logger.debug("Receive WSC/Start from AP") | |
8753 | msg = get_wsc_msg(hapd) | |
8754 | if msg['wsc_opcode'] != WSC_Start: | |
8755 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8756 | ||
8757 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8758 | uuid_e = 16*'\x11' | |
8759 | e_nonce = 16*'\x22' | |
8760 | own_private, e_pk = wsc_dh_init() | |
8761 | ||
8762 | logger.debug("Send M1 to AP") | |
8763 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8764 | e_nonce, e_pk) | |
8765 | send_wsc_msg(hapd, addr, m1) | |
8766 | ||
8767 | logger.debug("Receive M2 from AP") | |
8768 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8769 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8770 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8771 | ||
8772 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8773 | r_nonce) | |
8774 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8775 | ||
8776 | logger.debug("Send WSC_ACK to AP") | |
8777 | attrs = '\x10\x00\x00' | |
8778 | ack = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_ACK) | |
8779 | send_wsc_msg(hapd, addr, ack) | |
8780 | ||
8781 | wps_wait_eap_failure(hapd, dev[0]) | |
8782 | ||
9fd6804d | 8783 | @remote_compatible |
7511ead0 JM |
8784 | def test_wps_ext_m2_ack(dev, apdev): |
8785 | """WPS proto: M2 followed by ACK""" | |
8786 | pin = "12345670" | |
8787 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8788 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8789 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8790 | ||
8791 | logger.debug("Receive WSC/Start from AP") | |
8792 | msg = get_wsc_msg(hapd) | |
8793 | if msg['wsc_opcode'] != WSC_Start: | |
8794 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8795 | ||
8796 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8797 | uuid_e = 16*'\x11' | |
8798 | e_nonce = 16*'\x22' | |
8799 | own_private, e_pk = wsc_dh_init() | |
8800 | ||
8801 | logger.debug("Send M1 to AP") | |
8802 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8803 | e_nonce, e_pk) | |
8804 | send_wsc_msg(hapd, addr, m1) | |
8805 | ||
8806 | logger.debug("Receive M2 from AP") | |
8807 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8808 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8809 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8810 | ||
8811 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8812 | r_nonce) | |
8813 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8814 | ||
8815 | logger.debug("Send WSC_ACK to AP") | |
8816 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, eap_code=2) | |
8817 | send_wsc_msg(hapd, addr, ack) | |
8818 | ||
8819 | wps_wait_eap_failure(hapd, dev[0]) | |
8820 | ||
9fd6804d | 8821 | @remote_compatible |
7511ead0 JM |
8822 | def test_wps_ext_m2_ack_no_msg_type(dev, apdev): |
8823 | """WPS proto: M2 followed by ACK missing Msg Type""" | |
8824 | pin = "12345670" | |
8825 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8826 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8827 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8828 | ||
8829 | logger.debug("Receive WSC/Start from AP") | |
8830 | msg = get_wsc_msg(hapd) | |
8831 | if msg['wsc_opcode'] != WSC_Start: | |
8832 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8833 | ||
8834 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8835 | uuid_e = 16*'\x11' | |
8836 | e_nonce = 16*'\x22' | |
8837 | own_private, e_pk = wsc_dh_init() | |
8838 | ||
8839 | logger.debug("Send M1 to AP") | |
8840 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8841 | e_nonce, e_pk) | |
8842 | send_wsc_msg(hapd, addr, m1) | |
8843 | ||
8844 | logger.debug("Receive M2 from AP") | |
8845 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8846 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8847 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8848 | ||
8849 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8850 | r_nonce) | |
8851 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8852 | ||
8853 | logger.debug("Send WSC_ACK to AP") | |
8854 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, | |
8855 | msg_type=None, eap_code=2) | |
8856 | send_wsc_msg(hapd, addr, ack) | |
8857 | ||
8858 | wps_wait_eap_failure(hapd, dev[0]) | |
8859 | ||
9fd6804d | 8860 | @remote_compatible |
7511ead0 JM |
8861 | def test_wps_ext_m2_ack_invalid_msg_type(dev, apdev): |
8862 | """WPS proto: M2 followed by ACK with invalid Msg Type""" | |
8863 | pin = "12345670" | |
8864 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8865 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8866 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8867 | ||
8868 | logger.debug("Receive WSC/Start from AP") | |
8869 | msg = get_wsc_msg(hapd) | |
8870 | if msg['wsc_opcode'] != WSC_Start: | |
8871 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8872 | ||
8873 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8874 | uuid_e = 16*'\x11' | |
8875 | e_nonce = 16*'\x22' | |
8876 | own_private, e_pk = wsc_dh_init() | |
8877 | ||
8878 | logger.debug("Send M1 to AP") | |
8879 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8880 | e_nonce, e_pk) | |
8881 | send_wsc_msg(hapd, addr, m1) | |
8882 | ||
8883 | logger.debug("Receive M2 from AP") | |
8884 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8885 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8886 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8887 | ||
8888 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8889 | r_nonce) | |
8890 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8891 | ||
8892 | logger.debug("Send WSC_ACK to AP") | |
8893 | ack,attrs = build_ack(msg['eap_identifier'], e_nonce, r_nonce, | |
8894 | msg_type=WPS_WSC_NACK, eap_code=2) | |
8895 | send_wsc_msg(hapd, addr, ack) | |
8896 | ||
8897 | wps_wait_eap_failure(hapd, dev[0]) | |
8898 | ||
9fd6804d | 8899 | @remote_compatible |
7511ead0 JM |
8900 | def test_wps_ext_m2_ack_e_nonce_mismatch(dev, apdev): |
8901 | """WPS proto: M2 followed by ACK with e-nonce mismatch""" | |
8902 | pin = "12345670" | |
8903 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8904 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8905 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8906 | ||
8907 | logger.debug("Receive WSC/Start from AP") | |
8908 | msg = get_wsc_msg(hapd) | |
8909 | if msg['wsc_opcode'] != WSC_Start: | |
8910 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8911 | ||
8912 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8913 | uuid_e = 16*'\x11' | |
8914 | e_nonce = 16*'\x22' | |
8915 | own_private, e_pk = wsc_dh_init() | |
8916 | ||
8917 | logger.debug("Send M1 to AP") | |
8918 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8919 | e_nonce, e_pk) | |
8920 | send_wsc_msg(hapd, addr, m1) | |
8921 | ||
8922 | logger.debug("Receive M2 from AP") | |
8923 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
8924 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
8925 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
8926 | ||
8927 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
8928 | r_nonce) | |
8929 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
8930 | ||
8931 | logger.debug("Send WSC_ACK to AP") | |
8932 | ack,attrs = build_ack(msg['eap_identifier'], 16*'\x00', r_nonce, | |
8933 | eap_code=2) | |
8934 | send_wsc_msg(hapd, addr, ack) | |
8935 | ||
8936 | wps_wait_eap_failure(hapd, dev[0]) | |
8937 | ||
9fd6804d | 8938 | @remote_compatible |
7511ead0 JM |
8939 | def test_wps_ext_m1_invalid(dev, apdev): |
8940 | """WPS proto: M1 failing parsing""" | |
8941 | pin = "12345670" | |
8942 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8943 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8944 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8945 | ||
8946 | logger.debug("Receive WSC/Start from AP") | |
8947 | msg = get_wsc_msg(hapd) | |
8948 | if msg['wsc_opcode'] != WSC_Start: | |
8949 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8950 | ||
8951 | logger.debug("Send M1 to AP") | |
8952 | attrs = '\x10\x00\x00' | |
8953 | m1 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8954 | send_wsc_msg(hapd, addr, m1) | |
8955 | ||
8956 | wps_wait_eap_failure(hapd, dev[0]) | |
8957 | ||
8958 | def test_wps_ext_m1_missing_msg_type(dev, apdev): | |
8959 | """WPS proto: M1 missing Msg Type""" | |
8960 | pin = "12345670" | |
8961 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8962 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8963 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8964 | ||
8965 | logger.debug("Receive WSC/Start from AP") | |
8966 | msg = get_wsc_msg(hapd) | |
8967 | if msg['wsc_opcode'] != WSC_Start: | |
8968 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8969 | ||
8970 | logger.debug("Send M1 to AP") | |
8971 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
8972 | m1 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
8973 | send_wsc_msg(hapd, addr, m1) | |
8974 | ||
8975 | wps_wait_ap_nack(hapd, dev[0], 16*'\x00', 16*'\x00') | |
8976 | ||
8977 | def wps_ext_wsc_done(dev, apdev): | |
8978 | pin = "12345670" | |
8979 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
8980 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
8981 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
8982 | ||
8983 | logger.debug("Receive WSC/Start from AP") | |
8984 | msg = get_wsc_msg(hapd) | |
8985 | if msg['wsc_opcode'] != WSC_Start: | |
8986 | raise Exception("Unexpected Op-Code for WSC/Start") | |
8987 | ||
8988 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
8989 | uuid_e = 16*'\x11' | |
8990 | e_nonce = 16*'\x22' | |
8991 | own_private, e_pk = wsc_dh_init() | |
8992 | ||
8993 | logger.debug("Send M1 to AP") | |
8994 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
8995 | e_nonce, e_pk) | |
8996 | send_wsc_msg(hapd, addr, m1) | |
8997 | ||
8998 | logger.debug("Receive M2 from AP") | |
8999 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
9000 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
9001 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
9002 | ||
9003 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
9004 | r_nonce) | |
9005 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
9006 | ||
9007 | logger.debug("Send M3 to AP") | |
9008 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9009 | attrs += build_attr_msg_type(WPS_M3) | |
9010 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9011 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
9012 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
9013 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
9014 | raw_m3_attrs = attrs | |
9015 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9016 | send_wsc_msg(hapd, addr, m3) | |
9017 | ||
9018 | logger.debug("Receive M4 from AP") | |
9019 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
9020 | ||
9021 | logger.debug("Send M5 to AP") | |
9022 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9023 | attrs += build_attr_msg_type(WPS_M5) | |
9024 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9025 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
9026 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9027 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
9028 | raw_m5_attrs = attrs | |
9029 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9030 | send_wsc_msg(hapd, addr, m5) | |
9031 | ||
9032 | logger.debug("Receive M6 from AP") | |
9033 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
9034 | ||
9035 | logger.debug("Send M7 to AP") | |
9036 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9037 | attrs += build_attr_msg_type(WPS_M7) | |
9038 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9039 | data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
9040 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9041 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
9042 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9043 | raw_m7_attrs = attrs | |
9044 | send_wsc_msg(hapd, addr, m7) | |
9045 | ||
9046 | logger.debug("Receive M8 from AP") | |
9047 | msg, m8_attrs, raw_m8_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M8) | |
9048 | return hapd, msg, e_nonce, r_nonce | |
9049 | ||
9fd6804d | 9050 | @remote_compatible |
7511ead0 JM |
9051 | def test_wps_ext_wsc_done_invalid(dev, apdev): |
9052 | """WPS proto: invalid WSC_Done""" | |
9053 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9054 | ||
9055 | logger.debug("Send WSC_Done to AP") | |
9056 | attrs = '\x10\x00\x00' | |
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_no_msg_type(dev, apdev): |
9064 | """WPS proto: invalid WSC_Done""" | |
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_DONE) | |
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_wrong_msg_type(dev, apdev): |
9079 | """WPS proto: WSC_Done with wrong Msg Type""" | |
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_ACK) | |
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 | ||
9fd6804d | 9092 | @remote_compatible |
7511ead0 JM |
9093 | def test_wps_ext_wsc_done_no_e_nonce(dev, apdev): |
9094 | """WPS proto: WSC_Done without e_nonce""" | |
9095 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9096 | ||
9097 | logger.debug("Send WSC_Done to AP") | |
9098 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9099 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
9100 | #attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
9101 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9102 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9103 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9104 | ||
9105 | wps_wait_eap_failure(hapd, dev[0]) | |
9106 | ||
9107 | def test_wps_ext_wsc_done_no_r_nonce(dev, apdev): | |
9108 | """WPS proto: WSC_Done without r_nonce""" | |
9109 | hapd, msg, e_nonce, r_nonce = wps_ext_wsc_done(dev, apdev) | |
9110 | ||
9111 | logger.debug("Send WSC_Done to AP") | |
9112 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9113 | attrs += build_attr_msg_type(WPS_WSC_DONE) | |
9114 | attrs += build_wsc_attr(ATTR_ENROLLEE_NONCE, e_nonce) | |
9115 | #attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9116 | wsc_done = build_eap_wsc(2, msg['eap_identifier'], attrs, opcode=WSC_Done) | |
9117 | send_wsc_msg(hapd, dev[0].own_addr(), wsc_done) | |
9118 | ||
9119 | wps_wait_eap_failure(hapd, dev[0]) | |
9120 | ||
9fd6804d | 9121 | @remote_compatible |
7511ead0 JM |
9122 | def test_wps_ext_m7_no_encr_settings(dev, apdev): |
9123 | """WPS proto: M7 without Encr Settings""" | |
9124 | pin = "12345670" | |
9125 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
9126 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
9127 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
9128 | ||
9129 | logger.debug("Receive WSC/Start from AP") | |
9130 | msg = get_wsc_msg(hapd) | |
9131 | if msg['wsc_opcode'] != WSC_Start: | |
9132 | raise Exception("Unexpected Op-Code for WSC/Start") | |
9133 | ||
9134 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
9135 | uuid_e = 16*'\x11' | |
9136 | e_nonce = 16*'\x22' | |
9137 | own_private, e_pk = wsc_dh_init() | |
9138 | ||
9139 | logger.debug("Send M1 to AP") | |
9140 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
9141 | e_nonce, e_pk) | |
9142 | send_wsc_msg(hapd, addr, m1) | |
9143 | ||
9144 | logger.debug("Receive M2 from AP") | |
9145 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
9146 | r_nonce = m2_attrs[ATTR_REGISTRAR_NONCE] | |
9147 | r_pk = m2_attrs[ATTR_PUBLIC_KEY] | |
9148 | ||
9149 | authkey,keywrapkey = wsc_dh_kdf(r_pk, own_private, mac_addr, e_nonce, | |
9150 | r_nonce) | |
9151 | e_s1,e_s2,e_hash1,e_hash2 = wsc_dev_pw_hash(authkey, pin, e_pk, r_pk) | |
9152 | ||
9153 | logger.debug("Send M3 to AP") | |
9154 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9155 | attrs += build_attr_msg_type(WPS_M3) | |
9156 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9157 | attrs += build_wsc_attr(ATTR_E_HASH1, e_hash1) | |
9158 | attrs += build_wsc_attr(ATTR_E_HASH2, e_hash2) | |
9159 | attrs += build_attr_authenticator(authkey, raw_m2_attrs, attrs) | |
9160 | raw_m3_attrs = attrs | |
9161 | m3 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9162 | send_wsc_msg(hapd, addr, m3) | |
9163 | ||
9164 | logger.debug("Receive M4 from AP") | |
9165 | msg, m4_attrs, raw_m4_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M4) | |
9166 | ||
9167 | logger.debug("Send M5 to AP") | |
9168 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9169 | attrs += build_attr_msg_type(WPS_M5) | |
9170 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9171 | data = build_wsc_attr(ATTR_E_SNONCE1, e_s1) | |
9172 | attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9173 | attrs += build_attr_authenticator(authkey, raw_m4_attrs, attrs) | |
9174 | raw_m5_attrs = attrs | |
9175 | m5 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9176 | send_wsc_msg(hapd, addr, m5) | |
9177 | ||
9178 | logger.debug("Receive M6 from AP") | |
9179 | msg, m6_attrs, raw_m6_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M6) | |
9180 | ||
9181 | logger.debug("Send M7 to AP") | |
9182 | attrs = build_wsc_attr(ATTR_VERSION, '\x10') | |
9183 | attrs += build_attr_msg_type(WPS_M7) | |
9184 | attrs += build_wsc_attr(ATTR_REGISTRAR_NONCE, r_nonce) | |
9185 | #data = build_wsc_attr(ATTR_E_SNONCE2, e_s2) | |
9186 | #attrs += build_attr_encr_settings(authkey, keywrapkey, data) | |
9187 | attrs += build_attr_authenticator(authkey, raw_m6_attrs, attrs) | |
9188 | m7 = build_eap_wsc(2, msg['eap_identifier'], attrs) | |
9189 | raw_m7_attrs = attrs | |
9190 | send_wsc_msg(hapd, addr, m7) | |
9191 | ||
9192 | wps_wait_ap_nack(hapd, dev[0], e_nonce, r_nonce) | |
9193 | ||
9fd6804d | 9194 | @remote_compatible |
7511ead0 JM |
9195 | def test_wps_ext_m1_workaround(dev, apdev): |
9196 | """WPS proto: M1 Manufacturer/Model workaround""" | |
9197 | pin = "12345670" | |
9198 | addr,bssid,hapd = wps_start_ext(apdev[0], dev[0], pin=pin) | |
9199 | wps_ext_eap_identity_req(dev[0], hapd, bssid) | |
9200 | wps_ext_eap_identity_resp(hapd, dev[0], addr) | |
9201 | ||
9202 | logger.debug("Receive WSC/Start from AP") | |
9203 | msg = get_wsc_msg(hapd) | |
9204 | if msg['wsc_opcode'] != WSC_Start: | |
9205 | raise Exception("Unexpected Op-Code for WSC/Start") | |
9206 | ||
9207 | mac_addr = binascii.unhexlify(dev[0].own_addr().replace(':', '')) | |
9208 | uuid_e = 16*'\x11' | |
9209 | e_nonce = 16*'\x22' | |
9210 | own_private, e_pk = wsc_dh_init() | |
9211 | ||
9212 | logger.debug("Send M1 to AP") | |
9213 | m1, raw_m1_attrs = build_m1(msg['eap_identifier'], uuid_e, mac_addr, | |
9214 | e_nonce, e_pk, manufacturer='Apple TEST', | |
9215 | model_name='AirPort', config_methods='\xff\xff') | |
9216 | send_wsc_msg(hapd, addr, m1) | |
9217 | ||
9218 | logger.debug("Receive M2 from AP") | |
9219 | msg, m2_attrs, raw_m2_attrs = recv_wsc_msg(hapd, WSC_MSG, WPS_M2) | |
53bd8653 | 9220 | |
9fd6804d | 9221 | @remote_compatible |
53bd8653 JM |
9222 | def test_ap_wps_disable_enable(dev, apdev): |
9223 | """WPS and DISABLE/ENABLE AP""" | |
9224 | hapd = wps_start_ap(apdev[0]) | |
9225 | hapd.disable() | |
9226 | hapd.enable() | |
9227 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
dd124ee8 JM |
9228 | |
9229 | def test_ap_wps_upnp_web_oom(dev, apdev, params): | |
9230 | """hostapd WPS UPnP web OOM""" | |
9231 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
21aa8b7e | 9232 | hapd = add_ssdp_ap(apdev[0], ap_uuid) |
dd124ee8 JM |
9233 | |
9234 | location = ssdp_get_location(ap_uuid) | |
9235 | url = urlparse.urlparse(location) | |
9236 | urls = upnp_get_urls(location) | |
9237 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
9238 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
9239 | ||
9240 | conn = httplib.HTTPConnection(url.netloc) | |
9241 | with alloc_fail(hapd, 1, "web_connection_parse_get"): | |
9242 | conn.request("GET", "/wps_device.xml") | |
9243 | try: | |
9244 | resp = conn.getresponse() | |
9245 | except: | |
9246 | pass | |
9247 | ||
9248 | conn = httplib.HTTPConnection(url.netloc) | |
9249 | conn.request("GET", "/unknown") | |
9250 | resp = conn.getresponse() | |
9251 | if resp.status != 404: | |
9252 | raise Exception("Unexpected HTTP result for unknown URL: %d" + resp.status) | |
9253 | ||
9254 | with alloc_fail(hapd, 1, "web_connection_parse_get"): | |
9255 | conn.request("GET", "/unknown") | |
9256 | try: | |
9257 | resp = conn.getresponse() | |
9258 | print resp.status | |
9259 | except: | |
9260 | pass | |
9261 | ||
9262 | conn = httplib.HTTPConnection(url.netloc) | |
9263 | conn.request("GET", "/wps_device.xml") | |
9264 | resp = conn.getresponse() | |
9265 | if resp.status != 200: | |
9266 | raise Exception("GET /wps_device.xml failed") | |
9267 | ||
9268 | conn = httplib.HTTPConnection(url.netloc) | |
9269 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9270 | if resp.status != 200: | |
9271 | raise Exception("GetDeviceInfo failed") | |
9272 | ||
9273 | with alloc_fail(hapd, 1, "web_process_get_device_info"): | |
9274 | conn = httplib.HTTPConnection(url.netloc) | |
9275 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9276 | if resp.status != 500: | |
9277 | raise Exception("Internal error not reported from GetDeviceInfo OOM") | |
9278 | ||
9279 | with alloc_fail(hapd, 1, "wps_build_m1;web_process_get_device_info"): | |
9280 | conn = httplib.HTTPConnection(url.netloc) | |
9281 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9282 | if resp.status != 500: | |
9283 | raise Exception("Internal error not reported from GetDeviceInfo OOM") | |
9284 | ||
9285 | with alloc_fail(hapd, 1, "wpabuf_alloc;web_connection_send_reply"): | |
9286 | conn = httplib.HTTPConnection(url.netloc) | |
9287 | try: | |
9288 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9289 | except: | |
9290 | pass | |
9291 | ||
9292 | conn = httplib.HTTPConnection(url.netloc) | |
9293 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
9294 | if resp.status != 200: | |
9295 | raise Exception("GetDeviceInfo failed") | |
9296 | ||
9297 | # No NewWLANEventType in PutWLANResponse NewMessage | |
9298 | conn = httplib.HTTPConnection(url.netloc) | |
9299 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo") | |
9300 | if resp.status != 600: | |
9301 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9302 | ||
9303 | # No NewWLANEventMAC in PutWLANResponse NewMessage | |
9304 | conn = httplib.HTTPConnection(url.netloc) | |
9305 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9306 | newmsg="foo", neweventtype="1") | |
9307 | if resp.status != 600: | |
9308 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9309 | ||
9310 | # Invalid NewWLANEventMAC in PutWLANResponse NewMessage | |
9311 | conn = httplib.HTTPConnection(url.netloc) | |
9312 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9313 | newmsg="foo", neweventtype="1", | |
9314 | neweventmac="foo") | |
9315 | if resp.status != 600: | |
9316 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9317 | ||
9318 | # Workaround for NewWLANEventMAC in PutWLANResponse NewMessage | |
9319 | # Ignored unexpected PutWLANResponse WLANEventType 1 | |
9320 | conn = httplib.HTTPConnection(url.netloc) | |
9321 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9322 | newmsg="foo", neweventtype="1", | |
9323 | neweventmac="00.11.22.33.44.55") | |
9324 | if resp.status != 500: | |
9325 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9326 | ||
9327 | # PutWLANResponse NewMessage with invalid EAP message | |
9328 | conn = httplib.HTTPConnection(url.netloc) | |
9329 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", | |
9330 | newmsg="foo", neweventtype="2", | |
9331 | neweventmac="00:11:22:33:44:55") | |
9332 | if resp.status != 200: | |
9333 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9334 | ||
9335 | with alloc_fail(hapd, 1, "web_connection_parse_subscribe"): | |
9336 | conn = httplib.HTTPConnection(url.netloc) | |
9337 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
9338 | "NT": "upnp:event", | |
9339 | "timeout": "Second-1234" } | |
9340 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
9341 | try: | |
9342 | resp = conn.getresponse() | |
9343 | except: | |
9344 | pass | |
9345 | ||
9346 | with alloc_fail(hapd, 1, "dup_binstr;web_connection_parse_subscribe"): | |
9347 | conn = httplib.HTTPConnection(url.netloc) | |
9348 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
9349 | "NT": "upnp:event", | |
9350 | "timeout": "Second-1234" } | |
9351 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
9352 | resp = conn.getresponse() | |
9353 | if resp.status != 500: | |
9354 | raise Exception("Unexpected HTTP response: %d" % resp.status) | |
9355 | ||
9356 | with alloc_fail(hapd, 1, "wpabuf_alloc;web_connection_parse_unsubscribe"): | |
9357 | conn = httplib.HTTPConnection(url.netloc) | |
9358 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
9359 | "NT": "upnp:event", | |
9360 | "timeout": "Second-1234" } | |
9361 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
9362 | try: | |
9363 | resp = conn.getresponse() | |
9364 | except: | |
9365 | pass | |
9366 | ||
9367 | with alloc_fail(hapd, 1, "web_connection_unimplemented"): | |
9368 | conn = httplib.HTTPConnection(url.netloc) | |
9369 | conn.request("HEAD", "/wps_device.xml") | |
9370 | try: | |
9371 | resp = conn.getresponse() | |
9372 | except: | |
9373 | pass | |
d1341917 JM |
9374 | |
9375 | def test_ap_wps_frag_ack_oom(dev, apdev): | |
9376 | """WPS and fragment ack OOM""" | |
9377 | dev[0].request("SET wps_fragment_size 50") | |
9378 | hapd = wps_start_ap(apdev[0]) | |
9379 | with alloc_fail(hapd, 1, "eap_wsc_build_frag_ack"): | |
9380 | wps_run_pbc_fail_ap(apdev[0], dev[0], hapd) | |
1e35aa15 JM |
9381 | |
9382 | def wait_scan_stopped(dev): | |
9383 | dev.request("ABORT_SCAN") | |
9384 | for i in range(50): | |
9385 | res = dev.get_driver_status_field("scan_state") | |
9386 | if "SCAN_STARTED" not in res and "SCAN_REQUESTED" not in res: | |
9387 | break | |
9388 | logger.debug("Waiting for scan to complete") | |
9389 | time.sleep(0.1) | |
9390 | ||
9fd6804d | 9391 | @remote_compatible |
1e35aa15 JM |
9392 | def test_ap_wps_eap_wsc_errors(dev, apdev): |
9393 | """WPS and EAP-WSC error cases""" | |
9394 | ssid = "test-wps-conf-pin" | |
9395 | appin = "12345670" | |
9396 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9397 | "wpa_passphrase": "12345678", "wpa": "2", | |
9398 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9399 | "fragment_size": "300", "ap_pin": appin } | |
8b8a1864 | 9400 | hapd = hostapd.add_ap(apdev[0], params) |
1e35aa15 JM |
9401 | bssid = apdev[0]['bssid'] |
9402 | ||
9403 | pin = dev[0].wps_read_pin() | |
9404 | hapd.request("WPS_PIN any " + pin) | |
9405 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
9406 | dev[0].dump_monitor() | |
9407 | ||
9408 | dev[0].wps_reg(bssid, appin + " new_ssid=a", "new ssid", "WPA2PSK", "CCMP", | |
9409 | "new passphrase", no_wait=True) | |
9410 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9411 | if ev is None: | |
9412 | raise Exception("WPS-FAIL not reported") | |
9413 | dev[0].request("WPS_CANCEL") | |
9414 | dev[0].wait_disconnected() | |
9415 | wait_scan_stopped(dev[0]) | |
9416 | dev[0].dump_monitor() | |
9417 | ||
9418 | dev[0].wps_reg(bssid, appin, "new ssid", "FOO", "CCMP", | |
9419 | "new passphrase", no_wait=True) | |
9420 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9421 | if ev is None: | |
9422 | raise Exception("WPS-FAIL not reported") | |
9423 | dev[0].request("WPS_CANCEL") | |
9424 | dev[0].wait_disconnected() | |
9425 | wait_scan_stopped(dev[0]) | |
9426 | dev[0].dump_monitor() | |
9427 | ||
9428 | dev[0].wps_reg(bssid, appin, "new ssid", "WPA2PSK", "FOO", | |
9429 | "new passphrase", no_wait=True) | |
9430 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9431 | if ev is None: | |
9432 | raise Exception("WPS-FAIL not reported") | |
9433 | dev[0].request("WPS_CANCEL") | |
9434 | dev[0].wait_disconnected() | |
9435 | wait_scan_stopped(dev[0]) | |
9436 | dev[0].dump_monitor() | |
9437 | ||
9438 | dev[0].wps_reg(bssid, appin + "new_key=a", "new ssid", "WPA2PSK", "CCMP", | |
9439 | "new passphrase", no_wait=True) | |
9440 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=10) | |
9441 | if ev is None: | |
9442 | raise Exception("WPS-FAIL not reported") | |
9443 | dev[0].request("WPS_CANCEL") | |
9444 | dev[0].wait_disconnected() | |
9445 | wait_scan_stopped(dev[0]) | |
9446 | dev[0].dump_monitor() | |
9447 | ||
9448 | tests = [ "eap_wsc_init", | |
9449 | "eap_msg_alloc;eap_wsc_build_msg", | |
9450 | "wpabuf_alloc;eap_wsc_process_fragment" ] | |
9451 | for func in tests: | |
9452 | with alloc_fail(dev[0], 1, func): | |
9453 | dev[0].request("WPS_PIN %s %s" % (bssid, pin)) | |
9454 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
9455 | dev[0].request("WPS_CANCEL") | |
9456 | dev[0].wait_disconnected() | |
9457 | wait_scan_stopped(dev[0]) | |
9458 | dev[0].dump_monitor() | |
d8e5a55f | 9459 | |
bd3948c0 JM |
9460 | with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_sm_build_expanded_nak"): |
9461 | dev[0].wps_reg(bssid, appin + " new_ssid=a", "new ssid", "WPA2PSK", | |
9462 | "CCMP", "new passphrase", no_wait=True) | |
9463 | wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") | |
9464 | dev[0].request("WPS_CANCEL") | |
9465 | dev[0].wait_disconnected() | |
9466 | wait_scan_stopped(dev[0]) | |
9467 | dev[0].dump_monitor() | |
9468 | ||
d8e5a55f JM |
9469 | def test_ap_wps_eap_wsc(dev, apdev): |
9470 | """WPS and EAP-WSC in network profile""" | |
9471 | params = int_eap_server_params() | |
9472 | params["wps_state"] = "2" | |
8b8a1864 | 9473 | hapd = hostapd.add_ap(apdev[0], params) |
d8e5a55f JM |
9474 | bssid = apdev[0]['bssid'] |
9475 | ||
9476 | logger.info("Unexpected identity") | |
9477 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9478 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-unexpected", | |
9479 | wait_connect=False) | |
9480 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9481 | if ev is None: | |
9482 | raise Exception("No EAP-Failure seen") | |
9483 | dev[0].request("REMOVE_NETWORK all") | |
9484 | dev[0].wait_disconnected() | |
9485 | ||
9486 | logger.info("No phase1 parameter") | |
9487 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9488 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9489 | wait_connect=False) | |
9490 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9491 | if ev is None: | |
9492 | raise Exception("Timeout on EAP method start") | |
9493 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9494 | if ev is None: | |
9495 | raise Exception("No EAP-Failure seen") | |
9496 | dev[0].request("REMOVE_NETWORK all") | |
9497 | dev[0].wait_disconnected() | |
9498 | ||
9499 | logger.info("No PIN/PBC in phase1") | |
9500 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9501 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9502 | phase1="foo", wait_connect=False) | |
9503 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9504 | if ev is None: | |
9505 | raise Exception("Timeout on EAP method start") | |
9506 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9507 | if ev is None: | |
9508 | raise Exception("No EAP-Failure seen") | |
9509 | dev[0].request("REMOVE_NETWORK all") | |
9510 | dev[0].wait_disconnected() | |
9511 | ||
9512 | logger.info("Invalid pkhash in phase1") | |
9513 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9514 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9515 | phase1="foo pkhash=q pbc=1", wait_connect=False) | |
9516 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9517 | if ev is None: | |
9518 | raise Exception("Timeout on EAP method start") | |
9519 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9520 | if ev is None: | |
9521 | raise Exception("No EAP-Failure seen") | |
9522 | dev[0].request("REMOVE_NETWORK all") | |
9523 | dev[0].wait_disconnected() | |
9524 | ||
9525 | logger.info("Zero fragment_size") | |
9526 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9527 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9528 | fragment_size="0", phase1="pin=12345670", wait_connect=False) | |
9529 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9530 | if ev is None: | |
9531 | raise Exception("Timeout on EAP method start") | |
9532 | ev = dev[0].wait_event(["WPS-M2D"], timeout=5) | |
9533 | if ev is None: | |
9534 | raise Exception("No M2D seen") | |
9535 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9536 | if ev is None: | |
9537 | raise Exception("No EAP-Failure seen") | |
9538 | dev[0].request("REMOVE_NETWORK all") | |
9539 | dev[0].wait_disconnected() | |
9540 | ||
9541 | logger.info("Missing new_auth") | |
9542 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9543 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9544 | phase1="pin=12345670 new_ssid=aa", wait_connect=False) | |
9545 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9546 | if ev is None: | |
9547 | raise Exception("Timeout on EAP method start") | |
9548 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9549 | if ev is None: | |
9550 | raise Exception("No EAP-Failure seen") | |
9551 | dev[0].request("REMOVE_NETWORK all") | |
9552 | dev[0].wait_disconnected() | |
9553 | ||
9554 | logger.info("Missing new_encr") | |
9555 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9556 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9557 | phase1="pin=12345670 new_auth=WPA2PSK new_ssid=aa", wait_connect=False) | |
9558 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9559 | if ev is None: | |
9560 | raise Exception("Timeout on EAP method start") | |
9561 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9562 | if ev is None: | |
9563 | raise Exception("No EAP-Failure seen") | |
9564 | dev[0].request("REMOVE_NETWORK all") | |
9565 | dev[0].wait_disconnected() | |
9566 | ||
9567 | logger.info("Missing new_key") | |
9568 | dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412", | |
9569 | eap="WSC", identity="WFA-SimpleConfig-Enrollee-1-0", | |
9570 | phase1="pin=12345670 new_auth=WPA2PSK new_ssid=aa new_encr=CCMP", | |
9571 | wait_connect=False) | |
9572 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=5) | |
9573 | if ev is None: | |
9574 | raise Exception("Timeout on EAP method start") | |
9575 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5) | |
9576 | if ev is None: | |
9577 | raise Exception("No EAP-Failure seen") | |
9578 | dev[0].request("REMOVE_NETWORK all") | |
9579 | dev[0].wait_disconnected() | |
4425b1ed JM |
9580 | |
9581 | def test_ap_wps_and_bss_limit(dev, apdev): | |
9582 | """WPS and wpa_supplicant BSS entry limit""" | |
9583 | try: | |
9584 | _test_ap_wps_and_bss_limit(dev, apdev) | |
9585 | finally: | |
9586 | dev[0].request("SET bss_max_count 200") | |
9587 | pass | |
9588 | ||
9589 | def _test_ap_wps_and_bss_limit(dev, apdev): | |
9590 | params = { "ssid": "test-wps", "eap_server": "1", "wps_state": "2", | |
9591 | "wpa_passphrase": "12345678", "wpa": "2", | |
9592 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
9593 | hapd = hostapd.add_ap(apdev[0], params) | |
9594 | ||
9595 | params = { "ssid": "test-wps-2", "eap_server": "1", "wps_state": "2", | |
9596 | "wpa_passphrase": "1234567890", "wpa": "2", | |
9597 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
9598 | hapd2 = hostapd.add_ap(apdev[1], params) | |
9599 | ||
9600 | id = dev[1].add_network() | |
9601 | dev[1].set_network(id, "mode", "2") | |
9602 | dev[1].set_network_quoted(id, "ssid", "wpas-ap-no-wps") | |
9603 | dev[1].set_network_quoted(id, "psk", "12345678") | |
9604 | dev[1].set_network(id, "frequency", "2462") | |
9605 | dev[1].set_network(id, "scan_freq", "2462") | |
9606 | dev[1].set_network(id, "wps_disabled", "1") | |
9607 | dev[1].select_network(id) | |
9608 | ||
9609 | id = dev[2].add_network() | |
9610 | dev[2].set_network(id, "mode", "2") | |
9611 | dev[2].set_network_quoted(id, "ssid", "wpas-ap") | |
9612 | dev[2].set_network_quoted(id, "psk", "12345678") | |
9613 | dev[2].set_network(id, "frequency", "2437") | |
9614 | dev[2].set_network(id, "scan_freq", "2437") | |
9615 | dev[2].select_network(id) | |
9616 | ||
9617 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
9618 | wpas.interface_add("wlan5") | |
9619 | id = wpas.add_network() | |
9620 | wpas.set_network(id, "mode", "2") | |
9621 | wpas.set_network_quoted(id, "ssid", "wpas-ap") | |
9622 | wpas.set_network_quoted(id, "psk", "12345678") | |
9623 | wpas.set_network(id, "frequency", "2437") | |
9624 | wpas.set_network(id, "scan_freq", "2437") | |
9625 | wpas.select_network(id) | |
9626 | ||
9627 | dev[1].wait_connected() | |
9628 | dev[2].wait_connected() | |
9629 | wpas.wait_connected() | |
9630 | wpas.request("WPS_PIN any 12345670") | |
9631 | ||
9632 | hapd.request("WPS_PBC") | |
9633 | hapd2.request("WPS_PBC") | |
9634 | ||
9635 | dev[0].request("SET bss_max_count 1") | |
9636 | ||
9637 | id = dev[0].add_network() | |
9638 | dev[0].set_network_quoted(id, "ssid", "testing") | |
9639 | ||
9640 | id = dev[0].add_network() | |
9641 | dev[0].set_network_quoted(id, "ssid", "testing") | |
9642 | dev[0].set_network(id, "key_mgmt", "WPS") | |
9643 | ||
9644 | dev[0].request("WPS_PBC") | |
9645 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
9646 | dev[0].request("WPS_CANCEL") | |
9647 | ||
9648 | id = dev[0].add_network() | |
9649 | dev[0].set_network_quoted(id, "ssid", "testing") | |
9650 | dev[0].set_network(id, "key_mgmt", "WPS") | |
9651 | ||
9652 | dev[0].scan(freq="2412") | |
74b23faf JM |
9653 | |
9654 | def test_ap_wps_pbc_2ap(dev, apdev): | |
9655 | """WPS PBC with two APs advertising same SSID""" | |
9656 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
9657 | "wpa_passphrase": "12345678", "wpa": "2", | |
9658 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9659 | "wps_independent": "1"} | |
9660 | hapd = hostapd.add_ap(apdev[0], params) | |
9661 | params = { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
9662 | "wpa_passphrase": "123456789", "wpa": "2", | |
9663 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9664 | "wps_independent": "1"} | |
9665 | hapd2 = hostapd.add_ap(apdev[1], params) | |
9666 | hapd.request("WPS_PBC") | |
9667 | ||
9668 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
9669 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
9670 | wpas.dump_monitor() | |
9671 | ||
9672 | wpas.scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) | |
9673 | wpas.scan_for_bss(apdev[1]['bssid'], freq="2412") | |
9674 | wpas.request("WPS_PBC") | |
9675 | wpas.wait_connected() | |
9676 | wpas.request("DISCONNECT") | |
9677 | hapd.request("DISABLE") | |
9678 | hapd2.request("DISABLE") | |
9679 | wpas.flush_scan_cache() | |
aed9e23a JM |
9680 | |
9681 | def test_ap_wps_er_enrollee_to_conf_ap(dev, apdev): | |
9682 | """WPS ER enrolling a new device to a configured AP""" | |
9683 | try: | |
9684 | _test_ap_wps_er_enrollee_to_conf_ap(dev, apdev) | |
9685 | finally: | |
9686 | dev[0].request("WPS_ER_STOP") | |
9687 | ||
9688 | def _test_ap_wps_er_enrollee_to_conf_ap(dev, apdev): | |
9689 | ssid = "wps-er-enrollee-to-conf-ap" | |
9690 | ap_pin = "12345670" | |
9691 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
9692 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9693 | "wpa_passphrase": "12345678", "wpa": "2", | |
9694 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9695 | "device_name": "Wireless AP", "manufacturer": "Company", | |
9696 | "model_name": "WAP", "model_number": "123", | |
9697 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
9698 | "os_version": "01020300", | |
9699 | "config_methods": "label push_button", | |
9700 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"} | |
9701 | hapd = hostapd.add_ap(apdev[0], params) | |
9702 | bssid = hapd.own_addr() | |
9703 | ||
9704 | id = dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
9705 | dev[0].dump_monitor() | |
9706 | ||
9707 | dev[0].request("WPS_ER_START ifname=lo") | |
9708 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
9709 | if ev is None: | |
9710 | raise Exception("AP discovery timed out") | |
9711 | if ap_uuid not in ev: | |
9712 | raise Exception("Expected AP UUID not found") | |
9713 | ||
9714 | pin = dev[2].wps_read_pin() | |
9715 | addr2 = dev[2].own_addr() | |
9716 | dev[0].dump_monitor() | |
9717 | dev[2].scan_for_bss(bssid, freq=2412) | |
9718 | dev[2].dump_monitor() | |
9719 | dev[2].request("WPS_PIN %s %s" % (bssid, pin)) | |
9720 | ||
9721 | for i in range(3): | |
9722 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) | |
9723 | if ev is None: | |
9724 | raise Exception("Enrollee not seen") | |
9725 | if addr2 in ev: | |
9726 | break | |
9727 | if addr2 not in ev: | |
9728 | raise Exception("Unexpected Enrollee MAC address") | |
9729 | dev[0].dump_monitor() | |
9730 | ||
9731 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " " + str(id)) | |
9732 | dev[0].request("WPS_ER_PIN " + addr2 + " " + pin + " " + addr2) | |
9733 | dev[2].wait_connected(timeout=30) | |
9734 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
9735 | if ev is None: | |
9736 | raise Exception("WPS ER did not report success") | |
9737 | ||
9738 | def test_ap_wps_er_enrollee_to_conf_ap2(dev, apdev): | |
9739 | """WPS ER enrolling a new device to a configured AP (2)""" | |
9740 | try: | |
9741 | _test_ap_wps_er_enrollee_to_conf_ap2(dev, apdev) | |
9742 | finally: | |
9743 | dev[0].request("WPS_ER_STOP") | |
9744 | ||
9745 | def _test_ap_wps_er_enrollee_to_conf_ap2(dev, apdev): | |
9746 | ssid = "wps-er-enrollee-to-conf-ap" | |
9747 | ap_pin = "12345670" | |
9748 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
9749 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9750 | "wpa_passphrase": "12345678", "wpa": "2", | |
9751 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9752 | "device_name": "Wireless AP", "manufacturer": "Company", | |
9753 | "model_name": "WAP", "model_number": "123", | |
9754 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
9755 | "os_version": "01020300", | |
9756 | "config_methods": "label push_button", | |
9757 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"} | |
9758 | hapd = hostapd.add_ap(apdev[0], params) | |
9759 | bssid = hapd.own_addr() | |
9760 | ||
9761 | id = dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
9762 | dev[0].dump_monitor() | |
9763 | ||
9764 | dev[0].request("WPS_ER_START ifname=lo") | |
9765 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
9766 | if ev is None: | |
9767 | raise Exception("AP discovery timed out") | |
9768 | if ap_uuid not in ev: | |
9769 | raise Exception("Expected AP UUID not found") | |
9770 | ||
9771 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
9772 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
9773 | if ev is None: | |
9774 | raise Exception("AP learn timed out") | |
9775 | if ap_uuid not in ev: | |
9776 | raise Exception("Expected AP UUID not in settings") | |
9777 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) | |
9778 | if ev is None: | |
9779 | raise Exception("WPS-FAIL after AP learn timed out") | |
9780 | time.sleep(0.1) | |
9781 | ||
9782 | pin = dev[1].wps_read_pin() | |
9783 | addr1 = dev[1].own_addr() | |
9784 | dev[0].dump_monitor() | |
9785 | dev[0].request("WPS_ER_PIN any " + pin) | |
9786 | time.sleep(0.1) | |
9787 | dev[1].scan_for_bss(bssid, freq=2412) | |
9788 | dev[1].request("WPS_PIN any %s" % pin) | |
9789 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) | |
9790 | if ev is None: | |
9791 | raise Exception("Enrollee did not report success") | |
9792 | dev[1].wait_connected(timeout=15) | |
9793 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
9794 | if ev is None: | |
9795 | raise Exception("WPS ER did not report success") | |
5026406d JM |
9796 | |
9797 | def test_ap_wps_ignore_broadcast_ssid(dev, apdev): | |
9798 | """WPS AP trying to ignore broadcast SSID""" | |
9799 | ssid = "test-wps" | |
9800 | hapd = hostapd.add_ap(apdev[0], | |
9801 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
9802 | "ignore_broadcast_ssid": "1" }) | |
9803 | if "FAIL" not in hapd.request("WPS_PBC"): | |
9804 | raise Exception("WPS unexpectedly enabled") | |
9805 | ||
9806 | def test_ap_wps_wep(dev, apdev): | |
9807 | """WPS AP trying to enable WEP""" | |
9808 | ssid = "test-wps" | |
9809 | hapd = hostapd.add_ap(apdev[0], | |
9810 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
9811 | "ieee80211n": "0", "wep_key0": '"hello"' }) | |
9812 | if "FAIL" not in hapd.request("WPS_PBC"): | |
9813 | raise Exception("WPS unexpectedly enabled") | |
9814 | ||
9815 | def test_ap_wps_tkip(dev, apdev): | |
9816 | """WPS AP trying to enable TKIP""" | |
9817 | ssid = "test-wps" | |
9818 | hapd = hostapd.add_ap(apdev[0], | |
9819 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
9820 | "ieee80211n": "0", "wpa": '1', | |
9821 | "wpa_key_mgmt": "WPA-PSK", | |
9822 | "wpa_passphrase": "12345678" }) | |
9823 | if "FAIL" not in hapd.request("WPS_PBC"): | |
9824 | raise Exception("WPS unexpectedly enabled") | |
454b66d2 JM |
9825 | |
9826 | def test_ap_wps_conf_dummy_cred(dev, apdev): | |
9827 | """WPS PIN provisioning with configured AP using dummy cred""" | |
9828 | ssid = "test-wps-conf" | |
9829 | hapd = hostapd.add_ap(apdev[0], | |
9830 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9831 | "wpa_passphrase": "12345678", "wpa": "2", | |
9832 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
9833 | hapd.request("WPS_PIN any 12345670") | |
9834 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
9835 | dev[0].dump_monitor() | |
9836 | try: | |
9837 | hapd.set("wps_testing_dummy_cred", "1") | |
9838 | dev[0].request("WPS_PIN " + apdev[0]['bssid'] + " 12345670") | |
9839 | for i in range(1, 3): | |
9840 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=15) | |
9841 | if ev is None: | |
9842 | raise Exception("WPS credential %d not received" % i) | |
9843 | dev[0].wait_connected(timeout=30) | |
9844 | finally: | |
9845 | hapd.set("wps_testing_dummy_cred", "0") | |
cde2143c JM |
9846 | |
9847 | def test_ap_wps_rf_bands(dev, apdev): | |
9848 | """WPS and wps_rf_bands configuration""" | |
9849 | ssid = "test-wps-conf" | |
9850 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9851 | "wpa_passphrase": "12345678", "wpa": "2", | |
9852 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9853 | "wps_rf_bands": "ag" } | |
9854 | ||
9855 | hapd = hostapd.add_ap(apdev[0], params) | |
9856 | bssid = hapd.own_addr() | |
9857 | hapd.request("WPS_PBC") | |
9858 | dev[0].scan_for_bss(bssid, freq="2412") | |
9859 | dev[0].dump_monitor() | |
9860 | dev[0].request("WPS_PBC " + bssid) | |
9861 | dev[0].wait_connected(timeout=30) | |
9862 | bss = dev[0].get_bss(bssid) | |
9863 | logger.info("BSS: " + str(bss)) | |
9864 | if "103c000103" not in bss['ie']: | |
9865 | raise Exception("RF Bands attribute with expected values not found") | |
9866 | dev[0].request("DISCONNECT") | |
9867 | dev[0].wait_disconnected() | |
9868 | hapd.set("wps_rf_bands", "ad") | |
9869 | hapd.set("wps_rf_bands", "a") | |
9870 | hapd.set("wps_rf_bands", "g") | |
9871 | hapd.set("wps_rf_bands", "b") | |
9872 | hapd.set("wps_rf_bands", "ga") | |
9873 | hapd.disable() | |
9874 | dev[0].dump_monitor() | |
9875 | dev[0].flush_scan_cache() | |
93b85d44 JM |
9876 | |
9877 | def test_ap_wps_pbc_in_m1(dev, apdev): | |
9878 | """WPS and pbc_in_m1""" | |
9879 | ssid = "test-wps-conf" | |
9880 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
9881 | "wpa_passphrase": "12345678", "wpa": "2", | |
9882 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9883 | "config_methods": "virtual_push_button virtual_display", | |
9884 | "pbc_in_m1": "1" } | |
9885 | ||
9886 | hapd = hostapd.add_ap(apdev[0], params) | |
9887 | bssid = hapd.own_addr() | |
9888 | hapd.request("WPS_PBC") | |
9889 | dev[0].scan_for_bss(bssid, freq="2412") | |
9890 | dev[0].dump_monitor() | |
9891 | dev[0].request("WPS_PBC " + bssid) | |
9892 | dev[0].wait_connected(timeout=30) | |
9893 | dev[0].request("DISCONNECT") | |
9894 | dev[0].wait_disconnected() | |
9895 | hapd.disable() | |
9896 | dev[0].dump_monitor() | |
9897 | dev[0].flush_scan_cache() | |
35320d7a JM |
9898 | |
9899 | def test_ap_wps_pin_start_failure(dev, apdev): | |
9900 | """WPS_PIN start failure""" | |
9901 | with alloc_fail(dev[0], 1, "wpas_wps_start_dev_pw"): | |
9902 | if "FAIL" not in dev[0].request("WPS_PIN any 12345670"): | |
9903 | raise Exception("WPS_PIN not rejected during OOM") | |
9904 | with alloc_fail(dev[0], 1, "wpas_wps_start_dev_pw"): | |
9905 | if "FAIL" not in dev[0].request("WPS_PIN any"): | |
9906 | raise Exception("WPS_PIN not rejected during OOM") | |
cc5bf65f JM |
9907 | |
9908 | def test_ap_wps_ap_pin_failure(dev, apdev): | |
9909 | """WPS_AP_PIN failure""" | |
9910 | id = dev[0].add_network() | |
9911 | dev[0].set_network(id, "mode", "2") | |
9912 | dev[0].set_network_quoted(id, "ssid", "wpas-ap-wps") | |
9913 | dev[0].set_network_quoted(id, "psk", "1234567890") | |
9914 | dev[0].set_network(id, "frequency", "2412") | |
9915 | dev[0].set_network(id, "scan_freq", "2412") | |
9916 | dev[0].select_network(id) | |
9917 | dev[0].wait_connected() | |
9918 | ||
9919 | with fail_test(dev[0], 1, | |
9920 | "os_get_random;wpa_supplicant_ctrl_iface_wps_ap_pin"): | |
9921 | if "FAIL" not in dev[0].request("WPS_AP_PIN random"): | |
9922 | raise Exception("WPS_AP_PIN random accepted") | |
9923 | with alloc_fail(dev[0], 1, "wpas_wps_ap_pin_set"): | |
9924 | if "FAIL" not in dev[0].request("WPS_AP_PIN set 12345670"): | |
9925 | raise Exception("WPS_AP_PIN set accepted") | |
9926 | ||
9927 | dev[0].request("DISCONNECT") | |
9928 | dev[0].wait_disconnected() |