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