dpp.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * DPP functionality shared between hostapd and wpa_supplicant
  3. * Copyright (c) 2017, Qualcomm Atheros, Inc.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef DPP_H
  9. #define DPP_H
  10. #include <openssl/x509.h>
  11. #include "utils/list.h"
  12. #include "common/wpa_common.h"
  13. #include "crypto/sha256.h"
  14. /* DPP Public Action frame identifiers - OUI_WFA */
  15. #define DPP_OUI_TYPE 0x1A
  16. enum dpp_public_action_frame_type {
  17. DPP_PA_AUTHENTICATION_REQ = 0,
  18. DPP_PA_AUTHENTICATION_RESP = 1,
  19. DPP_PA_AUTHENTICATION_CONF = 2,
  20. DPP_PA_PEER_DISCOVERY_REQ = 5,
  21. DPP_PA_PEER_DISCOVERY_RESP = 6,
  22. DPP_PA_PKEX_EXCHANGE_REQ = 7,
  23. DPP_PA_PKEX_EXCHANGE_RESP = 8,
  24. DPP_PA_PKEX_COMMIT_REVEAL_REQ = 9,
  25. DPP_PA_PKEX_COMMIT_REVEAL_RESP = 10,
  26. };
  27. enum dpp_attribute_id {
  28. DPP_ATTR_STATUS = 0x1000,
  29. DPP_ATTR_I_BOOTSTRAP_KEY_HASH = 0x1001,
  30. DPP_ATTR_R_BOOTSTRAP_KEY_HASH = 0x1002,
  31. DPP_ATTR_I_PROTOCOL_KEY = 0x1003,
  32. DPP_ATTR_WRAPPED_DATA = 0x1004,
  33. DPP_ATTR_I_NONCE = 0x1005,
  34. DPP_ATTR_I_CAPABILITIES = 0x1006,
  35. DPP_ATTR_R_NONCE = 0x1007,
  36. DPP_ATTR_R_CAPABILITIES = 0x1008,
  37. DPP_ATTR_R_PROTOCOL_KEY = 0x1009,
  38. DPP_ATTR_I_AUTH_TAG = 0x100A,
  39. DPP_ATTR_R_AUTH_TAG = 0x100B,
  40. DPP_ATTR_CONFIG_OBJ = 0x100C,
  41. DPP_ATTR_CONNECTOR = 0x100D,
  42. DPP_ATTR_CONFIG_ATTR_OBJ = 0x100E,
  43. DPP_ATTR_BOOTSTRAP_KEY = 0x100F,
  44. DPP_ATTR_PEER_NET_PK_HASH = 0x1010,
  45. DPP_ATTR_OWN_NET_NK_HASH = 0x1011,
  46. DPP_ATTR_FINITE_CYCLIC_GROUP = 0x1012,
  47. DPP_ATTR_ENCRYPTED_KEY = 0x1013,
  48. DPP_ATTR_ENROLLEE_NONCE = 0x1014,
  49. DPP_ATTR_CODE_IDENTIFIER = 0x1015,
  50. };
  51. enum dpp_status_error {
  52. DPP_STATUS_OK = 0,
  53. DPP_STATUS_NOT_COMPATIBLE = 1,
  54. DPP_STATUS_AUTH_FAILURE = 2,
  55. DPP_STATUS_UNWRAP_FAILURE = 3,
  56. DPP_STATUS_BAD_GROUP = 4,
  57. DPP_STATUS_CONFIGURE_FAILURE = 5,
  58. DPP_STATUS_RESPONSE_PENDING = 6,
  59. };
  60. #define DPP_CAPAB_ENROLLEE BIT(0)
  61. #define DPP_CAPAB_CONFIGURATOR BIT(1)
  62. #define DPP_CAPAB_ROLE_MASK (BIT(0) | BIT(1))
  63. #define DPP_BOOTSTRAP_MAX_FREQ 30
  64. #define DPP_MAX_NONCE_LEN 32
  65. #define DPP_MAX_HASH_LEN 64
  66. #define DPP_MAX_SHARED_SECRET_LEN 66
  67. struct dpp_curve_params {
  68. const char *name;
  69. size_t hash_len;
  70. size_t aes_siv_key_len;
  71. size_t nonce_len;
  72. size_t prime_len;
  73. const char *jwk_crv;
  74. u16 ike_group;
  75. const char *jws_alg;
  76. };
  77. enum dpp_bootstrap_type {
  78. DPP_BOOTSTRAP_QR_CODE,
  79. DPP_BOOTSTRAP_PKEX,
  80. };
  81. struct dpp_bootstrap_info {
  82. struct dl_list list;
  83. unsigned int id;
  84. enum dpp_bootstrap_type type;
  85. char *uri;
  86. u8 mac_addr[ETH_ALEN];
  87. char *info;
  88. unsigned int freq[DPP_BOOTSTRAP_MAX_FREQ];
  89. unsigned int num_freq;
  90. int own;
  91. EVP_PKEY *pubkey;
  92. u8 pubkey_hash[SHA256_MAC_LEN];
  93. const struct dpp_curve_params *curve;
  94. };
  95. struct dpp_pkex {
  96. unsigned int initiator:1;
  97. unsigned int exchange_done:1;
  98. struct dpp_bootstrap_info *own_bi;
  99. u8 own_mac[ETH_ALEN];
  100. u8 peer_mac[ETH_ALEN];
  101. char *identifier;
  102. char *code;
  103. EVP_PKEY *x;
  104. EVP_PKEY *y;
  105. u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
  106. u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
  107. u8 z[DPP_MAX_HASH_LEN];
  108. EVP_PKEY *peer_bootstrap_key;
  109. struct wpabuf *exchange_req;
  110. struct wpabuf *exchange_resp;
  111. };
  112. struct dpp_configuration {
  113. u8 ssid[32];
  114. size_t ssid_len;
  115. int dpp; /* whether to use DPP or legacy configuration */
  116. /* For DPP configuration (connector) */
  117. os_time_t netaccesskey_expiry;
  118. /* TODO: groups, devices */
  119. /* For legacy configuration */
  120. char *passphrase;
  121. u8 psk[32];
  122. };
  123. struct dpp_authentication {
  124. void *msg_ctx;
  125. const struct dpp_curve_params *curve;
  126. struct dpp_bootstrap_info *peer_bi;
  127. struct dpp_bootstrap_info *own_bi;
  128. u8 waiting_pubkey_hash[SHA256_MAC_LEN];
  129. int response_pending;
  130. enum dpp_status_error auth_resp_status;
  131. u8 peer_mac_addr[ETH_ALEN];
  132. u8 i_nonce[DPP_MAX_NONCE_LEN];
  133. u8 r_nonce[DPP_MAX_NONCE_LEN];
  134. u8 e_nonce[DPP_MAX_NONCE_LEN];
  135. u8 i_capab;
  136. u8 r_capab;
  137. EVP_PKEY *own_protocol_key;
  138. EVP_PKEY *peer_protocol_key;
  139. struct wpabuf *req_attr;
  140. struct wpabuf *resp_attr;
  141. unsigned int curr_freq;
  142. size_t secret_len;
  143. u8 Mx[DPP_MAX_SHARED_SECRET_LEN];
  144. u8 Nx[DPP_MAX_SHARED_SECRET_LEN];
  145. u8 Lx[DPP_MAX_SHARED_SECRET_LEN];
  146. u8 k1[DPP_MAX_HASH_LEN];
  147. u8 k2[DPP_MAX_HASH_LEN];
  148. u8 ke[DPP_MAX_HASH_LEN];
  149. int initiator;
  150. int configurator;
  151. int remove_on_tx_status;
  152. int auth_success;
  153. struct wpabuf *conf_req;
  154. struct dpp_configuration *conf_ap;
  155. struct dpp_configuration *conf_sta;
  156. struct dpp_configurator *conf;
  157. char *connector; /* received signedConnector */
  158. u8 ssid[SSID_MAX_LEN];
  159. u8 ssid_len;
  160. char passphrase[64];
  161. u8 psk[PMK_LEN];
  162. int psk_set;
  163. struct wpabuf *net_access_key;
  164. os_time_t net_access_key_expiry;
  165. struct wpabuf *c_sign_key;
  166. os_time_t c_sign_key_expiry;
  167. #ifdef CONFIG_TESTING_OPTIONS
  168. char *config_obj_override;
  169. char *discovery_override;
  170. char *groups_override;
  171. char *devices_override;
  172. unsigned int ignore_netaccesskey_mismatch:1;
  173. #endif /* CONFIG_TESTING_OPTIONS */
  174. };
  175. struct dpp_configurator {
  176. struct dl_list list;
  177. unsigned int id;
  178. int own;
  179. EVP_PKEY *csign;
  180. char *kid;
  181. const struct dpp_curve_params *curve;
  182. os_time_t csign_expiry;
  183. };
  184. struct dpp_introduction {
  185. u8 pmkid[PMKID_LEN];
  186. u8 pmk[PMK_LEN_MAX];
  187. size_t pmk_len;
  188. u8 pk_hash[SHA256_MAC_LEN];
  189. u8 nk_hash[SHA256_MAC_LEN];
  190. };
  191. void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
  192. int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
  193. int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
  194. const char *chan_list);
  195. int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
  196. int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
  197. struct dpp_bootstrap_info * dpp_parse_qr_code(const char *uri);
  198. char * dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
  199. const u8 *privkey, size_t privkey_len);
  200. struct dpp_authentication * dpp_auth_init(void *msg_ctx,
  201. struct dpp_bootstrap_info *peer_bi,
  202. struct dpp_bootstrap_info *own_bi,
  203. int configurator);
  204. struct dpp_authentication *
  205. dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
  206. struct dpp_bootstrap_info *peer_bi,
  207. struct dpp_bootstrap_info *own_bi,
  208. unsigned int freq, const u8 *attr_start,
  209. const u8 *wrapped_data, u16 wrapped_data_len);
  210. struct wpabuf *
  211. dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *attr_start,
  212. size_t attr_len);
  213. struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
  214. const char *json);
  215. int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *attr_start,
  216. size_t attr_len);
  217. int dpp_notify_new_qr_code(struct dpp_authentication *auth,
  218. struct dpp_bootstrap_info *peer_bi);
  219. void dpp_configuration_free(struct dpp_configuration *conf);
  220. void dpp_auth_deinit(struct dpp_authentication *auth);
  221. struct wpabuf *
  222. dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
  223. size_t attr_len);
  224. int dpp_conf_resp_rx(struct dpp_authentication *auth,
  225. const struct wpabuf *resp);
  226. struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
  227. size_t len);
  228. const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
  229. int dpp_check_attrs(const u8 *buf, size_t len);
  230. int dpp_key_expired(const char *timestamp, os_time_t *expiry);
  231. void dpp_configurator_free(struct dpp_configurator *conf);
  232. struct dpp_configurator *
  233. dpp_keygen_configurator(const char *curve, const u8 *privkey,
  234. size_t privkey_len);
  235. int dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
  236. const u8 *net_access_key, size_t net_access_key_len,
  237. const u8 *csign_key, size_t csign_key_len,
  238. const u8 *peer_connector, size_t peer_connector_len);
  239. struct dpp_pkex * dpp_pkex_init(struct dpp_bootstrap_info *bi,
  240. const u8 *own_mac,
  241. const char *identifier,
  242. const char *code);
  243. struct dpp_pkex * dpp_pkex_rx_exchange_req(struct dpp_bootstrap_info *bi,
  244. const u8 *own_mac,
  245. const u8 *peer_mac,
  246. const char *identifier,
  247. const char *code,
  248. const u8 *buf, size_t len);
  249. struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
  250. const u8 *buf, size_t len);
  251. struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
  252. const u8 *buf, size_t len);
  253. int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex,
  254. const u8 *buf, size_t len);
  255. void dpp_pkex_free(struct dpp_pkex *pkex);
  256. #endif /* DPP_H */