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