]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/common/dpp.h
tests: DPP protocol - invalid Bootstrap Key in PKEX Commit-Reveal
[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;
30d27b04 170 unsigned int curr_freq;
d2709206 171 unsigned int neg_freq;
30d27b04
JM
172 size_t secret_len;
173 u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
174 u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
175 u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
176 u8 k1[DPP_MAX_HASH_LEN];
177 u8 k2[DPP_MAX_HASH_LEN];
178 u8 ke[DPP_MAX_HASH_LEN];
179 int initiator;
180 int configurator;
181 int remove_on_tx_status;
182 int auth_success;
461d39af
JM
183 struct wpabuf *conf_req;
184 struct dpp_configuration *conf_ap;
185 struct dpp_configuration *conf_sta;
186 struct dpp_configurator *conf;
187 char *connector; /* received signedConnector */
188 u8 ssid[SSID_MAX_LEN];
189 u8 ssid_len;
8528994e
JM
190 char passphrase[64];
191 u8 psk[PMK_LEN];
192 int psk_set;
461d39af
JM
193 struct wpabuf *net_access_key;
194 os_time_t net_access_key_expiry;
195 struct wpabuf *c_sign_key;
461d39af
JM
196#ifdef CONFIG_TESTING_OPTIONS
197 char *config_obj_override;
198 char *discovery_override;
199 char *groups_override;
461d39af
JM
200 unsigned int ignore_netaccesskey_mismatch:1;
201#endif /* CONFIG_TESTING_OPTIONS */
202};
203
204struct dpp_configurator {
205 struct dl_list list;
206 unsigned int id;
207 int own;
208 EVP_PKEY *csign;
209 char *kid;
210 const struct dpp_curve_params *curve;
30d27b04
JM
211};
212
650a70a7
JM
213struct dpp_introduction {
214 u8 pmkid[PMKID_LEN];
215 u8 pmk[PMK_LEN_MAX];
216 size_t pmk_len;
650a70a7
JM
217};
218
60239f60
JM
219#ifdef CONFIG_TESTING_OPTIONS
220enum dpp_test_behavior {
221 DPP_TEST_DISABLED = 0,
222 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
223 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
224 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
225 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
226 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
227 DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
228 DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
229 DPP_TEST_ZERO_I_CAPAB = 8,
230 DPP_TEST_ZERO_R_CAPAB = 9,
0e7cb8c6
JM
231 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
232 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
233 DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
234 DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
235 DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
236 DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
ce9acce0
JM
237 DPP_TEST_NO_STATUS_AUTH_RESP = 16,
238 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
239 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
240 DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
241 DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
242 DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
243 DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
244 DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
245 DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
f9c7d770
JM
246 DPP_TEST_NO_STATUS_AUTH_CONF = 25,
247 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26,
248 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27,
249 DPP_TEST_NO_I_AUTH_AUTH_CONF = 28,
250 DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29,
978bc3f2
JM
251 DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30,
252 DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31,
253 DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32,
254 DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33,
61f9f27f
JM
255 DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34,
256 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35,
257 DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36,
258 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37,
259 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38,
260 DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39,
261 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40,
262 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41,
263 DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42,
264 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43,
1cfcbd32
JM
265 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44,
266 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45,
f31ef96d 267 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46,
89d0bf67
JM
268 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47,
269 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48,
60239f60
JM
270};
271
272extern enum dpp_test_behavior dpp_test;
273#endif /* CONFIG_TESTING_OPTIONS */
274
be27e185 275void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
484788b8 276const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
500ed7f0 277int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
be27e185
JM
278int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
279 const char *chan_list);
280int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
281int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
282struct dpp_bootstrap_info * dpp_parse_qr_code(const char *uri);
283char * dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
284 const u8 *privkey, size_t privkey_len);
30d27b04
JM
285struct dpp_authentication * dpp_auth_init(void *msg_ctx,
286 struct dpp_bootstrap_info *peer_bi,
287 struct dpp_bootstrap_info *own_bi,
d2709206
JM
288 int configurator,
289 unsigned int neg_freq);
30d27b04
JM
290struct dpp_authentication *
291dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
292 struct dpp_bootstrap_info *peer_bi,
293 struct dpp_bootstrap_info *own_bi,
dc4d271c 294 unsigned int freq, const u8 *hdr, const u8 *attr_start,
27fefbbb 295 size_t attr_len);
30d27b04 296struct wpabuf *
dc4d271c
JM
297dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
298 const u8 *attr_start, size_t attr_len);
461d39af
JM
299struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
300 const char *json);
dc4d271c
JM
301int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
302 const u8 *attr_start, size_t attr_len);
30d27b04
JM
303int dpp_notify_new_qr_code(struct dpp_authentication *auth,
304 struct dpp_bootstrap_info *peer_bi);
461d39af 305void dpp_configuration_free(struct dpp_configuration *conf);
30d27b04 306void dpp_auth_deinit(struct dpp_authentication *auth);
461d39af
JM
307struct wpabuf *
308dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
309 size_t attr_len);
310int dpp_conf_resp_rx(struct dpp_authentication *auth,
311 const struct wpabuf *resp);
30d27b04
JM
312struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
313 size_t len);
314const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
315int dpp_check_attrs(const u8 *buf, size_t len);
461d39af
JM
316int dpp_key_expired(const char *timestamp, os_time_t *expiry);
317void dpp_configurator_free(struct dpp_configurator *conf);
318struct dpp_configurator *
319dpp_keygen_configurator(const char *curve, const u8 *privkey,
320 size_t privkey_len);
f522bb23
JM
321int dpp_configurator_own_config(struct dpp_authentication *auth,
322 const char *curve);
e85b6601
JM
323enum dpp_status_error
324dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
325 const u8 *net_access_key, size_t net_access_key_len,
326 const u8 *csign_key, size_t csign_key_len,
327 const u8 *peer_connector, size_t peer_connector_len,
328 os_time_t *expiry);
219d4c9f 329struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi,
500ed7f0
JM
330 const u8 *own_mac,
331 const char *identifier,
332 const char *code);
219d4c9f
JM
333struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx,
334 struct dpp_bootstrap_info *bi,
500ed7f0
JM
335 const u8 *own_mac,
336 const u8 *peer_mac,
337 const char *identifier,
338 const char *code,
339 const u8 *buf, size_t len);
340struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
341 const u8 *buf, size_t len);
342struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
4be5bc98 343 const u8 *hdr,
500ed7f0 344 const u8 *buf, size_t len);
4be5bc98 345int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
500ed7f0
JM
346 const u8 *buf, size_t len);
347void dpp_pkex_free(struct dpp_pkex *pkex);
be27e185
JM
348
349#endif /* DPP_H */