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