LCOV - code coverage report
Current view: top level - src/ap - authsrv.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 89 110 80.9 %
Date: 2014-03-02 Functions: 5 6 83.3 %
Branches: 32 46 69.6 %

           Branch data     Line data    Source code
       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
      29                 :          0 : static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
      30                 :            :                                  struct sta_info *sta, void *ctx)
      31                 :            : {
      32         [ #  # ]:          0 :         if (eapol_auth_eap_pending_cb(sta->eapol_sm, ctx) == 0)
      33                 :          0 :                 return 1;
      34                 :          0 :         return 0;
      35                 :            : }
      36                 :            : 
      37                 :            : 
      38                 :         16 : static void hostapd_sim_db_cb(void *ctx, void *session_ctx)
      39                 :            : {
      40                 :         16 :         struct hostapd_data *hapd = ctx;
      41         [ +  - ]:         16 :         if (ap_for_each_sta(hapd, hostapd_sim_db_cb_sta, session_ctx) == 0) {
      42                 :            : #ifdef RADIUS_SERVER
      43                 :         16 :                 radius_server_eap_pending_cb(hapd->radius_srv, session_ctx);
      44                 :            : #endif /* RADIUS_SERVER */
      45                 :            :         }
      46                 :         16 : }
      47                 :            : #endif /* EAP_SIM_DB */
      48                 :            : 
      49                 :            : 
      50                 :            : #ifdef RADIUS_SERVER
      51                 :            : 
      52                 :        527 : 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                 :            : 
      59                 :        527 :         eap_user = hostapd_get_eap_user(ctx, identity, identity_len, phase2);
      60         [ -  + ]:        527 :         if (eap_user == NULL)
      61                 :          0 :                 return -1;
      62                 :            : 
      63         [ +  + ]:        527 :         if (user == NULL)
      64                 :        193 :                 return 0;
      65                 :            : 
      66                 :        334 :         os_memset(user, 0, sizeof(*user));
      67         [ +  + ]:       3006 :         for (i = 0; i < EAP_MAX_METHODS; i++) {
      68                 :       2672 :                 user->methods[i].vendor = eap_user->methods[i].vendor;
      69                 :       2672 :                 user->methods[i].method = eap_user->methods[i].method;
      70                 :            :         }
      71                 :            : 
      72         [ +  + ]:        334 :         if (eap_user->password) {
      73                 :        193 :                 user->password = os_malloc(eap_user->password_len);
      74         [ -  + ]:        193 :                 if (user->password == NULL)
      75                 :          0 :                         return -1;
      76                 :        193 :                 os_memcpy(user->password, eap_user->password,
      77                 :            :                           eap_user->password_len);
      78                 :        193 :                 user->password_len = eap_user->password_len;
      79                 :        193 :                 user->password_hash = eap_user->password_hash;
      80                 :            :         }
      81                 :        334 :         user->force_version = eap_user->force_version;
      82                 :        334 :         user->ttls_auth = eap_user->ttls_auth;
      83                 :        334 :         user->remediation = eap_user->remediation;
      84                 :            : 
      85                 :        527 :         return 0;
      86                 :            : }
      87                 :            : 
      88                 :            : 
      89                 :          2 : static int hostapd_setup_radius_srv(struct hostapd_data *hapd)
      90                 :            : {
      91                 :            :         struct radius_server_conf srv;
      92                 :          2 :         struct hostapd_bss_config *conf = hapd->conf;
      93                 :          2 :         os_memset(&srv, 0, sizeof(srv));
      94                 :          2 :         srv.client_file = conf->radius_server_clients;
      95                 :          2 :         srv.auth_port = conf->radius_server_auth_port;
      96                 :          2 :         srv.acct_port = conf->radius_server_acct_port;
      97                 :          2 :         srv.conf_ctx = hapd;
      98                 :          2 :         srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
      99                 :          2 :         srv.ssl_ctx = hapd->ssl_ctx;
     100                 :          2 :         srv.msg_ctx = hapd->msg_ctx;
     101                 :          2 :         srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
     102                 :          2 :         srv.eap_fast_a_id = conf->eap_fast_a_id;
     103                 :          2 :         srv.eap_fast_a_id_len = conf->eap_fast_a_id_len;
     104                 :          2 :         srv.eap_fast_a_id_info = conf->eap_fast_a_id_info;
     105                 :          2 :         srv.eap_fast_prov = conf->eap_fast_prov;
     106                 :          2 :         srv.pac_key_lifetime = conf->pac_key_lifetime;
     107                 :          2 :         srv.pac_key_refresh_time = conf->pac_key_refresh_time;
     108                 :          2 :         srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
     109                 :          2 :         srv.tnc = conf->tnc;
     110                 :          2 :         srv.wps = hapd->wps;
     111                 :          2 :         srv.ipv6 = conf->radius_server_ipv6;
     112                 :          2 :         srv.get_eap_user = hostapd_radius_get_eap_user;
     113                 :          2 :         srv.eap_req_id_text = conf->eap_req_id_text;
     114                 :          2 :         srv.eap_req_id_text_len = conf->eap_req_id_text_len;
     115                 :          2 :         srv.pwd_group = conf->pwd_group;
     116         [ +  + ]:          2 :         srv.server_id = conf->server_id ? conf->server_id : "hostapd";
     117                 :            : #ifdef CONFIG_RADIUS_TEST
     118                 :            :         srv.dump_msk_file = conf->dump_msk_file;
     119                 :            : #endif /* CONFIG_RADIUS_TEST */
     120                 :            : #ifdef CONFIG_HS20
     121                 :          2 :         srv.subscr_remediation_url = conf->subscr_remediation_url;
     122                 :          2 :         srv.subscr_remediation_method = conf->subscr_remediation_method;
     123                 :            : #endif /* CONFIG_HS20 */
     124                 :            : 
     125                 :          2 :         hapd->radius_srv = radius_server_init(&srv);
     126         [ -  + ]:          2 :         if (hapd->radius_srv == NULL) {
     127                 :          0 :                 wpa_printf(MSG_ERROR, "RADIUS server initialization failed.");
     128                 :          0 :                 return -1;
     129                 :            :         }
     130                 :            : 
     131                 :          2 :         return 0;
     132                 :            : }
     133                 :            : 
     134                 :            : #endif /* RADIUS_SERVER */
     135                 :            : 
     136                 :            : 
     137                 :        429 : int authsrv_init(struct hostapd_data *hapd)
     138                 :            : {
     139                 :            : #ifdef EAP_TLS_FUNCS
     140 [ +  + ][ +  + ]:        343 :         if (hapd->conf->eap_server &&
     141 [ +  - ][ +  - ]:         56 :             (hapd->conf->ca_cert || hapd->conf->server_cert ||
     142         [ -  + ]:         56 :              hapd->conf->private_key || hapd->conf->dh_file)) {
     143                 :            :                 struct tls_connection_params params;
     144                 :            : 
     145                 :          9 :                 hapd->ssl_ctx = tls_init(NULL);
     146         [ -  + ]:          9 :                 if (hapd->ssl_ctx == NULL) {
     147                 :          0 :                         wpa_printf(MSG_ERROR, "Failed to initialize TLS");
     148                 :          0 :                         authsrv_deinit(hapd);
     149                 :          0 :                         return -1;
     150                 :            :                 }
     151                 :            : 
     152                 :          9 :                 os_memset(&params, 0, sizeof(params));
     153                 :          9 :                 params.ca_cert = hapd->conf->ca_cert;
     154                 :          9 :                 params.client_cert = hapd->conf->server_cert;
     155                 :          9 :                 params.private_key = hapd->conf->private_key;
     156                 :          9 :                 params.private_key_passwd = hapd->conf->private_key_passwd;
     157                 :          9 :                 params.dh_file = hapd->conf->dh_file;
     158                 :          9 :                 params.ocsp_stapling_response =
     159                 :          9 :                         hapd->conf->ocsp_stapling_response;
     160                 :            : 
     161         [ -  + ]:          9 :                 if (tls_global_set_params(hapd->ssl_ctx, &params)) {
     162                 :          0 :                         wpa_printf(MSG_ERROR, "Failed to set TLS parameters");
     163                 :          0 :                         authsrv_deinit(hapd);
     164                 :          0 :                         return -1;
     165                 :            :                 }
     166                 :            : 
     167         [ -  + ]:          9 :                 if (tls_global_set_verify(hapd->ssl_ctx,
     168                 :          9 :                                           hapd->conf->check_crl)) {
     169                 :          0 :                         wpa_printf(MSG_ERROR, "Failed to enable check_crl");
     170                 :          0 :                         authsrv_deinit(hapd);
     171                 :          0 :                         return -1;
     172                 :            :                 }
     173                 :            :         }
     174                 :            : #endif /* EAP_TLS_FUNCS */
     175                 :            : 
     176                 :            : #ifdef EAP_SIM_DB
     177         [ +  + ]:        343 :         if (hapd->conf->eap_sim_db) {
     178                 :          1 :                 hapd->eap_sim_db_priv =
     179                 :          1 :                         eap_sim_db_init(hapd->conf->eap_sim_db,
     180                 :            :                                         hostapd_sim_db_cb, hapd);
     181         [ -  + ]:          1 :                 if (hapd->eap_sim_db_priv == NULL) {
     182                 :          0 :                         wpa_printf(MSG_ERROR, "Failed to initialize EAP-SIM "
     183                 :            :                                    "database interface");
     184                 :          0 :                         authsrv_deinit(hapd);
     185                 :          0 :                         return -1;
     186                 :            :                 }
     187                 :            :         }
     188                 :            : #endif /* EAP_SIM_DB */
     189                 :            : 
     190                 :            : #ifdef RADIUS_SERVER
     191   [ +  +  -  + ]:        345 :         if (hapd->conf->radius_server_clients &&
     192                 :          2 :             hostapd_setup_radius_srv(hapd))
     193                 :          0 :                 return -1;
     194                 :            : #endif /* RADIUS_SERVER */
     195                 :            : 
     196                 :        429 :         return 0;
     197                 :            : }
     198                 :            : 
     199                 :            : 
     200                 :        429 : void authsrv_deinit(struct hostapd_data *hapd)
     201                 :            : {
     202                 :            : #ifdef RADIUS_SERVER
     203                 :        343 :         radius_server_deinit(hapd->radius_srv);
     204                 :        343 :         hapd->radius_srv = NULL;
     205                 :            : #endif /* RADIUS_SERVER */
     206                 :            : 
     207                 :            : #ifdef EAP_TLS_FUNCS
     208         [ +  + ]:        343 :         if (hapd->ssl_ctx) {
     209                 :          9 :                 tls_deinit(hapd->ssl_ctx);
     210                 :          9 :                 hapd->ssl_ctx = NULL;
     211                 :            :         }
     212                 :            : #endif /* EAP_TLS_FUNCS */
     213                 :            : 
     214                 :            : #ifdef EAP_SIM_DB
     215         [ +  + ]:        343 :         if (hapd->eap_sim_db_priv) {
     216                 :          1 :                 eap_sim_db_deinit(hapd->eap_sim_db_priv);
     217                 :          1 :                 hapd->eap_sim_db_priv = NULL;
     218                 :            :         }
     219                 :            : #endif /* EAP_SIM_DB */
     220                 :        429 : }

Generated by: LCOV version 1.9