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