blob: ab3f92719cdb6529ab7b2e625b71ecac72edb4aa [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 Shalomfdcde762020-04-02 11:19:20 -0700141 char *configurator_params;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700142};
143
Roshan Pius3a1667e2018-07-03 15:17:14 -0700144#define PKEX_COUNTER_T_LIMIT 5
145
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700146struct dpp_pkex {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700147 void *msg_ctx;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700148 unsigned int initiator:1;
149 unsigned int exchange_done:1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700150 unsigned int failed:1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700151 struct dpp_bootstrap_info *own_bi;
152 u8 own_mac[ETH_ALEN];
153 u8 peer_mac[ETH_ALEN];
154 char *identifier;
155 char *code;
156 EVP_PKEY *x;
157 EVP_PKEY *y;
158 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
159 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
160 u8 z[DPP_MAX_HASH_LEN];
161 EVP_PKEY *peer_bootstrap_key;
162 struct wpabuf *exchange_req;
163 struct wpabuf *exchange_resp;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700164 unsigned int t; /* number of failures on code use */
165 unsigned int exch_req_wait_time;
166 unsigned int exch_req_tries;
167 unsigned int freq;
168};
169
170enum dpp_akm {
171 DPP_AKM_UNKNOWN,
172 DPP_AKM_DPP,
173 DPP_AKM_PSK,
174 DPP_AKM_SAE,
Hai Shalom021b0b52019-04-10 11:17:58 -0700175 DPP_AKM_PSK_SAE,
176 DPP_AKM_SAE_DPP,
177 DPP_AKM_PSK_SAE_DPP,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700178};
179
Hai Shalomc3565922019-10-28 11:58:20 -0700180enum dpp_netrole {
181 DPP_NETROLE_STA,
182 DPP_NETROLE_AP,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800183 DPP_NETROLE_CONFIGURATOR,
Hai Shalomc3565922019-10-28 11:58:20 -0700184};
185
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700186struct dpp_configuration {
187 u8 ssid[32];
188 size_t ssid_len;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800189 int ssid_charset;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700190 enum dpp_akm akm;
Hai Shalomc3565922019-10-28 11:58:20 -0700191 enum dpp_netrole netrole;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700192
193 /* For DPP configuration (connector) */
194 os_time_t netaccesskey_expiry;
195
196 /* TODO: groups */
Hai Shalomce48b4a2018-09-05 11:41:35 -0700197 char *group_id;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700198
199 /* For legacy configuration */
200 char *passphrase;
201 u8 psk[32];
Hai Shalom021b0b52019-04-10 11:17:58 -0700202 int psk_set;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700203};
204
Hai Shalomfdcde762020-04-02 11:19:20 -0700205struct dpp_asymmetric_key {
206 struct dpp_asymmetric_key *next;
207 EVP_PKEY *csign;
208 char *config_template;
209 char *connector_template;
210};
211
Hai Shalomc3565922019-10-28 11:58:20 -0700212#define DPP_MAX_CONF_OBJ 10
Hai Shalom06768112019-12-04 15:49:43 -0800213#define DPP_MAX_CHANNELS 32
Hai Shalomc3565922019-10-28 11:58:20 -0700214
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700215struct dpp_authentication {
Hai Shalomfdcde762020-04-02 11:19:20 -0700216 struct dpp_global *global;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700217 void *msg_ctx;
Hai Shalom021b0b52019-04-10 11:17:58 -0700218 u8 peer_version;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700219 const struct dpp_curve_params *curve;
220 struct dpp_bootstrap_info *peer_bi;
221 struct dpp_bootstrap_info *own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700222 struct dpp_bootstrap_info *tmp_own_bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700223 u8 waiting_pubkey_hash[SHA256_MAC_LEN];
224 int response_pending;
225 enum dpp_status_error auth_resp_status;
Hai Shalom021b0b52019-04-10 11:17:58 -0700226 enum dpp_status_error conf_resp_status;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700227 u8 peer_mac_addr[ETH_ALEN];
228 u8 i_nonce[DPP_MAX_NONCE_LEN];
229 u8 r_nonce[DPP_MAX_NONCE_LEN];
230 u8 e_nonce[DPP_MAX_NONCE_LEN];
231 u8 i_capab;
232 u8 r_capab;
233 EVP_PKEY *own_protocol_key;
234 EVP_PKEY *peer_protocol_key;
235 struct wpabuf *req_msg;
236 struct wpabuf *resp_msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700237 /* Intersection of possible frequencies for initiating DPP
238 * Authentication exchange */
239 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
240 unsigned int num_freq, freq_idx;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700241 unsigned int curr_freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700242 unsigned int neg_freq;
243 unsigned int num_freq_iters;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700244 size_t secret_len;
245 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700246 size_t Mx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700247 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700248 size_t Nx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700249 u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700250 size_t Lx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700251 u8 k1[DPP_MAX_HASH_LEN];
252 u8 k2[DPP_MAX_HASH_LEN];
253 u8 ke[DPP_MAX_HASH_LEN];
254 int initiator;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700255 int waiting_auth_resp;
256 int waiting_auth_conf;
257 int auth_req_ack;
258 unsigned int auth_resp_tries;
259 u8 allowed_roles;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700260 int configurator;
261 int remove_on_tx_status;
Hai Shalom021b0b52019-04-10 11:17:58 -0700262 int connect_on_tx_status;
263 int waiting_conf_result;
Hai Shalomc3565922019-10-28 11:58:20 -0700264 int waiting_conn_status_result;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700265 int auth_success;
266 struct wpabuf *conf_req;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700267 const struct wpabuf *conf_resp; /* owned by GAS server */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700268 struct dpp_configuration *conf_ap;
Hai Shalomc3565922019-10-28 11:58:20 -0700269 struct dpp_configuration *conf2_ap;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700270 struct dpp_configuration *conf_sta;
Hai Shalomc3565922019-10-28 11:58:20 -0700271 struct dpp_configuration *conf2_sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700272 int provision_configurator;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700273 struct dpp_configurator *conf;
Hai Shalomc3565922019-10-28 11:58:20 -0700274 struct dpp_config_obj {
275 char *connector; /* received signedConnector */
276 u8 ssid[SSID_MAX_LEN];
277 u8 ssid_len;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800278 int ssid_charset;
Hai Shalomc3565922019-10-28 11:58:20 -0700279 char passphrase[64];
280 u8 psk[PMK_LEN];
281 int psk_set;
282 enum dpp_akm akm;
283 struct wpabuf *c_sign_key;
284 } conf_obj[DPP_MAX_CONF_OBJ];
285 unsigned int num_conf_obj;
Hai Shalomfdcde762020-04-02 11:19:20 -0700286 struct dpp_asymmetric_key *conf_key_pkg;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700287 struct wpabuf *net_access_key;
288 os_time_t net_access_key_expiry;
Hai Shalomc3565922019-10-28 11:58:20 -0700289 int send_conn_status;
290 int conn_status_requested;
291 int akm_use_selector;
Hai Shalomfdcde762020-04-02 11:19:20 -0700292 int configurator_set;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700293#ifdef CONFIG_TESTING_OPTIONS
294 char *config_obj_override;
295 char *discovery_override;
296 char *groups_override;
297 unsigned int ignore_netaccesskey_mismatch:1;
298#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom06768112019-12-04 15:49:43 -0800299 unsigned short band_list[DPP_MAX_CHANNELS];
300 int band_list_size;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700301};
302
303struct dpp_configurator {
304 struct dl_list list;
305 unsigned int id;
306 int own;
307 EVP_PKEY *csign;
308 char *kid;
309 const struct dpp_curve_params *curve;
310};
311
312struct dpp_introduction {
313 u8 pmkid[PMKID_LEN];
314 u8 pmk[PMK_LEN_MAX];
315 size_t pmk_len;
316};
317
Hai Shalom81f62d82019-07-22 12:10:00 -0700318struct dpp_relay_config {
319 const struct hostapd_ip_addr *ipaddr;
320 const u8 *pkhash;
321
322 void *cb_ctx;
323 void (*tx)(void *ctx, const u8 *addr, unsigned int freq, const u8 *msg,
324 size_t len);
325 void (*gas_resp_tx)(void *ctx, const u8 *addr, u8 dialog_token, int prot,
326 struct wpabuf *buf);
327};
328
329struct dpp_controller_config {
330 const char *configurator_params;
331 int tcp_port;
332};
333
Roshan Pius3a1667e2018-07-03 15:17:14 -0700334#ifdef CONFIG_TESTING_OPTIONS
335enum dpp_test_behavior {
336 DPP_TEST_DISABLED = 0,
337 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
338 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
339 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
340 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
341 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
342 DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
343 DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
344 DPP_TEST_ZERO_I_CAPAB = 8,
345 DPP_TEST_ZERO_R_CAPAB = 9,
346 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
347 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
348 DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
349 DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
350 DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
351 DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
352 DPP_TEST_NO_STATUS_AUTH_RESP = 16,
353 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
354 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
355 DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
356 DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
357 DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
358 DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
359 DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
360 DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
361 DPP_TEST_NO_STATUS_AUTH_CONF = 25,
362 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
363 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
364 DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
365 DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
366 DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
367 DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
368 DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
369 DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
370 DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
371 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
372 DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
373 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
374 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
375 DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
376 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
377 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
378 DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
379 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
380 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
381 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
382 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
383 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
384 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
385 DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
386 DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
387 DPP_TEST_NO_E_NONCE_CONF_REQ = 51,
388 DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52,
389 DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53,
390 DPP_TEST_NO_E_NONCE_CONF_RESP = 54,
391 DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55,
392 DPP_TEST_NO_STATUS_CONF_RESP = 56,
393 DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57,
394 DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
395 DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
396 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60,
397 DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61,
398 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62,
399 DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63,
400 DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64,
401 DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65,
402 DPP_TEST_INVALID_I_PROTO_KEY_AUTH_REQ = 66,
403 DPP_TEST_INVALID_R_PROTO_KEY_AUTH_RESP = 67,
404 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 68,
405 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 69,
406 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 70,
407 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 71,
408 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 72,
409 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 73,
410 DPP_TEST_INVALID_STATUS_AUTH_RESP = 74,
411 DPP_TEST_INVALID_STATUS_AUTH_CONF = 75,
412 DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ = 76,
413 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP = 77,
414 DPP_TEST_INVALID_STATUS_PEER_DISC_RESP = 78,
415 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP = 79,
416 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ = 80,
417 DPP_TEST_INVALID_I_NONCE_AUTH_REQ = 81,
418 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ = 82,
419 DPP_TEST_INVALID_E_NONCE_CONF_REQ = 83,
420 DPP_TEST_STOP_AT_PKEX_EXCHANGE_RESP = 84,
421 DPP_TEST_STOP_AT_PKEX_CR_REQ = 85,
422 DPP_TEST_STOP_AT_PKEX_CR_RESP = 86,
423 DPP_TEST_STOP_AT_AUTH_REQ = 87,
424 DPP_TEST_STOP_AT_AUTH_RESP = 88,
425 DPP_TEST_STOP_AT_AUTH_CONF = 89,
426 DPP_TEST_STOP_AT_CONF_REQ = 90,
Hai Shalom021b0b52019-04-10 11:17:58 -0700427 DPP_TEST_REJECT_CONFIG = 91,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700428};
429
430extern enum dpp_test_behavior dpp_test;
431extern u8 dpp_pkex_own_mac_override[ETH_ALEN];
432extern u8 dpp_pkex_peer_mac_override[ETH_ALEN];
433extern u8 dpp_pkex_ephemeral_key_override[600];
434extern size_t dpp_pkex_ephemeral_key_override_len;
435extern u8 dpp_protocol_key_override[600];
436extern size_t dpp_protocol_key_override_len;
437extern u8 dpp_nonce_override[DPP_MAX_NONCE_LEN];
438extern size_t dpp_nonce_override_len;
439#endif /* CONFIG_TESTING_OPTIONS */
440
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700441void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
442const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700443int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
444 const char *chan_list);
445int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
446int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
Hai Shalomfdcde762020-04-02 11:19:20 -0700447int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi,
448 struct dpp_bootstrap_info *peer_bi);
449struct dpp_authentication *
450dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700451struct hostapd_hw_modes;
Hai Shalomfdcde762020-04-02 11:19:20 -0700452struct dpp_authentication * dpp_auth_init(struct dpp_global *dpp, void *msg_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700453 struct dpp_bootstrap_info *peer_bi,
454 struct dpp_bootstrap_info *own_bi,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700455 u8 dpp_allowed_roles,
456 unsigned int neg_freq,
457 struct hostapd_hw_modes *own_modes,
458 u16 num_modes);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700459struct dpp_authentication *
Hai Shalomfdcde762020-04-02 11:19:20 -0700460dpp_auth_req_rx(struct dpp_global *dpp, void *msg_ctx, u8 dpp_allowed_roles,
461 int qr_mutual, struct dpp_bootstrap_info *peer_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700462 struct dpp_bootstrap_info *own_bi,
463 unsigned int freq, const u8 *hdr, const u8 *attr_start,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700464 size_t attr_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700465struct wpabuf *
466dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
467 const u8 *attr_start, size_t attr_len);
468struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
469 const char *json);
Hai Shalomc3565922019-10-28 11:58:20 -0700470struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800471 const char *name,
472 enum dpp_netrole netrole,
Hai Shalomc3565922019-10-28 11:58:20 -0700473 const char *mud_url, int *opclasses);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700474int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
475 const u8 *attr_start, size_t attr_len);
476int dpp_notify_new_qr_code(struct dpp_authentication *auth,
477 struct dpp_bootstrap_info *peer_bi);
Hai Shalom021b0b52019-04-10 11:17:58 -0700478struct dpp_configuration * dpp_configuration_alloc(const char *type);
479int dpp_akm_psk(enum dpp_akm akm);
480int dpp_akm_sae(enum dpp_akm akm);
481int dpp_akm_legacy(enum dpp_akm akm);
482int dpp_akm_dpp(enum dpp_akm akm);
483int dpp_akm_ver2(enum dpp_akm akm);
484int dpp_configuration_valid(const struct dpp_configuration *conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700485void dpp_configuration_free(struct dpp_configuration *conf);
Hai Shalomfdcde762020-04-02 11:19:20 -0700486int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700487void dpp_auth_deinit(struct dpp_authentication *auth);
488struct wpabuf *
489dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
490 size_t attr_len);
491int dpp_conf_resp_rx(struct dpp_authentication *auth,
492 const struct wpabuf *resp);
Hai Shalom021b0b52019-04-10 11:17:58 -0700493enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth,
494 const u8 *hdr,
495 const u8 *attr_start, size_t attr_len);
496struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth,
497 enum dpp_status_error status);
Hai Shalomc3565922019-10-28 11:58:20 -0700498enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth,
499 const u8 *hdr,
500 const u8 *attr_start,
501 size_t attr_len,
502 u8 *ssid, size_t *ssid_len,
503 char **channel_list);
504struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth,
505 enum dpp_status_error result,
506 const u8 *ssid, size_t ssid_len,
507 const char *channel_list);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700508struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
509 size_t len);
510const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
511int dpp_check_attrs(const u8 *buf, size_t len);
512int dpp_key_expired(const char *timestamp, os_time_t *expiry);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700513const char * dpp_akm_str(enum dpp_akm akm);
Hai Shalomc3565922019-10-28 11:58:20 -0700514const char * dpp_akm_selector_str(enum dpp_akm akm);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700515int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf,
516 size_t buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700517void dpp_configurator_free(struct dpp_configurator *conf);
518struct dpp_configurator *
519dpp_keygen_configurator(const char *curve, const u8 *privkey,
520 size_t privkey_len);
521int dpp_configurator_own_config(struct dpp_authentication *auth,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700522 const char *curve, int ap);
523enum dpp_status_error
524dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
525 const u8 *net_access_key, size_t net_access_key_len,
526 const u8 *csign_key, size_t csign_key_len,
527 const u8 *peer_connector, size_t peer_connector_len,
528 os_time_t *expiry);
529struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700530 const u8 *own_mac,
531 const char *identifier,
532 const char *code);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700533struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
534 struct dpp_bootstrap_info *bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700535 const u8 *own_mac,
536 const u8 *peer_mac,
537 const char *identifier,
538 const char *code,
539 const u8 *buf, size_t len);
540struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700541 const u8 *peer_mac,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700542 const u8 *buf, size_t len);
543struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
544 const u8 *hdr,
545 const u8 *buf, size_t len);
546int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
547 const u8 *buf, size_t len);
548void dpp_pkex_free(struct dpp_pkex *pkex);
549
Roshan Pius3a1667e2018-07-03 15:17:14 -0700550char * dpp_corrupt_connector_signature(const char *connector);
551
Hai Shalom021b0b52019-04-10 11:17:58 -0700552
553struct dpp_pfs {
554 struct crypto_ecdh *ecdh;
555 const struct dpp_curve_params *curve;
556 struct wpabuf *ie;
557 struct wpabuf *secret;
558};
559
560struct dpp_pfs * dpp_pfs_init(const u8 *net_access_key,
561 size_t net_access_key_len);
562int dpp_pfs_process(struct dpp_pfs *pfs, const u8 *peer_ie, size_t peer_ie_len);
563void dpp_pfs_free(struct dpp_pfs *pfs);
564
565struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp,
566 const char *uri);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800567struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp,
568 const char *uri);
Hai Shalom021b0b52019-04-10 11:17:58 -0700569int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd);
570struct dpp_bootstrap_info *
571dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id);
572int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id);
573struct dpp_bootstrap_info *
574dpp_pkex_finish(struct dpp_global *dpp, struct dpp_pkex *pkex, const u8 *peer,
575 unsigned int freq);
576const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id);
577int dpp_bootstrap_info(struct dpp_global *dpp, int id,
578 char *reply, int reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -0700579int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params);
Hai Shalom021b0b52019-04-10 11:17:58 -0700580void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap,
581 const u8 *r_bootstrap,
582 struct dpp_bootstrap_info **own_bi,
583 struct dpp_bootstrap_info **peer_bi);
Hai Shalomfdcde762020-04-02 11:19:20 -0700584struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp,
585 const u8 *hash);
Hai Shalom021b0b52019-04-10 11:17:58 -0700586int dpp_configurator_add(struct dpp_global *dpp, const char *cmd);
587int dpp_configurator_remove(struct dpp_global *dpp, const char *id);
588int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id,
589 char *buf, size_t buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -0700590int dpp_configurator_from_backup(struct dpp_global *dpp,
591 struct dpp_asymmetric_key *key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700592int dpp_relay_add_controller(struct dpp_global *dpp,
593 struct dpp_relay_config *config);
594int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr,
595 const u8 *buf, size_t len, unsigned int freq,
596 const u8 *i_bootstrap, const u8 *r_bootstrap);
597int dpp_relay_rx_gas_req(struct dpp_global *dpp, const u8 *src, const u8 *data,
598 size_t data_len);
599int dpp_controller_start(struct dpp_global *dpp,
600 struct dpp_controller_config *config);
601void dpp_controller_stop(struct dpp_global *dpp);
602int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth,
603 const struct hostapd_ip_addr *addr, int port);
Hai Shalomfdcde762020-04-02 11:19:20 -0700604struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700605
606struct dpp_global_config {
607 void *msg_ctx;
608 void *cb_ctx;
609 int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
Hai Shalomfdcde762020-04-02 11:19:20 -0700610 void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700611};
612
613struct dpp_global * dpp_global_init(struct dpp_global_config *config);
Hai Shalom021b0b52019-04-10 11:17:58 -0700614void dpp_global_clear(struct dpp_global *dpp);
615void dpp_global_deinit(struct dpp_global *dpp);
616
617#endif /* CONFIG_DPP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700618#endif /* DPP_H */