1 /* 2 * DPP functionality shared between hostapd and wpa_supplicant 3 * Copyright (c) 2017, Qualcomm Atheros, Inc. 4 * Copyright (c) 2018-2020, The Linux Foundation 5 * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc. 6 * 7 * This software may be distributed under the terms of the BSD license. 8 * See README for more details. 9 */ 10 11 #ifndef DPP_H 12 #define DPP_H 13 14 #ifdef CONFIG_DPP 15 #include "utils/list.h" 16 #include "common/wpa_common.h" 17 #include "crypto/sha256.h" 18 #include "crypto/crypto.h" 19 20 struct hostapd_ip_addr; 21 struct dpp_global; 22 struct json_token; 23 struct dpp_reconfig_id; 24 25 #ifdef CONFIG_TESTING_OPTIONS 26 #define DPP_VERSION (dpp_version_override) 27 extern int dpp_version_override; 28 #else /* CONFIG_TESTING_OPTIONS */ 29 #ifdef CONFIG_DPP3 30 #define DPP_VERSION 3 31 #elif defined(CONFIG_DPP2) 32 #define DPP_VERSION 2 33 #else 34 #define DPP_VERSION 1 35 #endif 36 #endif /* CONFIG_TESTING_OPTIONS */ 37 38 #define DPP_HDR_LEN (4 + 2) /* OUI, OUI Type, Crypto Suite, DPP frame type */ 39 #define DPP_TCP_PORT 8908 40 41 enum dpp_public_action_frame_type { 42 DPP_PA_AUTHENTICATION_REQ = 0, 43 DPP_PA_AUTHENTICATION_RESP = 1, 44 DPP_PA_AUTHENTICATION_CONF = 2, 45 DPP_PA_PEER_DISCOVERY_REQ = 5, 46 DPP_PA_PEER_DISCOVERY_RESP = 6, 47 DPP_PA_PKEX_V1_EXCHANGE_REQ = 7, 48 DPP_PA_PKEX_EXCHANGE_RESP = 8, 49 DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9, 50 DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10, 51 DPP_PA_CONFIGURATION_RESULT = 11, 52 DPP_PA_CONNECTION_STATUS_RESULT = 12, 53 DPP_PA_PRESENCE_ANNOUNCEMENT = 13, 54 DPP_PA_RECONFIG_ANNOUNCEMENT = 14, 55 DPP_PA_RECONFIG_AUTH_REQ = 15, 56 DPP_PA_RECONFIG_AUTH_RESP = 16, 57 DPP_PA_RECONFIG_AUTH_CONF = 17, 58 DPP_PA_PKEX_EXCHANGE_REQ = 18, 59 }; 60 61 enum dpp_attribute_id { 62 DPP_ATTR_STATUS = 0x1000, 63 DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001, 64 DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002, 65 DPP_ATTR_I_PROTOCOL_KEY = 0x1003, 66 DPP_ATTR_WRAPPED_DATA = 0x1004, 67 DPP_ATTR_I_NONCE = 0x1005, 68 DPP_ATTR_I_CAPABILITIES = 0x1006, 69 DPP_ATTR_R_NONCE = 0x1007, 70 DPP_ATTR_R_CAPABILITIES = 0x1008, 71 DPP_ATTR_R_PROTOCOL_KEY = 0x1009, 72 DPP_ATTR_I_AUTH_TAG = 0x100A, 73 DPP_ATTR_R_AUTH_TAG = 0x100B, 74 DPP_ATTR_CONFIG_OBJ = 0x100C, 75 DPP_ATTR_CONNECTOR = 0x100D, 76 DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E, 77 DPP_ATTR_BOOTSTRAP_KEY = 0x100F, 78 DPP_ATTR_OWN_NET_NK_HASH = 0x1011, 79 DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012, 80 DPP_ATTR_ENCRYPTED_KEY = 0x1013, 81 DPP_ATTR_ENROLLEE_NONCE = 0x1014, 82 DPP_ATTR_CODE_IDENTIFIER = 0x1015, 83 DPP_ATTR_TRANSACTION_ID = 0x1016, 84 DPP_ATTR_BOOTSTRAP_INFO = 0x1017, 85 DPP_ATTR_CHANNEL = 0x1018, 86 DPP_ATTR_PROTOCOL_VERSION = 0x1019, 87 DPP_ATTR_ENVELOPED_DATA = 0x101A, 88 DPP_ATTR_SEND_CONN_STATUS = 0x101B, 89 DPP_ATTR_CONN_STATUS = 0x101C, 90 DPP_ATTR_RECONFIG_FLAGS = 0x101D, 91 DPP_ATTR_C_SIGN_KEY_HASH = 0x101E, 92 DPP_ATTR_CSR_ATTR_REQ = 0x101F, 93 DPP_ATTR_A_NONCE = 0x1020, 94 DPP_ATTR_E_PRIME_ID = 0x1021, 95 DPP_ATTR_CONFIGURATOR_NONCE = 0x1022, 96 }; 97 98 enum dpp_status_error { 99 DPP_STATUS_OK = 0, 100 DPP_STATUS_NOT_COMPATIBLE = 1, 101 DPP_STATUS_AUTH_FAILURE = 2, 102 DPP_STATUS_UNWRAP_FAILURE = 3, 103 DPP_STATUS_BAD_GROUP = 4, 104 DPP_STATUS_CONFIGURE_FAILURE = 5, 105 DPP_STATUS_RESPONSE_PENDING = 6, 106 DPP_STATUS_INVALID_CONNECTOR = 7, 107 DPP_STATUS_NO_MATCH = 8, 108 DPP_STATUS_CONFIG_REJECTED = 9, 109 DPP_STATUS_NO_AP = 10, 110 DPP_STATUS_CONFIGURE_PENDING = 11, 111 DPP_STATUS_CSR_NEEDED = 12, 112 DPP_STATUS_CSR_BAD = 13, 113 DPP_STATUS_NEW_KEY_NEEDED = 14, 114 }; 115 116 /* DPP Reconfig Flags object - connectorKey values */ 117 enum dpp_connector_key { 118 DPP_CONFIG_REUSEKEY = 0, 119 DPP_CONFIG_REPLACEKEY = 1, 120 }; 121 122 #define DPP_CAPAB_ENROLLEE BIT(0) 123 #define DPP_CAPAB_CONFIGURATOR BIT(1) 124 #define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1)) 125 126 #define DPP_BOOTSTRAP_MAX_FREQ 30 127 #define DPP_MAX_NONCE_LEN 32 128 #define DPP_MAX_HASH_LEN 64 129 #define DPP_MAX_SHARED_SECRET_LEN 66 130 #define DPP_CP_LEN 64 131 132 struct dpp_curve_params { 133 const char *name; 134 size_t hash_len; 135 size_t aes_siv_key_len; 136 size_t nonce_len; 137 size_t prime_len; 138 const char *jwk_crv; 139 u16 ike_group; 140 const char *jws_alg; 141 }; 142 143 enum dpp_bootstrap_type { 144 DPP_BOOTSTRAP_QR_CODE, 145 DPP_BOOTSTRAP_PKEX, 146 DPP_BOOTSTRAP_NFC_URI, 147 }; 148 149 struct dpp_bootstrap_info { 150 struct dl_list list; 151 unsigned int id; 152 enum dpp_bootstrap_type type; 153 char *uri; 154 u8 mac_addr[ETH_ALEN]; 155 char *chan; 156 char *info; 157 char *pk; 158 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ]; 159 unsigned int num_freq; 160 bool channels_listed; 161 u8 version; 162 int own; 163 struct crypto_ec_key *pubkey; 164 u8 pubkey_hash[SHA256_MAC_LEN]; 165 u8 pubkey_hash_chirp[SHA256_MAC_LEN]; 166 const struct dpp_curve_params *curve; 167 unsigned int pkex_t; /* number of failures before dpp_pkex 168 * instantiation */ 169 int nfc_negotiated; /* whether this has been used in NFC negotiated 170 * connection handover */ 171 char *configurator_params; 172 }; 173 174 #define PKEX_COUNTER_T_LIMIT 5 175 176 enum dpp_pkex_ver { 177 PKEX_VER_AUTO, 178 PKEX_VER_ONLY_1, 179 PKEX_VER_ONLY_2, 180 }; 181 182 struct dpp_pkex { 183 void *msg_ctx; 184 unsigned int initiator:1; 185 unsigned int exchange_done:1; 186 unsigned int failed:1; 187 unsigned int v2:1; 188 unsigned int forced_ver:1; 189 struct dpp_bootstrap_info *own_bi; 190 u8 own_mac[ETH_ALEN]; 191 u8 peer_mac[ETH_ALEN]; 192 char *identifier; 193 char *code; 194 struct crypto_ec_key *x; 195 struct crypto_ec_key *y; 196 u8 Mx[DPP_MAX_SHARED_SECRET_LEN]; 197 u8 Nx[DPP_MAX_SHARED_SECRET_LEN]; 198 u8 z[DPP_MAX_HASH_LEN]; 199 struct crypto_ec_key *peer_bootstrap_key; 200 struct wpabuf *exchange_req; 201 struct wpabuf *exchange_resp; 202 unsigned int t; /* number of failures on code use */ 203 unsigned int exch_req_wait_time; 204 unsigned int exch_req_tries; 205 unsigned int freq; 206 u8 peer_version; 207 }; 208 209 enum dpp_akm { 210 DPP_AKM_UNKNOWN, 211 DPP_AKM_DPP, 212 DPP_AKM_PSK, 213 DPP_AKM_SAE, 214 DPP_AKM_PSK_SAE, 215 DPP_AKM_SAE_DPP, 216 DPP_AKM_PSK_SAE_DPP, 217 DPP_AKM_DOT1X, 218 }; 219 220 enum dpp_netrole { 221 DPP_NETROLE_STA, 222 DPP_NETROLE_AP, 223 DPP_NETROLE_CONFIGURATOR, 224 }; 225 226 struct dpp_configuration { 227 u8 ssid[32]; 228 size_t ssid_len; 229 int ssid_charset; 230 enum dpp_akm akm; 231 enum dpp_netrole netrole; 232 233 /* For DPP configuration (connector) */ 234 os_time_t netaccesskey_expiry; 235 236 /* TODO: groups */ 237 char *group_id; 238 239 /* For legacy configuration */ 240 char *passphrase; 241 u8 psk[32]; 242 int psk_set; 243 244 char *csrattrs; 245 }; 246 247 struct dpp_asymmetric_key { 248 struct dpp_asymmetric_key *next; 249 struct crypto_ec_key *csign; 250 struct crypto_ec_key *pp_key; 251 char *config_template; 252 char *connector_template; 253 }; 254 255 #define DPP_MAX_CONF_OBJ 10 256 257 struct dpp_authentication { 258 struct dpp_global *global; 259 void *msg_ctx; 260 u8 peer_version; 261 const struct dpp_curve_params *curve; 262 const struct dpp_curve_params *new_curve; 263 struct dpp_bootstrap_info *peer_bi; 264 struct dpp_bootstrap_info *own_bi; 265 struct dpp_bootstrap_info *tmp_own_bi; 266 struct dpp_bootstrap_info *tmp_peer_bi; 267 u8 waiting_pubkey_hash[SHA256_MAC_LEN]; 268 int response_pending; 269 int reconfig; 270 enum dpp_connector_key reconfig_connector_key; 271 enum dpp_status_error auth_resp_status; 272 enum dpp_status_error conf_resp_status; 273 enum dpp_status_error force_conf_resp_status; 274 u8 peer_mac_addr[ETH_ALEN]; 275 u8 i_nonce[DPP_MAX_NONCE_LEN]; 276 u8 r_nonce[DPP_MAX_NONCE_LEN]; 277 u8 e_nonce[DPP_MAX_NONCE_LEN]; 278 u8 c_nonce[DPP_MAX_NONCE_LEN]; 279 u8 i_capab; 280 u8 r_capab; 281 enum dpp_netrole e_netrole; 282 struct crypto_ec_key *own_protocol_key; 283 struct crypto_ec_key *peer_protocol_key; 284 struct crypto_ec_key *reconfig_old_protocol_key; 285 struct wpabuf *req_msg; 286 struct wpabuf *resp_msg; 287 struct wpabuf *reconfig_req_msg; 288 struct wpabuf *reconfig_resp_msg; 289 /* Intersection of possible frequencies for initiating DPP 290 * Authentication exchange */ 291 unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ]; 292 unsigned int num_freq, freq_idx; 293 unsigned int curr_freq; 294 unsigned int neg_freq; 295 unsigned int num_freq_iters; 296 size_t secret_len; 297 u8 Mx[DPP_MAX_SHARED_SECRET_LEN]; 298 size_t Mx_len; 299 u8 Nx[DPP_MAX_SHARED_SECRET_LEN]; 300 size_t Nx_len; 301 u8 Lx[DPP_MAX_SHARED_SECRET_LEN]; 302 size_t Lx_len; 303 u8 k1[DPP_MAX_HASH_LEN]; 304 u8 k2[DPP_MAX_HASH_LEN]; 305 u8 ke[DPP_MAX_HASH_LEN]; 306 u8 bk[DPP_MAX_HASH_LEN]; 307 int initiator; 308 int waiting_auth_resp; 309 int waiting_auth_conf; 310 int auth_req_ack; 311 unsigned int auth_resp_tries; 312 u8 allowed_roles; 313 int configurator; 314 int remove_on_tx_status; 315 int connect_on_tx_status; 316 int waiting_conf_result; 317 int waiting_conn_status_result; 318 int auth_success; 319 bool reconfig_success; 320 struct wpabuf *conf_req; 321 const struct wpabuf *conf_resp; /* owned by GAS server */ 322 struct wpabuf *conf_resp_tcp; 323 struct dpp_configuration *conf_ap; 324 struct dpp_configuration *conf2_ap; 325 struct dpp_configuration *conf_sta; 326 struct dpp_configuration *conf2_sta; 327 int provision_configurator; 328 struct dpp_configurator *conf; 329 struct dpp_config_obj { 330 char *connector; /* received signedConnector */ 331 u8 ssid[SSID_MAX_LEN]; 332 u8 ssid_len; 333 int ssid_charset; 334 char passphrase[64]; 335 u8 psk[PMK_LEN]; 336 int psk_set; 337 enum dpp_akm akm; 338 struct wpabuf *c_sign_key; 339 struct wpabuf *certbag; 340 struct wpabuf *certs; 341 struct wpabuf *cacert; 342 char *server_name; 343 struct wpabuf *pp_key; 344 } conf_obj[DPP_MAX_CONF_OBJ]; 345 unsigned int num_conf_obj; 346 struct dpp_asymmetric_key *conf_key_pkg; 347 struct wpabuf *net_access_key; 348 os_time_t net_access_key_expiry; 349 int send_conn_status; 350 int conn_status_requested; 351 int akm_use_selector; 352 int configurator_set; 353 u8 transaction_id; 354 u8 *csrattrs; 355 size_t csrattrs_len; 356 bool waiting_csr; 357 struct wpabuf *csr; 358 struct wpabuf *priv_key; /* DER-encoded private key used for csr */ 359 bool waiting_cert; 360 char *trusted_eap_server_name; 361 struct wpabuf *cacert; 362 struct wpabuf *certbag; 363 bool waiting_new_key; 364 bool new_key_received; 365 void *config_resp_ctx; 366 void *gas_server_ctx; 367 bool use_config_query; 368 bool waiting_config; 369 char *e_name; 370 char *e_mud_url; 371 int *e_band_support; 372 #ifdef CONFIG_TESTING_OPTIONS 373 char *config_obj_override; 374 char *discovery_override; 375 char *groups_override; 376 unsigned int ignore_netaccesskey_mismatch:1; 377 #endif /* CONFIG_TESTING_OPTIONS */ 378 }; 379 380 struct dpp_configurator { 381 struct dl_list list; 382 unsigned int id; 383 int own; 384 struct crypto_ec_key *csign; 385 u8 kid_hash[SHA256_MAC_LEN]; 386 char *kid; 387 const struct dpp_curve_params *curve; 388 const struct dpp_curve_params *net_access_key_curve; 389 char *connector; /* own Connector for reconfiguration */ 390 struct crypto_ec_key *connector_key; 391 struct crypto_ec_key *pp_key; 392 }; 393 394 struct dpp_introduction { 395 u8 pmkid[PMKID_LEN]; 396 u8 pmk[PMK_LEN_MAX]; 397 size_t pmk_len; 398 int peer_version; 399 }; 400 401 struct dpp_relay_config { 402 const struct hostapd_ip_addr *ipaddr; 403 const u8 *pkhash; 404 405 void *msg_ctx; 406 void *cb_ctx; 407 void (*tx)(void *ctx, const u8 *addr, unsigned int freq, const u8 *msg, 408 size_t len); 409 void (*gas_resp_tx)(void *ctx, const u8 *addr, u8 dialog_token, int prot, 410 struct wpabuf *buf); 411 }; 412 413 struct dpp_controller_config { 414 const char *configurator_params; 415 int tcp_port; 416 u8 allowed_roles; 417 int qr_mutual; 418 enum dpp_netrole netrole; 419 void *msg_ctx; 420 void *cb_ctx; 421 int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth); 422 bool (*tcp_msg_sent)(void *ctx, struct dpp_authentication *auth); 423 }; 424 425 #ifdef CONFIG_TESTING_OPTIONS 426 enum dpp_test_behavior { 427 DPP_TEST_DISABLED = 0, 428 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1, 429 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2, 430 DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3, 431 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4, 432 DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5, 433 DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6, 434 DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7, 435 DPP_TEST_ZERO_I_CAPAB = 8, 436 DPP_TEST_ZERO_R_CAPAB = 9, 437 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10, 438 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11, 439 DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12, 440 DPP_TEST_NO_I_NONCE_AUTH_REQ = 13, 441 DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14, 442 DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15, 443 DPP_TEST_NO_STATUS_AUTH_RESP = 16, 444 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17, 445 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18, 446 DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19, 447 DPP_TEST_NO_R_NONCE_AUTH_RESP = 20, 448 DPP_TEST_NO_I_NONCE_AUTH_RESP = 21, 449 DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22, 450 DPP_TEST_NO_R_AUTH_AUTH_RESP = 23, 451 DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24, 452 DPP_TEST_NO_STATUS_AUTH_CONF = 25, 453 DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 26, 454 DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 27, 455 DPP_TEST_NO_I_AUTH_AUTH_CONF = 28, 456 DPP_TEST_NO_WRAPPED_DATA_AUTH_CONF = 29, 457 DPP_TEST_I_NONCE_MISMATCH_AUTH_RESP = 30, 458 DPP_TEST_INCOMPATIBLE_R_CAPAB_AUTH_RESP = 31, 459 DPP_TEST_R_AUTH_MISMATCH_AUTH_RESP = 32, 460 DPP_TEST_I_AUTH_MISMATCH_AUTH_CONF = 33, 461 DPP_TEST_NO_FINITE_CYCLIC_GROUP_PKEX_EXCHANGE_REQ = 34, 462 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 35, 463 DPP_TEST_NO_STATUS_PKEX_EXCHANGE_RESP = 36, 464 DPP_TEST_NO_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 37, 465 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_REQ = 38, 466 DPP_TEST_NO_I_AUTH_TAG_PKEX_CR_REQ = 39, 467 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_REQ = 40, 468 DPP_TEST_NO_BOOTSTRAP_KEY_PKEX_CR_RESP = 41, 469 DPP_TEST_NO_R_AUTH_TAG_PKEX_CR_RESP = 42, 470 DPP_TEST_NO_WRAPPED_DATA_PKEX_CR_RESP = 43, 471 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_REQ = 44, 472 DPP_TEST_INVALID_ENCRYPTED_KEY_PKEX_EXCHANGE_RESP = 45, 473 DPP_TEST_INVALID_STATUS_PKEX_EXCHANGE_RESP = 46, 474 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_REQ = 47, 475 DPP_TEST_INVALID_BOOTSTRAP_KEY_PKEX_CR_RESP = 48, 476 DPP_TEST_I_AUTH_TAG_MISMATCH_PKEX_CR_REQ = 49, 477 DPP_TEST_R_AUTH_TAG_MISMATCH_PKEX_CR_RESP = 50, 478 DPP_TEST_NO_E_NONCE_CONF_REQ = 51, 479 DPP_TEST_NO_CONFIG_ATTR_OBJ_CONF_REQ = 52, 480 DPP_TEST_NO_WRAPPED_DATA_CONF_REQ = 53, 481 DPP_TEST_NO_E_NONCE_CONF_RESP = 54, 482 DPP_TEST_NO_CONFIG_OBJ_CONF_RESP = 55, 483 DPP_TEST_NO_STATUS_CONF_RESP = 56, 484 DPP_TEST_NO_WRAPPED_DATA_CONF_RESP = 57, 485 DPP_TEST_INVALID_STATUS_CONF_RESP = 58, 486 DPP_TEST_E_NONCE_MISMATCH_CONF_RESP = 59, 487 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ = 60, 488 DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ = 61, 489 DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP = 62, 490 DPP_TEST_NO_STATUS_PEER_DISC_RESP = 63, 491 DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP = 64, 492 DPP_TEST_AUTH_RESP_IN_PLACE_OF_CONF = 65, 493 DPP_TEST_INVALID_I_PROTO_KEY_AUTH_REQ = 66, 494 DPP_TEST_INVALID_R_PROTO_KEY_AUTH_RESP = 67, 495 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 68, 496 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 69, 497 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 70, 498 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 71, 499 DPP_TEST_INVALID_R_BOOTSTRAP_KEY_HASH_AUTH_CONF = 72, 500 DPP_TEST_INVALID_I_BOOTSTRAP_KEY_HASH_AUTH_CONF = 73, 501 DPP_TEST_INVALID_STATUS_AUTH_RESP = 74, 502 DPP_TEST_INVALID_STATUS_AUTH_CONF = 75, 503 DPP_TEST_INVALID_CONFIG_ATTR_OBJ_CONF_REQ = 76, 504 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP = 77, 505 DPP_TEST_INVALID_STATUS_PEER_DISC_RESP = 78, 506 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP = 79, 507 DPP_TEST_INVALID_CONNECTOR_PEER_DISC_REQ = 80, 508 DPP_TEST_INVALID_I_NONCE_AUTH_REQ = 81, 509 DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_REQ = 82, 510 DPP_TEST_INVALID_E_NONCE_CONF_REQ = 83, 511 DPP_TEST_STOP_AT_PKEX_EXCHANGE_RESP = 84, 512 DPP_TEST_STOP_AT_PKEX_CR_REQ = 85, 513 DPP_TEST_STOP_AT_PKEX_CR_RESP = 86, 514 DPP_TEST_STOP_AT_AUTH_REQ = 87, 515 DPP_TEST_STOP_AT_AUTH_RESP = 88, 516 DPP_TEST_STOP_AT_AUTH_CONF = 89, 517 DPP_TEST_STOP_AT_CONF_REQ = 90, 518 DPP_TEST_REJECT_CONFIG = 91, 519 DPP_TEST_NO_PROTOCOL_VERSION_PEER_DISC_REQ = 92, 520 DPP_TEST_NO_PROTOCOL_VERSION_PEER_DISC_RESP = 93, 521 DPP_TEST_INVALID_PROTOCOL_VERSION_PEER_DISC_REQ = 94, 522 DPP_TEST_INVALID_PROTOCOL_VERSION_PEER_DISC_RESP = 95, 523 DPP_TEST_INVALID_PROTOCOL_VERSION_RECONFIG_AUTH_REQ = 96, 524 DPP_TEST_NO_PROTOCOL_VERSION_RECONFIG_AUTH_REQ = 97, 525 }; 526 527 extern enum dpp_test_behavior dpp_test; 528 extern u8 dpp_pkex_own_mac_override[ETH_ALEN]; 529 extern u8 dpp_pkex_peer_mac_override[ETH_ALEN]; 530 extern u8 dpp_pkex_ephemeral_key_override[600]; 531 extern size_t dpp_pkex_ephemeral_key_override_len; 532 extern u8 dpp_protocol_key_override[600]; 533 extern size_t dpp_protocol_key_override_len; 534 extern u8 dpp_nonce_override[DPP_MAX_NONCE_LEN]; 535 extern size_t dpp_nonce_override_len; 536 #endif /* CONFIG_TESTING_OPTIONS */ 537 538 void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info); 539 const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type); 540 int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi, 541 const char *chan_list); 542 int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac); 543 int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info); 544 int dpp_nfc_update_bi(struct dpp_bootstrap_info *own_bi, 545 struct dpp_bootstrap_info *peer_bi); 546 const char * dpp_netrole_str(enum dpp_netrole netrole); 547 struct dpp_authentication * 548 dpp_alloc_auth(struct dpp_global *dpp, void *msg_ctx); 549 struct hostapd_hw_modes; 550 struct dpp_authentication * dpp_auth_init(struct dpp_global *dpp, void *msg_ctx, 551 struct dpp_bootstrap_info *peer_bi, 552 struct dpp_bootstrap_info *own_bi, 553 u8 dpp_allowed_roles, 554 unsigned int neg_freq, 555 struct hostapd_hw_modes *own_modes, 556 u16 num_modes); 557 struct dpp_authentication * 558 dpp_auth_req_rx(struct dpp_global *dpp, void *msg_ctx, u8 dpp_allowed_roles, 559 int qr_mutual, struct dpp_bootstrap_info *peer_bi, 560 struct dpp_bootstrap_info *own_bi, 561 unsigned int freq, const u8 *hdr, const u8 *attr_start, 562 size_t attr_len); 563 struct wpabuf * 564 dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr, 565 const u8 *attr_start, size_t attr_len); 566 struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth, 567 const char *json); 568 struct wpabuf * dpp_build_conf_req_helper(struct dpp_authentication *auth, 569 const char *name, 570 enum dpp_netrole netrole, 571 const char *mud_url, int *opclasses); 572 int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr, 573 const u8 *attr_start, size_t attr_len); 574 int dpp_notify_new_qr_code(struct dpp_authentication *auth, 575 struct dpp_bootstrap_info *peer_bi); 576 void dpp_controller_pkex_add(struct dpp_global *dpp, 577 struct dpp_bootstrap_info *bi, 578 const char *code, const char *identifier); 579 struct dpp_configuration * dpp_configuration_alloc(const char *type); 580 int dpp_akm_psk(enum dpp_akm akm); 581 int dpp_akm_sae(enum dpp_akm akm); 582 int dpp_akm_legacy(enum dpp_akm akm); 583 int dpp_akm_dpp(enum dpp_akm akm); 584 int dpp_akm_ver2(enum dpp_akm akm); 585 int dpp_configuration_valid(const struct dpp_configuration *conf); 586 void dpp_configuration_free(struct dpp_configuration *conf); 587 int dpp_set_configurator(struct dpp_authentication *auth, const char *cmd); 588 void dpp_auth_deinit(struct dpp_authentication *auth); 589 struct wpabuf * 590 dpp_build_conf_resp(struct dpp_authentication *auth, const u8 *e_nonce, 591 u16 e_nonce_len, enum dpp_netrole netrole, 592 bool cert_req); 593 struct wpabuf * 594 dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start, 595 size_t attr_len); 596 int dpp_conf_resp_rx(struct dpp_authentication *auth, 597 const struct wpabuf *resp); 598 enum dpp_status_error dpp_conf_result_rx(struct dpp_authentication *auth, 599 const u8 *hdr, 600 const u8 *attr_start, size_t attr_len); 601 struct wpabuf * dpp_build_conf_result(struct dpp_authentication *auth, 602 enum dpp_status_error status); 603 enum dpp_status_error dpp_conn_status_result_rx(struct dpp_authentication *auth, 604 const u8 *hdr, 605 const u8 *attr_start, 606 size_t attr_len, 607 u8 *ssid, size_t *ssid_len, 608 char **channel_list); 609 struct wpabuf * dpp_build_conn_status_result(struct dpp_authentication *auth, 610 enum dpp_status_error result, 611 const u8 *ssid, size_t ssid_len, 612 const char *channel_list); 613 struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type, 614 size_t len); 615 const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len); 616 int dpp_check_attrs(const u8 *buf, size_t len); 617 int dpp_key_expired(const char *timestamp, os_time_t *expiry); 618 const char * dpp_akm_str(enum dpp_akm akm); 619 const char * dpp_akm_selector_str(enum dpp_akm akm); 620 int dpp_configurator_get_key(const struct dpp_configurator *conf, char *buf, 621 size_t buflen); 622 void dpp_configurator_free(struct dpp_configurator *conf); 623 int dpp_configurator_own_config(struct dpp_authentication *auth, 624 const char *curve, int ap); 625 enum dpp_status_error 626 dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector, 627 const u8 *net_access_key, size_t net_access_key_len, 628 const u8 *csign_key, size_t csign_key_len, 629 const u8 *peer_connector, size_t peer_connector_len, 630 os_time_t *expiry); 631 int dpp_get_connector_version(const char *connector); 632 struct dpp_pkex * dpp_pkex_init(void *msg_ctx, struct dpp_bootstrap_info *bi, 633 const u8 *own_mac, 634 const char *identifier, const char *code, 635 bool v2); 636 struct dpp_pkex * dpp_pkex_rx_exchange_req(void *msg_ctx, 637 struct dpp_bootstrap_info *bi, 638 const u8 *own_mac, 639 const u8 *peer_mac, 640 const char *identifier, 641 const char *code, 642 const u8 *buf, size_t len, bool v2); 643 struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex, 644 const u8 *peer_mac, 645 const u8 *buf, size_t len); 646 struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex, 647 const u8 *hdr, 648 const u8 *buf, size_t len); 649 int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr, 650 const u8 *buf, size_t len); 651 void dpp_pkex_free(struct dpp_pkex *pkex); 652 653 char * dpp_corrupt_connector_signature(const char *connector); 654 655 656 struct dpp_pfs { 657 struct crypto_ecdh *ecdh; 658 const struct dpp_curve_params *curve; 659 struct wpabuf *ie; 660 struct wpabuf *secret; 661 }; 662 663 struct dpp_pfs * dpp_pfs_init(const u8 *net_access_key, 664 size_t net_access_key_len); 665 int dpp_pfs_process(struct dpp_pfs *pfs, const u8 *peer_ie, size_t peer_ie_len); 666 void dpp_pfs_free(struct dpp_pfs *pfs); 667 668 struct wpabuf * dpp_build_csr(struct dpp_authentication *auth, 669 const char *name); 670 int dpp_validate_csr(struct dpp_authentication *auth, const struct wpabuf *csr); 671 672 struct dpp_bootstrap_info * dpp_add_qr_code(struct dpp_global *dpp, 673 const char *uri); 674 struct dpp_bootstrap_info * dpp_add_nfc_uri(struct dpp_global *dpp, 675 const char *uri); 676 int dpp_bootstrap_gen(struct dpp_global *dpp, const char *cmd); 677 struct dpp_bootstrap_info * 678 dpp_bootstrap_get_id(struct dpp_global *dpp, unsigned int id); 679 int dpp_bootstrap_remove(struct dpp_global *dpp, const char *id); 680 struct dpp_bootstrap_info * 681 dpp_pkex_finish(struct dpp_global *dpp, struct dpp_pkex *pkex, const u8 *peer, 682 unsigned int freq); 683 const char * dpp_bootstrap_get_uri(struct dpp_global *dpp, unsigned int id); 684 int dpp_bootstrap_info(struct dpp_global *dpp, int id, 685 char *reply, int reply_size); 686 int dpp_bootstrap_set(struct dpp_global *dpp, int id, const char *params); 687 void dpp_bootstrap_find_pair(struct dpp_global *dpp, const u8 *i_bootstrap, 688 const u8 *r_bootstrap, 689 struct dpp_bootstrap_info **own_bi, 690 struct dpp_bootstrap_info **peer_bi); 691 struct dpp_bootstrap_info * dpp_bootstrap_find_chirp(struct dpp_global *dpp, 692 const u8 *hash); 693 int dpp_configurator_add(struct dpp_global *dpp, const char *cmd); 694 int dpp_configurator_set(struct dpp_global *dpp, const char *cmd); 695 int dpp_configurator_remove(struct dpp_global *dpp, const char *id); 696 int dpp_configurator_get_key_id(struct dpp_global *dpp, unsigned int id, 697 char *buf, size_t buflen); 698 int dpp_configurator_from_backup(struct dpp_global *dpp, 699 struct dpp_asymmetric_key *key); 700 struct dpp_configurator * dpp_configurator_find_kid(struct dpp_global *dpp, 701 const u8 *kid); 702 int dpp_relay_add_controller(struct dpp_global *dpp, 703 struct dpp_relay_config *config); 704 int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr, 705 const u8 *buf, size_t len, unsigned int freq, 706 const u8 *i_bootstrap, const u8 *r_bootstrap, 707 void *cb_ctx); 708 int dpp_relay_rx_gas_req(struct dpp_global *dpp, const u8 *src, const u8 *data, 709 size_t data_len); 710 int dpp_controller_start(struct dpp_global *dpp, 711 struct dpp_controller_config *config); 712 void dpp_controller_stop(struct dpp_global *dpp); 713 void dpp_controller_stop_for_ctx(struct dpp_global *dpp, void *cb_ctx); 714 struct dpp_authentication * dpp_controller_get_auth(struct dpp_global *dpp, 715 unsigned int id); 716 void dpp_controller_new_qr_code(struct dpp_global *dpp, 717 struct dpp_bootstrap_info *bi); 718 int dpp_tcp_pkex_init(struct dpp_global *dpp, struct dpp_pkex *pkex, 719 const struct hostapd_ip_addr *addr, int port, 720 void *msg_ctx, void *cb_ctx, 721 int (*pkex_done)(void *ctx, void *conn, 722 struct dpp_bootstrap_info *bi)); 723 int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth, 724 const struct hostapd_ip_addr *addr, int port, 725 const char *name, enum dpp_netrole netrole, void *msg_ctx, 726 void *cb_ctx, 727 int (*process_conf_obj)(void *ctx, 728 struct dpp_authentication *auth), 729 bool (*tcp_msg_sent)(void *ctx, 730 struct dpp_authentication *auth)); 731 int dpp_tcp_auth(struct dpp_global *dpp, void *_conn, 732 struct dpp_authentication *auth, const char *name, 733 enum dpp_netrole netrole, 734 int (*process_conf_obj)(void *ctx, 735 struct dpp_authentication *auth), 736 bool (*tcp_msg_sent)(void *ctx, 737 struct dpp_authentication *auth)); 738 bool dpp_tcp_conn_status_requested(struct dpp_global *dpp); 739 void dpp_tcp_send_conn_status(struct dpp_global *dpp, 740 enum dpp_status_error result, 741 const u8 *ssid, size_t ssid_len, 742 const char *channel_list); 743 744 struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi); 745 void dpp_notify_chirp_received(void *msg_ctx, int id, const u8 *src, 746 unsigned int freq, const u8 *hash); 747 748 struct dpp_global_config { 749 void *cb_ctx; 750 void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi); 751 }; 752 753 struct dpp_global * dpp_global_init(struct dpp_global_config *config); 754 void dpp_global_clear(struct dpp_global *dpp); 755 void dpp_global_deinit(struct dpp_global *dpp); 756 757 /* dpp_reconfig.c */ 758 759 struct wpabuf * dpp_build_reconfig_announcement(const u8 *csign_key, 760 size_t csign_key_len, 761 const u8 *net_access_key, 762 size_t net_access_key_len, 763 struct dpp_reconfig_id *id); 764 struct dpp_authentication * 765 dpp_reconfig_init(struct dpp_global *dpp, void *msg_ctx, 766 struct dpp_configurator *conf, unsigned int freq, u16 group, 767 const u8 *a_nonce_attr, size_t a_nonce_len, 768 const u8 *e_id_attr, size_t e_id_len); 769 struct dpp_authentication * 770 dpp_reconfig_auth_req_rx(struct dpp_global *dpp, void *msg_ctx, 771 const char *own_connector, 772 const u8 *net_access_key, size_t net_access_key_len, 773 const u8 *csign_key, size_t csign_key_len, 774 unsigned int freq, const u8 *hdr, 775 const u8 *attr_start, size_t attr_len); 776 struct wpabuf * 777 dpp_reconfig_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr, 778 const u8 *attr_start, size_t attr_len); 779 int dpp_reconfig_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr, 780 const u8 *attr_start, size_t attr_len); 781 782 struct dpp_reconfig_id * dpp_gen_reconfig_id(const u8 *csign_key, 783 size_t csign_key_len, 784 const u8 *pp_key, 785 size_t pp_key_len); 786 int dpp_update_reconfig_id(struct dpp_reconfig_id *id); 787 void dpp_free_reconfig_id(struct dpp_reconfig_id *id); 788 789 #endif /* CONFIG_DPP */ 790 #endif /* DPP_H */ 791