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