1 /*
2  * DPP functionality shared between hostapd and wpa_supplicant
3  * Copyright (c) 2017, Qualcomm Atheros, Inc.
4  * Copyright (c) 2018-2019, 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 
15 #include "utils/list.h"
16 #include "crypto/sha256.h"
17 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "esp_err.h"
20 #include "esp_dpp.h"
21 
22 struct crypto_ecdh;
23 struct hostapd_ip_addr;
24 struct dpp_global;
25 
26 #define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
27 #define DPP_TCP_PORT 7871
28 #define SSID_MAX_LEN 32
29 #define PMKID_LEN 16
30 #define PMK_LEN 32
31 #define PMK_LEN_SUITE_B_192 48
32 #define PMK_LEN_MAX 64
33 
34 /* DPP events */
35 #define DPP_EVENT_AUTH_SUCCESS "DPP-AUTH-SUCCESS "
36 #define DPP_EVENT_AUTH_INIT_FAILED "DPP-AUTH-INIT-FAILED "
37 #define DPP_EVENT_NOT_COMPATIBLE "DPP-NOT-COMPATIBLE "
38 #define DPP_EVENT_RESPONSE_PENDING "DPP-RESPONSE-PENDING "
39 #define DPP_EVENT_SCAN_PEER_QR_CODE "DPP-SCAN-PEER-QR-CODE "
40 #define DPP_EVENT_AUTH_DIRECTION "DPP-AUTH-DIRECTION "
41 #define DPP_EVENT_CONF_RECEIVED "DPP-CONF-RECEIVED "
42 #define DPP_EVENT_CONF_SENT "DPP-CONF-SENT "
43 #define DPP_EVENT_CONF_FAILED "DPP-CONF-FAILED "
44 #define DPP_EVENT_CONN_STATUS_RESULT "DPP-CONN-STATUS-RESULT "
45 #define DPP_EVENT_CONFOBJ_AKM "DPP-CONFOBJ-AKM "
46 #define DPP_EVENT_CONFOBJ_SSID "DPP-CONFOBJ-SSID "
47 #define DPP_EVENT_CONFOBJ_SSID_CHARSET "DPP-CONFOBJ-SSID-CHARSET "
48 #define DPP_EVENT_CONFOBJ_PASS "DPP-CONFOBJ-PASS "
49 #define DPP_EVENT_CONFOBJ_PSK "DPP-CONFOBJ-PSK "
50 #define DPP_EVENT_CONNECTOR "DPP-CONNECTOR "
51 #define DPP_EVENT_C_SIGN_KEY "DPP-C-SIGN-KEY "
52 #define DPP_EVENT_NET_ACCESS_KEY "DPP-NET-ACCESS-KEY "
53 #define DPP_EVENT_MISSING_CONNECTOR "DPP-MISSING-CONNECTOR "
54 #define DPP_EVENT_NETWORK_ID "DPP-NETWORK-ID "
55 #define DPP_EVENT_RX "DPP-RX "
56 #define DPP_EVENT_TX "DPP-TX "
57 #define DPP_EVENT_TX_STATUS "DPP-TX-STATUS "
58 #define DPP_EVENT_FAIL "DPP-FAIL "
59 #define DPP_EVENT_PKEX_T_LIMIT "DPP-PKEX-T-LIMIT "
60 #define DPP_EVENT_INTRO "DPP-INTRO "
61 #define DPP_EVENT_CONF_REQ_RX "DPP-CONF-REQ-RX "
62 
63 
64 #define WLAN_ACTION_PUBLIC 4
65 #define WLAN_PA_VENDOR_SPECIFIC 9
66 #define OUI_WFA 0x506f9a
67 #define DPP_OUI_TYPE 0x1A
68 
69 #define WLAN_EID_ADV_PROTO 108
70 #define WLAN_EID_VENDOR_SPECIFIC 221
71 
72 #define WLAN_PA_GAS_INITIAL_REQ 10
73 
74 enum dpp_public_action_frame_type {
75 	DPP_PA_AUTHENTICATION_REQ = 0,
76 	DPP_PA_AUTHENTICATION_RESP = 1,
77 	DPP_PA_AUTHENTICATION_CONF = 2,
78 	DPP_PA_PEER_DISCOVERY_REQ = 5,
79 	DPP_PA_PEER_DISCOVERY_RESP = 6,
80 	DPP_PA_PKEX_EXCHANGE_REQ = 7,
81 	DPP_PA_PKEX_EXCHANGE_RESP = 8,
82 	DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9,
83 	DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10,
84 	DPP_PA_CONFIGURATION_RESULT = 11,
85 	DPP_PA_CONNECTION_STATUS_RESULT = 12,
86 };
87 
88 enum dpp_attribute_id {
89 	DPP_ATTR_STATUS = 0x1000,
90 	DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001,
91 	DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002,
92 	DPP_ATTR_I_PROTOCOL_KEY = 0x1003,
93 	DPP_ATTR_WRAPPED_DATA = 0x1004,
94 	DPP_ATTR_I_NONCE = 0x1005,
95 	DPP_ATTR_I_CAPABILITIES = 0x1006,
96 	DPP_ATTR_R_NONCE = 0x1007,
97 	DPP_ATTR_R_CAPABILITIES = 0x1008,
98 	DPP_ATTR_R_PROTOCOL_KEY = 0x1009,
99 	DPP_ATTR_I_AUTH_TAG = 0x100A,
100 	DPP_ATTR_R_AUTH_TAG = 0x100B,
101 	DPP_ATTR_CONFIG_OBJ = 0x100C,
102 	DPP_ATTR_CONNECTOR = 0x100D,
103 	DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E,
104 	DPP_ATTR_BOOTSTRAP_KEY = 0x100F,
105 	DPP_ATTR_OWN_NET_NK_HASH = 0x1011,
106 	DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012,
107 	DPP_ATTR_ENCRYPTED_KEY = 0x1013,
108 	DPP_ATTR_ENROLLEE_NONCE = 0x1014,
109 	DPP_ATTR_CODE_IDENTIFIER = 0x1015,
110 	DPP_ATTR_TRANSACTION_ID = 0x1016,
111 	DPP_ATTR_BOOTSTRAP_INFO = 0x1017,
112 	DPP_ATTR_CHANNEL = 0x1018,
113 	DPP_ATTR_PROTOCOL_VERSION = 0x1019,
114 	DPP_ATTR_ENVELOPED_DATA = 0x101A,
115 	DPP_ATTR_SEND_CONN_STATUS = 0x101B,
116 	DPP_ATTR_CONN_STATUS = 0x101C,
117 };
118 
119 enum dpp_status_error {
120 	DPP_STATUS_OK = 0,
121 	DPP_STATUS_NOT_COMPATIBLE = 1,
122 	DPP_STATUS_AUTH_FAILURE = 2,
123 	DPP_STATUS_UNWRAP_FAILURE = 3,
124 	DPP_STATUS_BAD_GROUP = 4,
125 	DPP_STATUS_CONFIGURE_FAILURE = 5,
126 	DPP_STATUS_RESPONSE_PENDING = 6,
127 	DPP_STATUS_INVALID_CONNECTOR = 7,
128 	DPP_STATUS_NO_MATCH = 8,
129 	DPP_STATUS_CONFIG_REJECTED = 9,
130 	DPP_STATUS_NO_AP = 10,
131 };
132 
133 #define DPP_CAPAB_ENROLLEE BIT(0)
134 #define DPP_CAPAB_CONFIGURATOR BIT(1)
135 #define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
136 
137 #define DPP_BOOTSTRAP_MAX_FREQ 30
138 #define DPP_MAX_NONCE_LEN 32
139 #define DPP_MAX_HASH_LEN 64
140 #define DPP_MAX_SHARED_SECRET_LEN 66
141 
142 struct dpp_curve_params {
143 	const char *name;
144 	size_t hash_len;
145 	size_t aes_siv_key_len;
146 	size_t nonce_len;
147 	size_t prime_len;
148 	const char *jwk_crv;
149 	u16 ike_group;
150 	const char *jws_alg;
151 };
152 
153 struct dpp_bootstrap_info {
154 	struct dl_list list;
155 	unsigned int id;
156 	enum dpp_bootstrap_type type;
157 	char *uri;
158 	u8 mac_addr[ETH_ALEN];
159 	char *info;
160 	unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
161 	unsigned int num_freq;
162 	int own;
163 	struct crypto_key *pubkey;
164 	u8 pubkey_hash[SHA256_MAC_LEN];
165 	const struct dpp_curve_params *curve;
166 	unsigned int pkex_t; /* number of failures before dpp_pkex
167 			      * instantiation */
168 };
169 
170 #define PKEX_COUNTER_T_LIMIT 5
171 
172 struct dpp_pkex {
173 	void *msg_ctx;
174 	unsigned int initiator:1;
175 	unsigned int exchange_done:1;
176 	unsigned int failed:1;
177 	struct dpp_bootstrap_info *own_bi;
178 	u8 own_mac[ETH_ALEN];
179 	u8 peer_mac[ETH_ALEN];
180 	char *identifier;
181 	char *code;
182 	struct crypto_key *x;
183 	struct crypto_key *y;
184 	u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
185 	u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
186 	u8 z[DPP_MAX_HASH_LEN];
187 	struct crypto_key *peer_bootstrap_key;
188 	struct wpabuf *exchange_req;
189 	struct wpabuf *exchange_resp;
190 	unsigned int t; /* number of failures on code use */
191 	unsigned int exch_req_wait_time;
192 	unsigned int exch_req_tries;
193 	unsigned int freq;
194 };
195 
196 enum dpp_akm {
197 	DPP_AKM_UNKNOWN,
198 	DPP_AKM_DPP,
199 	DPP_AKM_PSK,
200 	DPP_AKM_SAE,
201 	DPP_AKM_PSK_SAE,
202 	DPP_AKM_SAE_DPP,
203 	DPP_AKM_PSK_SAE_DPP,
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 
231 #define DPP_MAX_CONF_OBJ 10
232 
233 struct dpp_authentication {
234 	void *msg_ctx;
235 	u8 peer_version;
236 	const struct dpp_curve_params *curve;
237 	struct dpp_bootstrap_info *peer_bi;
238 	struct dpp_bootstrap_info *own_bi;
239 	struct dpp_bootstrap_info *tmp_own_bi;
240 	u8 waiting_pubkey_hash[SHA256_MAC_LEN];
241 	int response_pending;
242 	enum dpp_status_error auth_resp_status;
243 	enum dpp_status_error conf_resp_status;
244 	u8 peer_mac_addr[ETH_ALEN];
245 	u8 i_nonce[DPP_MAX_NONCE_LEN];
246 	u8 r_nonce[DPP_MAX_NONCE_LEN];
247 	u8 e_nonce[DPP_MAX_NONCE_LEN];
248 	u8 i_capab;
249 	u8 r_capab;
250 	struct crypto_key *own_protocol_key;
251 	struct crypto_key *peer_protocol_key;
252 	struct wpabuf *req_msg;
253 	struct wpabuf *resp_msg;
254 	/* Intersection of possible frequencies for initiating DPP
255 	 * Authentication exchange */
256 	unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
257 	unsigned int num_freq, freq_idx;
258     unsigned int curr_chan;
259 	unsigned int curr_freq;
260 	unsigned int neg_freq;
261 	unsigned int num_freq_iters;
262 	size_t secret_len;
263 	u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
264 	size_t Mx_len;
265 	u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
266 	size_t Nx_len;
267 	u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
268 	size_t Lx_len;
269 	u8 k1[DPP_MAX_HASH_LEN];
270 	u8 k2[DPP_MAX_HASH_LEN];
271 	u8 ke[DPP_MAX_HASH_LEN];
272 	int initiator;
273 	int waiting_auth_resp;
274 	int waiting_auth_conf;
275 	int auth_req_ack;
276 	unsigned int auth_resp_tries;
277 	u8 allowed_roles;
278 	int configurator;
279 	int remove_on_tx_status;
280 	int connect_on_tx_status;
281 	int waiting_conf_result;
282 	int waiting_conn_status_result;
283 	int auth_success;
284 	struct wpabuf *conf_req;
285 	const struct wpabuf *conf_resp; /* owned by GAS server */
286 	struct dpp_configuration *conf_ap;
287 	struct dpp_configuration *conf2_ap;
288 	struct dpp_configuration *conf_sta;
289 	struct dpp_configuration *conf2_sta;
290 	struct dpp_configurator *conf;
291 	struct dpp_config_obj {
292 		char *connector; /* received signedConnector */
293 		u8 ssid[SSID_MAX_LEN];
294 		u8 ssid_len;
295 		int ssid_charset;
296 		char passphrase[64];
297 		u8 psk[PMK_LEN];
298 		int psk_set;
299 		enum dpp_akm akm;
300 		struct wpabuf *c_sign_key;
301 	} conf_obj[DPP_MAX_CONF_OBJ];
302 	unsigned int num_conf_obj;
303 	struct wpabuf *net_access_key;
304 	os_time_t net_access_key_expiry;
305 	int send_conn_status;
306 	int conn_status_requested;
307 	int akm_use_selector;
308 #ifdef CONFIG_WPA_TESTING_OPTIONS
309 	char *config_obj_override;
310 	char *discovery_override;
311 	char *groups_override;
312 	unsigned int ignore_netaccesskey_mismatch:1;
313 #endif /* CONFIG_WPA_TESTING_OPTIONS */
314 };
315 
316 struct dpp_configurator {
317 	struct dl_list list;
318 	unsigned int id;
319 	int own;
320 	struct crypto_key *csign;
321 	char *kid;
322 	const struct dpp_curve_params *curve;
323 };
324 
325 struct dpp_introduction {
326 	u8 pmkid[PMKID_LEN];
327 	u8 pmk[PMK_LEN_MAX];
328 	size_t pmk_len;
329 };
330 
331 #ifdef CONFIG_WPA_TESTING_OPTIONS
332 enum dpp_test_behavior {
333 	DPP_TEST_DISABLED = 0,
334 	DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
335 	DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
336 	DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
337 	DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
338 	DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
339 	DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
340 	DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
341 	DPP_TEST_ZERO_I_CAPAB = 8,
342 	DPP_TEST_ZERO_R_CAPAB = 9,
343 	DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
344 	DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
345 	DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
346 	DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
347 	DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
348 	DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
349 	DPP_TEST_NO_STATUS_AUTH_RESP = 16,
350 	DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
351 	DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
352 	DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
353 	DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
354 	DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
355 	DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
356 	DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
357 	DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
358 	DPP_TEST_NO_STATUS_AUTH_CONF = 25,
359 	DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
360 	DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
361 	DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
362 	DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
363 	DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
364 	DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
365 	DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
366 	DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
367 	DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
368 	DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
369 	DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
370 	DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
371 	DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
372 	DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
373 	DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
374 	DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
375 	DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
376 	DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
377 	DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
378 	DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
379 	DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
380 	DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
381 	DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
382 	DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
383 	DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
384 	DPP_TEST_NO_E_NONCE_CONF_REQ = 51,
385 	DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52,
386 	DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53,
387 	DPP_TEST_NO_E_NONCE_CONF_RESP = 54,
388 	DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55,
389 	DPP_TEST_NO_STATUS_CONF_RESP = 56,
390 	DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57,
391 	DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
392 	DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
393 	DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60,
394 	DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61,
395 	DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62,
396 	DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63,
397 	DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64,
398 	DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65,
399 	DPP_TEST_INVALID_I_PROTO_KEY_AUTH_REQ = 66,
400 	DPP_TEST_INVALID_R_PROTO_KEY_AUTH_RESP = 67,
401 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 68,
402 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 69,
403 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 70,
404 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 71,
405 	DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 72,
406 	DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 73,
407 	DPP_TEST_INVALID_STATUS_AUTH_RESP = 74,
408 	DPP_TEST_INVALID_STATUS_AUTH_CONF = 75,
409 	DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ = 76,
410 	DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP = 77,
411 	DPP_TEST_INVALID_STATUS_PEER_DISC_RESP = 78,
412 	DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP = 79,
413 	DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ = 80,
414 	DPP_TEST_INVALID_I_NONCE_AUTH_REQ = 81,
415 	DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ = 82,
416 	DPP_TEST_INVALID_E_NONCE_CONF_REQ = 83,
417 	DPP_TEST_STOP_AT_PKEX_EXCHANGE_RESP = 84,
418 	DPP_TEST_STOP_AT_PKEX_CR_REQ = 85,
419 	DPP_TEST_STOP_AT_PKEX_CR_RESP = 86,
420 	DPP_TEST_STOP_AT_AUTH_REQ = 87,
421 	DPP_TEST_STOP_AT_AUTH_RESP = 88,
422 	DPP_TEST_STOP_AT_AUTH_CONF = 89,
423 	DPP_TEST_STOP_AT_CONF_REQ = 90,
424 	DPP_TEST_REJECT_CONFIG = 91,
425 };
426 
427 extern enum dpp_test_behavior dpp_test;
428 extern u8 dpp_pkex_own_mac_override[ETH_ALEN];
429 extern u8 dpp_pkex_peer_mac_override[ETH_ALEN];
430 extern u8 dpp_pkex_ephemeral_key_override[600];
431 extern size_t dpp_pkex_ephemeral_key_override_len;
432 extern u8 dpp_protocol_key_override[600];
433 extern size_t dpp_protocol_key_override_len;
434 extern u8 dpp_nonce_override[DPP_MAX_NONCE_LEN];
435 extern size_t dpp_nonce_override_len;
436 #endif /* CONFIG_WPA_TESTING_OPTIONS */
437 
438 void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
439 const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
440 int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
441 int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
442 			    const char *chan_list);
443 int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
444 int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
445 char * dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
446 		  u8 *privkey, size_t privkey_len);
447 struct hostapd_hw_modes;
448 struct dpp_authentication * dpp_auth_init(void *msg_ctx,
449 					  struct dpp_bootstrap_info *peer_bi,
450 					  struct dpp_bootstrap_info *own_bi,
451 					  u8 dpp_allowed_roles,
452 					  unsigned int neg_freq,
453 					  struct hostapd_hw_modes *own_modes,
454 					  u16 num_modes);
455 struct dpp_authentication *
456 dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
457 		struct dpp_bootstrap_info *peer_bi,
458 		struct dpp_bootstrap_info *own_bi,
459 		unsigned int freq, const u8 *hdr, const u8 *attr_start,
460 		size_t attr_len);
461 struct wpabuf *
462 dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
463 		 const u8 *attr_start, size_t attr_len);
464 struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
465 				   const char *json);
466 struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
467 					  const char *name,
468 					  enum dpp_netrole netrole,
469 					  const char *mud_url, int *opclasses);
470 int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
471 		     const u8 *attr_start, size_t attr_len);
472 int dpp_notify_new_qr_code(struct dpp_authentication *auth,
473 			   struct dpp_bootstrap_info *peer_bi);
474 struct dpp_configuration * dpp_configuration_alloc(const char *type);
475 int dpp_akm_psk(enum dpp_akm akm);
476 int dpp_akm_sae(enum dpp_akm akm);
477 int dpp_akm_legacy(enum dpp_akm akm);
478 int dpp_akm_dpp(enum dpp_akm akm);
479 int dpp_akm_ver2(enum dpp_akm akm);
480 int dpp_configuration_valid(const struct dpp_configuration *conf);
481 void dpp_configuration_free(struct dpp_configuration *conf);
482 int dpp_set_configurator(struct dpp_global *dpp, void *msg_ctx,
483 			 struct dpp_authentication *auth,
484 			 const char *cmd);
485 void dpp_auth_deinit(struct dpp_authentication *auth);
486 struct wpabuf *
487 dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
488 		size_t attr_len);
489 int dpp_conf_resp_rx(struct dpp_authentication *auth, const u8 *resp,
490 		             u32 resp_len);
491 enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth,
492 					 const u8 *hdr,
493 					 const u8 *attr_start, size_t attr_len);
494 struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth,
495 				      enum dpp_status_error status);
496 enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth,
497 						const u8 *hdr,
498 						const u8 *attr_start,
499 						size_t attr_len,
500 						u8 *ssid, size_t *ssid_len,
501 						char **channel_list);
502 struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth,
503 					     enum dpp_status_error result,
504 					     const u8 *ssid, size_t ssid_len,
505 					     const char *channel_list);
506 struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
507 			      size_t len);
508 const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
509 int dpp_check_attrs(const u8 *buf, size_t len);
510 int dpp_key_expired(const char *timestamp, os_time_t *expiry);
511 const char * dpp_akm_str(enum dpp_akm akm);
512 const char * dpp_akm_selector_str(enum dpp_akm akm);
513 int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf,
514 			     size_t buflen);
515 void dpp_configurator_free(struct dpp_configurator *conf);
516 struct dpp_configurator *
517 dpp_keygen_configurator(const char *curve, u8 *privkey,
518 			size_t privkey_len);
519 int dpp_configurator_own_config(struct dpp_authentication *auth,
520 				const char *curve, int ap);
521 enum dpp_status_error
522 dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
523 	       const u8 *net_access_key, size_t net_access_key_len,
524 	       const u8 *csign_key, size_t csign_key_len,
525 	       const u8 *peer_connector, size_t peer_connector_len,
526 	       os_time_t *expiry);
527 struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
528 				const u8 *own_mac,
529 				const char *identifier,
530 				const char *code);
531 struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
532 					   struct dpp_bootstrap_info *bi,
533 					   const u8 *own_mac,
534 					   const u8 *peer_mac,
535 					   const char *identifier,
536 					   const char *code,
537 					   const u8 *buf, size_t len);
538 struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
539 					  const u8 *peer_mac,
540 					  const u8 *buf, size_t len);
541 struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
542 					      const u8 *hdr,
543 					      const u8 *buf, size_t len);
544 int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
545 				   const u8 *buf, size_t len);
546 void dpp_pkex_free(struct dpp_pkex *pkex);
547 
548 char * dpp_corrupt_connector_signature(const char *connector);
549 
550 
551 struct dpp_pfs {
552 	struct crypto_ecdh *ecdh;
553 	const struct dpp_curve_params *curve;
554 	struct wpabuf *ie;
555 	struct wpabuf *secret;
556 };
557 
558 struct dpp_pfs * dpp_pfs_init(const u8 *net_access_key,
559 			      size_t net_access_key_len);
560 int dpp_pfs_process(struct dpp_pfs *pfs, const u8 *peer_ie, size_t peer_ie_len);
561 void dpp_pfs_free(struct dpp_pfs *pfs);
562 
563 struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp,
564 					    const char *uri);
565 struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp,
566 					    const char *uri);
567 int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd);
568 struct dpp_bootstrap_info *
569 dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id);
570 int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id);
571 struct dpp_bootstrap_info *
572 dpp_pkex_finish(struct dpp_global *dpp, struct dpp_pkex *pkex, const u8 *peer,
573 		unsigned int freq);
574 const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id);
575 int dpp_bootstrap_info(struct dpp_global *dpp, int id,
576 		       char *reply, int reply_size);
577 void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap,
578 			     const u8 *r_bootstrap,
579 			     struct dpp_bootstrap_info **own_bi,
580 			     struct dpp_bootstrap_info **peer_bi);
581 struct dpp_global_config {
582 	void *msg_ctx;
583 	void *cb_ctx;
584 	int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
585 };
586 
587 struct dpp_global * dpp_global_init(struct dpp_global_config *config);
588 void dpp_global_clear(struct dpp_global *dpp);
589 void dpp_global_deinit(struct dpp_global *dpp);
590 
591 #endif /* CONFIG_DPP */
592 #endif /* DPP_H */
593