]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/common/dpp.h
DPP: Retransmit DPP Authentication Response frame if it is not ACKed
[thirdparty/hostap.git] / src / common / dpp.h
CommitLineData
be27e185
JM
1/*
2 * DPP functionality shared between hostapd and wpa_supplicant
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#ifndef DPP_H
10#define DPP_H
11
12#include <openssl/x509.h>
13
14#include "utils/list.h"
650a70a7 15#include "common/wpa_common.h"
be27e185
JM
16#include "crypto/sha256.h"
17
dc4d271c
JM
18#define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
19
30d27b04
JM
20enum dpp_public_action_frame_type {
21 DPP_PA_AUTHENTICATION_REQ = 0,
22 DPP_PA_AUTHENTICATION_RESP = 1,
23 DPP_PA_AUTHENTICATION_CONF = 2,
24 DPP_PA_PEER_DISCOVERY_REQ = 5,
25 DPP_PA_PEER_DISCOVERY_RESP = 6,
26 DPP_PA_PKEX_EXCHANGE_REQ = 7,
27 DPP_PA_PKEX_EXCHANGE_RESP = 8,
28 DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9,
29 DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10,
30};
31
32enum dpp_attribute_id {
33 DPP_ATTR_STATUS = 0x1000,
34 DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001,
35 DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002,
36 DPP_ATTR_I_PROTOCOL_KEY = 0x1003,
37 DPP_ATTR_WRAPPED_DATA = 0x1004,
38 DPP_ATTR_I_NONCE = 0x1005,
39 DPP_ATTR_I_CAPABILITIES = 0x1006,
40 DPP_ATTR_R_NONCE = 0x1007,
41 DPP_ATTR_R_CAPABILITIES = 0x1008,
42 DPP_ATTR_R_PROTOCOL_KEY = 0x1009,
43 DPP_ATTR_I_AUTH_TAG = 0x100A,
44 DPP_ATTR_R_AUTH_TAG = 0x100B,
45 DPP_ATTR_CONFIG_OBJ = 0x100C,
46 DPP_ATTR_CONNECTOR = 0x100D,
47 DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E,
48 DPP_ATTR_BOOTSTRAP_KEY = 0x100F,
30d27b04
JM
49 DPP_ATTR_OWN_NET_NK_HASH = 0x1011,
50 DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012,
51 DPP_ATTR_ENCRYPTED_KEY = 0x1013,
52 DPP_ATTR_ENROLLEE_NONCE = 0x1014,
53 DPP_ATTR_CODE_IDENTIFIER = 0x1015,
85fd8263 54 DPP_ATTR_TRANSACTION_ID = 0x1016,
d2709206
JM
55 DPP_ATTR_BOOTSTRAP_INFO = 0x1017,
56 DPP_ATTR_CHANNEL = 0x1018,
60239f60 57 DPP_ATTR_TESTING = 0x10ff, /* not defined in the DPP tech spec */
30d27b04
JM
58};
59
60enum dpp_status_error {
61 DPP_STATUS_OK = 0,
62 DPP_STATUS_NOT_COMPATIBLE = 1,
63 DPP_STATUS_AUTH_FAILURE = 2,
64 DPP_STATUS_UNWRAP_FAILURE = 3,
65 DPP_STATUS_BAD_GROUP = 4,
66 DPP_STATUS_CONFIGURE_FAILURE = 5,
67 DPP_STATUS_RESPONSE_PENDING = 6,
e85b6601
JM
68 DPP_STATUS_INVALID_CONNECTOR = 7,
69 DPP_STATUS_NO_MATCH = 8,
30d27b04
JM
70};
71
72#define DPP_CAPAB_ENROLLEE BIT(0)
73#define DPP_CAPAB_CONFIGURATOR BIT(1)
74#define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
75
be27e185 76#define DPP_BOOTSTRAP_MAX_FREQ 30
30d27b04
JM
77#define DPP_MAX_NONCE_LEN 32
78#define DPP_MAX_HASH_LEN 64
79#define DPP_MAX_SHARED_SECRET_LEN 66
be27e185
JM
80
81struct dpp_curve_params {
82 const char *name;
83 size_t hash_len;
84 size_t aes_siv_key_len;
85 size_t nonce_len;
86 size_t prime_len;
87 const char *jwk_crv;
500ed7f0 88 u16 ike_group;
31f03cb0 89 const char *jws_alg;
be27e185
JM
90};
91
92enum dpp_bootstrap_type {
93 DPP_BOOTSTRAP_QR_CODE,
500ed7f0 94 DPP_BOOTSTRAP_PKEX,
be27e185
JM
95};
96
97struct dpp_bootstrap_info {
98 struct dl_list list;
99 unsigned int id;
100 enum dpp_bootstrap_type type;
101 char *uri;
102 u8 mac_addr[ETH_ALEN];
103 char *info;
104 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
105 unsigned int num_freq;
106 int own;
107 EVP_PKEY *pubkey;
108 u8 pubkey_hash[SHA256_MAC_LEN];
109 const struct dpp_curve_params *curve;
29ab69e4
JM
110 unsigned int pkex_t; /* number of failures before dpp_pkex
111 * instantiation */
be27e185
JM
112};
113
29ab69e4
JM
114#define PKEX_COUNTER_T_LIMIT 5
115
500ed7f0 116struct dpp_pkex {
219d4c9f 117 void *msg_ctx;
500ed7f0
JM
118 unsigned int initiator:1;
119 unsigned int exchange_done:1;
e0247e79 120 unsigned int failed:1;
500ed7f0
JM
121 struct dpp_bootstrap_info *own_bi;
122 u8 own_mac[ETH_ALEN];
123 u8 peer_mac[ETH_ALEN];
124 char *identifier;
125 char *code;
126 EVP_PKEY *x;
127 EVP_PKEY *y;
128 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
129 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
130 u8 z[DPP_MAX_HASH_LEN];
131 EVP_PKEY *peer_bootstrap_key;
132 struct wpabuf *exchange_req;
133 struct wpabuf *exchange_resp;
29ab69e4 134 unsigned int t; /* number of failures on code use */
500ed7f0
JM
135};
136
461d39af
JM
137struct dpp_configuration {
138 u8 ssid[32];
139 size_t ssid_len;
140 int dpp; /* whether to use DPP or legacy configuration */
141
142 /* For DPP configuration (connector) */
143 os_time_t netaccesskey_expiry;
144
a4bf0078 145 /* TODO: groups */
461d39af
JM
146
147 /* For legacy configuration */
148 char *passphrase;
149 u8 psk[32];
150};
151
30d27b04
JM
152struct dpp_authentication {
153 void *msg_ctx;
154 const struct dpp_curve_params *curve;
155 struct dpp_bootstrap_info *peer_bi;
156 struct dpp_bootstrap_info *own_bi;
157 u8 waiting_pubkey_hash[SHA256_MAC_LEN];
158 int response_pending;
159 enum dpp_status_error auth_resp_status;
160 u8 peer_mac_addr[ETH_ALEN];
161 u8 i_nonce[DPP_MAX_NONCE_LEN];
162 u8 r_nonce[DPP_MAX_NONCE_LEN];
461d39af 163 u8 e_nonce[DPP_MAX_NONCE_LEN];
30d27b04
JM
164 u8 i_capab;
165 u8 r_capab;
166 EVP_PKEY *own_protocol_key;
167 EVP_PKEY *peer_protocol_key;
dc4d271c
JM
168 struct wpabuf *req_msg;
169 struct wpabuf *resp_msg;
f97ace34
JM
170 /* Intersection of possible frequencies for initiating DPP
171 * Authentication exchange */
172 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
173 unsigned int num_freq, freq_idx;
30d27b04 174 unsigned int curr_freq;
d2709206 175 unsigned int neg_freq;
f97ace34 176 unsigned int num_freq_iters;
30d27b04
JM
177 size_t secret_len;
178 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
179 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
180 u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
181 u8 k1[DPP_MAX_HASH_LEN];
182 u8 k2[DPP_MAX_HASH_LEN];
183 u8 ke[DPP_MAX_HASH_LEN];
184 int initiator;
f97ace34 185 int waiting_auth_resp;
95b0104a
JM
186 int waiting_auth_conf;
187 unsigned int auth_resp_tries;
d1f08264 188 u8 allowed_roles;
30d27b04
JM
189 int configurator;
190 int remove_on_tx_status;
191 int auth_success;
461d39af
JM
192 struct wpabuf *conf_req;
193 struct dpp_configuration *conf_ap;
194 struct dpp_configuration *conf_sta;
195 struct dpp_configurator *conf;
196 char *connector; /* received signedConnector */
197 u8 ssid[SSID_MAX_LEN];
198 u8 ssid_len;
8528994e
JM
199 char passphrase[64];
200 u8 psk[PMK_LEN];
201 int psk_set;
461d39af
JM
202 struct wpabuf *net_access_key;
203 os_time_t net_access_key_expiry;
204 struct wpabuf *c_sign_key;
461d39af
JM
205#ifdef CONFIG_TESTING_OPTIONS
206 char *config_obj_override;
207 char *discovery_override;
208 char *groups_override;
461d39af
JM
209 unsigned int ignore_netaccesskey_mismatch:1;
210#endif /* CONFIG_TESTING_OPTIONS */
211};
212
213struct dpp_configurator {
214 struct dl_list list;
215 unsigned int id;
216 int own;
217 EVP_PKEY *csign;
218 char *kid;
219 const struct dpp_curve_params *curve;
30d27b04
JM
220};
221
650a70a7
JM
222struct dpp_introduction {
223 u8 pmkid[PMKID_LEN];
224 u8 pmk[PMK_LEN_MAX];
225 size_t pmk_len;
650a70a7
JM
226};
227
60239f60
JM
228#ifdef CONFIG_TESTING_OPTIONS
229enum dpp_test_behavior {
230 DPP_TEST_DISABLED = 0,
231 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
232 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
233 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
234 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
235 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
236 DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
237 DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
238 DPP_TEST_ZERO_I_CAPAB = 8,
239 DPP_TEST_ZERO_R_CAPAB = 9,
0e7cb8c6
JM
240 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
241 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
242 DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
243 DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
244 DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
245 DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
ce9acce0
JM
246 DPP_TEST_NO_STATUS_AUTH_RESP = 16,
247 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
248 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
249 DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
250 DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
251 DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
252 DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
253 DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
254 DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
f9c7d770
JM
255 DPP_TEST_NO_STATUS_AUTH_CONF = 25,
256 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
257 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
258 DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
259 DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
978bc3f2
JM
260 DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
261 DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
262 DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
263 DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
61f9f27f
JM
264 DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
265 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
266 DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
267 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
268 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
269 DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
270 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
271 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
272 DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
273 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
1cfcbd32
JM
274 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
275 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
f31ef96d 276 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
89d0bf67
JM
277 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
278 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
7e0ebe21
JM
279 DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
280 DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
f411ad1b
JM
281 DPP_TEST_NO_E_NONCE_CONF_REQ = 51,
282 DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52,
283 DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53,
284 DPP_TEST_NO_E_NONCE_CONF_RESP = 54,
285 DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55,
286 DPP_TEST_NO_STATUS_CONF_RESP = 56,
287 DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57,
af7f10fc
JM
288 DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
289 DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
a306ed5a
JM
290 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60,
291 DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61,
292 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62,
293 DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63,
294 DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64,
60239f60
JM
295};
296
297extern enum dpp_test_behavior dpp_test;
298#endif /* CONFIG_TESTING_OPTIONS */
299
be27e185 300void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
484788b8 301const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
500ed7f0 302int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
be27e185
JM
303int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
304 const char *chan_list);
305int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
306int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
307struct dpp_bootstrap_info * dpp_parse_qr_code(const char *uri);
308char * dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
309 const u8 *privkey, size_t privkey_len);
f97ace34 310struct hostapd_hw_modes;
30d27b04
JM
311struct dpp_authentication * dpp_auth_init(void *msg_ctx,
312 struct dpp_bootstrap_info *peer_bi,
313 struct dpp_bootstrap_info *own_bi,
d1f08264 314 u8 dpp_allowed_roles,
f97ace34
JM
315 unsigned int neg_freq,
316 struct hostapd_hw_modes *own_modes,
317 u16 num_modes);
30d27b04
JM
318struct dpp_authentication *
319dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
320 struct dpp_bootstrap_info *peer_bi,
321 struct dpp_bootstrap_info *own_bi,
dc4d271c 322 unsigned int freq, const u8 *hdr, const u8 *attr_start,
27fefbbb 323 size_t attr_len);
30d27b04 324struct wpabuf *
dc4d271c
JM
325dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
326 const u8 *attr_start, size_t attr_len);
461d39af
JM
327struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
328 const char *json);
dc4d271c
JM
329int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
330 const u8 *attr_start, size_t attr_len);
30d27b04
JM
331int dpp_notify_new_qr_code(struct dpp_authentication *auth,
332 struct dpp_bootstrap_info *peer_bi);
461d39af 333void dpp_configuration_free(struct dpp_configuration *conf);
30d27b04 334void dpp_auth_deinit(struct dpp_authentication *auth);
461d39af
JM
335struct wpabuf *
336dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
337 size_t attr_len);
338int dpp_conf_resp_rx(struct dpp_authentication *auth,
339 const struct wpabuf *resp);
30d27b04
JM
340struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
341 size_t len);
342const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
343int dpp_check_attrs(const u8 *buf, size_t len);
461d39af
JM
344int dpp_key_expired(const char *timestamp, os_time_t *expiry);
345void dpp_configurator_free(struct dpp_configurator *conf);
346struct dpp_configurator *
347dpp_keygen_configurator(const char *curve, const u8 *privkey,
348 size_t privkey_len);
f522bb23
JM
349int dpp_configurator_own_config(struct dpp_authentication *auth,
350 const char *curve);
e85b6601
JM
351enum dpp_status_error
352dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
353 const u8 *net_access_key, size_t net_access_key_len,
354 const u8 *csign_key, size_t csign_key_len,
355 const u8 *peer_connector, size_t peer_connector_len,
356 os_time_t *expiry);
219d4c9f 357struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
500ed7f0
JM
358 const u8 *own_mac,
359 const char *identifier,
360 const char *code);
219d4c9f
JM
361struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
362 struct dpp_bootstrap_info *bi,
500ed7f0
JM
363 const u8 *own_mac,
364 const u8 *peer_mac,
365 const char *identifier,
366 const char *code,
367 const u8 *buf, size_t len);
368struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
369 const u8 *buf, size_t len);
370struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
4be5bc98 371 const u8 *hdr,
500ed7f0 372 const u8 *buf, size_t len);
4be5bc98 373int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
500ed7f0
JM
374 const u8 *buf, size_t len);
375void dpp_pkex_free(struct dpp_pkex *pkex);
be27e185
JM
376
377#endif /* DPP_H */