dpp.c (4b72b91a7132df1f77bbae194e1071ac621f1edb) dpp.c (32a95656b51ebefcdf3e0b02c110825f59abd26f)
1/*
2 * DPP functionality shared between hostapd and wpa_supplicant
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2020, The Linux Foundation
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */

--- 14 unchanged lines hidden (view full) ---

23#include "drivers/driver.h"
24#include "dpp.h"
25#include "dpp_i.h"
26
27
28static const char * dpp_netrole_str(enum dpp_netrole netrole);
29
30#ifdef CONFIG_TESTING_OPTIONS
1/*
2 * DPP functionality shared between hostapd and wpa_supplicant
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2020, The Linux Foundation
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */

--- 14 unchanged lines hidden (view full) ---

23#include "drivers/driver.h"
24#include "dpp.h"
25#include "dpp_i.h"
26
27
28static const char * dpp_netrole_str(enum dpp_netrole netrole);
29
30#ifdef CONFIG_TESTING_OPTIONS
31#ifdef CONFIG_DPP2
31#ifdef CONFIG_DPP3
32int dpp_version_override = 3;
33#elif defined(CONFIG_DPP2)
32int dpp_version_override = 2;
33#else
34int dpp_version_override = 1;
35#endif
36enum dpp_test_behavior dpp_test = DPP_TEST_DISABLED;
37#endif /* CONFIG_TESTING_OPTIONS */
38
39

--- 261 unchanged lines hidden (view full) ---

301#ifdef CONFIG_DPP2
302 if (!version || DPP_VERSION < 2)
303 return 0;
304
305 if (*version == '1')
306 bi->version = 1;
307 else if (*version == '2')
308 bi->version = 2;
34int dpp_version_override = 2;
35#else
36int dpp_version_override = 1;
37#endif
38enum dpp_test_behavior dpp_test = DPP_TEST_DISABLED;
39#endif /* CONFIG_TESTING_OPTIONS */
40
41

--- 261 unchanged lines hidden (view full) ---

303#ifdef CONFIG_DPP2
304 if (!version || DPP_VERSION < 2)
305 return 0;
306
307 if (*version == '1')
308 bi->version = 1;
309 else if (*version == '2')
310 bi->version = 2;
311 else if (*version == '3')
312 bi->version = 3;
309 else
310 wpa_printf(MSG_DEBUG, "DPP: Unknown URI version");
311
312 wpa_printf(MSG_DEBUG, "DPP: URI version: %d", bi->version);
313#endif /* CONFIG_DPP2 */
314
315 return 0;
316}

--- 306 unchanged lines hidden (view full) ---

623 if (!bi->uri)
624 return -1;
625 os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%sK:%s;;",
626 bi->chan ? "C:" : "", bi->chan ? bi->chan : "",
627 bi->chan ? ";" : "",
628 macstr,
629 bi->info ? "I:" : "", bi->info ? bi->info : "",
630 bi->info ? ";" : "",
313 else
314 wpa_printf(MSG_DEBUG, "DPP: Unknown URI version");
315
316 wpa_printf(MSG_DEBUG, "DPP: URI version: %d", bi->version);
317#endif /* CONFIG_DPP2 */
318
319 return 0;
320}

--- 306 unchanged lines hidden (view full) ---

627 if (!bi->uri)
628 return -1;
629 os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%sK:%s;;",
630 bi->chan ? "C:" : "", bi->chan ? bi->chan : "",
631 bi->chan ? ";" : "",
632 macstr,
633 bi->info ? "I:" : "", bi->info ? bi->info : "",
634 bi->info ? ";" : "",
631 DPP_VERSION == 2 ? "V:2;" : "",
635 DPP_VERSION == 3 ? "V:3;" :
636 (DPP_VERSION == 2 ? "V:2;" : ""),
632 bi->pk);
633 return 0;
634}
635
636
637struct dpp_authentication *
638dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx)
639{

--- 854 unchanged lines hidden (view full) ---

1494 }
1495 os_snprintf(expiry, sizeof(expiry),
1496 "%04u-%02u-%02uT%02u:%02u:%02uZ",
1497 tm.year, tm.month, tm.day,
1498 tm.hour, tm.min, tm.sec);
1499 json_value_sep(dppcon);
1500 json_add_string(dppcon, "expiry", expiry);
1501 }
637 bi->pk);
638 return 0;
639}
640
641
642struct dpp_authentication *
643dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx)
644{

--- 854 unchanged lines hidden (view full) ---

1499 }
1500 os_snprintf(expiry, sizeof(expiry),
1501 "%04u-%02u-%02uT%02u:%02u:%02uZ",
1502 tm.year, tm.month, tm.day,
1503 tm.hour, tm.min, tm.sec);
1504 json_value_sep(dppcon);
1505 json_add_string(dppcon, "expiry", expiry);
1506 }
1507#ifdef CONFIG_DPP3
1508 json_value_sep(dppcon);
1509 json_add_int(dppcon, "version", auth->peer_version);
1510#endif /* CONFIG_DPP3 */
1502 json_end_object(dppcon);
1503 wpa_printf(MSG_DEBUG, "DPP: dppCon: %s",
1504 (const char *) wpabuf_head(dppcon));
1505
1506 signed_conn = dpp_sign_connector(auth->conf, dppcon);
1507 if (!signed_conn)
1508 goto fail;
1509

