authsrv.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Authentication server setup
  3. * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "crypto/tls.h"
  11. #include "eap_server/eap.h"
  12. #include "eap_server/eap_sim_db.h"
  13. #include "eapol_auth/eapol_auth_sm.h"
  14. #include "radius/radius_server.h"
  15. #include "hostapd.h"
  16. #include "ap_config.h"
  17. #include "sta_info.h"
  18. #include "authsrv.h"
  19. #if defined(EAP_SERVER_SIM) || defined(EAP_SERVER_AKA)
  20. #define EAP_SIM_DB
  21. #endif /* EAP_SERVER_SIM || EAP_SERVER_AKA */
  22. #ifdef EAP_SIM_DB
  23. static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
  24. struct sta_info *sta, void *ctx)
  25. {
  26. if (eapol_auth_eap_pending_cb(sta->eapol_sm, ctx) == 0)
  27. return 1;
  28. return 0;
  29. }
  30. static void hostapd_sim_db_cb(void *ctx, void *session_ctx)
  31. {
  32. struct hostapd_data *hapd = ctx;
  33. if (ap_for_each_sta(hapd, hostapd_sim_db_cb_sta, session_ctx) == 0) {
  34. #ifdef RADIUS_SERVER
  35. radius_server_eap_pending_cb(hapd->radius_srv, session_ctx);
  36. #endif /* RADIUS_SERVER */
  37. }
  38. }
  39. #endif /* EAP_SIM_DB */
  40. #ifdef RADIUS_SERVER
  41. static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
  42. size_t identity_len, int phase2,
  43. struct eap_user *user)
  44. {
  45. const struct hostapd_eap_user *eap_user;
  46. int i;
  47. int rv = -1;
  48. eap_user = hostapd_get_eap_user(ctx, identity, identity_len, phase2);
  49. if (eap_user == NULL)
  50. goto out;
  51. if (user == NULL)
  52. return 0;
  53. os_memset(user, 0, sizeof(*user));
  54. for (i = 0; i < EAP_MAX_METHODS; i++) {
  55. user->methods[i].vendor = eap_user->methods[i].vendor;
  56. user->methods[i].method = eap_user->methods[i].method;
  57. }
  58. if (eap_user->password) {
  59. user->password = os_malloc(eap_user->password_len);
  60. if (user->password == NULL)
  61. goto out;
  62. os_memcpy(user->password, eap_user->password,
  63. eap_user->password_len);
  64. user->password_len = eap_user->password_len;
  65. user->password_hash = eap_user->password_hash;
  66. }
  67. user->force_version = eap_user->force_version;
  68. user->macacl = eap_user->macacl;
  69. user->ttls_auth = eap_user->ttls_auth;
  70. user->remediation = eap_user->remediation;
  71. user->accept_attr = eap_user->accept_attr;
  72. rv = 0;
  73. out:
  74. if (rv)
  75. wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
  76. return rv;
  77. }
  78. static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
  79. {
  80. struct radius_server_conf srv;
  81. struct hostapd_bss_config *conf = hapd->conf;
  82. os_memset(&srv, 0, sizeof(srv));
  83. srv.client_file = conf->radius_server_clients;
  84. srv.auth_port = conf->radius_server_auth_port;
  85. srv.acct_port = conf->radius_server_acct_port;
  86. srv.conf_ctx = hapd;
  87. srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
  88. srv.ssl_ctx = hapd->ssl_ctx;
  89. srv.msg_ctx = hapd->msg_ctx;
  90. srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
  91. srv.eap_fast_a_id = conf->eap_fast_a_id;
  92. srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
  93. srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
  94. srv.eap_fast_prov = conf->eap_fast_prov;
  95. srv.pac_key_lifetime = conf->pac_key_lifetime;
  96. srv.pac_key_refresh_time = conf->pac_key_refresh_time;
  97. srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
  98. srv.tnc = conf->tnc;
  99. srv.wps = hapd->wps;
  100. srv.ipv6 = conf->radius_server_ipv6;
  101. srv.get_eap_user = hostapd_radius_get_eap_user;
  102. srv.eap_req_id_text = conf->eap_req_id_text;
  103. srv.eap_req_id_text_len = conf->eap_req_id_text_len;
  104. srv.pwd_group = conf->pwd_group;
  105. srv.server_id = conf->server_id ? conf->server_id : "hostapd";
  106. srv.sqlite_file = conf->eap_user_sqlite;
  107. #ifdef CONFIG_RADIUS_TEST
  108. srv.dump_msk_file = conf->dump_msk_file;
  109. #endif /* CONFIG_RADIUS_TEST */
  110. #ifdef CONFIG_HS20
  111. srv.subscr_remediation_url = conf->subscr_remediation_url;
  112. srv.subscr_remediation_method = conf->subscr_remediation_method;
  113. #endif /* CONFIG_HS20 */
  114. srv.erp = conf->eap_server_erp;
  115. srv.erp_domain = conf->erp_domain;
  116. hapd->radius_srv = radius_server_init(&srv);
  117. if (hapd->radius_srv == NULL) {
  118. wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
  119. return -1;
  120. }
  121. return 0;
  122. }
  123. #endif /* RADIUS_SERVER */
  124. int authsrv_init(struct hostapd_data *hapd)
  125. {
  126. #ifdef EAP_TLS_FUNCS
  127. if (hapd->conf->eap_server &&
  128. (hapd->conf->ca_cert || hapd->conf->server_cert ||
  129. hapd->conf->private_key || hapd->conf->dh_file)) {
  130. struct tls_connection_params params;
  131. hapd->ssl_ctx = tls_init(NULL);
  132. if (hapd->ssl_ctx == NULL) {
  133. wpa_printf(MSG_ERROR, "Failed to initialize TLS");
  134. authsrv_deinit(hapd);
  135. return -1;
  136. }
  137. os_memset(&params, 0, sizeof(params));
  138. params.ca_cert = hapd->conf->ca_cert;
  139. params.client_cert = hapd->conf->server_cert;
  140. params.private_key = hapd->conf->private_key;
  141. params.private_key_passwd = hapd->conf->private_key_passwd;
  142. params.dh_file = hapd->conf->dh_file;
  143. params.openssl_ciphers = hapd->conf->openssl_ciphers;
  144. params.ocsp_stapling_response =
  145. hapd->conf->ocsp_stapling_response;
  146. if (tls_global_set_params(hapd->ssl_ctx, &params)) {
  147. wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
  148. authsrv_deinit(hapd);
  149. return -1;
  150. }
  151. if (tls_global_set_verify(hapd->ssl_ctx,
  152. hapd->conf->check_crl)) {
  153. wpa_printf(MSG_ERROR, "Failed to enable check_crl");
  154. authsrv_deinit(hapd);
  155. return -1;
  156. }
  157. }
  158. #endif /* EAP_TLS_FUNCS */
  159. #ifdef EAP_SIM_DB
  160. if (hapd->conf->eap_sim_db) {
  161. hapd->eap_sim_db_priv =
  162. eap_sim_db_init(hapd->conf->eap_sim_db,
  163. hostapd_sim_db_cb, hapd);
  164. if (hapd->eap_sim_db_priv == NULL) {
  165. wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
  166. "database interface");
  167. authsrv_deinit(hapd);
  168. return -1;
  169. }
  170. }
  171. #endif /* EAP_SIM_DB */
  172. #ifdef RADIUS_SERVER
  173. if (hapd->conf->radius_server_clients &&
  174. hostapd_setup_radius_srv(hapd))
  175. return -1;
  176. #endif /* RADIUS_SERVER */
  177. return 0;
  178. }
  179. void authsrv_deinit(struct hostapd_data *hapd)
  180. {
  181. #ifdef RADIUS_SERVER
  182. radius_server_deinit(hapd->radius_srv);
  183. hapd->radius_srv = NULL;
  184. #endif /* RADIUS_SERVER */
  185. #ifdef EAP_TLS_FUNCS
  186. if (hapd->ssl_ctx) {
  187. tls_deinit(hapd->ssl_ctx);
  188. hapd->ssl_ctx = NULL;
  189. }
  190. #endif /* EAP_TLS_FUNCS */
  191. #ifdef EAP_SIM_DB
  192. if (hapd->eap_sim_db_priv) {
  193. eap_sim_db_deinit(hapd->eap_sim_db_priv);
  194. hapd->eap_sim_db_priv = NULL;
  195. }
  196. #endif /* EAP_SIM_DB */
  197. }