authsrv.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_memdup(eap_user->password,
  60. eap_user->password_len);
  61. if (user->password == NULL)
  62. goto out;
  63. user->password_len = eap_user->password_len;
  64. user->password_hash = eap_user->password_hash;
  65. }
  66. user->force_version = eap_user->force_version;
  67. user->macacl = eap_user->macacl;
  68. user->ttls_auth = eap_user->ttls_auth;
  69. user->remediation = eap_user->remediation;
  70. user->accept_attr = eap_user->accept_attr;
  71. rv = 0;
  72. out:
  73. if (rv)
  74. wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
  75. return rv;
  76. }
  77. static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
  78. {
  79. struct radius_server_conf srv;
  80. struct hostapd_bss_config *conf = hapd->conf;
  81. os_memset(&srv, 0, sizeof(srv));
  82. srv.client_file = conf->radius_server_clients;
  83. srv.auth_port = conf->radius_server_auth_port;
  84. srv.acct_port = conf->radius_server_acct_port;
  85. srv.conf_ctx = hapd;
  86. srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
  87. srv.ssl_ctx = hapd->ssl_ctx;
  88. srv.msg_ctx = hapd->msg_ctx;
  89. srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
  90. srv.eap_fast_a_id = conf->eap_fast_a_id;
  91. srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
  92. srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
  93. srv.eap_fast_prov = conf->eap_fast_prov;
  94. srv.pac_key_lifetime = conf->pac_key_lifetime;
  95. srv.pac_key_refresh_time = conf->pac_key_refresh_time;
  96. srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
  97. srv.tnc = conf->tnc;
  98. srv.wps = hapd->wps;
  99. srv.ipv6 = conf->radius_server_ipv6;
  100. srv.get_eap_user = hostapd_radius_get_eap_user;
  101. srv.eap_req_id_text = conf->eap_req_id_text;
  102. srv.eap_req_id_text_len = conf->eap_req_id_text_len;
  103. srv.pwd_group = conf->pwd_group;
  104. srv.server_id = conf->server_id ? conf->server_id : "hostapd";
  105. srv.sqlite_file = conf->eap_user_sqlite;
  106. #ifdef CONFIG_RADIUS_TEST
  107. srv.dump_msk_file = conf->dump_msk_file;
  108. #endif /* CONFIG_RADIUS_TEST */
  109. #ifdef CONFIG_HS20
  110. srv.subscr_remediation_url = conf->subscr_remediation_url;
  111. srv.subscr_remediation_method = conf->subscr_remediation_method;
  112. #endif /* CONFIG_HS20 */
  113. srv.erp = conf->eap_server_erp;
  114. srv.erp_domain = conf->erp_domain;
  115. srv.tls_session_lifetime = conf->tls_session_lifetime;
  116. srv.tls_flags = conf->tls_flags;
  117. hapd->radius_srv = radius_server_init(&srv);
  118. if (hapd->radius_srv == NULL) {
  119. wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
  120. return -1;
  121. }
  122. return 0;
  123. }
  124. #endif /* RADIUS_SERVER */
  125. int authsrv_init(struct hostapd_data *hapd)
  126. {
  127. #ifdef EAP_TLS_FUNCS
  128. if (hapd->conf->eap_server &&
  129. (hapd->conf->ca_cert || hapd->conf->server_cert ||
  130. hapd->conf->private_key || hapd->conf->dh_file)) {
  131. struct tls_config conf;
  132. struct tls_connection_params params;
  133. os_memset(&conf, 0, sizeof(conf));
  134. conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
  135. conf.tls_flags = hapd->conf->tls_flags;
  136. hapd->ssl_ctx = tls_init(&conf);
  137. if (hapd->ssl_ctx == NULL) {
  138. wpa_printf(MSG_ERROR, "Failed to initialize TLS");
  139. authsrv_deinit(hapd);
  140. return -1;
  141. }
  142. os_memset(&params, 0, sizeof(params));
  143. params.ca_cert = hapd->conf->ca_cert;
  144. params.client_cert = hapd->conf->server_cert;
  145. params.private_key = hapd->conf->private_key;
  146. params.private_key_passwd = hapd->conf->private_key_passwd;
  147. params.dh_file = hapd->conf->dh_file;
  148. params.openssl_ciphers = hapd->conf->openssl_ciphers;
  149. params.ocsp_stapling_response =
  150. hapd->conf->ocsp_stapling_response;
  151. params.ocsp_stapling_response_multi =
  152. hapd->conf->ocsp_stapling_response_multi;
  153. if (tls_global_set_params(hapd->ssl_ctx, &params)) {
  154. wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
  155. authsrv_deinit(hapd);
  156. return -1;
  157. }
  158. if (tls_global_set_verify(hapd->ssl_ctx,
  159. hapd->conf->check_crl)) {
  160. wpa_printf(MSG_ERROR, "Failed to enable check_crl");
  161. authsrv_deinit(hapd);
  162. return -1;
  163. }
  164. }
  165. #endif /* EAP_TLS_FUNCS */
  166. #ifdef EAP_SIM_DB
  167. if (hapd->conf->eap_sim_db) {
  168. hapd->eap_sim_db_priv =
  169. eap_sim_db_init(hapd->conf->eap_sim_db,
  170. hapd->conf->eap_sim_db_timeout,
  171. hostapd_sim_db_cb, hapd);
  172. if (hapd->eap_sim_db_priv == NULL) {
  173. wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
  174. "database interface");
  175. authsrv_deinit(hapd);
  176. return -1;
  177. }
  178. }
  179. #endif /* EAP_SIM_DB */
  180. #ifdef RADIUS_SERVER
  181. if (hapd->conf->radius_server_clients &&
  182. hostapd_setup_radius_srv(hapd))
  183. return -1;
  184. #endif /* RADIUS_SERVER */
  185. return 0;
  186. }
  187. void authsrv_deinit(struct hostapd_data *hapd)
  188. {
  189. #ifdef RADIUS_SERVER
  190. radius_server_deinit(hapd->radius_srv);
  191. hapd->radius_srv = NULL;
  192. #endif /* RADIUS_SERVER */
  193. #ifdef EAP_TLS_FUNCS
  194. if (hapd->ssl_ctx) {
  195. tls_deinit(hapd->ssl_ctx);
  196. hapd->ssl_ctx = NULL;
  197. }
  198. #endif /* EAP_TLS_FUNCS */
  199. #ifdef EAP_SIM_DB
  200. if (hapd->eap_sim_db_priv) {
  201. eap_sim_db_deinit(hapd->eap_sim_db_priv);
  202. hapd->eap_sim_db_priv = NULL;
  203. }
  204. #endif /* EAP_SIM_DB */
  205. }