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