The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_eap_aka.c
Go to the documentation of this file.
1/*
2 * This program is is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 5fd4dc6e89026dd93cffd5db031ccca292b9d8f9 $
19 * @file rlm_eap_aka.c
20 * @brief Implements EAP-AKA
21 *
22 * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 *
24 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 * @copyright 2016 The FreeRADIUS server project
26 * @copyright 2016 Network RADIUS SAS (legal.com)
27 */
28RCSID("$Id: 5fd4dc6e89026dd93cffd5db031ccca292b9d8f9 $")
29
30#include <freeradius-devel/eap/base.h>
31#include <freeradius-devel/eap_aka_sim/attrs.h>
32#include <freeradius-devel/eap_aka_sim/base.h>
33#include <freeradius-devel/eap_aka_sim/module.h>
34#include <freeradius-devel/server/virtual_servers.h>
35#include <freeradius-devel/unlang/module.h>
36#include <freeradius-devel/util/rand.h>
37#include <freeradius-devel/util/debug.h>
38
40 { FR_CONF_OFFSET_TYPE_FLAGS("virtual_server", FR_TYPE_VOID, 0, eap_aka_sim_module_conf_t, virtual_server),
43 .process_module_name = "eap_aka",
44 } },
45 { FR_CONF_OFFSET_IS_SET("prefer_aka_prime", FR_TYPE_BOOL, 0, eap_aka_sim_module_conf_t, aka.send_at_bidding_prefer_prime ), .dflt = "no" },
46
48};
49
51
53{
54 eap_session_t *eap_session = eap_session_get(request->parent);
55 eap_aka_sim_mod_session_t *mod_session;
56
57 MEM(mod_session = talloc_zero(eap_session, eap_aka_sim_mod_session_t));
58 mod_session->id = (uint8_t)(fr_rand() & 0xff);
59 mod_session->ctx.hmac_md = mod_session->ctx.checkcode_md = EVP_sha1();
60 eap_session->opaque = mod_session;
61 eap_session->process = eap_aka_sim_process;
62
63 return eap_session->process(p_result, mctx, request);
64}
65
66static int mod_instantiate(module_inst_ctx_t const *mctx)
67{
68 eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->mi->data, eap_aka_sim_module_conf_t);
69 CONF_SECTION *conf = mctx->mi->conf;
70
72
73 /*
74 * If the user didn't specify a bidding value
75 * infer whether we need to send the bidding
76 * attribute, by whether the EAP module has
77 * has the AKA-Prime module enabled.
78 */
79 if (!inst->aka.send_at_bidding_prefer_prime_is_set) {
81 CONF_PAIR *cp = NULL;
82
83 while ((cp = cf_pair_find_next(parent, cp, "type"))) {
84 if (strcmp(cf_pair_value(cp), "aka-prime") == 0) {
85 cf_log_debug(conf, "Setting 'prefer_aka_prime = yes', as EAP-AKA-Prime is enabled");
86 inst->aka.send_at_bidding_prefer_prime = true;
87 inst->aka.send_at_bidding_prefer_prime_is_set = true;
88 break;
89 }
90 }
91 }
92
93 return 0;
94}
95
96static eap_type_t mod_type_identity(UNUSED void *instance, char const *id, size_t len)
97{
99
101}
102
103static int mod_load(void)
104{
105 if (fr_aka_sim_init() < 0) return -1;
106
108
109 return 0;
110}
111
112static void mod_unload(void)
113{
115
117}
118
119/*
120 * The module name should be the only globally exported symbol.
121 * That is, everything else should be 'static'.
122 */
124 .common = {
125 .magic = MODULE_MAGIC_INIT,
126 .name = "eap_aka",
127
129 .inst_type = "eap_aka_sim_module_conf_t",
131
132 .onload = mod_load,
133 .unload = mod_unload,
134
135 .instantiate = mod_instantiate,
136 },
137 .provides = { FR_EAP_METHOD_AKA },
138 .type_identity = mod_type_identity,
139 .session_init = mod_session_init,
140 .namespace = &dict_eap_aka_sim
141};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
#define RCSID(id)
Definition build.h:485
#define UNUSED
Definition build.h:317
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:662
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:616
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Definition cf_parse.h:298
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:599
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *attr)
Find a pair with a name matching attr, after specified pair.
Definition cf_util.c:1440
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1581
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_log_debug(_cf, _fmt,...)
Definition cf_util.h:289
#define MEM(x)
Definition debug.h:36
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
enum eap_type eap_type_t
@ FR_EAP_METHOD_AKA
Definition types.h:68
@ FR_EAP_METHOD_INVALID
Definition types.h:45
int fr_aka_sim_xlat_func_register(void)
Definition xlat.c:497
EVP_MD const * hmac_md
HMAC digest algorithm, usually EVP_sha1().
Definition base.h:240
EVP_MD const * checkcode_md
HMAC we use for calculating the checkcode.
Definition base.h:241
void fr_aka_sim_xlat_func_unregister(void)
Definition xlat.c:531
fr_aka_sim_ctx_t ctx
Definition module.h:82
uint8_t id
Last ID used, monotonically increments.
Definition module.h:73
Structure used to track session state at the module level.
Definition module.h:72
static eap_session_t * eap_session_get(request_t *request)
Definition session.h:83
void * opaque
Opaque data used by EAP methods.
Definition session.h:63
module_method_t process
Callback that should be used to process the next round.
Definition session.h:65
Tracks the progress of a single session of any EAP method.
Definition session.h:41
fr_dict_t const * dict_eap_aka_sim
Definition base.c:48
void fr_aka_sim_free(void)
Definition base.c:315
int fr_aka_sim_init(void)
Definition base.c:284
eap_type_t fr_aka_sim_id_to_eap_type(char const *id, size_t len)
Determine if a given identity is a 3gpp identity, and return the EAP method hinted.
Definition id.c:306
@ FR_TYPE_VOID
User data.
@ FR_TYPE_BOOL
A truth value.
unsigned char uint8_t
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
static const conf_parser_t config[]
Definition base.c:186
static rs_t * conf
Definition radsniff.c:53
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:105
static int mod_load(void)
static void mod_unload(void)
static conf_parser_t submodule_config[]
Definition rlm_eap_aka.c:39
static unlang_action_t mod_session_init(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_eap_aka.c:52
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_eap_aka.c:66
rlm_eap_submodule_t rlm_eap_aka
static eap_type_t mod_type_identity(UNUSED void *instance, char const *id, size_t len)
Definition rlm_eap_aka.c:96
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:291
unlang_action_t eap_aka_sim_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Decode EAP session data into attribute.
Definition module.c:294
eap_aka_sim_process_conf_t * inst
eap_type_t type
The preferred EAP-Type of this instance of the EAP-SIM/AKA/AKA' state machine.
module_t common
Common fields provided by all modules.
Definition submodule.h:50
eap_type_t provides[MAX_PROVIDED_METHODS]
Allow the module to register itself for more than one EAP-Method.
Definition submodule.h:52
Interface exported by EAP submodules.
Definition submodule.h:49
static fr_slen_t parent
Definition pair.h:841
int virtual_server_cf_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Wrapper for the config parser to allow pass1 resolution of virtual servers.
Additional validation rules for virtual server lookup.