3 * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "wps_attr_parse.h"
14 struct wps_attr_parse_test {
20 const struct wps_attr_parse_test wps_attr_parse_test_cases[] = {
23 /* Truncated attribute header */
27 /* Attribute overflow */
28 { "10100001", -1, 0 },
29 #ifdef CONFIG_WPS_STRICT
30 { "10270000001057000101", -1, 0 },
31 { "1027000010570001010000000000", -1, 0 },
32 #else /* CONFIG_WPS_STRICT */
33 /* Network Key workaround */
34 { "10270000001057000101", 0, 1 },
35 { "10230000001057000101", -1, 0 },
36 { "10270000101057000101", -1, 0 },
37 /* Mac OS X 10.6 padding workaround */
38 { "1027000010570001010000000000", 0, 1 },
39 { "1027000010570001010000000000000001000000", -1, 0 },
40 #endif /* CONFIG_WPS_STRICT */
42 { "104a000110", 0, 0 },
43 { "104a0000", -1, 0 },
45 { "1022000101", 0, 0 },
46 { "10220000", -1, 0 },
48 { "101a001000112233445566778899aabbccddeeff", 0, 0 },
49 { "101a00111122334455667788990011223344556677", -1, 0 },
51 { "1039001000112233445566778899aabbccddeeff", 0, 0 },
52 { "103900111122334455667788990011223344556677", -1, 0 },
54 { "1047001000112233445566778899aabbccddeeff", 0, 0 },
55 { "10470000", -1, 0 },
56 { "104700111122334455667788990011223344556677", -1, 0 },
58 { "1048001000112233445566778899aabbccddeeff", 0, 0 },
59 { "10480000", -1, 0 },
60 { "104800111122334455667788990011223344556677", -1, 0 },
62 { "100400021122", 0, 0 },
63 { "10040001ff", -1, 0 },
65 { "101000021122", 0, 0 },
66 { "10100001ff", -1, 0 },
67 /* Connection Type Flags */
68 { "100d0001ff", 0, 0 },
69 { "100d0002ffff", -1, 0 },
71 { "10080002ffff", 0, 0 },
72 { "10080001ff", -1, 0 },
73 /* Selected Registrar Config Methods */
74 { "10530002ffff", 0, 0 },
75 { "10530001ff", -1, 0 },
76 /* Primary Device Type */
77 { "105400081122334455667788", 0, 0 },
78 { "105400111122334455667788990011223344556677", -1, 0 },
80 { "103c0001ff", 0, 0 },
81 { "103c0002ffff", -1, 0 },
82 /* Association State */
83 { "10020002ffff", 0, 0 },
84 { "10020001ff", -1, 0 },
86 { "100900020001", 0, 0 },
87 { "10090001ff", -1, 0 },
88 /* Device Password ID */
89 { "101200020004", 0, 0 },
90 { "10120001ff", -1, 0 },
91 /* OOB Device Password */
92 { "102c001611223344556677889900112233445566778899000007", 0, 0 },
93 { "102c0036112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344", 0, 0 },
94 { "102c0001ff", -1, 0 },
95 { "102c003711223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455", -1, 0 },
96 { "102c002511223344556677889900112233445566778899001122334455667788990011223344556677", -1, 0 },
98 { "102d000411223344", 0, 0 },
99 { "102d00111122334455667788990011223344556677", -1, 0 },
101 { "1044000101", 0, 0 },
102 { "10440002ffff", -1, 0 },
104 { "100500081122334455667788", 0, 0 },
105 { "10050000", -1, 0 },
106 { "100500111122334455667788990011223344556677", -1, 0 },
108 { "103d00201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
109 { "103d0000", -1, 0 },
110 { "103d0021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
112 { "103e00201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
113 { "103e0000", -1, 0 },
114 { "103e0021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
116 { "101400201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
117 { "10140000", -1, 0 },
118 { "10140021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
120 { "101500201122334455667788990011223344556677889900112233445566778899001122", 0, 0 },
121 { "10150000", -1, 0 },
122 { "10150021112233445566778899001122334455667788990011223344556677889900112233", -1, 0 },
124 { "103f001011223344556677889900112233445566", 0, 0 },
125 { "103f0000", -1, 0 },
126 { "103f00111122334455667788990011223344556677", -1, 0 },
128 { "1040001011223344556677889900112233445566", 0, 0 },
129 { "10400000", -1, 0 },
130 { "104000111122334455667788990011223344556677", -1, 0 },
132 { "1016001011223344556677889900112233445566", 0, 0 },
133 { "10160000", -1, 0 },
134 { "101600111122334455667788990011223344556677", -1, 0 },
136 { "1017001011223344556677889900112233445566", 0, 0 },
137 { "10170000", -1, 0 },
138 { "101700111122334455667788990011223344556677", -1, 0 },
139 /* Key Wrap Authenticator */
140 { "101e00081122334455667788", 0, 0 },
141 { "101e0000", -1, 0 },
142 { "101e0009112233445566778899", -1, 0 },
143 /* Authentication Type */
144 { "100300020001", 0, 0 },
145 { "10030001ff", -1, 0 },
146 /* Encryption Type */
147 { "100f00020001", 0, 0 },
148 { "100f0001ff", -1, 0 },
150 { "1026000101", 0, 0 },
151 { "10260002ffff", -1, 0 },
152 /* Network Key Index */
153 { "1028000101", 0, 3 },
154 { "10280002ffff", -1, 0 },
156 { "10200006112233445566", 0, 0 },
157 { "10200000", -1, 0 },
158 { "1020000711223344556677", -1, 0 },
159 /* Selected Registrar */
160 { "1041000101", 0, 0 },
161 { "10410002ffff", -1, 0 },
163 { "103a000101", 0, 0 },
164 { "103a0002ffff", -1, 0 },
166 { "103b000101", 0, 0 },
167 { "103b0002ffff", -1, 0 },
169 { "10210000", 0, 0 },
171 { "10230000", 0, 0 },
173 { "10240000", 0, 0 },
175 { "10420000", 0, 0 },
177 { "10110000", 0, 0 },
179 { "10320000", 0, 0 },
181 { "10180000", 0, 0 },
183 { "10450000", 0, 0 },
184 /* AP Setup Locked */
185 { "1057000101", 0, 0 },
186 { "10570002ffff", -1, 0 },
187 /* Requested Device Type */
188 { "106a00081122334455667788", 0, 0 },
189 { "106a0000", -1, 0 },
190 { "106a0009112233445566778899", -1, 0 },
191 /* More than maximum Requested Device Type attributes */
192 { "106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788106a00081122334455667788", 0, 4 },
193 /* Secondary Device Type List */
194 { "105500081122334455667788", 0, 0 },
195 { "1055000711223344556677", -1, 0 },
196 { "1055008811223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566", -1, 0 },
198 { "100100020001", 0, 0 },
199 { "1001000101", -1, 0 },
200 /* Skip invalid Vendor Extension */
201 { "10490000", 0, 0 },
202 { "1049000100", 0, 0 },
203 { "104900020000", 0, 0 },
204 /* Too long unknown vendor extension */
206 "112233445566778899001122334455667788990011223344556677889900"
207 "112233445566778899001122334455667788990011223344556677889900"
208 "112233445566778899001122334455667788990011223344556677889900"
209 "112233445566778899001122334455667788990011223344556677889900"
210 "112233445566778899001122334455667788990011223344556677889900"
211 "112233445566778899001122334455667788990011223344556677889900"
212 "112233445566778899001122334455667788990011223344556677889900"
213 "112233445566778899001122334455667788990011223344556677889900"
214 "112233445566778899001122334455667788990011223344556677889900"
215 "112233445566778899001122334455667788990011223344556677889900"
216 "112233445566778899001122334455667788990011223344556677889900"
217 "112233445566778899001122334455667788990011223344556677889900"
218 "112233445566778899001122334455667788990011223344556677889900"
219 "112233445566778899001122334455667788990011223344556677889900"
220 "112233445566778899001122334455667788990011223344556677889900"
221 "112233445566778899001122334455667788990011223344556677889900"
222 "112233445566778899001122334455667788990011223344556677889900"
223 "112233445566778899001122334455667788990011223344556677889900"
224 "112233445566778899001122334455667788990011223344556677889900"
225 "112233445566778899001122334455667788990011223344556677889900"
226 "112233445566778899001122334455667788990011223344556677889900"
227 "112233445566778899001122334455667788990011223344556677889900"
228 "112233445566778899001122334455667788990011223344556677889900"
229 "112233445566778899001122334455667788990011223344556677889900"
230 "112233445566778899001122334455667788990011223344556677889900"
231 "112233445566778899001122334455667788990011223344556677889900"
232 "112233445566778899001122334455667788990011223344556677889900"
233 "112233445566778899001122334455667788990011223344556677889900"
234 "112233445566778899001122334455667788990011223344556677889900"
235 "112233445566778899001122334455667788990011223344556677889900"
236 "112233445566778899001122334455667788990011223344556677889900"
237 "112233445566778899001122334455667788990011223344556677889900"
238 "112233445566778899001122334455667788990011223344556677889900"
239 "112233445566778899001122334455667788990011223344556677889900"
240 "1122334455", -1, 0 },
241 /* Maximum unknown vendor extensions */
242 { "10490003111111104900032222221049000333333310490003444444104900035555551049000366666610490003777777104900038888881049000399999910490003AAAAAA", 0, 5 },
243 /* More than maximum unknown vendor extensions */
244 { "10490003111111104900032222221049000333333310490003444444104900035555551049000366666610490003777777104900038888881049000399999910490003AAAAAA10490003BBBBBB", -1, 0 },
245 /* WFA vendor extensions */
246 { "1049000300372a", 0, 0 },
247 { "1049000400372a00", 0, 0 },
248 { "1049000500372a0001", 0, 0 },
249 { "1049001600372a0001ff0100020101030101040101ff00fe0101", 0, 6 },
250 /* Invalid Version2 length */
251 { "1049000500372a0000", -1, 0 },
252 /* Invalid Network Key Shareable length */
253 { "1049000500372a0200", -1, 0 },
254 /* Invalid Requedt To Enroll length */
255 { "1049000500372a0300", -1, 0 },
256 /* Invalid Settings Delay Time length */
257 { "1049000500372a0400", -1, 0 },
258 /* More than maximum Credential attributes */
259 { "100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000100e0000", 0, 2 },
263 static int wps_attr_parse_tests(void)
265 struct wps_parse_attr attr;
269 wpa_printf(MSG_INFO, "WPS attribute parsing tests");
271 for (i = 0; i < ARRAY_SIZE(wps_attr_parse_test_cases); i++) {
274 const struct wps_attr_parse_test *test =
275 &wps_attr_parse_test_cases[i];
277 len = os_strlen(test->data) / 2;
278 buf = wpabuf_alloc(len);
281 if (hexstr2bin(test->data, wpabuf_put(buf, len), len) < 0) {
285 if (wps_parse_msg(buf, &attr) != test->result) {
286 wpa_printf(MSG_ERROR, "WPS attribute parsing test %u failed: %s",
290 switch (test->extra) {
292 if (!attr.network_key || !attr.ap_setup_locked)
296 if (attr.num_cred != MAX_CRED_COUNT)
300 if (!attr.network_key_idx)
304 if (attr.num_req_dev_type != MAX_REQ_DEV_TYPE_COUNT)
308 if (attr.num_vendor_ext != MAX_WPS_PARSE_VENDOR_EXT)
312 if (!attr.version2 ||
313 !attr.authorized_macs ||
314 !attr.network_key_shareable ||
315 !attr.request_to_enroll ||
316 !attr.settings_delay_time)
327 int wps_module_tests(void)
331 wpa_printf(MSG_INFO, "WPS module tests");
333 if (wps_attr_parse_tests() < 0)