2 * Authentication server setup
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "crypto/tls.h"
19 #include "eap_server/eap.h"
20 #include "eap_server/eap_sim_db.h"
21 #include "eapol_auth/eapol_auth_sm.h"
22 #include "radius/radius_server.h"
24 #include "ap_config.h"
29 #if defined(EAP_SERVER_SIM) || defined(EAP_SERVER_AKA)
31 #endif /* EAP_SERVER_SIM || EAP_SERVER_AKA */
35 static int hostapd_sim_db_cb_sta(struct hostapd_data
*hapd
,
36 struct sta_info
*sta
, void *ctx
)
38 if (eapol_auth_eap_pending_cb(sta
->eapol_sm
, ctx
) == 0)
44 static void hostapd_sim_db_cb(void *ctx
, void *session_ctx
)
46 struct hostapd_data
*hapd
= ctx
;
47 if (ap_for_each_sta(hapd
, hostapd_sim_db_cb_sta
, session_ctx
) == 0) {
49 radius_server_eap_pending_cb(hapd
->radius_srv
, session_ctx
);
50 #endif /* RADIUS_SERVER */
53 #endif /* EAP_SIM_DB */
58 static int hostapd_radius_get_eap_user(void *ctx
, const u8
*identity
,
59 size_t identity_len
, int phase2
,
60 struct eap_user
*user
)
62 const struct hostapd_eap_user
*eap_user
;
65 eap_user
= hostapd_get_eap_user(ctx
, identity
, identity_len
, phase2
);
72 os_memset(user
, 0, sizeof(*user
));
73 count
= EAP_USER_MAX_METHODS
;
74 if (count
> EAP_MAX_METHODS
)
75 count
= EAP_MAX_METHODS
;
76 for (i
= 0; i
< count
; i
++) {
77 user
->methods
[i
].vendor
= eap_user
->methods
[i
].vendor
;
78 user
->methods
[i
].method
= eap_user
->methods
[i
].method
;
81 if (eap_user
->password
) {
82 user
->password
= os_malloc(eap_user
->password_len
);
83 if (user
->password
== NULL
)
85 os_memcpy(user
->password
, eap_user
->password
,
86 eap_user
->password_len
);
87 user
->password_len
= eap_user
->password_len
;
88 user
->password_hash
= eap_user
->password_hash
;
90 user
->force_version
= eap_user
->force_version
;
91 user
->ttls_auth
= eap_user
->ttls_auth
;
97 static int hostapd_setup_radius_srv(struct hostapd_data
*hapd
)
99 struct radius_server_conf srv
;
100 struct hostapd_bss_config
*conf
= hapd
->conf
;
101 os_memset(&srv
, 0, sizeof(srv
));
102 srv
.client_file
= conf
->radius_server_clients
;
103 srv
.auth_port
= conf
->radius_server_auth_port
;
105 srv
.eap_sim_db_priv
= hapd
->eap_sim_db_priv
;
106 srv
.ssl_ctx
= hapd
->ssl_ctx
;
107 srv
.pac_opaque_encr_key
= conf
->pac_opaque_encr_key
;
108 srv
.eap_fast_a_id
= conf
->eap_fast_a_id
;
109 srv
.eap_fast_a_id_len
= conf
->eap_fast_a_id_len
;
110 srv
.eap_fast_a_id_info
= conf
->eap_fast_a_id_info
;
111 srv
.eap_fast_prov
= conf
->eap_fast_prov
;
112 srv
.pac_key_lifetime
= conf
->pac_key_lifetime
;
113 srv
.pac_key_refresh_time
= conf
->pac_key_refresh_time
;
114 srv
.eap_sim_aka_result_ind
= conf
->eap_sim_aka_result_ind
;
117 srv
.ipv6
= conf
->radius_server_ipv6
;
118 srv
.get_eap_user
= hostapd_radius_get_eap_user
;
119 srv
.eap_req_id_text
= conf
->eap_req_id_text
;
120 srv
.eap_req_id_text_len
= conf
->eap_req_id_text_len
;
122 hapd
->radius_srv
= radius_server_init(&srv
);
123 if (hapd
->radius_srv
== NULL
) {
124 wpa_printf(MSG_ERROR
, "RADIUS server initialization failed.");
131 #endif /* RADIUS_SERVER */
134 int authsrv_init(struct hostapd_data
*hapd
)
137 if (hapd
->conf
->eap_server
&&
138 (hapd
->conf
->ca_cert
|| hapd
->conf
->server_cert
||
139 hapd
->conf
->dh_file
)) {
140 struct tls_connection_params params
;
142 hapd
->ssl_ctx
= tls_init(NULL
);
143 if (hapd
->ssl_ctx
== NULL
) {
144 wpa_printf(MSG_ERROR
, "Failed to initialize TLS");
145 authsrv_deinit(hapd
);
149 os_memset(¶ms
, 0, sizeof(params
));
150 params
.ca_cert
= hapd
->conf
->ca_cert
;
151 params
.client_cert
= hapd
->conf
->server_cert
;
152 params
.private_key
= hapd
->conf
->private_key
;
153 params
.private_key_passwd
= hapd
->conf
->private_key_passwd
;
154 params
.dh_file
= hapd
->conf
->dh_file
;
156 if (tls_global_set_params(hapd
->ssl_ctx
, ¶ms
)) {
157 wpa_printf(MSG_ERROR
, "Failed to set TLS parameters");
158 authsrv_deinit(hapd
);
162 if (tls_global_set_verify(hapd
->ssl_ctx
,
163 hapd
->conf
->check_crl
)) {
164 wpa_printf(MSG_ERROR
, "Failed to enable check_crl");
165 authsrv_deinit(hapd
);
169 #endif /* EAP_TLS_FUNCS */
172 if (hapd
->conf
->eap_sim_db
) {
173 hapd
->eap_sim_db_priv
=
174 eap_sim_db_init(hapd
->conf
->eap_sim_db
,
175 hostapd_sim_db_cb
, hapd
);
176 if (hapd
->eap_sim_db_priv
== NULL
) {
177 wpa_printf(MSG_ERROR
, "Failed to initialize EAP-SIM "
178 "database interface");
179 authsrv_deinit(hapd
);
183 #endif /* EAP_SIM_DB */
186 if (hapd
->conf
->radius_server_clients
&&
187 hostapd_setup_radius_srv(hapd
))
189 #endif /* RADIUS_SERVER */
195 void authsrv_deinit(struct hostapd_data
*hapd
)
198 radius_server_deinit(hapd
->radius_srv
);
199 hapd
->radius_srv
= NULL
;
200 #endif /* RADIUS_SERVER */
204 tls_deinit(hapd
->ssl_ctx
);
205 hapd
->ssl_ctx
= NULL
;
207 #endif /* EAP_TLS_FUNCS */
210 if (hapd
->eap_sim_db_priv
) {
211 eap_sim_db_deinit(hapd
->eap_sim_db_priv
);
212 hapd
->eap_sim_db_priv
= NULL
;
214 #endif /* EAP_SIM_DB */