Home | History | Annotate | Line # | Download | only in common
      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  * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc.
      6  *
      7  * This software may be distributed under the terms of the BSD license.
      8  * See README for more details.
      9  */
     10 
     11 #ifndef DPP_H
     12 #define DPP_H
     13 
     14 #ifdef CONFIG_DPP
     15 #include "utils/list.h"
     16 #include "common/wpa_common.h"
     17 #include "crypto/sha256.h"
     18 #include "crypto/crypto.h"
     19 
     20 struct hostapd_ip_addr;
     21 struct dpp_global;
     22 struct json_token;
     23 struct dpp_reconfig_id;
     24 
     25 #ifdef CONFIG_TESTING_OPTIONS
     26 #define DPP_VERSION (dpp_version_override)
     27 extern int dpp_version_override;
     28 #else /* CONFIG_TESTING_OPTIONS */
     29 #ifdef CONFIG_DPP3
     30 #define DPP_VERSION 3
     31 #elif defined(CONFIG_DPP2)
     32 #define DPP_VERSION 2
     33 #else
     34 #define DPP_VERSION 1
     35 #endif
     36 #endif /* CONFIG_TESTING_OPTIONS */
     37 
     38 #define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
     39 #define DPP_TCP_PORT 8908
     40 
     41 enum dpp_public_action_frame_type {
     42 	DPP_PA_AUTHENTICATION_REQ = 0,
     43 	DPP_PA_AUTHENTICATION_RESP = 1,
     44 	DPP_PA_AUTHENTICATION_CONF = 2,
     45 	DPP_PA_PEER_DISCOVERY_REQ = 5,
     46 	DPP_PA_PEER_DISCOVERY_RESP = 6,
     47 	DPP_PA_PKEX_V1_EXCHANGE_REQ = 7,
     48 	DPP_PA_PKEX_EXCHANGE_RESP = 8,
     49 	DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9,
     50 	DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10,
     51 	DPP_PA_CONFIGURATION_RESULT = 11,
     52 	DPP_PA_CONNECTION_STATUS_RESULT = 12,
     53 	DPP_PA_PRESENCE_ANNOUNCEMENT = 13,
     54 	DPP_PA_RECONFIG_ANNOUNCEMENT = 14,
     55 	DPP_PA_RECONFIG_AUTH_REQ = 15,
     56 	DPP_PA_RECONFIG_AUTH_RESP = 16,
     57 	DPP_PA_RECONFIG_AUTH_CONF = 17,
     58 	DPP_PA_PKEX_EXCHANGE_REQ = 18,
     59 	DPP_PA_PB_PRESENCE_ANNOUNCEMENT = 19,
     60 	DPP_PA_PB_PRESENCE_ANNOUNCEMENT_RESP = 20,
     61 	DPP_PA_PRIV_PEER_INTRO_QUERY = 21,
     62 	DPP_PA_PRIV_PEER_INTRO_NOTIFY = 22,
     63 	DPP_PA_PRIV_PEER_INTRO_UPDATE = 23,
     64 };
     65 
     66 enum dpp_attribute_id {
     67 	DPP_ATTR_STATUS = 0x1000,
     68 	DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001,
     69 	DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002,
     70 	DPP_ATTR_I_PROTOCOL_KEY = 0x1003,
     71 	DPP_ATTR_WRAPPED_DATA = 0x1004,
     72 	DPP_ATTR_I_NONCE = 0x1005,
     73 	DPP_ATTR_I_CAPABILITIES = 0x1006,
     74 	DPP_ATTR_R_NONCE = 0x1007,
     75 	DPP_ATTR_R_CAPABILITIES = 0x1008,
     76 	DPP_ATTR_R_PROTOCOL_KEY = 0x1009,
     77 	DPP_ATTR_I_AUTH_TAG = 0x100A,
     78 	DPP_ATTR_R_AUTH_TAG = 0x100B,
     79 	DPP_ATTR_CONFIG_OBJ = 0x100C,
     80 	DPP_ATTR_CONNECTOR = 0x100D,
     81 	DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E,
     82 	DPP_ATTR_BOOTSTRAP_KEY = 0x100F,
     83 	DPP_ATTR_OWN_NET_NK_HASH = 0x1011,
     84 	DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012,
     85 	DPP_ATTR_ENCRYPTED_KEY = 0x1013,
     86 	DPP_ATTR_ENROLLEE_NONCE = 0x1014,
     87 	DPP_ATTR_CODE_IDENTIFIER = 0x1015,
     88 	DPP_ATTR_TRANSACTION_ID = 0x1016,
     89 	DPP_ATTR_BOOTSTRAP_INFO = 0x1017,
     90 	DPP_ATTR_CHANNEL = 0x1018,
     91 	DPP_ATTR_PROTOCOL_VERSION = 0x1019,
     92 	DPP_ATTR_ENVELOPED_DATA = 0x101A,
     93 	DPP_ATTR_SEND_CONN_STATUS = 0x101B,
     94 	DPP_ATTR_CONN_STATUS = 0x101C,
     95 	DPP_ATTR_RECONFIG_FLAGS = 0x101D,
     96 	DPP_ATTR_C_SIGN_KEY_HASH = 0x101E,
     97 	DPP_ATTR_CSR_ATTR_REQ = 0x101F,
     98 	DPP_ATTR_A_NONCE = 0x1020,
     99 	DPP_ATTR_E_PRIME_ID = 0x1021,
    100 	DPP_ATTR_CONFIGURATOR_NONCE = 0x1022,
    101 };
    102 
    103 enum dpp_status_error {
    104 	DPP_STATUS_OK = 0,
    105 	DPP_STATUS_NOT_COMPATIBLE = 1,
    106 	DPP_STATUS_AUTH_FAILURE = 2,
    107 	DPP_STATUS_UNWRAP_FAILURE = 3,
    108 	DPP_STATUS_BAD_GROUP = 4,
    109 	DPP_STATUS_CONFIGURE_FAILURE = 5,
    110 	DPP_STATUS_RESPONSE_PENDING = 6,
    111 	DPP_STATUS_INVALID_CONNECTOR = 7,
    112 	DPP_STATUS_NO_MATCH = 8,
    113 	DPP_STATUS_CONFIG_REJECTED = 9,
    114 	DPP_STATUS_NO_AP = 10,
    115 	DPP_STATUS_CONFIGURE_PENDING = 11,
    116 	DPP_STATUS_CSR_NEEDED = 12,
    117 	DPP_STATUS_CSR_BAD = 13,
    118 	DPP_STATUS_NEW_KEY_NEEDED = 14,
    119 };
    120 
    121 /* DPP Reconfig Flags object - connectorKey values */
    122 enum dpp_connector_key {
    123 	DPP_CONFIG_REUSEKEY = 0,
    124 	DPP_CONFIG_REPLACEKEY = 1,
    125 };
    126 
    127 #define DPP_CAPAB_ENROLLEE BIT(0)
    128 #define DPP_CAPAB_CONFIGURATOR BIT(1)
    129 #define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
    130 
    131 #define DPP_BOOTSTRAP_MAX_FREQ 30
    132 #define DPP_MAX_NONCE_LEN 32
    133 #define DPP_MAX_HASH_LEN 64
    134 #define DPP_MAX_SHARED_SECRET_LEN 66
    135 #define DPP_CP_LEN 64
    136 
    137 struct dpp_curve_params {
    138 	const char *name;
    139 	size_t hash_len;
    140 	size_t aes_siv_key_len;
    141 	size_t nonce_len;
    142 	size_t prime_len;
    143 	const char *jwk_crv;
    144 	u16 ike_group;
    145 	const char *jws_alg;
    146 };
    147 
    148 enum dpp_bootstrap_type {
    149 	DPP_BOOTSTRAP_QR_CODE,
    150 	DPP_BOOTSTRAP_PKEX,
    151 	DPP_BOOTSTRAP_NFC_URI,
    152 };
    153 
    154 enum dpp_bootstrap_supported_curves {
    155 	DPP_BOOTSTRAP_CURVE_P_256 = 0,
    156 	DPP_BOOTSTRAP_CURVE_P_384 = 1,
    157 	DPP_BOOTSTRAP_CURVE_P_521 = 2,
    158 	DPP_BOOTSTRAP_CURVE_BP_256 = 3,
    159 	DPP_BOOTSTRAP_CURVE_BP_384 = 4,
    160 	DPP_BOOTSTRAP_CURVE_BP_512 = 5,
    161 };
    162 
    163 struct dpp_bootstrap_info {
    164 	struct dl_list list;
    165 	unsigned int id;
    166 	enum dpp_bootstrap_type type;
    167 	char *uri;
    168 	u8 mac_addr[ETH_ALEN];
    169 	char *chan;
    170 	char *info;
    171 	struct hostapd_ip_addr *host;
    172 	unsigned int port;
    173 	char *pk;
    174 	unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
    175 	unsigned int num_freq;
    176 	bool channels_listed;
    177 	u8 version;
    178 	u8 supported_curves; /* enum dpp_bootstrap_supported_curves bitmap */
    179 	int own;
    180 	struct crypto_ec_key *pubkey;
    181 	u8 pubkey_hash[SHA256_MAC_LEN];
    182 	u8 pubkey_hash_chirp[SHA256_MAC_LEN];
    183 	const struct dpp_curve_params *curve;
    184 	unsigned int pkex_t; /* number of failures before dpp_pkex
    185 			      * instantiation */
    186 	int nfc_negotiated; /* whether this has been used in NFC negotiated
    187 			     * connection handover */
    188 	char *configurator_params;
    189 	u8 peer_pubkey_hash[SHA256_MAC_LEN]; /* for enforcing a specific
    190 					      * peer bootstrapping key with
    191 					      * PKEX */
    192 };
    193 
    194 #define PKEX_COUNTER_T_LIMIT 5
    195 
    196 enum dpp_pkex_ver {
    197 	PKEX_VER_AUTO,
    198 	PKEX_VER_ONLY_1,
    199 	PKEX_VER_ONLY_2,
    200 };
    201 
    202 struct dpp_pkex {
    203 	void *msg_ctx;
    204 	unsigned int initiator:1;
    205 	unsigned int exchange_done:1;
    206 	unsigned int failed:1;
    207 	unsigned int v2:1;
    208 	unsigned int forced_ver:1;
    209 	struct dpp_bootstrap_info *own_bi;
    210 	u8 own_mac[ETH_ALEN];
    211 	u8 peer_mac[ETH_ALEN];
    212 	char *identifier;
    213 	char *code;
    214 	size_t code_len;
    215 	struct crypto_ec_key *x;
    216 	struct crypto_ec_key *y;
    217 	u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
    218 	u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
    219 	u8 z[DPP_MAX_HASH_LEN];
    220 	struct crypto_ec_key *peer_bootstrap_key;
    221 	struct wpabuf *exchange_req;
    222 	struct wpabuf *exchange_resp;
    223 	unsigned int t; /* number of failures on code use */
    224 	unsigned int exch_req_wait_time;
    225 	unsigned int exch_req_tries;
    226 	unsigned int freq;
    227 	u8 peer_version;
    228 	struct wpabuf *enc_key;
    229 };
    230 
    231 enum dpp_akm {
    232 	DPP_AKM_UNKNOWN,
    233 	DPP_AKM_DPP,
    234 	DPP_AKM_PSK,
    235 	DPP_AKM_SAE,
    236 	DPP_AKM_PSK_SAE,
    237 	DPP_AKM_SAE_DPP,
    238 	DPP_AKM_PSK_SAE_DPP,
    239 	DPP_AKM_DOT1X,
    240 };
    241 
    242 enum dpp_netrole {
    243 	DPP_NETROLE_STA,
    244 	DPP_NETROLE_AP,
    245 	DPP_NETROLE_CONFIGURATOR,
    246 };
    247 
    248 struct dpp_configuration {
    249 	u8 ssid[32];
    250 	size_t ssid_len;
    251 	int ssid_charset;
    252 	enum dpp_akm akm;
    253 	enum dpp_netrole netrole;
    254 
    255 	/* For DPP configuration (connector) */
    256 	os_time_t netaccesskey_expiry;
    257 
    258 	/* TODO: groups */
    259 	char *group_id;
    260 
    261 	/* For legacy configuration */
    262 	char *passphrase;
    263 	u8 psk[32];
    264 	int psk_set;
    265 
    266 	char *csrattrs;
    267 	char *extra_name;
    268 	char *extra_value;
    269 };
    270 
    271 struct dpp_asymmetric_key {
    272 	struct dpp_asymmetric_key *next;
    273 	struct crypto_ec_key *csign;
    274 	struct crypto_ec_key *pp_key;
    275 	char *config_template;
    276 	char *connector_template;
    277 };
    278 
    279 #define DPP_MAX_CONF_OBJ 10
    280 
    281 struct dpp_authentication {
    282 	struct dpp_global *global;
    283 	void *msg_ctx;
    284 	u8 peer_version;
    285 	const struct dpp_curve_params *curve;
    286 	const struct dpp_curve_params *new_curve;
    287 	struct dpp_bootstrap_info *peer_bi;
    288 	struct dpp_bootstrap_info *own_bi;
    289 	struct dpp_bootstrap_info *tmp_own_bi;
    290 	struct dpp_bootstrap_info *tmp_peer_bi;
    291 	u8 waiting_pubkey_hash[SHA256_MAC_LEN];
    292 	int response_pending;
    293 	int reconfig;
    294 	enum dpp_connector_key reconfig_connector_key;
    295 	enum dpp_status_error auth_resp_status;
    296 	enum dpp_status_error conf_resp_status;
    297 	enum dpp_status_error force_conf_resp_status;
    298 	u8 peer_mac_addr[ETH_ALEN];
    299 	u8 i_nonce[DPP_MAX_NONCE_LEN];
    300 	u8 r_nonce[DPP_MAX_NONCE_LEN];
    301 	u8 e_nonce[DPP_MAX_NONCE_LEN];
    302 	u8 c_nonce[DPP_MAX_NONCE_LEN];
    303 	u8 i_capab;
    304 	u8 r_capab;
    305 	enum dpp_netrole e_netrole;
    306 	struct crypto_ec_key *own_protocol_key;
    307 	struct crypto_ec_key *peer_protocol_key;
    308 	struct crypto_ec_key *reconfig_old_protocol_key;
    309 	struct wpabuf *req_msg;
    310 	struct wpabuf *resp_msg;
    311 	struct wpabuf *reconfig_req_msg;
    312 	struct wpabuf *reconfig_resp_msg;
    313 	/* Intersection of possible frequencies for initiating DPP
    314 	 * Authentication exchange */
    315 	unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
    316 	unsigned int num_freq, freq_idx;
    317 	unsigned int curr_freq;
    318 	unsigned int neg_freq;
    319 	unsigned int num_freq_iters;
    320 	size_t secret_len;
    321 	u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
    322 	size_t Mx_len;
    323 	u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
    324 	size_t Nx_len;
    325 	u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
    326 	size_t Lx_len;
    327 	u8 k1[DPP_MAX_HASH_LEN];
    328 	u8 k2[DPP_MAX_HASH_LEN];
    329 	u8 ke[DPP_MAX_HASH_LEN];
    330 	u8 bk[DPP_MAX_HASH_LEN];
    331 	int initiator;
    332 	int waiting_auth_resp;
    333 	int waiting_auth_conf;
    334 	int auth_req_ack;
    335 	unsigned int auth_resp_tries;
    336 	u8 allowed_roles;
    337 	int configurator;
    338 	int remove_on_tx_status;
    339 	int connect_on_tx_status;
    340 	int waiting_conf_result;
    341 	int waiting_conn_status_result;
    342 	int auth_success;
    343 	bool reconfig_success;
    344 	struct wpabuf *conf_req;
    345 	const struct wpabuf *conf_resp; /* owned by GAS server */
    346 	struct wpabuf *conf_resp_tcp;
    347 	struct dpp_configuration *conf_ap;
    348 	struct dpp_configuration *conf2_ap;
    349 	struct dpp_configuration *conf_sta;
    350 	struct dpp_configuration *conf2_sta;
    351 	int provision_configurator;
    352 	struct dpp_configurator *conf;
    353 	struct dpp_config_obj {
    354 		char *connector; /* received signedConnector */
    355 		u8 ssid[SSID_MAX_LEN];
    356 		u8 ssid_len;
    357 		int ssid_charset;
    358 		char passphrase[64];
    359 		u8 psk[PMK_LEN];
    360 		int psk_set;
    361 		enum dpp_akm akm;
    362 		struct wpabuf *c_sign_key;
    363 		struct wpabuf *certbag;
    364 		struct wpabuf *certs;
    365 		struct wpabuf *cacert;
    366 		char *server_name;
    367 		struct wpabuf *pp_key;
    368 	} conf_obj[DPP_MAX_CONF_OBJ];
    369 	unsigned int num_conf_obj;
    370 	struct dpp_asymmetric_key *conf_key_pkg;
    371 	struct wpabuf *net_access_key;
    372 	os_time_t net_access_key_expiry;
    373 	int send_conn_status;
    374 	int conn_status_requested;
    375 	int akm_use_selector;
    376 	int configurator_set;
    377 	u8 transaction_id;
    378 	u8 *csrattrs;
    379 	size_t csrattrs_len;
    380 	bool waiting_csr;
    381 	struct wpabuf *csr;
    382 	struct wpabuf *priv_key; /* DER-encoded private key used for csr */
    383 	bool waiting_cert;
    384 	char *trusted_eap_server_name;
    385 	struct wpabuf *cacert;
    386 	struct wpabuf *certbag;
    387 	bool waiting_new_key;
    388 	bool new_key_received;
    389 	void *config_resp_ctx;
    390 	void *gas_server_ctx;
    391 	bool use_config_query;
    392 	bool waiting_config;
    393 	char *e_name;
    394 	char *e_mud_url;
    395 	int *e_band_support;
    396 #ifdef CONFIG_TESTING_OPTIONS
    397 	char *config_obj_override;
    398 	char *discovery_override;
    399 	char *groups_override;
    400 	unsigned int ignore_netaccesskey_mismatch:1;
    401 #endif /* CONFIG_TESTING_OPTIONS */
    402 };
    403 
    404 struct dpp_configurator {
    405 	struct dl_list list;
    406 	unsigned int id;
    407 	int own;
    408 	struct crypto_ec_key *csign;
    409 	u8 kid_hash[SHA256_MAC_LEN];
    410 	char *kid;
    411 	const struct dpp_curve_params *curve;
    412 	const struct dpp_curve_params *net_access_key_curve;
    413 	char *connector; /* own Connector for reconfiguration */
    414 	struct crypto_ec_key *connector_key;
    415 	struct crypto_ec_key *pp_key;
    416 };
    417 
    418 struct dpp_introduction {
    419 	u8 pmkid[PMKID_LEN];
    420 	u8 pmk[PMK_LEN_MAX];
    421 	size_t pmk_len;
    422 	int peer_version;
    423 	struct crypto_ec_key *peer_key;
    424 	enum hpke_kem_id kem_id;
    425 	enum hpke_kdf_id kdf_id;
    426 	enum hpke_aead_id aead_id;
    427 };
    428 
    429 struct dpp_relay_config {
    430 	const struct hostapd_ip_addr *ipaddr;
    431 	const u8 *pkhash;
    432 
    433 	void *msg_ctx;
    434 	void *cb_ctx;
    435 	void (*tx)(void *ctx, const u8 *addr, unsigned int freq, const u8 *msg,
    436 		   size_t len);
    437 	void (*gas_resp_tx)(void *ctx, const u8 *addr, u8 dialog_token, int prot,
    438 			    struct wpabuf *buf);
    439 };
    440 
    441 struct dpp_controller_config {
    442 	const char *configurator_params;
    443 	int tcp_port;
    444 	u8 allowed_roles;
    445 	int qr_mutual;
    446 	enum dpp_netrole netrole;
    447 	void *msg_ctx;
    448 	void *cb_ctx;
    449 	int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
    450 	bool (*tcp_msg_sent)(void *ctx, struct dpp_authentication *auth);
    451 };
    452 
    453 #define DPP_PB_INFO_COUNT 2
    454 
    455 struct dpp_pb_info {
    456 	u8 hash[SHA256_MAC_LEN];
    457 	struct os_reltime rx_time;
    458 };
    459 
    460 #ifdef CONFIG_TESTING_OPTIONS
    461 enum dpp_test_behavior {
    462 	DPP_TEST_DISABLED = 0,
    463 	DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
    464 	DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
    465 	DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
    466 	DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
    467 	DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
    468 	DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
    469 	DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
    470 	DPP_TEST_ZERO_I_CAPAB = 8,
    471 	DPP_TEST_ZERO_R_CAPAB = 9,
    472 	DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
    473 	DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
    474 	DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
    475 	DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
    476 	DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
    477 	DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
    478 	DPP_TEST_NO_STATUS_AUTH_RESP = 16,
    479 	DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
    480 	DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
    481 	DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
    482 	DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
    483 	DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
    484 	DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
    485 	DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
    486 	DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
    487 	DPP_TEST_NO_STATUS_AUTH_CONF = 25,
    488 	DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
    489 	DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
    490 	DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
    491 	DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
    492 	DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
    493 	DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
    494 	DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
    495 	DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
    496 	DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
    497 	DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
    498 	DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
    499 	DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
    500 	DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
    501 	DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
    502 	DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
    503 	DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
    504 	DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
    505 	DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
    506 	DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
    507 	DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
    508 	DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
    509 	DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
    510 	DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
    511 	DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
    512 	DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
    513 	DPP_TEST_NO_E_NONCE_CONF_REQ = 51,
    514 	DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52,
    515 	DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53,
    516 	DPP_TEST_NO_E_NONCE_CONF_RESP = 54,
    517 	DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55,
    518 	DPP_TEST_NO_STATUS_CONF_RESP = 56,
    519 	DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57,
    520 	DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
    521 	DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
    522 	DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60,
    523 	DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61,
    524 	DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62,
    525 	DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63,
    526 	DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64,
    527 	DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65,
    528 	DPP_TEST_INVALID_I_PROTO_KEY_AUTH_REQ = 66,
    529 	DPP_TEST_INVALID_R_PROTO_KEY_AUTH_RESP = 67,
    530 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 68,
    531 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 69,
    532 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 70,
    533 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 71,
    534 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 72,
    535 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 73,
    536 	DPP_TEST_INVALID_STATUS_AUTH_RESP = 74,
    537 	DPP_TEST_INVALID_STATUS_AUTH_CONF = 75,
    538 	DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ = 76,
    539 	DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP = 77,
    540 	DPP_TEST_INVALID_STATUS_PEER_DISC_RESP = 78,
    541 	DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP = 79,
    542 	DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ = 80,
    543 	DPP_TEST_INVALID_I_NONCE_AUTH_REQ = 81,
    544 	DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ = 82,
    545 	DPP_TEST_INVALID_E_NONCE_CONF_REQ = 83,
    546 	DPP_TEST_STOP_AT_PKEX_EXCHANGE_RESP = 84,
    547 	DPP_TEST_STOP_AT_PKEX_CR_REQ = 85,
    548 	DPP_TEST_STOP_AT_PKEX_CR_RESP = 86,
    549 	DPP_TEST_STOP_AT_AUTH_REQ = 87,
    550 	DPP_TEST_STOP_AT_AUTH_RESP = 88,
    551 	DPP_TEST_STOP_AT_AUTH_CONF = 89,
    552 	DPP_TEST_STOP_AT_CONF_REQ = 90,
    553 	DPP_TEST_REJECT_CONFIG = 91,
    554 	DPP_TEST_NO_PROTOCOL_VERSION_PEER_DISC_REQ = 92,
    555 	DPP_TEST_NO_PROTOCOL_VERSION_PEER_DISC_RESP = 93,
    556 	DPP_TEST_INVALID_PROTOCOL_VERSION_PEER_DISC_REQ = 94,
    557 	DPP_TEST_INVALID_PROTOCOL_VERSION_PEER_DISC_RESP = 95,
    558 	DPP_TEST_INVALID_PROTOCOL_VERSION_RECONFIG_AUTH_REQ = 96,
    559 	DPP_TEST_NO_PROTOCOL_VERSION_RECONFIG_AUTH_REQ = 97,
    560 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_PB_REQ = 98,
    561 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_PB_RESP = 99,
    562 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_PB_RESP = 100,
    563 };
    564 
    565 extern enum dpp_test_behavior dpp_test;
    566 extern u8 dpp_pkex_own_mac_override[ETH_ALEN];
    567 extern u8 dpp_pkex_peer_mac_override[ETH_ALEN];
    568 extern u8 dpp_pkex_ephemeral_key_override[600];
    569 extern size_t dpp_pkex_ephemeral_key_override_len;
    570 extern u8 dpp_protocol_key_override[600];
    571 extern size_t dpp_protocol_key_override_len;
    572 extern u8 dpp_nonce_override[DPP_MAX_NONCE_LEN];
    573 extern size_t dpp_nonce_override_len;
    574 #endif /* CONFIG_TESTING_OPTIONS */
    575 
    576 void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
    577 const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
    578 int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
    579 			    const char *chan_list);
    580 int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
    581 int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
    582 int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi,
    583 		      struct dpp_bootstrap_info *peer_bi);
    584 const char * dpp_netrole_str(enum dpp_netrole netrole);
    585 struct dpp_authentication *
    586 dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx);
    587 struct hostapd_hw_modes;
    588 struct dpp_authentication * dpp_auth_init(struct dpp_global *dpp, void *msg_ctx,
    589 					  struct dpp_bootstrap_info *peer_bi,
    590 					  struct dpp_bootstrap_info *own_bi,
    591 					  u8 dpp_allowed_roles,
    592 					  unsigned int neg_freq,
    593 					  struct hostapd_hw_modes *own_modes,
    594 					  u16 num_modes);
    595 struct dpp_authentication *
    596 dpp_auth_req_rx(struct dpp_global *dpp, void *msg_ctx, u8 dpp_allowed_roles,
    597 			int qr_mutual, struct dpp_bootstrap_info *peer_bi,
    598 		struct dpp_bootstrap_info *own_bi,
    599 		unsigned int freq, const u8 *hdr, const u8 *attr_start,
    600 		size_t attr_len);
    601 struct wpabuf *
    602 dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
    603 		 const u8 *attr_start, size_t attr_len);
    604 struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
    605 				   const char *json);
    606 struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
    607 					  const char *name,
    608 					  enum dpp_netrole netrole,
    609 					  const char *mud_url, int *opclasses,
    610 					  const char *extra_name,
    611 					  const char *extra_value);
    612 int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
    613 		     const u8 *attr_start, size_t attr_len);
    614 int dpp_notify_new_qr_code(struct dpp_authentication *auth,
    615 			   struct dpp_bootstrap_info *peer_bi);
    616 void dpp_controller_pkex_add(struct dpp_global *dpp,
    617 			     struct dpp_bootstrap_info *bi,
    618 			     const char *code, const char *identifier);
    619 bool dpp_controller_is_own_pkex_req(struct dpp_global *dpp,
    620 				    const u8 *buf, size_t len);
    621 struct dpp_configuration * dpp_configuration_alloc(const char *type);
    622 int dpp_akm_psk(enum dpp_akm akm);
    623 int dpp_akm_sae(enum dpp_akm akm);
    624 int dpp_akm_legacy(enum dpp_akm akm);
    625 int dpp_akm_dpp(enum dpp_akm akm);
    626 int dpp_akm_ver2(enum dpp_akm akm);
    627 int dpp_configuration_valid(const struct dpp_configuration *conf);
    628 void dpp_configuration_free(struct dpp_configuration *conf);
    629 int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd);
    630 void dpp_auth_deinit(struct dpp_authentication *auth);
    631 struct wpabuf *
    632 dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce,
    633 		    u16 e_nonce_len, enum dpp_netrole netrole,
    634 		    bool cert_req);
    635 struct wpabuf *
    636 dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
    637 		size_t attr_len);
    638 int dpp_conf_resp_rx(struct dpp_authentication *auth,
    639 		     const struct wpabuf *resp);
    640 enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth,
    641 					 const u8 *hdr,
    642 					 const u8 *attr_start, size_t attr_len);
    643 struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth,
    644 				      enum dpp_status_error status);
    645 enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth,
    646 						const u8 *hdr,
    647 						const u8 *attr_start,
    648 						size_t attr_len,
    649 						u8 *ssid, size_t *ssid_len,
    650 						char **channel_list);
    651 struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth,
    652 					     enum dpp_status_error result,
    653 					     const u8 *ssid, size_t ssid_len,
    654 					     const char *channel_list);
    655 struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
    656 			      size_t len);
    657 const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
    658 int dpp_check_attrs(const u8 *buf, size_t len);
    659 int dpp_key_expired(const char *timestamp, os_time_t *expiry);
    660 const char * dpp_akm_str(enum dpp_akm akm);
    661 const char * dpp_akm_selector_str(enum dpp_akm akm);
    662 int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf,
    663 			     size_t buflen);
    664 void dpp_configurator_free(struct dpp_configurator *conf);
    665 int dpp_configurator_own_config(struct dpp_authentication *auth,
    666 				const char *curve, int ap);
    667 enum dpp_status_error
    668 dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
    669 	       const u8 *net_access_key, size_t net_access_key_len,
    670 	       const u8 *csign_key, size_t csign_key_len,
    671 	       const u8 *peer_connector, size_t peer_connector_len,
    672 	       os_time_t *expiry, u8 *peer_key_hash);
    673 void dpp_peer_intro_deinit(struct dpp_introduction *intro);
    674 int dpp_get_connector_version(const char *connector);
    675 struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
    676 				const u8 *own_mac,
    677 				const char *identifier, const char *code,
    678 				size_t code_len, bool v2);
    679 struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
    680 					   struct dpp_bootstrap_info *bi,
    681 					   const u8 *own_mac,
    682 					   const u8 *peer_mac,
    683 					   const char *identifier,
    684 					   const char *code, size_t code_len,
    685 					   const u8 *buf, size_t len, bool v2);
    686 struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
    687 					  const u8 *peer_mac,
    688 					  const u8 *buf, size_t len);
    689 struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
    690 					      const u8 *hdr,
    691 					      const u8 *buf, size_t len);
    692 int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
    693 				   const u8 *buf, size_t len);
    694 void dpp_pkex_free(struct dpp_pkex *pkex);
    695 
    696 char * dpp_corrupt_connector_signature(const char *connector);
    697 
    698 
    699 struct dpp_pfs {
    700 	struct crypto_ecdh *ecdh;
    701 	const struct dpp_curve_params *curve;
    702 	struct wpabuf *ie;
    703 	struct wpabuf *secret;
    704 };
    705 
    706 struct dpp_pfs * dpp_pfs_init(const u8 *net_access_key,
    707 			      size_t net_access_key_len);
    708 int dpp_pfs_process(struct dpp_pfs *pfs, const u8 *peer_ie, size_t peer_ie_len);
    709 void dpp_pfs_free(struct dpp_pfs *pfs);
    710 
    711 struct crypto_ec_key * dpp_set_keypair(const struct dpp_curve_params **curve,
    712 				       const u8 *privkey, size_t privkey_len);
    713 int dpp_hpke_suite(int iana_group, enum hpke_kem_id *kem_id,
    714 		   enum hpke_kdf_id *kdf_id, enum hpke_aead_id *aead_id);
    715 
    716 struct wpabuf * dpp_build_csr(struct dpp_authentication *auth,
    717 			      const char *name);
    718 int dpp_validate_csr(struct dpp_authentication *auth, const struct wpabuf *csr);
    719 
    720 struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp,
    721 					    const char *uri);
    722 struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp,
    723 					    const char *uri);
    724 int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd);
    725 struct dpp_bootstrap_info *
    726 dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id);
    727 int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id);
    728 struct dpp_bootstrap_info *
    729 dpp_pkex_finish(struct dpp_global *dpp, struct dpp_pkex *pkex, const u8 *peer,
    730 		unsigned int freq);
    731 const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id);
    732 int dpp_bootstrap_info(struct dpp_global *dpp, int id,
    733 		       char *reply, int reply_size);
    734 int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params);
    735 void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap,
    736 			     const u8 *r_bootstrap,
    737 			     struct dpp_bootstrap_info **own_bi,
    738 			     struct dpp_bootstrap_info **peer_bi);
    739 struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp,
    740 						     const u8 *hash);
    741 int dpp_configurator_add(struct dpp_global *dpp, const char *cmd);
    742 int dpp_configurator_set(struct dpp_global *dpp, const char *cmd);
    743 int dpp_configurator_remove(struct dpp_global *dpp, const char *id);
    744 int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id,
    745 				char *buf, size_t buflen);
    746 int dpp_configurator_from_backup(struct dpp_global *dpp,
    747 				 struct dpp_asymmetric_key *key);
    748 struct dpp_configurator * dpp_configurator_find_kid(struct dpp_global *dpp,
    749 						    const u8 *kid);
    750 int dpp_relay_add_controller(struct dpp_global *dpp,
    751 			     struct dpp_relay_config *config);
    752 void dpp_relay_remove_controller(struct dpp_global *dpp,
    753 				 const struct hostapd_ip_addr *addr);
    754 int dpp_relay_listen(struct dpp_global *dpp, int port,
    755 		     struct dpp_relay_config *config);
    756 void dpp_relay_stop_listen(struct dpp_global *dpp);
    757 int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr,
    758 			const u8 *buf, size_t len, unsigned int freq,
    759 			const u8 *i_bootstrap, const u8 *r_bootstrap,
    760 			void *cb_ctx);
    761 int dpp_relay_rx_gas_req(struct dpp_global *dpp, const u8 *src, const u8 *data,
    762 			 size_t data_len);
    763 bool dpp_relay_controller_available(struct dpp_global *dpp);
    764 int dpp_controller_start(struct dpp_global *dpp,
    765 			 struct dpp_controller_config *config);
    766 int dpp_controller_set_params(struct dpp_global *dpp,
    767 			      const char *configurator_params);
    768 void dpp_controller_stop(struct dpp_global *dpp);
    769 void dpp_controller_stop_for_ctx(struct dpp_global *dpp, void *cb_ctx);
    770 struct dpp_authentication * dpp_controller_get_auth(struct dpp_global *dpp,
    771 						    unsigned int id);
    772 void dpp_controller_new_qr_code(struct dpp_global *dpp,
    773 				struct dpp_bootstrap_info *bi);
    774 int dpp_tcp_pkex_init(struct dpp_global *dpp, struct dpp_pkex *pkex,
    775 		      const struct hostapd_ip_addr *addr, int port,
    776 		      void *msg_ctx, void *cb_ctx,
    777 		      int (*pkex_done)(void *ctx, void *conn,
    778 				       struct dpp_bootstrap_info *bi));
    779 int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth,
    780 		 const struct hostapd_ip_addr *addr, int port,
    781 		 const char *name, enum dpp_netrole netrole,
    782 		 const char *mud_url,
    783 		 const char *extra_conf_req_name,
    784 		 const char *extra_conf_req_value,
    785 		 void *msg_ctx, void *cb_ctx,
    786 		 int (*process_conf_obj)(void *ctx,
    787 					 struct dpp_authentication *auth),
    788 		 bool (*tcp_msg_sent)(void *ctx,
    789 				      struct dpp_authentication *auth));
    790 int dpp_tcp_auth(struct dpp_global *dpp, void *_conn,
    791 		 struct dpp_authentication *auth, const char *name,
    792 		 enum dpp_netrole netrole, const char *mud_url,
    793 		 const char *extra_conf_req_name,
    794 		 const char *extra_conf_req_value,
    795 		 int (*process_conf_obj)(void *ctx,
    796 					 struct dpp_authentication *auth),
    797 		 bool (*tcp_msg_sent)(void *ctx,
    798 				      struct dpp_authentication *auth));
    799 bool dpp_tcp_conn_status_requested(struct dpp_global *dpp);
    800 void dpp_tcp_send_conn_status(struct dpp_global *dpp,
    801 			      enum dpp_status_error result,
    802 			      const u8 *ssid, size_t ssid_len,
    803 			      const char *channel_list);
    804 
    805 struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi);
    806 void dpp_notify_chirp_received(void *msg_ctx, int id, const u8 *src,
    807 				unsigned int freq, const u8 *hash);
    808 
    809 struct wpabuf * dpp_build_pb_announcement(struct dpp_bootstrap_info *bi);
    810 struct wpabuf * dpp_build_pb_announcement_resp(struct dpp_bootstrap_info *bi,
    811 					       const u8 *e_hash,
    812 					       const u8 *c_nonce,
    813 					       size_t c_nonce_len);
    814 
    815 struct dpp_global_config {
    816 	void *cb_ctx;
    817 	void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi);
    818 };
    819 
    820 struct dpp_global * dpp_global_init(struct dpp_global_config *config);
    821 void dpp_global_clear(struct dpp_global *dpp);
    822 void dpp_global_deinit(struct dpp_global *dpp);
    823 void dpp_notify_auth_success(struct dpp_authentication *auth, int initiator);
    824 
    825 /* dpp_reconfig.c */
    826 
    827 struct wpabuf * dpp_build_reconfig_announcement(const u8 *csign_key,
    828 						size_t csign_key_len,
    829 						const u8 *net_access_key,
    830 						size_t net_access_key_len,
    831 						struct dpp_reconfig_id *id);
    832 struct dpp_authentication *
    833 dpp_reconfig_init(struct dpp_global *dpp, void *msg_ctx,
    834 		  struct dpp_configurator *conf, unsigned int freq, u16 group,
    835 		  const u8 *a_nonce_attr, size_t a_nonce_len,
    836 		  const u8 *e_id_attr, size_t e_id_len);
    837 struct dpp_authentication *
    838 dpp_reconfig_auth_req_rx(struct dpp_global *dpp, void *msg_ctx,
    839 			 const char *own_connector,
    840 			 const u8 *net_access_key, size_t net_access_key_len,
    841 			 const u8 *csign_key, size_t csign_key_len,
    842 			 unsigned int freq, const u8 *hdr,
    843 			 const u8 *attr_start, size_t attr_len);
    844 struct wpabuf *
    845 dpp_reconfig_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
    846 			  const u8 *attr_start, size_t attr_len);
    847 int dpp_reconfig_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
    848 			      const u8 *attr_start, size_t attr_len);
    849 
    850 struct dpp_reconfig_id * dpp_gen_reconfig_id(const u8 *csign_key,
    851 					     size_t csign_key_len,
    852 					     const u8 *pp_key,
    853 					     size_t pp_key_len);
    854 int dpp_update_reconfig_id(struct dpp_reconfig_id *id);
    855 void dpp_free_reconfig_id(struct dpp_reconfig_id *id);
    856 int dpp_get_pubkey_hash(struct crypto_ec_key *key, u8 *hash);
    857 
    858 #endif /* CONFIG_DPP */
    859 #endif /* DPP_H */
    860