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 "crypto/sha256.h"
17 /* DPP Public Action frame identifiers - OUI_WFA */
18 #define DPP_OUI_TYPE 0x1A
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_PEER_NET_PK_HASH
= 0x1010,
50 DPP_ATTR_OWN_NET_NK_HASH
= 0x1011,
51 DPP_ATTR_FINITE_CYCLIC_GROUP
= 0x1012,
52 DPP_ATTR_ENCRYPTED_KEY
= 0x1013,
53 DPP_ATTR_ENROLLEE_NONCE
= 0x1014,
54 DPP_ATTR_CODE_IDENTIFIER
= 0x1015,
57 enum dpp_status_error
{
59 DPP_STATUS_NOT_COMPATIBLE
= 1,
60 DPP_STATUS_AUTH_FAILURE
= 2,
61 DPP_STATUS_UNWRAP_FAILURE
= 3,
62 DPP_STATUS_BAD_GROUP
= 4,
63 DPP_STATUS_CONFIGURE_FAILURE
= 5,
64 DPP_STATUS_RESPONSE_PENDING
= 6,
67 #define DPP_CAPAB_ENROLLEE BIT(0)
68 #define DPP_CAPAB_CONFIGURATOR BIT(1)
69 #define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
71 #define DPP_BOOTSTRAP_MAX_FREQ 30
72 #define DPP_MAX_NONCE_LEN 32
73 #define DPP_MAX_HASH_LEN 64
74 #define DPP_MAX_SHARED_SECRET_LEN 66
76 struct dpp_curve_params
{
79 size_t aes_siv_key_len
;
85 enum dpp_bootstrap_type
{
86 DPP_BOOTSTRAP_QR_CODE
,
89 struct dpp_bootstrap_info
{
92 enum dpp_bootstrap_type type
;
94 u8 mac_addr
[ETH_ALEN
];
96 unsigned int freq
[DPP_BOOTSTRAP_MAX_FREQ
];
97 unsigned int num_freq
;
100 u8 pubkey_hash
[SHA256_MAC_LEN
];
101 const struct dpp_curve_params
*curve
;
104 struct dpp_configuration
{
107 int dpp
; /* whether to use DPP or legacy configuration */
109 /* For DPP configuration (connector) */
110 os_time_t netaccesskey_expiry
;
112 /* TODO: groups, devices */
114 /* For legacy configuration */
119 struct dpp_authentication
{
121 const struct dpp_curve_params
*curve
;
122 struct dpp_bootstrap_info
*peer_bi
;
123 struct dpp_bootstrap_info
*own_bi
;
124 u8 waiting_pubkey_hash
[SHA256_MAC_LEN
];
125 int response_pending
;
126 enum dpp_status_error auth_resp_status
;
127 u8 peer_mac_addr
[ETH_ALEN
];
128 u8 i_nonce
[DPP_MAX_NONCE_LEN
];
129 u8 r_nonce
[DPP_MAX_NONCE_LEN
];
130 u8 e_nonce
[DPP_MAX_NONCE_LEN
];
133 EVP_PKEY
*own_protocol_key
;
134 EVP_PKEY
*peer_protocol_key
;
135 struct wpabuf
*req_attr
;
136 struct wpabuf
*resp_attr
;
137 unsigned int curr_freq
;
139 u8 Mx
[DPP_MAX_SHARED_SECRET_LEN
];
140 u8 Nx
[DPP_MAX_SHARED_SECRET_LEN
];
141 u8 Lx
[DPP_MAX_SHARED_SECRET_LEN
];
142 u8 k1
[DPP_MAX_HASH_LEN
];
143 u8 k2
[DPP_MAX_HASH_LEN
];
144 u8 ke
[DPP_MAX_HASH_LEN
];
147 int remove_on_tx_status
;
149 struct wpabuf
*conf_req
;
150 struct dpp_configuration
*conf_ap
;
151 struct dpp_configuration
*conf_sta
;
152 struct dpp_configurator
*conf
;
153 char *connector
; /* received signedConnector */
154 u8 ssid
[SSID_MAX_LEN
];
156 struct wpabuf
*net_access_key
;
157 os_time_t net_access_key_expiry
;
158 struct wpabuf
*c_sign_key
;
159 os_time_t c_sign_key_expiry
;
160 #ifdef CONFIG_TESTING_OPTIONS
161 char *config_obj_override
;
162 char *discovery_override
;
163 char *groups_override
;
164 char *devices_override
;
165 unsigned int ignore_netaccesskey_mismatch
:1;
166 #endif /* CONFIG_TESTING_OPTIONS */
169 struct dpp_configurator
{
175 const struct dpp_curve_params
*curve
;
176 os_time_t csign_expiry
;
179 void dpp_bootstrap_info_free(struct dpp_bootstrap_info
*info
);
180 int dpp_parse_uri_chan_list(struct dpp_bootstrap_info
*bi
,
181 const char *chan_list
);
182 int dpp_parse_uri_mac(struct dpp_bootstrap_info
*bi
, const char *mac
);
183 int dpp_parse_uri_info(struct dpp_bootstrap_info
*bi
, const char *info
);
184 struct dpp_bootstrap_info
* dpp_parse_qr_code(const char *uri
);
185 char * dpp_keygen(struct dpp_bootstrap_info
*bi
, const char *curve
,
186 const u8
*privkey
, size_t privkey_len
);
187 struct dpp_authentication
* dpp_auth_init(void *msg_ctx
,
188 struct dpp_bootstrap_info
*peer_bi
,
189 struct dpp_bootstrap_info
*own_bi
,
191 struct dpp_authentication
*
192 dpp_auth_req_rx(void *msg_ctx
, u8 dpp_allowed_roles
, int qr_mutual
,
193 struct dpp_bootstrap_info
*peer_bi
,
194 struct dpp_bootstrap_info
*own_bi
,
195 unsigned int freq
, const u8
*attr_start
,
196 const u8
*wrapped_data
, u16 wrapped_data_len
);
198 dpp_auth_resp_rx(struct dpp_authentication
*auth
, const u8
*attr_start
,
200 struct wpabuf
* dpp_build_conf_req(struct dpp_authentication
*auth
,
202 int dpp_auth_conf_rx(struct dpp_authentication
*auth
, const u8
*attr_start
,
204 int dpp_notify_new_qr_code(struct dpp_authentication
*auth
,
205 struct dpp_bootstrap_info
*peer_bi
);
206 void dpp_configuration_free(struct dpp_configuration
*conf
);
207 void dpp_auth_deinit(struct dpp_authentication
*auth
);
209 dpp_conf_req_rx(struct dpp_authentication
*auth
, const u8
*attr_start
,
211 int dpp_conf_resp_rx(struct dpp_authentication
*auth
,
212 const struct wpabuf
*resp
);
213 struct wpabuf
* dpp_alloc_msg(enum dpp_public_action_frame_type type
,
215 const u8
* dpp_get_attr(const u8
*buf
, size_t len
, u16 req_id
, u16
*ret_len
);
216 int dpp_check_attrs(const u8
*buf
, size_t len
);
217 int dpp_key_expired(const char *timestamp
, os_time_t
*expiry
);
218 void dpp_configurator_free(struct dpp_configurator
*conf
);
219 struct dpp_configurator
*
220 dpp_keygen_configurator(const char *curve
, const u8
*privkey
,