blob: b3d910742e50f5567fd28038df72f6dc70f7dd2b [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Authentication server setup
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "crypto/tls.h"
13#include "eap_server/eap.h"
14#include "eap_server/eap_sim_db.h"
15#include "eapol_auth/eapol_auth_sm.h"
16#include "radius/radius_server.h"
17#include "hostapd.h"
18#include "ap_config.h"
19#include "sta_info.h"
20#include "authsrv.h"
21
22
23#if defined(EAP_SERVER_SIM) || defined(EAP_SERVER_AKA)
24#define EAP_SIM_DB
25#endif /* EAP_SERVER_SIM || EAP_SERVER_AKA */
26
27
28#ifdef EAP_SIM_DB
29static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
30 struct sta_info *sta, void *ctx)
31{
32 if (eapol_auth_eap_pending_cb(sta->eapol_sm, ctx) == 0)
33 return 1;
34 return 0;
35}
36
37
38static void hostapd_sim_db_cb(void *ctx, void *session_ctx)
39{
40 struct hostapd_data *hapd = ctx;
41 if (ap_for_each_sta(hapd, hostapd_sim_db_cb_sta, session_ctx) == 0) {
42#ifdef RADIUS_SERVER
43 radius_server_eap_pending_cb(hapd->radius_srv, session_ctx);
44#endif /* RADIUS_SERVER */
45 }
46}
47#endif /* EAP_SIM_DB */
48
49
50#ifdef RADIUS_SERVER
51
52static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
53 size_t identity_len, int phase2,
54 struct eap_user *user)
55{
56 const struct hostapd_eap_user *eap_user;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080057 int i;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070058 int rv = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070059
60 eap_user = hostapd_get_eap_user(ctx, identity, identity_len, phase2);
61 if (eap_user == NULL)
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070062 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063
64 if (user == NULL)
65 return 0;
66
67 os_memset(user, 0, sizeof(*user));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080068 for (i = 0; i < EAP_MAX_METHODS; i++) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069 user->methods[i].vendor = eap_user->methods[i].vendor;
70 user->methods[i].method = eap_user->methods[i].method;
71 }
72
73 if (eap_user->password) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070074 user->password = os_memdup(eap_user->password,
75 eap_user->password_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070076 if (user->password == NULL)
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070077 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070078 user->password_len = eap_user->password_len;
79 user->password_hash = eap_user->password_hash;
Roshan Pius3a1667e2018-07-03 15:17:14 -070080 if (eap_user->salt && eap_user->salt_len) {
81 user->salt = os_memdup(eap_user->salt,
82 eap_user->salt_len);
83 if (!user->salt)
84 goto out;
85 user->salt_len = eap_user->salt_len;
86 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087 }
88 user->force_version = eap_user->force_version;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -070089 user->macacl = eap_user->macacl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090 user->ttls_auth = eap_user->ttls_auth;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080091 user->remediation = eap_user->remediation;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070092 user->accept_attr = eap_user->accept_attr;
Roshan Pius3a1667e2018-07-03 15:17:14 -070093 user->t_c_timestamp = eap_user->t_c_timestamp;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070094 rv = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070096out:
97 if (rv)
98 wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
99
100 return rv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700101}
102
103
104static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
105{
106 struct radius_server_conf srv;
107 struct hostapd_bss_config *conf = hapd->conf;
108 os_memset(&srv, 0, sizeof(srv));
109 srv.client_file = conf->radius_server_clients;
110 srv.auth_port = conf->radius_server_auth_port;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -0800111 srv.acct_port = conf->radius_server_acct_port;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800112 srv.conf_ctx = hapd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113 srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
114 srv.ssl_ctx = hapd->ssl_ctx;
115 srv.msg_ctx = hapd->msg_ctx;
116 srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
117 srv.eap_fast_a_id = conf->eap_fast_a_id;
118 srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
119 srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
120 srv.eap_fast_prov = conf->eap_fast_prov;
121 srv.pac_key_lifetime = conf->pac_key_lifetime;
122 srv.pac_key_refresh_time = conf->pac_key_refresh_time;
Hai Shalom81f62d82019-07-22 12:10:00 -0700123 srv.eap_teap_auth = conf->eap_teap_auth;
124 srv.eap_teap_pac_no_inner = conf->eap_teap_pac_no_inner;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700125 srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
126 srv.tnc = conf->tnc;
127 srv.wps = hapd->wps;
128 srv.ipv6 = conf->radius_server_ipv6;
129 srv.get_eap_user = hostapd_radius_get_eap_user;
130 srv.eap_req_id_text = conf->eap_req_id_text;
131 srv.eap_req_id_text_len = conf->eap_req_id_text_len;
132 srv.pwd_group = conf->pwd_group;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700133 srv.server_id = conf->server_id ? conf->server_id : "hostapd";
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700134 srv.sqlite_file = conf->eap_user_sqlite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800135#ifdef CONFIG_RADIUS_TEST
136 srv.dump_msk_file = conf->dump_msk_file;
137#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800138#ifdef CONFIG_HS20
139 srv.subscr_remediation_url = conf->subscr_remediation_url;
140 srv.subscr_remediation_method = conf->subscr_remediation_method;
Hai Shalom74f70d42019-02-11 14:42:39 -0800141 srv.hs20_sim_provisioning_url = conf->hs20_sim_provisioning_url;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700142 srv.t_c_server_url = conf->t_c_server_url;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800143#endif /* CONFIG_HS20 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800144 srv.erp = conf->eap_server_erp;
145 srv.erp_domain = conf->erp_domain;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800146 srv.tls_session_lifetime = conf->tls_session_lifetime;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700147 srv.tls_flags = conf->tls_flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148
149 hapd->radius_srv = radius_server_init(&srv);
150 if (hapd->radius_srv == NULL) {
151 wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
152 return -1;
153 }
154
155 return 0;
156}
157
158#endif /* RADIUS_SERVER */
159
160
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800161#ifdef EAP_TLS_FUNCS
162static void authsrv_tls_event(void *ctx, enum tls_event ev,
163 union tls_event_data *data)
164{
165 switch (ev) {
166 case TLS_CERT_CHAIN_SUCCESS:
167 wpa_printf(MSG_DEBUG, "authsrv: remote certificate verification success");
168 break;
169 case TLS_CERT_CHAIN_FAILURE:
170 wpa_printf(MSG_INFO, "authsrv: certificate chain failure: reason=%d depth=%d subject='%s' err='%s'",
171 data->cert_fail.reason,
172 data->cert_fail.depth,
173 data->cert_fail.subject,
174 data->cert_fail.reason_txt);
175 break;
176 case TLS_PEER_CERTIFICATE:
177 wpa_printf(MSG_DEBUG, "authsrv: peer certificate: depth=%d serial_num=%s subject=%s",
178 data->peer_cert.depth,
179 data->peer_cert.serial_num ? data->peer_cert.serial_num : "N/A",
180 data->peer_cert.subject);
181 break;
182 case TLS_ALERT:
183 if (data->alert.is_local)
184 wpa_printf(MSG_DEBUG, "authsrv: local TLS alert: %s",
185 data->alert.description);
186 else
187 wpa_printf(MSG_DEBUG, "authsrv: remote TLS alert: %s",
188 data->alert.description);
189 break;
190 }
191}
192#endif /* EAP_TLS_FUNCS */
193
194
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195int authsrv_init(struct hostapd_data *hapd)
196{
197#ifdef EAP_TLS_FUNCS
198 if (hapd->conf->eap_server &&
199 (hapd->conf->ca_cert || hapd->conf->server_cert ||
Hai Shalom81f62d82019-07-22 12:10:00 -0700200 hapd->conf->private_key || hapd->conf->dh_file ||
201 hapd->conf->server_cert2 || hapd->conf->private_key2)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800202 struct tls_config conf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 struct tls_connection_params params;
204
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800205 os_memset(&conf, 0, sizeof(conf));
206 conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
Hai Shalom74f70d42019-02-11 14:42:39 -0800207 if (hapd->conf->crl_reload_interval > 0 &&
208 hapd->conf->check_crl <= 0) {
209 wpa_printf(MSG_INFO,
210 "Cannot enable CRL reload functionality - it depends on check_crl being set");
211 } else if (hapd->conf->crl_reload_interval > 0) {
212 conf.crl_reload_interval =
213 hapd->conf->crl_reload_interval;
214 wpa_printf(MSG_INFO,
215 "Enabled CRL reload functionality");
216 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700217 conf.tls_flags = hapd->conf->tls_flags;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800218 conf.event_cb = authsrv_tls_event;
219 conf.cb_ctx = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800220 hapd->ssl_ctx = tls_init(&conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 if (hapd->ssl_ctx == NULL) {
222 wpa_printf(MSG_ERROR, "Failed to initialize TLS");
223 authsrv_deinit(hapd);
224 return -1;
225 }
226
227 os_memset(&params, 0, sizeof(params));
228 params.ca_cert = hapd->conf->ca_cert;
229 params.client_cert = hapd->conf->server_cert;
Hai Shalom81f62d82019-07-22 12:10:00 -0700230 params.client_cert2 = hapd->conf->server_cert2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231 params.private_key = hapd->conf->private_key;
Hai Shalom81f62d82019-07-22 12:10:00 -0700232 params.private_key2 = hapd->conf->private_key2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700233 params.private_key_passwd = hapd->conf->private_key_passwd;
Hai Shalom81f62d82019-07-22 12:10:00 -0700234 params.private_key_passwd2 = hapd->conf->private_key_passwd2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700235 params.dh_file = hapd->conf->dh_file;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800236 params.openssl_ciphers = hapd->conf->openssl_ciphers;
Hai Shalom74f70d42019-02-11 14:42:39 -0800237 params.openssl_ecdh_curves = hapd->conf->openssl_ecdh_curves;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700238 params.ocsp_stapling_response =
239 hapd->conf->ocsp_stapling_response;
Dmitry Shmidtd97138d2015-12-28 13:27:49 -0800240 params.ocsp_stapling_response_multi =
241 hapd->conf->ocsp_stapling_response_multi;
Hai Shalom021b0b52019-04-10 11:17:58 -0700242 params.check_cert_subject = hapd->conf->check_cert_subject;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243
244 if (tls_global_set_params(hapd->ssl_ctx, &params)) {
245 wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
246 authsrv_deinit(hapd);
247 return -1;
248 }
249
250 if (tls_global_set_verify(hapd->ssl_ctx,
Hai Shalom74f70d42019-02-11 14:42:39 -0800251 hapd->conf->check_crl,
252 hapd->conf->check_crl_strict)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 wpa_printf(MSG_ERROR, "Failed to enable check_crl");
254 authsrv_deinit(hapd);
255 return -1;
256 }
257 }
258#endif /* EAP_TLS_FUNCS */
259
260#ifdef EAP_SIM_DB
261 if (hapd->conf->eap_sim_db) {
262 hapd->eap_sim_db_priv =
263 eap_sim_db_init(hapd->conf->eap_sim_db,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800264 hapd->conf->eap_sim_db_timeout,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 hostapd_sim_db_cb, hapd);
266 if (hapd->eap_sim_db_priv == NULL) {
267 wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
268 "database interface");
269 authsrv_deinit(hapd);
270 return -1;
271 }
272 }
273#endif /* EAP_SIM_DB */
274
275#ifdef RADIUS_SERVER
276 if (hapd->conf->radius_server_clients &&
277 hostapd_setup_radius_srv(hapd))
278 return -1;
279#endif /* RADIUS_SERVER */
280
281 return 0;
282}
283
284
285void authsrv_deinit(struct hostapd_data *hapd)
286{
287#ifdef RADIUS_SERVER
288 radius_server_deinit(hapd->radius_srv);
289 hapd->radius_srv = NULL;
290#endif /* RADIUS_SERVER */
291
292#ifdef EAP_TLS_FUNCS
293 if (hapd->ssl_ctx) {
294 tls_deinit(hapd->ssl_ctx);
295 hapd->ssl_ctx = NULL;
296 }
297#endif /* EAP_TLS_FUNCS */
298
299#ifdef EAP_SIM_DB
300 if (hapd->eap_sim_db_priv) {
301 eap_sim_db_deinit(hapd->eap_sim_db_priv);
302 hapd->eap_sim_db_priv = NULL;
303 }
304#endif /* EAP_SIM_DB */
305}