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 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: cf3beb12d488aa4cadf720eb2f33249ad226765d $
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: cf3beb12d488aa4cadf720eb2f33249ad226765d $")
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/util/rand.h>
35
37 { FR_CONF_OFFSET_TYPE_FLAGS("virtual_server", FR_TYPE_VOID, 0, eap_aka_sim_module_conf_t, virtual_server),
40 .process_module_name = "eap_aka",
41 } },
42 { 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" },
43
45};
46
48
50{
51 eap_session_t *eap_session = eap_session_get(request->parent);
52 eap_aka_sim_mod_session_t *mod_session;
53
54 MEM(mod_session = talloc_zero(eap_session, eap_aka_sim_mod_session_t));
55 mod_session->id = (uint8_t)(fr_rand() & 0xff);
56 mod_session->ctx.hmac_md = mod_session->ctx.checkcode_md = EVP_sha1();
57 eap_session->opaque = mod_session;
58 eap_session->process = eap_aka_sim_process;
59
60 return eap_session->process(p_result, mctx, request);
61}
62
63static int mod_instantiate(module_inst_ctx_t const *mctx)
64{
65 eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->mi->data, eap_aka_sim_module_conf_t);
66 CONF_SECTION *conf = mctx->mi->conf;
67
69
70 /*
71 * If the user didn't specify a bidding value
72 * infer whether we need to send the bidding
73 * attribute, by whether the EAP module has
74 * has the AKA-Prime module enabled.
75 */
76 if (!inst->aka.send_at_bidding_prefer_prime_is_set) {
78 CONF_PAIR *cp = NULL;
79
80 while ((cp = cf_pair_find_next(parent, cp, "type"))) {
81 if (strcmp(cf_pair_value(cp), "aka-prime") == 0) {
82 cf_log_debug(conf, "Setting 'prefer_aka_prime = yes', as EAP-AKA-Prime is enabled");
83 inst->aka.send_at_bidding_prefer_prime = true;
84 inst->aka.send_at_bidding_prefer_prime_is_set = true;
85 break;
86 }
87 }
88 }
89
90 return 0;
91}
92
93static eap_type_t mod_type_identity(UNUSED void *instance, char const *id, size_t len)
94{
96
98}
99
100static int mod_load(void)
101{
102 if (fr_aka_sim_init() < 0) return -1;
103
105
106 return 0;
107}
108
109static void mod_unload(void)
110{
112
114}
115
116/*
117 * The module name should be the only globally exported symbol.
118 * That is, everything else should be 'static'.
119 */
121 .common = {
122 .magic = MODULE_MAGIC_INIT,
123 .name = "eap_aka",
124
126 .inst_type = "eap_aka_sim_module_conf_t",
128
129 .onload = mod_load,
130 .unload = mod_unload,
131
132 .instantiate = mod_instantiate,
133 },
134 .provides = { FR_EAP_METHOD_AKA },
135 .type_identity = mod_type_identity,
136 .session_init = mod_session_init,
137 .namespace = &dict_eap_aka_sim
138};
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:506
#define UNUSED
Definition build.h:336
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:657
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:611
#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:294
#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:238
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:594
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:72
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:1436
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:685
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:98
#define cf_log_debug(_cf, _fmt,...)
Definition cf_util.h:288
#define MEM(x)
Definition debug.h:46
#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:498
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:532
fr_aka_sim_ctx_t ctx
Definition module.h:83
uint8_t id
Last ID used, monotonically increments.
Definition module.h:74
Structure used to track session state at the module level.
Definition module.h:73
static eap_session_t * eap_session_get(request_t *request)
Definition session.h:85
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:163
static rs_t * conf
Definition radsniff.c:52
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:104
static int mod_load(void)
static void mod_unload(void)
static conf_parser_t submodule_config[]
Definition rlm_eap_aka.c:36
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:49
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_eap_aka.c:63
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:93
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:293
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:292
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:858
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.