dpp.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. DPP_ATTR_TESTING = 0x10ff, /* not defined in the DPP tech spec */
  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 */
  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_msg;
  140. struct wpabuf *resp_msg;
  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. #ifdef CONFIG_TESTING_OPTIONS
  167. char *config_obj_override;
  168. char *discovery_override;
  169. char *groups_override;
  170. unsigned int ignore_netaccesskey_mismatch:1;
  171. #endif /* CONFIG_TESTING_OPTIONS */
  172. };
  173. struct dpp_configurator {
  174. struct dl_list list;
  175. unsigned int id;
  176. int own;
  177. EVP_PKEY *csign;
  178. char *kid;
  179. const struct dpp_curve_params *curve;
  180. };
  181. struct dpp_introduction {
  182. u8 pmkid[PMKID_LEN];
  183. u8 pmk[PMK_LEN_MAX];
  184. size_t pmk_len;
  185. };
  186. #ifdef CONFIG_TESTING_OPTIONS
  187. enum dpp_test_behavior {
  188. DPP_TEST_DISABLED = 0,
  189. DPP_TEST_AFTER_WRAPPED_DATA_AUTH_REQ = 1,
  190. DPP_TEST_AFTER_WRAPPED_DATA_AUTH_RESP = 2,
  191. DPP_TEST_AFTER_WRAPPED_DATA_AUTH_CONF = 3,
  192. DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_REQ = 4,
  193. DPP_TEST_AFTER_WRAPPED_DATA_PKEX_CR_RESP = 5,
  194. DPP_TEST_AFTER_WRAPPED_DATA_CONF_REQ = 6,
  195. DPP_TEST_AFTER_WRAPPED_DATA_CONF_RESP = 7,
  196. DPP_TEST_ZERO_I_CAPAB = 8,
  197. DPP_TEST_ZERO_R_CAPAB = 9,
  198. DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_REQ = 10,
  199. DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_REQ = 11,
  200. DPP_TEST_NO_I_PROTO_KEY_AUTH_REQ = 12,
  201. DPP_TEST_NO_I_NONCE_AUTH_REQ = 13,
  202. DPP_TEST_NO_I_CAPAB_AUTH_REQ = 14,
  203. DPP_TEST_NO_WRAPPED_DATA_AUTH_REQ = 15,
  204. DPP_TEST_NO_STATUS_AUTH_RESP = 16,
  205. DPP_TEST_NO_R_BOOTSTRAP_KEY_HASH_AUTH_RESP = 17,
  206. DPP_TEST_NO_I_BOOTSTRAP_KEY_HASH_AUTH_RESP = 18,
  207. DPP_TEST_NO_R_PROTO_KEY_AUTH_RESP = 19,
  208. DPP_TEST_NO_R_NONCE_AUTH_RESP = 20,
  209. DPP_TEST_NO_I_NONCE_AUTH_RESP = 21,
  210. DPP_TEST_NO_R_CAPAB_AUTH_RESP = 22,
  211. DPP_TEST_NO_R_AUTH_AUTH_RESP = 23,
  212. DPP_TEST_NO_WRAPPED_DATA_AUTH_RESP = 24,
  213. };
  214. extern enum dpp_test_behavior dpp_test;
  215. #endif /* CONFIG_TESTING_OPTIONS */
  216. void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
  217. const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
  218. int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
  219. int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
  220. const char *chan_list);
  221. int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
  222. int dpp_parse_uri_info(struct dpp_bootstrap_info *bi, const char *info);
  223. struct dpp_bootstrap_info * dpp_parse_qr_code(const char *uri);
  224. char * dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
  225. const u8 *privkey, size_t privkey_len);
  226. struct dpp_authentication * dpp_auth_init(void *msg_ctx,
  227. struct dpp_bootstrap_info *peer_bi,
  228. struct dpp_bootstrap_info *own_bi,
  229. int configurator);
  230. struct dpp_authentication *
  231. dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
  232. struct dpp_bootstrap_info *peer_bi,
  233. struct dpp_bootstrap_info *own_bi,
  234. unsigned int freq, const u8 *hdr, const u8 *attr_start,
  235. size_t attr_len);
  236. struct wpabuf *
  237. dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
  238. const u8 *attr_start, size_t attr_len);
  239. struct wpabuf * dpp_build_conf_req(struct dpp_authentication *auth,
  240. const char *json);
  241. int dpp_auth_conf_rx(struct dpp_authentication *auth, const u8 *hdr,
  242. const u8 *attr_start, size_t attr_len);
  243. int dpp_notify_new_qr_code(struct dpp_authentication *auth,
  244. struct dpp_bootstrap_info *peer_bi);
  245. void dpp_configuration_free(struct dpp_configuration *conf);
  246. void dpp_auth_deinit(struct dpp_authentication *auth);
  247. struct wpabuf *
  248. dpp_conf_req_rx(struct dpp_authentication *auth, const u8 *attr_start,
  249. size_t attr_len);
  250. int dpp_conf_resp_rx(struct dpp_authentication *auth,
  251. const struct wpabuf *resp);
  252. struct wpabuf * dpp_alloc_msg(enum dpp_public_action_frame_type type,
  253. size_t len);
  254. const u8 * dpp_get_attr(const u8 *buf, size_t len, u16 req_id, u16 *ret_len);
  255. int dpp_check_attrs(const u8 *buf, size_t len);
  256. int dpp_key_expired(const char *timestamp, os_time_t *expiry);
  257. void dpp_configurator_free(struct dpp_configurator *conf);
  258. struct dpp_configurator *
  259. dpp_keygen_configurator(const char *curve, const u8 *privkey,
  260. size_t privkey_len);
  261. int dpp_configurator_own_config(struct dpp_authentication *auth,
  262. const char *curve);
  263. int dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
  264. const u8 *net_access_key, size_t net_access_key_len,
  265. const u8 *csign_key, size_t csign_key_len,
  266. const u8 *peer_connector, size_t peer_connector_len,
  267. os_time_t *expiry);
  268. struct dpp_pkex * dpp_pkex_init(struct dpp_bootstrap_info *bi,
  269. const u8 *own_mac,
  270. const char *identifier,
  271. const char *code);
  272. struct dpp_pkex * dpp_pkex_rx_exchange_req(struct dpp_bootstrap_info *bi,
  273. const u8 *own_mac,
  274. const u8 *peer_mac,
  275. const char *identifier,
  276. const char *code,
  277. const u8 *buf, size_t len);
  278. struct wpabuf * dpp_pkex_rx_exchange_resp(struct dpp_pkex *pkex,
  279. const u8 *buf, size_t len);
  280. struct wpabuf * dpp_pkex_rx_commit_reveal_req(struct dpp_pkex *pkex,
  281. const u8 *hdr,
  282. const u8 *buf, size_t len);
  283. int dpp_pkex_rx_commit_reveal_resp(struct dpp_pkex *pkex, const u8 *hdr,
  284. const u8 *buf, size_t len);
  285. void dpp_pkex_free(struct dpp_pkex *pkex);
  286. #endif /* DPP_H */