dpp.h 8.1 KB

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