blob: d09f0d1c11002ec4023958908831ac6c48b3950f [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
2 * DPP functionality shared between hostapd and wpa_supplicant
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
Hai Shalomfdcde762020-04-02 11:19:20 -07004 * Copyright (c) 2018-2020, The Linux Foundation
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
9
10#include "utils/includes.h"
11#include <openssl/opensslv.h>
12#include <openssl/err.h>
13
14#include "utils/common.h"
15#include "utils/base64.h"
16#include "utils/json.h"
17#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070018#include "common/wpa_ctrl.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070019#include "common/gas.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070020#include "crypto/crypto.h"
21#include "crypto/random.h"
22#include "crypto/aes.h"
23#include "crypto/aes_siv.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070024#include "drivers/driver.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070025#include "dpp.h"
Hai Shalom4fbc08f2020-05-18 12:37:00 -070026#include "dpp_i.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070027
28
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080029static const char * dpp_netrole_str(enum dpp_netrole netrole);
30
Roshan Pius3a1667e2018-07-03 15:17:14 -070031#ifdef CONFIG_TESTING_OPTIONS
Hai Shalom4fbc08f2020-05-18 12:37:00 -070032#ifdef CONFIG_DPP2
33int dpp_version_override = 2;
34#else
35int dpp_version_override = 1;
36#endif
Roshan Pius3a1667e2018-07-03 15:17:14 -070037enum dpp_test_behavior dpp_test = DPP_TEST_DISABLED;
Roshan Pius3a1667e2018-07-03 15:17:14 -070038#endif /* CONFIG_TESTING_OPTIONS */
39
40#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
41 (defined(LIBRESSL_VERSION_NUMBER) && \
42 LIBRESSL_VERSION_NUMBER < 0x20700000L)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070043/* Compatibility wrappers for older versions. */
44
Hai Shalomb755a2a2020-04-23 21:49:02 -070045#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -070046static EC_KEY * EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
47{
48 if (pkey->type != EVP_PKEY_EC)
49 return NULL;
50 return pkey->pkey.ec;
51}
Hai Shalomb755a2a2020-04-23 21:49:02 -070052#endif /* CONFIG_DPP2 */
Hai Shalomfdcde762020-04-02 11:19:20 -070053
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070054#endif
55
56
Hai Shalom4fbc08f2020-05-18 12:37:00 -070057void dpp_auth_fail(struct dpp_authentication *auth, const char *txt)
Roshan Pius3a1667e2018-07-03 15:17:14 -070058{
59 wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_FAIL "%s", txt);
60}
61
62
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070063struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
64 size_t len)
65{
66 struct wpabuf *msg;
67
68 msg = wpabuf_alloc(8 + len);
69 if (!msg)
70 return NULL;
71 wpabuf_put_u8(msg, WLAN_ACTION_PUBLIC);
72 wpabuf_put_u8(msg, WLAN_PA_VENDOR_SPECIFIC);
73 wpabuf_put_be24(msg, OUI_WFA);
74 wpabuf_put_u8(msg, DPP_OUI_TYPE);
75 wpabuf_put_u8(msg, 1); /* Crypto Suite */
76 wpabuf_put_u8(msg, type);
77 return msg;
78}
79
80
81const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len)
82{
83 u16 id, alen;
84 const u8 *pos = buf, *end = buf + len;
85
86 while (end - pos >= 4) {
87 id = WPA_GET_LE16(pos);
88 pos += 2;
89 alen = WPA_GET_LE16(pos);
90 pos += 2;
91 if (alen > end - pos)
92 return NULL;
93 if (id == req_id) {
94 *ret_len = alen;
95 return pos;
96 }
97 pos += alen;
98 }
99
100 return NULL;
101}
102
103
Hai Shalomc3565922019-10-28 11:58:20 -0700104static const u8 * dpp_get_attr_next(const u8 *prev, const u8 *buf, size_t len,
105 u16 req_id, u16 *ret_len)
106{
107 u16 id, alen;
108 const u8 *pos, *end = buf + len;
109
110 if (!prev)
111 pos = buf;
112 else
113 pos = prev + WPA_GET_LE16(prev - 2);
114 while (end - pos >= 4) {
115 id = WPA_GET_LE16(pos);
116 pos += 2;
117 alen = WPA_GET_LE16(pos);
118 pos += 2;
119 if (alen > end - pos)
120 return NULL;
121 if (id == req_id) {
122 *ret_len = alen;
123 return pos;
124 }
125 pos += alen;
126 }
127
128 return NULL;
129}
130
131
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700132int dpp_check_attrs(const u8 *buf, size_t len)
133{
134 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700135 int wrapped_data = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700136
137 pos = buf;
138 end = buf + len;
139 while (end - pos >= 4) {
140 u16 id, alen;
141
142 id = WPA_GET_LE16(pos);
143 pos += 2;
144 alen = WPA_GET_LE16(pos);
145 pos += 2;
146 wpa_printf(MSG_MSGDUMP, "DPP: Attribute ID %04x len %u",
147 id, alen);
148 if (alen > end - pos) {
149 wpa_printf(MSG_DEBUG,
150 "DPP: Truncated message - not enough room for the attribute - dropped");
151 return -1;
152 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700153 if (wrapped_data) {
154 wpa_printf(MSG_DEBUG,
155 "DPP: An unexpected attribute included after the Wrapped Data attribute");
156 return -1;
157 }
158 if (id == DPP_ATTR_WRAPPED_DATA)
159 wrapped_data = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700160 pos += alen;
161 }
162
163 if (end != pos) {
164 wpa_printf(MSG_DEBUG,
165 "DPP: Unexpected octets (%d) after the last attribute",
166 (int) (end - pos));
167 return -1;
168 }
169
170 return 0;
171}
172
173
174void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info)
175{
176 if (!info)
177 return;
178 os_free(info->uri);
179 os_free(info->info);
Hai Shalomfdcde762020-04-02 11:19:20 -0700180 os_free(info->chan);
181 os_free(info->pk);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700182 EVP_PKEY_free(info->pubkey);
Hai Shalomfdcde762020-04-02 11:19:20 -0700183 str_clear_free(info->configurator_params);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700184 os_free(info);
185}
186
187
188const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type)
189{
190 switch (type) {
191 case DPP_BOOTSTRAP_QR_CODE:
192 return "QRCODE";
193 case DPP_BOOTSTRAP_PKEX:
194 return "PKEX";
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800195 case DPP_BOOTSTRAP_NFC_URI:
196 return "NFC-URI";
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700197 }
198 return "??";
199}
200
201
202static int dpp_uri_valid_info(const char *info)
203{
204 while (*info) {
205 unsigned char val = *info++;
206
207 if (val < 0x20 || val > 0x7e || val == 0x3b)
208 return 0;
209 }
210
211 return 1;
212}
213
214
215static int dpp_clone_uri(struct dpp_bootstrap_info *bi, const char *uri)
216{
217 bi->uri = os_strdup(uri);
218 return bi->uri ? 0 : -1;
219}
220
221
222int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
223 const char *chan_list)
224{
Hai Shalom81f62d82019-07-22 12:10:00 -0700225 const char *pos = chan_list, *pos2;
226 int opclass = -1, channel, freq;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700227
228 while (pos && *pos && *pos != ';') {
Hai Shalom81f62d82019-07-22 12:10:00 -0700229 pos2 = pos;
230 while (*pos2 >= '0' && *pos2 <= '9')
231 pos2++;
232 if (*pos2 == '/') {
233 opclass = atoi(pos);
234 pos = pos2 + 1;
235 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700236 if (opclass <= 0)
237 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700238 channel = atoi(pos);
239 if (channel <= 0)
240 goto fail;
241 while (*pos >= '0' && *pos <= '9')
242 pos++;
243 freq = ieee80211_chan_to_freq(NULL, opclass, channel);
244 wpa_printf(MSG_DEBUG,
245 "DPP: URI channel-list: opclass=%d channel=%d ==> freq=%d",
246 opclass, channel, freq);
247 if (freq < 0) {
248 wpa_printf(MSG_DEBUG,
249 "DPP: Ignore unknown URI channel-list channel (opclass=%d channel=%d)",
250 opclass, channel);
251 } else if (bi->num_freq == DPP_BOOTSTRAP_MAX_FREQ) {
252 wpa_printf(MSG_DEBUG,
253 "DPP: Too many channels in URI channel-list - ignore list");
254 bi->num_freq = 0;
255 break;
256 } else {
257 bi->freq[bi->num_freq++] = freq;
258 }
259
260 if (*pos == ';' || *pos == '\0')
261 break;
262 if (*pos != ',')
263 goto fail;
264 pos++;
265 }
266
267 return 0;
268fail:
269 wpa_printf(MSG_DEBUG, "DPP: Invalid URI channel-list");
270 return -1;
271}
272
273
274int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac)
275{
276 if (!mac)
277 return 0;
278
279 if (hwaddr_aton2(mac, bi->mac_addr) < 0) {
280 wpa_printf(MSG_DEBUG, "DPP: Invalid URI mac");
281 return -1;
282 }
283
284 wpa_printf(MSG_DEBUG, "DPP: URI mac: " MACSTR, MAC2STR(bi->mac_addr));
285
286 return 0;
287}
288
289
290int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info)
291{
292 const char *end;
293
294 if (!info)
295 return 0;
296
297 end = os_strchr(info, ';');
298 if (!end)
299 end = info + os_strlen(info);
300 bi->info = os_malloc(end - info + 1);
301 if (!bi->info)
302 return -1;
303 os_memcpy(bi->info, info, end - info);
304 bi->info[end - info] = '\0';
305 wpa_printf(MSG_DEBUG, "DPP: URI(information): %s", bi->info);
306 if (!dpp_uri_valid_info(bi->info)) {
307 wpa_printf(MSG_DEBUG, "DPP: Invalid URI information payload");
308 return -1;
309 }
310
311 return 0;
312}
313
314
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700315int dpp_parse_uri_version(struct dpp_bootstrap_info *bi, const char *version)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700316{
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700317#ifdef CONFIG_DPP2
318 if (!version || DPP_VERSION < 2)
319 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700320
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700321 if (*version == '1')
322 bi->version = 1;
323 else if (*version == '2')
324 bi->version = 2;
325 else
326 wpa_printf(MSG_DEBUG, "DPP: Unknown URI version");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700327
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700328 wpa_printf(MSG_DEBUG, "DPP: URI version: %d", bi->version);
329#endif /* CONFIG_DPP2 */
Hai Shalomfdcde762020-04-02 11:19:20 -0700330
331 return 0;
332}
333
334
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700335static int dpp_parse_uri_pk(struct dpp_bootstrap_info *bi, const char *info)
336{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700337 u8 *data;
338 size_t data_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700339 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700340 const char *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700341
342 end = os_strchr(info, ';');
343 if (!end)
344 return -1;
345
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800346 data = base64_decode(info, end - info, &data_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700347 if (!data) {
348 wpa_printf(MSG_DEBUG,
349 "DPP: Invalid base64 encoding on URI public-key");
350 return -1;
351 }
352 wpa_hexdump(MSG_DEBUG, "DPP: Base64 decoded URI public-key",
353 data, data_len);
354
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700355 res = dpp_get_subject_public_key(bi, data, data_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700356 os_free(data);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700357 return res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700358}
359
360
361static struct dpp_bootstrap_info * dpp_parse_uri(const char *uri)
362{
363 const char *pos = uri;
364 const char *end;
365 const char *chan_list = NULL, *mac = NULL, *info = NULL, *pk = NULL;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700366 const char *version = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700367 struct dpp_bootstrap_info *bi;
368
369 wpa_hexdump_ascii(MSG_DEBUG, "DPP: URI", uri, os_strlen(uri));
370
371 if (os_strncmp(pos, "DPP:", 4) != 0) {
372 wpa_printf(MSG_INFO, "DPP: Not a DPP URI");
373 return NULL;
374 }
375 pos += 4;
376
377 for (;;) {
378 end = os_strchr(pos, ';');
379 if (!end)
380 break;
381
382 if (end == pos) {
383 /* Handle terminating ";;" and ignore unexpected ";"
384 * for parsing robustness. */
385 pos++;
386 continue;
387 }
388
389 if (pos[0] == 'C' && pos[1] == ':' && !chan_list)
390 chan_list = pos + 2;
391 else if (pos[0] == 'M' && pos[1] == ':' && !mac)
392 mac = pos + 2;
393 else if (pos[0] == 'I' && pos[1] == ':' && !info)
394 info = pos + 2;
395 else if (pos[0] == 'K' && pos[1] == ':' && !pk)
396 pk = pos + 2;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700397 else if (pos[0] == 'V' && pos[1] == ':' && !version)
398 version = pos + 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700399 else
400 wpa_hexdump_ascii(MSG_DEBUG,
401 "DPP: Ignore unrecognized URI parameter",
402 pos, end - pos);
403 pos = end + 1;
404 }
405
406 if (!pk) {
407 wpa_printf(MSG_INFO, "DPP: URI missing public-key");
408 return NULL;
409 }
410
411 bi = os_zalloc(sizeof(*bi));
412 if (!bi)
413 return NULL;
414
415 if (dpp_clone_uri(bi, uri) < 0 ||
416 dpp_parse_uri_chan_list(bi, chan_list) < 0 ||
417 dpp_parse_uri_mac(bi, mac) < 0 ||
418 dpp_parse_uri_info(bi, info) < 0 ||
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700419 dpp_parse_uri_version(bi, version) < 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700420 dpp_parse_uri_pk(bi, pk) < 0) {
421 dpp_bootstrap_info_free(bi);
422 bi = NULL;
423 }
424
425 return bi;
426}
427
428
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700429void dpp_build_attr_status(struct wpabuf *msg, enum dpp_status_error status)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700430{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700431 wpa_printf(MSG_DEBUG, "DPP: Status %d", status);
432 wpabuf_put_le16(msg, DPP_ATTR_STATUS);
433 wpabuf_put_le16(msg, 1);
434 wpabuf_put_u8(msg, status);
435}
436
437
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700438void dpp_build_attr_r_bootstrap_key_hash(struct wpabuf *msg, const u8 *hash)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700439{
440 if (hash) {
441 wpa_printf(MSG_DEBUG, "DPP: R-Bootstrap Key Hash");
442 wpabuf_put_le16(msg, DPP_ATTR_R_BOOTSTRAP_KEY_HASH);
443 wpabuf_put_le16(msg, SHA256_MAC_LEN);
444 wpabuf_put_data(msg, hash, SHA256_MAC_LEN);
445 }
446}
447
448
Roshan Pius3a1667e2018-07-03 15:17:14 -0700449static int dpp_channel_ok_init(struct hostapd_hw_modes *own_modes,
450 u16 num_modes, unsigned int freq)
451{
452 u16 m;
453 int c, flag;
454
455 if (!own_modes || !num_modes)
456 return 1;
457
458 for (m = 0; m < num_modes; m++) {
459 for (c = 0; c < own_modes[m].num_channels; c++) {
460 if ((unsigned int) own_modes[m].channels[c].freq !=
461 freq)
462 continue;
463 flag = own_modes[m].channels[c].flag;
464 if (!(flag & (HOSTAPD_CHAN_DISABLED |
465 HOSTAPD_CHAN_NO_IR |
466 HOSTAPD_CHAN_RADAR)))
467 return 1;
468 }
469 }
470
471 wpa_printf(MSG_DEBUG, "DPP: Peer channel %u MHz not supported", freq);
472 return 0;
473}
474
475
476static int freq_included(const unsigned int freqs[], unsigned int num,
477 unsigned int freq)
478{
479 while (num > 0) {
480 if (freqs[--num] == freq)
481 return 1;
482 }
483 return 0;
484}
485
486
487static void freq_to_start(unsigned int freqs[], unsigned int num,
488 unsigned int freq)
489{
490 unsigned int i;
491
492 for (i = 0; i < num; i++) {
493 if (freqs[i] == freq)
494 break;
495 }
496 if (i == 0 || i >= num)
497 return;
498 os_memmove(&freqs[1], &freqs[0], i * sizeof(freqs[0]));
499 freqs[0] = freq;
500}
501
502
503static int dpp_channel_intersect(struct dpp_authentication *auth,
504 struct hostapd_hw_modes *own_modes,
505 u16 num_modes)
506{
507 struct dpp_bootstrap_info *peer_bi = auth->peer_bi;
508 unsigned int i, freq;
509
510 for (i = 0; i < peer_bi->num_freq; i++) {
511 freq = peer_bi->freq[i];
512 if (freq_included(auth->freq, auth->num_freq, freq))
513 continue;
514 if (dpp_channel_ok_init(own_modes, num_modes, freq))
515 auth->freq[auth->num_freq++] = freq;
516 }
517 if (!auth->num_freq) {
518 wpa_printf(MSG_INFO,
519 "DPP: No available channels for initiating DPP Authentication");
520 return -1;
521 }
522 auth->curr_freq = auth->freq[0];
523 return 0;
524}
525
526
527static int dpp_channel_local_list(struct dpp_authentication *auth,
528 struct hostapd_hw_modes *own_modes,
529 u16 num_modes)
530{
531 u16 m;
532 int c, flag;
533 unsigned int freq;
534
535 auth->num_freq = 0;
536
537 if (!own_modes || !num_modes) {
538 auth->freq[0] = 2412;
539 auth->freq[1] = 2437;
540 auth->freq[2] = 2462;
541 auth->num_freq = 3;
542 return 0;
543 }
544
545 for (m = 0; m < num_modes; m++) {
546 for (c = 0; c < own_modes[m].num_channels; c++) {
547 freq = own_modes[m].channels[c].freq;
548 flag = own_modes[m].channels[c].flag;
549 if (flag & (HOSTAPD_CHAN_DISABLED |
550 HOSTAPD_CHAN_NO_IR |
551 HOSTAPD_CHAN_RADAR))
552 continue;
553 if (freq_included(auth->freq, auth->num_freq, freq))
554 continue;
555 auth->freq[auth->num_freq++] = freq;
556 if (auth->num_freq == DPP_BOOTSTRAP_MAX_FREQ) {
557 m = num_modes;
558 break;
559 }
560 }
561 }
562
563 return auth->num_freq == 0 ? -1 : 0;
564}
565
566
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700567int dpp_prepare_channel_list(struct dpp_authentication *auth,
568 unsigned int neg_freq,
569 struct hostapd_hw_modes *own_modes, u16 num_modes)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700570{
571 int res;
572 char freqs[DPP_BOOTSTRAP_MAX_FREQ * 6 + 10], *pos, *end;
573 unsigned int i;
574
Hai Shalomfdcde762020-04-02 11:19:20 -0700575 if (!own_modes) {
576 if (!neg_freq)
577 return -1;
578 auth->num_freq = 1;
579 auth->freq[0] = neg_freq;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700580 auth->curr_freq = neg_freq;
Hai Shalomfdcde762020-04-02 11:19:20 -0700581 return 0;
582 }
583
Roshan Pius3a1667e2018-07-03 15:17:14 -0700584 if (auth->peer_bi->num_freq > 0)
585 res = dpp_channel_intersect(auth, own_modes, num_modes);
586 else
587 res = dpp_channel_local_list(auth, own_modes, num_modes);
588 if (res < 0)
589 return res;
590
591 /* Prioritize 2.4 GHz channels 6, 1, 11 (in this order) to hit the most
592 * likely channels first. */
593 freq_to_start(auth->freq, auth->num_freq, 2462);
594 freq_to_start(auth->freq, auth->num_freq, 2412);
595 freq_to_start(auth->freq, auth->num_freq, 2437);
596
597 auth->freq_idx = 0;
598 auth->curr_freq = auth->freq[0];
599
600 pos = freqs;
601 end = pos + sizeof(freqs);
602 for (i = 0; i < auth->num_freq; i++) {
603 res = os_snprintf(pos, end - pos, " %u", auth->freq[i]);
604 if (os_snprintf_error(end - pos, res))
605 break;
606 pos += res;
607 }
608 *pos = '\0';
609 wpa_printf(MSG_DEBUG, "DPP: Possible frequencies for initiating:%s",
610 freqs);
611
612 return 0;
613}
614
615
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700616int dpp_gen_uri(struct dpp_bootstrap_info *bi)
Hai Shalomfdcde762020-04-02 11:19:20 -0700617{
618 char macstr[ETH_ALEN * 2 + 10];
619 size_t len;
620
621 len = 4; /* "DPP:" */
622 if (bi->chan)
623 len += 3 + os_strlen(bi->chan); /* C:...; */
624 if (is_zero_ether_addr(bi->mac_addr))
625 macstr[0] = '\0';
626 else
627 os_snprintf(macstr, sizeof(macstr), "M:" COMPACT_MACSTR ";",
628 MAC2STR(bi->mac_addr));
629 len += os_strlen(macstr); /* M:...; */
630 if (bi->info)
631 len += 3 + os_strlen(bi->info); /* I:...; */
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700632#ifdef CONFIG_DPP2
633 len += 4; /* V:2; */
634#endif /* CONFIG_DPP2 */
Hai Shalomfdcde762020-04-02 11:19:20 -0700635 len += 4 + os_strlen(bi->pk); /* K:...;; */
636
637 os_free(bi->uri);
638 bi->uri = os_malloc(len + 1);
639 if (!bi->uri)
640 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700641 os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%sK:%s;;",
Hai Shalomfdcde762020-04-02 11:19:20 -0700642 bi->chan ? "C:" : "", bi->chan ? bi->chan : "",
643 bi->chan ? ";" : "",
644 macstr,
645 bi->info ? "I:" : "", bi->info ? bi->info : "",
646 bi->info ? ";" : "",
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700647 DPP_VERSION == 2 ? "V:2;" : "",
Hai Shalomfdcde762020-04-02 11:19:20 -0700648 bi->pk);
649 return 0;
650}
651
652
Hai Shalomfdcde762020-04-02 11:19:20 -0700653struct dpp_authentication *
654dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx)
655{
656 struct dpp_authentication *auth;
657
658 auth = os_zalloc(sizeof(*auth));
659 if (!auth)
660 return NULL;
661 auth->global = dpp;
662 auth->msg_ctx = msg_ctx;
663 auth->conf_resp_status = 255;
664 return auth;
665}
666
667
Hai Shalom021b0b52019-04-10 11:17:58 -0700668static struct wpabuf * dpp_build_conf_req_attr(struct dpp_authentication *auth,
669 const char *json)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700670{
671 size_t nonce_len;
672 size_t json_len, clear_len;
673 struct wpabuf *clear = NULL, *msg = NULL;
674 u8 *wrapped;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700675 size_t attr_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700676
677 wpa_printf(MSG_DEBUG, "DPP: Build configuration request");
678
679 nonce_len = auth->curve->nonce_len;
680 if (random_get_bytes(auth->e_nonce, nonce_len)) {
681 wpa_printf(MSG_ERROR, "DPP: Failed to generate E-nonce");
682 goto fail;
683 }
684 wpa_hexdump(MSG_DEBUG, "DPP: E-nonce", auth->e_nonce, nonce_len);
685 json_len = os_strlen(json);
Hai Shalomc3565922019-10-28 11:58:20 -0700686 wpa_hexdump_ascii(MSG_DEBUG, "DPP: configRequest JSON", json, json_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700687
688 /* { E-nonce, configAttrib }ke */
689 clear_len = 4 + nonce_len + 4 + json_len;
690 clear = wpabuf_alloc(clear_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700691 attr_len = 4 + clear_len + AES_BLOCK_SIZE;
692#ifdef CONFIG_TESTING_OPTIONS
693 if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ)
694 attr_len += 5;
695#endif /* CONFIG_TESTING_OPTIONS */
696 msg = wpabuf_alloc(attr_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700697 if (!clear || !msg)
698 goto fail;
699
Roshan Pius3a1667e2018-07-03 15:17:14 -0700700#ifdef CONFIG_TESTING_OPTIONS
701 if (dpp_test == DPP_TEST_NO_E_NONCE_CONF_REQ) {
702 wpa_printf(MSG_INFO, "DPP: TESTING - no E-nonce");
703 goto skip_e_nonce;
704 }
705 if (dpp_test == DPP_TEST_INVALID_E_NONCE_CONF_REQ) {
706 wpa_printf(MSG_INFO, "DPP: TESTING - invalid E-nonce");
707 wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE);
708 wpabuf_put_le16(clear, nonce_len - 1);
709 wpabuf_put_data(clear, auth->e_nonce, nonce_len - 1);
710 goto skip_e_nonce;
711 }
712 if (dpp_test == DPP_TEST_NO_WRAPPED_DATA_CONF_REQ) {
713 wpa_printf(MSG_INFO, "DPP: TESTING - no Wrapped Data");
714 goto skip_wrapped_data;
715 }
716#endif /* CONFIG_TESTING_OPTIONS */
717
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700718 /* E-nonce */
719 wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE);
720 wpabuf_put_le16(clear, nonce_len);
721 wpabuf_put_data(clear, auth->e_nonce, nonce_len);
722
Roshan Pius3a1667e2018-07-03 15:17:14 -0700723#ifdef CONFIG_TESTING_OPTIONS
724skip_e_nonce:
725 if (dpp_test == DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ) {
726 wpa_printf(MSG_INFO, "DPP: TESTING - no configAttrib");
727 goto skip_conf_attr_obj;
728 }
729#endif /* CONFIG_TESTING_OPTIONS */
730
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700731 /* configAttrib */
732 wpabuf_put_le16(clear, DPP_ATTR_CONFIG_ATTR_OBJ);
733 wpabuf_put_le16(clear, json_len);
734 wpabuf_put_data(clear, json, json_len);
735
Roshan Pius3a1667e2018-07-03 15:17:14 -0700736#ifdef CONFIG_TESTING_OPTIONS
737skip_conf_attr_obj:
738#endif /* CONFIG_TESTING_OPTIONS */
739
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700740 wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA);
741 wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
742 wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
743
744 /* No AES-SIV AD */
745 wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear);
746 if (aes_siv_encrypt(auth->ke, auth->curve->hash_len,
747 wpabuf_head(clear), wpabuf_len(clear),
748 0, NULL, NULL, wrapped) < 0)
749 goto fail;
750 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext",
751 wrapped, wpabuf_len(clear) + AES_BLOCK_SIZE);
752
Roshan Pius3a1667e2018-07-03 15:17:14 -0700753#ifdef CONFIG_TESTING_OPTIONS
754 if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ) {
755 wpa_printf(MSG_INFO, "DPP: TESTING - attr after Wrapped Data");
756 dpp_build_attr_status(msg, DPP_STATUS_OK);
757 }
758skip_wrapped_data:
759#endif /* CONFIG_TESTING_OPTIONS */
760
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700761 wpa_hexdump_buf(MSG_DEBUG,
762 "DPP: Configuration Request frame attributes", msg);
763 wpabuf_free(clear);
764 return msg;
765
766fail:
767 wpabuf_free(clear);
768 wpabuf_free(msg);
769 return NULL;
770}
771
772
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700773void dpp_write_adv_proto(struct wpabuf *buf)
Hai Shalom021b0b52019-04-10 11:17:58 -0700774{
775 /* Advertisement Protocol IE */
776 wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
777 wpabuf_put_u8(buf, 8); /* Length */
778 wpabuf_put_u8(buf, 0x7f);
779 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
780 wpabuf_put_u8(buf, 5);
781 wpabuf_put_be24(buf, OUI_WFA);
782 wpabuf_put_u8(buf, DPP_OUI_TYPE);
783 wpabuf_put_u8(buf, 0x01);
784}
785
786
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700787void dpp_write_gas_query(struct wpabuf *buf, struct wpabuf *query)
Hai Shalom021b0b52019-04-10 11:17:58 -0700788{
789 /* GAS Query */
790 wpabuf_put_le16(buf, wpabuf_len(query));
791 wpabuf_put_buf(buf, query);
792}
793
794
795struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
796 const char *json)
797{
798 struct wpabuf *buf, *conf_req;
799
800 conf_req = dpp_build_conf_req_attr(auth, json);
801 if (!conf_req) {
802 wpa_printf(MSG_DEBUG,
803 "DPP: No configuration request data available");
804 return NULL;
805 }
806
807 buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
808 if (!buf) {
809 wpabuf_free(conf_req);
810 return NULL;
811 }
812
813 dpp_write_adv_proto(buf);
814 dpp_write_gas_query(buf, conf_req);
815 wpabuf_free(conf_req);
816 wpa_hexdump_buf(MSG_MSGDUMP, "DPP: GAS Config Request", buf);
817
818 return buf;
819}
820
821
Hai Shalomc3565922019-10-28 11:58:20 -0700822struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800823 const char *name,
824 enum dpp_netrole netrole,
Hai Shalomc3565922019-10-28 11:58:20 -0700825 const char *mud_url, int *opclasses)
826{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800827 size_t len, name_len;
Hai Shalomc3565922019-10-28 11:58:20 -0700828 const char *tech = "infra";
829 const char *dpp_name;
Hai Shalomc3565922019-10-28 11:58:20 -0700830 struct wpabuf *buf, *json;
831
832#ifdef CONFIG_TESTING_OPTIONS
833 if (dpp_test == DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ) {
834 static const char *bogus_tech = "knfra";
835
836 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Config Attr");
837 tech = bogus_tech;
838 }
839#endif /* CONFIG_TESTING_OPTIONS */
840
841 dpp_name = name ? name : "Test";
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800842 name_len = os_strlen(dpp_name);
Hai Shalomc3565922019-10-28 11:58:20 -0700843
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800844 len = 100 + name_len * 6 + 1 + int_array_len(opclasses) * 4;
Hai Shalomc3565922019-10-28 11:58:20 -0700845 if (mud_url && mud_url[0])
846 len += 10 + os_strlen(mud_url);
847 json = wpabuf_alloc(len);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800848 if (!json)
849 return NULL;
850
851 json_start_object(json, NULL);
852 if (json_add_string_escape(json, "name", dpp_name, name_len) < 0) {
853 wpabuf_free(json);
Hai Shalomc3565922019-10-28 11:58:20 -0700854 return NULL;
855 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800856 json_value_sep(json);
857 json_add_string(json, "wi-fi_tech", tech);
858 json_value_sep(json);
859 json_add_string(json, "netRole", dpp_netrole_str(netrole));
860 if (mud_url && mud_url[0]) {
861 json_value_sep(json);
862 json_add_string(json, "mudurl", mud_url);
863 }
Hai Shalomc3565922019-10-28 11:58:20 -0700864 if (opclasses) {
865 int i;
866
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800867 json_value_sep(json);
868 json_start_array(json, "bandSupport");
Hai Shalomc3565922019-10-28 11:58:20 -0700869 for (i = 0; opclasses[i]; i++)
870 wpabuf_printf(json, "%s%u", i ? "," : "", opclasses[i]);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800871 json_end_array(json);
Hai Shalomc3565922019-10-28 11:58:20 -0700872 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800873 json_end_object(json);
Hai Shalomc3565922019-10-28 11:58:20 -0700874
875 buf = dpp_build_conf_req(auth, wpabuf_head(json));
876 wpabuf_free(json);
877
878 return buf;
879}
880
881
Hai Shalom021b0b52019-04-10 11:17:58 -0700882static int bin_str_eq(const char *val, size_t len, const char *cmp)
883{
884 return os_strlen(cmp) == len && os_memcmp(val, cmp, len) == 0;
885}
886
887
888struct dpp_configuration * dpp_configuration_alloc(const char *type)
889{
890 struct dpp_configuration *conf;
891 const char *end;
892 size_t len;
893
894 conf = os_zalloc(sizeof(*conf));
895 if (!conf)
896 goto fail;
897
898 end = os_strchr(type, ' ');
899 if (end)
900 len = end - type;
901 else
902 len = os_strlen(type);
903
904 if (bin_str_eq(type, len, "psk"))
905 conf->akm = DPP_AKM_PSK;
906 else if (bin_str_eq(type, len, "sae"))
907 conf->akm = DPP_AKM_SAE;
908 else if (bin_str_eq(type, len, "psk-sae") ||
909 bin_str_eq(type, len, "psk+sae"))
910 conf->akm = DPP_AKM_PSK_SAE;
911 else if (bin_str_eq(type, len, "sae-dpp") ||
912 bin_str_eq(type, len, "dpp+sae"))
913 conf->akm = DPP_AKM_SAE_DPP;
914 else if (bin_str_eq(type, len, "psk-sae-dpp") ||
915 bin_str_eq(type, len, "dpp+psk+sae"))
916 conf->akm = DPP_AKM_PSK_SAE_DPP;
917 else if (bin_str_eq(type, len, "dpp"))
918 conf->akm = DPP_AKM_DPP;
919 else
920 goto fail;
921
922 return conf;
923fail:
924 dpp_configuration_free(conf);
925 return NULL;
926}
927
928
929int dpp_akm_psk(enum dpp_akm akm)
930{
931 return akm == DPP_AKM_PSK || akm == DPP_AKM_PSK_SAE ||
932 akm == DPP_AKM_PSK_SAE_DPP;
933}
934
935
936int dpp_akm_sae(enum dpp_akm akm)
937{
938 return akm == DPP_AKM_SAE || akm == DPP_AKM_PSK_SAE ||
939 akm == DPP_AKM_SAE_DPP || akm == DPP_AKM_PSK_SAE_DPP;
940}
941
942
943int dpp_akm_legacy(enum dpp_akm akm)
944{
945 return akm == DPP_AKM_PSK || akm == DPP_AKM_PSK_SAE ||
946 akm == DPP_AKM_SAE;
947}
948
949
950int dpp_akm_dpp(enum dpp_akm akm)
951{
952 return akm == DPP_AKM_DPP || akm == DPP_AKM_SAE_DPP ||
953 akm == DPP_AKM_PSK_SAE_DPP;
954}
955
956
957int dpp_akm_ver2(enum dpp_akm akm)
958{
959 return akm == DPP_AKM_SAE_DPP || akm == DPP_AKM_PSK_SAE_DPP;
960}
961
962
963int dpp_configuration_valid(const struct dpp_configuration *conf)
964{
965 if (conf->ssid_len == 0)
966 return 0;
967 if (dpp_akm_psk(conf->akm) && !conf->passphrase && !conf->psk_set)
968 return 0;
969 if (dpp_akm_sae(conf->akm) && !conf->passphrase)
970 return 0;
971 return 1;
972}
973
974
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700975void dpp_configuration_free(struct dpp_configuration *conf)
976{
977 if (!conf)
978 return;
979 str_clear_free(conf->passphrase);
Hai Shalomce48b4a2018-09-05 11:41:35 -0700980 os_free(conf->group_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700981 bin_clear_free(conf, sizeof(*conf));
982}
983
984
Hai Shalomc3565922019-10-28 11:58:20 -0700985static int dpp_configuration_parse_helper(struct dpp_authentication *auth,
986 const char *cmd, int idx)
Hai Shalom021b0b52019-04-10 11:17:58 -0700987{
988 const char *pos, *end;
989 struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
990 struct dpp_configuration *conf = NULL;
991
992 pos = os_strstr(cmd, " conf=sta-");
993 if (pos) {
994 conf_sta = dpp_configuration_alloc(pos + 10);
995 if (!conf_sta)
996 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -0700997 conf_sta->netrole = DPP_NETROLE_STA;
Hai Shalom021b0b52019-04-10 11:17:58 -0700998 conf = conf_sta;
999 }
1000
1001 pos = os_strstr(cmd, " conf=ap-");
1002 if (pos) {
1003 conf_ap = dpp_configuration_alloc(pos + 9);
1004 if (!conf_ap)
1005 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07001006 conf_ap->netrole = DPP_NETROLE_AP;
Hai Shalom021b0b52019-04-10 11:17:58 -07001007 conf = conf_ap;
1008 }
1009
Hai Shalomfdcde762020-04-02 11:19:20 -07001010 pos = os_strstr(cmd, " conf=configurator");
1011 if (pos)
1012 auth->provision_configurator = 1;
1013
Hai Shalom021b0b52019-04-10 11:17:58 -07001014 if (!conf)
1015 return 0;
1016
1017 pos = os_strstr(cmd, " ssid=");
1018 if (pos) {
1019 pos += 6;
1020 end = os_strchr(pos, ' ');
1021 conf->ssid_len = end ? (size_t) (end - pos) : os_strlen(pos);
1022 conf->ssid_len /= 2;
1023 if (conf->ssid_len > sizeof(conf->ssid) ||
1024 hexstr2bin(pos, conf->ssid, conf->ssid_len) < 0)
1025 goto fail;
1026 } else {
1027#ifdef CONFIG_TESTING_OPTIONS
1028 /* use a default SSID for legacy testing reasons */
1029 os_memcpy(conf->ssid, "test", 4);
1030 conf->ssid_len = 4;
1031#else /* CONFIG_TESTING_OPTIONS */
1032 goto fail;
1033#endif /* CONFIG_TESTING_OPTIONS */
1034 }
1035
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001036 pos = os_strstr(cmd, " ssid_charset=");
1037 if (pos) {
1038 if (conf_ap) {
1039 wpa_printf(MSG_INFO,
1040 "DPP: ssid64 option (ssid_charset param) not allowed for AP enrollee");
1041 goto fail;
1042 }
1043 conf->ssid_charset = atoi(pos + 14);
1044 }
1045
Hai Shalom021b0b52019-04-10 11:17:58 -07001046 pos = os_strstr(cmd, " pass=");
1047 if (pos) {
1048 size_t pass_len;
1049
1050 pos += 6;
1051 end = os_strchr(pos, ' ');
1052 pass_len = end ? (size_t) (end - pos) : os_strlen(pos);
1053 pass_len /= 2;
1054 if (pass_len > 63 || pass_len < 8)
1055 goto fail;
1056 conf->passphrase = os_zalloc(pass_len + 1);
1057 if (!conf->passphrase ||
1058 hexstr2bin(pos, (u8 *) conf->passphrase, pass_len) < 0)
1059 goto fail;
1060 }
1061
1062 pos = os_strstr(cmd, " psk=");
1063 if (pos) {
1064 pos += 5;
1065 if (hexstr2bin(pos, conf->psk, PMK_LEN) < 0)
1066 goto fail;
1067 conf->psk_set = 1;
1068 }
1069
1070 pos = os_strstr(cmd, " group_id=");
1071 if (pos) {
1072 size_t group_id_len;
1073
1074 pos += 10;
1075 end = os_strchr(pos, ' ');
1076 group_id_len = end ? (size_t) (end - pos) : os_strlen(pos);
1077 conf->group_id = os_malloc(group_id_len + 1);
1078 if (!conf->group_id)
1079 goto fail;
1080 os_memcpy(conf->group_id, pos, group_id_len);
1081 conf->group_id[group_id_len] = '\0';
1082 }
1083
1084 pos = os_strstr(cmd, " expiry=");
1085 if (pos) {
1086 long int val;
1087
1088 pos += 8;
1089 val = strtol(pos, NULL, 0);
1090 if (val <= 0)
1091 goto fail;
1092 conf->netaccesskey_expiry = val;
1093 }
1094
1095 if (!dpp_configuration_valid(conf))
1096 goto fail;
1097
Hai Shalomc3565922019-10-28 11:58:20 -07001098 if (idx == 0) {
1099 auth->conf_sta = conf_sta;
1100 auth->conf_ap = conf_ap;
1101 } else if (idx == 1) {
1102 auth->conf2_sta = conf_sta;
1103 auth->conf2_ap = conf_ap;
1104 } else {
1105 goto fail;
1106 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001107 return 0;
1108
1109fail:
1110 dpp_configuration_free(conf_sta);
1111 dpp_configuration_free(conf_ap);
1112 return -1;
1113}
1114
1115
Hai Shalomc3565922019-10-28 11:58:20 -07001116static int dpp_configuration_parse(struct dpp_authentication *auth,
1117 const char *cmd)
1118{
1119 const char *pos;
1120 char *tmp;
1121 size_t len;
1122 int res;
1123
1124 pos = os_strstr(cmd, " @CONF-OBJ-SEP@ ");
1125 if (!pos)
1126 return dpp_configuration_parse_helper(auth, cmd, 0);
1127
1128 len = pos - cmd;
1129 tmp = os_malloc(len + 1);
1130 if (!tmp)
1131 goto fail;
1132 os_memcpy(tmp, cmd, len);
1133 tmp[len] = '\0';
1134 res = dpp_configuration_parse_helper(auth, cmd, 0);
1135 str_clear_free(tmp);
1136 if (res)
1137 goto fail;
1138 res = dpp_configuration_parse_helper(auth, cmd + len, 1);
1139 if (res)
1140 goto fail;
1141 return 0;
1142fail:
1143 dpp_configuration_free(auth->conf_sta);
1144 dpp_configuration_free(auth->conf2_sta);
1145 dpp_configuration_free(auth->conf_ap);
1146 dpp_configuration_free(auth->conf2_ap);
1147 return -1;
1148}
1149
1150
Hai Shalom021b0b52019-04-10 11:17:58 -07001151static struct dpp_configurator *
1152dpp_configurator_get_id(struct dpp_global *dpp, unsigned int id)
1153{
1154 struct dpp_configurator *conf;
1155
1156 if (!dpp)
1157 return NULL;
1158
1159 dl_list_for_each(conf, &dpp->configurator,
1160 struct dpp_configurator, list) {
1161 if (conf->id == id)
1162 return conf;
1163 }
1164 return NULL;
1165}
1166
1167
Hai Shalomfdcde762020-04-02 11:19:20 -07001168int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd)
Hai Shalom021b0b52019-04-10 11:17:58 -07001169{
1170 const char *pos;
Hai Shalomfdcde762020-04-02 11:19:20 -07001171 char *tmp = NULL;
1172 int ret = -1;
Hai Shalom021b0b52019-04-10 11:17:58 -07001173
Hai Shalomfdcde762020-04-02 11:19:20 -07001174 if (!cmd || auth->configurator_set)
Hai Shalom021b0b52019-04-10 11:17:58 -07001175 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001176 auth->configurator_set = 1;
1177
1178 if (cmd[0] != ' ') {
1179 size_t len;
1180
1181 len = os_strlen(cmd);
1182 tmp = os_malloc(len + 2);
1183 if (!tmp)
1184 goto fail;
1185 tmp[0] = ' ';
1186 os_memcpy(tmp + 1, cmd, len + 1);
1187 cmd = tmp;
1188 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001189
1190 wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd);
1191
1192 pos = os_strstr(cmd, " configurator=");
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001193 if (!auth->conf && pos) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001194 pos += 14;
Hai Shalomfdcde762020-04-02 11:19:20 -07001195 auth->conf = dpp_configurator_get_id(auth->global, atoi(pos));
Hai Shalom021b0b52019-04-10 11:17:58 -07001196 if (!auth->conf) {
1197 wpa_printf(MSG_INFO,
1198 "DPP: Could not find the specified configurator");
Hai Shalomfdcde762020-04-02 11:19:20 -07001199 goto fail;
Hai Shalom021b0b52019-04-10 11:17:58 -07001200 }
1201 }
1202
Hai Shalomc3565922019-10-28 11:58:20 -07001203 pos = os_strstr(cmd, " conn_status=");
1204 if (pos) {
1205 pos += 13;
1206 auth->send_conn_status = atoi(pos);
1207 }
1208
1209 pos = os_strstr(cmd, " akm_use_selector=");
1210 if (pos) {
1211 pos += 18;
1212 auth->akm_use_selector = atoi(pos);
1213 }
1214
Hai Shalom021b0b52019-04-10 11:17:58 -07001215 if (dpp_configuration_parse(auth, cmd) < 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001216 wpa_msg(auth->msg_ctx, MSG_INFO,
Hai Shalom021b0b52019-04-10 11:17:58 -07001217 "DPP: Failed to set configurator parameters");
Hai Shalomfdcde762020-04-02 11:19:20 -07001218 goto fail;
Hai Shalom021b0b52019-04-10 11:17:58 -07001219 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001220 ret = 0;
1221fail:
1222 os_free(tmp);
1223 return ret;
1224}
1225
1226
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001227void dpp_auth_deinit(struct dpp_authentication *auth)
1228{
Hai Shalomc3565922019-10-28 11:58:20 -07001229 unsigned int i;
1230
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001231 if (!auth)
1232 return;
1233 dpp_configuration_free(auth->conf_ap);
Hai Shalomc3565922019-10-28 11:58:20 -07001234 dpp_configuration_free(auth->conf2_ap);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001235 dpp_configuration_free(auth->conf_sta);
Hai Shalomc3565922019-10-28 11:58:20 -07001236 dpp_configuration_free(auth->conf2_sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001237 EVP_PKEY_free(auth->own_protocol_key);
1238 EVP_PKEY_free(auth->peer_protocol_key);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001239 EVP_PKEY_free(auth->reconfig_old_protocol_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001240 wpabuf_free(auth->req_msg);
1241 wpabuf_free(auth->resp_msg);
1242 wpabuf_free(auth->conf_req);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001243 wpabuf_free(auth->reconfig_req_msg);
1244 wpabuf_free(auth->reconfig_resp_msg);
Hai Shalomc3565922019-10-28 11:58:20 -07001245 for (i = 0; i < auth->num_conf_obj; i++) {
1246 struct dpp_config_obj *conf = &auth->conf_obj[i];
1247
1248 os_free(conf->connector);
1249 wpabuf_free(conf->c_sign_key);
1250 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001251#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -07001252 dpp_free_asymmetric_key(auth->conf_key_pkg);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001253#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001254 wpabuf_free(auth->net_access_key);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001255 dpp_bootstrap_info_free(auth->tmp_own_bi);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001256#ifdef CONFIG_TESTING_OPTIONS
1257 os_free(auth->config_obj_override);
1258 os_free(auth->discovery_override);
1259 os_free(auth->groups_override);
1260#endif /* CONFIG_TESTING_OPTIONS */
1261 bin_clear_free(auth, sizeof(*auth));
1262}
1263
1264
1265static struct wpabuf *
1266dpp_build_conf_start(struct dpp_authentication *auth,
1267 struct dpp_configuration *conf, size_t tailroom)
1268{
1269 struct wpabuf *buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001270
1271#ifdef CONFIG_TESTING_OPTIONS
1272 if (auth->discovery_override)
1273 tailroom += os_strlen(auth->discovery_override);
1274#endif /* CONFIG_TESTING_OPTIONS */
1275
1276 buf = wpabuf_alloc(200 + tailroom);
1277 if (!buf)
1278 return NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001279 json_start_object(buf, NULL);
1280 json_add_string(buf, "wi-fi_tech", "infra");
1281 json_value_sep(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001282#ifdef CONFIG_TESTING_OPTIONS
1283 if (auth->discovery_override) {
1284 wpa_printf(MSG_DEBUG, "DPP: TESTING - discovery override: '%s'",
1285 auth->discovery_override);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001286 wpabuf_put_str(buf, "\"discovery\":");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001287 wpabuf_put_str(buf, auth->discovery_override);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001288 json_value_sep(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001289 return buf;
1290 }
1291#endif /* CONFIG_TESTING_OPTIONS */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001292 json_start_object(buf, "discovery");
1293 if (((!conf->ssid_charset || auth->peer_version < 2) &&
1294 json_add_string_escape(buf, "ssid", conf->ssid,
1295 conf->ssid_len) < 0) ||
1296 ((conf->ssid_charset && auth->peer_version >= 2) &&
1297 json_add_base64url(buf, "ssid64", conf->ssid,
1298 conf->ssid_len) < 0)) {
1299 wpabuf_free(buf);
1300 return NULL;
1301 }
1302 if (conf->ssid_charset > 0) {
1303 json_value_sep(buf);
1304 json_add_int(buf, "ssid_charset", conf->ssid_charset);
1305 }
1306 json_end_object(buf);
1307 json_value_sep(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001308
1309 return buf;
1310}
1311
1312
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001313int dpp_build_jwk(struct wpabuf *buf, const char *name, EVP_PKEY *key,
1314 const char *kid, const struct dpp_curve_params *curve)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001315{
1316 struct wpabuf *pub;
1317 const u8 *pos;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001318 int ret = -1;
1319
1320 pub = dpp_get_pubkey_point(key, 0);
1321 if (!pub)
1322 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001323
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001324 json_start_object(buf, name);
1325 json_add_string(buf, "kty", "EC");
1326 json_value_sep(buf);
1327 json_add_string(buf, "crv", curve->jwk_crv);
1328 json_value_sep(buf);
1329 pos = wpabuf_head(pub);
1330 if (json_add_base64url(buf, "x", pos, curve->prime_len) < 0)
1331 goto fail;
1332 json_value_sep(buf);
1333 pos += curve->prime_len;
1334 if (json_add_base64url(buf, "y", pos, curve->prime_len) < 0)
1335 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001336 if (kid) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001337 json_value_sep(buf);
1338 json_add_string(buf, "kid", kid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001339 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001340 json_end_object(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001341 ret = 0;
1342fail:
1343 wpabuf_free(pub);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001344 return ret;
1345}
1346
1347
Hai Shalom021b0b52019-04-10 11:17:58 -07001348static void dpp_build_legacy_cred_params(struct wpabuf *buf,
1349 struct dpp_configuration *conf)
1350{
1351 if (conf->passphrase && os_strlen(conf->passphrase) < 64) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001352 json_add_string_escape(buf, "pass", conf->passphrase,
1353 os_strlen(conf->passphrase));
Hai Shalom021b0b52019-04-10 11:17:58 -07001354 } else if (conf->psk_set) {
1355 char psk[2 * sizeof(conf->psk) + 1];
1356
1357 wpa_snprintf_hex(psk, sizeof(psk),
1358 conf->psk, sizeof(conf->psk));
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001359 json_add_string(buf, "psk_hex", psk);
1360 forced_memzero(psk, sizeof(psk));
Hai Shalom021b0b52019-04-10 11:17:58 -07001361 }
1362}
1363
1364
Hai Shalomc3565922019-10-28 11:58:20 -07001365static const char * dpp_netrole_str(enum dpp_netrole netrole)
1366{
1367 switch (netrole) {
1368 case DPP_NETROLE_STA:
1369 return "sta";
1370 case DPP_NETROLE_AP:
1371 return "ap";
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001372 case DPP_NETROLE_CONFIGURATOR:
1373 return "configurator";
Hai Shalomc3565922019-10-28 11:58:20 -07001374 default:
1375 return "??";
1376 }
1377}
1378
1379
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001380static struct wpabuf *
Hai Shalomc3565922019-10-28 11:58:20 -07001381dpp_build_conf_obj_dpp(struct dpp_authentication *auth,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001382 struct dpp_configuration *conf)
1383{
1384 struct wpabuf *buf = NULL;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001385 char *signed_conn = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001386 size_t tailroom;
1387 const struct dpp_curve_params *curve;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001388 struct wpabuf *dppcon = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001389 size_t extra_len = 1000;
Hai Shalom021b0b52019-04-10 11:17:58 -07001390 int incl_legacy;
1391 enum dpp_akm akm;
Hai Shalomc3565922019-10-28 11:58:20 -07001392 const char *akm_str;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001393
1394 if (!auth->conf) {
1395 wpa_printf(MSG_INFO,
1396 "DPP: No configurator specified - cannot generate DPP config object");
1397 goto fail;
1398 }
1399 curve = auth->conf->curve;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001400
Hai Shalom021b0b52019-04-10 11:17:58 -07001401 akm = conf->akm;
1402 if (dpp_akm_ver2(akm) && auth->peer_version < 2) {
1403 wpa_printf(MSG_DEBUG,
1404 "DPP: Convert DPP+legacy credential to DPP-only for peer that does not support version 2");
1405 akm = DPP_AKM_DPP;
1406 }
1407
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001408#ifdef CONFIG_TESTING_OPTIONS
1409 if (auth->groups_override)
1410 extra_len += os_strlen(auth->groups_override);
1411#endif /* CONFIG_TESTING_OPTIONS */
1412
Hai Shalomce48b4a2018-09-05 11:41:35 -07001413 if (conf->group_id)
1414 extra_len += os_strlen(conf->group_id);
1415
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001416 /* Connector (JSON dppCon object) */
1417 dppcon = wpabuf_alloc(extra_len + 2 * auth->curve->prime_len * 4 / 3);
1418 if (!dppcon)
1419 goto fail;
1420#ifdef CONFIG_TESTING_OPTIONS
1421 if (auth->groups_override) {
1422 wpabuf_put_u8(dppcon, '{');
1423 if (auth->groups_override) {
1424 wpa_printf(MSG_DEBUG,
1425 "DPP: TESTING - groups override: '%s'",
1426 auth->groups_override);
1427 wpabuf_put_str(dppcon, "\"groups\":");
1428 wpabuf_put_str(dppcon, auth->groups_override);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001429 json_value_sep(dppcon);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001430 }
1431 goto skip_groups;
1432 }
1433#endif /* CONFIG_TESTING_OPTIONS */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001434 json_start_object(dppcon, NULL);
1435 json_start_array(dppcon, "groups");
1436 json_start_object(dppcon, NULL);
1437 json_add_string(dppcon, "groupId",
1438 conf->group_id ? conf->group_id : "*");
1439 json_value_sep(dppcon);
1440 json_add_string(dppcon, "netRole", dpp_netrole_str(conf->netrole));
1441 json_end_object(dppcon);
1442 json_end_array(dppcon);
1443 json_value_sep(dppcon);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001444#ifdef CONFIG_TESTING_OPTIONS
1445skip_groups:
1446#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001447 if (!auth->peer_protocol_key ||
1448 dpp_build_jwk(dppcon, "netAccessKey", auth->peer_protocol_key, NULL,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001449 auth->curve) < 0) {
1450 wpa_printf(MSG_DEBUG, "DPP: Failed to build netAccessKey JWK");
1451 goto fail;
1452 }
1453 if (conf->netaccesskey_expiry) {
1454 struct os_tm tm;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001455 char expiry[30];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001456
1457 if (os_gmtime(conf->netaccesskey_expiry, &tm) < 0) {
1458 wpa_printf(MSG_DEBUG,
1459 "DPP: Failed to generate expiry string");
1460 goto fail;
1461 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001462 os_snprintf(expiry, sizeof(expiry),
1463 "%04u-%02u-%02uT%02u:%02u:%02uZ",
1464 tm.year, tm.month, tm.day,
1465 tm.hour, tm.min, tm.sec);
1466 json_value_sep(dppcon);
1467 json_add_string(dppcon, "expiry", expiry);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001468 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001469 json_end_object(dppcon);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001470 wpa_printf(MSG_DEBUG, "DPP: dppCon: %s",
1471 (const char *) wpabuf_head(dppcon));
1472
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001473 signed_conn = dpp_sign_connector(auth->conf, dppcon);
1474 if (!signed_conn)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001475 goto fail;
1476
Hai Shalom021b0b52019-04-10 11:17:58 -07001477 incl_legacy = dpp_akm_psk(akm) || dpp_akm_sae(akm);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001478 tailroom = 1000;
1479 tailroom += 2 * curve->prime_len * 4 / 3 + os_strlen(auth->conf->kid);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001480 tailroom += os_strlen(signed_conn);
Hai Shalom021b0b52019-04-10 11:17:58 -07001481 if (incl_legacy)
1482 tailroom += 1000;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001483 buf = dpp_build_conf_start(auth, conf, tailroom);
1484 if (!buf)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001485 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001486
Hai Shalomc3565922019-10-28 11:58:20 -07001487 if (auth->akm_use_selector && dpp_akm_ver2(akm))
1488 akm_str = dpp_akm_selector_str(akm);
1489 else
1490 akm_str = dpp_akm_str(akm);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001491 json_start_object(buf, "cred");
1492 json_add_string(buf, "akm", akm_str);
1493 json_value_sep(buf);
Hai Shalom021b0b52019-04-10 11:17:58 -07001494 if (incl_legacy) {
1495 dpp_build_legacy_cred_params(buf, conf);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001496 json_value_sep(buf);
Hai Shalom021b0b52019-04-10 11:17:58 -07001497 }
1498 wpabuf_put_str(buf, "\"signedConnector\":\"");
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001499 wpabuf_put_str(buf, signed_conn);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001500 wpabuf_put_str(buf, "\"");
1501 json_value_sep(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001502 if (dpp_build_jwk(buf, "csign", auth->conf->csign, auth->conf->kid,
1503 curve) < 0) {
1504 wpa_printf(MSG_DEBUG, "DPP: Failed to build csign JWK");
1505 goto fail;
1506 }
1507
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001508 json_end_object(buf);
1509 json_end_object(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001510
1511 wpa_hexdump_ascii_key(MSG_DEBUG, "DPP: Configuration Object",
1512 wpabuf_head(buf), wpabuf_len(buf));
1513
1514out:
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001515 os_free(signed_conn);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001516 wpabuf_free(dppcon);
1517 return buf;
1518fail:
1519 wpa_printf(MSG_DEBUG, "DPP: Failed to build configuration object");
1520 wpabuf_free(buf);
1521 buf = NULL;
1522 goto out;
1523}
1524
1525
1526static struct wpabuf *
Hai Shalomc3565922019-10-28 11:58:20 -07001527dpp_build_conf_obj_legacy(struct dpp_authentication *auth,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001528 struct dpp_configuration *conf)
1529{
1530 struct wpabuf *buf;
Hai Shalomc3565922019-10-28 11:58:20 -07001531 const char *akm_str;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001532
1533 buf = dpp_build_conf_start(auth, conf, 1000);
1534 if (!buf)
1535 return NULL;
1536
Hai Shalomc3565922019-10-28 11:58:20 -07001537 if (auth->akm_use_selector && dpp_akm_ver2(conf->akm))
1538 akm_str = dpp_akm_selector_str(conf->akm);
1539 else
1540 akm_str = dpp_akm_str(conf->akm);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001541 json_start_object(buf, "cred");
1542 json_add_string(buf, "akm", akm_str);
1543 json_value_sep(buf);
Hai Shalom021b0b52019-04-10 11:17:58 -07001544 dpp_build_legacy_cred_params(buf, conf);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001545 json_end_object(buf);
1546 json_end_object(buf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001547
1548 wpa_hexdump_ascii_key(MSG_DEBUG, "DPP: Configuration Object (legacy)",
1549 wpabuf_head(buf), wpabuf_len(buf));
1550
1551 return buf;
1552}
1553
1554
1555static struct wpabuf *
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001556dpp_build_conf_obj(struct dpp_authentication *auth, enum dpp_netrole netrole,
1557 int idx)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001558{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001559 struct dpp_configuration *conf = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001560
1561#ifdef CONFIG_TESTING_OPTIONS
1562 if (auth->config_obj_override) {
Hai Shalomc3565922019-10-28 11:58:20 -07001563 if (idx != 0)
1564 return NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001565 wpa_printf(MSG_DEBUG, "DPP: Testing - Config Object override");
1566 return wpabuf_alloc_copy(auth->config_obj_override,
1567 os_strlen(auth->config_obj_override));
1568 }
1569#endif /* CONFIG_TESTING_OPTIONS */
1570
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001571 if (idx == 0) {
1572 if (netrole == DPP_NETROLE_STA)
1573 conf = auth->conf_sta;
1574 else if (netrole == DPP_NETROLE_AP)
1575 conf = auth->conf_ap;
1576 } else if (idx == 1) {
1577 if (netrole == DPP_NETROLE_STA)
1578 conf = auth->conf2_sta;
1579 else if (netrole == DPP_NETROLE_AP)
1580 conf = auth->conf2_ap;
1581 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001582 if (!conf) {
Hai Shalomc3565922019-10-28 11:58:20 -07001583 if (idx == 0)
1584 wpa_printf(MSG_DEBUG,
1585 "DPP: No configuration available for Enrollee(%s) - reject configuration request",
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001586 dpp_netrole_str(netrole));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001587 return NULL;
1588 }
1589
Hai Shalomfdcde762020-04-02 11:19:20 -07001590 if (dpp_akm_dpp(conf->akm) || (auth->peer_version >= 2 && auth->conf))
Hai Shalomc3565922019-10-28 11:58:20 -07001591 return dpp_build_conf_obj_dpp(auth, conf);
1592 return dpp_build_conf_obj_legacy(auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001593}
1594
1595
1596static struct wpabuf *
1597dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001598 u16 e_nonce_len, enum dpp_netrole netrole)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001599{
Hai Shalomfdcde762020-04-02 11:19:20 -07001600 struct wpabuf *conf = NULL, *conf2 = NULL, *env_data = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001601 size_t clear_len, attr_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001602 struct wpabuf *clear = NULL, *msg = NULL;
1603 u8 *wrapped;
1604 const u8 *addr[1];
1605 size_t len[1];
1606 enum dpp_status_error status;
1607
Hai Shalomfdcde762020-04-02 11:19:20 -07001608 if (netrole == DPP_NETROLE_CONFIGURATOR) {
1609#ifdef CONFIG_DPP2
1610 env_data = dpp_build_enveloped_data(auth);
1611#endif /* CONFIG_DPP2 */
1612 } else {
1613 conf = dpp_build_conf_obj(auth, netrole, 0);
1614 if (conf) {
1615 wpa_hexdump_ascii(MSG_DEBUG,
1616 "DPP: configurationObject JSON",
1617 wpabuf_head(conf), wpabuf_len(conf));
1618 conf2 = dpp_build_conf_obj(auth, netrole, 1);
1619 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001620 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001621 status = (conf || env_data) ? DPP_STATUS_OK :
1622 DPP_STATUS_CONFIGURE_FAILURE;
Hai Shalom021b0b52019-04-10 11:17:58 -07001623 auth->conf_resp_status = status;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001624
Hai Shalomc3565922019-10-28 11:58:20 -07001625 /* { E-nonce, configurationObject[, sendConnStatus]}ke */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001626 clear_len = 4 + e_nonce_len;
1627 if (conf)
1628 clear_len += 4 + wpabuf_len(conf);
Hai Shalomc3565922019-10-28 11:58:20 -07001629 if (conf2)
1630 clear_len += 4 + wpabuf_len(conf2);
Hai Shalomfdcde762020-04-02 11:19:20 -07001631 if (env_data)
1632 clear_len += 4 + wpabuf_len(env_data);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001633 if (auth->peer_version >= 2 && auth->send_conn_status &&
1634 netrole == DPP_NETROLE_STA)
Hai Shalomc3565922019-10-28 11:58:20 -07001635 clear_len += 4;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001636 clear = wpabuf_alloc(clear_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001637 attr_len = 4 + 1 + 4 + clear_len + AES_BLOCK_SIZE;
1638#ifdef CONFIG_TESTING_OPTIONS
1639 if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP)
1640 attr_len += 5;
1641#endif /* CONFIG_TESTING_OPTIONS */
1642 msg = wpabuf_alloc(attr_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001643 if (!clear || !msg)
1644 goto fail;
1645
Roshan Pius3a1667e2018-07-03 15:17:14 -07001646#ifdef CONFIG_TESTING_OPTIONS
1647 if (dpp_test == DPP_TEST_NO_E_NONCE_CONF_RESP) {
1648 wpa_printf(MSG_INFO, "DPP: TESTING - no E-nonce");
1649 goto skip_e_nonce;
1650 }
1651 if (dpp_test == DPP_TEST_E_NONCE_MISMATCH_CONF_RESP) {
1652 wpa_printf(MSG_INFO, "DPP: TESTING - E-nonce mismatch");
1653 wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE);
1654 wpabuf_put_le16(clear, e_nonce_len);
1655 wpabuf_put_data(clear, e_nonce, e_nonce_len - 1);
1656 wpabuf_put_u8(clear, e_nonce[e_nonce_len - 1] ^ 0x01);
1657 goto skip_e_nonce;
1658 }
1659 if (dpp_test == DPP_TEST_NO_WRAPPED_DATA_CONF_RESP) {
1660 wpa_printf(MSG_INFO, "DPP: TESTING - no Wrapped Data");
1661 goto skip_wrapped_data;
1662 }
1663#endif /* CONFIG_TESTING_OPTIONS */
1664
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001665 /* E-nonce */
1666 wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE);
1667 wpabuf_put_le16(clear, e_nonce_len);
1668 wpabuf_put_data(clear, e_nonce, e_nonce_len);
1669
Roshan Pius3a1667e2018-07-03 15:17:14 -07001670#ifdef CONFIG_TESTING_OPTIONS
1671skip_e_nonce:
1672 if (dpp_test == DPP_TEST_NO_CONFIG_OBJ_CONF_RESP) {
1673 wpa_printf(MSG_INFO, "DPP: TESTING - Config Object");
1674 goto skip_config_obj;
1675 }
1676#endif /* CONFIG_TESTING_OPTIONS */
1677
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001678 if (conf) {
1679 wpabuf_put_le16(clear, DPP_ATTR_CONFIG_OBJ);
1680 wpabuf_put_le16(clear, wpabuf_len(conf));
1681 wpabuf_put_buf(clear, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001682 }
Hai Shalomc3565922019-10-28 11:58:20 -07001683 if (auth->peer_version >= 2 && conf2) {
1684 wpabuf_put_le16(clear, DPP_ATTR_CONFIG_OBJ);
1685 wpabuf_put_le16(clear, wpabuf_len(conf2));
1686 wpabuf_put_buf(clear, conf2);
1687 } else if (conf2) {
1688 wpa_printf(MSG_DEBUG,
1689 "DPP: Second Config Object available, but peer does not support more than one");
1690 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001691 if (env_data) {
1692 wpabuf_put_le16(clear, DPP_ATTR_ENVELOPED_DATA);
1693 wpabuf_put_le16(clear, wpabuf_len(env_data));
1694 wpabuf_put_buf(clear, env_data);
1695 }
Hai Shalomc3565922019-10-28 11:58:20 -07001696
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001697 if (auth->peer_version >= 2 && auth->send_conn_status &&
1698 netrole == DPP_NETROLE_STA) {
Hai Shalomc3565922019-10-28 11:58:20 -07001699 wpa_printf(MSG_DEBUG, "DPP: sendConnStatus");
1700 wpabuf_put_le16(clear, DPP_ATTR_SEND_CONN_STATUS);
1701 wpabuf_put_le16(clear, 0);
1702 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001703
Roshan Pius3a1667e2018-07-03 15:17:14 -07001704#ifdef CONFIG_TESTING_OPTIONS
1705skip_config_obj:
1706 if (dpp_test == DPP_TEST_NO_STATUS_CONF_RESP) {
1707 wpa_printf(MSG_INFO, "DPP: TESTING - Status");
1708 goto skip_status;
1709 }
1710 if (dpp_test == DPP_TEST_INVALID_STATUS_CONF_RESP) {
1711 wpa_printf(MSG_INFO, "DPP: TESTING - invalid Status");
1712 status = 255;
1713 }
1714#endif /* CONFIG_TESTING_OPTIONS */
1715
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001716 /* DPP Status */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001717 dpp_build_attr_status(msg, status);
1718
1719#ifdef CONFIG_TESTING_OPTIONS
1720skip_status:
1721#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001722
1723 addr[0] = wpabuf_head(msg);
1724 len[0] = wpabuf_len(msg);
1725 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD", addr[0], len[0]);
1726
1727 wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA);
1728 wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
1729 wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
1730
1731 wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear);
1732 if (aes_siv_encrypt(auth->ke, auth->curve->hash_len,
1733 wpabuf_head(clear), wpabuf_len(clear),
1734 1, addr, len, wrapped) < 0)
1735 goto fail;
1736 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext",
1737 wrapped, wpabuf_len(clear) + AES_BLOCK_SIZE);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001738
1739#ifdef CONFIG_TESTING_OPTIONS
1740 if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP) {
1741 wpa_printf(MSG_INFO, "DPP: TESTING - attr after Wrapped Data");
1742 dpp_build_attr_status(msg, DPP_STATUS_OK);
1743 }
1744skip_wrapped_data:
1745#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001746
1747 wpa_hexdump_buf(MSG_DEBUG,
1748 "DPP: Configuration Response attributes", msg);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001749out:
Hai Shalomfdcde762020-04-02 11:19:20 -07001750 wpabuf_clear_free(conf);
1751 wpabuf_clear_free(conf2);
1752 wpabuf_clear_free(env_data);
1753 wpabuf_clear_free(clear);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001754
1755 return msg;
1756fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001757 wpabuf_free(msg);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001758 msg = NULL;
1759 goto out;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001760}
1761
1762
1763struct wpabuf *
1764dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
1765 size_t attr_len)
1766{
1767 const u8 *wrapped_data, *e_nonce, *config_attr;
1768 u16 wrapped_data_len, e_nonce_len, config_attr_len;
1769 u8 *unwrapped = NULL;
1770 size_t unwrapped_len = 0;
1771 struct wpabuf *resp = NULL;
1772 struct json_token *root = NULL, *token;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001773 enum dpp_netrole netrole;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001774
Roshan Pius3a1667e2018-07-03 15:17:14 -07001775#ifdef CONFIG_TESTING_OPTIONS
1776 if (dpp_test == DPP_TEST_STOP_AT_CONF_REQ) {
1777 wpa_printf(MSG_INFO,
1778 "DPP: TESTING - stop at Config Request");
1779 return NULL;
1780 }
1781#endif /* CONFIG_TESTING_OPTIONS */
1782
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001783 if (dpp_check_attrs(attr_start, attr_len) < 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001784 dpp_auth_fail(auth, "Invalid attribute in config request");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001785 return NULL;
1786 }
1787
1788 wrapped_data = dpp_get_attr(attr_start, attr_len, DPP_ATTR_WRAPPED_DATA,
1789 &wrapped_data_len);
1790 if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001791 dpp_auth_fail(auth,
1792 "Missing or invalid required Wrapped Data attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001793 return NULL;
1794 }
1795
1796 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext",
1797 wrapped_data, wrapped_data_len);
1798 unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE;
1799 unwrapped = os_malloc(unwrapped_len);
1800 if (!unwrapped)
1801 return NULL;
1802 if (aes_siv_decrypt(auth->ke, auth->curve->hash_len,
1803 wrapped_data, wrapped_data_len,
1804 0, NULL, NULL, unwrapped) < 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001805 dpp_auth_fail(auth, "AES-SIV decryption failed");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001806 goto fail;
1807 }
1808 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext",
1809 unwrapped, unwrapped_len);
1810
1811 if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001812 dpp_auth_fail(auth, "Invalid attribute in unwrapped data");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001813 goto fail;
1814 }
1815
1816 e_nonce = dpp_get_attr(unwrapped, unwrapped_len,
1817 DPP_ATTR_ENROLLEE_NONCE,
1818 &e_nonce_len);
1819 if (!e_nonce || e_nonce_len != auth->curve->nonce_len) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001820 dpp_auth_fail(auth,
1821 "Missing or invalid Enrollee Nonce attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001822 goto fail;
1823 }
1824 wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001825 os_memcpy(auth->e_nonce, e_nonce, e_nonce_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001826
1827 config_attr = dpp_get_attr(unwrapped, unwrapped_len,
1828 DPP_ATTR_CONFIG_ATTR_OBJ,
1829 &config_attr_len);
1830 if (!config_attr) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001831 dpp_auth_fail(auth,
1832 "Missing or invalid Config Attributes attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001833 goto fail;
1834 }
1835 wpa_hexdump_ascii(MSG_DEBUG, "DPP: Config Attributes",
1836 config_attr, config_attr_len);
1837
1838 root = json_parse((const char *) config_attr, config_attr_len);
1839 if (!root) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001840 dpp_auth_fail(auth, "Could not parse Config Attributes");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001841 goto fail;
1842 }
1843
1844 token = json_get_member(root, "name");
1845 if (!token || token->type != JSON_STRING) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001846 dpp_auth_fail(auth, "No Config Attributes - name");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001847 goto fail;
1848 }
1849 wpa_printf(MSG_DEBUG, "DPP: Enrollee name = '%s'", token->string);
1850
1851 token = json_get_member(root, "wi-fi_tech");
1852 if (!token || token->type != JSON_STRING) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001853 dpp_auth_fail(auth, "No Config Attributes - wi-fi_tech");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001854 goto fail;
1855 }
1856 wpa_printf(MSG_DEBUG, "DPP: wi-fi_tech = '%s'", token->string);
1857 if (os_strcmp(token->string, "infra") != 0) {
1858 wpa_printf(MSG_DEBUG, "DPP: Unsupported wi-fi_tech '%s'",
1859 token->string);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001860 dpp_auth_fail(auth, "Unsupported wi-fi_tech");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001861 goto fail;
1862 }
1863
1864 token = json_get_member(root, "netRole");
1865 if (!token || token->type != JSON_STRING) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001866 dpp_auth_fail(auth, "No Config Attributes - netRole");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001867 goto fail;
1868 }
1869 wpa_printf(MSG_DEBUG, "DPP: netRole = '%s'", token->string);
1870 if (os_strcmp(token->string, "sta") == 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001871 netrole = DPP_NETROLE_STA;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001872 } else if (os_strcmp(token->string, "ap") == 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001873 netrole = DPP_NETROLE_AP;
1874 } else if (os_strcmp(token->string, "configurator") == 0) {
1875 netrole = DPP_NETROLE_CONFIGURATOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001876 } else {
1877 wpa_printf(MSG_DEBUG, "DPP: Unsupported netRole '%s'",
1878 token->string);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001879 dpp_auth_fail(auth, "Unsupported netRole");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001880 goto fail;
1881 }
1882
Hai Shalomc3565922019-10-28 11:58:20 -07001883 token = json_get_member(root, "mudurl");
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001884 if (token && token->type == JSON_STRING) {
Hai Shalomc3565922019-10-28 11:58:20 -07001885 wpa_printf(MSG_DEBUG, "DPP: mudurl = '%s'", token->string);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001886 wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_MUD_URL "%s",
1887 token->string);
1888 }
Hai Shalomc3565922019-10-28 11:58:20 -07001889
1890 token = json_get_member(root, "bandSupport");
Hai Shalom06768112019-12-04 15:49:43 -08001891 auth->band_list_size = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07001892 if (token && token->type == JSON_ARRAY) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001893 int *opclass = NULL;
1894 char txt[200], *pos, *end;
1895 int i, res;
1896
Hai Shalom06768112019-12-04 15:49:43 -08001897 memset(auth->band_list, 0, sizeof(auth->band_list));
Hai Shalomc3565922019-10-28 11:58:20 -07001898 wpa_printf(MSG_DEBUG, "DPP: bandSupport");
1899 token = token->child;
1900 while (token) {
Hai Shalom06768112019-12-04 15:49:43 -08001901 if (token->type != JSON_NUMBER) {
Hai Shalomc3565922019-10-28 11:58:20 -07001902 wpa_printf(MSG_DEBUG,
1903 "DPP: Invalid bandSupport array member type");
Hai Shalom06768112019-12-04 15:49:43 -08001904 } else {
1905 if (auth->band_list_size < DPP_MAX_CHANNELS) {
1906 auth->band_list[auth->band_list_size++] = token->number;
1907 }
Hai Shalomc3565922019-10-28 11:58:20 -07001908 wpa_printf(MSG_DEBUG,
1909 "DPP: Supported global operating class: %d",
1910 token->number);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001911 int_array_add_unique(&opclass, token->number);
Hai Shalom06768112019-12-04 15:49:43 -08001912 }
Hai Shalomc3565922019-10-28 11:58:20 -07001913 token = token->sibling;
1914 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001915
1916 txt[0] = '\0';
1917 pos = txt;
1918 end = txt + sizeof(txt);
1919 for (i = 0; opclass && opclass[i]; i++) {
1920 res = os_snprintf(pos, end - pos, "%s%d",
1921 pos == txt ? "" : ",", opclass[i]);
1922 if (os_snprintf_error(end - pos, res)) {
1923 *pos = '\0';
1924 break;
1925 }
1926 pos += res;
1927 }
1928 os_free(opclass);
1929 wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_BAND_SUPPORT "%s",
1930 txt);
Hai Shalomc3565922019-10-28 11:58:20 -07001931 }
1932
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001933 resp = dpp_build_conf_resp(auth, e_nonce, e_nonce_len, netrole);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001934
1935fail:
1936 json_free(root);
1937 os_free(unwrapped);
1938 return resp;
1939}
1940
1941
Hai Shalomc3565922019-10-28 11:58:20 -07001942static int dpp_parse_cred_legacy(struct dpp_config_obj *conf,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001943 struct json_token *cred)
1944{
1945 struct json_token *pass, *psk_hex;
1946
1947 wpa_printf(MSG_DEBUG, "DPP: Legacy akm=psk credential");
1948
1949 pass = json_get_member(cred, "pass");
1950 psk_hex = json_get_member(cred, "psk_hex");
1951
1952 if (pass && pass->type == JSON_STRING) {
1953 size_t len = os_strlen(pass->string);
1954
1955 wpa_hexdump_ascii_key(MSG_DEBUG, "DPP: Legacy passphrase",
1956 pass->string, len);
1957 if (len < 8 || len > 63)
1958 return -1;
Hai Shalomc3565922019-10-28 11:58:20 -07001959 os_strlcpy(conf->passphrase, pass->string,
1960 sizeof(conf->passphrase));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001961 } else if (psk_hex && psk_hex->type == JSON_STRING) {
Hai Shalomc3565922019-10-28 11:58:20 -07001962 if (dpp_akm_sae(conf->akm) && !dpp_akm_psk(conf->akm)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001963 wpa_printf(MSG_DEBUG,
1964 "DPP: Unexpected psk_hex with akm=sae");
1965 return -1;
1966 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001967 if (os_strlen(psk_hex->string) != PMK_LEN * 2 ||
Hai Shalomc3565922019-10-28 11:58:20 -07001968 hexstr2bin(psk_hex->string, conf->psk, PMK_LEN) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001969 wpa_printf(MSG_DEBUG, "DPP: Invalid psk_hex encoding");
1970 return -1;
1971 }
1972 wpa_hexdump_key(MSG_DEBUG, "DPP: Legacy PSK",
Hai Shalomc3565922019-10-28 11:58:20 -07001973 conf->psk, PMK_LEN);
1974 conf->psk_set = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001975 } else {
1976 wpa_printf(MSG_DEBUG, "DPP: No pass or psk_hex strings found");
1977 return -1;
1978 }
1979
Hai Shalomc3565922019-10-28 11:58:20 -07001980 if (dpp_akm_sae(conf->akm) && !conf->passphrase[0]) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001981 wpa_printf(MSG_DEBUG, "DPP: No pass for sae found");
1982 return -1;
1983 }
1984
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001985 return 0;
1986}
1987
1988
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001989EVP_PKEY * dpp_parse_jwk(struct json_token *jwk,
1990 const struct dpp_curve_params **key_curve)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001991{
1992 struct json_token *token;
1993 const struct dpp_curve_params *curve;
1994 struct wpabuf *x = NULL, *y = NULL;
1995 EC_GROUP *group;
1996 EVP_PKEY *pkey = NULL;
1997
1998 token = json_get_member(jwk, "kty");
1999 if (!token || token->type != JSON_STRING) {
2000 wpa_printf(MSG_DEBUG, "DPP: No kty in JWK");
2001 goto fail;
2002 }
2003 if (os_strcmp(token->string, "EC") != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08002004 wpa_printf(MSG_DEBUG, "DPP: Unexpected JWK kty '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002005 token->string);
2006 goto fail;
2007 }
2008
2009 token = json_get_member(jwk, "crv");
2010 if (!token || token->type != JSON_STRING) {
2011 wpa_printf(MSG_DEBUG, "DPP: No crv in JWK");
2012 goto fail;
2013 }
2014 curve = dpp_get_curve_jwk_crv(token->string);
2015 if (!curve) {
2016 wpa_printf(MSG_DEBUG, "DPP: Unsupported JWK crv '%s'",
2017 token->string);
2018 goto fail;
2019 }
2020
2021 x = json_get_member_base64url(jwk, "x");
2022 if (!x) {
2023 wpa_printf(MSG_DEBUG, "DPP: No x in JWK");
2024 goto fail;
2025 }
2026 wpa_hexdump_buf(MSG_DEBUG, "DPP: JWK x", x);
2027 if (wpabuf_len(x) != curve->prime_len) {
2028 wpa_printf(MSG_DEBUG,
2029 "DPP: Unexpected JWK x length %u (expected %u for curve %s)",
2030 (unsigned int) wpabuf_len(x),
2031 (unsigned int) curve->prime_len, curve->name);
2032 goto fail;
2033 }
2034
2035 y = json_get_member_base64url(jwk, "y");
2036 if (!y) {
2037 wpa_printf(MSG_DEBUG, "DPP: No y in JWK");
2038 goto fail;
2039 }
2040 wpa_hexdump_buf(MSG_DEBUG, "DPP: JWK y", y);
2041 if (wpabuf_len(y) != curve->prime_len) {
2042 wpa_printf(MSG_DEBUG,
2043 "DPP: Unexpected JWK y length %u (expected %u for curve %s)",
2044 (unsigned int) wpabuf_len(y),
2045 (unsigned int) curve->prime_len, curve->name);
2046 goto fail;
2047 }
2048
2049 group = EC_GROUP_new_by_curve_name(OBJ_txt2nid(curve->name));
2050 if (!group) {
2051 wpa_printf(MSG_DEBUG, "DPP: Could not prepare group for JWK");
2052 goto fail;
2053 }
2054
2055 pkey = dpp_set_pubkey_point_group(group, wpabuf_head(x), wpabuf_head(y),
2056 wpabuf_len(x));
Hai Shalom81f62d82019-07-22 12:10:00 -07002057 EC_GROUP_free(group);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002058 *key_curve = curve;
2059
2060fail:
2061 wpabuf_free(x);
2062 wpabuf_free(y);
2063
2064 return pkey;
2065}
2066
2067
2068int dpp_key_expired(const char *timestamp, os_time_t *expiry)
2069{
2070 struct os_time now;
2071 unsigned int year, month, day, hour, min, sec;
2072 os_time_t utime;
2073 const char *pos;
2074
2075 /* ISO 8601 date and time:
2076 * <date>T<time>
2077 * YYYY-MM-DDTHH:MM:SSZ
2078 * YYYY-MM-DDTHH:MM:SS+03:00
2079 */
2080 if (os_strlen(timestamp) < 19) {
2081 wpa_printf(MSG_DEBUG,
2082 "DPP: Too short timestamp - assume expired key");
2083 return 1;
2084 }
2085 if (sscanf(timestamp, "%04u-%02u-%02uT%02u:%02u:%02u",
2086 &year, &month, &day, &hour, &min, &sec) != 6) {
2087 wpa_printf(MSG_DEBUG,
2088 "DPP: Failed to parse expiration day - assume expired key");
2089 return 1;
2090 }
2091
2092 if (os_mktime(year, month, day, hour, min, sec, &utime) < 0) {
2093 wpa_printf(MSG_DEBUG,
2094 "DPP: Invalid date/time information - assume expired key");
2095 return 1;
2096 }
2097
2098 pos = timestamp + 19;
2099 if (*pos == 'Z' || *pos == '\0') {
2100 /* In UTC - no need to adjust */
2101 } else if (*pos == '-' || *pos == '+') {
2102 int items;
2103
2104 /* Adjust local time to UTC */
2105 items = sscanf(pos + 1, "%02u:%02u", &hour, &min);
2106 if (items < 1) {
2107 wpa_printf(MSG_DEBUG,
2108 "DPP: Invalid time zone designator (%s) - assume expired key",
2109 pos);
2110 return 1;
2111 }
2112 if (*pos == '-')
2113 utime += 3600 * hour;
2114 if (*pos == '+')
2115 utime -= 3600 * hour;
2116 if (items > 1) {
2117 if (*pos == '-')
2118 utime += 60 * min;
2119 if (*pos == '+')
2120 utime -= 60 * min;
2121 }
2122 } else {
2123 wpa_printf(MSG_DEBUG,
2124 "DPP: Invalid time zone designator (%s) - assume expired key",
2125 pos);
2126 return 1;
2127 }
2128 if (expiry)
2129 *expiry = utime;
2130
2131 if (os_get_time(&now) < 0) {
2132 wpa_printf(MSG_DEBUG,
2133 "DPP: Cannot get current time - assume expired key");
2134 return 1;
2135 }
2136
2137 if (now.sec > utime) {
2138 wpa_printf(MSG_DEBUG, "DPP: Key has expired (%lu < %lu)",
2139 utime, now.sec);
2140 return 1;
2141 }
2142
2143 return 0;
2144}
2145
2146
2147static int dpp_parse_connector(struct dpp_authentication *auth,
Hai Shalomc3565922019-10-28 11:58:20 -07002148 struct dpp_config_obj *conf,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002149 const unsigned char *payload,
2150 u16 payload_len)
2151{
2152 struct json_token *root, *groups, *netkey, *token;
2153 int ret = -1;
2154 EVP_PKEY *key = NULL;
2155 const struct dpp_curve_params *curve;
2156 unsigned int rules = 0;
2157
2158 root = json_parse((const char *) payload, payload_len);
2159 if (!root) {
2160 wpa_printf(MSG_DEBUG, "DPP: JSON parsing of connector failed");
2161 goto fail;
2162 }
2163
2164 groups = json_get_member(root, "groups");
2165 if (!groups || groups->type != JSON_ARRAY) {
2166 wpa_printf(MSG_DEBUG, "DPP: No groups array found");
2167 goto skip_groups;
2168 }
2169 for (token = groups->child; token; token = token->sibling) {
2170 struct json_token *id, *role;
2171
2172 id = json_get_member(token, "groupId");
2173 if (!id || id->type != JSON_STRING) {
2174 wpa_printf(MSG_DEBUG, "DPP: Missing groupId string");
2175 goto fail;
2176 }
2177
2178 role = json_get_member(token, "netRole");
2179 if (!role || role->type != JSON_STRING) {
2180 wpa_printf(MSG_DEBUG, "DPP: Missing netRole string");
2181 goto fail;
2182 }
2183 wpa_printf(MSG_DEBUG,
2184 "DPP: connector group: groupId='%s' netRole='%s'",
2185 id->string, role->string);
2186 rules++;
2187 }
2188skip_groups:
2189
2190 if (!rules) {
2191 wpa_printf(MSG_DEBUG,
2192 "DPP: Connector includes no groups");
2193 goto fail;
2194 }
2195
2196 token = json_get_member(root, "expiry");
2197 if (!token || token->type != JSON_STRING) {
2198 wpa_printf(MSG_DEBUG,
2199 "DPP: No expiry string found - connector does not expire");
2200 } else {
2201 wpa_printf(MSG_DEBUG, "DPP: expiry = %s", token->string);
2202 if (dpp_key_expired(token->string,
2203 &auth->net_access_key_expiry)) {
2204 wpa_printf(MSG_DEBUG,
2205 "DPP: Connector (netAccessKey) has expired");
2206 goto fail;
2207 }
2208 }
2209
2210 netkey = json_get_member(root, "netAccessKey");
2211 if (!netkey || netkey->type != JSON_OBJECT) {
2212 wpa_printf(MSG_DEBUG, "DPP: No netAccessKey object found");
2213 goto fail;
2214 }
2215
2216 key = dpp_parse_jwk(netkey, &curve);
2217 if (!key)
2218 goto fail;
2219 dpp_debug_print_key("DPP: Received netAccessKey", key);
2220
2221 if (EVP_PKEY_cmp(key, auth->own_protocol_key) != 1) {
2222 wpa_printf(MSG_DEBUG,
2223 "DPP: netAccessKey in connector does not match own protocol key");
2224#ifdef CONFIG_TESTING_OPTIONS
2225 if (auth->ignore_netaccesskey_mismatch) {
2226 wpa_printf(MSG_DEBUG,
2227 "DPP: TESTING - skip netAccessKey mismatch");
2228 } else {
2229 goto fail;
2230 }
2231#else /* CONFIG_TESTING_OPTIONS */
2232 goto fail;
2233#endif /* CONFIG_TESTING_OPTIONS */
2234 }
2235
2236 ret = 0;
2237fail:
2238 EVP_PKEY_free(key);
2239 json_free(root);
2240 return ret;
2241}
2242
2243
Hai Shalomc3565922019-10-28 11:58:20 -07002244static void dpp_copy_csign(struct dpp_config_obj *conf, EVP_PKEY *csign)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002245{
2246 unsigned char *der = NULL;
2247 int der_len;
2248
2249 der_len = i2d_PUBKEY(csign, &der);
2250 if (der_len <= 0)
2251 return;
Hai Shalomc3565922019-10-28 11:58:20 -07002252 wpabuf_free(conf->c_sign_key);
2253 conf->c_sign_key = wpabuf_alloc_copy(der, der_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002254 OPENSSL_free(der);
2255}
2256
2257
Hai Shalomc3565922019-10-28 11:58:20 -07002258static void dpp_copy_netaccesskey(struct dpp_authentication *auth,
2259 struct dpp_config_obj *conf)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002260{
2261 unsigned char *der = NULL;
2262 int der_len;
2263 EC_KEY *eckey;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002264 EVP_PKEY *own_key;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002265
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002266 own_key = auth->own_protocol_key;
2267#ifdef CONFIG_DPP2
2268 if (auth->reconfig_connector_key == DPP_CONFIG_REUSEKEY &&
2269 auth->reconfig_old_protocol_key)
2270 own_key = auth->reconfig_old_protocol_key;
2271#endif /* CONFIG_DPP2 */
2272 eckey = EVP_PKEY_get1_EC_KEY(own_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002273 if (!eckey)
2274 return;
2275
2276 der_len = i2d_ECPrivateKey(eckey, &der);
2277 if (der_len <= 0) {
2278 EC_KEY_free(eckey);
2279 return;
2280 }
2281 wpabuf_free(auth->net_access_key);
2282 auth->net_access_key = wpabuf_alloc_copy(der, der_len);
2283 OPENSSL_free(der);
2284 EC_KEY_free(eckey);
2285}
2286
2287
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002288static int dpp_parse_cred_dpp(struct dpp_authentication *auth,
Hai Shalomc3565922019-10-28 11:58:20 -07002289 struct dpp_config_obj *conf,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002290 struct json_token *cred)
2291{
2292 struct dpp_signed_connector_info info;
2293 struct json_token *token, *csign;
2294 int ret = -1;
2295 EVP_PKEY *csign_pub = NULL;
2296 const struct dpp_curve_params *key_curve = NULL;
2297 const char *signed_connector;
2298
2299 os_memset(&info, 0, sizeof(info));
2300
Hai Shalomc3565922019-10-28 11:58:20 -07002301 if (dpp_akm_psk(conf->akm) || dpp_akm_sae(conf->akm)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002302 wpa_printf(MSG_DEBUG,
2303 "DPP: Legacy credential included in Connector credential");
Hai Shalomc3565922019-10-28 11:58:20 -07002304 if (dpp_parse_cred_legacy(conf, cred) < 0)
Hai Shalom021b0b52019-04-10 11:17:58 -07002305 return -1;
2306 }
2307
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002308 wpa_printf(MSG_DEBUG, "DPP: Connector credential");
2309
2310 csign = json_get_member(cred, "csign");
2311 if (!csign || csign->type != JSON_OBJECT) {
2312 wpa_printf(MSG_DEBUG, "DPP: No csign JWK in JSON");
2313 goto fail;
2314 }
2315
2316 csign_pub = dpp_parse_jwk(csign, &key_curve);
2317 if (!csign_pub) {
2318 wpa_printf(MSG_DEBUG, "DPP: Failed to parse csign JWK");
2319 goto fail;
2320 }
2321 dpp_debug_print_key("DPP: Received C-sign-key", csign_pub);
2322
2323 token = json_get_member(cred, "signedConnector");
2324 if (!token || token->type != JSON_STRING) {
2325 wpa_printf(MSG_DEBUG, "DPP: No signedConnector string found");
2326 goto fail;
2327 }
2328 wpa_hexdump_ascii(MSG_DEBUG, "DPP: signedConnector",
2329 token->string, os_strlen(token->string));
2330 signed_connector = token->string;
2331
2332 if (os_strchr(signed_connector, '"') ||
2333 os_strchr(signed_connector, '\n')) {
2334 wpa_printf(MSG_DEBUG,
2335 "DPP: Unexpected character in signedConnector");
2336 goto fail;
2337 }
2338
2339 if (dpp_process_signed_connector(&info, csign_pub,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002340 signed_connector) != DPP_STATUS_OK)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002341 goto fail;
2342
Hai Shalomc3565922019-10-28 11:58:20 -07002343 if (dpp_parse_connector(auth, conf,
2344 info.payload, info.payload_len) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002345 wpa_printf(MSG_DEBUG, "DPP: Failed to parse connector");
2346 goto fail;
2347 }
2348
Hai Shalomc3565922019-10-28 11:58:20 -07002349 os_free(conf->connector);
2350 conf->connector = os_strdup(signed_connector);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002351
Hai Shalomc3565922019-10-28 11:58:20 -07002352 dpp_copy_csign(conf, csign_pub);
Hai Shalomb755a2a2020-04-23 21:49:02 -07002353 if (dpp_akm_dpp(conf->akm) || auth->peer_version >= 2)
Hai Shalomfdcde762020-04-02 11:19:20 -07002354 dpp_copy_netaccesskey(auth, conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002355
2356 ret = 0;
2357fail:
2358 EVP_PKEY_free(csign_pub);
2359 os_free(info.payload);
2360 return ret;
2361}
2362
2363
Roshan Pius3a1667e2018-07-03 15:17:14 -07002364const char * dpp_akm_str(enum dpp_akm akm)
2365{
2366 switch (akm) {
2367 case DPP_AKM_DPP:
2368 return "dpp";
2369 case DPP_AKM_PSK:
2370 return "psk";
2371 case DPP_AKM_SAE:
2372 return "sae";
2373 case DPP_AKM_PSK_SAE:
2374 return "psk+sae";
Hai Shalom021b0b52019-04-10 11:17:58 -07002375 case DPP_AKM_SAE_DPP:
2376 return "dpp+sae";
2377 case DPP_AKM_PSK_SAE_DPP:
2378 return "dpp+psk+sae";
Roshan Pius3a1667e2018-07-03 15:17:14 -07002379 default:
2380 return "??";
2381 }
2382}
2383
2384
Hai Shalomc3565922019-10-28 11:58:20 -07002385const char * dpp_akm_selector_str(enum dpp_akm akm)
2386{
2387 switch (akm) {
2388 case DPP_AKM_DPP:
2389 return "506F9A02";
2390 case DPP_AKM_PSK:
2391 return "000FAC02+000FAC06";
2392 case DPP_AKM_SAE:
2393 return "000FAC08";
2394 case DPP_AKM_PSK_SAE:
2395 return "000FAC02+000FAC06+000FAC08";
2396 case DPP_AKM_SAE_DPP:
2397 return "506F9A02+000FAC08";
2398 case DPP_AKM_PSK_SAE_DPP:
2399 return "506F9A02+000FAC08+000FAC02+000FAC06";
2400 default:
2401 return "??";
2402 }
2403}
2404
2405
Roshan Pius3a1667e2018-07-03 15:17:14 -07002406static enum dpp_akm dpp_akm_from_str(const char *akm)
2407{
Hai Shalomc3565922019-10-28 11:58:20 -07002408 const char *pos;
2409 int dpp = 0, psk = 0, sae = 0;
2410
Roshan Pius3a1667e2018-07-03 15:17:14 -07002411 if (os_strcmp(akm, "psk") == 0)
2412 return DPP_AKM_PSK;
2413 if (os_strcmp(akm, "sae") == 0)
2414 return DPP_AKM_SAE;
2415 if (os_strcmp(akm, "psk+sae") == 0)
2416 return DPP_AKM_PSK_SAE;
2417 if (os_strcmp(akm, "dpp") == 0)
2418 return DPP_AKM_DPP;
Hai Shalom021b0b52019-04-10 11:17:58 -07002419 if (os_strcmp(akm, "dpp+sae") == 0)
2420 return DPP_AKM_SAE_DPP;
2421 if (os_strcmp(akm, "dpp+psk+sae") == 0)
2422 return DPP_AKM_PSK_SAE_DPP;
Hai Shalomc3565922019-10-28 11:58:20 -07002423
2424 pos = akm;
2425 while (*pos) {
2426 if (os_strlen(pos) < 8)
2427 break;
2428 if (os_strncasecmp(pos, "506F9A02", 8) == 0)
2429 dpp = 1;
2430 else if (os_strncasecmp(pos, "000FAC02", 8) == 0)
2431 psk = 1;
2432 else if (os_strncasecmp(pos, "000FAC06", 8) == 0)
2433 psk = 1;
2434 else if (os_strncasecmp(pos, "000FAC08", 8) == 0)
2435 sae = 1;
2436 pos += 8;
2437 if (*pos != '+')
2438 break;
2439 pos++;
2440 }
2441
2442 if (dpp && psk && sae)
2443 return DPP_AKM_PSK_SAE_DPP;
2444 if (dpp && sae)
2445 return DPP_AKM_SAE_DPP;
2446 if (dpp)
2447 return DPP_AKM_DPP;
2448 if (psk && sae)
2449 return DPP_AKM_PSK_SAE;
2450 if (sae)
2451 return DPP_AKM_SAE;
2452 if (psk)
2453 return DPP_AKM_PSK;
2454
Roshan Pius3a1667e2018-07-03 15:17:14 -07002455 return DPP_AKM_UNKNOWN;
2456}
2457
2458
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002459static int dpp_parse_conf_obj(struct dpp_authentication *auth,
2460 const u8 *conf_obj, u16 conf_obj_len)
2461{
2462 int ret = -1;
2463 struct json_token *root, *token, *discovery, *cred;
Hai Shalomc3565922019-10-28 11:58:20 -07002464 struct dpp_config_obj *conf;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002465 struct wpabuf *ssid64 = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07002466 int legacy;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002467
2468 root = json_parse((const char *) conf_obj, conf_obj_len);
2469 if (!root)
2470 return -1;
2471 if (root->type != JSON_OBJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002472 dpp_auth_fail(auth, "JSON root is not an object");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002473 goto fail;
2474 }
2475
2476 token = json_get_member(root, "wi-fi_tech");
2477 if (!token || token->type != JSON_STRING) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002478 dpp_auth_fail(auth, "No wi-fi_tech string value found");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002479 goto fail;
2480 }
2481 if (os_strcmp(token->string, "infra") != 0) {
2482 wpa_printf(MSG_DEBUG, "DPP: Unsupported wi-fi_tech value: '%s'",
2483 token->string);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002484 dpp_auth_fail(auth, "Unsupported wi-fi_tech value");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002485 goto fail;
2486 }
2487
2488 discovery = json_get_member(root, "discovery");
2489 if (!discovery || discovery->type != JSON_OBJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002490 dpp_auth_fail(auth, "No discovery object in JSON");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002491 goto fail;
2492 }
2493
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002494 ssid64 = json_get_member_base64url(discovery, "ssid64");
2495 if (ssid64) {
2496 wpa_hexdump_ascii(MSG_DEBUG, "DPP: discovery::ssid64",
2497 wpabuf_head(ssid64), wpabuf_len(ssid64));
2498 if (wpabuf_len(ssid64) > SSID_MAX_LEN) {
2499 dpp_auth_fail(auth, "Too long discovery::ssid64 value");
2500 goto fail;
2501 }
2502 } else {
2503 token = json_get_member(discovery, "ssid");
2504 if (!token || token->type != JSON_STRING) {
2505 dpp_auth_fail(auth,
2506 "No discovery::ssid string value found");
2507 goto fail;
2508 }
2509 wpa_hexdump_ascii(MSG_DEBUG, "DPP: discovery::ssid",
2510 token->string, os_strlen(token->string));
2511 if (os_strlen(token->string) > SSID_MAX_LEN) {
2512 dpp_auth_fail(auth,
2513 "Too long discovery::ssid string value");
2514 goto fail;
2515 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002516 }
Hai Shalomc3565922019-10-28 11:58:20 -07002517
2518 if (auth->num_conf_obj == DPP_MAX_CONF_OBJ) {
2519 wpa_printf(MSG_DEBUG,
2520 "DPP: No room for this many Config Objects - ignore this one");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002521 ret = 0;
2522 goto fail;
Hai Shalomc3565922019-10-28 11:58:20 -07002523 }
2524 conf = &auth->conf_obj[auth->num_conf_obj++];
2525
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002526 if (ssid64) {
2527 conf->ssid_len = wpabuf_len(ssid64);
2528 os_memcpy(conf->ssid, wpabuf_head(ssid64), conf->ssid_len);
2529 } else {
2530 conf->ssid_len = os_strlen(token->string);
2531 os_memcpy(conf->ssid, token->string, conf->ssid_len);
2532 }
2533
2534 token = json_get_member(discovery, "ssid_charset");
2535 if (token && token->type == JSON_NUMBER) {
2536 conf->ssid_charset = token->number;
2537 wpa_printf(MSG_DEBUG, "DPP: ssid_charset=%d",
2538 conf->ssid_charset);
2539 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002540
2541 cred = json_get_member(root, "cred");
2542 if (!cred || cred->type != JSON_OBJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002543 dpp_auth_fail(auth, "No cred object in JSON");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002544 goto fail;
2545 }
2546
2547 token = json_get_member(cred, "akm");
2548 if (!token || token->type != JSON_STRING) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002549 dpp_auth_fail(auth, "No cred::akm string value found");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002550 goto fail;
2551 }
Hai Shalomc3565922019-10-28 11:58:20 -07002552 conf->akm = dpp_akm_from_str(token->string);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002553
Hai Shalomfdcde762020-04-02 11:19:20 -07002554 legacy = dpp_akm_legacy(conf->akm);
2555 if (legacy && auth->peer_version >= 2) {
2556 struct json_token *csign, *s_conn;
2557
2558 csign = json_get_member(cred, "csign");
2559 s_conn = json_get_member(cred, "signedConnector");
2560 if (csign && csign->type == JSON_OBJECT &&
2561 s_conn && s_conn->type == JSON_STRING)
2562 legacy = 0;
2563 }
2564 if (legacy) {
Hai Shalomc3565922019-10-28 11:58:20 -07002565 if (dpp_parse_cred_legacy(conf, cred) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002566 goto fail;
Hai Shalomfdcde762020-04-02 11:19:20 -07002567 } else if (dpp_akm_dpp(conf->akm) ||
2568 (auth->peer_version >= 2 && dpp_akm_legacy(conf->akm))) {
Hai Shalomc3565922019-10-28 11:58:20 -07002569 if (dpp_parse_cred_dpp(auth, conf, cred) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002570 goto fail;
2571 } else {
2572 wpa_printf(MSG_DEBUG, "DPP: Unsupported akm: %s",
2573 token->string);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002574 dpp_auth_fail(auth, "Unsupported akm");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002575 goto fail;
2576 }
2577
2578 wpa_printf(MSG_DEBUG, "DPP: JSON parsing completed successfully");
2579 ret = 0;
2580fail:
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002581 wpabuf_free(ssid64);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002582 json_free(root);
2583 return ret;
2584}
2585
2586
2587int dpp_conf_resp_rx(struct dpp_authentication *auth,
2588 const struct wpabuf *resp)
2589{
2590 const u8 *wrapped_data, *e_nonce, *status, *conf_obj;
2591 u16 wrapped_data_len, e_nonce_len, status_len, conf_obj_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07002592 const u8 *env_data;
2593 u16 env_data_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002594 const u8 *addr[1];
2595 size_t len[1];
2596 u8 *unwrapped = NULL;
2597 size_t unwrapped_len = 0;
2598 int ret = -1;
2599
Hai Shalom021b0b52019-04-10 11:17:58 -07002600 auth->conf_resp_status = 255;
2601
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002602 if (dpp_check_attrs(wpabuf_head(resp), wpabuf_len(resp)) < 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002603 dpp_auth_fail(auth, "Invalid attribute in config response");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002604 return -1;
2605 }
2606
2607 wrapped_data = dpp_get_attr(wpabuf_head(resp), wpabuf_len(resp),
2608 DPP_ATTR_WRAPPED_DATA,
2609 &wrapped_data_len);
2610 if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002611 dpp_auth_fail(auth,
2612 "Missing or invalid required Wrapped Data attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002613 return -1;
2614 }
2615
2616 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext",
2617 wrapped_data, wrapped_data_len);
2618 unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE;
2619 unwrapped = os_malloc(unwrapped_len);
2620 if (!unwrapped)
2621 return -1;
2622
2623 addr[0] = wpabuf_head(resp);
2624 len[0] = wrapped_data - 4 - (const u8 *) wpabuf_head(resp);
2625 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD", addr[0], len[0]);
2626
2627 if (aes_siv_decrypt(auth->ke, auth->curve->hash_len,
2628 wrapped_data, wrapped_data_len,
2629 1, addr, len, unwrapped) < 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002630 dpp_auth_fail(auth, "AES-SIV decryption failed");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002631 goto fail;
2632 }
2633 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext",
2634 unwrapped, unwrapped_len);
2635
2636 if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002637 dpp_auth_fail(auth, "Invalid attribute in unwrapped data");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002638 goto fail;
2639 }
2640
2641 e_nonce = dpp_get_attr(unwrapped, unwrapped_len,
2642 DPP_ATTR_ENROLLEE_NONCE,
2643 &e_nonce_len);
2644 if (!e_nonce || e_nonce_len != auth->curve->nonce_len) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002645 dpp_auth_fail(auth,
2646 "Missing or invalid Enrollee Nonce attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002647 goto fail;
2648 }
2649 wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len);
2650 if (os_memcmp(e_nonce, auth->e_nonce, e_nonce_len) != 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002651 dpp_auth_fail(auth, "Enrollee Nonce mismatch");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002652 goto fail;
2653 }
2654
2655 status = dpp_get_attr(wpabuf_head(resp), wpabuf_len(resp),
2656 DPP_ATTR_STATUS, &status_len);
2657 if (!status || status_len < 1) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002658 dpp_auth_fail(auth,
2659 "Missing or invalid required DPP Status attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002660 goto fail;
2661 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002662 auth->conf_resp_status = status[0];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002663 wpa_printf(MSG_DEBUG, "DPP: Status %u", status[0]);
2664 if (status[0] != DPP_STATUS_OK) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002665 dpp_auth_fail(auth, "Configurator rejected configuration");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002666 goto fail;
2667 }
2668
Hai Shalomfdcde762020-04-02 11:19:20 -07002669 env_data = dpp_get_attr(unwrapped, unwrapped_len,
2670 DPP_ATTR_ENVELOPED_DATA, &env_data_len);
2671#ifdef CONFIG_DPP2
2672 if (env_data &&
2673 dpp_conf_resp_env_data(auth, env_data, env_data_len) < 0)
2674 goto fail;
2675#endif /* CONFIG_DPP2 */
2676
Hai Shalomc3565922019-10-28 11:58:20 -07002677 conf_obj = dpp_get_attr(unwrapped, unwrapped_len, DPP_ATTR_CONFIG_OBJ,
2678 &conf_obj_len);
Hai Shalomfdcde762020-04-02 11:19:20 -07002679 if (!conf_obj && !env_data) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002680 dpp_auth_fail(auth,
2681 "Missing required Configuration Object attribute");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002682 goto fail;
2683 }
Hai Shalomc3565922019-10-28 11:58:20 -07002684 while (conf_obj) {
2685 wpa_hexdump_ascii(MSG_DEBUG, "DPP: configurationObject JSON",
2686 conf_obj, conf_obj_len);
2687 if (dpp_parse_conf_obj(auth, conf_obj, conf_obj_len) < 0)
2688 goto fail;
2689 conf_obj = dpp_get_attr_next(conf_obj, unwrapped, unwrapped_len,
2690 DPP_ATTR_CONFIG_OBJ,
2691 &conf_obj_len);
2692 }
2693
2694#ifdef CONFIG_DPP2
2695 status = dpp_get_attr(unwrapped, unwrapped_len,
2696 DPP_ATTR_SEND_CONN_STATUS, &status_len);
2697 if (status) {
2698 wpa_printf(MSG_DEBUG,
2699 "DPP: Configurator requested connection status result");
2700 auth->conn_status_requested = 1;
2701 }
2702#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002703
2704 ret = 0;
2705
2706fail:
2707 os_free(unwrapped);
2708 return ret;
2709}
2710
2711
Hai Shalom021b0b52019-04-10 11:17:58 -07002712#ifdef CONFIG_DPP2
Hai Shalomc3565922019-10-28 11:58:20 -07002713
Hai Shalom021b0b52019-04-10 11:17:58 -07002714enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth,
2715 const u8 *hdr,
2716 const u8 *attr_start, size_t attr_len)
2717{
2718 const u8 *wrapped_data, *status, *e_nonce;
2719 u16 wrapped_data_len, status_len, e_nonce_len;
2720 const u8 *addr[2];
2721 size_t len[2];
2722 u8 *unwrapped = NULL;
2723 size_t unwrapped_len = 0;
2724 enum dpp_status_error ret = 256;
2725
2726 wrapped_data = dpp_get_attr(attr_start, attr_len, DPP_ATTR_WRAPPED_DATA,
2727 &wrapped_data_len);
2728 if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) {
2729 dpp_auth_fail(auth,
2730 "Missing or invalid required Wrapped Data attribute");
2731 goto fail;
2732 }
2733 wpa_hexdump(MSG_DEBUG, "DPP: Wrapped data",
2734 wrapped_data, wrapped_data_len);
2735
2736 attr_len = wrapped_data - 4 - attr_start;
2737
2738 addr[0] = hdr;
2739 len[0] = DPP_HDR_LEN;
2740 addr[1] = attr_start;
2741 len[1] = attr_len;
2742 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]);
2743 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]);
2744 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext",
2745 wrapped_data, wrapped_data_len);
2746 unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE;
2747 unwrapped = os_malloc(unwrapped_len);
2748 if (!unwrapped)
2749 goto fail;
2750 if (aes_siv_decrypt(auth->ke, auth->curve->hash_len,
2751 wrapped_data, wrapped_data_len,
2752 2, addr, len, unwrapped) < 0) {
2753 dpp_auth_fail(auth, "AES-SIV decryption failed");
2754 goto fail;
2755 }
2756 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext",
2757 unwrapped, unwrapped_len);
2758
2759 if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) {
2760 dpp_auth_fail(auth, "Invalid attribute in unwrapped data");
2761 goto fail;
2762 }
2763
2764 e_nonce = dpp_get_attr(unwrapped, unwrapped_len,
2765 DPP_ATTR_ENROLLEE_NONCE,
2766 &e_nonce_len);
2767 if (!e_nonce || e_nonce_len != auth->curve->nonce_len) {
2768 dpp_auth_fail(auth,
2769 "Missing or invalid Enrollee Nonce attribute");
2770 goto fail;
2771 }
2772 wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len);
2773 if (os_memcmp(e_nonce, auth->e_nonce, e_nonce_len) != 0) {
2774 dpp_auth_fail(auth, "Enrollee Nonce mismatch");
2775 wpa_hexdump(MSG_DEBUG, "DPP: Expected Enrollee Nonce",
2776 auth->e_nonce, e_nonce_len);
2777 goto fail;
2778 }
2779
2780 status = dpp_get_attr(unwrapped, unwrapped_len, DPP_ATTR_STATUS,
2781 &status_len);
2782 if (!status || status_len < 1) {
2783 dpp_auth_fail(auth,
2784 "Missing or invalid required DPP Status attribute");
2785 goto fail;
2786 }
2787 wpa_printf(MSG_DEBUG, "DPP: Status %u", status[0]);
2788 ret = status[0];
2789
2790fail:
2791 bin_clear_free(unwrapped, unwrapped_len);
2792 return ret;
2793}
Hai Shalom021b0b52019-04-10 11:17:58 -07002794
2795
2796struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth,
2797 enum dpp_status_error status)
2798{
2799 struct wpabuf *msg, *clear;
2800 size_t nonce_len, clear_len, attr_len;
2801 const u8 *addr[2];
2802 size_t len[2];
2803 u8 *wrapped;
2804
2805 nonce_len = auth->curve->nonce_len;
2806 clear_len = 5 + 4 + nonce_len;
2807 attr_len = 4 + clear_len + AES_BLOCK_SIZE;
2808 clear = wpabuf_alloc(clear_len);
2809 msg = dpp_alloc_msg(DPP_PA_CONFIGURATION_RESULT, attr_len);
2810 if (!clear || !msg)
Hai Shalomc3565922019-10-28 11:58:20 -07002811 goto fail;
Hai Shalom021b0b52019-04-10 11:17:58 -07002812
2813 /* DPP Status */
2814 dpp_build_attr_status(clear, status);
2815
2816 /* E-nonce */
2817 wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE);
2818 wpabuf_put_le16(clear, nonce_len);
2819 wpabuf_put_data(clear, auth->e_nonce, nonce_len);
2820
2821 /* OUI, OUI type, Crypto Suite, DPP frame type */
2822 addr[0] = wpabuf_head_u8(msg) + 2;
2823 len[0] = 3 + 1 + 1 + 1;
2824 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]);
2825
2826 /* Attributes before Wrapped Data (none) */
2827 addr[1] = wpabuf_put(msg, 0);
2828 len[1] = 0;
2829 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]);
2830
2831 /* Wrapped Data */
2832 wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA);
2833 wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
2834 wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
2835
2836 wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear);
2837 if (aes_siv_encrypt(auth->ke, auth->curve->hash_len,
2838 wpabuf_head(clear), wpabuf_len(clear),
2839 2, addr, len, wrapped) < 0)
2840 goto fail;
2841
2842 wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Result attributes", msg);
2843 wpabuf_free(clear);
2844 return msg;
2845fail:
2846 wpabuf_free(clear);
2847 wpabuf_free(msg);
2848 return NULL;
2849}
2850
2851
Hai Shalomc3565922019-10-28 11:58:20 -07002852static int valid_channel_list(const char *val)
2853{
2854 while (*val) {
2855 if (!((*val >= '0' && *val <= '9') ||
2856 *val == '/' || *val == ','))
2857 return 0;
2858 val++;
2859 }
2860
2861 return 1;
2862}
2863
2864
2865enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth,
2866 const u8 *hdr,
2867 const u8 *attr_start,
2868 size_t attr_len,
2869 u8 *ssid, size_t *ssid_len,
2870 char **channel_list)
2871{
2872 const u8 *wrapped_data, *status, *e_nonce;
2873 u16 wrapped_data_len, status_len, e_nonce_len;
2874 const u8 *addr[2];
2875 size_t len[2];
2876 u8 *unwrapped = NULL;
2877 size_t unwrapped_len = 0;
2878 enum dpp_status_error ret = 256;
2879 struct json_token *root = NULL, *token;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002880 struct wpabuf *ssid64;
Hai Shalomc3565922019-10-28 11:58:20 -07002881
2882 *ssid_len = 0;
2883 *channel_list = NULL;
2884
2885 wrapped_data = dpp_get_attr(attr_start, attr_len, DPP_ATTR_WRAPPED_DATA,
2886 &wrapped_data_len);
2887 if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) {
2888 dpp_auth_fail(auth,
2889 "Missing or invalid required Wrapped Data attribute");
2890 goto fail;
2891 }
2892 wpa_hexdump(MSG_DEBUG, "DPP: Wrapped data",
2893 wrapped_data, wrapped_data_len);
2894
2895 attr_len = wrapped_data - 4 - attr_start;
2896
2897 addr[0] = hdr;
2898 len[0] = DPP_HDR_LEN;
2899 addr[1] = attr_start;
2900 len[1] = attr_len;
2901 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]);
2902 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]);
2903 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext",
2904 wrapped_data, wrapped_data_len);
2905 unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE;
2906 unwrapped = os_malloc(unwrapped_len);
2907 if (!unwrapped)
2908 goto fail;
2909 if (aes_siv_decrypt(auth->ke, auth->curve->hash_len,
2910 wrapped_data, wrapped_data_len,
2911 2, addr, len, unwrapped) < 0) {
2912 dpp_auth_fail(auth, "AES-SIV decryption failed");
2913 goto fail;
2914 }
2915 wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext",
2916 unwrapped, unwrapped_len);
2917
2918 if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) {
2919 dpp_auth_fail(auth, "Invalid attribute in unwrapped data");
2920 goto fail;
2921 }
2922
2923 e_nonce = dpp_get_attr(unwrapped, unwrapped_len,
2924 DPP_ATTR_ENROLLEE_NONCE,
2925 &e_nonce_len);
2926 if (!e_nonce || e_nonce_len != auth->curve->nonce_len) {
2927 dpp_auth_fail(auth,
2928 "Missing or invalid Enrollee Nonce attribute");
2929 goto fail;
2930 }
2931 wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len);
2932 if (os_memcmp(e_nonce, auth->e_nonce, e_nonce_len) != 0) {
2933 dpp_auth_fail(auth, "Enrollee Nonce mismatch");
2934 wpa_hexdump(MSG_DEBUG, "DPP: Expected Enrollee Nonce",
2935 auth->e_nonce, e_nonce_len);
2936 goto fail;
2937 }
2938
2939 status = dpp_get_attr(unwrapped, unwrapped_len, DPP_ATTR_CONN_STATUS,
2940 &status_len);
2941 if (!status) {
2942 dpp_auth_fail(auth,
2943 "Missing required DPP Connection Status attribute");
2944 goto fail;
2945 }
2946 wpa_hexdump_ascii(MSG_DEBUG, "DPP: connStatus JSON",
2947 status, status_len);
2948
2949 root = json_parse((const char *) status, status_len);
2950 if (!root) {
2951 dpp_auth_fail(auth, "Could not parse connStatus");
2952 goto fail;
2953 }
2954
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002955 ssid64 = json_get_member_base64url(root, "ssid64");
2956 if (ssid64 && wpabuf_len(ssid64) <= SSID_MAX_LEN) {
2957 *ssid_len = wpabuf_len(ssid64);
2958 os_memcpy(ssid, wpabuf_head(ssid64), *ssid_len);
Hai Shalomc3565922019-10-28 11:58:20 -07002959 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002960 wpabuf_free(ssid64);
Hai Shalomc3565922019-10-28 11:58:20 -07002961
2962 token = json_get_member(root, "channelList");
2963 if (token && token->type == JSON_STRING &&
2964 valid_channel_list(token->string))
2965 *channel_list = os_strdup(token->string);
2966
2967 token = json_get_member(root, "result");
2968 if (!token || token->type != JSON_NUMBER) {
2969 dpp_auth_fail(auth, "No connStatus - result");
2970 goto fail;
2971 }
2972 wpa_printf(MSG_DEBUG, "DPP: result %d", token->number);
2973 ret = token->number;
2974
2975fail:
2976 json_free(root);
2977 bin_clear_free(unwrapped, unwrapped_len);
2978 return ret;
2979}
2980
2981
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002982struct wpabuf * dpp_build_conn_status(enum dpp_status_error result,
2983 const u8 *ssid, size_t ssid_len,
2984 const char *channel_list)
2985{
2986 struct wpabuf *json;
2987
2988 json = wpabuf_alloc(1000);
2989 if (!json)
2990 return NULL;
2991 json_start_object(json, NULL);
2992 json_add_int(json, "result", result);
2993 if (ssid) {
2994 json_value_sep(json);
2995 if (json_add_base64url(json, "ssid64", ssid, ssid_len) < 0) {
2996 wpabuf_free(json);
2997 return NULL;
2998 }
2999 }
3000 if (channel_list) {
3001 json_value_sep(json);
3002 json_add_string(json, "channelList", channel_list);
3003 }
3004 json_end_object(json);
3005 wpa_hexdump_ascii(MSG_DEBUG, "DPP: connStatus JSON",
3006 wpabuf_head(json), wpabuf_len(json));
3007
3008 return json;
3009}
3010
3011
Hai Shalomc3565922019-10-28 11:58:20 -07003012struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth,
3013 enum dpp_status_error result,
3014 const u8 *ssid, size_t ssid_len,
3015 const char *channel_list)
3016{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003017 struct wpabuf *msg = NULL, *clear = NULL, *json;
Hai Shalomc3565922019-10-28 11:58:20 -07003018 size_t nonce_len, clear_len, attr_len;
3019 const u8 *addr[2];
3020 size_t len[2];
3021 u8 *wrapped;
3022
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003023 json = dpp_build_conn_status(result, ssid, ssid_len, channel_list);
Hai Shalomc3565922019-10-28 11:58:20 -07003024 if (!json)
3025 return NULL;
Hai Shalomc3565922019-10-28 11:58:20 -07003026
3027 nonce_len = auth->curve->nonce_len;
3028 clear_len = 5 + 4 + nonce_len + 4 + wpabuf_len(json);
3029 attr_len = 4 + clear_len + AES_BLOCK_SIZE;
3030 clear = wpabuf_alloc(clear_len);
3031 msg = dpp_alloc_msg(DPP_PA_CONNECTION_STATUS_RESULT, attr_len);
3032 if (!clear || !msg)
3033 goto fail;
3034
3035 /* E-nonce */
3036 wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE);
3037 wpabuf_put_le16(clear, nonce_len);
3038 wpabuf_put_data(clear, auth->e_nonce, nonce_len);
3039
3040 /* DPP Connection Status */
3041 wpabuf_put_le16(clear, DPP_ATTR_CONN_STATUS);
3042 wpabuf_put_le16(clear, wpabuf_len(json));
3043 wpabuf_put_buf(clear, json);
3044
3045 /* OUI, OUI type, Crypto Suite, DPP frame type */
3046 addr[0] = wpabuf_head_u8(msg) + 2;
3047 len[0] = 3 + 1 + 1 + 1;
3048 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]);
3049
3050 /* Attributes before Wrapped Data (none) */
3051 addr[1] = wpabuf_put(msg, 0);
3052 len[1] = 0;
3053 wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]);
3054
3055 /* Wrapped Data */
3056 wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA);
3057 wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
3058 wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE);
3059
3060 wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear);
3061 if (aes_siv_encrypt(auth->ke, auth->curve->hash_len,
3062 wpabuf_head(clear), wpabuf_len(clear),
3063 2, addr, len, wrapped) < 0)
3064 goto fail;
3065
3066 wpa_hexdump_buf(MSG_DEBUG, "DPP: Connection Status Result attributes",
3067 msg);
3068 wpabuf_free(json);
3069 wpabuf_free(clear);
3070 return msg;
3071fail:
3072 wpabuf_free(json);
3073 wpabuf_free(clear);
3074 wpabuf_free(msg);
3075 return NULL;
3076}
3077
3078#endif /* CONFIG_DPP2 */
3079
3080
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003081void dpp_configurator_free(struct dpp_configurator *conf)
3082{
3083 if (!conf)
3084 return;
3085 EVP_PKEY_free(conf->csign);
3086 os_free(conf->kid);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003087 os_free(conf->connector);
3088 EVP_PKEY_free(conf->connector_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003089 os_free(conf);
3090}
3091
3092
Roshan Pius3a1667e2018-07-03 15:17:14 -07003093int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf,
3094 size_t buflen)
3095{
3096 EC_KEY *eckey;
3097 int key_len, ret = -1;
3098 unsigned char *key = NULL;
3099
3100 if (!conf->csign)
3101 return -1;
3102
3103 eckey = EVP_PKEY_get1_EC_KEY(conf->csign);
3104 if (!eckey)
3105 return -1;
3106
3107 key_len = i2d_ECPrivateKey(eckey, &key);
3108 if (key_len > 0)
3109 ret = wpa_snprintf_hex(buf, buflen, key, key_len);
3110
3111 EC_KEY_free(eckey);
3112 OPENSSL_free(key);
3113 return ret;
3114}
3115
3116
Hai Shalomfdcde762020-04-02 11:19:20 -07003117static int dpp_configurator_gen_kid(struct dpp_configurator *conf)
3118{
3119 struct wpabuf *csign_pub = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07003120 const u8 *addr[1];
3121 size_t len[1];
3122 int res;
3123
3124 csign_pub = dpp_get_pubkey_point(conf->csign, 1);
3125 if (!csign_pub) {
3126 wpa_printf(MSG_INFO, "DPP: Failed to extract C-sign-key");
3127 return -1;
3128 }
3129
3130 /* kid = SHA256(ANSI X9.63 uncompressed C-sign-key) */
3131 addr[0] = wpabuf_head(csign_pub);
3132 len[0] = wpabuf_len(csign_pub);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003133 res = sha256_vector(1, addr, len, conf->kid_hash);
Hai Shalomfdcde762020-04-02 11:19:20 -07003134 wpabuf_free(csign_pub);
3135 if (res < 0) {
3136 wpa_printf(MSG_DEBUG,
3137 "DPP: Failed to derive kid for C-sign-key");
3138 return -1;
3139 }
3140
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003141 conf->kid = base64_url_encode(conf->kid_hash, sizeof(conf->kid_hash),
3142 NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003143 return conf->kid ? 0 : -1;
3144}
3145
3146
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003147struct dpp_configurator *
3148dpp_keygen_configurator(const char *curve, const u8 *privkey,
3149 size_t privkey_len)
3150{
3151 struct dpp_configurator *conf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003152
3153 conf = os_zalloc(sizeof(*conf));
3154 if (!conf)
3155 return NULL;
3156
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003157 conf->curve = dpp_get_curve_name(curve);
3158 if (!conf->curve) {
3159 wpa_printf(MSG_INFO, "DPP: Unsupported curve: %s", curve);
3160 os_free(conf);
3161 return NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003162 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003163
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003164 if (privkey)
3165 conf->csign = dpp_set_keypair(&conf->curve, privkey,
3166 privkey_len);
3167 else
3168 conf->csign = dpp_gen_keypair(conf->curve);
3169 if (!conf->csign)
3170 goto fail;
3171 conf->own = 1;
3172
Hai Shalomfdcde762020-04-02 11:19:20 -07003173 if (dpp_configurator_gen_kid(conf) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003174 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003175 return conf;
3176fail:
3177 dpp_configurator_free(conf);
Hai Shalomfdcde762020-04-02 11:19:20 -07003178 return NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003179}
3180
3181
3182int dpp_configurator_own_config(struct dpp_authentication *auth,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003183 const char *curve, int ap)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003184{
3185 struct wpabuf *conf_obj;
3186 int ret = -1;
3187
3188 if (!auth->conf) {
3189 wpa_printf(MSG_DEBUG, "DPP: No configurator specified");
3190 return -1;
3191 }
3192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003193 auth->curve = dpp_get_curve_name(curve);
3194 if (!auth->curve) {
3195 wpa_printf(MSG_INFO, "DPP: Unsupported curve: %s", curve);
3196 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003197 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003198
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003199 wpa_printf(MSG_DEBUG,
3200 "DPP: Building own configuration/connector with curve %s",
3201 auth->curve->name);
3202
3203 auth->own_protocol_key = dpp_gen_keypair(auth->curve);
3204 if (!auth->own_protocol_key)
3205 return -1;
Hai Shalomc3565922019-10-28 11:58:20 -07003206 dpp_copy_netaccesskey(auth, &auth->conf_obj[0]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003207 auth->peer_protocol_key = auth->own_protocol_key;
Hai Shalomc3565922019-10-28 11:58:20 -07003208 dpp_copy_csign(&auth->conf_obj[0], auth->conf->csign);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003209
Hai Shalomc3565922019-10-28 11:58:20 -07003210 conf_obj = dpp_build_conf_obj(auth, ap, 0);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003211 if (!conf_obj) {
3212 wpabuf_free(auth->conf_obj[0].c_sign_key);
3213 auth->conf_obj[0].c_sign_key = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003214 goto fail;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003215 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003216 ret = dpp_parse_conf_obj(auth, wpabuf_head(conf_obj),
3217 wpabuf_len(conf_obj));
3218fail:
3219 wpabuf_free(conf_obj);
3220 auth->peer_protocol_key = NULL;
3221 return ret;
3222}
3223
3224
3225static int dpp_compatible_netrole(const char *role1, const char *role2)
3226{
3227 return (os_strcmp(role1, "sta") == 0 && os_strcmp(role2, "ap") == 0) ||
3228 (os_strcmp(role1, "ap") == 0 && os_strcmp(role2, "sta") == 0);
3229}
3230
3231
3232static int dpp_connector_compatible_group(struct json_token *root,
3233 const char *group_id,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003234 const char *net_role,
3235 bool reconfig)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003236{
3237 struct json_token *groups, *token;
3238
3239 groups = json_get_member(root, "groups");
3240 if (!groups || groups->type != JSON_ARRAY)
3241 return 0;
3242
3243 for (token = groups->child; token; token = token->sibling) {
3244 struct json_token *id, *role;
3245
3246 id = json_get_member(token, "groupId");
3247 if (!id || id->type != JSON_STRING)
3248 continue;
3249
3250 role = json_get_member(token, "netRole");
3251 if (!role || role->type != JSON_STRING)
3252 continue;
3253
3254 if (os_strcmp(id->string, "*") != 0 &&
3255 os_strcmp(group_id, "*") != 0 &&
3256 os_strcmp(id->string, group_id) != 0)
3257 continue;
3258
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003259 if (reconfig && os_strcmp(net_role, "configurator") == 0)
3260 return 1;
3261 if (!reconfig && dpp_compatible_netrole(role->string, net_role))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003262 return 1;
3263 }
3264
3265 return 0;
3266}
3267
3268
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003269int dpp_connector_match_groups(struct json_token *own_root,
3270 struct json_token *peer_root, bool reconfig)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003271{
3272 struct json_token *groups, *token;
3273
3274 groups = json_get_member(peer_root, "groups");
3275 if (!groups || groups->type != JSON_ARRAY) {
3276 wpa_printf(MSG_DEBUG, "DPP: No peer groups array found");
3277 return 0;
3278 }
3279
3280 for (token = groups->child; token; token = token->sibling) {
3281 struct json_token *id, *role;
3282
3283 id = json_get_member(token, "groupId");
3284 if (!id || id->type != JSON_STRING) {
3285 wpa_printf(MSG_DEBUG,
3286 "DPP: Missing peer groupId string");
3287 continue;
3288 }
3289
3290 role = json_get_member(token, "netRole");
3291 if (!role || role->type != JSON_STRING) {
3292 wpa_printf(MSG_DEBUG,
3293 "DPP: Missing peer groups::netRole string");
3294 continue;
3295 }
3296 wpa_printf(MSG_DEBUG,
3297 "DPP: peer connector group: groupId='%s' netRole='%s'",
3298 id->string, role->string);
3299 if (dpp_connector_compatible_group(own_root, id->string,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003300 role->string, reconfig)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003301 wpa_printf(MSG_DEBUG,
3302 "DPP: Compatible group/netRole in own connector");
3303 return 1;
3304 }
3305 }
3306
3307 return 0;
3308}
3309
3310
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003311struct json_token * dpp_parse_own_connector(const char *own_connector)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003312{
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003313 unsigned char *own_conn;
3314 size_t own_conn_len;
3315 const char *pos, *end;
3316 struct json_token *own_root;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003317
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003318 pos = os_strchr(own_connector, '.');
3319 if (!pos) {
3320 wpa_printf(MSG_DEBUG, "DPP: Own connector is missing the first dot (.)");
3321 return NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003322 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003323 pos++;
3324 end = os_strchr(pos, '.');
3325 if (!end) {
3326 wpa_printf(MSG_DEBUG, "DPP: Own connector is missing the second dot (.)");
3327 return NULL;
3328 }
3329 own_conn = base64_url_decode(pos, end - pos, &own_conn_len);
3330 if (!own_conn) {
3331 wpa_printf(MSG_DEBUG,
3332 "DPP: Failed to base64url decode own signedConnector JWS Payload");
3333 return NULL;
3334 }
3335
3336 own_root = json_parse((const char *) own_conn, own_conn_len);
3337 os_free(own_conn);
3338 if (!own_root)
3339 wpa_printf(MSG_DEBUG, "DPP: Failed to parse local connector");
3340
3341 return own_root;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003342}
3343
3344
Roshan Pius3a1667e2018-07-03 15:17:14 -07003345enum dpp_status_error
3346dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
3347 const u8 *net_access_key, size_t net_access_key_len,
3348 const u8 *csign_key, size_t csign_key_len,
3349 const u8 *peer_connector, size_t peer_connector_len,
3350 os_time_t *expiry)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003351{
3352 struct json_token *root = NULL, *netkey, *token;
3353 struct json_token *own_root = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003354 enum dpp_status_error ret = 255, res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003355 EVP_PKEY *own_key = NULL, *peer_key = NULL;
3356 struct wpabuf *own_key_pub = NULL;
3357 const struct dpp_curve_params *curve, *own_curve;
3358 struct dpp_signed_connector_info info;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003359 size_t Nx_len;
3360 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
3361
3362 os_memset(intro, 0, sizeof(*intro));
3363 os_memset(&info, 0, sizeof(info));
3364 if (expiry)
3365 *expiry = 0;
3366
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003367 own_key = dpp_set_keypair(&own_curve, net_access_key,
3368 net_access_key_len);
3369 if (!own_key) {
3370 wpa_printf(MSG_ERROR, "DPP: Failed to parse own netAccessKey");
3371 goto fail;
3372 }
3373
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003374 own_root = dpp_parse_own_connector(own_connector);
3375 if (!own_root)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003376 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003377
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003378 res = dpp_check_signed_connector(&info, csign_key, csign_key_len,
3379 peer_connector, peer_connector_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003380 if (res != DPP_STATUS_OK) {
3381 ret = res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003382 goto fail;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003383 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003384
3385 root = json_parse((const char *) info.payload, info.payload_len);
3386 if (!root) {
3387 wpa_printf(MSG_DEBUG, "DPP: JSON parsing of connector failed");
Roshan Pius3a1667e2018-07-03 15:17:14 -07003388 ret = DPP_STATUS_INVALID_CONNECTOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003389 goto fail;
3390 }
3391
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003392 if (!dpp_connector_match_groups(own_root, root, false)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003393 wpa_printf(MSG_DEBUG,
3394 "DPP: Peer connector does not include compatible group netrole with own connector");
Roshan Pius3a1667e2018-07-03 15:17:14 -07003395 ret = DPP_STATUS_NO_MATCH;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003396 goto fail;
3397 }
3398
3399 token = json_get_member(root, "expiry");
3400 if (!token || token->type != JSON_STRING) {
3401 wpa_printf(MSG_DEBUG,
3402 "DPP: No expiry string found - connector does not expire");
3403 } else {
3404 wpa_printf(MSG_DEBUG, "DPP: expiry = %s", token->string);
3405 if (dpp_key_expired(token->string, expiry)) {
3406 wpa_printf(MSG_DEBUG,
3407 "DPP: Connector (netAccessKey) has expired");
Roshan Pius3a1667e2018-07-03 15:17:14 -07003408 ret = DPP_STATUS_INVALID_CONNECTOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003409 goto fail;
3410 }
3411 }
3412
3413 netkey = json_get_member(root, "netAccessKey");
3414 if (!netkey || netkey->type != JSON_OBJECT) {
3415 wpa_printf(MSG_DEBUG, "DPP: No netAccessKey object found");
Roshan Pius3a1667e2018-07-03 15:17:14 -07003416 ret = DPP_STATUS_INVALID_CONNECTOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003417 goto fail;
3418 }
3419
3420 peer_key = dpp_parse_jwk(netkey, &curve);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003421 if (!peer_key) {
3422 ret = DPP_STATUS_INVALID_CONNECTOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003423 goto fail;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003424 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003425 dpp_debug_print_key("DPP: Received netAccessKey", peer_key);
3426
3427 if (own_curve != curve) {
3428 wpa_printf(MSG_DEBUG,
3429 "DPP: Mismatching netAccessKey curves (%s != %s)",
3430 own_curve->name, curve->name);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003431 ret = DPP_STATUS_INVALID_CONNECTOR;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003432 goto fail;
3433 }
3434
3435 /* ECDH: N = nk * PK */
Hai Shalomc3565922019-10-28 11:58:20 -07003436 if (dpp_ecdh(own_key, peer_key, Nx, &Nx_len) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003437 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003438
3439 wpa_hexdump_key(MSG_DEBUG, "DPP: ECDH shared secret (N.x)",
3440 Nx, Nx_len);
3441
3442 /* PMK = HKDF(<>, "DPP PMK", N.x) */
3443 if (dpp_derive_pmk(Nx, Nx_len, intro->pmk, curve->hash_len) < 0) {
3444 wpa_printf(MSG_ERROR, "DPP: Failed to derive PMK");
3445 goto fail;
3446 }
3447 intro->pmk_len = curve->hash_len;
3448
3449 /* PMKID = Truncate-128(H(min(NK.x, PK.x) | max(NK.x, PK.x))) */
3450 if (dpp_derive_pmkid(curve, own_key, peer_key, intro->pmkid) < 0) {
3451 wpa_printf(MSG_ERROR, "DPP: Failed to derive PMKID");
3452 goto fail;
3453 }
3454
Roshan Pius3a1667e2018-07-03 15:17:14 -07003455 ret = DPP_STATUS_OK;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003456fail:
Roshan Pius3a1667e2018-07-03 15:17:14 -07003457 if (ret != DPP_STATUS_OK)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003458 os_memset(intro, 0, sizeof(*intro));
3459 os_memset(Nx, 0, sizeof(Nx));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003460 os_free(info.payload);
3461 EVP_PKEY_free(own_key);
3462 wpabuf_free(own_key_pub);
3463 EVP_PKEY_free(peer_key);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003464 json_free(root);
3465 json_free(own_root);
3466 return ret;
3467}
3468
3469
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003470unsigned int dpp_next_id(struct dpp_global *dpp)
Hai Shalom021b0b52019-04-10 11:17:58 -07003471{
3472 struct dpp_bootstrap_info *bi;
3473 unsigned int max_id = 0;
3474
3475 dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) {
3476 if (bi->id > max_id)
3477 max_id = bi->id;
3478 }
3479 return max_id + 1;
3480}
3481
3482
3483static int dpp_bootstrap_del(struct dpp_global *dpp, unsigned int id)
3484{
3485 struct dpp_bootstrap_info *bi, *tmp;
3486 int found = 0;
3487
3488 if (!dpp)
3489 return -1;
3490
3491 dl_list_for_each_safe(bi, tmp, &dpp->bootstrap,
3492 struct dpp_bootstrap_info, list) {
3493 if (id && bi->id != id)
3494 continue;
3495 found = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003496#ifdef CONFIG_DPP2
3497 if (dpp->remove_bi)
3498 dpp->remove_bi(dpp->cb_ctx, bi);
3499#endif /* CONFIG_DPP2 */
Hai Shalom021b0b52019-04-10 11:17:58 -07003500 dl_list_del(&bi->list);
3501 dpp_bootstrap_info_free(bi);
3502 }
3503
3504 if (id == 0)
3505 return 0; /* flush succeeds regardless of entries found */
3506 return found ? 0 : -1;
3507}
3508
3509
3510struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp,
3511 const char *uri)
3512{
3513 struct dpp_bootstrap_info *bi;
3514
3515 if (!dpp)
3516 return NULL;
3517
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003518 bi = dpp_parse_uri(uri);
Hai Shalom021b0b52019-04-10 11:17:58 -07003519 if (!bi)
3520 return NULL;
3521
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003522 bi->type = DPP_BOOTSTRAP_QR_CODE;
3523 bi->id = dpp_next_id(dpp);
3524 dl_list_add(&dpp->bootstrap, &bi->list);
3525 return bi;
3526}
3527
3528
3529struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp,
3530 const char *uri)
3531{
3532 struct dpp_bootstrap_info *bi;
3533
3534 if (!dpp)
3535 return NULL;
3536
3537 bi = dpp_parse_uri(uri);
3538 if (!bi)
3539 return NULL;
3540
3541 bi->type = DPP_BOOTSTRAP_NFC_URI;
Hai Shalom021b0b52019-04-10 11:17:58 -07003542 bi->id = dpp_next_id(dpp);
3543 dl_list_add(&dpp->bootstrap, &bi->list);
3544 return bi;
3545}
3546
3547
3548int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd)
3549{
Hai Shalomfdcde762020-04-02 11:19:20 -07003550 char *mac = NULL, *info = NULL, *curve = NULL;
Hai Shalom021b0b52019-04-10 11:17:58 -07003551 char *key = NULL;
3552 u8 *privkey = NULL;
3553 size_t privkey_len = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07003554 int ret = -1;
3555 struct dpp_bootstrap_info *bi;
3556
3557 if (!dpp)
3558 return -1;
3559
3560 bi = os_zalloc(sizeof(*bi));
3561 if (!bi)
3562 goto fail;
3563
3564 if (os_strstr(cmd, "type=qrcode"))
3565 bi->type = DPP_BOOTSTRAP_QR_CODE;
3566 else if (os_strstr(cmd, "type=pkex"))
3567 bi->type = DPP_BOOTSTRAP_PKEX;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003568 else if (os_strstr(cmd, "type=nfc-uri"))
3569 bi->type = DPP_BOOTSTRAP_NFC_URI;
Hai Shalom021b0b52019-04-10 11:17:58 -07003570 else
3571 goto fail;
3572
Hai Shalomfdcde762020-04-02 11:19:20 -07003573 bi->chan = get_param(cmd, " chan=");
Hai Shalom021b0b52019-04-10 11:17:58 -07003574 mac = get_param(cmd, " mac=");
3575 info = get_param(cmd, " info=");
3576 curve = get_param(cmd, " curve=");
3577 key = get_param(cmd, " key=");
3578
3579 if (key) {
3580 privkey_len = os_strlen(key) / 2;
3581 privkey = os_malloc(privkey_len);
3582 if (!privkey ||
3583 hexstr2bin(key, privkey, privkey_len) < 0)
3584 goto fail;
3585 }
3586
Hai Shalomfdcde762020-04-02 11:19:20 -07003587 if (dpp_keygen(bi, curve, privkey, privkey_len) < 0 ||
3588 dpp_parse_uri_chan_list(bi, bi->chan) < 0 ||
3589 dpp_parse_uri_mac(bi, mac) < 0 ||
3590 dpp_parse_uri_info(bi, info) < 0 ||
3591 dpp_gen_uri(bi) < 0)
Hai Shalom021b0b52019-04-10 11:17:58 -07003592 goto fail;
3593
Hai Shalom021b0b52019-04-10 11:17:58 -07003594 bi->id = dpp_next_id(dpp);
3595 dl_list_add(&dpp->bootstrap, &bi->list);
3596 ret = bi->id;
3597 bi = NULL;
3598fail:
3599 os_free(curve);
Hai Shalom021b0b52019-04-10 11:17:58 -07003600 os_free(mac);
3601 os_free(info);
3602 str_clear_free(key);
3603 bin_clear_free(privkey, privkey_len);
3604 dpp_bootstrap_info_free(bi);
3605 return ret;
3606}
3607
3608
3609struct dpp_bootstrap_info *
3610dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id)
3611{
3612 struct dpp_bootstrap_info *bi;
3613
3614 if (!dpp)
3615 return NULL;
3616
3617 dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) {
3618 if (bi->id == id)
3619 return bi;
3620 }
3621 return NULL;
3622}
3623
3624
3625int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id)
3626{
3627 unsigned int id_val;
3628
3629 if (os_strcmp(id, "*") == 0) {
3630 id_val = 0;
3631 } else {
3632 id_val = atoi(id);
3633 if (id_val == 0)
3634 return -1;
3635 }
3636
3637 return dpp_bootstrap_del(dpp, id_val);
3638}
3639
3640
Hai Shalom021b0b52019-04-10 11:17:58 -07003641const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id)
3642{
3643 struct dpp_bootstrap_info *bi;
3644
3645 bi = dpp_bootstrap_get_id(dpp, id);
3646 if (!bi)
3647 return NULL;
3648 return bi->uri;
3649}
3650
3651
3652int dpp_bootstrap_info(struct dpp_global *dpp, int id,
3653 char *reply, int reply_size)
3654{
3655 struct dpp_bootstrap_info *bi;
Hai Shalom81f62d82019-07-22 12:10:00 -07003656 char pkhash[2 * SHA256_MAC_LEN + 1];
Hai Shalom021b0b52019-04-10 11:17:58 -07003657
3658 bi = dpp_bootstrap_get_id(dpp, id);
3659 if (!bi)
3660 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -07003661 wpa_snprintf_hex(pkhash, sizeof(pkhash), bi->pubkey_hash,
3662 SHA256_MAC_LEN);
Hai Shalom021b0b52019-04-10 11:17:58 -07003663 return os_snprintf(reply, reply_size, "type=%s\n"
3664 "mac_addr=" MACSTR "\n"
3665 "info=%s\n"
3666 "num_freq=%u\n"
Hai Shalomfdcde762020-04-02 11:19:20 -07003667 "use_freq=%u\n"
Hai Shalom81f62d82019-07-22 12:10:00 -07003668 "curve=%s\n"
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003669 "pkhash=%s\n"
3670 "version=%d\n",
Hai Shalom021b0b52019-04-10 11:17:58 -07003671 dpp_bootstrap_type_txt(bi->type),
3672 MAC2STR(bi->mac_addr),
3673 bi->info ? bi->info : "",
3674 bi->num_freq,
Hai Shalomfdcde762020-04-02 11:19:20 -07003675 bi->num_freq == 1 ? bi->freq[0] : 0,
Hai Shalom81f62d82019-07-22 12:10:00 -07003676 bi->curve->name,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003677 pkhash,
3678 bi->version);
Hai Shalom021b0b52019-04-10 11:17:58 -07003679}
3680
3681
Hai Shalomfdcde762020-04-02 11:19:20 -07003682int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params)
3683{
3684 struct dpp_bootstrap_info *bi;
3685
3686 bi = dpp_bootstrap_get_id(dpp, id);
3687 if (!bi)
3688 return -1;
3689
3690 str_clear_free(bi->configurator_params);
3691
3692 if (params) {
3693 bi->configurator_params = os_strdup(params);
3694 return bi->configurator_params ? 0 : -1;
3695 }
3696
3697 bi->configurator_params = NULL;
3698 return 0;
3699}
3700
3701
Hai Shalom021b0b52019-04-10 11:17:58 -07003702void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap,
3703 const u8 *r_bootstrap,
3704 struct dpp_bootstrap_info **own_bi,
3705 struct dpp_bootstrap_info **peer_bi)
3706{
3707 struct dpp_bootstrap_info *bi;
3708
3709 *own_bi = NULL;
3710 *peer_bi = NULL;
3711 if (!dpp)
3712 return;
3713
3714 dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) {
3715 if (!*own_bi && bi->own &&
3716 os_memcmp(bi->pubkey_hash, r_bootstrap,
3717 SHA256_MAC_LEN) == 0) {
3718 wpa_printf(MSG_DEBUG,
3719 "DPP: Found matching own bootstrapping information");
3720 *own_bi = bi;
3721 }
3722
3723 if (!*peer_bi && !bi->own &&
3724 os_memcmp(bi->pubkey_hash, i_bootstrap,
3725 SHA256_MAC_LEN) == 0) {
3726 wpa_printf(MSG_DEBUG,
3727 "DPP: Found matching peer bootstrapping information");
3728 *peer_bi = bi;
3729 }
3730
3731 if (*own_bi && *peer_bi)
3732 break;
3733 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003734}
Hai Shalom021b0b52019-04-10 11:17:58 -07003735
Hai Shalomfdcde762020-04-02 11:19:20 -07003736
3737#ifdef CONFIG_DPP2
3738struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp,
3739 const u8 *hash)
3740{
3741 struct dpp_bootstrap_info *bi;
3742
3743 if (!dpp)
3744 return NULL;
3745
3746 dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) {
3747 if (!bi->own && os_memcmp(bi->pubkey_hash_chirp, hash,
3748 SHA256_MAC_LEN) == 0)
3749 return bi;
3750 }
3751
3752 return NULL;
3753}
3754#endif /* CONFIG_DPP2 */
3755
3756
3757static int dpp_nfc_update_bi_channel(struct dpp_bootstrap_info *own_bi,
3758 struct dpp_bootstrap_info *peer_bi)
3759{
3760 unsigned int i, freq = 0;
3761 enum hostapd_hw_mode mode;
3762 u8 op_class, channel;
3763 char chan[20];
3764
3765 if (peer_bi->num_freq == 0)
3766 return 0; /* no channel preference/constraint */
3767
3768 for (i = 0; i < peer_bi->num_freq; i++) {
3769 if (own_bi->num_freq == 0 ||
3770 freq_included(own_bi->freq, own_bi->num_freq,
3771 peer_bi->freq[i])) {
3772 freq = peer_bi->freq[i];
3773 break;
3774 }
3775 }
3776 if (!freq) {
3777 wpa_printf(MSG_DEBUG, "DPP: No common channel found");
3778 return -1;
3779 }
3780
3781 mode = ieee80211_freq_to_channel_ext(freq, 0, 0, &op_class, &channel);
3782 if (mode == NUM_HOSTAPD_MODES) {
3783 wpa_printf(MSG_DEBUG,
3784 "DPP: Could not determine operating class or channel number for %u MHz",
3785 freq);
3786 }
3787
3788 wpa_printf(MSG_DEBUG,
3789 "DPP: Selected %u MHz (op_class %u channel %u) as the negotiation channel based on information from NFC negotiated handover",
3790 freq, op_class, channel);
3791 os_snprintf(chan, sizeof(chan), "%u/%u", op_class, channel);
3792 os_free(own_bi->chan);
3793 own_bi->chan = os_strdup(chan);
3794 own_bi->freq[0] = freq;
3795 own_bi->num_freq = 1;
3796 os_free(peer_bi->chan);
3797 peer_bi->chan = os_strdup(chan);
3798 peer_bi->freq[0] = freq;
3799 peer_bi->num_freq = 1;
3800
3801 return dpp_gen_uri(own_bi);
3802}
3803
3804
3805static int dpp_nfc_update_bi_key(struct dpp_bootstrap_info *own_bi,
3806 struct dpp_bootstrap_info *peer_bi)
3807{
3808 if (peer_bi->curve == own_bi->curve)
3809 return 0;
3810
3811 wpa_printf(MSG_DEBUG,
3812 "DPP: Update own bootstrapping key to match peer curve from NFC handover");
3813
3814 EVP_PKEY_free(own_bi->pubkey);
3815 own_bi->pubkey = NULL;
3816
3817 if (dpp_keygen(own_bi, peer_bi->curve->name, NULL, 0) < 0 ||
3818 dpp_gen_uri(own_bi) < 0)
3819 goto fail;
3820
3821 return 0;
3822fail:
3823 dl_list_del(&own_bi->list);
3824 dpp_bootstrap_info_free(own_bi);
3825 return -1;
3826}
3827
3828
3829int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi,
3830 struct dpp_bootstrap_info *peer_bi)
3831{
3832 if (dpp_nfc_update_bi_channel(own_bi, peer_bi) < 0 ||
3833 dpp_nfc_update_bi_key(own_bi, peer_bi) < 0)
3834 return -1;
3835 return 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07003836}
3837
3838
3839static unsigned int dpp_next_configurator_id(struct dpp_global *dpp)
3840{
3841 struct dpp_configurator *conf;
3842 unsigned int max_id = 0;
3843
3844 dl_list_for_each(conf, &dpp->configurator, struct dpp_configurator,
3845 list) {
3846 if (conf->id > max_id)
3847 max_id = conf->id;
3848 }
3849 return max_id + 1;
3850}
3851
3852
3853int dpp_configurator_add(struct dpp_global *dpp, const char *cmd)
3854{
3855 char *curve = NULL;
3856 char *key = NULL;
3857 u8 *privkey = NULL;
3858 size_t privkey_len = 0;
3859 int ret = -1;
3860 struct dpp_configurator *conf = NULL;
3861
3862 curve = get_param(cmd, " curve=");
3863 key = get_param(cmd, " key=");
3864
3865 if (key) {
3866 privkey_len = os_strlen(key) / 2;
3867 privkey = os_malloc(privkey_len);
3868 if (!privkey ||
3869 hexstr2bin(key, privkey, privkey_len) < 0)
3870 goto fail;
3871 }
3872
3873 conf = dpp_keygen_configurator(curve, privkey, privkey_len);
3874 if (!conf)
3875 goto fail;
3876
3877 conf->id = dpp_next_configurator_id(dpp);
3878 dl_list_add(&dpp->configurator, &conf->list);
3879 ret = conf->id;
3880 conf = NULL;
3881fail:
3882 os_free(curve);
3883 str_clear_free(key);
3884 bin_clear_free(privkey, privkey_len);
3885 dpp_configurator_free(conf);
3886 return ret;
3887}
3888
3889
3890static int dpp_configurator_del(struct dpp_global *dpp, unsigned int id)
3891{
3892 struct dpp_configurator *conf, *tmp;
3893 int found = 0;
3894
3895 if (!dpp)
3896 return -1;
3897
3898 dl_list_for_each_safe(conf, tmp, &dpp->configurator,
3899 struct dpp_configurator, list) {
3900 if (id && conf->id != id)
3901 continue;
3902 found = 1;
3903 dl_list_del(&conf->list);
3904 dpp_configurator_free(conf);
3905 }
3906
3907 if (id == 0)
3908 return 0; /* flush succeeds regardless of entries found */
3909 return found ? 0 : -1;
3910}
3911
3912
3913int dpp_configurator_remove(struct dpp_global *dpp, const char *id)
3914{
3915 unsigned int id_val;
3916
3917 if (os_strcmp(id, "*") == 0) {
3918 id_val = 0;
3919 } else {
3920 id_val = atoi(id);
3921 if (id_val == 0)
3922 return -1;
3923 }
3924
3925 return dpp_configurator_del(dpp, id_val);
3926}
3927
3928
3929int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id,
3930 char *buf, size_t buflen)
3931{
3932 struct dpp_configurator *conf;
3933
3934 conf = dpp_configurator_get_id(dpp, id);
3935 if (!conf)
3936 return -1;
3937
3938 return dpp_configurator_get_key(conf, buf, buflen);
3939}
3940
3941
Hai Shalom81f62d82019-07-22 12:10:00 -07003942#ifdef CONFIG_DPP2
3943
Hai Shalomfdcde762020-04-02 11:19:20 -07003944int dpp_configurator_from_backup(struct dpp_global *dpp,
3945 struct dpp_asymmetric_key *key)
3946{
3947 struct dpp_configurator *conf;
3948 const EC_KEY *eckey;
3949 const EC_GROUP *group;
3950 int nid;
3951 const struct dpp_curve_params *curve;
3952
3953 if (!key->csign)
3954 return -1;
3955 eckey = EVP_PKEY_get0_EC_KEY(key->csign);
3956 if (!eckey)
3957 return -1;
3958 group = EC_KEY_get0_group(eckey);
3959 if (!group)
3960 return -1;
3961 nid = EC_GROUP_get_curve_name(group);
3962 curve = dpp_get_curve_nid(nid);
3963 if (!curve) {
3964 wpa_printf(MSG_INFO, "DPP: Unsupported group in c-sign-key");
3965 return -1;
3966 }
3967
3968 conf = os_zalloc(sizeof(*conf));
3969 if (!conf)
3970 return -1;
3971 conf->curve = curve;
3972 conf->csign = key->csign;
3973 key->csign = NULL;
3974 conf->own = 1;
3975 if (dpp_configurator_gen_kid(conf) < 0) {
3976 dpp_configurator_free(conf);
3977 return -1;
3978 }
3979
3980 conf->id = dpp_next_configurator_id(dpp);
3981 dl_list_add(&dpp->configurator, &conf->list);
3982 return conf->id;
3983}
3984
3985
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003986struct dpp_configurator * dpp_configurator_find_kid(struct dpp_global *dpp,
3987 const u8 *kid)
Hai Shalom81f62d82019-07-22 12:10:00 -07003988{
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003989 struct dpp_configurator *conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07003990
3991 if (!dpp)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003992 return NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -07003993
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003994 dl_list_for_each(conf, &dpp->configurator,
3995 struct dpp_configurator, list) {
3996 if (os_memcmp(conf->kid_hash, kid, SHA256_MAC_LEN) == 0)
3997 return conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07003998 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003999 return NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -07004000}
4001
4002#endif /* CONFIG_DPP2 */
4003
4004
4005struct dpp_global * dpp_global_init(struct dpp_global_config *config)
Hai Shalom021b0b52019-04-10 11:17:58 -07004006{
4007 struct dpp_global *dpp;
4008
4009 dpp = os_zalloc(sizeof(*dpp));
4010 if (!dpp)
4011 return NULL;
Hai Shalom81f62d82019-07-22 12:10:00 -07004012 dpp->msg_ctx = config->msg_ctx;
4013#ifdef CONFIG_DPP2
4014 dpp->cb_ctx = config->cb_ctx;
4015 dpp->process_conf_obj = config->process_conf_obj;
Hai Shalomfdcde762020-04-02 11:19:20 -07004016 dpp->remove_bi = config->remove_bi;
Hai Shalom81f62d82019-07-22 12:10:00 -07004017#endif /* CONFIG_DPP2 */
Hai Shalom021b0b52019-04-10 11:17:58 -07004018
4019 dl_list_init(&dpp->bootstrap);
4020 dl_list_init(&dpp->configurator);
Hai Shalom81f62d82019-07-22 12:10:00 -07004021#ifdef CONFIG_DPP2
4022 dl_list_init(&dpp->controllers);
4023 dl_list_init(&dpp->tcp_init);
4024#endif /* CONFIG_DPP2 */
Hai Shalom021b0b52019-04-10 11:17:58 -07004025
4026 return dpp;
4027}
4028
4029
4030void dpp_global_clear(struct dpp_global *dpp)
4031{
4032 if (!dpp)
4033 return;
4034
4035 dpp_bootstrap_del(dpp, 0);
4036 dpp_configurator_del(dpp, 0);
Hai Shalom81f62d82019-07-22 12:10:00 -07004037#ifdef CONFIG_DPP2
4038 dpp_tcp_init_flush(dpp);
4039 dpp_relay_flush_controllers(dpp);
4040 dpp_controller_stop(dpp);
4041#endif /* CONFIG_DPP2 */
Hai Shalom021b0b52019-04-10 11:17:58 -07004042}
4043
4044
4045void dpp_global_deinit(struct dpp_global *dpp)
4046{
4047 dpp_global_clear(dpp);
4048 os_free(dpp);
4049}
Hai Shalom81f62d82019-07-22 12:10:00 -07004050
4051
4052#ifdef CONFIG_DPP2
Hai Shalomfdcde762020-04-02 11:19:20 -07004053struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi)
4054{
4055 struct wpabuf *msg;
4056
4057 wpa_printf(MSG_DEBUG, "DPP: Build Presence Announcement frame");
4058
4059 msg = dpp_alloc_msg(DPP_PA_PRESENCE_ANNOUNCEMENT, 4 + SHA256_MAC_LEN);
4060 if (!msg)
4061 return NULL;
4062
4063 /* Responder Bootstrapping Key Hash */
4064 dpp_build_attr_r_bootstrap_key_hash(msg, bi->pubkey_hash_chirp);
4065 wpa_hexdump_buf(MSG_DEBUG,
4066 "DPP: Presence Announcement frame attributes", msg);
4067 return msg;
4068}
Hai Shalom81f62d82019-07-22 12:10:00 -07004069#endif /* CONFIG_DPP2 */