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