blob: 585d39800b60ab596137891716d483cadb741ebc [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
2 * DPP functionality shared between hostapd and wpa_supplicant
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
Hai Shalomfdcde762020-04-02 11:19:20 -07004 * Copyright (c) 2018-2020, The Linux Foundation
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005 *
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
Hai Shalom021b0b52019-04-10 11:17:58 -070013#ifdef CONFIG_DPP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070014#include <openssl/x509.h>
15
16#include "utils/list.h"
17#include "common/wpa_common.h"
18#include "crypto/sha256.h"
19
Hai Shalom021b0b52019-04-10 11:17:58 -070020struct crypto_ecdh;
Hai Shalom81f62d82019-07-22 12:10:00 -070021struct hostapd_ip_addr;
Hai Shalom021b0b52019-04-10 11:17:58 -070022struct dpp_global;
23
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070024#define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
Hai Shalom81f62d82019-07-22 12:10:00 -070025#define DPP_TCP_PORT 7871
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070026
27enum dpp_public_action_frame_type {
28 DPP_PA_AUTHENTICATION_REQ = 0,
29 DPP_PA_AUTHENTICATION_RESP = 1,
30 DPP_PA_AUTHENTICATION_CONF = 2,
31 DPP_PA_PEER_DISCOVERY_REQ = 5,
32 DPP_PA_PEER_DISCOVERY_RESP = 6,
33 DPP_PA_PKEX_EXCHANGE_REQ = 7,
34 DPP_PA_PKEX_EXCHANGE_RESP = 8,
35 DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9,
36 DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10,
Hai Shalom021b0b52019-04-10 11:17:58 -070037 DPP_PA_CONFIGURATION_RESULT = 11,
Hai Shalomc3565922019-10-28 11:58:20 -070038 DPP_PA_CONNECTION_STATUS_RESULT = 12,
Hai Shalomfdcde762020-04-02 11:19:20 -070039 DPP_PA_PRESENCE_ANNOUNCEMENT = 13,
40 DPP_PA_RECONFIG_ANNOUNCEMENT = 14,
41 DPP_PA_RECONFIG_AUTH_REQ = 15,
42 DPP_PA_RECONFIG_AUTH_RESP = 16,
43 DPP_PA_RECONFIG_AUTH_CONF = 17,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070044};
45
46enum dpp_attribute_id {
47 DPP_ATTR_STATUS = 0x1000,
48 DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001,
49 DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002,
50 DPP_ATTR_I_PROTOCOL_KEY = 0x1003,
51 DPP_ATTR_WRAPPED_DATA = 0x1004,
52 DPP_ATTR_I_NONCE = 0x1005,
53 DPP_ATTR_I_CAPABILITIES = 0x1006,
54 DPP_ATTR_R_NONCE = 0x1007,
55 DPP_ATTR_R_CAPABILITIES = 0x1008,
56 DPP_ATTR_R_PROTOCOL_KEY = 0x1009,
57 DPP_ATTR_I_AUTH_TAG = 0x100A,
58 DPP_ATTR_R_AUTH_TAG = 0x100B,
59 DPP_ATTR_CONFIG_OBJ = 0x100C,
60 DPP_ATTR_CONNECTOR = 0x100D,
61 DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E,
62 DPP_ATTR_BOOTSTRAP_KEY = 0x100F,
63 DPP_ATTR_OWN_NET_NK_HASH = 0x1011,
64 DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012,
65 DPP_ATTR_ENCRYPTED_KEY = 0x1013,
66 DPP_ATTR_ENROLLEE_NONCE = 0x1014,
67 DPP_ATTR_CODE_IDENTIFIER = 0x1015,
68 DPP_ATTR_TRANSACTION_ID = 0x1016,
Roshan Pius3a1667e2018-07-03 15:17:14 -070069 DPP_ATTR_BOOTSTRAP_INFO = 0x1017,
70 DPP_ATTR_CHANNEL = 0x1018,
Hai Shalom021b0b52019-04-10 11:17:58 -070071 DPP_ATTR_PROTOCOL_VERSION = 0x1019,
72 DPP_ATTR_ENVELOPED_DATA = 0x101A,
Hai Shalomc3565922019-10-28 11:58:20 -070073 DPP_ATTR_SEND_CONN_STATUS = 0x101B,
74 DPP_ATTR_CONN_STATUS = 0x101C,
Hai Shalomfdcde762020-04-02 11:19:20 -070075 DPP_ATTR_RECONFIG_FLAGS = 0x101D,
76 DPP_ATTR_C_SIGN_KEY_HASH = 0x101E,
77 DPP_ATTR_CSR_ATTR_REQ = 0x101F,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070078};
79
80enum dpp_status_error {
81 DPP_STATUS_OK = 0,
82 DPP_STATUS_NOT_COMPATIBLE = 1,
83 DPP_STATUS_AUTH_FAILURE = 2,
84 DPP_STATUS_UNWRAP_FAILURE = 3,
85 DPP_STATUS_BAD_GROUP = 4,
86 DPP_STATUS_CONFIGURE_FAILURE = 5,
87 DPP_STATUS_RESPONSE_PENDING = 6,
Roshan Pius3a1667e2018-07-03 15:17:14 -070088 DPP_STATUS_INVALID_CONNECTOR = 7,
89 DPP_STATUS_NO_MATCH = 8,
Hai Shalom021b0b52019-04-10 11:17:58 -070090 DPP_STATUS_CONFIG_REJECTED = 9,
Hai Shalomc3565922019-10-28 11:58:20 -070091 DPP_STATUS_NO_AP = 10,
Hai Shalomfdcde762020-04-02 11:19:20 -070092 DPP_STATUS_CONFIGURE_PENDING = 11,
93 DPP_STATUS_CSR_NEEDED = 12,
94 DPP_STATUS_CSR_BAD = 13,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070095};
96
97#define DPP_CAPAB_ENROLLEE BIT(0)
98#define DPP_CAPAB_CONFIGURATOR BIT(1)
99#define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
100
101#define DPP_BOOTSTRAP_MAX_FREQ 30
102#define DPP_MAX_NONCE_LEN 32
103#define DPP_MAX_HASH_LEN 64
104#define DPP_MAX_SHARED_SECRET_LEN 66
105
106struct dpp_curve_params {
107 const char *name;
108 size_t hash_len;
109 size_t aes_siv_key_len;
110 size_t nonce_len;
111 size_t prime_len;
112 const char *jwk_crv;
113 u16 ike_group;
114 const char *jws_alg;
115};
116
117enum dpp_bootstrap_type {
118 DPP_BOOTSTRAP_QR_CODE,
119 DPP_BOOTSTRAP_PKEX,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800120 DPP_BOOTSTRAP_NFC_URI,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700121};
122
123struct dpp_bootstrap_info {
124 struct dl_list list;
125 unsigned int id;
126 enum dpp_bootstrap_type type;
127 char *uri;
128 u8 mac_addr[ETH_ALEN];
Hai Shalomfdcde762020-04-02 11:19:20 -0700129 char *chan;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700130 char *info;
Hai Shalomfdcde762020-04-02 11:19:20 -0700131 char *pk;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700132 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
133 unsigned int num_freq;
134 int own;
135 EVP_PKEY *pubkey;
136 u8 pubkey_hash[SHA256_MAC_LEN];
Hai Shalomfdcde762020-04-02 11:19:20 -0700137 u8 pubkey_hash_chirp[SHA256_MAC_LEN];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700138 const struct dpp_curve_params *curve;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700139 unsigned int pkex_t; /* number of failures before dpp_pkex
140 * instantiation */
Hai Shalomb755a2a2020-04-23 21:49:02 -0700141 int nfc_negotiated; /* whether this has been used in NFC negotiated
142 * connection handover */
Hai Shalomfdcde762020-04-02 11:19:20 -0700143 char *configurator_params;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700144};
145
Roshan Pius3a1667e2018-07-03 15:17:14 -0700146#define PKEX_COUNTER_T_LIMIT 5
147
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700148struct dpp_pkex {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700149 void *msg_ctx;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700150 unsigned int initiator:1;
151 unsigned int exchange_done:1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700152 unsigned int failed:1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700153 struct dpp_bootstrap_info *own_bi;
154 u8 own_mac[ETH_ALEN];
155 u8 peer_mac[ETH_ALEN];
156 char *identifier;
157 char *code;
158 EVP_PKEY *x;
159 EVP_PKEY *y;
160 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
161 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
162 u8 z[DPP_MAX_HASH_LEN];
163 EVP_PKEY *peer_bootstrap_key;
164 struct wpabuf *exchange_req;
165 struct wpabuf *exchange_resp;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700166 unsigned int t; /* number of failures on code use */
167 unsigned int exch_req_wait_time;
168 unsigned int exch_req_tries;
169 unsigned int freq;
170};
171
172enum dpp_akm {
173 DPP_AKM_UNKNOWN,
174 DPP_AKM_DPP,
175 DPP_AKM_PSK,
176 DPP_AKM_SAE,
Hai Shalom021b0b52019-04-10 11:17:58 -0700177 DPP_AKM_PSK_SAE,
178 DPP_AKM_SAE_DPP,
179 DPP_AKM_PSK_SAE_DPP,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700180};
181
Hai Shalomc3565922019-10-28 11:58:20 -0700182enum dpp_netrole {
183 DPP_NETROLE_STA,
184 DPP_NETROLE_AP,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800185 DPP_NETROLE_CONFIGURATOR,
Hai Shalomc3565922019-10-28 11:58:20 -0700186};
187
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700188struct dpp_configuration {
189 u8 ssid[32];
190 size_t ssid_len;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800191 int ssid_charset;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700192 enum dpp_akm akm;
Hai Shalomc3565922019-10-28 11:58:20 -0700193 enum dpp_netrole netrole;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700194
195 /* For DPP configuration (connector) */
196 os_time_t netaccesskey_expiry;
197
198 /* TODO: groups */
Hai Shalomce48b4a2018-09-05 11:41:35 -0700199 char *group_id;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700200
201 /* For legacy configuration */
202 char *passphrase;
203 u8 psk[32];
Hai Shalom021b0b52019-04-10 11:17:58 -0700204 int psk_set;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700205};
206
Hai Shalomfdcde762020-04-02 11:19:20 -0700207struct dpp_asymmetric_key {
208 struct dpp_asymmetric_key *next;
209 EVP_PKEY *csign;
210 char *config_template;
211 char *connector_template;
212};
213
Hai Shalomc3565922019-10-28 11:58:20 -0700214#define DPP_MAX_CONF_OBJ 10
Hai Shalom06768112019-12-04 15:49:43 -0800215#define DPP_MAX_CHANNELS 32
Hai Shalomc3565922019-10-28 11:58:20 -0700216
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700217struct dpp_authentication {
Hai Shalomfdcde762020-04-02 11:19:20 -0700218 struct dpp_global *global;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700219 void *msg_ctx;
Hai Shalom021b0b52019-04-10 11:17:58 -0700220 u8 peer_version;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700221 const struct dpp_curve_params *curve;
222 struct dpp_bootstrap_info *peer_bi;
223 struct dpp_bootstrap_info *own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700224 struct dpp_bootstrap_info *tmp_own_bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700225 u8 waiting_pubkey_hash[SHA256_MAC_LEN];
226 int response_pending;
227 enum dpp_status_error auth_resp_status;
Hai Shalom021b0b52019-04-10 11:17:58 -0700228 enum dpp_status_error conf_resp_status;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700229 u8 peer_mac_addr[ETH_ALEN];
230 u8 i_nonce[DPP_MAX_NONCE_LEN];
231 u8 r_nonce[DPP_MAX_NONCE_LEN];
232 u8 e_nonce[DPP_MAX_NONCE_LEN];
233 u8 i_capab;
234 u8 r_capab;
235 EVP_PKEY *own_protocol_key;
236 EVP_PKEY *peer_protocol_key;
237 struct wpabuf *req_msg;
238 struct wpabuf *resp_msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700239 /* Intersection of possible frequencies for initiating DPP
240 * Authentication exchange */
241 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
242 unsigned int num_freq, freq_idx;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700243 unsigned int curr_freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700244 unsigned int neg_freq;
245 unsigned int num_freq_iters;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700246 size_t secret_len;
247 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700248 size_t Mx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700249 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700250 size_t Nx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700251 u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700252 size_t Lx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700253 u8 k1[DPP_MAX_HASH_LEN];
254 u8 k2[DPP_MAX_HASH_LEN];
255 u8 ke[DPP_MAX_HASH_LEN];
256 int initiator;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700257 int waiting_auth_resp;
258 int waiting_auth_conf;
259 int auth_req_ack;
260 unsigned int auth_resp_tries;
261 u8 allowed_roles;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700262 int configurator;
263 int remove_on_tx_status;
Hai Shalom021b0b52019-04-10 11:17:58 -0700264 int connect_on_tx_status;
265 int waiting_conf_result;
Hai Shalomc3565922019-10-28 11:58:20 -0700266 int waiting_conn_status_result;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700267 int auth_success;
268 struct wpabuf *conf_req;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700269 const struct wpabuf *conf_resp; /* owned by GAS server */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700270 struct dpp_configuration *conf_ap;
Hai Shalomc3565922019-10-28 11:58:20 -0700271 struct dpp_configuration *conf2_ap;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700272 struct dpp_configuration *conf_sta;
Hai Shalomc3565922019-10-28 11:58:20 -0700273 struct dpp_configuration *conf2_sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700274 int provision_configurator;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700275 struct dpp_configurator *conf;
Hai Shalomc3565922019-10-28 11:58:20 -0700276 struct dpp_config_obj {
277 char *connector; /* received signedConnector */
278 u8 ssid[SSID_MAX_LEN];
279 u8 ssid_len;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800280 int ssid_charset;
Hai Shalomc3565922019-10-28 11:58:20 -0700281 char passphrase[64];
282 u8 psk[PMK_LEN];
283 int psk_set;
284 enum dpp_akm akm;
285 struct wpabuf *c_sign_key;
286 } conf_obj[DPP_MAX_CONF_OBJ];
287 unsigned int num_conf_obj;
Hai Shalomfdcde762020-04-02 11:19:20 -0700288 struct dpp_asymmetric_key *conf_key_pkg;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700289 struct wpabuf *net_access_key;
290 os_time_t net_access_key_expiry;
Hai Shalomc3565922019-10-28 11:58:20 -0700291 int send_conn_status;
292 int conn_status_requested;
293 int akm_use_selector;
Hai Shalomfdcde762020-04-02 11:19:20 -0700294 int configurator_set;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700295#ifdef CONFIG_TESTING_OPTIONS
296 char *config_obj_override;
297 char *discovery_override;
298 char *groups_override;
299 unsigned int ignore_netaccesskey_mismatch:1;
300#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom06768112019-12-04 15:49:43 -0800301 unsigned short band_list[DPP_MAX_CHANNELS];
302 int band_list_size;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700303};
304
305struct dpp_configurator {
306 struct dl_list list;
307 unsigned int id;
308 int own;
309 EVP_PKEY *csign;
310 char *kid;
311 const struct dpp_curve_params *curve;
312};
313
314struct dpp_introduction {
315 u8 pmkid[PMKID_LEN];
316 u8 pmk[PMK_LEN_MAX];
317 size_t pmk_len;
318};
319
Hai Shalom81f62d82019-07-22 12:10:00 -0700320struct dpp_relay_config {
321 const struct hostapd_ip_addr *ipaddr;
322 const u8 *pkhash;
323
324 void *cb_ctx;
325 void (*tx)(void *ctx, const u8 *addr, unsigned int freq, const u8 *msg,
326 size_t len);
327 void (*gas_resp_tx)(void *ctx, const u8 *addr, u8 dialog_token, int prot,
328 struct wpabuf *buf);
329};
330
331struct dpp_controller_config {
332 const char *configurator_params;
333 int tcp_port;
334};
335
Roshan Pius3a1667e2018-07-03 15:17:14 -0700336#ifdef CONFIG_TESTING_OPTIONS
337enum dpp_test_behavior {
338 DPP_TEST_DISABLED = 0,
339 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
340 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
341 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
342 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
343 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
344 DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
345 DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
346 DPP_TEST_ZERO_I_CAPAB = 8,
347 DPP_TEST_ZERO_R_CAPAB = 9,
348 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
349 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
350 DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
351 DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
352 DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
353 DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
354 DPP_TEST_NO_STATUS_AUTH_RESP = 16,
355 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
356 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
357 DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
358 DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
359 DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
360 DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
361 DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
362 DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
363 DPP_TEST_NO_STATUS_AUTH_CONF = 25,
364 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
365 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
366 DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
367 DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
368 DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
369 DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
370 DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
371 DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
372 DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
373 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
374 DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
375 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
376 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
377 DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
378 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
379 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
380 DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
381 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
382 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
383 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
384 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
385 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
386 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
387 DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
388 DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
389 DPP_TEST_NO_E_NONCE_CONF_REQ = 51,
390 DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52,
391 DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53,
392 DPP_TEST_NO_E_NONCE_CONF_RESP = 54,
393 DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55,
394 DPP_TEST_NO_STATUS_CONF_RESP = 56,
395 DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57,
396 DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
397 DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
398 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60,
399 DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61,
400 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62,
401 DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63,
402 DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64,
403 DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65,
404 DPP_TEST_INVALID_I_PROTO_KEY_AUTH_REQ = 66,
405 DPP_TEST_INVALID_R_PROTO_KEY_AUTH_RESP = 67,
406 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 68,
407 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 69,
408 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 70,
409 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 71,
410 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 72,
411 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 73,
412 DPP_TEST_INVALID_STATUS_AUTH_RESP = 74,
413 DPP_TEST_INVALID_STATUS_AUTH_CONF = 75,
414 DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ = 76,
415 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP = 77,
416 DPP_TEST_INVALID_STATUS_PEER_DISC_RESP = 78,
417 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP = 79,
418 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ = 80,
419 DPP_TEST_INVALID_I_NONCE_AUTH_REQ = 81,
420 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ = 82,
421 DPP_TEST_INVALID_E_NONCE_CONF_REQ = 83,
422 DPP_TEST_STOP_AT_PKEX_EXCHANGE_RESP = 84,
423 DPP_TEST_STOP_AT_PKEX_CR_REQ = 85,
424 DPP_TEST_STOP_AT_PKEX_CR_RESP = 86,
425 DPP_TEST_STOP_AT_AUTH_REQ = 87,
426 DPP_TEST_STOP_AT_AUTH_RESP = 88,
427 DPP_TEST_STOP_AT_AUTH_CONF = 89,
428 DPP_TEST_STOP_AT_CONF_REQ = 90,
Hai Shalom021b0b52019-04-10 11:17:58 -0700429 DPP_TEST_REJECT_CONFIG = 91,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700430};
431
432extern enum dpp_test_behavior dpp_test;
433extern u8 dpp_pkex_own_mac_override[ETH_ALEN];
434extern u8 dpp_pkex_peer_mac_override[ETH_ALEN];
435extern u8 dpp_pkex_ephemeral_key_override[600];
436extern size_t dpp_pkex_ephemeral_key_override_len;
437extern u8 dpp_protocol_key_override[600];
438extern size_t dpp_protocol_key_override_len;
439extern u8 dpp_nonce_override[DPP_MAX_NONCE_LEN];
440extern size_t dpp_nonce_override_len;
441#endif /* CONFIG_TESTING_OPTIONS */
442
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700443void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
444const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700445int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
446 const char *chan_list);
447int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
448int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
Hai Shalomfdcde762020-04-02 11:19:20 -0700449int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi,
450 struct dpp_bootstrap_info *peer_bi);
451struct dpp_authentication *
452dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700453struct hostapd_hw_modes;
Hai Shalomfdcde762020-04-02 11:19:20 -0700454struct dpp_authentication * dpp_auth_init(struct dpp_global *dpp, void *msg_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700455 struct dpp_bootstrap_info *peer_bi,
456 struct dpp_bootstrap_info *own_bi,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700457 u8 dpp_allowed_roles,
458 unsigned int neg_freq,
459 struct hostapd_hw_modes *own_modes,
460 u16 num_modes);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700461struct dpp_authentication *
Hai Shalomfdcde762020-04-02 11:19:20 -0700462dpp_auth_req_rx(struct dpp_global *dpp, void *msg_ctx, u8 dpp_allowed_roles,
463 int qr_mutual, struct dpp_bootstrap_info *peer_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700464 struct dpp_bootstrap_info *own_bi,
465 unsigned int freq, const u8 *hdr, const u8 *attr_start,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700466 size_t attr_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700467struct wpabuf *
468dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
469 const u8 *attr_start, size_t attr_len);
470struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
471 const char *json);
Hai Shalomc3565922019-10-28 11:58:20 -0700472struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800473 const char *name,
474 enum dpp_netrole netrole,
Hai Shalomc3565922019-10-28 11:58:20 -0700475 const char *mud_url, int *opclasses);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700476int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
477 const u8 *attr_start, size_t attr_len);
478int dpp_notify_new_qr_code(struct dpp_authentication *auth,
479 struct dpp_bootstrap_info *peer_bi);
Hai Shalom021b0b52019-04-10 11:17:58 -0700480struct dpp_configuration * dpp_configuration_alloc(const char *type);
481int dpp_akm_psk(enum dpp_akm akm);
482int dpp_akm_sae(enum dpp_akm akm);
483int dpp_akm_legacy(enum dpp_akm akm);
484int dpp_akm_dpp(enum dpp_akm akm);
485int dpp_akm_ver2(enum dpp_akm akm);
486int dpp_configuration_valid(const struct dpp_configuration *conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700487void dpp_configuration_free(struct dpp_configuration *conf);
Hai Shalomfdcde762020-04-02 11:19:20 -0700488int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700489void dpp_auth_deinit(struct dpp_authentication *auth);
490struct wpabuf *
491dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
492 size_t attr_len);
493int dpp_conf_resp_rx(struct dpp_authentication *auth,
494 const struct wpabuf *resp);
Hai Shalom021b0b52019-04-10 11:17:58 -0700495enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth,
496 const u8 *hdr,
497 const u8 *attr_start, size_t attr_len);
498struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth,
499 enum dpp_status_error status);
Hai Shalomc3565922019-10-28 11:58:20 -0700500enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth,
501 const u8 *hdr,
502 const u8 *attr_start,
503 size_t attr_len,
504 u8 *ssid, size_t *ssid_len,
505 char **channel_list);
506struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth,
507 enum dpp_status_error result,
508 const u8 *ssid, size_t ssid_len,
509 const char *channel_list);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700510struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
511 size_t len);
512const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
513int dpp_check_attrs(const u8 *buf, size_t len);
514int dpp_key_expired(const char *timestamp, os_time_t *expiry);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700515const char * dpp_akm_str(enum dpp_akm akm);
Hai Shalomc3565922019-10-28 11:58:20 -0700516const char * dpp_akm_selector_str(enum dpp_akm akm);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700517int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf,
518 size_t buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700519void dpp_configurator_free(struct dpp_configurator *conf);
520struct dpp_configurator *
521dpp_keygen_configurator(const char *curve, const u8 *privkey,
522 size_t privkey_len);
523int dpp_configurator_own_config(struct dpp_authentication *auth,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700524 const char *curve, int ap);
525enum dpp_status_error
526dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
527 const u8 *net_access_key, size_t net_access_key_len,
528 const u8 *csign_key, size_t csign_key_len,
529 const u8 *peer_connector, size_t peer_connector_len,
530 os_time_t *expiry);
531struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700532 const u8 *own_mac,
533 const char *identifier,
534 const char *code);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700535struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
536 struct dpp_bootstrap_info *bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700537 const u8 *own_mac,
538 const u8 *peer_mac,
539 const char *identifier,
540 const char *code,
541 const u8 *buf, size_t len);
542struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700543 const u8 *peer_mac,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700544 const u8 *buf, size_t len);
545struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
546 const u8 *hdr,
547 const u8 *buf, size_t len);
548int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
549 const u8 *buf, size_t len);
550void dpp_pkex_free(struct dpp_pkex *pkex);
551
Roshan Pius3a1667e2018-07-03 15:17:14 -0700552char * dpp_corrupt_connector_signature(const char *connector);
553
Hai Shalom021b0b52019-04-10 11:17:58 -0700554
555struct dpp_pfs {
556 struct crypto_ecdh *ecdh;
557 const struct dpp_curve_params *curve;
558 struct wpabuf *ie;
559 struct wpabuf *secret;
560};
561
562struct dpp_pfs * dpp_pfs_init(const u8 *net_access_key,
563 size_t net_access_key_len);
564int dpp_pfs_process(struct dpp_pfs *pfs, const u8 *peer_ie, size_t peer_ie_len);
565void dpp_pfs_free(struct dpp_pfs *pfs);
566
567struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp,
568 const char *uri);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800569struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp,
570 const char *uri);
Hai Shalom021b0b52019-04-10 11:17:58 -0700571int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd);
572struct dpp_bootstrap_info *
573dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id);
574int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id);
575struct dpp_bootstrap_info *
576dpp_pkex_finish(struct dpp_global *dpp, struct dpp_pkex *pkex, const u8 *peer,
577 unsigned int freq);
578const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id);
579int dpp_bootstrap_info(struct dpp_global *dpp, int id,
580 char *reply, int reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -0700581int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params);
Hai Shalom021b0b52019-04-10 11:17:58 -0700582void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap,
583 const u8 *r_bootstrap,
584 struct dpp_bootstrap_info **own_bi,
585 struct dpp_bootstrap_info **peer_bi);
Hai Shalomfdcde762020-04-02 11:19:20 -0700586struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp,
587 const u8 *hash);
Hai Shalom021b0b52019-04-10 11:17:58 -0700588int dpp_configurator_add(struct dpp_global *dpp, const char *cmd);
589int dpp_configurator_remove(struct dpp_global *dpp, const char *id);
590int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id,
591 char *buf, size_t buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -0700592int dpp_configurator_from_backup(struct dpp_global *dpp,
593 struct dpp_asymmetric_key *key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700594int dpp_relay_add_controller(struct dpp_global *dpp,
595 struct dpp_relay_config *config);
596int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr,
597 const u8 *buf, size_t len, unsigned int freq,
598 const u8 *i_bootstrap, const u8 *r_bootstrap);
599int dpp_relay_rx_gas_req(struct dpp_global *dpp, const u8 *src, const u8 *data,
600 size_t data_len);
601int dpp_controller_start(struct dpp_global *dpp,
602 struct dpp_controller_config *config);
603void dpp_controller_stop(struct dpp_global *dpp);
604int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth,
605 const struct hostapd_ip_addr *addr, int port);
Hai Shalomfdcde762020-04-02 11:19:20 -0700606struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700607
608struct dpp_global_config {
609 void *msg_ctx;
610 void *cb_ctx;
611 int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
Hai Shalomfdcde762020-04-02 11:19:20 -0700612 void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700613};
614
615struct dpp_global * dpp_global_init(struct dpp_global_config *config);
Hai Shalom021b0b52019-04-10 11:17:58 -0700616void dpp_global_clear(struct dpp_global *dpp);
617void dpp_global_deinit(struct dpp_global *dpp);
618
619#endif /* CONFIG_DPP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700620#endif /* DPP_H */