--- 2179 unchanged lines hidden (view full) ---

3689 if (dpp_key_expired(token->string, expiry)) {
3690 wpa_printf(MSG_DEBUG,
3691 "DPP: Connector (netAccessKey) has expired");
3692 ret = DPP_STATUS_INVALID_CONNECTOR;
3693 goto fail;
3694 }
3695 }
3696
1511 json_end_object(dppcon);
1512 wpa_printf(MSG_DEBUG, "DPP: dppCon: %s",
1513 (const char *) wpabuf_head(dppcon));
1514
1515 signed_conn = dpp_sign_connector(auth->conf, dppcon);
1516 if (!signed_conn)
1517 goto fail;
1518

--- 2179 unchanged lines hidden (view full) ---

3698 if (dpp_key_expired(token->string, expiry)) {
3699 wpa_printf(MSG_DEBUG,
3700 "DPP: Connector (netAccessKey) has expired");
3701 ret = DPP_STATUS_INVALID_CONNECTOR;
3702 goto fail;
3703 }
3704 }
3705
3706#ifdef CONFIG_DPP3
3707 token = json_get_member(root, "version");
3708 if (token && token->type == JSON_NUMBER) {
3709 wpa_printf(MSG_DEBUG, "DPP: version = %d", token->number);
3710 intro->peer_version = token->number;
3711 }
3712#endif /* CONFIG_DPP3 */
3713
3697 netkey = json_get_member(root, "netAccessKey");
3698 if (!netkey || netkey->type != JSON_OBJECT) {
3699 wpa_printf(MSG_DEBUG, "DPP: No netAccessKey object found");
3700 ret = DPP_STATUS_INVALID_CONNECTOR;
3701 goto fail;
3702 }
3703
3704 peer_key = dpp_parse_jwk(netkey, &curve);

--- 41 unchanged lines hidden (view full) ---

3746 wpabuf_free(own_key_pub);
3747 crypto_ec_key_deinit(peer_key);
3748 json_free(root);
3749 json_free(own_root);
3750 return ret;
3751}
3752
3753
3714 netkey = json_get_member(root, "netAccessKey");
3715 if (!netkey || netkey->type != JSON_OBJECT) {
3716 wpa_printf(MSG_DEBUG, "DPP: No netAccessKey object found");
3717 ret = DPP_STATUS_INVALID_CONNECTOR;
3718 goto fail;
3719 }
3720
3721 peer_key = dpp_parse_jwk(netkey, &curve);

--- 41 unchanged lines hidden (view full) ---

3763 wpabuf_free(own_key_pub);
3764 crypto_ec_key_deinit(peer_key);
3765 json_free(root);
3766 json_free(own_root);
3767 return ret;
3768}
3769
3770
3771#ifdef CONFIG_DPP3
3772int dpp_get_connector_version(const char *connector)
3773{
3774 struct json_token *root, *token;
3775 int ver = -1;
3776
3777 root = dpp_parse_own_connector(connector);
3778 if (!root)
3779 return -1;
3780
3781 token = json_get_member(root, "version");
3782 if (token && token->type == JSON_NUMBER)
3783 ver = token->number;
3784
3785 json_free(root);
3786 return ver;
3787}
3788#endif /* CONFIG_DPP3 */
3789
3790
3754unsigned int dpp_next_id(struct dpp_global *dpp)
3755{
3756 struct dpp_bootstrap_info *bi;
3757 unsigned int max_id = 0;
3758
3759 dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) {
3760 if (bi->id > max_id)
3761 max_id = bi->id;

--- 621 unchanged lines hidden ---
3791unsigned int dpp_next_id(struct dpp_global *dpp)
3792{
3793 struct dpp_bootstrap_info *bi;
3794 unsigned int max_id = 0;
3795
3796 dl_list_for_each(bi, &dpp->bootstrap, struct dpp_bootstrap_info, list) {
3797 if (bi->id > max_id)
3798 max_id = bi->id;

--- 621 unchanged lines hidden ---