120-reconfigure-wps-credentials.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. From b389a77a0f6dccf495dbce5be9476000f6ec06a2 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <[email protected]>
  3. Date: Wed, 9 Dec 2020 19:55:53 +0100
  4. Subject: [PATCH] wps: reconfigure credentials on reload
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. When new credentials are configured and hostapd is reconfigured using
  9. SIGHUP (or reload on the ctrl_iface), also update the wps credentials.
  10. Before these changes, when WPS is triggered the registar always serves
  11. the credentials that were configured when hostapd started.
  12. Signed-off-by: Raphaël Mélotte <[email protected]>
  13. ---
  14. src/ap/wps_hostapd.c | 86 +++++++++++++++++++++++++++++++++++++++--
  15. src/wps/wps.h | 6 +++
  16. src/wps/wps_registrar.c | 29 ++++++++++++++
  17. 3 files changed, 118 insertions(+), 3 deletions(-)
  18. diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c
  19. index dc8aa8f65..ff942a67b 100644
  20. --- a/src/ap/wps_hostapd.c
  21. +++ b/src/ap/wps_hostapd.c
  22. @@ -1375,6 +1375,43 @@ static void hostapd_wps_nfc_clear(struct wps_context *wps)
  23. #endif /* CONFIG_WPS_NFC */
  24. }
  25. +int hostapd_wps_update_multi_ap(struct hostapd_data *hapd,
  26. + struct wps_registrar *reg) {
  27. + struct hostapd_bss_config *conf = hapd->conf;
  28. + u8 *multi_ap_backhaul_network_key = NULL;
  29. + size_t multi_ap_backhaul_network_key_len = 0;
  30. + int ret = -1;
  31. +
  32. + if ((conf->multi_ap & FRONTHAUL_BSS) &&
  33. + conf->multi_ap_backhaul_ssid.ssid_len) {
  34. + if (conf->multi_ap_backhaul_ssid.wpa_passphrase) {
  35. + multi_ap_backhaul_network_key =
  36. + (u8 *) os_strdup(conf->multi_ap_backhaul_ssid.wpa_passphrase);
  37. + if (multi_ap_backhaul_network_key == NULL)
  38. + return -1;
  39. + multi_ap_backhaul_network_key_len =
  40. + os_strlen(conf->multi_ap_backhaul_ssid.wpa_passphrase);
  41. + } else if (conf->multi_ap_backhaul_ssid.wpa_psk) {
  42. + multi_ap_backhaul_network_key = os_malloc(2 * PMK_LEN + 1);
  43. + if (multi_ap_backhaul_network_key == NULL)
  44. + return -1;
  45. + wpa_snprintf_hex((char *) multi_ap_backhaul_network_key,
  46. + 2 * PMK_LEN + 1,
  47. + conf->multi_ap_backhaul_ssid.wpa_psk->psk,
  48. + PMK_LEN);
  49. + multi_ap_backhaul_network_key_len = 2 * PMK_LEN;
  50. + }
  51. + ret = wps_registrar_update_multi_ap(reg,
  52. + conf->multi_ap_backhaul_ssid.ssid,
  53. + conf->multi_ap_backhaul_ssid.ssid_len,
  54. + multi_ap_backhaul_network_key,
  55. + multi_ap_backhaul_network_key_len);
  56. + os_free(multi_ap_backhaul_network_key);
  57. + }
  58. + return ret;
  59. +}
  60. +
  61. +
  62. void hostapd_deinit_wps(struct hostapd_data *hapd)
  63. {
  64. @@ -1409,11 +1446,54 @@ void hostapd_update_wps(struct hostapd_data *hapd)
  65. hapd->wps->upc = hapd->conf->upc;
  66. #endif /* CONFIG_WPS_UPNP */
  67. - hostapd_wps_set_vendor_ext(hapd, hapd->wps);
  68. - hostapd_wps_set_application_ext(hapd, hapd->wps);
  69. + struct wps_context *wps = hapd->wps;
  70. + struct hostapd_bss_config *conf = hapd->conf;
  71. +
  72. + os_memcpy(wps->ssid, conf->ssid.ssid, conf->ssid.ssid_len);
  73. + wps->ssid_len = conf->ssid.ssid_len;
  74. +
  75. + /* Clear wps settings, then fill them again */
  76. + os_free(wps->network_key);
  77. + wps->network_key = NULL;
  78. + wps->network_key_len = 0;
  79. + wps->psk_set = 0;
  80. + if (conf->ssid.wpa_psk_file) {
  81. + /* Use per-device PSKs */
  82. + } else if (conf->ssid.wpa_passphrase) {
  83. + wps->network_key = (u8 *) os_strdup(conf->ssid.wpa_passphrase);
  84. + if (wps->network_key == NULL)
  85. + return;
  86. + wps->network_key_len = os_strlen(conf->ssid.wpa_passphrase);
  87. + } else if (conf->ssid.wpa_psk) {
  88. + wps->network_key = os_malloc(2 * PMK_LEN + 1);
  89. + if (wps->network_key == NULL)
  90. + return;
  91. + wpa_snprintf_hex((char *) wps->network_key, 2 * PMK_LEN + 1,
  92. + conf->ssid.wpa_psk->psk, PMK_LEN);
  93. + wps->network_key_len = 2 * PMK_LEN;
  94. +#ifdef CONFIG_WEP
  95. + } else if (conf->ssid.wep.keys_set && conf->ssid.wep.key[0]) {
  96. + wps->network_key = os_malloc(conf->ssid.wep.len[0]);
  97. + if (wps->network_key == NULL)
  98. + return;
  99. + os_memcpy(wps->network_key, conf->ssid.wep.key[0],
  100. + conf->ssid.wep.len[0]);
  101. + wps->network_key_len = conf->ssid.wep.len[0];
  102. +#endif /* CONFIG_WEP */
  103. + }
  104. +
  105. + if (conf->ssid.wpa_psk) {
  106. + os_memcpy(wps->psk, conf->ssid.wpa_psk->psk, PMK_LEN);
  107. + wps->psk_set = 1;
  108. + }
  109. +
  110. + hostapd_wps_update_multi_ap(hapd, wps->registrar);
  111. +
  112. + hostapd_wps_set_vendor_ext(hapd, wps);
  113. + hostapd_wps_set_application_ext(hapd, wps);
  114. if (hapd->conf->wps_state)
  115. - wps_registrar_update_ie(hapd->wps->registrar);
  116. + wps_registrar_update_ie(wps->registrar);
  117. else
  118. hostapd_deinit_wps(hapd);
  119. }
  120. diff --git a/src/wps/wps.h b/src/wps/wps.h
  121. index 93888b011..110e3ea52 100644
  122. --- a/src/wps/wps.h
  123. +++ b/src/wps/wps.h
  124. @@ -938,6 +938,12 @@ struct wpabuf * wps_build_nfc_handover_sel_p2p(struct wps_context *ctx,
  125. struct wpabuf *nfc_dh_pubkey,
  126. struct wpabuf *nfc_dev_pw);
  127. +int wps_registrar_update_multi_ap(struct wps_registrar *reg,
  128. + const u8 *multi_ap_backhaul_ssid,
  129. + size_t multi_ap_backhaul_ssid_len,
  130. + const u8 *multi_ap_backhaul_network_key,
  131. + size_t multi_ap_backhaul_network_key_len);
  132. +
  133. /* ndef.c */
  134. struct wpabuf * ndef_parse_wifi(const struct wpabuf *buf);
  135. struct wpabuf * ndef_build_wifi(const struct wpabuf *buf);
  136. diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c
  137. index 9e1ee36da..d6b27be28 100644
  138. --- a/src/wps/wps_registrar.c
  139. +++ b/src/wps/wps_registrar.c
  140. @@ -3669,6 +3669,35 @@ int wps_registrar_config_ap(struct wps_registrar *reg,
  141. }
  142. +int wps_registrar_update_multi_ap(struct wps_registrar *reg,
  143. + const u8 *multi_ap_backhaul_ssid,
  144. + size_t multi_ap_backhaul_ssid_len,
  145. + const u8 *multi_ap_backhaul_network_key,
  146. + size_t multi_ap_backhaul_network_key_len)
  147. +{
  148. + if (multi_ap_backhaul_ssid != NULL) {
  149. + os_memcpy(reg->multi_ap_backhaul_ssid,
  150. + multi_ap_backhaul_ssid,
  151. + multi_ap_backhaul_ssid_len);
  152. + reg->multi_ap_backhaul_ssid_len =
  153. + multi_ap_backhaul_ssid_len;
  154. + }
  155. + os_free(reg->multi_ap_backhaul_network_key);
  156. + reg->multi_ap_backhaul_network_key = NULL;
  157. + reg->multi_ap_backhaul_network_key_len = 0;
  158. +
  159. + if (multi_ap_backhaul_network_key != NULL) {
  160. + reg->multi_ap_backhaul_network_key =
  161. + os_memdup(multi_ap_backhaul_network_key,
  162. + multi_ap_backhaul_network_key_len);
  163. + if (reg->multi_ap_backhaul_network_key == NULL)
  164. + return -1;
  165. + reg->multi_ap_backhaul_network_key_len =
  166. + multi_ap_backhaul_network_key_len;
  167. + }
  168. + return 0;
  169. +}
  170. +
  171. #ifdef CONFIG_WPS_NFC
  172. int wps_registrar_add_nfc_pw_token(struct wps_registrar *reg,
  173. --
  174. 2.29.2