blob: 6e3decd85822d938103aeab88a41f345f287869d [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 Shmidt8d520ff2011-05-09 14:06:53 -070058
59 eap_user = hostapd_get_eap_user(ctx, identity, identity_len, phase2);
60 if (eap_user == NULL)
61 return -1;
62
63 if (user == NULL)
64 return 0;
65
66 os_memset(user, 0, sizeof(*user));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080067 for (i = 0; i < EAP_MAX_METHODS; i++) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068 user->methods[i].vendor = eap_user->methods[i].vendor;
69 user->methods[i].method = eap_user->methods[i].method;
70 }
71
72 if (eap_user->password) {
73 user->password = os_malloc(eap_user->password_len);
74 if (user->password == NULL)
75 return -1;
76 os_memcpy(user->password, eap_user->password,
77 eap_user->password_len);
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->ttls_auth = eap_user->ttls_auth;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080083 user->remediation = eap_user->remediation;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070084 user->accept_attr = eap_user->accept_attr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085
86 return 0;
87}
88
89
90static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
91{
92 struct radius_server_conf srv;
93 struct hostapd_bss_config *conf = hapd->conf;
94 os_memset(&srv, 0, sizeof(srv));
95 srv.client_file = conf->radius_server_clients;
96 srv.auth_port = conf->radius_server_auth_port;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -080097 srv.acct_port = conf->radius_server_acct_port;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080098 srv.conf_ctx = hapd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070099 srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
100 srv.ssl_ctx = hapd->ssl_ctx;
101 srv.msg_ctx = hapd->msg_ctx;
102 srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
103 srv.eap_fast_a_id = conf->eap_fast_a_id;
104 srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
105 srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
106 srv.eap_fast_prov = conf->eap_fast_prov;
107 srv.pac_key_lifetime = conf->pac_key_lifetime;
108 srv.pac_key_refresh_time = conf->pac_key_refresh_time;
109 srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
110 srv.tnc = conf->tnc;
111 srv.wps = hapd->wps;
112 srv.ipv6 = conf->radius_server_ipv6;
113 srv.get_eap_user = hostapd_radius_get_eap_user;
114 srv.eap_req_id_text = conf->eap_req_id_text;
115 srv.eap_req_id_text_len = conf->eap_req_id_text_len;
116 srv.pwd_group = conf->pwd_group;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700117 srv.server_id = conf->server_id ? conf->server_id : "hostapd";
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700118 srv.sqlite_file = conf->eap_user_sqlite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800119#ifdef CONFIG_RADIUS_TEST
120 srv.dump_msk_file = conf->dump_msk_file;
121#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800122#ifdef CONFIG_HS20
123 srv.subscr_remediation_url = conf->subscr_remediation_url;
124 srv.subscr_remediation_method = conf->subscr_remediation_method;
125#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700126
127 hapd->radius_srv = radius_server_init(&srv);
128 if (hapd->radius_srv == NULL) {
129 wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
130 return -1;
131 }
132
133 return 0;
134}
135
136#endif /* RADIUS_SERVER */
137
138
139int authsrv_init(struct hostapd_data *hapd)
140{
141#ifdef EAP_TLS_FUNCS
142 if (hapd->conf->eap_server &&
143 (hapd->conf->ca_cert || hapd->conf->server_cert ||
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800144 hapd->conf->private_key || hapd->conf->dh_file)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 struct tls_connection_params params;
146
147 hapd->ssl_ctx = tls_init(NULL);
148 if (hapd->ssl_ctx == NULL) {
149 wpa_printf(MSG_ERROR, "Failed to initialize TLS");
150 authsrv_deinit(hapd);
151 return -1;
152 }
153
154 os_memset(&params, 0, sizeof(params));
155 params.ca_cert = hapd->conf->ca_cert;
156 params.client_cert = hapd->conf->server_cert;
157 params.private_key = hapd->conf->private_key;
158 params.private_key_passwd = hapd->conf->private_key_passwd;
159 params.dh_file = hapd->conf->dh_file;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700160 params.ocsp_stapling_response =
161 hapd->conf->ocsp_stapling_response;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162
163 if (tls_global_set_params(hapd->ssl_ctx, &params)) {
164 wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
165 authsrv_deinit(hapd);
166 return -1;
167 }
168
169 if (tls_global_set_verify(hapd->ssl_ctx,
170 hapd->conf->check_crl)) {
171 wpa_printf(MSG_ERROR, "Failed to enable check_crl");
172 authsrv_deinit(hapd);
173 return -1;
174 }
175 }
176#endif /* EAP_TLS_FUNCS */
177
178#ifdef EAP_SIM_DB
179 if (hapd->conf->eap_sim_db) {
180 hapd->eap_sim_db_priv =
181 eap_sim_db_init(hapd->conf->eap_sim_db,
182 hostapd_sim_db_cb, hapd);
183 if (hapd->eap_sim_db_priv == NULL) {
184 wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
185 "database interface");
186 authsrv_deinit(hapd);
187 return -1;
188 }
189 }
190#endif /* EAP_SIM_DB */
191
192#ifdef RADIUS_SERVER
193 if (hapd->conf->radius_server_clients &&
194 hostapd_setup_radius_srv(hapd))
195 return -1;
196#endif /* RADIUS_SERVER */
197
198 return 0;
199}
200
201
202void authsrv_deinit(struct hostapd_data *hapd)
203{
204#ifdef RADIUS_SERVER
205 radius_server_deinit(hapd->radius_srv);
206 hapd->radius_srv = NULL;
207#endif /* RADIUS_SERVER */
208
209#ifdef EAP_TLS_FUNCS
210 if (hapd->ssl_ctx) {
211 tls_deinit(hapd->ssl_ctx);
212 hapd->ssl_ctx = NULL;
213 }
214#endif /* EAP_TLS_FUNCS */
215
216#ifdef EAP_SIM_DB
217 if (hapd->eap_sim_db_priv) {
218 eap_sim_db_deinit(hapd->eap_sim_db_priv);
219 hapd->eap_sim_db_priv = NULL;
220 }
221#endif /* EAP_SIM_DB */
222}