Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * DPP functionality shared between hostapd and wpa_supplicant |
| 3 | * Copyright (c) 2017, Qualcomm Atheros, Inc. |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4 | * Copyright (c) 2018-2020, The Linux Foundation |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5 | * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc. |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6 | * |
| 7 | * This software may be distributed under the terms of the BSD license. |
| 8 | * See README for more details. |
| 9 | */ |
| 10 | |
| 11 | #include "utils/includes.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12 | |
| 13 | #include "utils/common.h" |
| 14 | #include "utils/base64.h" |
| 15 | #include "utils/json.h" |
| 16 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 17 | #include "common/wpa_ctrl.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 18 | #include "common/gas.h" |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 19 | #include "eap_common/eap_defs.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 20 | #include "crypto/crypto.h" |
| 21 | #include "crypto/random.h" |
| 22 | #include "crypto/aes.h" |
| 23 | #include "crypto/aes_siv.h" |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 24 | #include "drivers/driver.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 25 | #include "dpp.h" |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 26 | #include "dpp_i.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 27 | |
| 28 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 29 | #ifdef CONFIG_TESTING_OPTIONS |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 30 | #ifdef CONFIG_DPP3 |
| 31 | int dpp_version_override = 3; |
| 32 | #elif defined(CONFIG_DPP2) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 33 | int dpp_version_override = 2; |
| 34 | #else |
| 35 | int dpp_version_override = 1; |
| 36 | #endif |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 37 | enum dpp_test_behavior dpp_test = DPP_TEST_DISABLED; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 38 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 39 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 40 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 41 | void dpp_auth_fail(struct dpp_authentication *auth, const char *txt) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 42 | { |
| 43 | wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_FAIL "%s", txt); |
| 44 | } |
| 45 | |
| 46 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 47 | struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type, |
| 48 | size_t len) |
| 49 | { |
| 50 | struct wpabuf *msg; |
| 51 | |
| 52 | msg = wpabuf_alloc(8 + len); |
| 53 | if (!msg) |
| 54 | return NULL; |
| 55 | wpabuf_put_u8(msg, WLAN_ACTION_PUBLIC); |
| 56 | wpabuf_put_u8(msg, WLAN_PA_VENDOR_SPECIFIC); |
| 57 | wpabuf_put_be24(msg, OUI_WFA); |
| 58 | wpabuf_put_u8(msg, DPP_OUI_TYPE); |
| 59 | wpabuf_put_u8(msg, 1); /* Crypto Suite */ |
| 60 | wpabuf_put_u8(msg, type); |
| 61 | return msg; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len) |
| 66 | { |
| 67 | u16 id, alen; |
| 68 | const u8 *pos = buf, *end = buf + len; |
| 69 | |
| 70 | while (end - pos >= 4) { |
| 71 | id = WPA_GET_LE16(pos); |
| 72 | pos += 2; |
| 73 | alen = WPA_GET_LE16(pos); |
| 74 | pos += 2; |
| 75 | if (alen > end - pos) |
| 76 | return NULL; |
| 77 | if (id == req_id) { |
| 78 | *ret_len = alen; |
| 79 | return pos; |
| 80 | } |
| 81 | pos += alen; |
| 82 | } |
| 83 | |
| 84 | return NULL; |
| 85 | } |
| 86 | |
| 87 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 88 | static const u8 * dpp_get_attr_next(const u8 *prev, const u8 *buf, size_t len, |
| 89 | u16 req_id, u16 *ret_len) |
| 90 | { |
| 91 | u16 id, alen; |
| 92 | const u8 *pos, *end = buf + len; |
| 93 | |
| 94 | if (!prev) |
| 95 | pos = buf; |
| 96 | else |
| 97 | pos = prev + WPA_GET_LE16(prev - 2); |
| 98 | while (end - pos >= 4) { |
| 99 | id = WPA_GET_LE16(pos); |
| 100 | pos += 2; |
| 101 | alen = WPA_GET_LE16(pos); |
| 102 | pos += 2; |
| 103 | if (alen > end - pos) |
| 104 | return NULL; |
| 105 | if (id == req_id) { |
| 106 | *ret_len = alen; |
| 107 | return pos; |
| 108 | } |
| 109 | pos += alen; |
| 110 | } |
| 111 | |
| 112 | return NULL; |
| 113 | } |
| 114 | |
| 115 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 116 | int dpp_check_attrs(const u8 *buf, size_t len) |
| 117 | { |
| 118 | const u8 *pos, *end; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 119 | int wrapped_data = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 120 | |
| 121 | pos = buf; |
| 122 | end = buf + len; |
| 123 | while (end - pos >= 4) { |
| 124 | u16 id, alen; |
| 125 | |
| 126 | id = WPA_GET_LE16(pos); |
| 127 | pos += 2; |
| 128 | alen = WPA_GET_LE16(pos); |
| 129 | pos += 2; |
| 130 | wpa_printf(MSG_MSGDUMP, "DPP: Attribute ID %04x len %u", |
| 131 | id, alen); |
| 132 | if (alen > end - pos) { |
| 133 | wpa_printf(MSG_DEBUG, |
| 134 | "DPP: Truncated message - not enough room for the attribute - dropped"); |
| 135 | return -1; |
| 136 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 137 | if (wrapped_data) { |
| 138 | wpa_printf(MSG_DEBUG, |
| 139 | "DPP: An unexpected attribute included after the Wrapped Data attribute"); |
| 140 | return -1; |
| 141 | } |
| 142 | if (id == DPP_ATTR_WRAPPED_DATA) |
| 143 | wrapped_data = 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 144 | pos += alen; |
| 145 | } |
| 146 | |
| 147 | if (end != pos) { |
| 148 | wpa_printf(MSG_DEBUG, |
| 149 | "DPP: Unexpected octets (%d) after the last attribute", |
| 150 | (int) (end - pos)); |
| 151 | return -1; |
| 152 | } |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info) |
| 159 | { |
| 160 | if (!info) |
| 161 | return; |
| 162 | os_free(info->uri); |
| 163 | os_free(info->info); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 164 | os_free(info->chan); |
| 165 | os_free(info->pk); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 166 | crypto_ec_key_deinit(info->pubkey); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 167 | str_clear_free(info->configurator_params); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 168 | os_free(info); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type) |
| 173 | { |
| 174 | switch (type) { |
| 175 | case DPP_BOOTSTRAP_QR_CODE: |
| 176 | return "QRCODE"; |
| 177 | case DPP_BOOTSTRAP_PKEX: |
| 178 | return "PKEX"; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 179 | case DPP_BOOTSTRAP_NFC_URI: |
| 180 | return "NFC-URI"; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 181 | } |
| 182 | return "??"; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | static int dpp_uri_valid_info(const char *info) |
| 187 | { |
| 188 | while (*info) { |
| 189 | unsigned char val = *info++; |
| 190 | |
| 191 | if (val < 0x20 || val > 0x7e || val == 0x3b) |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | return 1; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | static int dpp_clone_uri(struct dpp_bootstrap_info *bi, const char *uri) |
| 200 | { |
| 201 | bi->uri = os_strdup(uri); |
| 202 | return bi->uri ? 0 : -1; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi, |
| 207 | const char *chan_list) |
| 208 | { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 209 | const char *pos = chan_list, *pos2; |
| 210 | int opclass = -1, channel, freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 211 | |
| 212 | while (pos && *pos && *pos != ';') { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 213 | pos2 = pos; |
| 214 | while (*pos2 >= '0' && *pos2 <= '9') |
| 215 | pos2++; |
| 216 | if (*pos2 == '/') { |
| 217 | opclass = atoi(pos); |
| 218 | pos = pos2 + 1; |
| 219 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 220 | if (opclass <= 0) |
| 221 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 222 | channel = atoi(pos); |
| 223 | if (channel <= 0) |
| 224 | goto fail; |
| 225 | while (*pos >= '0' && *pos <= '9') |
| 226 | pos++; |
| 227 | freq = ieee80211_chan_to_freq(NULL, opclass, channel); |
| 228 | wpa_printf(MSG_DEBUG, |
| 229 | "DPP: URI channel-list: opclass=%d channel=%d ==> freq=%d", |
| 230 | opclass, channel, freq); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 231 | bi->channels_listed = true; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 232 | if (freq < 0) { |
| 233 | wpa_printf(MSG_DEBUG, |
| 234 | "DPP: Ignore unknown URI channel-list channel (opclass=%d channel=%d)", |
| 235 | opclass, channel); |
| 236 | } else if (bi->num_freq == DPP_BOOTSTRAP_MAX_FREQ) { |
| 237 | wpa_printf(MSG_DEBUG, |
| 238 | "DPP: Too many channels in URI channel-list - ignore list"); |
| 239 | bi->num_freq = 0; |
| 240 | break; |
| 241 | } else { |
| 242 | bi->freq[bi->num_freq++] = freq; |
| 243 | } |
| 244 | |
| 245 | if (*pos == ';' || *pos == '\0') |
| 246 | break; |
| 247 | if (*pos != ',') |
| 248 | goto fail; |
| 249 | pos++; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | fail: |
| 254 | wpa_printf(MSG_DEBUG, "DPP: Invalid URI channel-list"); |
| 255 | return -1; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac) |
| 260 | { |
| 261 | if (!mac) |
| 262 | return 0; |
| 263 | |
| 264 | if (hwaddr_aton2(mac, bi->mac_addr) < 0) { |
| 265 | wpa_printf(MSG_DEBUG, "DPP: Invalid URI mac"); |
| 266 | return -1; |
| 267 | } |
| 268 | |
| 269 | wpa_printf(MSG_DEBUG, "DPP: URI mac: " MACSTR, MAC2STR(bi->mac_addr)); |
| 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info) |
| 276 | { |
| 277 | const char *end; |
| 278 | |
| 279 | if (!info) |
| 280 | return 0; |
| 281 | |
| 282 | end = os_strchr(info, ';'); |
| 283 | if (!end) |
| 284 | end = info + os_strlen(info); |
| 285 | bi->info = os_malloc(end - info + 1); |
| 286 | if (!bi->info) |
| 287 | return -1; |
| 288 | os_memcpy(bi->info, info, end - info); |
| 289 | bi->info[end - info] = '\0'; |
| 290 | wpa_printf(MSG_DEBUG, "DPP: URI(information): %s", bi->info); |
| 291 | if (!dpp_uri_valid_info(bi->info)) { |
| 292 | wpa_printf(MSG_DEBUG, "DPP: Invalid URI information payload"); |
| 293 | return -1; |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 300 | int dpp_parse_uri_version(struct dpp_bootstrap_info *bi, const char *version) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 301 | { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 302 | #ifdef CONFIG_DPP2 |
| 303 | if (!version || DPP_VERSION < 2) |
| 304 | return 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 305 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 306 | if (*version == '1') |
| 307 | bi->version = 1; |
| 308 | else if (*version == '2') |
| 309 | bi->version = 2; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 310 | else if (*version == '3') |
| 311 | bi->version = 3; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 312 | else |
| 313 | wpa_printf(MSG_DEBUG, "DPP: Unknown URI version"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 314 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 315 | wpa_printf(MSG_DEBUG, "DPP: URI version: %d", bi->version); |
| 316 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 322 | static int dpp_parse_uri_pk(struct dpp_bootstrap_info *bi, const char *info) |
| 323 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 324 | u8 *data; |
| 325 | size_t data_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 326 | int res; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 327 | const char *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 328 | |
| 329 | end = os_strchr(info, ';'); |
| 330 | if (!end) |
| 331 | return -1; |
| 332 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 333 | data = base64_decode(info, end - info, &data_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 334 | if (!data) { |
| 335 | wpa_printf(MSG_DEBUG, |
| 336 | "DPP: Invalid base64 encoding on URI public-key"); |
| 337 | return -1; |
| 338 | } |
| 339 | wpa_hexdump(MSG_DEBUG, "DPP: Base64 decoded URI public-key", |
| 340 | data, data_len); |
| 341 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 342 | res = dpp_get_subject_public_key(bi, data, data_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 343 | os_free(data); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 344 | return res; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 348 | static int dpp_parse_uri_supported_curves(struct dpp_bootstrap_info *bi, |
| 349 | const char *txt) |
| 350 | { |
| 351 | int val; |
| 352 | |
| 353 | if (!txt) |
| 354 | return 0; |
| 355 | |
| 356 | val = hex2num(txt[0]); |
| 357 | if (val < 0) |
| 358 | return -1; |
| 359 | bi->supported_curves = val; |
| 360 | |
| 361 | val = hex2num(txt[1]); |
| 362 | if (val > 0) |
| 363 | bi->supported_curves |= val << 4; |
| 364 | |
| 365 | wpa_printf(MSG_DEBUG, "DPP: URI supported curves: 0x%x", |
| 366 | bi->supported_curves); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 372 | static struct dpp_bootstrap_info * dpp_parse_uri(const char *uri) |
| 373 | { |
| 374 | const char *pos = uri; |
| 375 | const char *end; |
| 376 | const char *chan_list = NULL, *mac = NULL, *info = NULL, *pk = NULL; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 377 | const char *version = NULL, *supported_curves = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 378 | struct dpp_bootstrap_info *bi; |
| 379 | |
| 380 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: URI", uri, os_strlen(uri)); |
| 381 | |
| 382 | if (os_strncmp(pos, "DPP:", 4) != 0) { |
| 383 | wpa_printf(MSG_INFO, "DPP: Not a DPP URI"); |
| 384 | return NULL; |
| 385 | } |
| 386 | pos += 4; |
| 387 | |
| 388 | for (;;) { |
| 389 | end = os_strchr(pos, ';'); |
| 390 | if (!end) |
| 391 | break; |
| 392 | |
| 393 | if (end == pos) { |
| 394 | /* Handle terminating ";;" and ignore unexpected ";" |
| 395 | * for parsing robustness. */ |
| 396 | pos++; |
| 397 | continue; |
| 398 | } |
| 399 | |
| 400 | if (pos[0] == 'C' && pos[1] == ':' && !chan_list) |
| 401 | chan_list = pos + 2; |
| 402 | else if (pos[0] == 'M' && pos[1] == ':' && !mac) |
| 403 | mac = pos + 2; |
| 404 | else if (pos[0] == 'I' && pos[1] == ':' && !info) |
| 405 | info = pos + 2; |
| 406 | else if (pos[0] == 'K' && pos[1] == ':' && !pk) |
| 407 | pk = pos + 2; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 408 | else if (pos[0] == 'V' && pos[1] == ':' && !version) |
| 409 | version = pos + 2; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 410 | else if (pos[0] == 'B' && pos[1] == ':' && !supported_curves) |
| 411 | supported_curves = pos + 2; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 412 | else |
| 413 | wpa_hexdump_ascii(MSG_DEBUG, |
| 414 | "DPP: Ignore unrecognized URI parameter", |
| 415 | pos, end - pos); |
| 416 | pos = end + 1; |
| 417 | } |
| 418 | |
| 419 | if (!pk) { |
| 420 | wpa_printf(MSG_INFO, "DPP: URI missing public-key"); |
| 421 | return NULL; |
| 422 | } |
| 423 | |
| 424 | bi = os_zalloc(sizeof(*bi)); |
| 425 | if (!bi) |
| 426 | return NULL; |
| 427 | |
| 428 | if (dpp_clone_uri(bi, uri) < 0 || |
| 429 | dpp_parse_uri_chan_list(bi, chan_list) < 0 || |
| 430 | dpp_parse_uri_mac(bi, mac) < 0 || |
| 431 | dpp_parse_uri_info(bi, info) < 0 || |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 432 | dpp_parse_uri_version(bi, version) < 0 || |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 433 | dpp_parse_uri_supported_curves(bi, supported_curves) < 0 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 434 | dpp_parse_uri_pk(bi, pk) < 0) { |
| 435 | dpp_bootstrap_info_free(bi); |
| 436 | bi = NULL; |
| 437 | } |
| 438 | |
| 439 | return bi; |
| 440 | } |
| 441 | |
| 442 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 443 | void dpp_build_attr_status(struct wpabuf *msg, enum dpp_status_error status) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 444 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 445 | wpa_printf(MSG_DEBUG, "DPP: Status %d", status); |
| 446 | wpabuf_put_le16(msg, DPP_ATTR_STATUS); |
| 447 | wpabuf_put_le16(msg, 1); |
| 448 | wpabuf_put_u8(msg, status); |
| 449 | } |
| 450 | |
| 451 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 452 | void dpp_build_attr_r_bootstrap_key_hash(struct wpabuf *msg, const u8 *hash) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 453 | { |
| 454 | if (hash) { |
| 455 | wpa_printf(MSG_DEBUG, "DPP: R-Bootstrap Key Hash"); |
| 456 | wpabuf_put_le16(msg, DPP_ATTR_R_BOOTSTRAP_KEY_HASH); |
| 457 | wpabuf_put_le16(msg, SHA256_MAC_LEN); |
| 458 | wpabuf_put_data(msg, hash, SHA256_MAC_LEN); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 463 | static int dpp_channel_ok_init(struct hostapd_hw_modes *own_modes, |
| 464 | u16 num_modes, unsigned int freq) |
| 465 | { |
| 466 | u16 m; |
| 467 | int c, flag; |
| 468 | |
| 469 | if (!own_modes || !num_modes) |
| 470 | return 1; |
| 471 | |
| 472 | for (m = 0; m < num_modes; m++) { |
| 473 | for (c = 0; c < own_modes[m].num_channels; c++) { |
| 474 | if ((unsigned int) own_modes[m].channels[c].freq != |
| 475 | freq) |
| 476 | continue; |
| 477 | flag = own_modes[m].channels[c].flag; |
| 478 | if (!(flag & (HOSTAPD_CHAN_DISABLED | |
| 479 | HOSTAPD_CHAN_NO_IR | |
| 480 | HOSTAPD_CHAN_RADAR))) |
| 481 | return 1; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | wpa_printf(MSG_DEBUG, "DPP: Peer channel %u MHz not supported", freq); |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | |
| 490 | static int freq_included(const unsigned int freqs[], unsigned int num, |
| 491 | unsigned int freq) |
| 492 | { |
| 493 | while (num > 0) { |
| 494 | if (freqs[--num] == freq) |
| 495 | return 1; |
| 496 | } |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | |
| 501 | static void freq_to_start(unsigned int freqs[], unsigned int num, |
| 502 | unsigned int freq) |
| 503 | { |
| 504 | unsigned int i; |
| 505 | |
| 506 | for (i = 0; i < num; i++) { |
| 507 | if (freqs[i] == freq) |
| 508 | break; |
| 509 | } |
| 510 | if (i == 0 || i >= num) |
| 511 | return; |
| 512 | os_memmove(&freqs[1], &freqs[0], i * sizeof(freqs[0])); |
| 513 | freqs[0] = freq; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | static int dpp_channel_intersect(struct dpp_authentication *auth, |
| 518 | struct hostapd_hw_modes *own_modes, |
| 519 | u16 num_modes) |
| 520 | { |
| 521 | struct dpp_bootstrap_info *peer_bi = auth->peer_bi; |
| 522 | unsigned int i, freq; |
| 523 | |
| 524 | for (i = 0; i < peer_bi->num_freq; i++) { |
| 525 | freq = peer_bi->freq[i]; |
| 526 | if (freq_included(auth->freq, auth->num_freq, freq)) |
| 527 | continue; |
| 528 | if (dpp_channel_ok_init(own_modes, num_modes, freq)) |
| 529 | auth->freq[auth->num_freq++] = freq; |
| 530 | } |
| 531 | if (!auth->num_freq) { |
| 532 | wpa_printf(MSG_INFO, |
| 533 | "DPP: No available channels for initiating DPP Authentication"); |
| 534 | return -1; |
| 535 | } |
| 536 | auth->curr_freq = auth->freq[0]; |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | static int dpp_channel_local_list(struct dpp_authentication *auth, |
| 542 | struct hostapd_hw_modes *own_modes, |
| 543 | u16 num_modes) |
| 544 | { |
| 545 | u16 m; |
| 546 | int c, flag; |
| 547 | unsigned int freq; |
| 548 | |
| 549 | auth->num_freq = 0; |
| 550 | |
| 551 | if (!own_modes || !num_modes) { |
| 552 | auth->freq[0] = 2412; |
| 553 | auth->freq[1] = 2437; |
| 554 | auth->freq[2] = 2462; |
| 555 | auth->num_freq = 3; |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | for (m = 0; m < num_modes; m++) { |
| 560 | for (c = 0; c < own_modes[m].num_channels; c++) { |
| 561 | freq = own_modes[m].channels[c].freq; |
| 562 | flag = own_modes[m].channels[c].flag; |
| 563 | if (flag & (HOSTAPD_CHAN_DISABLED | |
| 564 | HOSTAPD_CHAN_NO_IR | |
| 565 | HOSTAPD_CHAN_RADAR)) |
| 566 | continue; |
| 567 | if (freq_included(auth->freq, auth->num_freq, freq)) |
| 568 | continue; |
| 569 | auth->freq[auth->num_freq++] = freq; |
| 570 | if (auth->num_freq == DPP_BOOTSTRAP_MAX_FREQ) { |
| 571 | m = num_modes; |
| 572 | break; |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | return auth->num_freq == 0 ? -1 : 0; |
| 578 | } |
| 579 | |
| 580 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 581 | int dpp_prepare_channel_list(struct dpp_authentication *auth, |
| 582 | unsigned int neg_freq, |
| 583 | struct hostapd_hw_modes *own_modes, u16 num_modes) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 584 | { |
| 585 | int res; |
| 586 | char freqs[DPP_BOOTSTRAP_MAX_FREQ * 6 + 10], *pos, *end; |
| 587 | unsigned int i; |
| 588 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 589 | if (!own_modes) { |
| 590 | if (!neg_freq) |
| 591 | return -1; |
| 592 | auth->num_freq = 1; |
| 593 | auth->freq[0] = neg_freq; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 594 | auth->curr_freq = neg_freq; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 598 | if (auth->peer_bi->num_freq > 0) |
| 599 | res = dpp_channel_intersect(auth, own_modes, num_modes); |
| 600 | else |
| 601 | res = dpp_channel_local_list(auth, own_modes, num_modes); |
| 602 | if (res < 0) |
| 603 | return res; |
| 604 | |
| 605 | /* Prioritize 2.4 GHz channels 6, 1, 11 (in this order) to hit the most |
| 606 | * likely channels first. */ |
| 607 | freq_to_start(auth->freq, auth->num_freq, 2462); |
| 608 | freq_to_start(auth->freq, auth->num_freq, 2412); |
| 609 | freq_to_start(auth->freq, auth->num_freq, 2437); |
| 610 | |
| 611 | auth->freq_idx = 0; |
| 612 | auth->curr_freq = auth->freq[0]; |
| 613 | |
| 614 | pos = freqs; |
| 615 | end = pos + sizeof(freqs); |
| 616 | for (i = 0; i < auth->num_freq; i++) { |
| 617 | res = os_snprintf(pos, end - pos, " %u", auth->freq[i]); |
| 618 | if (os_snprintf_error(end - pos, res)) |
| 619 | break; |
| 620 | pos += res; |
| 621 | } |
| 622 | *pos = '\0'; |
| 623 | wpa_printf(MSG_DEBUG, "DPP: Possible frequencies for initiating:%s", |
| 624 | freqs); |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 630 | int dpp_gen_uri(struct dpp_bootstrap_info *bi) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 631 | { |
| 632 | char macstr[ETH_ALEN * 2 + 10]; |
| 633 | size_t len; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 634 | char supp_curves[10]; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 635 | |
| 636 | len = 4; /* "DPP:" */ |
| 637 | if (bi->chan) |
| 638 | len += 3 + os_strlen(bi->chan); /* C:...; */ |
| 639 | if (is_zero_ether_addr(bi->mac_addr)) |
| 640 | macstr[0] = '\0'; |
| 641 | else |
| 642 | os_snprintf(macstr, sizeof(macstr), "M:" COMPACT_MACSTR ";", |
| 643 | MAC2STR(bi->mac_addr)); |
| 644 | len += os_strlen(macstr); /* M:...; */ |
| 645 | if (bi->info) |
| 646 | len += 3 + os_strlen(bi->info); /* I:...; */ |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 647 | #ifdef CONFIG_DPP2 |
| 648 | len += 4; /* V:2; */ |
| 649 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 650 | len += 4 + os_strlen(bi->pk); /* K:...;; */ |
| 651 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 652 | if (bi->supported_curves) { |
| 653 | u8 val = bi->supported_curves; |
| 654 | |
| 655 | if (val & 0xf0) { |
| 656 | val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4); |
| 657 | len += os_snprintf(supp_curves, sizeof(supp_curves), |
| 658 | "B:%02x;", val); |
| 659 | } else { |
| 660 | len += os_snprintf(supp_curves, sizeof(supp_curves), |
| 661 | "B:%x;", val); |
| 662 | } |
| 663 | } else { |
| 664 | supp_curves[0] = '\0'; |
| 665 | } |
| 666 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 667 | os_free(bi->uri); |
| 668 | bi->uri = os_malloc(len + 1); |
| 669 | if (!bi->uri) |
| 670 | return -1; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 671 | os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 672 | bi->chan ? "C:" : "", bi->chan ? bi->chan : "", |
| 673 | bi->chan ? ";" : "", |
| 674 | macstr, |
| 675 | bi->info ? "I:" : "", bi->info ? bi->info : "", |
| 676 | bi->info ? ";" : "", |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 677 | DPP_VERSION == 3 ? "V:3;" : |
| 678 | (DPP_VERSION == 2 ? "V:2;" : ""), |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 679 | supp_curves, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 680 | bi->pk); |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 685 | struct dpp_authentication * |
| 686 | dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx) |
| 687 | { |
| 688 | struct dpp_authentication *auth; |
| 689 | |
| 690 | auth = os_zalloc(sizeof(*auth)); |
| 691 | if (!auth) |
| 692 | return NULL; |
| 693 | auth->global = dpp; |
| 694 | auth->msg_ctx = msg_ctx; |
| 695 | auth->conf_resp_status = 255; |
| 696 | return auth; |
| 697 | } |
| 698 | |
| 699 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 700 | static struct wpabuf * dpp_build_conf_req_attr(struct dpp_authentication *auth, |
| 701 | const char *json) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 702 | { |
| 703 | size_t nonce_len; |
| 704 | size_t json_len, clear_len; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 705 | struct wpabuf *clear = NULL, *msg = NULL, *pe = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 706 | u8 *wrapped; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 707 | size_t attr_len; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 708 | #ifdef CONFIG_DPP3 |
| 709 | u8 auth_i[DPP_MAX_HASH_LEN]; |
| 710 | #endif /* CONFIG_DPP3 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 711 | |
| 712 | wpa_printf(MSG_DEBUG, "DPP: Build configuration request"); |
| 713 | |
| 714 | nonce_len = auth->curve->nonce_len; |
| 715 | if (random_get_bytes(auth->e_nonce, nonce_len)) { |
| 716 | wpa_printf(MSG_ERROR, "DPP: Failed to generate E-nonce"); |
| 717 | goto fail; |
| 718 | } |
| 719 | wpa_hexdump(MSG_DEBUG, "DPP: E-nonce", auth->e_nonce, nonce_len); |
| 720 | json_len = os_strlen(json); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 721 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: configRequest JSON", json, json_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 722 | |
| 723 | /* { E-nonce, configAttrib }ke */ |
| 724 | clear_len = 4 + nonce_len + 4 + json_len; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 725 | #ifdef CONFIG_DPP3 |
| 726 | if (auth->waiting_new_key) { |
| 727 | pe = crypto_ec_key_get_pubkey_point(auth->own_protocol_key, 0); |
| 728 | if (!pe) |
| 729 | goto fail; |
| 730 | clear_len += 4 + wpabuf_len(pe); |
| 731 | |
| 732 | if (dpp_derive_auth_i(auth, auth_i) < 0) |
| 733 | goto fail; |
| 734 | clear_len += 4 + auth->curve->hash_len; |
| 735 | } |
| 736 | #endif /* CONFIG_DPP3 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 737 | clear = wpabuf_alloc(clear_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 738 | attr_len = 4 + clear_len + AES_BLOCK_SIZE; |
| 739 | #ifdef CONFIG_TESTING_OPTIONS |
| 740 | if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ) |
| 741 | attr_len += 5; |
| 742 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 743 | msg = wpabuf_alloc(attr_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 744 | if (!clear || !msg) |
| 745 | goto fail; |
| 746 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 747 | #ifdef CONFIG_TESTING_OPTIONS |
| 748 | if (dpp_test == DPP_TEST_NO_E_NONCE_CONF_REQ) { |
| 749 | wpa_printf(MSG_INFO, "DPP: TESTING - no E-nonce"); |
| 750 | goto skip_e_nonce; |
| 751 | } |
| 752 | if (dpp_test == DPP_TEST_INVALID_E_NONCE_CONF_REQ) { |
| 753 | wpa_printf(MSG_INFO, "DPP: TESTING - invalid E-nonce"); |
| 754 | wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE); |
| 755 | wpabuf_put_le16(clear, nonce_len - 1); |
| 756 | wpabuf_put_data(clear, auth->e_nonce, nonce_len - 1); |
| 757 | goto skip_e_nonce; |
| 758 | } |
| 759 | if (dpp_test == DPP_TEST_NO_WRAPPED_DATA_CONF_REQ) { |
| 760 | wpa_printf(MSG_INFO, "DPP: TESTING - no Wrapped Data"); |
| 761 | goto skip_wrapped_data; |
| 762 | } |
| 763 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 764 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 765 | /* E-nonce */ |
| 766 | wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE); |
| 767 | wpabuf_put_le16(clear, nonce_len); |
| 768 | wpabuf_put_data(clear, auth->e_nonce, nonce_len); |
| 769 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 770 | #ifdef CONFIG_TESTING_OPTIONS |
| 771 | skip_e_nonce: |
| 772 | if (dpp_test == DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ) { |
| 773 | wpa_printf(MSG_INFO, "DPP: TESTING - no configAttrib"); |
| 774 | goto skip_conf_attr_obj; |
| 775 | } |
| 776 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 777 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 778 | #ifdef CONFIG_DPP3 |
| 779 | if (pe) { |
| 780 | wpa_printf(MSG_DEBUG, "DPP: Pe"); |
| 781 | wpabuf_put_le16(clear, DPP_ATTR_I_PROTOCOL_KEY); |
| 782 | wpabuf_put_le16(clear, wpabuf_len(pe)); |
| 783 | wpabuf_put_buf(clear, pe); |
| 784 | } |
| 785 | if (auth->waiting_new_key) { |
| 786 | wpa_printf(MSG_DEBUG, "DPP: Initiator Authentication Tag"); |
| 787 | wpabuf_put_le16(clear, DPP_ATTR_I_AUTH_TAG); |
| 788 | wpabuf_put_le16(clear, auth->curve->hash_len); |
| 789 | wpabuf_put_data(clear, auth_i, auth->curve->hash_len); |
| 790 | } |
| 791 | #endif /* CONFIG_DPP3 */ |
| 792 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 793 | /* configAttrib */ |
| 794 | wpabuf_put_le16(clear, DPP_ATTR_CONFIG_ATTR_OBJ); |
| 795 | wpabuf_put_le16(clear, json_len); |
| 796 | wpabuf_put_data(clear, json, json_len); |
| 797 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 798 | #ifdef CONFIG_TESTING_OPTIONS |
| 799 | skip_conf_attr_obj: |
| 800 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 801 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 802 | wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA); |
| 803 | wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 804 | wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 805 | |
| 806 | /* No AES-SIV AD */ |
| 807 | wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear); |
| 808 | if (aes_siv_encrypt(auth->ke, auth->curve->hash_len, |
| 809 | wpabuf_head(clear), wpabuf_len(clear), |
| 810 | 0, NULL, NULL, wrapped) < 0) |
| 811 | goto fail; |
| 812 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext", |
| 813 | wrapped, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 814 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 815 | #ifdef CONFIG_TESTING_OPTIONS |
| 816 | if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ) { |
| 817 | wpa_printf(MSG_INFO, "DPP: TESTING - attr after Wrapped Data"); |
| 818 | dpp_build_attr_status(msg, DPP_STATUS_OK); |
| 819 | } |
| 820 | skip_wrapped_data: |
| 821 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 822 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 823 | wpa_hexdump_buf(MSG_DEBUG, |
| 824 | "DPP: Configuration Request frame attributes", msg); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 825 | out: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 826 | wpabuf_free(clear); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 827 | wpabuf_free(pe); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 828 | return msg; |
| 829 | |
| 830 | fail: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 831 | wpabuf_free(msg); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 832 | msg = NULL; |
| 833 | goto out; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 837 | void dpp_write_adv_proto(struct wpabuf *buf) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 838 | { |
| 839 | /* Advertisement Protocol IE */ |
| 840 | wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO); |
| 841 | wpabuf_put_u8(buf, 8); /* Length */ |
| 842 | wpabuf_put_u8(buf, 0x7f); |
| 843 | wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); |
| 844 | wpabuf_put_u8(buf, 5); |
| 845 | wpabuf_put_be24(buf, OUI_WFA); |
| 846 | wpabuf_put_u8(buf, DPP_OUI_TYPE); |
| 847 | wpabuf_put_u8(buf, 0x01); |
| 848 | } |
| 849 | |
| 850 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 851 | void dpp_write_gas_query(struct wpabuf *buf, struct wpabuf *query) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 852 | { |
| 853 | /* GAS Query */ |
| 854 | wpabuf_put_le16(buf, wpabuf_len(query)); |
| 855 | wpabuf_put_buf(buf, query); |
| 856 | } |
| 857 | |
| 858 | |
| 859 | struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth, |
| 860 | const char *json) |
| 861 | { |
| 862 | struct wpabuf *buf, *conf_req; |
| 863 | |
| 864 | conf_req = dpp_build_conf_req_attr(auth, json); |
| 865 | if (!conf_req) { |
| 866 | wpa_printf(MSG_DEBUG, |
| 867 | "DPP: No configuration request data available"); |
| 868 | return NULL; |
| 869 | } |
| 870 | |
| 871 | buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req)); |
| 872 | if (!buf) { |
| 873 | wpabuf_free(conf_req); |
| 874 | return NULL; |
| 875 | } |
| 876 | |
| 877 | dpp_write_adv_proto(buf); |
| 878 | dpp_write_gas_query(buf, conf_req); |
| 879 | wpabuf_free(conf_req); |
| 880 | wpa_hexdump_buf(MSG_MSGDUMP, "DPP: GAS Config Request", buf); |
| 881 | |
| 882 | return buf; |
| 883 | } |
| 884 | |
| 885 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 886 | struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 887 | const char *name, |
| 888 | enum dpp_netrole netrole, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 889 | const char *mud_url, int *opclasses) |
| 890 | { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 891 | size_t len, name_len; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 892 | const char *tech = "infra"; |
| 893 | const char *dpp_name; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 894 | struct wpabuf *buf = NULL, *json = NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 895 | char *csr = NULL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 896 | |
| 897 | #ifdef CONFIG_TESTING_OPTIONS |
| 898 | if (dpp_test == DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ) { |
| 899 | static const char *bogus_tech = "knfra"; |
| 900 | |
| 901 | wpa_printf(MSG_INFO, "DPP: TESTING - invalid Config Attr"); |
| 902 | tech = bogus_tech; |
| 903 | } |
| 904 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 905 | |
| 906 | dpp_name = name ? name : "Test"; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 907 | name_len = os_strlen(dpp_name); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 908 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 909 | len = 100 + name_len * 6 + 1 + int_array_len(opclasses) * 4; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 910 | if (mud_url && mud_url[0]) |
| 911 | len += 10 + os_strlen(mud_url); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 912 | #ifdef CONFIG_DPP2 |
| 913 | if (auth->csr) { |
| 914 | size_t csr_len; |
| 915 | |
| 916 | csr = base64_encode_no_lf(wpabuf_head(auth->csr), |
| 917 | wpabuf_len(auth->csr), &csr_len); |
| 918 | if (!csr) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 919 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 920 | len += 30 + csr_len; |
| 921 | } |
| 922 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 923 | json = wpabuf_alloc(len); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 924 | if (!json) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 925 | goto fail; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 926 | |
| 927 | json_start_object(json, NULL); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 928 | if (json_add_string_escape(json, "name", dpp_name, name_len) < 0) |
| 929 | goto fail; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 930 | json_value_sep(json); |
| 931 | json_add_string(json, "wi-fi_tech", tech); |
| 932 | json_value_sep(json); |
| 933 | json_add_string(json, "netRole", dpp_netrole_str(netrole)); |
| 934 | if (mud_url && mud_url[0]) { |
| 935 | json_value_sep(json); |
| 936 | json_add_string(json, "mudurl", mud_url); |
| 937 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 938 | if (opclasses) { |
| 939 | int i; |
| 940 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 941 | json_value_sep(json); |
| 942 | json_start_array(json, "bandSupport"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 943 | for (i = 0; opclasses[i]; i++) |
| 944 | wpabuf_printf(json, "%s%u", i ? "," : "", opclasses[i]); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 945 | json_end_array(json); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 946 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 947 | if (csr) { |
| 948 | json_value_sep(json); |
| 949 | json_add_string(json, "pkcs10", csr); |
| 950 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 951 | json_end_object(json); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 952 | |
| 953 | buf = dpp_build_conf_req(auth, wpabuf_head(json)); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 954 | fail: |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 955 | wpabuf_free(json); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 956 | os_free(csr); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 957 | |
| 958 | return buf; |
| 959 | } |
| 960 | |
| 961 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 962 | static int bin_str_eq(const char *val, size_t len, const char *cmp) |
| 963 | { |
| 964 | return os_strlen(cmp) == len && os_memcmp(val, cmp, len) == 0; |
| 965 | } |
| 966 | |
| 967 | |
| 968 | struct dpp_configuration * dpp_configuration_alloc(const char *type) |
| 969 | { |
| 970 | struct dpp_configuration *conf; |
| 971 | const char *end; |
| 972 | size_t len; |
| 973 | |
| 974 | conf = os_zalloc(sizeof(*conf)); |
| 975 | if (!conf) |
| 976 | goto fail; |
| 977 | |
| 978 | end = os_strchr(type, ' '); |
| 979 | if (end) |
| 980 | len = end - type; |
| 981 | else |
| 982 | len = os_strlen(type); |
| 983 | |
| 984 | if (bin_str_eq(type, len, "psk")) |
| 985 | conf->akm = DPP_AKM_PSK; |
| 986 | else if (bin_str_eq(type, len, "sae")) |
| 987 | conf->akm = DPP_AKM_SAE; |
| 988 | else if (bin_str_eq(type, len, "psk-sae") || |
| 989 | bin_str_eq(type, len, "psk+sae")) |
| 990 | conf->akm = DPP_AKM_PSK_SAE; |
| 991 | else if (bin_str_eq(type, len, "sae-dpp") || |
| 992 | bin_str_eq(type, len, "dpp+sae")) |
| 993 | conf->akm = DPP_AKM_SAE_DPP; |
| 994 | else if (bin_str_eq(type, len, "psk-sae-dpp") || |
| 995 | bin_str_eq(type, len, "dpp+psk+sae")) |
| 996 | conf->akm = DPP_AKM_PSK_SAE_DPP; |
| 997 | else if (bin_str_eq(type, len, "dpp")) |
| 998 | conf->akm = DPP_AKM_DPP; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 999 | else if (bin_str_eq(type, len, "dot1x")) |
| 1000 | conf->akm = DPP_AKM_DOT1X; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1001 | else |
| 1002 | goto fail; |
| 1003 | |
| 1004 | return conf; |
| 1005 | fail: |
| 1006 | dpp_configuration_free(conf); |
| 1007 | return NULL; |
| 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | int dpp_akm_psk(enum dpp_akm akm) |
| 1012 | { |
| 1013 | return akm == DPP_AKM_PSK || akm == DPP_AKM_PSK_SAE || |
| 1014 | akm == DPP_AKM_PSK_SAE_DPP; |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | int dpp_akm_sae(enum dpp_akm akm) |
| 1019 | { |
| 1020 | return akm == DPP_AKM_SAE || akm == DPP_AKM_PSK_SAE || |
| 1021 | akm == DPP_AKM_SAE_DPP || akm == DPP_AKM_PSK_SAE_DPP; |
| 1022 | } |
| 1023 | |
| 1024 | |
| 1025 | int dpp_akm_legacy(enum dpp_akm akm) |
| 1026 | { |
| 1027 | return akm == DPP_AKM_PSK || akm == DPP_AKM_PSK_SAE || |
| 1028 | akm == DPP_AKM_SAE; |
| 1029 | } |
| 1030 | |
| 1031 | |
| 1032 | int dpp_akm_dpp(enum dpp_akm akm) |
| 1033 | { |
| 1034 | return akm == DPP_AKM_DPP || akm == DPP_AKM_SAE_DPP || |
| 1035 | akm == DPP_AKM_PSK_SAE_DPP; |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | int dpp_akm_ver2(enum dpp_akm akm) |
| 1040 | { |
| 1041 | return akm == DPP_AKM_SAE_DPP || akm == DPP_AKM_PSK_SAE_DPP; |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | int dpp_configuration_valid(const struct dpp_configuration *conf) |
| 1046 | { |
| 1047 | if (conf->ssid_len == 0) |
| 1048 | return 0; |
| 1049 | if (dpp_akm_psk(conf->akm) && !conf->passphrase && !conf->psk_set) |
| 1050 | return 0; |
| 1051 | if (dpp_akm_sae(conf->akm) && !conf->passphrase) |
| 1052 | return 0; |
| 1053 | return 1; |
| 1054 | } |
| 1055 | |
| 1056 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1057 | void dpp_configuration_free(struct dpp_configuration *conf) |
| 1058 | { |
| 1059 | if (!conf) |
| 1060 | return; |
| 1061 | str_clear_free(conf->passphrase); |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 1062 | os_free(conf->group_id); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1063 | os_free(conf->csrattrs); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1064 | bin_clear_free(conf, sizeof(*conf)); |
| 1065 | } |
| 1066 | |
| 1067 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1068 | static int dpp_configuration_parse_helper(struct dpp_authentication *auth, |
| 1069 | const char *cmd, int idx) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1070 | { |
| 1071 | const char *pos, *end; |
| 1072 | struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL; |
| 1073 | struct dpp_configuration *conf = NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1074 | size_t len; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1075 | |
| 1076 | pos = os_strstr(cmd, " conf=sta-"); |
| 1077 | if (pos) { |
| 1078 | conf_sta = dpp_configuration_alloc(pos + 10); |
| 1079 | if (!conf_sta) |
| 1080 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1081 | conf_sta->netrole = DPP_NETROLE_STA; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1082 | conf = conf_sta; |
| 1083 | } |
| 1084 | |
| 1085 | pos = os_strstr(cmd, " conf=ap-"); |
| 1086 | if (pos) { |
| 1087 | conf_ap = dpp_configuration_alloc(pos + 9); |
| 1088 | if (!conf_ap) |
| 1089 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1090 | conf_ap->netrole = DPP_NETROLE_AP; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1091 | conf = conf_ap; |
| 1092 | } |
| 1093 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1094 | pos = os_strstr(cmd, " conf=configurator"); |
| 1095 | if (pos) |
| 1096 | auth->provision_configurator = 1; |
| 1097 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1098 | if (!conf) |
| 1099 | return 0; |
| 1100 | |
| 1101 | pos = os_strstr(cmd, " ssid="); |
| 1102 | if (pos) { |
| 1103 | pos += 6; |
| 1104 | end = os_strchr(pos, ' '); |
| 1105 | conf->ssid_len = end ? (size_t) (end - pos) : os_strlen(pos); |
| 1106 | conf->ssid_len /= 2; |
| 1107 | if (conf->ssid_len > sizeof(conf->ssid) || |
| 1108 | hexstr2bin(pos, conf->ssid, conf->ssid_len) < 0) |
| 1109 | goto fail; |
| 1110 | } else { |
| 1111 | #ifdef CONFIG_TESTING_OPTIONS |
| 1112 | /* use a default SSID for legacy testing reasons */ |
| 1113 | os_memcpy(conf->ssid, "test", 4); |
| 1114 | conf->ssid_len = 4; |
| 1115 | #else /* CONFIG_TESTING_OPTIONS */ |
| 1116 | goto fail; |
| 1117 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1118 | } |
| 1119 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1120 | pos = os_strstr(cmd, " ssid_charset="); |
| 1121 | if (pos) { |
| 1122 | if (conf_ap) { |
| 1123 | wpa_printf(MSG_INFO, |
| 1124 | "DPP: ssid64 option (ssid_charset param) not allowed for AP enrollee"); |
| 1125 | goto fail; |
| 1126 | } |
| 1127 | conf->ssid_charset = atoi(pos + 14); |
| 1128 | } |
| 1129 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1130 | pos = os_strstr(cmd, " pass="); |
| 1131 | if (pos) { |
| 1132 | size_t pass_len; |
| 1133 | |
| 1134 | pos += 6; |
| 1135 | end = os_strchr(pos, ' '); |
| 1136 | pass_len = end ? (size_t) (end - pos) : os_strlen(pos); |
| 1137 | pass_len /= 2; |
| 1138 | if (pass_len > 63 || pass_len < 8) |
| 1139 | goto fail; |
| 1140 | conf->passphrase = os_zalloc(pass_len + 1); |
| 1141 | if (!conf->passphrase || |
| 1142 | hexstr2bin(pos, (u8 *) conf->passphrase, pass_len) < 0) |
| 1143 | goto fail; |
| 1144 | } |
| 1145 | |
| 1146 | pos = os_strstr(cmd, " psk="); |
| 1147 | if (pos) { |
| 1148 | pos += 5; |
| 1149 | if (hexstr2bin(pos, conf->psk, PMK_LEN) < 0) |
| 1150 | goto fail; |
| 1151 | conf->psk_set = 1; |
| 1152 | } |
| 1153 | |
| 1154 | pos = os_strstr(cmd, " group_id="); |
| 1155 | if (pos) { |
| 1156 | size_t group_id_len; |
| 1157 | |
| 1158 | pos += 10; |
| 1159 | end = os_strchr(pos, ' '); |
| 1160 | group_id_len = end ? (size_t) (end - pos) : os_strlen(pos); |
| 1161 | conf->group_id = os_malloc(group_id_len + 1); |
| 1162 | if (!conf->group_id) |
| 1163 | goto fail; |
| 1164 | os_memcpy(conf->group_id, pos, group_id_len); |
| 1165 | conf->group_id[group_id_len] = '\0'; |
| 1166 | } |
| 1167 | |
| 1168 | pos = os_strstr(cmd, " expiry="); |
| 1169 | if (pos) { |
| 1170 | long int val; |
| 1171 | |
| 1172 | pos += 8; |
| 1173 | val = strtol(pos, NULL, 0); |
| 1174 | if (val <= 0) |
| 1175 | goto fail; |
| 1176 | conf->netaccesskey_expiry = val; |
| 1177 | } |
| 1178 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1179 | pos = os_strstr(cmd, " csrattrs="); |
| 1180 | if (pos) { |
| 1181 | pos += 10; |
| 1182 | end = os_strchr(pos, ' '); |
| 1183 | len = end ? (size_t) (end - pos) : os_strlen(pos); |
| 1184 | conf->csrattrs = os_zalloc(len + 1); |
| 1185 | if (!conf->csrattrs) |
| 1186 | goto fail; |
| 1187 | os_memcpy(conf->csrattrs, pos, len); |
| 1188 | } |
| 1189 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1190 | if (!dpp_configuration_valid(conf)) |
| 1191 | goto fail; |
| 1192 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1193 | if (idx == 0) { |
| 1194 | auth->conf_sta = conf_sta; |
| 1195 | auth->conf_ap = conf_ap; |
| 1196 | } else if (idx == 1) { |
| 1197 | auth->conf2_sta = conf_sta; |
| 1198 | auth->conf2_ap = conf_ap; |
| 1199 | } else { |
| 1200 | goto fail; |
| 1201 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1202 | return 0; |
| 1203 | |
| 1204 | fail: |
| 1205 | dpp_configuration_free(conf_sta); |
| 1206 | dpp_configuration_free(conf_ap); |
| 1207 | return -1; |
| 1208 | } |
| 1209 | |
| 1210 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1211 | static int dpp_configuration_parse(struct dpp_authentication *auth, |
| 1212 | const char *cmd) |
| 1213 | { |
| 1214 | const char *pos; |
| 1215 | char *tmp; |
| 1216 | size_t len; |
| 1217 | int res; |
| 1218 | |
| 1219 | pos = os_strstr(cmd, " @CONF-OBJ-SEP@ "); |
| 1220 | if (!pos) |
| 1221 | return dpp_configuration_parse_helper(auth, cmd, 0); |
| 1222 | |
| 1223 | len = pos - cmd; |
| 1224 | tmp = os_malloc(len + 1); |
| 1225 | if (!tmp) |
| 1226 | goto fail; |
| 1227 | os_memcpy(tmp, cmd, len); |
| 1228 | tmp[len] = '\0'; |
| 1229 | res = dpp_configuration_parse_helper(auth, cmd, 0); |
| 1230 | str_clear_free(tmp); |
| 1231 | if (res) |
| 1232 | goto fail; |
| 1233 | res = dpp_configuration_parse_helper(auth, cmd + len, 1); |
| 1234 | if (res) |
| 1235 | goto fail; |
| 1236 | return 0; |
| 1237 | fail: |
| 1238 | dpp_configuration_free(auth->conf_sta); |
| 1239 | dpp_configuration_free(auth->conf2_sta); |
| 1240 | dpp_configuration_free(auth->conf_ap); |
| 1241 | dpp_configuration_free(auth->conf2_ap); |
| 1242 | return -1; |
| 1243 | } |
| 1244 | |
| 1245 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1246 | static struct dpp_configurator * |
| 1247 | dpp_configurator_get_id(struct dpp_global *dpp, unsigned int id) |
| 1248 | { |
| 1249 | struct dpp_configurator *conf; |
| 1250 | |
| 1251 | if (!dpp) |
| 1252 | return NULL; |
| 1253 | |
| 1254 | dl_list_for_each(conf, &dpp->configurator, |
| 1255 | struct dpp_configurator, list) { |
| 1256 | if (conf->id == id) |
| 1257 | return conf; |
| 1258 | } |
| 1259 | return NULL; |
| 1260 | } |
| 1261 | |
| 1262 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1263 | int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1264 | { |
| 1265 | const char *pos; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1266 | char *tmp = NULL; |
| 1267 | int ret = -1; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1268 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1269 | if (!cmd || auth->configurator_set) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1270 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1271 | auth->configurator_set = 1; |
| 1272 | |
| 1273 | if (cmd[0] != ' ') { |
| 1274 | size_t len; |
| 1275 | |
| 1276 | len = os_strlen(cmd); |
| 1277 | tmp = os_malloc(len + 2); |
| 1278 | if (!tmp) |
| 1279 | goto fail; |
| 1280 | tmp[0] = ' '; |
| 1281 | os_memcpy(tmp + 1, cmd, len + 1); |
| 1282 | cmd = tmp; |
| 1283 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1284 | |
| 1285 | wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd); |
| 1286 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1287 | if (os_strstr(cmd, " conf=query")) { |
| 1288 | auth->configurator_set = 0; |
| 1289 | auth->use_config_query = true; |
| 1290 | ret = 0; |
| 1291 | goto fail; |
| 1292 | } |
| 1293 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1294 | pos = os_strstr(cmd, " configurator="); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1295 | if (!auth->conf && pos) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1296 | pos += 14; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1297 | auth->conf = dpp_configurator_get_id(auth->global, atoi(pos)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1298 | if (!auth->conf) { |
| 1299 | wpa_printf(MSG_INFO, |
| 1300 | "DPP: Could not find the specified configurator"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1301 | goto fail; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1305 | pos = os_strstr(cmd, " conn_status="); |
| 1306 | if (pos) { |
| 1307 | pos += 13; |
| 1308 | auth->send_conn_status = atoi(pos); |
| 1309 | } |
| 1310 | |
| 1311 | pos = os_strstr(cmd, " akm_use_selector="); |
| 1312 | if (pos) { |
| 1313 | pos += 18; |
| 1314 | auth->akm_use_selector = atoi(pos); |
| 1315 | } |
| 1316 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1317 | if (dpp_configuration_parse(auth, cmd) < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1318 | wpa_msg(auth->msg_ctx, MSG_INFO, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1319 | "DPP: Failed to set configurator parameters"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1320 | goto fail; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1321 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1322 | ret = 0; |
| 1323 | fail: |
| 1324 | os_free(tmp); |
| 1325 | return ret; |
| 1326 | } |
| 1327 | |
| 1328 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1329 | void dpp_auth_deinit(struct dpp_authentication *auth) |
| 1330 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1331 | unsigned int i; |
| 1332 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1333 | if (!auth) |
| 1334 | return; |
| 1335 | dpp_configuration_free(auth->conf_ap); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1336 | dpp_configuration_free(auth->conf2_ap); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1337 | dpp_configuration_free(auth->conf_sta); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1338 | dpp_configuration_free(auth->conf2_sta); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1339 | crypto_ec_key_deinit(auth->own_protocol_key); |
| 1340 | crypto_ec_key_deinit(auth->peer_protocol_key); |
| 1341 | crypto_ec_key_deinit(auth->reconfig_old_protocol_key); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1342 | wpabuf_free(auth->req_msg); |
| 1343 | wpabuf_free(auth->resp_msg); |
| 1344 | wpabuf_free(auth->conf_req); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1345 | wpabuf_free(auth->reconfig_req_msg); |
| 1346 | wpabuf_free(auth->reconfig_resp_msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1347 | for (i = 0; i < auth->num_conf_obj; i++) { |
| 1348 | struct dpp_config_obj *conf = &auth->conf_obj[i]; |
| 1349 | |
| 1350 | os_free(conf->connector); |
| 1351 | wpabuf_free(conf->c_sign_key); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1352 | wpabuf_free(conf->certbag); |
| 1353 | wpabuf_free(conf->certs); |
| 1354 | wpabuf_free(conf->cacert); |
| 1355 | os_free(conf->server_name); |
| 1356 | wpabuf_free(conf->pp_key); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1357 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1358 | #ifdef CONFIG_DPP2 |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1359 | dpp_free_asymmetric_key(auth->conf_key_pkg); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1360 | os_free(auth->csrattrs); |
| 1361 | wpabuf_free(auth->csr); |
| 1362 | wpabuf_free(auth->priv_key); |
| 1363 | wpabuf_free(auth->cacert); |
| 1364 | wpabuf_free(auth->certbag); |
| 1365 | os_free(auth->trusted_eap_server_name); |
| 1366 | wpabuf_free(auth->conf_resp_tcp); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1367 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1368 | wpabuf_free(auth->net_access_key); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1369 | dpp_bootstrap_info_free(auth->tmp_own_bi); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1370 | if (auth->tmp_peer_bi) { |
| 1371 | dl_list_del(&auth->tmp_peer_bi->list); |
| 1372 | dpp_bootstrap_info_free(auth->tmp_peer_bi); |
| 1373 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1374 | os_free(auth->e_name); |
| 1375 | os_free(auth->e_mud_url); |
| 1376 | os_free(auth->e_band_support); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1377 | #ifdef CONFIG_TESTING_OPTIONS |
| 1378 | os_free(auth->config_obj_override); |
| 1379 | os_free(auth->discovery_override); |
| 1380 | os_free(auth->groups_override); |
| 1381 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1382 | bin_clear_free(auth, sizeof(*auth)); |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | static struct wpabuf * |
| 1387 | dpp_build_conf_start(struct dpp_authentication *auth, |
| 1388 | struct dpp_configuration *conf, size_t tailroom) |
| 1389 | { |
| 1390 | struct wpabuf *buf; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1391 | |
| 1392 | #ifdef CONFIG_TESTING_OPTIONS |
| 1393 | if (auth->discovery_override) |
| 1394 | tailroom += os_strlen(auth->discovery_override); |
| 1395 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1396 | |
| 1397 | buf = wpabuf_alloc(200 + tailroom); |
| 1398 | if (!buf) |
| 1399 | return NULL; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1400 | json_start_object(buf, NULL); |
| 1401 | json_add_string(buf, "wi-fi_tech", "infra"); |
| 1402 | json_value_sep(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1403 | #ifdef CONFIG_TESTING_OPTIONS |
| 1404 | if (auth->discovery_override) { |
| 1405 | wpa_printf(MSG_DEBUG, "DPP: TESTING - discovery override: '%s'", |
| 1406 | auth->discovery_override); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1407 | wpabuf_put_str(buf, "\"discovery\":"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1408 | wpabuf_put_str(buf, auth->discovery_override); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1409 | json_value_sep(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1410 | return buf; |
| 1411 | } |
| 1412 | #endif /* CONFIG_TESTING_OPTIONS */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1413 | json_start_object(buf, "discovery"); |
| 1414 | if (((!conf->ssid_charset || auth->peer_version < 2) && |
| 1415 | json_add_string_escape(buf, "ssid", conf->ssid, |
| 1416 | conf->ssid_len) < 0) || |
| 1417 | ((conf->ssid_charset && auth->peer_version >= 2) && |
| 1418 | json_add_base64url(buf, "ssid64", conf->ssid, |
| 1419 | conf->ssid_len) < 0)) { |
| 1420 | wpabuf_free(buf); |
| 1421 | return NULL; |
| 1422 | } |
| 1423 | if (conf->ssid_charset > 0) { |
| 1424 | json_value_sep(buf); |
| 1425 | json_add_int(buf, "ssid_charset", conf->ssid_charset); |
| 1426 | } |
| 1427 | json_end_object(buf); |
| 1428 | json_value_sep(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1429 | |
| 1430 | return buf; |
| 1431 | } |
| 1432 | |
| 1433 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1434 | int dpp_build_jwk(struct wpabuf *buf, const char *name, |
| 1435 | struct crypto_ec_key *key, const char *kid, |
| 1436 | const struct dpp_curve_params *curve) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1437 | { |
| 1438 | struct wpabuf *pub; |
| 1439 | const u8 *pos; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1440 | int ret = -1; |
| 1441 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1442 | pub = crypto_ec_key_get_pubkey_point(key, 0); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1443 | if (!pub) |
| 1444 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1445 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1446 | json_start_object(buf, name); |
| 1447 | json_add_string(buf, "kty", "EC"); |
| 1448 | json_value_sep(buf); |
| 1449 | json_add_string(buf, "crv", curve->jwk_crv); |
| 1450 | json_value_sep(buf); |
| 1451 | pos = wpabuf_head(pub); |
| 1452 | if (json_add_base64url(buf, "x", pos, curve->prime_len) < 0) |
| 1453 | goto fail; |
| 1454 | json_value_sep(buf); |
| 1455 | pos += curve->prime_len; |
| 1456 | if (json_add_base64url(buf, "y", pos, curve->prime_len) < 0) |
| 1457 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1458 | if (kid) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1459 | json_value_sep(buf); |
| 1460 | json_add_string(buf, "kid", kid); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1461 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1462 | json_end_object(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1463 | ret = 0; |
| 1464 | fail: |
| 1465 | wpabuf_free(pub); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1466 | return ret; |
| 1467 | } |
| 1468 | |
| 1469 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1470 | static void dpp_build_legacy_cred_params(struct wpabuf *buf, |
| 1471 | struct dpp_configuration *conf) |
| 1472 | { |
| 1473 | if (conf->passphrase && os_strlen(conf->passphrase) < 64) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1474 | json_add_string_escape(buf, "pass", conf->passphrase, |
| 1475 | os_strlen(conf->passphrase)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1476 | } else if (conf->psk_set) { |
| 1477 | char psk[2 * sizeof(conf->psk) + 1]; |
| 1478 | |
| 1479 | wpa_snprintf_hex(psk, sizeof(psk), |
| 1480 | conf->psk, sizeof(conf->psk)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1481 | json_add_string(buf, "psk_hex", psk); |
| 1482 | forced_memzero(psk, sizeof(psk)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1487 | const char * dpp_netrole_str(enum dpp_netrole netrole) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1488 | { |
| 1489 | switch (netrole) { |
| 1490 | case DPP_NETROLE_STA: |
| 1491 | return "sta"; |
| 1492 | case DPP_NETROLE_AP: |
| 1493 | return "ap"; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1494 | case DPP_NETROLE_CONFIGURATOR: |
| 1495 | return "configurator"; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1496 | default: |
| 1497 | return "??"; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1502 | static struct wpabuf * |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1503 | dpp_build_conf_obj_dpp(struct dpp_authentication *auth, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1504 | struct dpp_configuration *conf) |
| 1505 | { |
| 1506 | struct wpabuf *buf = NULL; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1507 | char *signed_conn = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1508 | size_t tailroom; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1509 | const struct dpp_curve_params *curve; /* C-sign-key curve */ |
| 1510 | const struct dpp_curve_params *nak_curve; /* netAccessKey curve */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1511 | struct wpabuf *dppcon = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1512 | size_t extra_len = 1000; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1513 | int incl_legacy; |
| 1514 | enum dpp_akm akm; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1515 | const char *akm_str; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1516 | |
| 1517 | if (!auth->conf) { |
| 1518 | wpa_printf(MSG_INFO, |
| 1519 | "DPP: No configurator specified - cannot generate DPP config object"); |
| 1520 | goto fail; |
| 1521 | } |
| 1522 | curve = auth->conf->curve; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1523 | if (auth->new_curve && auth->new_key_received) |
| 1524 | nak_curve = auth->new_curve; |
| 1525 | else |
| 1526 | nak_curve = auth->curve; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1527 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1528 | akm = conf->akm; |
| 1529 | if (dpp_akm_ver2(akm) && auth->peer_version < 2) { |
| 1530 | wpa_printf(MSG_DEBUG, |
| 1531 | "DPP: Convert DPP+legacy credential to DPP-only for peer that does not support version 2"); |
| 1532 | akm = DPP_AKM_DPP; |
| 1533 | } |
| 1534 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1535 | #ifdef CONFIG_TESTING_OPTIONS |
| 1536 | if (auth->groups_override) |
| 1537 | extra_len += os_strlen(auth->groups_override); |
| 1538 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1539 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 1540 | if (conf->group_id) |
| 1541 | extra_len += os_strlen(conf->group_id); |
| 1542 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1543 | /* Connector (JSON dppCon object) */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1544 | dppcon = wpabuf_alloc(extra_len + 2 * nak_curve->prime_len * 4 / 3); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1545 | if (!dppcon) |
| 1546 | goto fail; |
| 1547 | #ifdef CONFIG_TESTING_OPTIONS |
| 1548 | if (auth->groups_override) { |
| 1549 | wpabuf_put_u8(dppcon, '{'); |
| 1550 | if (auth->groups_override) { |
| 1551 | wpa_printf(MSG_DEBUG, |
| 1552 | "DPP: TESTING - groups override: '%s'", |
| 1553 | auth->groups_override); |
| 1554 | wpabuf_put_str(dppcon, "\"groups\":"); |
| 1555 | wpabuf_put_str(dppcon, auth->groups_override); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1556 | json_value_sep(dppcon); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1557 | } |
| 1558 | goto skip_groups; |
| 1559 | } |
| 1560 | #endif /* CONFIG_TESTING_OPTIONS */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1561 | json_start_object(dppcon, NULL); |
| 1562 | json_start_array(dppcon, "groups"); |
| 1563 | json_start_object(dppcon, NULL); |
| 1564 | json_add_string(dppcon, "groupId", |
| 1565 | conf->group_id ? conf->group_id : "*"); |
| 1566 | json_value_sep(dppcon); |
| 1567 | json_add_string(dppcon, "netRole", dpp_netrole_str(conf->netrole)); |
| 1568 | json_end_object(dppcon); |
| 1569 | json_end_array(dppcon); |
| 1570 | json_value_sep(dppcon); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1571 | #ifdef CONFIG_TESTING_OPTIONS |
| 1572 | skip_groups: |
| 1573 | #endif /* CONFIG_TESTING_OPTIONS */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1574 | if (!auth->peer_protocol_key) { |
| 1575 | wpa_printf(MSG_DEBUG, |
| 1576 | "DPP: No peer protocol key available to build netAccessKey JWK"); |
| 1577 | goto fail; |
| 1578 | } |
| 1579 | #ifdef CONFIG_DPP3 |
| 1580 | if (auth->conf->net_access_key_curve && |
| 1581 | auth->curve != auth->conf->net_access_key_curve && |
| 1582 | !auth->new_key_received) { |
| 1583 | wpa_printf(MSG_DEBUG, |
| 1584 | "DPP: Peer protocol key curve (%s) does not match the required netAccessKey curve (%s) - %s", |
| 1585 | auth->curve->name, |
| 1586 | auth->conf->net_access_key_curve->name, |
| 1587 | auth->waiting_new_key ? |
| 1588 | "the required key not received" : |
| 1589 | "request a new key"); |
| 1590 | if (auth->waiting_new_key) |
| 1591 | auth->waiting_new_key = false; /* failed */ |
| 1592 | else |
| 1593 | auth->waiting_new_key = true; |
| 1594 | goto fail; |
| 1595 | } |
| 1596 | #endif /* CONFIG_DPP3 */ |
| 1597 | if (dpp_build_jwk(dppcon, "netAccessKey", auth->peer_protocol_key, NULL, |
| 1598 | nak_curve) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1599 | wpa_printf(MSG_DEBUG, "DPP: Failed to build netAccessKey JWK"); |
| 1600 | goto fail; |
| 1601 | } |
| 1602 | if (conf->netaccesskey_expiry) { |
| 1603 | struct os_tm tm; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1604 | char expiry[30]; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1605 | |
| 1606 | if (os_gmtime(conf->netaccesskey_expiry, &tm) < 0) { |
| 1607 | wpa_printf(MSG_DEBUG, |
| 1608 | "DPP: Failed to generate expiry string"); |
| 1609 | goto fail; |
| 1610 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1611 | os_snprintf(expiry, sizeof(expiry), |
| 1612 | "%04u-%02u-%02uT%02u:%02u:%02uZ", |
| 1613 | tm.year, tm.month, tm.day, |
| 1614 | tm.hour, tm.min, tm.sec); |
| 1615 | json_value_sep(dppcon); |
| 1616 | json_add_string(dppcon, "expiry", expiry); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1617 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1618 | #ifdef CONFIG_DPP3 |
| 1619 | json_value_sep(dppcon); |
| 1620 | json_add_int(dppcon, "version", auth->peer_version); |
| 1621 | #endif /* CONFIG_DPP3 */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1622 | json_end_object(dppcon); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1623 | wpa_printf(MSG_DEBUG, "DPP: dppCon: %s", |
| 1624 | (const char *) wpabuf_head(dppcon)); |
| 1625 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1626 | signed_conn = dpp_sign_connector(auth->conf, dppcon); |
| 1627 | if (!signed_conn) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1628 | goto fail; |
| 1629 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1630 | incl_legacy = dpp_akm_psk(akm) || dpp_akm_sae(akm); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1631 | tailroom = 1000; |
| 1632 | tailroom += 2 * curve->prime_len * 4 / 3 + os_strlen(auth->conf->kid); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1633 | tailroom += os_strlen(signed_conn); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1634 | if (incl_legacy) |
| 1635 | tailroom += 1000; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1636 | if (akm == DPP_AKM_DOT1X) { |
| 1637 | if (auth->certbag) |
| 1638 | tailroom += 2 * wpabuf_len(auth->certbag); |
| 1639 | if (auth->cacert) |
| 1640 | tailroom += 2 * wpabuf_len(auth->cacert); |
| 1641 | if (auth->trusted_eap_server_name) |
| 1642 | tailroom += os_strlen(auth->trusted_eap_server_name); |
| 1643 | tailroom += 1000; |
| 1644 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1645 | buf = dpp_build_conf_start(auth, conf, tailroom); |
| 1646 | if (!buf) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1647 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1648 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1649 | if (auth->akm_use_selector && dpp_akm_ver2(akm)) |
| 1650 | akm_str = dpp_akm_selector_str(akm); |
| 1651 | else |
| 1652 | akm_str = dpp_akm_str(akm); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1653 | json_start_object(buf, "cred"); |
| 1654 | json_add_string(buf, "akm", akm_str); |
| 1655 | json_value_sep(buf); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1656 | if (incl_legacy) { |
| 1657 | dpp_build_legacy_cred_params(buf, conf); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1658 | json_value_sep(buf); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1659 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1660 | if (akm == DPP_AKM_DOT1X) { |
| 1661 | json_start_object(buf, "entCreds"); |
| 1662 | if (!auth->certbag) |
| 1663 | goto fail; |
| 1664 | json_add_base64(buf, "certBag", wpabuf_head(auth->certbag), |
| 1665 | wpabuf_len(auth->certbag)); |
| 1666 | if (auth->cacert) { |
| 1667 | json_value_sep(buf); |
| 1668 | json_add_base64(buf, "caCert", |
| 1669 | wpabuf_head(auth->cacert), |
| 1670 | wpabuf_len(auth->cacert)); |
| 1671 | } |
| 1672 | if (auth->trusted_eap_server_name) { |
| 1673 | json_value_sep(buf); |
| 1674 | json_add_string(buf, "trustedEapServerName", |
| 1675 | auth->trusted_eap_server_name); |
| 1676 | } |
| 1677 | json_value_sep(buf); |
| 1678 | json_start_array(buf, "eapMethods"); |
| 1679 | wpabuf_printf(buf, "%d", EAP_TYPE_TLS); |
| 1680 | json_end_array(buf); |
| 1681 | json_end_object(buf); |
| 1682 | json_value_sep(buf); |
| 1683 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1684 | wpabuf_put_str(buf, "\"signedConnector\":\""); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1685 | wpabuf_put_str(buf, signed_conn); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1686 | wpabuf_put_str(buf, "\""); |
| 1687 | json_value_sep(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1688 | if (dpp_build_jwk(buf, "csign", auth->conf->csign, auth->conf->kid, |
| 1689 | curve) < 0) { |
| 1690 | wpa_printf(MSG_DEBUG, "DPP: Failed to build csign JWK"); |
| 1691 | goto fail; |
| 1692 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1693 | #ifdef CONFIG_DPP2 |
| 1694 | if (auth->peer_version >= 2 && auth->conf->pp_key) { |
| 1695 | json_value_sep(buf); |
| 1696 | if (dpp_build_jwk(buf, "ppKey", auth->conf->pp_key, NULL, |
| 1697 | curve) < 0) { |
| 1698 | wpa_printf(MSG_DEBUG, "DPP: Failed to build ppKey JWK"); |
| 1699 | goto fail; |
| 1700 | } |
| 1701 | } |
| 1702 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1703 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1704 | json_end_object(buf); |
| 1705 | json_end_object(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1706 | |
| 1707 | wpa_hexdump_ascii_key(MSG_DEBUG, "DPP: Configuration Object", |
| 1708 | wpabuf_head(buf), wpabuf_len(buf)); |
| 1709 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1710 | #ifdef CONFIG_DPP3 |
| 1711 | if (!auth->conf->net_access_key_curve) { |
| 1712 | /* All netAccessKey values used in the network will have to be |
| 1713 | * from the same curve for network introduction to work, so |
| 1714 | * hardcode the first used netAccessKey curve for consecutive |
| 1715 | * operations if there was no explicit configuration of which |
| 1716 | * curve to use. */ |
| 1717 | wpa_printf(MSG_DEBUG, |
| 1718 | "DPP: Update Configurator to require netAccessKey curve %s based on first provisioning", |
| 1719 | nak_curve->name); |
| 1720 | auth->conf->net_access_key_curve = nak_curve; |
| 1721 | } |
| 1722 | #endif /* CONFIG_DPP3 */ |
| 1723 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1724 | out: |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1725 | os_free(signed_conn); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1726 | wpabuf_free(dppcon); |
| 1727 | return buf; |
| 1728 | fail: |
| 1729 | wpa_printf(MSG_DEBUG, "DPP: Failed to build configuration object"); |
| 1730 | wpabuf_free(buf); |
| 1731 | buf = NULL; |
| 1732 | goto out; |
| 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | static struct wpabuf * |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1737 | dpp_build_conf_obj_legacy(struct dpp_authentication *auth, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1738 | struct dpp_configuration *conf) |
| 1739 | { |
| 1740 | struct wpabuf *buf; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1741 | const char *akm_str; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1742 | |
| 1743 | buf = dpp_build_conf_start(auth, conf, 1000); |
| 1744 | if (!buf) |
| 1745 | return NULL; |
| 1746 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1747 | if (auth->akm_use_selector && dpp_akm_ver2(conf->akm)) |
| 1748 | akm_str = dpp_akm_selector_str(conf->akm); |
| 1749 | else |
| 1750 | akm_str = dpp_akm_str(conf->akm); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1751 | json_start_object(buf, "cred"); |
| 1752 | json_add_string(buf, "akm", akm_str); |
| 1753 | json_value_sep(buf); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1754 | dpp_build_legacy_cred_params(buf, conf); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1755 | json_end_object(buf); |
| 1756 | json_end_object(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1757 | |
| 1758 | wpa_hexdump_ascii_key(MSG_DEBUG, "DPP: Configuration Object (legacy)", |
| 1759 | wpabuf_head(buf), wpabuf_len(buf)); |
| 1760 | |
| 1761 | return buf; |
| 1762 | } |
| 1763 | |
| 1764 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1765 | static int dpp_get_peer_bi_id(struct dpp_authentication *auth) |
| 1766 | { |
| 1767 | struct dpp_bootstrap_info *bi; |
| 1768 | |
| 1769 | if (auth->peer_bi) |
| 1770 | return auth->peer_bi->id; |
| 1771 | if (auth->tmp_peer_bi) |
| 1772 | return auth->tmp_peer_bi->id; |
| 1773 | |
| 1774 | bi = os_zalloc(sizeof(*bi)); |
| 1775 | if (!bi) |
| 1776 | return -1; |
| 1777 | bi->id = dpp_next_id(auth->global); |
| 1778 | dl_list_add(&auth->global->bootstrap, &bi->list); |
| 1779 | auth->tmp_peer_bi = bi; |
| 1780 | return bi->id; |
| 1781 | } |
| 1782 | |
| 1783 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1784 | static struct wpabuf * |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1785 | dpp_build_conf_obj(struct dpp_authentication *auth, enum dpp_netrole netrole, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1786 | int idx, bool cert_req) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1787 | { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1788 | struct dpp_configuration *conf = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1789 | |
| 1790 | #ifdef CONFIG_TESTING_OPTIONS |
| 1791 | if (auth->config_obj_override) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1792 | if (idx != 0) |
| 1793 | return NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1794 | wpa_printf(MSG_DEBUG, "DPP: Testing - Config Object override"); |
| 1795 | return wpabuf_alloc_copy(auth->config_obj_override, |
| 1796 | os_strlen(auth->config_obj_override)); |
| 1797 | } |
| 1798 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1799 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1800 | if (idx == 0) { |
| 1801 | if (netrole == DPP_NETROLE_STA) |
| 1802 | conf = auth->conf_sta; |
| 1803 | else if (netrole == DPP_NETROLE_AP) |
| 1804 | conf = auth->conf_ap; |
| 1805 | } else if (idx == 1) { |
| 1806 | if (netrole == DPP_NETROLE_STA) |
| 1807 | conf = auth->conf2_sta; |
| 1808 | else if (netrole == DPP_NETROLE_AP) |
| 1809 | conf = auth->conf2_ap; |
| 1810 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1811 | if (!conf) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1812 | if (idx == 0) { |
| 1813 | if (auth->use_config_query) { |
| 1814 | wpa_printf(MSG_DEBUG, |
| 1815 | "DPP: No configuration available for Enrollee(%s) - waiting for configuration", |
| 1816 | dpp_netrole_str(netrole)); |
| 1817 | auth->waiting_config = true; |
| 1818 | dpp_get_peer_bi_id(auth); |
| 1819 | return NULL; |
| 1820 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1821 | wpa_printf(MSG_DEBUG, |
| 1822 | "DPP: No configuration available for Enrollee(%s) - reject configuration request", |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1823 | dpp_netrole_str(netrole)); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1824 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1825 | return NULL; |
| 1826 | } |
| 1827 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1828 | if (conf->akm == DPP_AKM_DOT1X) { |
| 1829 | if (!auth->conf) { |
| 1830 | wpa_printf(MSG_DEBUG, |
| 1831 | "DPP: No Configurator data available"); |
| 1832 | return NULL; |
| 1833 | } |
| 1834 | if (!cert_req && !auth->certbag) { |
| 1835 | wpa_printf(MSG_DEBUG, |
| 1836 | "DPP: No certificate data available for dot1x configuration"); |
| 1837 | return NULL; |
| 1838 | } |
| 1839 | return dpp_build_conf_obj_dpp(auth, conf); |
| 1840 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1841 | if (dpp_akm_dpp(conf->akm) || (auth->peer_version >= 2 && auth->conf)) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1842 | return dpp_build_conf_obj_dpp(auth, conf); |
| 1843 | return dpp_build_conf_obj_legacy(auth, conf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1847 | struct wpabuf * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1848 | dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1849 | u16 e_nonce_len, enum dpp_netrole netrole, bool cert_req) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1850 | { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1851 | struct wpabuf *conf = NULL, *conf2 = NULL, *env_data = NULL, *pc = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1852 | size_t clear_len, attr_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1853 | struct wpabuf *clear = NULL, *msg = NULL; |
| 1854 | u8 *wrapped; |
| 1855 | const u8 *addr[1]; |
| 1856 | size_t len[1]; |
| 1857 | enum dpp_status_error status; |
| 1858 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1859 | if (auth->force_conf_resp_status != DPP_STATUS_OK) { |
| 1860 | status = auth->force_conf_resp_status; |
| 1861 | goto forced_status; |
| 1862 | } |
| 1863 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1864 | if (netrole == DPP_NETROLE_CONFIGURATOR) { |
| 1865 | #ifdef CONFIG_DPP2 |
| 1866 | env_data = dpp_build_enveloped_data(auth); |
| 1867 | #endif /* CONFIG_DPP2 */ |
| 1868 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1869 | conf = dpp_build_conf_obj(auth, netrole, 0, cert_req); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1870 | if (conf) { |
| 1871 | wpa_hexdump_ascii(MSG_DEBUG, |
| 1872 | "DPP: configurationObject JSON", |
| 1873 | wpabuf_head(conf), wpabuf_len(conf)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1874 | conf2 = dpp_build_conf_obj(auth, netrole, 1, cert_req); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1875 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1876 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1877 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1878 | if (!conf && auth->waiting_config) |
| 1879 | return NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1880 | if (conf || env_data) |
| 1881 | status = DPP_STATUS_OK; |
| 1882 | else if (!cert_req && netrole == DPP_NETROLE_STA && auth->conf_sta && |
| 1883 | auth->conf_sta->akm == DPP_AKM_DOT1X && !auth->waiting_csr) |
| 1884 | status = DPP_STATUS_CSR_NEEDED; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1885 | #ifdef CONFIG_DPP3 |
| 1886 | else if (auth->waiting_new_key) |
| 1887 | status = DPP_STATUS_NEW_KEY_NEEDED; |
| 1888 | #endif /* CONFIG_DPP3 */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1889 | else |
| 1890 | status = DPP_STATUS_CONFIGURE_FAILURE; |
| 1891 | forced_status: |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1892 | auth->conf_resp_status = status; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1893 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1894 | /* { E-nonce, configurationObject[, sendConnStatus]}ke */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1895 | clear_len = 4 + e_nonce_len; |
| 1896 | if (conf) |
| 1897 | clear_len += 4 + wpabuf_len(conf); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1898 | if (conf2) |
| 1899 | clear_len += 4 + wpabuf_len(conf2); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1900 | if (env_data) |
| 1901 | clear_len += 4 + wpabuf_len(env_data); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1902 | if (auth->peer_version >= 2 && auth->send_conn_status && |
| 1903 | netrole == DPP_NETROLE_STA) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1904 | clear_len += 4; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1905 | if (status == DPP_STATUS_CSR_NEEDED && auth->conf_sta && |
| 1906 | auth->conf_sta->csrattrs) |
| 1907 | clear_len += 4 + os_strlen(auth->conf_sta->csrattrs); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 1908 | #ifdef CONFIG_DPP3 |
| 1909 | if (status == DPP_STATUS_NEW_KEY_NEEDED) { |
| 1910 | struct crypto_ec_key *new_pc; |
| 1911 | |
| 1912 | clear_len += 6; /* Finite Cyclic Group attribute */ |
| 1913 | |
| 1914 | wpa_printf(MSG_DEBUG, |
| 1915 | "DPP: Generate a new own protocol key for the curve %s", |
| 1916 | auth->conf->net_access_key_curve->name); |
| 1917 | new_pc = dpp_gen_keypair(auth->conf->net_access_key_curve); |
| 1918 | if (!new_pc) { |
| 1919 | wpa_printf(MSG_DEBUG, "DPP: Failed to generate new Pc"); |
| 1920 | return NULL; |
| 1921 | } |
| 1922 | pc = crypto_ec_key_get_pubkey_point(new_pc, 0); |
| 1923 | if (!pc) { |
| 1924 | crypto_ec_key_deinit(new_pc); |
| 1925 | return NULL; |
| 1926 | } |
| 1927 | crypto_ec_key_deinit(auth->own_protocol_key); |
| 1928 | auth->own_protocol_key = new_pc; |
| 1929 | auth->new_curve = auth->conf->net_access_key_curve; |
| 1930 | clear_len += 4 + wpabuf_len(pc); |
| 1931 | } |
| 1932 | #endif /* CONFIG_DPP3 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1933 | clear = wpabuf_alloc(clear_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1934 | attr_len = 4 + 1 + 4 + clear_len + AES_BLOCK_SIZE; |
| 1935 | #ifdef CONFIG_TESTING_OPTIONS |
| 1936 | if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP) |
| 1937 | attr_len += 5; |
| 1938 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1939 | msg = wpabuf_alloc(attr_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1940 | if (!clear || !msg) |
| 1941 | goto fail; |
| 1942 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1943 | #ifdef CONFIG_TESTING_OPTIONS |
| 1944 | if (dpp_test == DPP_TEST_NO_E_NONCE_CONF_RESP) { |
| 1945 | wpa_printf(MSG_INFO, "DPP: TESTING - no E-nonce"); |
| 1946 | goto skip_e_nonce; |
| 1947 | } |
| 1948 | if (dpp_test == DPP_TEST_E_NONCE_MISMATCH_CONF_RESP) { |
| 1949 | wpa_printf(MSG_INFO, "DPP: TESTING - E-nonce mismatch"); |
| 1950 | wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE); |
| 1951 | wpabuf_put_le16(clear, e_nonce_len); |
| 1952 | wpabuf_put_data(clear, e_nonce, e_nonce_len - 1); |
| 1953 | wpabuf_put_u8(clear, e_nonce[e_nonce_len - 1] ^ 0x01); |
| 1954 | goto skip_e_nonce; |
| 1955 | } |
| 1956 | if (dpp_test == DPP_TEST_NO_WRAPPED_DATA_CONF_RESP) { |
| 1957 | wpa_printf(MSG_INFO, "DPP: TESTING - no Wrapped Data"); |
| 1958 | goto skip_wrapped_data; |
| 1959 | } |
| 1960 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1961 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1962 | /* E-nonce */ |
| 1963 | wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE); |
| 1964 | wpabuf_put_le16(clear, e_nonce_len); |
| 1965 | wpabuf_put_data(clear, e_nonce, e_nonce_len); |
| 1966 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1967 | #ifdef CONFIG_TESTING_OPTIONS |
| 1968 | skip_e_nonce: |
| 1969 | if (dpp_test == DPP_TEST_NO_CONFIG_OBJ_CONF_RESP) { |
| 1970 | wpa_printf(MSG_INFO, "DPP: TESTING - Config Object"); |
| 1971 | goto skip_config_obj; |
| 1972 | } |
| 1973 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1974 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1975 | if (conf) { |
| 1976 | wpabuf_put_le16(clear, DPP_ATTR_CONFIG_OBJ); |
| 1977 | wpabuf_put_le16(clear, wpabuf_len(conf)); |
| 1978 | wpabuf_put_buf(clear, conf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1979 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1980 | if (auth->peer_version >= 2 && conf2) { |
| 1981 | wpabuf_put_le16(clear, DPP_ATTR_CONFIG_OBJ); |
| 1982 | wpabuf_put_le16(clear, wpabuf_len(conf2)); |
| 1983 | wpabuf_put_buf(clear, conf2); |
| 1984 | } else if (conf2) { |
| 1985 | wpa_printf(MSG_DEBUG, |
| 1986 | "DPP: Second Config Object available, but peer does not support more than one"); |
| 1987 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1988 | if (env_data) { |
| 1989 | wpabuf_put_le16(clear, DPP_ATTR_ENVELOPED_DATA); |
| 1990 | wpabuf_put_le16(clear, wpabuf_len(env_data)); |
| 1991 | wpabuf_put_buf(clear, env_data); |
| 1992 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1993 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1994 | if (auth->peer_version >= 2 && auth->send_conn_status && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1995 | netrole == DPP_NETROLE_STA && status == DPP_STATUS_OK) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1996 | wpa_printf(MSG_DEBUG, "DPP: sendConnStatus"); |
| 1997 | wpabuf_put_le16(clear, DPP_ATTR_SEND_CONN_STATUS); |
| 1998 | wpabuf_put_le16(clear, 0); |
| 1999 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2000 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2001 | if (status == DPP_STATUS_CSR_NEEDED && auth->conf_sta && |
| 2002 | auth->conf_sta->csrattrs) { |
| 2003 | auth->waiting_csr = true; |
| 2004 | wpa_printf(MSG_DEBUG, "DPP: CSR Attributes Request"); |
| 2005 | wpabuf_put_le16(clear, DPP_ATTR_CSR_ATTR_REQ); |
| 2006 | wpabuf_put_le16(clear, os_strlen(auth->conf_sta->csrattrs)); |
| 2007 | wpabuf_put_str(clear, auth->conf_sta->csrattrs); |
| 2008 | } |
| 2009 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 2010 | #ifdef CONFIG_DPP3 |
| 2011 | if (status == DPP_STATUS_NEW_KEY_NEEDED && auth->conf && |
| 2012 | auth->conf->net_access_key_curve) { |
| 2013 | u16 ike_group = auth->conf->net_access_key_curve->ike_group; |
| 2014 | |
| 2015 | /* Finite Cyclic Group attribute */ |
| 2016 | wpa_printf(MSG_DEBUG, "DPP: Finite Cyclic Group: %u", |
| 2017 | ike_group); |
| 2018 | wpabuf_put_le16(clear, DPP_ATTR_FINITE_CYCLIC_GROUP); |
| 2019 | wpabuf_put_le16(clear, 2); |
| 2020 | wpabuf_put_le16(clear, ike_group); |
| 2021 | |
| 2022 | if (pc) { |
| 2023 | wpa_printf(MSG_DEBUG, "DPP: Pc"); |
| 2024 | wpabuf_put_le16(clear, DPP_ATTR_R_PROTOCOL_KEY); |
| 2025 | wpabuf_put_le16(clear, wpabuf_len(pc)); |
| 2026 | wpabuf_put_buf(clear, pc); |
| 2027 | } |
| 2028 | } |
| 2029 | #endif /* CONFIG_DPP3 */ |
| 2030 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2031 | #ifdef CONFIG_TESTING_OPTIONS |
| 2032 | skip_config_obj: |
| 2033 | if (dpp_test == DPP_TEST_NO_STATUS_CONF_RESP) { |
| 2034 | wpa_printf(MSG_INFO, "DPP: TESTING - Status"); |
| 2035 | goto skip_status; |
| 2036 | } |
| 2037 | if (dpp_test == DPP_TEST_INVALID_STATUS_CONF_RESP) { |
| 2038 | wpa_printf(MSG_INFO, "DPP: TESTING - invalid Status"); |
| 2039 | status = 255; |
| 2040 | } |
| 2041 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2042 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2043 | /* DPP Status */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2044 | dpp_build_attr_status(msg, status); |
| 2045 | |
| 2046 | #ifdef CONFIG_TESTING_OPTIONS |
| 2047 | skip_status: |
| 2048 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2049 | |
| 2050 | addr[0] = wpabuf_head(msg); |
| 2051 | len[0] = wpabuf_len(msg); |
| 2052 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD", addr[0], len[0]); |
| 2053 | |
| 2054 | wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA); |
| 2055 | wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 2056 | wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 2057 | |
| 2058 | wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear); |
| 2059 | if (aes_siv_encrypt(auth->ke, auth->curve->hash_len, |
| 2060 | wpabuf_head(clear), wpabuf_len(clear), |
| 2061 | 1, addr, len, wrapped) < 0) |
| 2062 | goto fail; |
| 2063 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext", |
| 2064 | wrapped, wpabuf_len(clear) + AES_BLOCK_SIZE); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2065 | |
| 2066 | #ifdef CONFIG_TESTING_OPTIONS |
| 2067 | if (dpp_test == DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP) { |
| 2068 | wpa_printf(MSG_INFO, "DPP: TESTING - attr after Wrapped Data"); |
| 2069 | dpp_build_attr_status(msg, DPP_STATUS_OK); |
| 2070 | } |
| 2071 | skip_wrapped_data: |
| 2072 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2073 | |
| 2074 | wpa_hexdump_buf(MSG_DEBUG, |
| 2075 | "DPP: Configuration Response attributes", msg); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2076 | out: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2077 | wpabuf_clear_free(conf); |
| 2078 | wpabuf_clear_free(conf2); |
| 2079 | wpabuf_clear_free(env_data); |
| 2080 | wpabuf_clear_free(clear); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 2081 | wpabuf_free(pc); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2082 | |
| 2083 | return msg; |
| 2084 | fail: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2085 | wpabuf_free(msg); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2086 | msg = NULL; |
| 2087 | goto out; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | |
| 2091 | struct wpabuf * |
| 2092 | dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start, |
| 2093 | size_t attr_len) |
| 2094 | { |
| 2095 | const u8 *wrapped_data, *e_nonce, *config_attr; |
| 2096 | u16 wrapped_data_len, e_nonce_len, config_attr_len; |
| 2097 | u8 *unwrapped = NULL; |
| 2098 | size_t unwrapped_len = 0; |
| 2099 | struct wpabuf *resp = NULL; |
| 2100 | struct json_token *root = NULL, *token; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2101 | enum dpp_netrole netrole; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2102 | struct wpabuf *cert_req = NULL; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 2103 | #ifdef CONFIG_DPP3 |
| 2104 | const u8 *i_proto; |
| 2105 | u16 i_proto_len; |
| 2106 | #endif /* CONFIG_DPP3 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2107 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2108 | #ifdef CONFIG_TESTING_OPTIONS |
| 2109 | if (dpp_test == DPP_TEST_STOP_AT_CONF_REQ) { |
| 2110 | wpa_printf(MSG_INFO, |
| 2111 | "DPP: TESTING - stop at Config Request"); |
| 2112 | return NULL; |
| 2113 | } |
| 2114 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2115 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2116 | if (dpp_check_attrs(attr_start, attr_len) < 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2117 | dpp_auth_fail(auth, "Invalid attribute in config request"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2118 | return NULL; |
| 2119 | } |
| 2120 | |
| 2121 | wrapped_data = dpp_get_attr(attr_start, attr_len, DPP_ATTR_WRAPPED_DATA, |
| 2122 | &wrapped_data_len); |
| 2123 | if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2124 | dpp_auth_fail(auth, |
| 2125 | "Missing or invalid required Wrapped Data attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2126 | return NULL; |
| 2127 | } |
| 2128 | |
| 2129 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext", |
| 2130 | wrapped_data, wrapped_data_len); |
| 2131 | unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE; |
| 2132 | unwrapped = os_malloc(unwrapped_len); |
| 2133 | if (!unwrapped) |
| 2134 | return NULL; |
| 2135 | if (aes_siv_decrypt(auth->ke, auth->curve->hash_len, |
| 2136 | wrapped_data, wrapped_data_len, |
| 2137 | 0, NULL, NULL, unwrapped) < 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2138 | dpp_auth_fail(auth, "AES-SIV decryption failed"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2139 | goto fail; |
| 2140 | } |
| 2141 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext", |
| 2142 | unwrapped, unwrapped_len); |
| 2143 | |
| 2144 | if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2145 | dpp_auth_fail(auth, "Invalid attribute in unwrapped data"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2146 | goto fail; |
| 2147 | } |
| 2148 | |
| 2149 | e_nonce = dpp_get_attr(unwrapped, unwrapped_len, |
| 2150 | DPP_ATTR_ENROLLEE_NONCE, |
| 2151 | &e_nonce_len); |
| 2152 | if (!e_nonce || e_nonce_len != auth->curve->nonce_len) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2153 | dpp_auth_fail(auth, |
| 2154 | "Missing or invalid Enrollee Nonce attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2155 | goto fail; |
| 2156 | } |
| 2157 | wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2158 | os_memcpy(auth->e_nonce, e_nonce, e_nonce_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2159 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 2160 | #ifdef CONFIG_DPP3 |
| 2161 | i_proto = dpp_get_attr(unwrapped, unwrapped_len, |
| 2162 | DPP_ATTR_I_PROTOCOL_KEY, &i_proto_len); |
| 2163 | if (i_proto && !auth->waiting_new_key) { |
| 2164 | dpp_auth_fail(auth, |
| 2165 | "Enrollee included a new protocol key even though one was not expected"); |
| 2166 | goto fail; |
| 2167 | } |
| 2168 | if (i_proto) { |
| 2169 | struct crypto_ec_key *pe; |
| 2170 | u8 auth_i[DPP_MAX_HASH_LEN]; |
| 2171 | const u8 *rx_auth_i; |
| 2172 | u16 rx_auth_i_len; |
| 2173 | |
| 2174 | wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Protocol Key (new Pe)", |
| 2175 | i_proto, i_proto_len); |
| 2176 | |
| 2177 | pe = dpp_set_pubkey_point(auth->own_protocol_key, |
| 2178 | i_proto, i_proto_len); |
| 2179 | if (!pe) { |
| 2180 | dpp_auth_fail(auth, |
| 2181 | "Invalid Initiator Protocol Key (Pe)"); |
| 2182 | goto fail; |
| 2183 | } |
| 2184 | dpp_debug_print_key("New Peer Protocol Key (Pe)", pe); |
| 2185 | crypto_ec_key_deinit(auth->peer_protocol_key); |
| 2186 | auth->peer_protocol_key = pe; |
| 2187 | auth->new_key_received = true; |
| 2188 | auth->waiting_new_key = false; |
| 2189 | |
| 2190 | if (dpp_derive_auth_i(auth, auth_i) < 0) |
| 2191 | goto fail; |
| 2192 | |
| 2193 | rx_auth_i = dpp_get_attr(unwrapped, unwrapped_len, |
| 2194 | DPP_ATTR_I_AUTH_TAG, &rx_auth_i_len); |
| 2195 | if (!rx_auth_i) { |
| 2196 | dpp_auth_fail(auth, |
| 2197 | "Missing Initiator Authentication Tag"); |
| 2198 | goto fail; |
| 2199 | } |
| 2200 | if (rx_auth_i_len != auth->curve->hash_len || |
| 2201 | os_memcmp(rx_auth_i, auth_i, auth->curve->hash_len) != 0) { |
| 2202 | dpp_auth_fail(auth, |
| 2203 | "Mismatch in Initiator Authenticating Tag"); |
| 2204 | wpa_hexdump(MSG_DEBUG, "DPP: Received Auth-I", |
| 2205 | rx_auth_i, rx_auth_i_len); |
| 2206 | wpa_hexdump(MSG_DEBUG, "DPP: Derived Auth-I'", |
| 2207 | auth_i, auth->curve->hash_len); |
| 2208 | goto fail; |
| 2209 | } |
| 2210 | } |
| 2211 | #endif /* CONFIG_DPP3 */ |
| 2212 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2213 | config_attr = dpp_get_attr(unwrapped, unwrapped_len, |
| 2214 | DPP_ATTR_CONFIG_ATTR_OBJ, |
| 2215 | &config_attr_len); |
| 2216 | if (!config_attr) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2217 | dpp_auth_fail(auth, |
| 2218 | "Missing or invalid Config Attributes attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2219 | goto fail; |
| 2220 | } |
| 2221 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: Config Attributes", |
| 2222 | config_attr, config_attr_len); |
| 2223 | |
| 2224 | root = json_parse((const char *) config_attr, config_attr_len); |
| 2225 | if (!root) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2226 | dpp_auth_fail(auth, "Could not parse Config Attributes"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2227 | goto fail; |
| 2228 | } |
| 2229 | |
| 2230 | token = json_get_member(root, "name"); |
| 2231 | if (!token || token->type != JSON_STRING) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2232 | dpp_auth_fail(auth, "No Config Attributes - name"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2233 | goto fail; |
| 2234 | } |
| 2235 | wpa_printf(MSG_DEBUG, "DPP: Enrollee name = '%s'", token->string); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2236 | os_free(auth->e_name); |
| 2237 | auth->e_name = os_strdup(token->string); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2238 | |
| 2239 | token = json_get_member(root, "wi-fi_tech"); |
| 2240 | if (!token || token->type != JSON_STRING) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2241 | dpp_auth_fail(auth, "No Config Attributes - wi-fi_tech"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2242 | goto fail; |
| 2243 | } |
| 2244 | wpa_printf(MSG_DEBUG, "DPP: wi-fi_tech = '%s'", token->string); |
| 2245 | if (os_strcmp(token->string, "infra") != 0) { |
| 2246 | wpa_printf(MSG_DEBUG, "DPP: Unsupported wi-fi_tech '%s'", |
| 2247 | token->string); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2248 | dpp_auth_fail(auth, "Unsupported wi-fi_tech"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2249 | goto fail; |
| 2250 | } |
| 2251 | |
| 2252 | token = json_get_member(root, "netRole"); |
| 2253 | if (!token || token->type != JSON_STRING) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2254 | dpp_auth_fail(auth, "No Config Attributes - netRole"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2255 | goto fail; |
| 2256 | } |
| 2257 | wpa_printf(MSG_DEBUG, "DPP: netRole = '%s'", token->string); |
| 2258 | if (os_strcmp(token->string, "sta") == 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2259 | netrole = DPP_NETROLE_STA; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2260 | } else if (os_strcmp(token->string, "ap") == 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2261 | netrole = DPP_NETROLE_AP; |
| 2262 | } else if (os_strcmp(token->string, "configurator") == 0) { |
| 2263 | netrole = DPP_NETROLE_CONFIGURATOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2264 | } else { |
| 2265 | wpa_printf(MSG_DEBUG, "DPP: Unsupported netRole '%s'", |
| 2266 | token->string); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2267 | dpp_auth_fail(auth, "Unsupported netRole"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2268 | goto fail; |
| 2269 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2270 | auth->e_netrole = netrole; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2271 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2272 | token = json_get_member(root, "mudurl"); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2273 | if (token && token->type == JSON_STRING) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2274 | wpa_printf(MSG_DEBUG, "DPP: mudurl = '%s'", token->string); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2275 | wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_MUD_URL "%s", |
| 2276 | token->string); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2277 | os_free(auth->e_mud_url); |
| 2278 | auth->e_mud_url = os_strdup(token->string); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2279 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2280 | |
| 2281 | token = json_get_member(root, "bandSupport"); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 2282 | auth->band_list_size = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2283 | if (token && token->type == JSON_ARRAY) { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2284 | int *opclass = NULL; |
| 2285 | char txt[200], *pos, *end; |
| 2286 | int i, res; |
| 2287 | |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 2288 | memset(auth->band_list, 0, sizeof(auth->band_list)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2289 | wpa_printf(MSG_DEBUG, "DPP: bandSupport"); |
| 2290 | token = token->child; |
| 2291 | while (token) { |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 2292 | if (token->type != JSON_NUMBER) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2293 | wpa_printf(MSG_DEBUG, |
| 2294 | "DPP: Invalid bandSupport array member type"); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 2295 | } else { |
| 2296 | if (auth->band_list_size < DPP_MAX_CHANNELS) { |
| 2297 | auth->band_list[auth->band_list_size++] = token->number; |
| 2298 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2299 | wpa_printf(MSG_DEBUG, |
| 2300 | "DPP: Supported global operating class: %d", |
| 2301 | token->number); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2302 | int_array_add_unique(&opclass, token->number); |
Hai Shalom | 0676811 | 2019-12-04 15:49:43 -0800 | [diff] [blame] | 2303 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2304 | token = token->sibling; |
| 2305 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2306 | |
| 2307 | txt[0] = '\0'; |
| 2308 | pos = txt; |
| 2309 | end = txt + sizeof(txt); |
| 2310 | for (i = 0; opclass && opclass[i]; i++) { |
| 2311 | res = os_snprintf(pos, end - pos, "%s%d", |
| 2312 | pos == txt ? "" : ",", opclass[i]); |
| 2313 | if (os_snprintf_error(end - pos, res)) { |
| 2314 | *pos = '\0'; |
| 2315 | break; |
| 2316 | } |
| 2317 | pos += res; |
| 2318 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2319 | os_free(auth->e_band_support); |
| 2320 | auth->e_band_support = opclass; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2321 | wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_BAND_SUPPORT "%s", |
| 2322 | txt); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2325 | #ifdef CONFIG_DPP2 |
| 2326 | cert_req = json_get_member_base64(root, "pkcs10"); |
| 2327 | if (cert_req) { |
| 2328 | char *txt; |
| 2329 | int id; |
| 2330 | |
| 2331 | wpa_hexdump_buf(MSG_DEBUG, "DPP: CertificateRequest", cert_req); |
| 2332 | if (dpp_validate_csr(auth, cert_req) < 0) { |
| 2333 | wpa_printf(MSG_DEBUG, "DPP: CSR is not valid"); |
| 2334 | auth->force_conf_resp_status = DPP_STATUS_CSR_BAD; |
| 2335 | goto cont; |
| 2336 | } |
| 2337 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2338 | id = dpp_get_peer_bi_id(auth); |
| 2339 | if (id < 0) |
| 2340 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2341 | |
| 2342 | wpa_printf(MSG_DEBUG, "DPP: CSR is valid - forward to CA/RA"); |
| 2343 | txt = base64_encode_no_lf(wpabuf_head(cert_req), |
| 2344 | wpabuf_len(cert_req), NULL); |
| 2345 | if (!txt) |
| 2346 | goto fail; |
| 2347 | |
| 2348 | wpa_msg(auth->msg_ctx, MSG_INFO, DPP_EVENT_CSR "peer=%d csr=%s", |
| 2349 | id, txt); |
| 2350 | os_free(txt); |
| 2351 | auth->waiting_csr = false; |
| 2352 | auth->waiting_cert = true; |
| 2353 | goto fail; |
| 2354 | } |
| 2355 | cont: |
| 2356 | #endif /* CONFIG_DPP2 */ |
| 2357 | |
| 2358 | resp = dpp_build_conf_resp(auth, e_nonce, e_nonce_len, netrole, |
| 2359 | cert_req); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2360 | |
| 2361 | fail: |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2362 | wpabuf_free(cert_req); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2363 | json_free(root); |
| 2364 | os_free(unwrapped); |
| 2365 | return resp; |
| 2366 | } |
| 2367 | |
| 2368 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2369 | static int dpp_parse_cred_legacy(struct dpp_config_obj *conf, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2370 | struct json_token *cred) |
| 2371 | { |
| 2372 | struct json_token *pass, *psk_hex; |
| 2373 | |
| 2374 | wpa_printf(MSG_DEBUG, "DPP: Legacy akm=psk credential"); |
| 2375 | |
| 2376 | pass = json_get_member(cred, "pass"); |
| 2377 | psk_hex = json_get_member(cred, "psk_hex"); |
| 2378 | |
| 2379 | if (pass && pass->type == JSON_STRING) { |
| 2380 | size_t len = os_strlen(pass->string); |
| 2381 | |
| 2382 | wpa_hexdump_ascii_key(MSG_DEBUG, "DPP: Legacy passphrase", |
| 2383 | pass->string, len); |
| 2384 | if (len < 8 || len > 63) |
| 2385 | return -1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2386 | os_strlcpy(conf->passphrase, pass->string, |
| 2387 | sizeof(conf->passphrase)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2388 | } else if (psk_hex && psk_hex->type == JSON_STRING) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2389 | if (dpp_akm_sae(conf->akm) && !dpp_akm_psk(conf->akm)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2390 | wpa_printf(MSG_DEBUG, |
| 2391 | "DPP: Unexpected psk_hex with akm=sae"); |
| 2392 | return -1; |
| 2393 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2394 | if (os_strlen(psk_hex->string) != PMK_LEN * 2 || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2395 | hexstr2bin(psk_hex->string, conf->psk, PMK_LEN) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2396 | wpa_printf(MSG_DEBUG, "DPP: Invalid psk_hex encoding"); |
| 2397 | return -1; |
| 2398 | } |
| 2399 | wpa_hexdump_key(MSG_DEBUG, "DPP: Legacy PSK", |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2400 | conf->psk, PMK_LEN); |
| 2401 | conf->psk_set = 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2402 | } else { |
| 2403 | wpa_printf(MSG_DEBUG, "DPP: No pass or psk_hex strings found"); |
| 2404 | return -1; |
| 2405 | } |
| 2406 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2407 | if (dpp_akm_sae(conf->akm) && !conf->passphrase[0]) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2408 | wpa_printf(MSG_DEBUG, "DPP: No pass for sae found"); |
| 2409 | return -1; |
| 2410 | } |
| 2411 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2416 | struct crypto_ec_key * dpp_parse_jwk(struct json_token *jwk, |
| 2417 | const struct dpp_curve_params **key_curve) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2418 | { |
| 2419 | struct json_token *token; |
| 2420 | const struct dpp_curve_params *curve; |
| 2421 | struct wpabuf *x = NULL, *y = NULL; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2422 | struct crypto_ec_key *key = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2423 | |
| 2424 | token = json_get_member(jwk, "kty"); |
| 2425 | if (!token || token->type != JSON_STRING) { |
| 2426 | wpa_printf(MSG_DEBUG, "DPP: No kty in JWK"); |
| 2427 | goto fail; |
| 2428 | } |
| 2429 | if (os_strcmp(token->string, "EC") != 0) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2430 | wpa_printf(MSG_DEBUG, "DPP: Unexpected JWK kty '%s'", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2431 | token->string); |
| 2432 | goto fail; |
| 2433 | } |
| 2434 | |
| 2435 | token = json_get_member(jwk, "crv"); |
| 2436 | if (!token || token->type != JSON_STRING) { |
| 2437 | wpa_printf(MSG_DEBUG, "DPP: No crv in JWK"); |
| 2438 | goto fail; |
| 2439 | } |
| 2440 | curve = dpp_get_curve_jwk_crv(token->string); |
| 2441 | if (!curve) { |
| 2442 | wpa_printf(MSG_DEBUG, "DPP: Unsupported JWK crv '%s'", |
| 2443 | token->string); |
| 2444 | goto fail; |
| 2445 | } |
| 2446 | |
| 2447 | x = json_get_member_base64url(jwk, "x"); |
| 2448 | if (!x) { |
| 2449 | wpa_printf(MSG_DEBUG, "DPP: No x in JWK"); |
| 2450 | goto fail; |
| 2451 | } |
| 2452 | wpa_hexdump_buf(MSG_DEBUG, "DPP: JWK x", x); |
| 2453 | if (wpabuf_len(x) != curve->prime_len) { |
| 2454 | wpa_printf(MSG_DEBUG, |
| 2455 | "DPP: Unexpected JWK x length %u (expected %u for curve %s)", |
| 2456 | (unsigned int) wpabuf_len(x), |
| 2457 | (unsigned int) curve->prime_len, curve->name); |
| 2458 | goto fail; |
| 2459 | } |
| 2460 | |
| 2461 | y = json_get_member_base64url(jwk, "y"); |
| 2462 | if (!y) { |
| 2463 | wpa_printf(MSG_DEBUG, "DPP: No y in JWK"); |
| 2464 | goto fail; |
| 2465 | } |
| 2466 | wpa_hexdump_buf(MSG_DEBUG, "DPP: JWK y", y); |
| 2467 | if (wpabuf_len(y) != curve->prime_len) { |
| 2468 | wpa_printf(MSG_DEBUG, |
| 2469 | "DPP: Unexpected JWK y length %u (expected %u for curve %s)", |
| 2470 | (unsigned int) wpabuf_len(y), |
| 2471 | (unsigned int) curve->prime_len, curve->name); |
| 2472 | goto fail; |
| 2473 | } |
| 2474 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2475 | key = crypto_ec_key_set_pub(curve->ike_group, wpabuf_head(x), |
| 2476 | wpabuf_head(y), wpabuf_len(x)); |
| 2477 | if (!key) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2478 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2479 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2480 | *key_curve = curve; |
| 2481 | |
| 2482 | fail: |
| 2483 | wpabuf_free(x); |
| 2484 | wpabuf_free(y); |
| 2485 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2486 | return key; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | |
| 2490 | int dpp_key_expired(const char *timestamp, os_time_t *expiry) |
| 2491 | { |
| 2492 | struct os_time now; |
| 2493 | unsigned int year, month, day, hour, min, sec; |
| 2494 | os_time_t utime; |
| 2495 | const char *pos; |
| 2496 | |
| 2497 | /* ISO 8601 date and time: |
| 2498 | * <date>T<time> |
| 2499 | * YYYY-MM-DDTHH:MM:SSZ |
| 2500 | * YYYY-MM-DDTHH:MM:SS+03:00 |
| 2501 | */ |
| 2502 | if (os_strlen(timestamp) < 19) { |
| 2503 | wpa_printf(MSG_DEBUG, |
| 2504 | "DPP: Too short timestamp - assume expired key"); |
| 2505 | return 1; |
| 2506 | } |
| 2507 | if (sscanf(timestamp, "%04u-%02u-%02uT%02u:%02u:%02u", |
| 2508 | &year, &month, &day, &hour, &min, &sec) != 6) { |
| 2509 | wpa_printf(MSG_DEBUG, |
| 2510 | "DPP: Failed to parse expiration day - assume expired key"); |
| 2511 | return 1; |
| 2512 | } |
| 2513 | |
| 2514 | if (os_mktime(year, month, day, hour, min, sec, &utime) < 0) { |
| 2515 | wpa_printf(MSG_DEBUG, |
| 2516 | "DPP: Invalid date/time information - assume expired key"); |
| 2517 | return 1; |
| 2518 | } |
| 2519 | |
| 2520 | pos = timestamp + 19; |
| 2521 | if (*pos == 'Z' || *pos == '\0') { |
| 2522 | /* In UTC - no need to adjust */ |
| 2523 | } else if (*pos == '-' || *pos == '+') { |
| 2524 | int items; |
| 2525 | |
| 2526 | /* Adjust local time to UTC */ |
| 2527 | items = sscanf(pos + 1, "%02u:%02u", &hour, &min); |
| 2528 | if (items < 1) { |
| 2529 | wpa_printf(MSG_DEBUG, |
| 2530 | "DPP: Invalid time zone designator (%s) - assume expired key", |
| 2531 | pos); |
| 2532 | return 1; |
| 2533 | } |
| 2534 | if (*pos == '-') |
| 2535 | utime += 3600 * hour; |
| 2536 | if (*pos == '+') |
| 2537 | utime -= 3600 * hour; |
| 2538 | if (items > 1) { |
| 2539 | if (*pos == '-') |
| 2540 | utime += 60 * min; |
| 2541 | if (*pos == '+') |
| 2542 | utime -= 60 * min; |
| 2543 | } |
| 2544 | } else { |
| 2545 | wpa_printf(MSG_DEBUG, |
| 2546 | "DPP: Invalid time zone designator (%s) - assume expired key", |
| 2547 | pos); |
| 2548 | return 1; |
| 2549 | } |
| 2550 | if (expiry) |
| 2551 | *expiry = utime; |
| 2552 | |
| 2553 | if (os_get_time(&now) < 0) { |
| 2554 | wpa_printf(MSG_DEBUG, |
| 2555 | "DPP: Cannot get current time - assume expired key"); |
| 2556 | return 1; |
| 2557 | } |
| 2558 | |
| 2559 | if (now.sec > utime) { |
| 2560 | wpa_printf(MSG_DEBUG, "DPP: Key has expired (%lu < %lu)", |
| 2561 | utime, now.sec); |
| 2562 | return 1; |
| 2563 | } |
| 2564 | |
| 2565 | return 0; |
| 2566 | } |
| 2567 | |
| 2568 | |
| 2569 | static int dpp_parse_connector(struct dpp_authentication *auth, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2570 | struct dpp_config_obj *conf, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2571 | const unsigned char *payload, |
| 2572 | u16 payload_len) |
| 2573 | { |
| 2574 | struct json_token *root, *groups, *netkey, *token; |
| 2575 | int ret = -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2576 | struct crypto_ec_key *key = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2577 | const struct dpp_curve_params *curve; |
| 2578 | unsigned int rules = 0; |
| 2579 | |
| 2580 | root = json_parse((const char *) payload, payload_len); |
| 2581 | if (!root) { |
| 2582 | wpa_printf(MSG_DEBUG, "DPP: JSON parsing of connector failed"); |
| 2583 | goto fail; |
| 2584 | } |
| 2585 | |
| 2586 | groups = json_get_member(root, "groups"); |
| 2587 | if (!groups || groups->type != JSON_ARRAY) { |
| 2588 | wpa_printf(MSG_DEBUG, "DPP: No groups array found"); |
| 2589 | goto skip_groups; |
| 2590 | } |
| 2591 | for (token = groups->child; token; token = token->sibling) { |
| 2592 | struct json_token *id, *role; |
| 2593 | |
| 2594 | id = json_get_member(token, "groupId"); |
| 2595 | if (!id || id->type != JSON_STRING) { |
| 2596 | wpa_printf(MSG_DEBUG, "DPP: Missing groupId string"); |
| 2597 | goto fail; |
| 2598 | } |
| 2599 | |
| 2600 | role = json_get_member(token, "netRole"); |
| 2601 | if (!role || role->type != JSON_STRING) { |
| 2602 | wpa_printf(MSG_DEBUG, "DPP: Missing netRole string"); |
| 2603 | goto fail; |
| 2604 | } |
| 2605 | wpa_printf(MSG_DEBUG, |
| 2606 | "DPP: connector group: groupId='%s' netRole='%s'", |
| 2607 | id->string, role->string); |
| 2608 | rules++; |
| 2609 | } |
| 2610 | skip_groups: |
| 2611 | |
| 2612 | if (!rules) { |
| 2613 | wpa_printf(MSG_DEBUG, |
| 2614 | "DPP: Connector includes no groups"); |
| 2615 | goto fail; |
| 2616 | } |
| 2617 | |
| 2618 | token = json_get_member(root, "expiry"); |
| 2619 | if (!token || token->type != JSON_STRING) { |
| 2620 | wpa_printf(MSG_DEBUG, |
| 2621 | "DPP: No expiry string found - connector does not expire"); |
| 2622 | } else { |
| 2623 | wpa_printf(MSG_DEBUG, "DPP: expiry = %s", token->string); |
| 2624 | if (dpp_key_expired(token->string, |
| 2625 | &auth->net_access_key_expiry)) { |
| 2626 | wpa_printf(MSG_DEBUG, |
| 2627 | "DPP: Connector (netAccessKey) has expired"); |
| 2628 | goto fail; |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | netkey = json_get_member(root, "netAccessKey"); |
| 2633 | if (!netkey || netkey->type != JSON_OBJECT) { |
| 2634 | wpa_printf(MSG_DEBUG, "DPP: No netAccessKey object found"); |
| 2635 | goto fail; |
| 2636 | } |
| 2637 | |
| 2638 | key = dpp_parse_jwk(netkey, &curve); |
| 2639 | if (!key) |
| 2640 | goto fail; |
| 2641 | dpp_debug_print_key("DPP: Received netAccessKey", key); |
| 2642 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2643 | if (crypto_ec_key_cmp(key, auth->own_protocol_key)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2644 | wpa_printf(MSG_DEBUG, |
| 2645 | "DPP: netAccessKey in connector does not match own protocol key"); |
| 2646 | #ifdef CONFIG_TESTING_OPTIONS |
| 2647 | if (auth->ignore_netaccesskey_mismatch) { |
| 2648 | wpa_printf(MSG_DEBUG, |
| 2649 | "DPP: TESTING - skip netAccessKey mismatch"); |
| 2650 | } else { |
| 2651 | goto fail; |
| 2652 | } |
| 2653 | #else /* CONFIG_TESTING_OPTIONS */ |
| 2654 | goto fail; |
| 2655 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2656 | } |
| 2657 | |
| 2658 | ret = 0; |
| 2659 | fail: |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2660 | crypto_ec_key_deinit(key); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2661 | json_free(root); |
| 2662 | return ret; |
| 2663 | } |
| 2664 | |
| 2665 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2666 | static void dpp_copy_csign(struct dpp_config_obj *conf, |
| 2667 | struct crypto_ec_key *csign) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2668 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2669 | struct wpabuf *c_sign_key; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2670 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2671 | c_sign_key = crypto_ec_key_get_subject_public_key(csign); |
| 2672 | if (!c_sign_key) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2673 | return; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2674 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2675 | wpabuf_free(conf->c_sign_key); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2676 | conf->c_sign_key = c_sign_key; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2680 | static void dpp_copy_ppkey(struct dpp_config_obj *conf, |
| 2681 | struct crypto_ec_key *ppkey) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2682 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2683 | struct wpabuf *pp_key; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2684 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2685 | pp_key = crypto_ec_key_get_subject_public_key(ppkey); |
| 2686 | if (!pp_key) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2687 | return; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2688 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2689 | wpabuf_free(conf->pp_key); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2690 | conf->pp_key = pp_key; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2694 | static void dpp_copy_netaccesskey(struct dpp_authentication *auth, |
| 2695 | struct dpp_config_obj *conf) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2696 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2697 | struct wpabuf *net_access_key; |
| 2698 | struct crypto_ec_key *own_key; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2699 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2700 | own_key = auth->own_protocol_key; |
| 2701 | #ifdef CONFIG_DPP2 |
| 2702 | if (auth->reconfig_connector_key == DPP_CONFIG_REUSEKEY && |
| 2703 | auth->reconfig_old_protocol_key) |
| 2704 | own_key = auth->reconfig_old_protocol_key; |
| 2705 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2706 | |
| 2707 | net_access_key = crypto_ec_key_get_ecprivate_key(own_key, true); |
| 2708 | if (!net_access_key) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2709 | return; |
| 2710 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2711 | wpabuf_free(auth->net_access_key); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2712 | auth->net_access_key = net_access_key; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2716 | static int dpp_parse_cred_dpp(struct dpp_authentication *auth, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2717 | struct dpp_config_obj *conf, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2718 | struct json_token *cred) |
| 2719 | { |
| 2720 | struct dpp_signed_connector_info info; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2721 | struct json_token *token, *csign, *ppkey; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2722 | int ret = -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2723 | struct crypto_ec_key *csign_pub = NULL, *pp_pub = NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2724 | const struct dpp_curve_params *key_curve = NULL, *pp_curve = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2725 | const char *signed_connector; |
| 2726 | |
| 2727 | os_memset(&info, 0, sizeof(info)); |
| 2728 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2729 | if (dpp_akm_psk(conf->akm) || dpp_akm_sae(conf->akm)) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2730 | wpa_printf(MSG_DEBUG, |
| 2731 | "DPP: Legacy credential included in Connector credential"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2732 | if (dpp_parse_cred_legacy(conf, cred) < 0) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2733 | return -1; |
| 2734 | } |
| 2735 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2736 | wpa_printf(MSG_DEBUG, "DPP: Connector credential"); |
| 2737 | |
| 2738 | csign = json_get_member(cred, "csign"); |
| 2739 | if (!csign || csign->type != JSON_OBJECT) { |
| 2740 | wpa_printf(MSG_DEBUG, "DPP: No csign JWK in JSON"); |
| 2741 | goto fail; |
| 2742 | } |
| 2743 | |
| 2744 | csign_pub = dpp_parse_jwk(csign, &key_curve); |
| 2745 | if (!csign_pub) { |
| 2746 | wpa_printf(MSG_DEBUG, "DPP: Failed to parse csign JWK"); |
| 2747 | goto fail; |
| 2748 | } |
| 2749 | dpp_debug_print_key("DPP: Received C-sign-key", csign_pub); |
| 2750 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2751 | ppkey = json_get_member(cred, "ppKey"); |
| 2752 | if (ppkey && ppkey->type == JSON_OBJECT) { |
| 2753 | pp_pub = dpp_parse_jwk(ppkey, &pp_curve); |
| 2754 | if (!pp_pub) { |
| 2755 | wpa_printf(MSG_DEBUG, "DPP: Failed to parse ppKey JWK"); |
| 2756 | goto fail; |
| 2757 | } |
| 2758 | dpp_debug_print_key("DPP: Received ppKey", pp_pub); |
| 2759 | if (key_curve != pp_curve) { |
| 2760 | wpa_printf(MSG_DEBUG, |
| 2761 | "DPP: C-sign-key and ppKey do not use the same curve"); |
| 2762 | goto fail; |
| 2763 | } |
| 2764 | } |
| 2765 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2766 | token = json_get_member(cred, "signedConnector"); |
| 2767 | if (!token || token->type != JSON_STRING) { |
| 2768 | wpa_printf(MSG_DEBUG, "DPP: No signedConnector string found"); |
| 2769 | goto fail; |
| 2770 | } |
| 2771 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: signedConnector", |
| 2772 | token->string, os_strlen(token->string)); |
| 2773 | signed_connector = token->string; |
| 2774 | |
| 2775 | if (os_strchr(signed_connector, '"') || |
| 2776 | os_strchr(signed_connector, '\n')) { |
| 2777 | wpa_printf(MSG_DEBUG, |
| 2778 | "DPP: Unexpected character in signedConnector"); |
| 2779 | goto fail; |
| 2780 | } |
| 2781 | |
| 2782 | if (dpp_process_signed_connector(&info, csign_pub, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2783 | signed_connector) != DPP_STATUS_OK) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2784 | goto fail; |
| 2785 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2786 | if (dpp_parse_connector(auth, conf, |
| 2787 | info.payload, info.payload_len) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2788 | wpa_printf(MSG_DEBUG, "DPP: Failed to parse connector"); |
| 2789 | goto fail; |
| 2790 | } |
| 2791 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2792 | os_free(conf->connector); |
| 2793 | conf->connector = os_strdup(signed_connector); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2794 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2795 | dpp_copy_csign(conf, csign_pub); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2796 | if (pp_pub) |
| 2797 | dpp_copy_ppkey(conf, pp_pub); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2798 | if (dpp_akm_dpp(conf->akm) || auth->peer_version >= 2) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2799 | dpp_copy_netaccesskey(auth, conf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2800 | |
| 2801 | ret = 0; |
| 2802 | fail: |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2803 | crypto_ec_key_deinit(csign_pub); |
| 2804 | crypto_ec_key_deinit(pp_pub); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2805 | os_free(info.payload); |
| 2806 | return ret; |
| 2807 | } |
| 2808 | |
| 2809 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2810 | #ifdef CONFIG_DPP2 |
| 2811 | static int dpp_parse_cred_dot1x(struct dpp_authentication *auth, |
| 2812 | struct dpp_config_obj *conf, |
| 2813 | struct json_token *cred) |
| 2814 | { |
| 2815 | struct json_token *ent, *name; |
| 2816 | |
| 2817 | ent = json_get_member(cred, "entCreds"); |
| 2818 | if (!ent || ent->type != JSON_OBJECT) { |
| 2819 | dpp_auth_fail(auth, "No entCreds in JSON"); |
| 2820 | return -1; |
| 2821 | } |
| 2822 | |
| 2823 | conf->certbag = json_get_member_base64(ent, "certBag"); |
| 2824 | if (!conf->certbag) { |
| 2825 | dpp_auth_fail(auth, "No certBag in JSON"); |
| 2826 | return -1; |
| 2827 | } |
| 2828 | wpa_hexdump_buf(MSG_MSGDUMP, "DPP: Received certBag", conf->certbag); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2829 | conf->certs = crypto_pkcs7_get_certificates(conf->certbag); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2830 | if (!conf->certs) { |
| 2831 | dpp_auth_fail(auth, "No certificates in certBag"); |
| 2832 | return -1; |
| 2833 | } |
| 2834 | |
| 2835 | conf->cacert = json_get_member_base64(ent, "caCert"); |
| 2836 | if (conf->cacert) |
| 2837 | wpa_hexdump_buf(MSG_MSGDUMP, "DPP: Received caCert", |
| 2838 | conf->cacert); |
| 2839 | |
| 2840 | name = json_get_member(ent, "trustedEapServerName"); |
| 2841 | if (name && |
| 2842 | (name->type != JSON_STRING || |
| 2843 | has_ctrl_char((const u8 *) name->string, |
| 2844 | os_strlen(name->string)))) { |
| 2845 | dpp_auth_fail(auth, |
| 2846 | "Invalid trustedEapServerName type in JSON"); |
| 2847 | return -1; |
| 2848 | } |
| 2849 | if (name && name->string) { |
| 2850 | wpa_printf(MSG_DEBUG, "DPP: Received trustedEapServerName: %s", |
| 2851 | name->string); |
| 2852 | conf->server_name = os_strdup(name->string); |
| 2853 | if (!conf->server_name) |
| 2854 | return -1; |
| 2855 | } |
| 2856 | |
| 2857 | return 0; |
| 2858 | } |
| 2859 | #endif /* CONFIG_DPP2 */ |
| 2860 | |
| 2861 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2862 | const char * dpp_akm_str(enum dpp_akm akm) |
| 2863 | { |
| 2864 | switch (akm) { |
| 2865 | case DPP_AKM_DPP: |
| 2866 | return "dpp"; |
| 2867 | case DPP_AKM_PSK: |
| 2868 | return "psk"; |
| 2869 | case DPP_AKM_SAE: |
| 2870 | return "sae"; |
| 2871 | case DPP_AKM_PSK_SAE: |
| 2872 | return "psk+sae"; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2873 | case DPP_AKM_SAE_DPP: |
| 2874 | return "dpp+sae"; |
| 2875 | case DPP_AKM_PSK_SAE_DPP: |
| 2876 | return "dpp+psk+sae"; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2877 | case DPP_AKM_DOT1X: |
| 2878 | return "dot1x"; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2879 | default: |
| 2880 | return "??"; |
| 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2885 | const char * dpp_akm_selector_str(enum dpp_akm akm) |
| 2886 | { |
| 2887 | switch (akm) { |
| 2888 | case DPP_AKM_DPP: |
| 2889 | return "506F9A02"; |
| 2890 | case DPP_AKM_PSK: |
| 2891 | return "000FAC02+000FAC06"; |
| 2892 | case DPP_AKM_SAE: |
| 2893 | return "000FAC08"; |
| 2894 | case DPP_AKM_PSK_SAE: |
| 2895 | return "000FAC02+000FAC06+000FAC08"; |
| 2896 | case DPP_AKM_SAE_DPP: |
| 2897 | return "506F9A02+000FAC08"; |
| 2898 | case DPP_AKM_PSK_SAE_DPP: |
| 2899 | return "506F9A02+000FAC08+000FAC02+000FAC06"; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2900 | case DPP_AKM_DOT1X: |
| 2901 | return "000FAC01+000FAC05"; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2902 | default: |
| 2903 | return "??"; |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2908 | static enum dpp_akm dpp_akm_from_str(const char *akm) |
| 2909 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2910 | const char *pos; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2911 | int dpp = 0, psk = 0, sae = 0, dot1x = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2912 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2913 | if (os_strcmp(akm, "psk") == 0) |
| 2914 | return DPP_AKM_PSK; |
| 2915 | if (os_strcmp(akm, "sae") == 0) |
| 2916 | return DPP_AKM_SAE; |
| 2917 | if (os_strcmp(akm, "psk+sae") == 0) |
| 2918 | return DPP_AKM_PSK_SAE; |
| 2919 | if (os_strcmp(akm, "dpp") == 0) |
| 2920 | return DPP_AKM_DPP; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2921 | if (os_strcmp(akm, "dpp+sae") == 0) |
| 2922 | return DPP_AKM_SAE_DPP; |
| 2923 | if (os_strcmp(akm, "dpp+psk+sae") == 0) |
| 2924 | return DPP_AKM_PSK_SAE_DPP; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2925 | if (os_strcmp(akm, "dot1x") == 0) |
| 2926 | return DPP_AKM_DOT1X; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2927 | |
| 2928 | pos = akm; |
| 2929 | while (*pos) { |
| 2930 | if (os_strlen(pos) < 8) |
| 2931 | break; |
| 2932 | if (os_strncasecmp(pos, "506F9A02", 8) == 0) |
| 2933 | dpp = 1; |
| 2934 | else if (os_strncasecmp(pos, "000FAC02", 8) == 0) |
| 2935 | psk = 1; |
| 2936 | else if (os_strncasecmp(pos, "000FAC06", 8) == 0) |
| 2937 | psk = 1; |
| 2938 | else if (os_strncasecmp(pos, "000FAC08", 8) == 0) |
| 2939 | sae = 1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2940 | else if (os_strncasecmp(pos, "000FAC01", 8) == 0) |
| 2941 | dot1x = 1; |
| 2942 | else if (os_strncasecmp(pos, "000FAC05", 8) == 0) |
| 2943 | dot1x = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2944 | pos += 8; |
| 2945 | if (*pos != '+') |
| 2946 | break; |
| 2947 | pos++; |
| 2948 | } |
| 2949 | |
| 2950 | if (dpp && psk && sae) |
| 2951 | return DPP_AKM_PSK_SAE_DPP; |
| 2952 | if (dpp && sae) |
| 2953 | return DPP_AKM_SAE_DPP; |
| 2954 | if (dpp) |
| 2955 | return DPP_AKM_DPP; |
| 2956 | if (psk && sae) |
| 2957 | return DPP_AKM_PSK_SAE; |
| 2958 | if (sae) |
| 2959 | return DPP_AKM_SAE; |
| 2960 | if (psk) |
| 2961 | return DPP_AKM_PSK; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2962 | if (dot1x) |
| 2963 | return DPP_AKM_DOT1X; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2964 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2965 | return DPP_AKM_UNKNOWN; |
| 2966 | } |
| 2967 | |
| 2968 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2969 | static int dpp_parse_conf_obj(struct dpp_authentication *auth, |
| 2970 | const u8 *conf_obj, u16 conf_obj_len) |
| 2971 | { |
| 2972 | int ret = -1; |
| 2973 | struct json_token *root, *token, *discovery, *cred; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2974 | struct dpp_config_obj *conf; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2975 | struct wpabuf *ssid64 = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2976 | int legacy; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2977 | |
| 2978 | root = json_parse((const char *) conf_obj, conf_obj_len); |
| 2979 | if (!root) |
| 2980 | return -1; |
| 2981 | if (root->type != JSON_OBJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2982 | dpp_auth_fail(auth, "JSON root is not an object"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2983 | goto fail; |
| 2984 | } |
| 2985 | |
| 2986 | token = json_get_member(root, "wi-fi_tech"); |
| 2987 | if (!token || token->type != JSON_STRING) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2988 | dpp_auth_fail(auth, "No wi-fi_tech string value found"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2989 | goto fail; |
| 2990 | } |
| 2991 | if (os_strcmp(token->string, "infra") != 0) { |
| 2992 | wpa_printf(MSG_DEBUG, "DPP: Unsupported wi-fi_tech value: '%s'", |
| 2993 | token->string); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2994 | dpp_auth_fail(auth, "Unsupported wi-fi_tech value"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2995 | goto fail; |
| 2996 | } |
| 2997 | |
| 2998 | discovery = json_get_member(root, "discovery"); |
| 2999 | if (!discovery || discovery->type != JSON_OBJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3000 | dpp_auth_fail(auth, "No discovery object in JSON"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3001 | goto fail; |
| 3002 | } |
| 3003 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3004 | ssid64 = json_get_member_base64url(discovery, "ssid64"); |
| 3005 | if (ssid64) { |
| 3006 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: discovery::ssid64", |
| 3007 | wpabuf_head(ssid64), wpabuf_len(ssid64)); |
| 3008 | if (wpabuf_len(ssid64) > SSID_MAX_LEN) { |
| 3009 | dpp_auth_fail(auth, "Too long discovery::ssid64 value"); |
| 3010 | goto fail; |
| 3011 | } |
| 3012 | } else { |
| 3013 | token = json_get_member(discovery, "ssid"); |
| 3014 | if (!token || token->type != JSON_STRING) { |
| 3015 | dpp_auth_fail(auth, |
| 3016 | "No discovery::ssid string value found"); |
| 3017 | goto fail; |
| 3018 | } |
| 3019 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: discovery::ssid", |
| 3020 | token->string, os_strlen(token->string)); |
| 3021 | if (os_strlen(token->string) > SSID_MAX_LEN) { |
| 3022 | dpp_auth_fail(auth, |
| 3023 | "Too long discovery::ssid string value"); |
| 3024 | goto fail; |
| 3025 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3026 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3027 | |
| 3028 | if (auth->num_conf_obj == DPP_MAX_CONF_OBJ) { |
| 3029 | wpa_printf(MSG_DEBUG, |
| 3030 | "DPP: No room for this many Config Objects - ignore this one"); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3031 | ret = 0; |
| 3032 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3033 | } |
| 3034 | conf = &auth->conf_obj[auth->num_conf_obj++]; |
| 3035 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3036 | if (ssid64) { |
| 3037 | conf->ssid_len = wpabuf_len(ssid64); |
| 3038 | os_memcpy(conf->ssid, wpabuf_head(ssid64), conf->ssid_len); |
| 3039 | } else { |
| 3040 | conf->ssid_len = os_strlen(token->string); |
| 3041 | os_memcpy(conf->ssid, token->string, conf->ssid_len); |
| 3042 | } |
| 3043 | |
| 3044 | token = json_get_member(discovery, "ssid_charset"); |
| 3045 | if (token && token->type == JSON_NUMBER) { |
| 3046 | conf->ssid_charset = token->number; |
| 3047 | wpa_printf(MSG_DEBUG, "DPP: ssid_charset=%d", |
| 3048 | conf->ssid_charset); |
| 3049 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3050 | |
| 3051 | cred = json_get_member(root, "cred"); |
| 3052 | if (!cred || cred->type != JSON_OBJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3053 | dpp_auth_fail(auth, "No cred object in JSON"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3054 | goto fail; |
| 3055 | } |
| 3056 | |
| 3057 | token = json_get_member(cred, "akm"); |
| 3058 | if (!token || token->type != JSON_STRING) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3059 | dpp_auth_fail(auth, "No cred::akm string value found"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3060 | goto fail; |
| 3061 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3062 | conf->akm = dpp_akm_from_str(token->string); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3063 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3064 | legacy = dpp_akm_legacy(conf->akm); |
| 3065 | if (legacy && auth->peer_version >= 2) { |
| 3066 | struct json_token *csign, *s_conn; |
| 3067 | |
| 3068 | csign = json_get_member(cred, "csign"); |
| 3069 | s_conn = json_get_member(cred, "signedConnector"); |
| 3070 | if (csign && csign->type == JSON_OBJECT && |
| 3071 | s_conn && s_conn->type == JSON_STRING) |
| 3072 | legacy = 0; |
| 3073 | } |
| 3074 | if (legacy) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3075 | if (dpp_parse_cred_legacy(conf, cred) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3076 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3077 | } else if (dpp_akm_dpp(conf->akm) || |
| 3078 | (auth->peer_version >= 2 && dpp_akm_legacy(conf->akm))) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3079 | if (dpp_parse_cred_dpp(auth, conf, cred) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3080 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3081 | #ifdef CONFIG_DPP2 |
| 3082 | } else if (conf->akm == DPP_AKM_DOT1X) { |
| 3083 | if (dpp_parse_cred_dot1x(auth, conf, cred) < 0 || |
| 3084 | dpp_parse_cred_dpp(auth, conf, cred) < 0) |
| 3085 | goto fail; |
| 3086 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3087 | } else { |
| 3088 | wpa_printf(MSG_DEBUG, "DPP: Unsupported akm: %s", |
| 3089 | token->string); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3090 | dpp_auth_fail(auth, "Unsupported akm"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3091 | goto fail; |
| 3092 | } |
| 3093 | |
| 3094 | wpa_printf(MSG_DEBUG, "DPP: JSON parsing completed successfully"); |
| 3095 | ret = 0; |
| 3096 | fail: |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3097 | wpabuf_free(ssid64); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3098 | json_free(root); |
| 3099 | return ret; |
| 3100 | } |
| 3101 | |
| 3102 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3103 | #ifdef CONFIG_DPP2 |
| 3104 | static u8 * dpp_get_csr_attrs(const u8 *attrs, size_t attrs_len, size_t *len) |
| 3105 | { |
| 3106 | const u8 *b64; |
| 3107 | u16 b64_len; |
| 3108 | |
| 3109 | b64 = dpp_get_attr(attrs, attrs_len, DPP_ATTR_CSR_ATTR_REQ, &b64_len); |
| 3110 | if (!b64) |
| 3111 | return NULL; |
| 3112 | return base64_decode((const char *) b64, b64_len, len); |
| 3113 | } |
| 3114 | #endif /* CONFIG_DPP2 */ |
| 3115 | |
| 3116 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3117 | int dpp_conf_resp_rx(struct dpp_authentication *auth, |
| 3118 | const struct wpabuf *resp) |
| 3119 | { |
| 3120 | const u8 *wrapped_data, *e_nonce, *status, *conf_obj; |
| 3121 | u16 wrapped_data_len, e_nonce_len, status_len, conf_obj_len; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3122 | const u8 *env_data; |
| 3123 | u16 env_data_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3124 | const u8 *addr[1]; |
| 3125 | size_t len[1]; |
| 3126 | u8 *unwrapped = NULL; |
| 3127 | size_t unwrapped_len = 0; |
| 3128 | int ret = -1; |
| 3129 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3130 | auth->conf_resp_status = 255; |
| 3131 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3132 | if (dpp_check_attrs(wpabuf_head(resp), wpabuf_len(resp)) < 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3133 | dpp_auth_fail(auth, "Invalid attribute in config response"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3134 | return -1; |
| 3135 | } |
| 3136 | |
| 3137 | wrapped_data = dpp_get_attr(wpabuf_head(resp), wpabuf_len(resp), |
| 3138 | DPP_ATTR_WRAPPED_DATA, |
| 3139 | &wrapped_data_len); |
| 3140 | if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3141 | dpp_auth_fail(auth, |
| 3142 | "Missing or invalid required Wrapped Data attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3143 | return -1; |
| 3144 | } |
| 3145 | |
| 3146 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext", |
| 3147 | wrapped_data, wrapped_data_len); |
| 3148 | unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE; |
| 3149 | unwrapped = os_malloc(unwrapped_len); |
| 3150 | if (!unwrapped) |
| 3151 | return -1; |
| 3152 | |
| 3153 | addr[0] = wpabuf_head(resp); |
| 3154 | len[0] = wrapped_data - 4 - (const u8 *) wpabuf_head(resp); |
| 3155 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD", addr[0], len[0]); |
| 3156 | |
| 3157 | if (aes_siv_decrypt(auth->ke, auth->curve->hash_len, |
| 3158 | wrapped_data, wrapped_data_len, |
| 3159 | 1, addr, len, unwrapped) < 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3160 | dpp_auth_fail(auth, "AES-SIV decryption failed"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3161 | goto fail; |
| 3162 | } |
| 3163 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext", |
| 3164 | unwrapped, unwrapped_len); |
| 3165 | |
| 3166 | if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3167 | dpp_auth_fail(auth, "Invalid attribute in unwrapped data"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3168 | goto fail; |
| 3169 | } |
| 3170 | |
| 3171 | e_nonce = dpp_get_attr(unwrapped, unwrapped_len, |
| 3172 | DPP_ATTR_ENROLLEE_NONCE, |
| 3173 | &e_nonce_len); |
| 3174 | if (!e_nonce || e_nonce_len != auth->curve->nonce_len) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3175 | dpp_auth_fail(auth, |
| 3176 | "Missing or invalid Enrollee Nonce attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3177 | goto fail; |
| 3178 | } |
| 3179 | wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len); |
| 3180 | if (os_memcmp(e_nonce, auth->e_nonce, e_nonce_len) != 0) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3181 | dpp_auth_fail(auth, "Enrollee Nonce mismatch"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3182 | goto fail; |
| 3183 | } |
| 3184 | |
| 3185 | status = dpp_get_attr(wpabuf_head(resp), wpabuf_len(resp), |
| 3186 | DPP_ATTR_STATUS, &status_len); |
| 3187 | if (!status || status_len < 1) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3188 | dpp_auth_fail(auth, |
| 3189 | "Missing or invalid required DPP Status attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3190 | goto fail; |
| 3191 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3192 | auth->conf_resp_status = status[0]; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3193 | wpa_printf(MSG_DEBUG, "DPP: Status %u", status[0]); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3194 | #ifdef CONFIG_DPP2 |
| 3195 | if (status[0] == DPP_STATUS_CSR_NEEDED) { |
| 3196 | u8 *csrattrs; |
| 3197 | size_t csrattrs_len; |
| 3198 | |
| 3199 | wpa_printf(MSG_DEBUG, "DPP: Configurator requested CSR"); |
| 3200 | |
| 3201 | csrattrs = dpp_get_csr_attrs(unwrapped, unwrapped_len, |
| 3202 | &csrattrs_len); |
| 3203 | if (!csrattrs) { |
| 3204 | dpp_auth_fail(auth, |
| 3205 | "Missing or invalid CSR Attributes Request attribute"); |
| 3206 | goto fail; |
| 3207 | } |
| 3208 | wpa_hexdump(MSG_DEBUG, "DPP: CsrAttrs", csrattrs, csrattrs_len); |
| 3209 | os_free(auth->csrattrs); |
| 3210 | auth->csrattrs = csrattrs; |
| 3211 | auth->csrattrs_len = csrattrs_len; |
| 3212 | ret = -2; |
| 3213 | goto fail; |
| 3214 | } |
| 3215 | #endif /* CONFIG_DPP2 */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 3216 | #ifdef CONFIG_DPP3 |
| 3217 | if (status[0] == DPP_STATUS_NEW_KEY_NEEDED) { |
| 3218 | const u8 *fcgroup, *r_proto; |
| 3219 | u16 fcgroup_len, r_proto_len; |
| 3220 | u16 group; |
| 3221 | const struct dpp_curve_params *curve; |
| 3222 | struct crypto_ec_key *new_pe; |
| 3223 | struct crypto_ec_key *pc; |
| 3224 | |
| 3225 | fcgroup = dpp_get_attr(unwrapped, unwrapped_len, |
| 3226 | DPP_ATTR_FINITE_CYCLIC_GROUP, |
| 3227 | &fcgroup_len); |
| 3228 | if (!fcgroup || fcgroup_len != 2) { |
| 3229 | dpp_auth_fail(auth, |
| 3230 | "Missing or invalid required Finite Cyclic Group attribute"); |
| 3231 | goto fail; |
| 3232 | } |
| 3233 | group = WPA_GET_LE16(fcgroup); |
| 3234 | |
| 3235 | wpa_printf(MSG_DEBUG, |
| 3236 | "DPP: Configurator requested a new protocol key from group %u", |
| 3237 | group); |
| 3238 | curve = dpp_get_curve_ike_group(group); |
| 3239 | if (!curve) { |
| 3240 | dpp_auth_fail(auth, |
| 3241 | "Unsupported group for new protocol key"); |
| 3242 | goto fail; |
| 3243 | } |
| 3244 | |
| 3245 | new_pe = dpp_gen_keypair(curve); |
| 3246 | if (!new_pe) { |
| 3247 | dpp_auth_fail(auth, |
| 3248 | "Failed to generate a new protocol key"); |
| 3249 | goto fail; |
| 3250 | } |
| 3251 | |
| 3252 | crypto_ec_key_deinit(auth->own_protocol_key); |
| 3253 | auth->own_protocol_key = new_pe; |
| 3254 | auth->new_curve = curve; |
| 3255 | |
| 3256 | r_proto = dpp_get_attr(unwrapped, unwrapped_len, |
| 3257 | DPP_ATTR_R_PROTOCOL_KEY, |
| 3258 | &r_proto_len); |
| 3259 | if (!r_proto) { |
| 3260 | dpp_auth_fail(auth, |
| 3261 | "Missing required Responder Protocol Key attribute (Pc)"); |
| 3262 | goto fail; |
| 3263 | } |
| 3264 | wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Protocol Key (new Pc)", |
| 3265 | r_proto, r_proto_len); |
| 3266 | |
| 3267 | pc = dpp_set_pubkey_point(new_pe, r_proto, r_proto_len); |
| 3268 | if (!pc) { |
| 3269 | dpp_auth_fail(auth, "Invalid Responder Protocol Key (Pc)"); |
| 3270 | goto fail; |
| 3271 | } |
| 3272 | dpp_debug_print_key("New Peer Protocol Key (Pc)", pc); |
| 3273 | |
| 3274 | crypto_ec_key_deinit(auth->peer_protocol_key); |
| 3275 | auth->peer_protocol_key = pc; |
| 3276 | |
| 3277 | auth->waiting_new_key = true; |
| 3278 | ret = -3; |
| 3279 | goto fail; |
| 3280 | } |
| 3281 | #endif /* CONFIG_DPP3 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3282 | if (status[0] != DPP_STATUS_OK) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3283 | dpp_auth_fail(auth, "Configurator rejected configuration"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3284 | goto fail; |
| 3285 | } |
| 3286 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3287 | env_data = dpp_get_attr(unwrapped, unwrapped_len, |
| 3288 | DPP_ATTR_ENVELOPED_DATA, &env_data_len); |
| 3289 | #ifdef CONFIG_DPP2 |
| 3290 | if (env_data && |
| 3291 | dpp_conf_resp_env_data(auth, env_data, env_data_len) < 0) |
| 3292 | goto fail; |
| 3293 | #endif /* CONFIG_DPP2 */ |
| 3294 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3295 | conf_obj = dpp_get_attr(unwrapped, unwrapped_len, DPP_ATTR_CONFIG_OBJ, |
| 3296 | &conf_obj_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3297 | if (!conf_obj && !env_data) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3298 | dpp_auth_fail(auth, |
| 3299 | "Missing required Configuration Object attribute"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3300 | goto fail; |
| 3301 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3302 | while (conf_obj) { |
| 3303 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: configurationObject JSON", |
| 3304 | conf_obj, conf_obj_len); |
| 3305 | if (dpp_parse_conf_obj(auth, conf_obj, conf_obj_len) < 0) |
| 3306 | goto fail; |
| 3307 | conf_obj = dpp_get_attr_next(conf_obj, unwrapped, unwrapped_len, |
| 3308 | DPP_ATTR_CONFIG_OBJ, |
| 3309 | &conf_obj_len); |
| 3310 | } |
| 3311 | |
| 3312 | #ifdef CONFIG_DPP2 |
| 3313 | status = dpp_get_attr(unwrapped, unwrapped_len, |
| 3314 | DPP_ATTR_SEND_CONN_STATUS, &status_len); |
| 3315 | if (status) { |
| 3316 | wpa_printf(MSG_DEBUG, |
| 3317 | "DPP: Configurator requested connection status result"); |
| 3318 | auth->conn_status_requested = 1; |
| 3319 | } |
| 3320 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3321 | |
| 3322 | ret = 0; |
| 3323 | |
| 3324 | fail: |
| 3325 | os_free(unwrapped); |
| 3326 | return ret; |
| 3327 | } |
| 3328 | |
| 3329 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3330 | #ifdef CONFIG_DPP2 |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3331 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3332 | enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth, |
| 3333 | const u8 *hdr, |
| 3334 | const u8 *attr_start, size_t attr_len) |
| 3335 | { |
| 3336 | const u8 *wrapped_data, *status, *e_nonce; |
| 3337 | u16 wrapped_data_len, status_len, e_nonce_len; |
| 3338 | const u8 *addr[2]; |
| 3339 | size_t len[2]; |
| 3340 | u8 *unwrapped = NULL; |
| 3341 | size_t unwrapped_len = 0; |
| 3342 | enum dpp_status_error ret = 256; |
| 3343 | |
| 3344 | wrapped_data = dpp_get_attr(attr_start, attr_len, DPP_ATTR_WRAPPED_DATA, |
| 3345 | &wrapped_data_len); |
| 3346 | if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) { |
| 3347 | dpp_auth_fail(auth, |
| 3348 | "Missing or invalid required Wrapped Data attribute"); |
| 3349 | goto fail; |
| 3350 | } |
| 3351 | wpa_hexdump(MSG_DEBUG, "DPP: Wrapped data", |
| 3352 | wrapped_data, wrapped_data_len); |
| 3353 | |
| 3354 | attr_len = wrapped_data - 4 - attr_start; |
| 3355 | |
| 3356 | addr[0] = hdr; |
| 3357 | len[0] = DPP_HDR_LEN; |
| 3358 | addr[1] = attr_start; |
| 3359 | len[1] = attr_len; |
| 3360 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]); |
| 3361 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]); |
| 3362 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext", |
| 3363 | wrapped_data, wrapped_data_len); |
| 3364 | unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE; |
| 3365 | unwrapped = os_malloc(unwrapped_len); |
| 3366 | if (!unwrapped) |
| 3367 | goto fail; |
| 3368 | if (aes_siv_decrypt(auth->ke, auth->curve->hash_len, |
| 3369 | wrapped_data, wrapped_data_len, |
| 3370 | 2, addr, len, unwrapped) < 0) { |
| 3371 | dpp_auth_fail(auth, "AES-SIV decryption failed"); |
| 3372 | goto fail; |
| 3373 | } |
| 3374 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext", |
| 3375 | unwrapped, unwrapped_len); |
| 3376 | |
| 3377 | if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) { |
| 3378 | dpp_auth_fail(auth, "Invalid attribute in unwrapped data"); |
| 3379 | goto fail; |
| 3380 | } |
| 3381 | |
| 3382 | e_nonce = dpp_get_attr(unwrapped, unwrapped_len, |
| 3383 | DPP_ATTR_ENROLLEE_NONCE, |
| 3384 | &e_nonce_len); |
| 3385 | if (!e_nonce || e_nonce_len != auth->curve->nonce_len) { |
| 3386 | dpp_auth_fail(auth, |
| 3387 | "Missing or invalid Enrollee Nonce attribute"); |
| 3388 | goto fail; |
| 3389 | } |
| 3390 | wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len); |
| 3391 | if (os_memcmp(e_nonce, auth->e_nonce, e_nonce_len) != 0) { |
| 3392 | dpp_auth_fail(auth, "Enrollee Nonce mismatch"); |
| 3393 | wpa_hexdump(MSG_DEBUG, "DPP: Expected Enrollee Nonce", |
| 3394 | auth->e_nonce, e_nonce_len); |
| 3395 | goto fail; |
| 3396 | } |
| 3397 | |
| 3398 | status = dpp_get_attr(unwrapped, unwrapped_len, DPP_ATTR_STATUS, |
| 3399 | &status_len); |
| 3400 | if (!status || status_len < 1) { |
| 3401 | dpp_auth_fail(auth, |
| 3402 | "Missing or invalid required DPP Status attribute"); |
| 3403 | goto fail; |
| 3404 | } |
| 3405 | wpa_printf(MSG_DEBUG, "DPP: Status %u", status[0]); |
| 3406 | ret = status[0]; |
| 3407 | |
| 3408 | fail: |
| 3409 | bin_clear_free(unwrapped, unwrapped_len); |
| 3410 | return ret; |
| 3411 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3412 | |
| 3413 | |
| 3414 | struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth, |
| 3415 | enum dpp_status_error status) |
| 3416 | { |
| 3417 | struct wpabuf *msg, *clear; |
| 3418 | size_t nonce_len, clear_len, attr_len; |
| 3419 | const u8 *addr[2]; |
| 3420 | size_t len[2]; |
| 3421 | u8 *wrapped; |
| 3422 | |
| 3423 | nonce_len = auth->curve->nonce_len; |
| 3424 | clear_len = 5 + 4 + nonce_len; |
| 3425 | attr_len = 4 + clear_len + AES_BLOCK_SIZE; |
| 3426 | clear = wpabuf_alloc(clear_len); |
| 3427 | msg = dpp_alloc_msg(DPP_PA_CONFIGURATION_RESULT, attr_len); |
| 3428 | if (!clear || !msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3429 | goto fail; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3430 | |
| 3431 | /* DPP Status */ |
| 3432 | dpp_build_attr_status(clear, status); |
| 3433 | |
| 3434 | /* E-nonce */ |
| 3435 | wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE); |
| 3436 | wpabuf_put_le16(clear, nonce_len); |
| 3437 | wpabuf_put_data(clear, auth->e_nonce, nonce_len); |
| 3438 | |
| 3439 | /* OUI, OUI type, Crypto Suite, DPP frame type */ |
| 3440 | addr[0] = wpabuf_head_u8(msg) + 2; |
| 3441 | len[0] = 3 + 1 + 1 + 1; |
| 3442 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]); |
| 3443 | |
| 3444 | /* Attributes before Wrapped Data (none) */ |
| 3445 | addr[1] = wpabuf_put(msg, 0); |
| 3446 | len[1] = 0; |
| 3447 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]); |
| 3448 | |
| 3449 | /* Wrapped Data */ |
| 3450 | wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA); |
| 3451 | wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 3452 | wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 3453 | |
| 3454 | wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear); |
| 3455 | if (aes_siv_encrypt(auth->ke, auth->curve->hash_len, |
| 3456 | wpabuf_head(clear), wpabuf_len(clear), |
| 3457 | 2, addr, len, wrapped) < 0) |
| 3458 | goto fail; |
| 3459 | |
| 3460 | wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Result attributes", msg); |
| 3461 | wpabuf_free(clear); |
| 3462 | return msg; |
| 3463 | fail: |
| 3464 | wpabuf_free(clear); |
| 3465 | wpabuf_free(msg); |
| 3466 | return NULL; |
| 3467 | } |
| 3468 | |
| 3469 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3470 | static int valid_channel_list(const char *val) |
| 3471 | { |
| 3472 | while (*val) { |
| 3473 | if (!((*val >= '0' && *val <= '9') || |
| 3474 | *val == '/' || *val == ',')) |
| 3475 | return 0; |
| 3476 | val++; |
| 3477 | } |
| 3478 | |
| 3479 | return 1; |
| 3480 | } |
| 3481 | |
| 3482 | |
| 3483 | enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth, |
| 3484 | const u8 *hdr, |
| 3485 | const u8 *attr_start, |
| 3486 | size_t attr_len, |
| 3487 | u8 *ssid, size_t *ssid_len, |
| 3488 | char **channel_list) |
| 3489 | { |
| 3490 | const u8 *wrapped_data, *status, *e_nonce; |
| 3491 | u16 wrapped_data_len, status_len, e_nonce_len; |
| 3492 | const u8 *addr[2]; |
| 3493 | size_t len[2]; |
| 3494 | u8 *unwrapped = NULL; |
| 3495 | size_t unwrapped_len = 0; |
| 3496 | enum dpp_status_error ret = 256; |
| 3497 | struct json_token *root = NULL, *token; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3498 | struct wpabuf *ssid64; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3499 | |
| 3500 | *ssid_len = 0; |
| 3501 | *channel_list = NULL; |
| 3502 | |
| 3503 | wrapped_data = dpp_get_attr(attr_start, attr_len, DPP_ATTR_WRAPPED_DATA, |
| 3504 | &wrapped_data_len); |
| 3505 | if (!wrapped_data || wrapped_data_len < AES_BLOCK_SIZE) { |
| 3506 | dpp_auth_fail(auth, |
| 3507 | "Missing or invalid required Wrapped Data attribute"); |
| 3508 | goto fail; |
| 3509 | } |
| 3510 | wpa_hexdump(MSG_DEBUG, "DPP: Wrapped data", |
| 3511 | wrapped_data, wrapped_data_len); |
| 3512 | |
| 3513 | attr_len = wrapped_data - 4 - attr_start; |
| 3514 | |
| 3515 | addr[0] = hdr; |
| 3516 | len[0] = DPP_HDR_LEN; |
| 3517 | addr[1] = attr_start; |
| 3518 | len[1] = attr_len; |
| 3519 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]); |
| 3520 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]); |
| 3521 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV ciphertext", |
| 3522 | wrapped_data, wrapped_data_len); |
| 3523 | unwrapped_len = wrapped_data_len - AES_BLOCK_SIZE; |
| 3524 | unwrapped = os_malloc(unwrapped_len); |
| 3525 | if (!unwrapped) |
| 3526 | goto fail; |
| 3527 | if (aes_siv_decrypt(auth->ke, auth->curve->hash_len, |
| 3528 | wrapped_data, wrapped_data_len, |
| 3529 | 2, addr, len, unwrapped) < 0) { |
| 3530 | dpp_auth_fail(auth, "AES-SIV decryption failed"); |
| 3531 | goto fail; |
| 3532 | } |
| 3533 | wpa_hexdump(MSG_DEBUG, "DPP: AES-SIV cleartext", |
| 3534 | unwrapped, unwrapped_len); |
| 3535 | |
| 3536 | if (dpp_check_attrs(unwrapped, unwrapped_len) < 0) { |
| 3537 | dpp_auth_fail(auth, "Invalid attribute in unwrapped data"); |
| 3538 | goto fail; |
| 3539 | } |
| 3540 | |
| 3541 | e_nonce = dpp_get_attr(unwrapped, unwrapped_len, |
| 3542 | DPP_ATTR_ENROLLEE_NONCE, |
| 3543 | &e_nonce_len); |
| 3544 | if (!e_nonce || e_nonce_len != auth->curve->nonce_len) { |
| 3545 | dpp_auth_fail(auth, |
| 3546 | "Missing or invalid Enrollee Nonce attribute"); |
| 3547 | goto fail; |
| 3548 | } |
| 3549 | wpa_hexdump(MSG_DEBUG, "DPP: Enrollee Nonce", e_nonce, e_nonce_len); |
| 3550 | if (os_memcmp(e_nonce, auth->e_nonce, e_nonce_len) != 0) { |
| 3551 | dpp_auth_fail(auth, "Enrollee Nonce mismatch"); |
| 3552 | wpa_hexdump(MSG_DEBUG, "DPP: Expected Enrollee Nonce", |
| 3553 | auth->e_nonce, e_nonce_len); |
| 3554 | goto fail; |
| 3555 | } |
| 3556 | |
| 3557 | status = dpp_get_attr(unwrapped, unwrapped_len, DPP_ATTR_CONN_STATUS, |
| 3558 | &status_len); |
| 3559 | if (!status) { |
| 3560 | dpp_auth_fail(auth, |
| 3561 | "Missing required DPP Connection Status attribute"); |
| 3562 | goto fail; |
| 3563 | } |
| 3564 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: connStatus JSON", |
| 3565 | status, status_len); |
| 3566 | |
| 3567 | root = json_parse((const char *) status, status_len); |
| 3568 | if (!root) { |
| 3569 | dpp_auth_fail(auth, "Could not parse connStatus"); |
| 3570 | goto fail; |
| 3571 | } |
| 3572 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3573 | ssid64 = json_get_member_base64url(root, "ssid64"); |
| 3574 | if (ssid64 && wpabuf_len(ssid64) <= SSID_MAX_LEN) { |
| 3575 | *ssid_len = wpabuf_len(ssid64); |
| 3576 | os_memcpy(ssid, wpabuf_head(ssid64), *ssid_len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3577 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3578 | wpabuf_free(ssid64); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3579 | |
| 3580 | token = json_get_member(root, "channelList"); |
| 3581 | if (token && token->type == JSON_STRING && |
| 3582 | valid_channel_list(token->string)) |
| 3583 | *channel_list = os_strdup(token->string); |
| 3584 | |
| 3585 | token = json_get_member(root, "result"); |
| 3586 | if (!token || token->type != JSON_NUMBER) { |
| 3587 | dpp_auth_fail(auth, "No connStatus - result"); |
| 3588 | goto fail; |
| 3589 | } |
| 3590 | wpa_printf(MSG_DEBUG, "DPP: result %d", token->number); |
| 3591 | ret = token->number; |
| 3592 | |
| 3593 | fail: |
| 3594 | json_free(root); |
| 3595 | bin_clear_free(unwrapped, unwrapped_len); |
| 3596 | return ret; |
| 3597 | } |
| 3598 | |
| 3599 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3600 | struct wpabuf * dpp_build_conn_status(enum dpp_status_error result, |
| 3601 | const u8 *ssid, size_t ssid_len, |
| 3602 | const char *channel_list) |
| 3603 | { |
| 3604 | struct wpabuf *json; |
| 3605 | |
| 3606 | json = wpabuf_alloc(1000); |
| 3607 | if (!json) |
| 3608 | return NULL; |
| 3609 | json_start_object(json, NULL); |
| 3610 | json_add_int(json, "result", result); |
| 3611 | if (ssid) { |
| 3612 | json_value_sep(json); |
| 3613 | if (json_add_base64url(json, "ssid64", ssid, ssid_len) < 0) { |
| 3614 | wpabuf_free(json); |
| 3615 | return NULL; |
| 3616 | } |
| 3617 | } |
| 3618 | if (channel_list) { |
| 3619 | json_value_sep(json); |
| 3620 | json_add_string(json, "channelList", channel_list); |
| 3621 | } |
| 3622 | json_end_object(json); |
| 3623 | wpa_hexdump_ascii(MSG_DEBUG, "DPP: connStatus JSON", |
| 3624 | wpabuf_head(json), wpabuf_len(json)); |
| 3625 | |
| 3626 | return json; |
| 3627 | } |
| 3628 | |
| 3629 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3630 | struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth, |
| 3631 | enum dpp_status_error result, |
| 3632 | const u8 *ssid, size_t ssid_len, |
| 3633 | const char *channel_list) |
| 3634 | { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3635 | struct wpabuf *msg = NULL, *clear = NULL, *json; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3636 | size_t nonce_len, clear_len, attr_len; |
| 3637 | const u8 *addr[2]; |
| 3638 | size_t len[2]; |
| 3639 | u8 *wrapped; |
| 3640 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3641 | json = dpp_build_conn_status(result, ssid, ssid_len, channel_list); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3642 | if (!json) |
| 3643 | return NULL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3644 | |
| 3645 | nonce_len = auth->curve->nonce_len; |
| 3646 | clear_len = 5 + 4 + nonce_len + 4 + wpabuf_len(json); |
| 3647 | attr_len = 4 + clear_len + AES_BLOCK_SIZE; |
| 3648 | clear = wpabuf_alloc(clear_len); |
| 3649 | msg = dpp_alloc_msg(DPP_PA_CONNECTION_STATUS_RESULT, attr_len); |
| 3650 | if (!clear || !msg) |
| 3651 | goto fail; |
| 3652 | |
| 3653 | /* E-nonce */ |
| 3654 | wpabuf_put_le16(clear, DPP_ATTR_ENROLLEE_NONCE); |
| 3655 | wpabuf_put_le16(clear, nonce_len); |
| 3656 | wpabuf_put_data(clear, auth->e_nonce, nonce_len); |
| 3657 | |
| 3658 | /* DPP Connection Status */ |
| 3659 | wpabuf_put_le16(clear, DPP_ATTR_CONN_STATUS); |
| 3660 | wpabuf_put_le16(clear, wpabuf_len(json)); |
| 3661 | wpabuf_put_buf(clear, json); |
| 3662 | |
| 3663 | /* OUI, OUI type, Crypto Suite, DPP frame type */ |
| 3664 | addr[0] = wpabuf_head_u8(msg) + 2; |
| 3665 | len[0] = 3 + 1 + 1 + 1; |
| 3666 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[0]", addr[0], len[0]); |
| 3667 | |
| 3668 | /* Attributes before Wrapped Data (none) */ |
| 3669 | addr[1] = wpabuf_put(msg, 0); |
| 3670 | len[1] = 0; |
| 3671 | wpa_hexdump(MSG_DEBUG, "DDP: AES-SIV AD[1]", addr[1], len[1]); |
| 3672 | |
| 3673 | /* Wrapped Data */ |
| 3674 | wpabuf_put_le16(msg, DPP_ATTR_WRAPPED_DATA); |
| 3675 | wpabuf_put_le16(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 3676 | wrapped = wpabuf_put(msg, wpabuf_len(clear) + AES_BLOCK_SIZE); |
| 3677 | |
| 3678 | wpa_hexdump_buf(MSG_DEBUG, "DPP: AES-SIV cleartext", clear); |
| 3679 | if (aes_siv_encrypt(auth->ke, auth->curve->hash_len, |
| 3680 | wpabuf_head(clear), wpabuf_len(clear), |
| 3681 | 2, addr, len, wrapped) < 0) |
| 3682 | goto fail; |
| 3683 | |
| 3684 | wpa_hexdump_buf(MSG_DEBUG, "DPP: Connection Status Result attributes", |
| 3685 | msg); |
| 3686 | wpabuf_free(json); |
| 3687 | wpabuf_free(clear); |
| 3688 | return msg; |
| 3689 | fail: |
| 3690 | wpabuf_free(json); |
| 3691 | wpabuf_free(clear); |
| 3692 | wpabuf_free(msg); |
| 3693 | return NULL; |
| 3694 | } |
| 3695 | |
| 3696 | #endif /* CONFIG_DPP2 */ |
| 3697 | |
| 3698 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3699 | void dpp_configurator_free(struct dpp_configurator *conf) |
| 3700 | { |
| 3701 | if (!conf) |
| 3702 | return; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3703 | crypto_ec_key_deinit(conf->csign); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3704 | os_free(conf->kid); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3705 | os_free(conf->connector); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3706 | crypto_ec_key_deinit(conf->connector_key); |
| 3707 | crypto_ec_key_deinit(conf->pp_key); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3708 | os_free(conf); |
| 3709 | } |
| 3710 | |
| 3711 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3712 | int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf, |
| 3713 | size_t buflen) |
| 3714 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3715 | struct wpabuf *key; |
| 3716 | int ret = -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3717 | |
| 3718 | if (!conf->csign) |
| 3719 | return -1; |
| 3720 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3721 | key = crypto_ec_key_get_ecprivate_key(conf->csign, true); |
| 3722 | if (!key) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3723 | return -1; |
| 3724 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3725 | ret = wpa_snprintf_hex(buf, buflen, wpabuf_head(key), wpabuf_len(key)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3726 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3727 | wpabuf_clear_free(key); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3728 | return ret; |
| 3729 | } |
| 3730 | |
| 3731 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3732 | static int dpp_configurator_gen_kid(struct dpp_configurator *conf) |
| 3733 | { |
| 3734 | struct wpabuf *csign_pub = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3735 | const u8 *addr[1]; |
| 3736 | size_t len[1]; |
| 3737 | int res; |
| 3738 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3739 | csign_pub = crypto_ec_key_get_pubkey_point(conf->csign, 1); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3740 | if (!csign_pub) { |
| 3741 | wpa_printf(MSG_INFO, "DPP: Failed to extract C-sign-key"); |
| 3742 | return -1; |
| 3743 | } |
| 3744 | |
| 3745 | /* kid = SHA256(ANSI X9.63 uncompressed C-sign-key) */ |
| 3746 | addr[0] = wpabuf_head(csign_pub); |
| 3747 | len[0] = wpabuf_len(csign_pub); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3748 | res = sha256_vector(1, addr, len, conf->kid_hash); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3749 | wpabuf_free(csign_pub); |
| 3750 | if (res < 0) { |
| 3751 | wpa_printf(MSG_DEBUG, |
| 3752 | "DPP: Failed to derive kid for C-sign-key"); |
| 3753 | return -1; |
| 3754 | } |
| 3755 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3756 | conf->kid = base64_url_encode(conf->kid_hash, sizeof(conf->kid_hash), |
| 3757 | NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3758 | return conf->kid ? 0 : -1; |
| 3759 | } |
| 3760 | |
| 3761 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3762 | static struct dpp_configurator * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3763 | dpp_keygen_configurator(const char *curve, const u8 *privkey, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3764 | size_t privkey_len, const u8 *pp_key, size_t pp_key_len) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3765 | { |
| 3766 | struct dpp_configurator *conf; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3767 | |
| 3768 | conf = os_zalloc(sizeof(*conf)); |
| 3769 | if (!conf) |
| 3770 | return NULL; |
| 3771 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3772 | conf->curve = dpp_get_curve_name(curve); |
| 3773 | if (!conf->curve) { |
| 3774 | wpa_printf(MSG_INFO, "DPP: Unsupported curve: %s", curve); |
| 3775 | os_free(conf); |
| 3776 | return NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3777 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3778 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3779 | if (privkey) |
| 3780 | conf->csign = dpp_set_keypair(&conf->curve, privkey, |
| 3781 | privkey_len); |
| 3782 | else |
| 3783 | conf->csign = dpp_gen_keypair(conf->curve); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3784 | if (pp_key) |
| 3785 | conf->pp_key = dpp_set_keypair(&conf->curve, pp_key, |
| 3786 | pp_key_len); |
| 3787 | else |
| 3788 | conf->pp_key = dpp_gen_keypair(conf->curve); |
| 3789 | if (!conf->csign || !conf->pp_key) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3790 | goto fail; |
| 3791 | conf->own = 1; |
| 3792 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3793 | if (dpp_configurator_gen_kid(conf) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3794 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3795 | return conf; |
| 3796 | fail: |
| 3797 | dpp_configurator_free(conf); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3798 | return NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | |
| 3802 | int dpp_configurator_own_config(struct dpp_authentication *auth, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3803 | const char *curve, int ap) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3804 | { |
| 3805 | struct wpabuf *conf_obj; |
| 3806 | int ret = -1; |
| 3807 | |
| 3808 | if (!auth->conf) { |
| 3809 | wpa_printf(MSG_DEBUG, "DPP: No configurator specified"); |
| 3810 | return -1; |
| 3811 | } |
| 3812 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3813 | auth->curve = dpp_get_curve_name(curve); |
| 3814 | if (!auth->curve) { |
| 3815 | wpa_printf(MSG_INFO, "DPP: Unsupported curve: %s", curve); |
| 3816 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3817 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3818 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3819 | wpa_printf(MSG_DEBUG, |
| 3820 | "DPP: Building own configuration/connector with curve %s", |
| 3821 | auth->curve->name); |
| 3822 | |
| 3823 | auth->own_protocol_key = dpp_gen_keypair(auth->curve); |
| 3824 | if (!auth->own_protocol_key) |
| 3825 | return -1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3826 | dpp_copy_netaccesskey(auth, &auth->conf_obj[0]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3827 | auth->peer_protocol_key = auth->own_protocol_key; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3828 | dpp_copy_csign(&auth->conf_obj[0], auth->conf->csign); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3829 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3830 | conf_obj = dpp_build_conf_obj(auth, ap, 0, NULL); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3831 | if (!conf_obj) { |
| 3832 | wpabuf_free(auth->conf_obj[0].c_sign_key); |
| 3833 | auth->conf_obj[0].c_sign_key = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3834 | goto fail; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3835 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3836 | ret = dpp_parse_conf_obj(auth, wpabuf_head(conf_obj), |
| 3837 | wpabuf_len(conf_obj)); |
| 3838 | fail: |
| 3839 | wpabuf_free(conf_obj); |
| 3840 | auth->peer_protocol_key = NULL; |
| 3841 | return ret; |
| 3842 | } |
| 3843 | |
| 3844 | |
| 3845 | static int dpp_compatible_netrole(const char *role1, const char *role2) |
| 3846 | { |
| 3847 | return (os_strcmp(role1, "sta") == 0 && os_strcmp(role2, "ap") == 0) || |
| 3848 | (os_strcmp(role1, "ap") == 0 && os_strcmp(role2, "sta") == 0); |
| 3849 | } |
| 3850 | |
| 3851 | |
| 3852 | static int dpp_connector_compatible_group(struct json_token *root, |
| 3853 | const char *group_id, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3854 | const char *net_role, |
| 3855 | bool reconfig) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3856 | { |
| 3857 | struct json_token *groups, *token; |
| 3858 | |
| 3859 | groups = json_get_member(root, "groups"); |
| 3860 | if (!groups || groups->type != JSON_ARRAY) |
| 3861 | return 0; |
| 3862 | |
| 3863 | for (token = groups->child; token; token = token->sibling) { |
| 3864 | struct json_token *id, *role; |
| 3865 | |
| 3866 | id = json_get_member(token, "groupId"); |
| 3867 | if (!id || id->type != JSON_STRING) |
| 3868 | continue; |
| 3869 | |
| 3870 | role = json_get_member(token, "netRole"); |
| 3871 | if (!role || role->type != JSON_STRING) |
| 3872 | continue; |
| 3873 | |
| 3874 | if (os_strcmp(id->string, "*") != 0 && |
| 3875 | os_strcmp(group_id, "*") != 0 && |
| 3876 | os_strcmp(id->string, group_id) != 0) |
| 3877 | continue; |
| 3878 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3879 | if (reconfig && os_strcmp(net_role, "configurator") == 0) |
| 3880 | return 1; |
| 3881 | if (!reconfig && dpp_compatible_netrole(role->string, net_role)) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3882 | return 1; |
| 3883 | } |
| 3884 | |
| 3885 | return 0; |
| 3886 | } |
| 3887 | |
| 3888 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3889 | int dpp_connector_match_groups(struct json_token *own_root, |
| 3890 | struct json_token *peer_root, bool reconfig) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3891 | { |
| 3892 | struct json_token *groups, *token; |
| 3893 | |
| 3894 | groups = json_get_member(peer_root, "groups"); |
| 3895 | if (!groups || groups->type != JSON_ARRAY) { |
| 3896 | wpa_printf(MSG_DEBUG, "DPP: No peer groups array found"); |
| 3897 | return 0; |
| 3898 | } |
| 3899 | |
| 3900 | for (token = groups->child; token; token = token->sibling) { |
| 3901 | struct json_token *id, *role; |
| 3902 | |
| 3903 | id = json_get_member(token, "groupId"); |
| 3904 | if (!id || id->type != JSON_STRING) { |
| 3905 | wpa_printf(MSG_DEBUG, |
| 3906 | "DPP: Missing peer groupId string"); |
| 3907 | continue; |
| 3908 | } |
| 3909 | |
| 3910 | role = json_get_member(token, "netRole"); |
| 3911 | if (!role || role->type != JSON_STRING) { |
| 3912 | wpa_printf(MSG_DEBUG, |
| 3913 | "DPP: Missing peer groups::netRole string"); |
| 3914 | continue; |
| 3915 | } |
| 3916 | wpa_printf(MSG_DEBUG, |
| 3917 | "DPP: peer connector group: groupId='%s' netRole='%s'", |
| 3918 | id->string, role->string); |
| 3919 | if (dpp_connector_compatible_group(own_root, id->string, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3920 | role->string, reconfig)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3921 | wpa_printf(MSG_DEBUG, |
| 3922 | "DPP: Compatible group/netRole in own connector"); |
| 3923 | return 1; |
| 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | return 0; |
| 3928 | } |
| 3929 | |
| 3930 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3931 | struct json_token * dpp_parse_own_connector(const char *own_connector) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3932 | { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3933 | unsigned char *own_conn; |
| 3934 | size_t own_conn_len; |
| 3935 | const char *pos, *end; |
| 3936 | struct json_token *own_root; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3937 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3938 | pos = os_strchr(own_connector, '.'); |
| 3939 | if (!pos) { |
| 3940 | wpa_printf(MSG_DEBUG, "DPP: Own connector is missing the first dot (.)"); |
| 3941 | return NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3942 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3943 | pos++; |
| 3944 | end = os_strchr(pos, '.'); |
| 3945 | if (!end) { |
| 3946 | wpa_printf(MSG_DEBUG, "DPP: Own connector is missing the second dot (.)"); |
| 3947 | return NULL; |
| 3948 | } |
| 3949 | own_conn = base64_url_decode(pos, end - pos, &own_conn_len); |
| 3950 | if (!own_conn) { |
| 3951 | wpa_printf(MSG_DEBUG, |
| 3952 | "DPP: Failed to base64url decode own signedConnector JWS Payload"); |
| 3953 | return NULL; |
| 3954 | } |
| 3955 | |
| 3956 | own_root = json_parse((const char *) own_conn, own_conn_len); |
| 3957 | os_free(own_conn); |
| 3958 | if (!own_root) |
| 3959 | wpa_printf(MSG_DEBUG, "DPP: Failed to parse local connector"); |
| 3960 | |
| 3961 | return own_root; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3965 | enum dpp_status_error |
| 3966 | dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector, |
| 3967 | const u8 *net_access_key, size_t net_access_key_len, |
| 3968 | const u8 *csign_key, size_t csign_key_len, |
| 3969 | const u8 *peer_connector, size_t peer_connector_len, |
| 3970 | os_time_t *expiry) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3971 | { |
| 3972 | struct json_token *root = NULL, *netkey, *token; |
| 3973 | struct json_token *own_root = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3974 | enum dpp_status_error ret = 255, res; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3975 | struct crypto_ec_key *own_key = NULL, *peer_key = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3976 | struct wpabuf *own_key_pub = NULL; |
| 3977 | const struct dpp_curve_params *curve, *own_curve; |
| 3978 | struct dpp_signed_connector_info info; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3979 | size_t Nx_len; |
| 3980 | u8 Nx[DPP_MAX_SHARED_SECRET_LEN]; |
| 3981 | |
| 3982 | os_memset(intro, 0, sizeof(*intro)); |
| 3983 | os_memset(&info, 0, sizeof(info)); |
| 3984 | if (expiry) |
| 3985 | *expiry = 0; |
| 3986 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3987 | own_key = dpp_set_keypair(&own_curve, net_access_key, |
| 3988 | net_access_key_len); |
| 3989 | if (!own_key) { |
| 3990 | wpa_printf(MSG_ERROR, "DPP: Failed to parse own netAccessKey"); |
| 3991 | goto fail; |
| 3992 | } |
| 3993 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3994 | own_root = dpp_parse_own_connector(own_connector); |
| 3995 | if (!own_root) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3996 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3997 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3998 | res = dpp_check_signed_connector(&info, csign_key, csign_key_len, |
| 3999 | peer_connector, peer_connector_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4000 | if (res != DPP_STATUS_OK) { |
| 4001 | ret = res; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4002 | goto fail; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4003 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4004 | |
| 4005 | root = json_parse((const char *) info.payload, info.payload_len); |
| 4006 | if (!root) { |
| 4007 | wpa_printf(MSG_DEBUG, "DPP: JSON parsing of connector failed"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4008 | ret = DPP_STATUS_INVALID_CONNECTOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4009 | goto fail; |
| 4010 | } |
| 4011 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4012 | if (!dpp_connector_match_groups(own_root, root, false)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4013 | wpa_printf(MSG_DEBUG, |
| 4014 | "DPP: Peer connector does not include compatible group netrole with own connector"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4015 | ret = DPP_STATUS_NO_MATCH; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4016 | goto fail; |
| 4017 | } |
| 4018 | |
| 4019 | token = json_get_member(root, "expiry"); |
| 4020 | if (!token || token->type != JSON_STRING) { |
| 4021 | wpa_printf(MSG_DEBUG, |
| 4022 | "DPP: No expiry string found - connector does not expire"); |
| 4023 | } else { |
| 4024 | wpa_printf(MSG_DEBUG, "DPP: expiry = %s", token->string); |
| 4025 | if (dpp_key_expired(token->string, expiry)) { |
| 4026 | wpa_printf(MSG_DEBUG, |
| 4027 | "DPP: Connector (netAccessKey) has expired"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4028 | ret = DPP_STATUS_INVALID_CONNECTOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4029 | goto fail; |
| 4030 | } |
| 4031 | } |
| 4032 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4033 | #ifdef CONFIG_DPP3 |
| 4034 | token = json_get_member(root, "version"); |
| 4035 | if (token && token->type == JSON_NUMBER) { |
| 4036 | wpa_printf(MSG_DEBUG, "DPP: version = %d", token->number); |
| 4037 | intro->peer_version = token->number; |
| 4038 | } |
| 4039 | #endif /* CONFIG_DPP3 */ |
| 4040 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4041 | netkey = json_get_member(root, "netAccessKey"); |
| 4042 | if (!netkey || netkey->type != JSON_OBJECT) { |
| 4043 | wpa_printf(MSG_DEBUG, "DPP: No netAccessKey object found"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4044 | ret = DPP_STATUS_INVALID_CONNECTOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4045 | goto fail; |
| 4046 | } |
| 4047 | |
| 4048 | peer_key = dpp_parse_jwk(netkey, &curve); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4049 | if (!peer_key) { |
| 4050 | ret = DPP_STATUS_INVALID_CONNECTOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4051 | goto fail; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4052 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4053 | dpp_debug_print_key("DPP: Received netAccessKey", peer_key); |
| 4054 | |
| 4055 | if (own_curve != curve) { |
| 4056 | wpa_printf(MSG_DEBUG, |
| 4057 | "DPP: Mismatching netAccessKey curves (%s != %s)", |
| 4058 | own_curve->name, curve->name); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4059 | ret = DPP_STATUS_INVALID_CONNECTOR; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4060 | goto fail; |
| 4061 | } |
| 4062 | |
| 4063 | /* ECDH: N = nk * PK */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4064 | if (dpp_ecdh(own_key, peer_key, Nx, &Nx_len) < 0) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4065 | goto fail; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4066 | |
| 4067 | wpa_hexdump_key(MSG_DEBUG, "DPP: ECDH shared secret (N.x)", |
| 4068 | Nx, Nx_len); |
| 4069 | |
| 4070 | /* PMK = HKDF(<>, "DPP PMK", N.x) */ |
| 4071 | if (dpp_derive_pmk(Nx, Nx_len, intro->pmk, curve->hash_len) < 0) { |
| 4072 | wpa_printf(MSG_ERROR, "DPP: Failed to derive PMK"); |
| 4073 | goto fail; |
| 4074 | } |
| 4075 | intro->pmk_len = curve->hash_len; |
| 4076 | |
| 4077 | /* PMKID = Truncate-128(H(min(NK.x, PK.x) | max(NK.x, PK.x))) */ |
| 4078 | if (dpp_derive_pmkid(curve, own_key, peer_key, intro->pmkid) < 0) { |
| 4079 | wpa_printf(MSG_ERROR, "DPP: Failed to derive PMKID"); |
| 4080 | goto fail; |
| 4081 | } |
| 4082 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4083 | ret = DPP_STATUS_OK; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4084 | fail: |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4085 | if (ret != DPP_STATUS_OK) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4086 | os_memset(intro, 0, sizeof(*intro)); |
| 4087 | os_memset(Nx, 0, sizeof(Nx)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4088 | os_free(info.payload); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4089 | crypto_ec_key_deinit(own_key); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4090 | wpabuf_free(own_key_pub); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4091 | crypto_ec_key_deinit(peer_key); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4092 | json_free(root); |
| 4093 | json_free(own_root); |
| 4094 | return ret; |
| 4095 | } |
| 4096 | |
| 4097 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4098 | #ifdef CONFIG_DPP3 |
| 4099 | int dpp_get_connector_version(const char *connector) |
| 4100 | { |
| 4101 | struct json_token *root, *token; |
| 4102 | int ver = -1; |
| 4103 | |
| 4104 | root = dpp_parse_own_connector(connector); |
| 4105 | if (!root) |
| 4106 | return -1; |
| 4107 | |
| 4108 | token = json_get_member(root, "version"); |
| 4109 | if (token && token->type == JSON_NUMBER) |
| 4110 | ver = token->number; |
| 4111 | |
| 4112 | json_free(root); |
| 4113 | return ver; |
| 4114 | } |
| 4115 | #endif /* CONFIG_DPP3 */ |
| 4116 | |
| 4117 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4118 | unsigned int dpp_next_id(struct dpp_global *dpp) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4119 | { |
| 4120 | struct dpp_bootstrap_info *bi; |
| 4121 | unsigned int max_id = 0; |
| 4122 | |
| 4123 | dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) { |
| 4124 | if (bi->id > max_id) |
| 4125 | max_id = bi->id; |
| 4126 | } |
| 4127 | return max_id + 1; |
| 4128 | } |
| 4129 | |
| 4130 | |
| 4131 | static int dpp_bootstrap_del(struct dpp_global *dpp, unsigned int id) |
| 4132 | { |
| 4133 | struct dpp_bootstrap_info *bi, *tmp; |
| 4134 | int found = 0; |
| 4135 | |
| 4136 | if (!dpp) |
| 4137 | return -1; |
| 4138 | |
| 4139 | dl_list_for_each_safe(bi, tmp, &dpp->bootstrap, |
| 4140 | struct dpp_bootstrap_info, list) { |
| 4141 | if (id && bi->id != id) |
| 4142 | continue; |
| 4143 | found = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4144 | #ifdef CONFIG_DPP2 |
| 4145 | if (dpp->remove_bi) |
| 4146 | dpp->remove_bi(dpp->cb_ctx, bi); |
| 4147 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4148 | dl_list_del(&bi->list); |
| 4149 | dpp_bootstrap_info_free(bi); |
| 4150 | } |
| 4151 | |
| 4152 | if (id == 0) |
| 4153 | return 0; /* flush succeeds regardless of entries found */ |
| 4154 | return found ? 0 : -1; |
| 4155 | } |
| 4156 | |
| 4157 | |
| 4158 | struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp, |
| 4159 | const char *uri) |
| 4160 | { |
| 4161 | struct dpp_bootstrap_info *bi; |
| 4162 | |
| 4163 | if (!dpp) |
| 4164 | return NULL; |
| 4165 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4166 | bi = dpp_parse_uri(uri); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4167 | if (!bi) |
| 4168 | return NULL; |
| 4169 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4170 | bi->type = DPP_BOOTSTRAP_QR_CODE; |
| 4171 | bi->id = dpp_next_id(dpp); |
| 4172 | dl_list_add(&dpp->bootstrap, &bi->list); |
| 4173 | return bi; |
| 4174 | } |
| 4175 | |
| 4176 | |
| 4177 | struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp, |
| 4178 | const char *uri) |
| 4179 | { |
| 4180 | struct dpp_bootstrap_info *bi; |
| 4181 | |
| 4182 | if (!dpp) |
| 4183 | return NULL; |
| 4184 | |
| 4185 | bi = dpp_parse_uri(uri); |
| 4186 | if (!bi) |
| 4187 | return NULL; |
| 4188 | |
| 4189 | bi->type = DPP_BOOTSTRAP_NFC_URI; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4190 | bi->id = dpp_next_id(dpp); |
| 4191 | dl_list_add(&dpp->bootstrap, &bi->list); |
| 4192 | return bi; |
| 4193 | } |
| 4194 | |
| 4195 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4196 | static int dpp_parse_supported_curves_list(struct dpp_bootstrap_info *bi, |
| 4197 | char *txt) |
| 4198 | { |
| 4199 | char *token, *context = NULL; |
| 4200 | u8 curves = 0; |
| 4201 | |
| 4202 | if (!txt) |
| 4203 | return 0; |
| 4204 | |
| 4205 | while ((token = str_token(txt, ":", &context))) { |
| 4206 | if (os_strcmp(token, "P-256") == 0) { |
| 4207 | curves |= BIT(DPP_BOOTSTRAP_CURVE_P_256); |
| 4208 | } else if (os_strcmp(token, "P-384") == 0) { |
| 4209 | curves |= BIT(DPP_BOOTSTRAP_CURVE_P_384); |
| 4210 | } else if (os_strcmp(token, "P-521") == 0) { |
| 4211 | curves |= BIT(DPP_BOOTSTRAP_CURVE_P_521); |
| 4212 | } else if (os_strcmp(token, "BP-256") == 0) { |
| 4213 | curves |= BIT(DPP_BOOTSTRAP_CURVE_BP_256); |
| 4214 | } else if (os_strcmp(token, "BP-384") == 0) { |
| 4215 | curves |= BIT(DPP_BOOTSTRAP_CURVE_BP_384); |
| 4216 | } else if (os_strcmp(token, "BP-512") == 0) { |
| 4217 | curves |= BIT(DPP_BOOTSTRAP_CURVE_BP_512); |
| 4218 | } else { |
| 4219 | wpa_printf(MSG_DEBUG, "DPP: Unsupported curve '%s'", |
| 4220 | token); |
| 4221 | return -1; |
| 4222 | } |
| 4223 | } |
| 4224 | bi->supported_curves = curves; |
| 4225 | |
| 4226 | wpa_printf(MSG_DEBUG, "DPP: URI supported curves: 0x%x", |
| 4227 | bi->supported_curves); |
| 4228 | |
| 4229 | return 0; |
| 4230 | } |
| 4231 | |
| 4232 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4233 | int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd) |
| 4234 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4235 | char *mac = NULL, *info = NULL, *curve = NULL; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4236 | char *key = NULL, *supported_curves = NULL; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4237 | u8 *privkey = NULL; |
| 4238 | size_t privkey_len = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4239 | int ret = -1; |
| 4240 | struct dpp_bootstrap_info *bi; |
| 4241 | |
| 4242 | if (!dpp) |
| 4243 | return -1; |
| 4244 | |
| 4245 | bi = os_zalloc(sizeof(*bi)); |
| 4246 | if (!bi) |
| 4247 | goto fail; |
| 4248 | |
| 4249 | if (os_strstr(cmd, "type=qrcode")) |
| 4250 | bi->type = DPP_BOOTSTRAP_QR_CODE; |
| 4251 | else if (os_strstr(cmd, "type=pkex")) |
| 4252 | bi->type = DPP_BOOTSTRAP_PKEX; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4253 | else if (os_strstr(cmd, "type=nfc-uri")) |
| 4254 | bi->type = DPP_BOOTSTRAP_NFC_URI; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4255 | else |
| 4256 | goto fail; |
| 4257 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4258 | bi->chan = get_param(cmd, " chan="); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4259 | mac = get_param(cmd, " mac="); |
| 4260 | info = get_param(cmd, " info="); |
| 4261 | curve = get_param(cmd, " curve="); |
| 4262 | key = get_param(cmd, " key="); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4263 | supported_curves = get_param(cmd, " supported_curves="); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4264 | |
| 4265 | if (key) { |
| 4266 | privkey_len = os_strlen(key) / 2; |
| 4267 | privkey = os_malloc(privkey_len); |
| 4268 | if (!privkey || |
| 4269 | hexstr2bin(key, privkey, privkey_len) < 0) |
| 4270 | goto fail; |
| 4271 | } |
| 4272 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4273 | if (dpp_keygen(bi, curve, privkey, privkey_len) < 0 || |
| 4274 | dpp_parse_uri_chan_list(bi, bi->chan) < 0 || |
| 4275 | dpp_parse_uri_mac(bi, mac) < 0 || |
| 4276 | dpp_parse_uri_info(bi, info) < 0 || |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4277 | dpp_parse_supported_curves_list(bi, supported_curves) < 0 || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4278 | dpp_gen_uri(bi) < 0) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4279 | goto fail; |
| 4280 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4281 | bi->id = dpp_next_id(dpp); |
| 4282 | dl_list_add(&dpp->bootstrap, &bi->list); |
| 4283 | ret = bi->id; |
| 4284 | bi = NULL; |
| 4285 | fail: |
| 4286 | os_free(curve); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4287 | os_free(mac); |
| 4288 | os_free(info); |
| 4289 | str_clear_free(key); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4290 | os_free(supported_curves); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4291 | bin_clear_free(privkey, privkey_len); |
| 4292 | dpp_bootstrap_info_free(bi); |
| 4293 | return ret; |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | struct dpp_bootstrap_info * |
| 4298 | dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id) |
| 4299 | { |
| 4300 | struct dpp_bootstrap_info *bi; |
| 4301 | |
| 4302 | if (!dpp) |
| 4303 | return NULL; |
| 4304 | |
| 4305 | dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) { |
| 4306 | if (bi->id == id) |
| 4307 | return bi; |
| 4308 | } |
| 4309 | return NULL; |
| 4310 | } |
| 4311 | |
| 4312 | |
| 4313 | int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id) |
| 4314 | { |
| 4315 | unsigned int id_val; |
| 4316 | |
| 4317 | if (os_strcmp(id, "*") == 0) { |
| 4318 | id_val = 0; |
| 4319 | } else { |
| 4320 | id_val = atoi(id); |
| 4321 | if (id_val == 0) |
| 4322 | return -1; |
| 4323 | } |
| 4324 | |
| 4325 | return dpp_bootstrap_del(dpp, id_val); |
| 4326 | } |
| 4327 | |
| 4328 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4329 | const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id) |
| 4330 | { |
| 4331 | struct dpp_bootstrap_info *bi; |
| 4332 | |
| 4333 | bi = dpp_bootstrap_get_id(dpp, id); |
| 4334 | if (!bi) |
| 4335 | return NULL; |
| 4336 | return bi->uri; |
| 4337 | } |
| 4338 | |
| 4339 | |
| 4340 | int dpp_bootstrap_info(struct dpp_global *dpp, int id, |
| 4341 | char *reply, int reply_size) |
| 4342 | { |
| 4343 | struct dpp_bootstrap_info *bi; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4344 | char pkhash[2 * SHA256_MAC_LEN + 1]; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4345 | char supp_curves[100]; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4346 | |
| 4347 | bi = dpp_bootstrap_get_id(dpp, id); |
| 4348 | if (!bi) |
| 4349 | return -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4350 | wpa_snprintf_hex(pkhash, sizeof(pkhash), bi->pubkey_hash, |
| 4351 | SHA256_MAC_LEN); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4352 | |
| 4353 | supp_curves[0] = '\0'; |
| 4354 | if (bi->supported_curves) { |
| 4355 | int ret; |
| 4356 | size_t i; |
| 4357 | char *pos = supp_curves; |
| 4358 | char *end = &supp_curves[sizeof(supp_curves)]; |
| 4359 | const char *curve[6] = { "P-256", "P-384", "P-521", |
| 4360 | "BP-256", "BP-384", "BP-512" }; |
| 4361 | |
| 4362 | ret = os_snprintf(pos, end - pos, "supp_curves="); |
| 4363 | if (os_snprintf_error(end - pos, ret)) |
| 4364 | return -1; |
| 4365 | pos += ret; |
| 4366 | |
| 4367 | for (i = 0; i < ARRAY_SIZE(curve); i++) { |
| 4368 | if (!(bi->supported_curves & BIT(i))) |
| 4369 | continue; |
| 4370 | ret = os_snprintf(pos, end - pos, "%s:", curve[i]); |
| 4371 | if (os_snprintf_error(end - pos, ret)) |
| 4372 | return -1; |
| 4373 | pos += ret; |
| 4374 | } |
| 4375 | |
| 4376 | if (pos[-1] == ':') |
| 4377 | pos[-1] = '\n'; |
| 4378 | else |
| 4379 | supp_curves[0] = '\0'; |
| 4380 | } |
| 4381 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4382 | return os_snprintf(reply, reply_size, "type=%s\n" |
| 4383 | "mac_addr=" MACSTR "\n" |
| 4384 | "info=%s\n" |
| 4385 | "num_freq=%u\n" |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4386 | "use_freq=%u\n" |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4387 | "curve=%s\n" |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4388 | "pkhash=%s\n" |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4389 | "version=%d\n%s", |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4390 | dpp_bootstrap_type_txt(bi->type), |
| 4391 | MAC2STR(bi->mac_addr), |
| 4392 | bi->info ? bi->info : "", |
| 4393 | bi->num_freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4394 | bi->num_freq == 1 ? bi->freq[0] : 0, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4395 | bi->curve->name, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4396 | pkhash, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4397 | bi->version, |
| 4398 | supp_curves); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4402 | int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params) |
| 4403 | { |
| 4404 | struct dpp_bootstrap_info *bi; |
| 4405 | |
| 4406 | bi = dpp_bootstrap_get_id(dpp, id); |
| 4407 | if (!bi) |
| 4408 | return -1; |
| 4409 | |
| 4410 | str_clear_free(bi->configurator_params); |
| 4411 | |
| 4412 | if (params) { |
| 4413 | bi->configurator_params = os_strdup(params); |
| 4414 | return bi->configurator_params ? 0 : -1; |
| 4415 | } |
| 4416 | |
| 4417 | bi->configurator_params = NULL; |
| 4418 | return 0; |
| 4419 | } |
| 4420 | |
| 4421 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4422 | void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap, |
| 4423 | const u8 *r_bootstrap, |
| 4424 | struct dpp_bootstrap_info **own_bi, |
| 4425 | struct dpp_bootstrap_info **peer_bi) |
| 4426 | { |
| 4427 | struct dpp_bootstrap_info *bi; |
| 4428 | |
| 4429 | *own_bi = NULL; |
| 4430 | *peer_bi = NULL; |
| 4431 | if (!dpp) |
| 4432 | return; |
| 4433 | |
| 4434 | dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) { |
| 4435 | if (!*own_bi && bi->own && |
| 4436 | os_memcmp(bi->pubkey_hash, r_bootstrap, |
| 4437 | SHA256_MAC_LEN) == 0) { |
| 4438 | wpa_printf(MSG_DEBUG, |
| 4439 | "DPP: Found matching own bootstrapping information"); |
| 4440 | *own_bi = bi; |
| 4441 | } |
| 4442 | |
| 4443 | if (!*peer_bi && !bi->own && |
| 4444 | os_memcmp(bi->pubkey_hash, i_bootstrap, |
| 4445 | SHA256_MAC_LEN) == 0) { |
| 4446 | wpa_printf(MSG_DEBUG, |
| 4447 | "DPP: Found matching peer bootstrapping information"); |
| 4448 | *peer_bi = bi; |
| 4449 | } |
| 4450 | |
| 4451 | if (*own_bi && *peer_bi) |
| 4452 | break; |
| 4453 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4454 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4455 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4456 | |
| 4457 | #ifdef CONFIG_DPP2 |
| 4458 | struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp, |
| 4459 | const u8 *hash) |
| 4460 | { |
| 4461 | struct dpp_bootstrap_info *bi; |
| 4462 | |
| 4463 | if (!dpp) |
| 4464 | return NULL; |
| 4465 | |
| 4466 | dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) { |
| 4467 | if (!bi->own && os_memcmp(bi->pubkey_hash_chirp, hash, |
| 4468 | SHA256_MAC_LEN) == 0) |
| 4469 | return bi; |
| 4470 | } |
| 4471 | |
| 4472 | return NULL; |
| 4473 | } |
| 4474 | #endif /* CONFIG_DPP2 */ |
| 4475 | |
| 4476 | |
| 4477 | static int dpp_nfc_update_bi_channel(struct dpp_bootstrap_info *own_bi, |
| 4478 | struct dpp_bootstrap_info *peer_bi) |
| 4479 | { |
| 4480 | unsigned int i, freq = 0; |
| 4481 | enum hostapd_hw_mode mode; |
| 4482 | u8 op_class, channel; |
| 4483 | char chan[20]; |
| 4484 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4485 | if (peer_bi->num_freq == 0 && !peer_bi->channels_listed) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4486 | return 0; /* no channel preference/constraint */ |
| 4487 | |
| 4488 | for (i = 0; i < peer_bi->num_freq; i++) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4489 | if ((own_bi->num_freq == 0 && !own_bi->channels_listed) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4490 | freq_included(own_bi->freq, own_bi->num_freq, |
| 4491 | peer_bi->freq[i])) { |
| 4492 | freq = peer_bi->freq[i]; |
| 4493 | break; |
| 4494 | } |
| 4495 | } |
| 4496 | if (!freq) { |
| 4497 | wpa_printf(MSG_DEBUG, "DPP: No common channel found"); |
| 4498 | return -1; |
| 4499 | } |
| 4500 | |
| 4501 | mode = ieee80211_freq_to_channel_ext(freq, 0, 0, &op_class, &channel); |
| 4502 | if (mode == NUM_HOSTAPD_MODES) { |
| 4503 | wpa_printf(MSG_DEBUG, |
| 4504 | "DPP: Could not determine operating class or channel number for %u MHz", |
| 4505 | freq); |
| 4506 | } |
| 4507 | |
| 4508 | wpa_printf(MSG_DEBUG, |
| 4509 | "DPP: Selected %u MHz (op_class %u channel %u) as the negotiation channel based on information from NFC negotiated handover", |
| 4510 | freq, op_class, channel); |
| 4511 | os_snprintf(chan, sizeof(chan), "%u/%u", op_class, channel); |
| 4512 | os_free(own_bi->chan); |
| 4513 | own_bi->chan = os_strdup(chan); |
| 4514 | own_bi->freq[0] = freq; |
| 4515 | own_bi->num_freq = 1; |
| 4516 | os_free(peer_bi->chan); |
| 4517 | peer_bi->chan = os_strdup(chan); |
| 4518 | peer_bi->freq[0] = freq; |
| 4519 | peer_bi->num_freq = 1; |
| 4520 | |
| 4521 | return dpp_gen_uri(own_bi); |
| 4522 | } |
| 4523 | |
| 4524 | |
| 4525 | static int dpp_nfc_update_bi_key(struct dpp_bootstrap_info *own_bi, |
| 4526 | struct dpp_bootstrap_info *peer_bi) |
| 4527 | { |
| 4528 | if (peer_bi->curve == own_bi->curve) |
| 4529 | return 0; |
| 4530 | |
| 4531 | wpa_printf(MSG_DEBUG, |
| 4532 | "DPP: Update own bootstrapping key to match peer curve from NFC handover"); |
| 4533 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4534 | crypto_ec_key_deinit(own_bi->pubkey); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4535 | own_bi->pubkey = NULL; |
| 4536 | |
| 4537 | if (dpp_keygen(own_bi, peer_bi->curve->name, NULL, 0) < 0 || |
| 4538 | dpp_gen_uri(own_bi) < 0) |
| 4539 | goto fail; |
| 4540 | |
| 4541 | return 0; |
| 4542 | fail: |
| 4543 | dl_list_del(&own_bi->list); |
| 4544 | dpp_bootstrap_info_free(own_bi); |
| 4545 | return -1; |
| 4546 | } |
| 4547 | |
| 4548 | |
| 4549 | int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi, |
| 4550 | struct dpp_bootstrap_info *peer_bi) |
| 4551 | { |
| 4552 | if (dpp_nfc_update_bi_channel(own_bi, peer_bi) < 0 || |
| 4553 | dpp_nfc_update_bi_key(own_bi, peer_bi) < 0) |
| 4554 | return -1; |
| 4555 | return 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | |
| 4559 | static unsigned int dpp_next_configurator_id(struct dpp_global *dpp) |
| 4560 | { |
| 4561 | struct dpp_configurator *conf; |
| 4562 | unsigned int max_id = 0; |
| 4563 | |
| 4564 | dl_list_for_each(conf, &dpp->configurator, struct dpp_configurator, |
| 4565 | list) { |
| 4566 | if (conf->id > max_id) |
| 4567 | max_id = conf->id; |
| 4568 | } |
| 4569 | return max_id + 1; |
| 4570 | } |
| 4571 | |
| 4572 | |
| 4573 | int dpp_configurator_add(struct dpp_global *dpp, const char *cmd) |
| 4574 | { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4575 | char *curve; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4576 | char *key = NULL, *ppkey = NULL; |
| 4577 | u8 *privkey = NULL, *pp_key = NULL; |
| 4578 | size_t privkey_len = 0, pp_key_len = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4579 | int ret = -1; |
| 4580 | struct dpp_configurator *conf = NULL; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4581 | const struct dpp_curve_params *net_access_key_curve = NULL; |
| 4582 | |
| 4583 | curve = get_param(cmd, " net_access_key_curve="); |
| 4584 | if (curve) { |
| 4585 | net_access_key_curve = dpp_get_curve_name(curve); |
| 4586 | if (!net_access_key_curve) { |
| 4587 | wpa_printf(MSG_DEBUG, |
| 4588 | "DPP: Unsupported net_access_key_curve: %s", |
| 4589 | curve); |
| 4590 | goto fail; |
| 4591 | } |
| 4592 | os_free(curve); |
| 4593 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4594 | |
| 4595 | curve = get_param(cmd, " curve="); |
| 4596 | key = get_param(cmd, " key="); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4597 | ppkey = get_param(cmd, " ppkey="); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4598 | |
| 4599 | if (key) { |
| 4600 | privkey_len = os_strlen(key) / 2; |
| 4601 | privkey = os_malloc(privkey_len); |
| 4602 | if (!privkey || |
| 4603 | hexstr2bin(key, privkey, privkey_len) < 0) |
| 4604 | goto fail; |
| 4605 | } |
| 4606 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4607 | if (ppkey) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4608 | pp_key_len = os_strlen(ppkey) / 2; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4609 | pp_key = os_malloc(pp_key_len); |
| 4610 | if (!pp_key || |
| 4611 | hexstr2bin(ppkey, pp_key, pp_key_len) < 0) |
| 4612 | goto fail; |
| 4613 | } |
| 4614 | |
| 4615 | conf = dpp_keygen_configurator(curve, privkey, privkey_len, |
| 4616 | pp_key, pp_key_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4617 | if (!conf) |
| 4618 | goto fail; |
| 4619 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4620 | conf->net_access_key_curve = net_access_key_curve; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4621 | conf->id = dpp_next_configurator_id(dpp); |
| 4622 | dl_list_add(&dpp->configurator, &conf->list); |
| 4623 | ret = conf->id; |
| 4624 | conf = NULL; |
| 4625 | fail: |
| 4626 | os_free(curve); |
| 4627 | str_clear_free(key); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4628 | str_clear_free(ppkey); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4629 | bin_clear_free(privkey, privkey_len); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4630 | bin_clear_free(pp_key, pp_key_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4631 | dpp_configurator_free(conf); |
| 4632 | return ret; |
| 4633 | } |
| 4634 | |
| 4635 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame^] | 4636 | int dpp_configurator_set(struct dpp_global *dpp, const char *cmd) |
| 4637 | { |
| 4638 | unsigned int id; |
| 4639 | struct dpp_configurator *conf; |
| 4640 | char *curve; |
| 4641 | |
| 4642 | id = atoi(cmd); |
| 4643 | conf = dpp_configurator_get_id(dpp, id); |
| 4644 | if (!conf) |
| 4645 | return -1; |
| 4646 | |
| 4647 | curve = get_param(cmd, " net_access_key_curve="); |
| 4648 | if (curve) { |
| 4649 | const struct dpp_curve_params *net_access_key_curve; |
| 4650 | |
| 4651 | net_access_key_curve = dpp_get_curve_name(curve); |
| 4652 | os_free(curve); |
| 4653 | if (!net_access_key_curve) |
| 4654 | return -1; |
| 4655 | conf->net_access_key_curve = net_access_key_curve; |
| 4656 | } |
| 4657 | |
| 4658 | return 0; |
| 4659 | } |
| 4660 | |
| 4661 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4662 | static int dpp_configurator_del(struct dpp_global *dpp, unsigned int id) |
| 4663 | { |
| 4664 | struct dpp_configurator *conf, *tmp; |
| 4665 | int found = 0; |
| 4666 | |
| 4667 | if (!dpp) |
| 4668 | return -1; |
| 4669 | |
| 4670 | dl_list_for_each_safe(conf, tmp, &dpp->configurator, |
| 4671 | struct dpp_configurator, list) { |
| 4672 | if (id && conf->id != id) |
| 4673 | continue; |
| 4674 | found = 1; |
| 4675 | dl_list_del(&conf->list); |
| 4676 | dpp_configurator_free(conf); |
| 4677 | } |
| 4678 | |
| 4679 | if (id == 0) |
| 4680 | return 0; /* flush succeeds regardless of entries found */ |
| 4681 | return found ? 0 : -1; |
| 4682 | } |
| 4683 | |
| 4684 | |
| 4685 | int dpp_configurator_remove(struct dpp_global *dpp, const char *id) |
| 4686 | { |
| 4687 | unsigned int id_val; |
| 4688 | |
| 4689 | if (os_strcmp(id, "*") == 0) { |
| 4690 | id_val = 0; |
| 4691 | } else { |
| 4692 | id_val = atoi(id); |
| 4693 | if (id_val == 0) |
| 4694 | return -1; |
| 4695 | } |
| 4696 | |
| 4697 | return dpp_configurator_del(dpp, id_val); |
| 4698 | } |
| 4699 | |
| 4700 | |
| 4701 | int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id, |
| 4702 | char *buf, size_t buflen) |
| 4703 | { |
| 4704 | struct dpp_configurator *conf; |
| 4705 | |
| 4706 | conf = dpp_configurator_get_id(dpp, id); |
| 4707 | if (!conf) |
| 4708 | return -1; |
| 4709 | |
| 4710 | return dpp_configurator_get_key(conf, buf, buflen); |
| 4711 | } |
| 4712 | |
| 4713 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4714 | #ifdef CONFIG_DPP2 |
| 4715 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4716 | int dpp_configurator_from_backup(struct dpp_global *dpp, |
| 4717 | struct dpp_asymmetric_key *key) |
| 4718 | { |
| 4719 | struct dpp_configurator *conf; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4720 | const struct dpp_curve_params *curve, *curve_pp; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4721 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4722 | if (!key->csign || !key->pp_key) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4723 | return -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4724 | |
| 4725 | curve = dpp_get_curve_ike_group(crypto_ec_key_group(key->csign)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4726 | if (!curve) { |
| 4727 | wpa_printf(MSG_INFO, "DPP: Unsupported group in c-sign-key"); |
| 4728 | return -1; |
| 4729 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4730 | |
| 4731 | curve_pp = dpp_get_curve_ike_group(crypto_ec_key_group(key->pp_key)); |
| 4732 | if (!curve_pp) { |
| 4733 | wpa_printf(MSG_INFO, "DPP: Unsupported group in ppKey"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4734 | return -1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | if (curve != curve_pp) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4738 | wpa_printf(MSG_INFO, |
| 4739 | "DPP: Mismatch in c-sign-key and ppKey groups"); |
| 4740 | return -1; |
| 4741 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4742 | |
| 4743 | conf = os_zalloc(sizeof(*conf)); |
| 4744 | if (!conf) |
| 4745 | return -1; |
| 4746 | conf->curve = curve; |
| 4747 | conf->csign = key->csign; |
| 4748 | key->csign = NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4749 | conf->pp_key = key->pp_key; |
| 4750 | key->pp_key = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4751 | conf->own = 1; |
| 4752 | if (dpp_configurator_gen_kid(conf) < 0) { |
| 4753 | dpp_configurator_free(conf); |
| 4754 | return -1; |
| 4755 | } |
| 4756 | |
| 4757 | conf->id = dpp_next_configurator_id(dpp); |
| 4758 | dl_list_add(&dpp->configurator, &conf->list); |
| 4759 | return conf->id; |
| 4760 | } |
| 4761 | |
| 4762 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4763 | struct dpp_configurator * dpp_configurator_find_kid(struct dpp_global *dpp, |
| 4764 | const u8 *kid) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4765 | { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4766 | struct dpp_configurator *conf; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4767 | |
| 4768 | if (!dpp) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4769 | return NULL; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4770 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4771 | dl_list_for_each(conf, &dpp->configurator, |
| 4772 | struct dpp_configurator, list) { |
| 4773 | if (os_memcmp(conf->kid_hash, kid, SHA256_MAC_LEN) == 0) |
| 4774 | return conf; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4775 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4776 | return NULL; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | #endif /* CONFIG_DPP2 */ |
| 4780 | |
| 4781 | |
| 4782 | struct dpp_global * dpp_global_init(struct dpp_global_config *config) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4783 | { |
| 4784 | struct dpp_global *dpp; |
| 4785 | |
| 4786 | dpp = os_zalloc(sizeof(*dpp)); |
| 4787 | if (!dpp) |
| 4788 | return NULL; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4789 | #ifdef CONFIG_DPP2 |
| 4790 | dpp->cb_ctx = config->cb_ctx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4791 | dpp->remove_bi = config->remove_bi; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4792 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4793 | |
| 4794 | dl_list_init(&dpp->bootstrap); |
| 4795 | dl_list_init(&dpp->configurator); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4796 | #ifdef CONFIG_DPP2 |
| 4797 | dl_list_init(&dpp->controllers); |
| 4798 | dl_list_init(&dpp->tcp_init); |
| 4799 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4800 | |
| 4801 | return dpp; |
| 4802 | } |
| 4803 | |
| 4804 | |
| 4805 | void dpp_global_clear(struct dpp_global *dpp) |
| 4806 | { |
| 4807 | if (!dpp) |
| 4808 | return; |
| 4809 | |
| 4810 | dpp_bootstrap_del(dpp, 0); |
| 4811 | dpp_configurator_del(dpp, 0); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4812 | #ifdef CONFIG_DPP2 |
| 4813 | dpp_tcp_init_flush(dpp); |
| 4814 | dpp_relay_flush_controllers(dpp); |
| 4815 | dpp_controller_stop(dpp); |
| 4816 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | |
| 4820 | void dpp_global_deinit(struct dpp_global *dpp) |
| 4821 | { |
| 4822 | dpp_global_clear(dpp); |
| 4823 | os_free(dpp); |
| 4824 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4825 | |
| 4826 | |
| 4827 | #ifdef CONFIG_DPP2 |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4828 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4829 | struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi) |
| 4830 | { |
| 4831 | struct wpabuf *msg; |
| 4832 | |
| 4833 | wpa_printf(MSG_DEBUG, "DPP: Build Presence Announcement frame"); |
| 4834 | |
| 4835 | msg = dpp_alloc_msg(DPP_PA_PRESENCE_ANNOUNCEMENT, 4 + SHA256_MAC_LEN); |
| 4836 | if (!msg) |
| 4837 | return NULL; |
| 4838 | |
| 4839 | /* Responder Bootstrapping Key Hash */ |
| 4840 | dpp_build_attr_r_bootstrap_key_hash(msg, bi->pubkey_hash_chirp); |
| 4841 | wpa_hexdump_buf(MSG_DEBUG, |
| 4842 | "DPP: Presence Announcement frame attributes", msg); |
| 4843 | return msg; |
| 4844 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4845 | |
| 4846 | |
| 4847 | void dpp_notify_chirp_received(void *msg_ctx, int id, const u8 *src, |
| 4848 | unsigned int freq, const u8 *hash) |
| 4849 | { |
| 4850 | char hex[SHA256_MAC_LEN * 2 + 1]; |
| 4851 | |
| 4852 | wpa_snprintf_hex(hex, sizeof(hex), hash, SHA256_MAC_LEN); |
| 4853 | wpa_msg(msg_ctx, MSG_INFO, |
| 4854 | DPP_EVENT_CHIRP_RX "id=%d src=" MACSTR " freq=%u hash=%s", |
| 4855 | id, MAC2STR(src), freq, hex); |
| 4856 | } |
| 4857 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4858 | #endif /* CONFIG_DPP2 */ |