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: e0bf27f2f3786e19679fa86f82a6d29b1dea2d79 $
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: e0bf27f2f3786e19679fa86f82a6d29b1dea2d79 $")
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
41 { 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" },
42
44};
45
47
48static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
49{
50 eap_session_t *eap_session = eap_session_get(request->parent);
51 eap_aka_sim_mod_session_t *mod_session;
52
53 MEM(mod_session = talloc_zero(eap_session, eap_aka_sim_mod_session_t));
54 mod_session->id = (uint8_t)(fr_rand() & 0xff);
55 mod_session->ctx.hmac_md = mod_session->ctx.checkcode_md = EVP_sha1();
56 eap_session->opaque = mod_session;
57 eap_session->process = eap_aka_sim_process;
58
59 return eap_session->process(p_result, mctx, request);
60}
61
62static int mod_instantiate(module_inst_ctx_t const *mctx)
63{
64 eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->mi->data, eap_aka_sim_module_conf_t);
65 CONF_SECTION *conf = mctx->mi->conf;
66
68
69 /*
70 * If the user didn't specify a bidding value
71 * infer whether we need to send the bidding
72 * attribute, by whether the EAP module has
73 * has the AKA-Prime module enabled.
74 */
75 if (!inst->aka.send_at_bidding_prefer_prime_is_set) {
77 CONF_PAIR *cp = NULL;
78
79 while ((cp = cf_pair_find_next(parent, cp, "type"))) {
80 if (strcmp(cf_pair_value(cp), "aka-prime") == 0) {
81 cf_log_debug(conf, "Setting 'prefer_aka_prime = yes', as EAP-AKA-Prime is enabled");
82 inst->aka.send_at_bidding_prefer_prime = true;
83 inst->aka.send_at_bidding_prefer_prime_is_set = true;
84 break;
85 }
86 }
87 }
88
89 return 0;
90}
91
92static eap_type_t mod_type_identity(UNUSED void *instance, char const *id, size_t len)
93{
95
97}
98
99static int mod_load(void)
100{
101 if (fr_aka_sim_init() < 0) return -1;
102
104
105 return 0;
106}
107
108static void mod_unload(void)
109{
111
113}
114
115/*
116 * The module name should be the only globally exported symbol.
117 * That is, everything else should be 'static'.
118 */
120 .common = {
121 .magic = MODULE_MAGIC_INIT,
122 .name = "eap_aka",
123
125 .inst_type = "eap_aka_sim_module_conf_t",
127
128 .onload = mod_load,
129 .unload = mod_unload,
130
132 },
133 .provides = { FR_EAP_METHOD_AKA },
134 .type_identity = mod_type_identity,
135 .session_init = mod_session_init,
136 .namespace = &dict_eap_aka_sim
137};
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:483
#define UNUSED
Definition build.h:315
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:642
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:596
#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:282
#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:579
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:1453
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:684
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1594
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_log_debug(_cf, _fmt,...)
Definition cf_util.h:292
#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:521
fr_aka_sim_ctx_t ctx
Definition module.h:79
uint8_t id
Last ID used, monotonically increments.
Definition module.h:72
Structure used to track session state at the module level.
Definition module.h:71
static eap_session_t * eap_session_get(request_t *request)
Definition session.h:82
void * opaque
Opaque data used by EAP methods.
Definition session.h:62
module_method_t process
Callback that should be used to process the next round.
Definition session.h:64
Tracks the progress of a single session of any EAP method.
Definition session.h:40
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:183
static rs_t * conf
Definition radsniff.c:53
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:105
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
static int mod_load(void)
Definition rlm_eap_aka.c:99
static void mod_unload(void)
static conf_parser_t submodule_config[]
Definition rlm_eap_aka.c:39
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_eap_aka.c:62
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:92
static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_eap_aka.c:48
static int instantiate(module_inst_ctx_t const *mctx)
Definition rlm_rest.c:1310
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:329
size_t inst_size
Size of the module's instance data.
Definition module.h:203
void * data
Module's instance data.
Definition module.h:271
unlang_action_t eap_aka_sim_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Decode EAP session data into attribute.
Definition module.c:295
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:851
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.