2 * DPP functionality shared between hostapd and wpa_supplicant
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include <openssl/x509.h>
14 #include "utils/list.h"
15 #include "common/wpa_common.h"
16 #include "crypto/sha256.h"
18 #define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */
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,
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 */
60 enum dpp_status_error
{
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,
72 #define DPP_CAPAB_ENROLLEE BIT(0)
73 #define DPP_CAPAB_CONFIGURATOR BIT(1)
74 #define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
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
81 struct dpp_curve_params
{
84 size_t aes_siv_key_len
;
92 enum dpp_bootstrap_type
{
93 DPP_BOOTSTRAP_QR_CODE
,
97 struct dpp_bootstrap_info
{
100 enum dpp_bootstrap_type type
;
102 u8 mac_addr
[ETH_ALEN
];
104 unsigned int freq
[DPP_BOOTSTRAP_MAX_FREQ
];
105 unsigned int num_freq
;
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
114 #define PKEX_COUNTER_T_LIMIT 5
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
];
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 */
137 struct dpp_configuration
{
140 int dpp
; /* whether to use DPP or legacy configuration */
142 /* For DPP configuration (connector) */
143 os_time_t netaccesskey_expiry
;
147 /* For legacy configuration */
152 struct dpp_authentication
{
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
];
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
;
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
];
185 int waiting_auth_resp
;
186 int waiting_auth_conf
;
187 unsigned int auth_resp_tries
;
190 int remove_on_tx_status
;
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
];
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 */
213 struct dpp_configurator
{
219 const struct dpp_curve_params
*curve
;
222 struct dpp_introduction
{
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,
297 extern enum dpp_test_behavior dpp_test
;
298 #endif /* CONFIG_TESTING_OPTIONS */
300 void dpp_bootstrap_info_free(struct dpp_bootstrap_info
*info
);
301 const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type
);
302 int dpp_bootstrap_key_hash(struct dpp_bootstrap_info
*bi
);
303 int dpp_parse_uri_chan_list(struct dpp_bootstrap_info
*bi
,
304 const char *chan_list
);
305 int dpp_parse_uri_mac(struct dpp_bootstrap_info
*bi
, const char *mac
);
306 int dpp_parse_uri_info(struct dpp_bootstrap_info
*bi
, const char *info
);
307 struct dpp_bootstrap_info
* dpp_parse_qr_code(const char *uri
);
308 char * dpp_keygen(struct dpp_bootstrap_info
*bi
, const char *curve
,
309 const u8
*privkey
, size_t privkey_len
);
310 struct hostapd_hw_modes
;
311 struct dpp_authentication
* dpp_auth_init(void *msg_ctx
,
312 struct dpp_bootstrap_info
*peer_bi
,
313 struct dpp_bootstrap_info
*own_bi
,
314 u8 dpp_allowed_roles
,
315 unsigned int neg_freq
,
316 struct hostapd_hw_modes
*own_modes
,
318 struct dpp_authentication
*
319 dpp_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
,
322 unsigned int freq
, const u8
*hdr
, const u8
*attr_start
,
325 dpp_auth_resp_rx(struct dpp_authentication
*auth
, const u8
*hdr
,
326 const u8
*attr_start
, size_t attr_len
);
327 struct wpabuf
* dpp_build_conf_req(struct dpp_authentication
*auth
,
329 int dpp_auth_conf_rx(struct dpp_authentication
*auth
, const u8
*hdr
,
330 const u8
*attr_start
, size_t attr_len
);
331 int dpp_notify_new_qr_code(struct dpp_authentication
*auth
,
332 struct dpp_bootstrap_info
*peer_bi
);
333 void dpp_configuration_free(struct dpp_configuration
*conf
);
334 void dpp_auth_deinit(struct dpp_authentication
*auth
);
336 dpp_conf_req_rx(struct dpp_authentication
*auth
, const u8
*attr_start
,
338 int dpp_conf_resp_rx(struct dpp_authentication
*auth
,
339 const struct wpabuf
*resp
);
340 struct wpabuf
* dpp_alloc_msg(enum dpp_public_action_frame_type type
,
342 const u8
* dpp_get_attr(const u8
*buf
, size_t len
, u16 req_id
, u16
*ret_len
);
343 int dpp_check_attrs(const u8
*buf
, size_t len
);
344 int dpp_key_expired(const char *timestamp
, os_time_t
*expiry
);
345 void dpp_configurator_free(struct dpp_configurator
*conf
);
346 struct dpp_configurator
*
347 dpp_keygen_configurator(const char *curve
, const u8
*privkey
,
349 int dpp_configurator_own_config(struct dpp_authentication
*auth
,
351 enum dpp_status_error
352 dpp_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
,
357 struct dpp_pkex
* dpp_pkex_init(void *msg_ctx
, struct dpp_bootstrap_info
*bi
,
359 const char *identifier
,
361 struct dpp_pkex
* dpp_pkex_rx_exchange_req(void *msg_ctx
,
362 struct dpp_bootstrap_info
*bi
,
365 const char *identifier
,
367 const u8
*buf
, size_t len
);
368 struct wpabuf
* dpp_pkex_rx_exchange_resp(struct dpp_pkex
*pkex
,
369 const u8
*buf
, size_t len
);
370 struct wpabuf
* dpp_pkex_rx_commit_reveal_req(struct dpp_pkex
*pkex
,
372 const u8
*buf
, size_t len
);
373 int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex
*pkex
, const u8
*hdr
,
374 const u8
*buf
, size_t len
);
375 void dpp_pkex_free(struct dpp_pkex
*pkex
);