]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/common/dpp.h
DPP: Testing capability to send unexpected Authentication Response
[thirdparty/hostap.git] / src / common / dpp.h
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"
15 #include "common/wpa_common.h"
16 #include "crypto/sha256.h"
17
18 #define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
19
20 enum 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
32 enum 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,
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,
54 DPP_ATTR_TRANSACTION_ID = 0x1016,
55 DPP_ATTR_BOOTSTRAP_INFO = 0x1017,
56 DPP_ATTR_CHANNEL = 0x1018,
57 DPP_ATTR_TESTING = 0x10ff, /* not defined in the DPP tech spec */
58 };
59
60 enum 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,
68 DPP_STATUS_INVALID_CONNECTOR = 7,
69 DPP_STATUS_NO_MATCH = 8,
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
76 #define DPP_BOOTSTRAP_MAX_FREQ 30
77 #define DPP_MAX_NONCE_LEN 32
78 #define DPP_MAX_HASH_LEN 64
79 #define DPP_MAX_SHARED_SECRET_LEN 66
80
81 struct 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;
88 u16 ike_group;
89 const char *jws_alg;
90 };
91
92 enum dpp_bootstrap_type {
93 DPP_BOOTSTRAP_QR_CODE,
94 DPP_BOOTSTRAP_PKEX,
95 };
96
97 struct 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;
110 unsigned int pkex_t; /* number of failures before dpp_pkex
111 * instantiation */
112 };
113
114 #define PKEX_COUNTER_T_LIMIT 5
115
116 struct dpp_pkex {
117 void *msg_ctx;
118 unsigned int initiator:1;
119 unsigned int exchange_done:1;
120 unsigned int failed:1;
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;
134 unsigned int t; /* number of failures on code use */
135 };
136
137 struct 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
145 /* TODO: groups */
146
147 /* For legacy configuration */
148 char *passphrase;
149 u8 psk[32];
150 };
151
152 struct 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];
163 u8 e_nonce[DPP_MAX_NONCE_LEN];
164 u8 i_capab;
165 u8 r_capab;
166 EVP_PKEY *own_protocol_key;
167 EVP_PKEY *peer_protocol_key;
168 struct wpabuf *req_msg;
169 struct wpabuf *resp_msg;
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;
174 unsigned int curr_freq;
175 unsigned int neg_freq;
176 unsigned int num_freq_iters;
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;
185 int waiting_auth_resp;
186 int waiting_auth_conf;
187 unsigned int auth_resp_tries;
188 u8 allowed_roles;
189 int configurator;
190 int remove_on_tx_status;
191 int auth_success;
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;
199 char passphrase[64];
200 u8 psk[PMK_LEN];
201 int psk_set;
202 struct wpabuf *net_access_key;
203 os_time_t net_access_key_expiry;
204 struct wpabuf *c_sign_key;
205 #ifdef CONFIG_TESTING_OPTIONS
206 char *config_obj_override;
207 char *discovery_override;
208 char *groups_override;
209 unsigned int ignore_netaccesskey_mismatch:1;
210 #endif /* CONFIG_TESTING_OPTIONS */
211 };
212
213 struct 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;
220 };
221
222 struct dpp_introduction {
223 u8 pmkid[PMKID_LEN];
224 u8 pmk[PMK_LEN_MAX];
225 size_t pmk_len;
226 };
227
228 #ifdef CONFIG_TESTING_OPTIONS
229 enum 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,
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,
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,
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,
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,
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,
274 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
275 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
276 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
277 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
278 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
279 DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49,
280 DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50,
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,
288 DPP_TEST_INVALID_STATUS_CONF_RESP = 58,
289 DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59,
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,
295 DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65,
296 };
297
298 extern enum dpp_test_behavior dpp_test;
299 #endif /* CONFIG_TESTING_OPTIONS */
300
301 void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
302 const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
303 int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
304 int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
305 const char *chan_list);
306 int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
307 int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
308 struct dpp_bootstrap_info * dpp_parse_qr_code(const char *uri);
309 char * dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
310 const u8 *privkey, size_t privkey_len);
311 struct hostapd_hw_modes;
312 struct dpp_authentication * dpp_auth_init(void *msg_ctx,
313 struct dpp_bootstrap_info *peer_bi,
314 struct dpp_bootstrap_info *own_bi,
315 u8 dpp_allowed_roles,
316 unsigned int neg_freq,
317 struct hostapd_hw_modes *own_modes,
318 u16 num_modes);
319 struct dpp_authentication *
320 dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
321 struct dpp_bootstrap_info *peer_bi,
322 struct dpp_bootstrap_info *own_bi,
323 unsigned int freq, const u8 *hdr, const u8 *attr_start,
324 size_t attr_len);
325 struct wpabuf *
326 dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
327 const u8 *attr_start, size_t attr_len);
328 struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
329 const char *json);
330 int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
331 const u8 *attr_start, size_t attr_len);
332 int dpp_notify_new_qr_code(struct dpp_authentication *auth,
333 struct dpp_bootstrap_info *peer_bi);
334 void dpp_configuration_free(struct dpp_configuration *conf);
335 void dpp_auth_deinit(struct dpp_authentication *auth);
336 struct wpabuf *
337 dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
338 size_t attr_len);
339 int dpp_conf_resp_rx(struct dpp_authentication *auth,
340 const struct wpabuf *resp);
341 struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
342 size_t len);
343 const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
344 int dpp_check_attrs(const u8 *buf, size_t len);
345 int dpp_key_expired(const char *timestamp, os_time_t *expiry);
346 void dpp_configurator_free(struct dpp_configurator *conf);
347 struct dpp_configurator *
348 dpp_keygen_configurator(const char *curve, const u8 *privkey,
349 size_t privkey_len);
350 int dpp_configurator_own_config(struct dpp_authentication *auth,
351 const char *curve);
352 enum dpp_status_error
353 dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
354 const u8 *net_access_key, size_t net_access_key_len,
355 const u8 *csign_key, size_t csign_key_len,
356 const u8 *peer_connector, size_t peer_connector_len,
357 os_time_t *expiry);
358 struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
359 const u8 *own_mac,
360 const char *identifier,
361 const char *code);
362 struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
363 struct dpp_bootstrap_info *bi,
364 const u8 *own_mac,
365 const u8 *peer_mac,
366 const char *identifier,
367 const char *code,
368 const u8 *buf, size_t len);
369 struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
370 const u8 *buf, size_t len);
371 struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
372 const u8 *hdr,
373 const u8 *buf, size_t len);
374 int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
375 const u8 *buf, size_t len);
376 void dpp_pkex_free(struct dpp_pkex *pkex);
377
378 #endif /* DPP_H */