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