blob: d77762e9cf408f3394ff632b151c796c983f37be [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;
Hai Shalom4fbc08f2020-05-18 12:37:00 -070023struct json_token;
24
25#ifdef CONFIG_TESTING_OPTIONS
26#define DPP_VERSION (dpp_version_override)
27extern int dpp_version_override;
28#else /* CONFIG_TESTING_OPTIONS */
29#ifdef CONFIG_DPP2
30#define DPP_VERSION 2
31#else
32#define DPP_VERSION 1
33#endif
34#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom021b0b52019-04-10 11:17:58 -070035
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070036#define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
Hai Shalom81f62d82019-07-22 12:10:00 -070037#define DPP_TCP_PORT 7871
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070038
39enum dpp_public_action_frame_type {
40 DPP_PA_AUTHENTICATION_REQ = 0,
41 DPP_PA_AUTHENTICATION_RESP = 1,
42 DPP_PA_AUTHENTICATION_CONF = 2,
43 DPP_PA_PEER_DISCOVERY_REQ = 5,
44 DPP_PA_PEER_DISCOVERY_RESP = 6,
45 DPP_PA_PKEX_EXCHANGE_REQ = 7,
46 DPP_PA_PKEX_EXCHANGE_RESP = 8,
47 DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9,
48 DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10,
Hai Shalom021b0b52019-04-10 11:17:58 -070049 DPP_PA_CONFIGURATION_RESULT = 11,
Hai Shalomc3565922019-10-28 11:58:20 -070050 DPP_PA_CONNECTION_STATUS_RESULT = 12,
Hai Shalomfdcde762020-04-02 11:19:20 -070051 DPP_PA_PRESENCE_ANNOUNCEMENT = 13,
52 DPP_PA_RECONFIG_ANNOUNCEMENT = 14,
53 DPP_PA_RECONFIG_AUTH_REQ = 15,
54 DPP_PA_RECONFIG_AUTH_RESP = 16,
55 DPP_PA_RECONFIG_AUTH_CONF = 17,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070056};
57
58enum dpp_attribute_id {
59 DPP_ATTR_STATUS = 0x1000,
60 DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001,
61 DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002,
62 DPP_ATTR_I_PROTOCOL_KEY = 0x1003,
63 DPP_ATTR_WRAPPED_DATA = 0x1004,
64 DPP_ATTR_I_NONCE = 0x1005,
65 DPP_ATTR_I_CAPABILITIES = 0x1006,
66 DPP_ATTR_R_NONCE = 0x1007,
67 DPP_ATTR_R_CAPABILITIES = 0x1008,
68 DPP_ATTR_R_PROTOCOL_KEY = 0x1009,
69 DPP_ATTR_I_AUTH_TAG = 0x100A,
70 DPP_ATTR_R_AUTH_TAG = 0x100B,
71 DPP_ATTR_CONFIG_OBJ = 0x100C,
72 DPP_ATTR_CONNECTOR = 0x100D,
73 DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E,
74 DPP_ATTR_BOOTSTRAP_KEY = 0x100F,
75 DPP_ATTR_OWN_NET_NK_HASH = 0x1011,
76 DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012,
77 DPP_ATTR_ENCRYPTED_KEY = 0x1013,
78 DPP_ATTR_ENROLLEE_NONCE = 0x1014,
79 DPP_ATTR_CODE_IDENTIFIER = 0x1015,
80 DPP_ATTR_TRANSACTION_ID = 0x1016,
Roshan Pius3a1667e2018-07-03 15:17:14 -070081 DPP_ATTR_BOOTSTRAP_INFO = 0x1017,
82 DPP_ATTR_CHANNEL = 0x1018,
Hai Shalom021b0b52019-04-10 11:17:58 -070083 DPP_ATTR_PROTOCOL_VERSION = 0x1019,
84 DPP_ATTR_ENVELOPED_DATA = 0x101A,
Hai Shalomc3565922019-10-28 11:58:20 -070085 DPP_ATTR_SEND_CONN_STATUS = 0x101B,
86 DPP_ATTR_CONN_STATUS = 0x101C,
Hai Shalomfdcde762020-04-02 11:19:20 -070087 DPP_ATTR_RECONFIG_FLAGS = 0x101D,
88 DPP_ATTR_C_SIGN_KEY_HASH = 0x101E,
89 DPP_ATTR_CSR_ATTR_REQ = 0x101F,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070090};
91
92enum dpp_status_error {
93 DPP_STATUS_OK = 0,
94 DPP_STATUS_NOT_COMPATIBLE = 1,
95 DPP_STATUS_AUTH_FAILURE = 2,
96 DPP_STATUS_UNWRAP_FAILURE = 3,
97 DPP_STATUS_BAD_GROUP = 4,
98 DPP_STATUS_CONFIGURE_FAILURE = 5,
99 DPP_STATUS_RESPONSE_PENDING = 6,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700100 DPP_STATUS_INVALID_CONNECTOR = 7,
101 DPP_STATUS_NO_MATCH = 8,
Hai Shalom021b0b52019-04-10 11:17:58 -0700102 DPP_STATUS_CONFIG_REJECTED = 9,
Hai Shalomc3565922019-10-28 11:58:20 -0700103 DPP_STATUS_NO_AP = 10,
Hai Shalomfdcde762020-04-02 11:19:20 -0700104 DPP_STATUS_CONFIGURE_PENDING = 11,
105 DPP_STATUS_CSR_NEEDED = 12,
106 DPP_STATUS_CSR_BAD = 13,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700107};
108
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700109/* DPP Reconfig Flags object - connectorKey values */
110enum dpp_connector_key {
111 DPP_CONFIG_REUSEKEY = 0,
112 DPP_CONFIG_REPLACEKEY = 1,
113};
114
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700115#define DPP_CAPAB_ENROLLEE BIT(0)
116#define DPP_CAPAB_CONFIGURATOR BIT(1)
117#define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
118
119#define DPP_BOOTSTRAP_MAX_FREQ 30
120#define DPP_MAX_NONCE_LEN 32
121#define DPP_MAX_HASH_LEN 64
122#define DPP_MAX_SHARED_SECRET_LEN 66
123
124struct dpp_curve_params {
125 const char *name;
126 size_t hash_len;
127 size_t aes_siv_key_len;
128 size_t nonce_len;
129 size_t prime_len;
130 const char *jwk_crv;
131 u16 ike_group;
132 const char *jws_alg;
133};
134
135enum dpp_bootstrap_type {
136 DPP_BOOTSTRAP_QR_CODE,
137 DPP_BOOTSTRAP_PKEX,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800138 DPP_BOOTSTRAP_NFC_URI,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700139};
140
141struct dpp_bootstrap_info {
142 struct dl_list list;
143 unsigned int id;
144 enum dpp_bootstrap_type type;
145 char *uri;
146 u8 mac_addr[ETH_ALEN];
Hai Shalomfdcde762020-04-02 11:19:20 -0700147 char *chan;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700148 char *info;
Hai Shalomfdcde762020-04-02 11:19:20 -0700149 char *pk;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700150 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
151 unsigned int num_freq;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700152 u8 version;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700153 int own;
154 EVP_PKEY *pubkey;
155 u8 pubkey_hash[SHA256_MAC_LEN];
Hai Shalomfdcde762020-04-02 11:19:20 -0700156 u8 pubkey_hash_chirp[SHA256_MAC_LEN];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700157 const struct dpp_curve_params *curve;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700158 unsigned int pkex_t; /* number of failures before dpp_pkex
159 * instantiation */
Hai Shalomb755a2a2020-04-23 21:49:02 -0700160 int nfc_negotiated; /* whether this has been used in NFC negotiated
161 * connection handover */
Hai Shalomfdcde762020-04-02 11:19:20 -0700162 char *configurator_params;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700163};
164
Roshan Pius3a1667e2018-07-03 15:17:14 -0700165#define PKEX_COUNTER_T_LIMIT 5
166
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700167struct dpp_pkex {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700168 void *msg_ctx;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700169 unsigned int initiator:1;
170 unsigned int exchange_done:1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700171 unsigned int failed:1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700172 struct dpp_bootstrap_info *own_bi;
173 u8 own_mac[ETH_ALEN];
174 u8 peer_mac[ETH_ALEN];
175 char *identifier;
176 char *code;
177 EVP_PKEY *x;
178 EVP_PKEY *y;
179 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
180 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
181 u8 z[DPP_MAX_HASH_LEN];
182 EVP_PKEY *peer_bootstrap_key;
183 struct wpabuf *exchange_req;
184 struct wpabuf *exchange_resp;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700185 unsigned int t; /* number of failures on code use */
186 unsigned int exch_req_wait_time;
187 unsigned int exch_req_tries;
188 unsigned int freq;
189};
190
191enum dpp_akm {
192 DPP_AKM_UNKNOWN,
193 DPP_AKM_DPP,
194 DPP_AKM_PSK,
195 DPP_AKM_SAE,
Hai Shalom021b0b52019-04-10 11:17:58 -0700196 DPP_AKM_PSK_SAE,
197 DPP_AKM_SAE_DPP,
198 DPP_AKM_PSK_SAE_DPP,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700199};
200
Hai Shalomc3565922019-10-28 11:58:20 -0700201enum dpp_netrole {
202 DPP_NETROLE_STA,
203 DPP_NETROLE_AP,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800204 DPP_NETROLE_CONFIGURATOR,
Hai Shalomc3565922019-10-28 11:58:20 -0700205};
206
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700207struct dpp_configuration {
208 u8 ssid[32];
209 size_t ssid_len;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800210 int ssid_charset;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700211 enum dpp_akm akm;
Hai Shalomc3565922019-10-28 11:58:20 -0700212 enum dpp_netrole netrole;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700213
214 /* For DPP configuration (connector) */
215 os_time_t netaccesskey_expiry;
216
217 /* TODO: groups */
Hai Shalomce48b4a2018-09-05 11:41:35 -0700218 char *group_id;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700219
220 /* For legacy configuration */
221 char *passphrase;
222 u8 psk[32];
Hai Shalom021b0b52019-04-10 11:17:58 -0700223 int psk_set;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700224};
225
Hai Shalomfdcde762020-04-02 11:19:20 -0700226struct dpp_asymmetric_key {
227 struct dpp_asymmetric_key *next;
228 EVP_PKEY *csign;
229 char *config_template;
230 char *connector_template;
231};
232
Hai Shalomc3565922019-10-28 11:58:20 -0700233#define DPP_MAX_CONF_OBJ 10
Hai Shalom06768112019-12-04 15:49:43 -0800234#define DPP_MAX_CHANNELS 32
Hai Shalomc3565922019-10-28 11:58:20 -0700235
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700236struct dpp_authentication {
Hai Shalomfdcde762020-04-02 11:19:20 -0700237 struct dpp_global *global;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700238 void *msg_ctx;
Hai Shalom021b0b52019-04-10 11:17:58 -0700239 u8 peer_version;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700240 const struct dpp_curve_params *curve;
241 struct dpp_bootstrap_info *peer_bi;
242 struct dpp_bootstrap_info *own_bi;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700243 struct dpp_bootstrap_info *tmp_own_bi;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700244 u8 waiting_pubkey_hash[SHA256_MAC_LEN];
245 int response_pending;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700246 int reconfig;
247 enum dpp_connector_key reconfig_connector_key;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700248 enum dpp_status_error auth_resp_status;
Hai Shalom021b0b52019-04-10 11:17:58 -0700249 enum dpp_status_error conf_resp_status;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700250 u8 peer_mac_addr[ETH_ALEN];
251 u8 i_nonce[DPP_MAX_NONCE_LEN];
252 u8 r_nonce[DPP_MAX_NONCE_LEN];
253 u8 e_nonce[DPP_MAX_NONCE_LEN];
254 u8 i_capab;
255 u8 r_capab;
256 EVP_PKEY *own_protocol_key;
257 EVP_PKEY *peer_protocol_key;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700258 EVP_PKEY *reconfig_old_protocol_key;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700259 struct wpabuf *req_msg;
260 struct wpabuf *resp_msg;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700261 struct wpabuf *reconfig_req_msg;
262 struct wpabuf *reconfig_resp_msg;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700263 /* Intersection of possible frequencies for initiating DPP
264 * Authentication exchange */
265 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
266 unsigned int num_freq, freq_idx;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700267 unsigned int curr_freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700268 unsigned int neg_freq;
269 unsigned int num_freq_iters;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700270 size_t secret_len;
271 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700272 size_t Mx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700273 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700274 size_t Nx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700275 u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -0700276 size_t Lx_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700277 u8 k1[DPP_MAX_HASH_LEN];
278 u8 k2[DPP_MAX_HASH_LEN];
279 u8 ke[DPP_MAX_HASH_LEN];
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700280 u8 bk[DPP_MAX_HASH_LEN];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700281 int initiator;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700282 int waiting_auth_resp;
283 int waiting_auth_conf;
284 int auth_req_ack;
285 unsigned int auth_resp_tries;
286 u8 allowed_roles;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700287 int configurator;
288 int remove_on_tx_status;
Hai Shalom021b0b52019-04-10 11:17:58 -0700289 int connect_on_tx_status;
290 int waiting_conf_result;
Hai Shalomc3565922019-10-28 11:58:20 -0700291 int waiting_conn_status_result;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700292 int auth_success;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700293 bool reconfig_success;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700294 struct wpabuf *conf_req;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700295 const struct wpabuf *conf_resp; /* owned by GAS server */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700296 struct dpp_configuration *conf_ap;
Hai Shalomc3565922019-10-28 11:58:20 -0700297 struct dpp_configuration *conf2_ap;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700298 struct dpp_configuration *conf_sta;
Hai Shalomc3565922019-10-28 11:58:20 -0700299 struct dpp_configuration *conf2_sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700300 int provision_configurator;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700301 struct dpp_configurator *conf;
Hai Shalomc3565922019-10-28 11:58:20 -0700302 struct dpp_config_obj {
303 char *connector; /* received signedConnector */
304 u8 ssid[SSID_MAX_LEN];
305 u8 ssid_len;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800306 int ssid_charset;
Hai Shalomc3565922019-10-28 11:58:20 -0700307 char passphrase[64];
308 u8 psk[PMK_LEN];
309 int psk_set;
310 enum dpp_akm akm;
311 struct wpabuf *c_sign_key;
312 } conf_obj[DPP_MAX_CONF_OBJ];
313 unsigned int num_conf_obj;
Hai Shalomfdcde762020-04-02 11:19:20 -0700314 struct dpp_asymmetric_key *conf_key_pkg;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700315 struct wpabuf *net_access_key;
316 os_time_t net_access_key_expiry;
Hai Shalomc3565922019-10-28 11:58:20 -0700317 int send_conn_status;
318 int conn_status_requested;
319 int akm_use_selector;
Hai Shalomfdcde762020-04-02 11:19:20 -0700320 int configurator_set;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700321 u8 transaction_id;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700322#ifdef CONFIG_TESTING_OPTIONS
323 char *config_obj_override;
324 char *discovery_override;
325 char *groups_override;
326 unsigned int ignore_netaccesskey_mismatch:1;
327#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom06768112019-12-04 15:49:43 -0800328 unsigned short band_list[DPP_MAX_CHANNELS];
329 int band_list_size;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700330};
331
332struct dpp_configurator {
333 struct dl_list list;
334 unsigned int id;
335 int own;
336 EVP_PKEY *csign;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700337 u8 kid_hash[SHA256_MAC_LEN];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700338 char *kid;
339 const struct dpp_curve_params *curve;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700340 char *connector; /* own Connector for reconfiguration */
341 EVP_PKEY *connector_key;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700342};
343
344struct dpp_introduction {
345 u8 pmkid[PMKID_LEN];
346 u8 pmk[PMK_LEN_MAX];
347 size_t pmk_len;
348};
349
Hai Shalom81f62d82019-07-22 12:10:00 -0700350struct dpp_relay_config {
351 const struct hostapd_ip_addr *ipaddr;
352 const u8 *pkhash;
353
354 void *cb_ctx;
355 void (*tx)(void *ctx, const u8 *addr, unsigned int freq, const u8 *msg,
356 size_t len);
357 void (*gas_resp_tx)(void *ctx, const u8 *addr, u8 dialog_token, int prot,
358 struct wpabuf *buf);
359};
360
361struct dpp_controller_config {
362 const char *configurator_params;
363 int tcp_port;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700364 u8 allowed_roles;
Hai Shalom81f62d82019-07-22 12:10:00 -0700365};
366
Roshan Pius3a1667e2018-07-03 15:17:14 -0700367#ifdef CONFIG_TESTING_OPTIONS
368enum dpp_test_behavior {
369 DPP_TEST_DISABLED = 0,
370 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
371 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
372 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
373 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
374 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
375 DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
376 DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
377 DPP_TEST_ZERO_I_CAPAB = 8,
378 DPP_TEST_ZERO_R_CAPAB = 9,
379 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
380 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
381 DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
382 DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
383 DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
384 DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
385 DPP_TEST_NO_STATUS_AUTH_RESP = 16,
386 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
387 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
388 DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
389 DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
390 DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
391 DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
392 DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
393 DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
394 DPP_TEST_NO_STATUS_AUTH_CONF = 25,
395 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
396 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
397 DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
398 DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
399 DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
400 DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
401 DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
402 DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
403 DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
404 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
405 DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
406 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
407 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
408 DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
409 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
410 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
411 DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
412 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
413 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
414 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
415 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
416 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
417 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
418 DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
419 DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
420 DPP_TEST_NO_E_NONCE_CONF_REQ = 51,
421 DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52,
422 DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53,
423 DPP_TEST_NO_E_NONCE_CONF_RESP = 54,
424 DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55,
425 DPP_TEST_NO_STATUS_CONF_RESP = 56,
426 DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57,
427 DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
428 DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
429 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60,
430 DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61,
431 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62,
432 DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63,
433 DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64,
434 DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65,
435 DPP_TEST_INVALID_I_PROTO_KEY_AUTH_REQ = 66,
436 DPP_TEST_INVALID_R_PROTO_KEY_AUTH_RESP = 67,
437 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 68,
438 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 69,
439 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 70,
440 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 71,
441 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 72,
442 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 73,
443 DPP_TEST_INVALID_STATUS_AUTH_RESP = 74,
444 DPP_TEST_INVALID_STATUS_AUTH_CONF = 75,
445 DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ = 76,
446 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP = 77,
447 DPP_TEST_INVALID_STATUS_PEER_DISC_RESP = 78,
448 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP = 79,
449 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ = 80,
450 DPP_TEST_INVALID_I_NONCE_AUTH_REQ = 81,
451 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ = 82,
452 DPP_TEST_INVALID_E_NONCE_CONF_REQ = 83,
453 DPP_TEST_STOP_AT_PKEX_EXCHANGE_RESP = 84,
454 DPP_TEST_STOP_AT_PKEX_CR_REQ = 85,
455 DPP_TEST_STOP_AT_PKEX_CR_RESP = 86,
456 DPP_TEST_STOP_AT_AUTH_REQ = 87,
457 DPP_TEST_STOP_AT_AUTH_RESP = 88,
458 DPP_TEST_STOP_AT_AUTH_CONF = 89,
459 DPP_TEST_STOP_AT_CONF_REQ = 90,
Hai Shalom021b0b52019-04-10 11:17:58 -0700460 DPP_TEST_REJECT_CONFIG = 91,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700461};
462
463extern enum dpp_test_behavior dpp_test;
464extern u8 dpp_pkex_own_mac_override[ETH_ALEN];
465extern u8 dpp_pkex_peer_mac_override[ETH_ALEN];
466extern u8 dpp_pkex_ephemeral_key_override[600];
467extern size_t dpp_pkex_ephemeral_key_override_len;
468extern u8 dpp_protocol_key_override[600];
469extern size_t dpp_protocol_key_override_len;
470extern u8 dpp_nonce_override[DPP_MAX_NONCE_LEN];
471extern size_t dpp_nonce_override_len;
472#endif /* CONFIG_TESTING_OPTIONS */
473
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700474void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
475const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700476int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
477 const char *chan_list);
478int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
479int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
Hai Shalomfdcde762020-04-02 11:19:20 -0700480int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi,
481 struct dpp_bootstrap_info *peer_bi);
482struct dpp_authentication *
483dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700484struct hostapd_hw_modes;
Hai Shalomfdcde762020-04-02 11:19:20 -0700485struct dpp_authentication * dpp_auth_init(struct dpp_global *dpp, void *msg_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700486 struct dpp_bootstrap_info *peer_bi,
487 struct dpp_bootstrap_info *own_bi,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700488 u8 dpp_allowed_roles,
489 unsigned int neg_freq,
490 struct hostapd_hw_modes *own_modes,
491 u16 num_modes);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700492struct dpp_authentication *
Hai Shalomfdcde762020-04-02 11:19:20 -0700493dpp_auth_req_rx(struct dpp_global *dpp, void *msg_ctx, u8 dpp_allowed_roles,
494 int qr_mutual, struct dpp_bootstrap_info *peer_bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700495 struct dpp_bootstrap_info *own_bi,
496 unsigned int freq, const u8 *hdr, const u8 *attr_start,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700497 size_t attr_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700498struct wpabuf *
499dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
500 const u8 *attr_start, size_t attr_len);
501struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
502 const char *json);
Hai Shalomc3565922019-10-28 11:58:20 -0700503struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800504 const char *name,
505 enum dpp_netrole netrole,
Hai Shalomc3565922019-10-28 11:58:20 -0700506 const char *mud_url, int *opclasses);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700507int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
508 const u8 *attr_start, size_t attr_len);
509int dpp_notify_new_qr_code(struct dpp_authentication *auth,
510 struct dpp_bootstrap_info *peer_bi);
Hai Shalom021b0b52019-04-10 11:17:58 -0700511struct dpp_configuration * dpp_configuration_alloc(const char *type);
512int dpp_akm_psk(enum dpp_akm akm);
513int dpp_akm_sae(enum dpp_akm akm);
514int dpp_akm_legacy(enum dpp_akm akm);
515int dpp_akm_dpp(enum dpp_akm akm);
516int dpp_akm_ver2(enum dpp_akm akm);
517int dpp_configuration_valid(const struct dpp_configuration *conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700518void dpp_configuration_free(struct dpp_configuration *conf);
Hai Shalomfdcde762020-04-02 11:19:20 -0700519int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700520void dpp_auth_deinit(struct dpp_authentication *auth);
521struct wpabuf *
522dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
523 size_t attr_len);
524int dpp_conf_resp_rx(struct dpp_authentication *auth,
525 const struct wpabuf *resp);
Hai Shalom021b0b52019-04-10 11:17:58 -0700526enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth,
527 const u8 *hdr,
528 const u8 *attr_start, size_t attr_len);
529struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth,
530 enum dpp_status_error status);
Hai Shalomc3565922019-10-28 11:58:20 -0700531enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth,
532 const u8 *hdr,
533 const u8 *attr_start,
534 size_t attr_len,
535 u8 *ssid, size_t *ssid_len,
536 char **channel_list);
537struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth,
538 enum dpp_status_error result,
539 const u8 *ssid, size_t ssid_len,
540 const char *channel_list);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700541struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
542 size_t len);
543const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
544int dpp_check_attrs(const u8 *buf, size_t len);
545int dpp_key_expired(const char *timestamp, os_time_t *expiry);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700546const char * dpp_akm_str(enum dpp_akm akm);
Hai Shalomc3565922019-10-28 11:58:20 -0700547const char * dpp_akm_selector_str(enum dpp_akm akm);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700548int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf,
549 size_t buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700550void dpp_configurator_free(struct dpp_configurator *conf);
551struct dpp_configurator *
552dpp_keygen_configurator(const char *curve, const u8 *privkey,
553 size_t privkey_len);
554int dpp_configurator_own_config(struct dpp_authentication *auth,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700555 const char *curve, int ap);
556enum dpp_status_error
557dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
558 const u8 *net_access_key, size_t net_access_key_len,
559 const u8 *csign_key, size_t csign_key_len,
560 const u8 *peer_connector, size_t peer_connector_len,
561 os_time_t *expiry);
562struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700563 const u8 *own_mac,
564 const char *identifier,
565 const char *code);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700566struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
567 struct dpp_bootstrap_info *bi,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700568 const u8 *own_mac,
569 const u8 *peer_mac,
570 const char *identifier,
571 const char *code,
572 const u8 *buf, size_t len);
573struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700574 const u8 *peer_mac,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700575 const u8 *buf, size_t len);
576struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
577 const u8 *hdr,
578 const u8 *buf, size_t len);
579int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
580 const u8 *buf, size_t len);
581void dpp_pkex_free(struct dpp_pkex *pkex);
582
Roshan Pius3a1667e2018-07-03 15:17:14 -0700583char * dpp_corrupt_connector_signature(const char *connector);
584
Hai Shalom021b0b52019-04-10 11:17:58 -0700585
586struct dpp_pfs {
587 struct crypto_ecdh *ecdh;
588 const struct dpp_curve_params *curve;
589 struct wpabuf *ie;
590 struct wpabuf *secret;
591};
592
593struct dpp_pfs * dpp_pfs_init(const u8 *net_access_key,
594 size_t net_access_key_len);
595int dpp_pfs_process(struct dpp_pfs *pfs, const u8 *peer_ie, size_t peer_ie_len);
596void dpp_pfs_free(struct dpp_pfs *pfs);
597
598struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp,
599 const char *uri);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800600struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp,
601 const char *uri);
Hai Shalom021b0b52019-04-10 11:17:58 -0700602int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd);
603struct dpp_bootstrap_info *
604dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id);
605int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id);
606struct dpp_bootstrap_info *
607dpp_pkex_finish(struct dpp_global *dpp, struct dpp_pkex *pkex, const u8 *peer,
608 unsigned int freq);
609const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id);
610int dpp_bootstrap_info(struct dpp_global *dpp, int id,
611 char *reply, int reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -0700612int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params);
Hai Shalom021b0b52019-04-10 11:17:58 -0700613void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap,
614 const u8 *r_bootstrap,
615 struct dpp_bootstrap_info **own_bi,
616 struct dpp_bootstrap_info **peer_bi);
Hai Shalomfdcde762020-04-02 11:19:20 -0700617struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp,
618 const u8 *hash);
Hai Shalom021b0b52019-04-10 11:17:58 -0700619int dpp_configurator_add(struct dpp_global *dpp, const char *cmd);
620int dpp_configurator_remove(struct dpp_global *dpp, const char *id);
621int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id,
622 char *buf, size_t buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -0700623int dpp_configurator_from_backup(struct dpp_global *dpp,
624 struct dpp_asymmetric_key *key);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700625struct dpp_configurator * dpp_configurator_find_kid(struct dpp_global *dpp,
626 const u8 *kid);
Hai Shalom81f62d82019-07-22 12:10:00 -0700627int dpp_relay_add_controller(struct dpp_global *dpp,
628 struct dpp_relay_config *config);
629int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr,
630 const u8 *buf, size_t len, unsigned int freq,
631 const u8 *i_bootstrap, const u8 *r_bootstrap);
632int dpp_relay_rx_gas_req(struct dpp_global *dpp, const u8 *src, const u8 *data,
633 size_t data_len);
634int dpp_controller_start(struct dpp_global *dpp,
635 struct dpp_controller_config *config);
636void dpp_controller_stop(struct dpp_global *dpp);
637int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth,
638 const struct hostapd_ip_addr *addr, int port);
Hai Shalomfdcde762020-04-02 11:19:20 -0700639struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700640
641struct dpp_global_config {
642 void *msg_ctx;
643 void *cb_ctx;
644 int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
Hai Shalomfdcde762020-04-02 11:19:20 -0700645 void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi);
Hai Shalom81f62d82019-07-22 12:10:00 -0700646};
647
648struct dpp_global * dpp_global_init(struct dpp_global_config *config);
Hai Shalom021b0b52019-04-10 11:17:58 -0700649void dpp_global_clear(struct dpp_global *dpp);
650void dpp_global_deinit(struct dpp_global *dpp);
651
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700652/* dpp_reconfig.c */
653
654struct wpabuf * dpp_build_reconfig_announcement(const u8 *csign_key,
655 size_t csign_key_len);
656struct dpp_authentication *
657dpp_reconfig_init(struct dpp_global *dpp, void *msg_ctx,
658 struct dpp_configurator *conf, unsigned int freq);
659struct dpp_authentication *
660dpp_reconfig_auth_req_rx(struct dpp_global *dpp, void *msg_ctx,
661 const char *own_connector,
662 const u8 *net_access_key, size_t net_access_key_len,
663 const u8 *csign_key, size_t csign_key_len,
664 unsigned int freq, const u8 *hdr,
665 const u8 *attr_start, size_t attr_len);
666struct wpabuf *
667dpp_reconfig_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
668 const u8 *attr_start, size_t attr_len);
669int dpp_reconfig_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
670 const u8 *attr_start, size_t attr_len);
671
Hai Shalom021b0b52019-04-10 11:17:58 -0700672#endif /* CONFIG_DPP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700673#endif /* DPP_H */