The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
base.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
5 * (at 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: 7e01277270779e135187ce7725a51c43e8471009 $
19 * @file src/process/tls/base.c
20 * @brief TLS processing.
21 *
22 * @copyright 2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 */
24#include <freeradius-devel/unlang/interpret.h>
25#include <freeradius-devel/util/debug.h>
26#include <freeradius-devel/protocol/tls/freeradius.h>
27
28static fr_dict_t const *dict_tls;
29
35
37
43
52
56
57#define FR_TLS_PACKET_CODE_VALID(_code) (((_code) > 0) && ((_code) <= FR_PACKET_TYPE_VALUE_NOTFOUND))
58
59#define PROCESS_INST process_tls_t
60#define PROCESS_PACKET_TYPE uint32_t
61#define PROCESS_CODE_DO_NOT_RESPOND FR_PACKET_TYPE_VALUE_FAILURE
62#define PROCESS_PACKET_CODE_VALID FR_TLS_PACKET_CODE_VALID
63
64#include <freeradius-devel/server/process.h>
65
66static fr_process_state_t const process_state[] = {
67 [FR_PACKET_TYPE_VALUE_LOAD_SESSION] = {
68 .packet_type = {
69 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
70 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
71
72 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_FAILURE,
73 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
74 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
75 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
76 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
77 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_FAILURE,
78 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
79 },
80 .default_rcode = RLM_MODULE_NOOP,
81 .recv = recv_generic,
82 .resume = resume_recv_no_send,
83 .section_offset = PROCESS_CONF_OFFSET(load_session),
84 },
85 [FR_PACKET_TYPE_VALUE_STORE_SESSION] = {
86 .packet_type = {
87 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
88 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
89
90 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_FAILURE,
91 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
92 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
93 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
94 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
95 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_FAILURE,
96 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
97 },
98 .default_rcode = RLM_MODULE_NOOP,
99 .recv = recv_generic,
100 .resume = resume_recv_no_send,
101 .section_offset = PROCESS_CONF_OFFSET(store_session),
102 },
103 [FR_PACKET_TYPE_VALUE_CLEAR_SESSION] = {
104 .packet_type = {
105 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
106 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
107
108 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_FAILURE,
109 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
110 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
111 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
112 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
113 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_FAILURE,
114 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
115 },
116 .default_rcode = RLM_MODULE_NOOP,
117 .recv = recv_generic,
118 .resume = resume_recv_no_send,
119 .section_offset = PROCESS_CONF_OFFSET(clear_session),
120 },
121 [FR_PACKET_TYPE_VALUE_VERIFY_CERTIFICATE] = {
122 .packet_type = {
123 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
124 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
125 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_SUCCESS,
126
127 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
128 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
129 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
130 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
131 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_FAILURE,
132 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
133 },
134 .default_rcode = RLM_MODULE_NOOP,
135 .recv = recv_generic,
136 .resume = resume_recv_no_send,
137 .section_offset = PROCESS_CONF_OFFSET(verify_certificate),
138 },
139 [FR_PACKET_TYPE_VALUE_NEW_SESSION] = {
140 .packet_type = {
141 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
142 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
143 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_SUCCESS,
144
145 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
146 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
147 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
148 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
149 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_FAILURE,
150 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND,
151 },
152 .default_rcode = RLM_MODULE_NOOP,
153 .recv = recv_generic,
154 .resume = resume_recv_no_send,
155 .section_offset = PROCESS_CONF_OFFSET(new_session),
156 },
157 [FR_PACKET_TYPE_VALUE_ESTABLISH_SESSION] = {
158 .packet_type = {
159 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_SUCCESS,
160 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_SUCCESS,
161 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_SUCCESS,
162
163 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_FAILURE,
164 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_FAILURE,
165 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_FAILURE,
166 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_FAILURE,
167 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_FAILURE,
168 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_NOTFOUND
169 },
170 .default_rcode = RLM_MODULE_NOOP,
171 .recv = recv_generic,
172 .resume = resume_recv_no_send,
173 .section_offset = PROCESS_CONF_OFFSET(establish_session),
174 },
175};
176
177static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
178{
179 fr_process_state_t const *state;
180
182
184
185 request->component = "tls";
186 request->module = NULL;
187 fr_assert(request->proto_dict == dict_tls);
188
189 /*
190 * Success, failure, and notfound are not TLS packets that we
191 */
192 if (!request->packet->code || (request->packet->code > FR_PACKET_TYPE_VALUE_ESTABLISH_SESSION)) {
193 REDEBUG("Invalid packet code %u", request->packet->code);
195 }
196
197 UPDATE_STATE(packet);
198
199 log_request_pair_list(L_DBG_LVL_1, request, NULL, &request->request_pairs, NULL);
200
201 return state->recv(p_result, mctx, request);
202}
203
205 {
206 .section = SECTION_NAME("store", "session"),
207 .actions = &mod_actions_authorize,
208 .offset = PROCESS_CONF_OFFSET(store_session)
209 },
210 {
211 .section = SECTION_NAME("load", "session"),
213 .offset = PROCESS_CONF_OFFSET(load_session)
214 },
215 {
216 .section = SECTION_NAME("clear", "session"),
218 .offset = PROCESS_CONF_OFFSET(clear_session)
219 },
220 {
221 .section = SECTION_NAME("verify", "certificate"),
223 .offset = PROCESS_CONF_OFFSET(verify_certificate)
224 },
225 {
226 .section = SECTION_NAME("new", "session"),
228 .offset = PROCESS_CONF_OFFSET(new_session)
229 },
230 {
231 .section = SECTION_NAME("establish", "session"),
233 .offset = PROCESS_CONF_OFFSET(establish_session)
234 },
236};
237
238
241 .common = {
242 .magic = MODULE_MAGIC_INIT,
243 .name = "tls",
245 MODULE_RCTX(process_rctx_t)
246 },
247 .process = mod_process,
248 .compile_list = compile_list,
249 .dict = &dict_tls,
250 .packet_type = &attr_packet_type
251};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:292
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:305
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
Specifies an attribute which must be present for the module to function.
Definition dict.h:291
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:304
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
fr_dict_attr_t const * attr_packet_type
Definition base.c:91
static fr_dict_t const * dict_tls
Definition base.c:77
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
Definition log.c:828
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition log.h:67
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unlang_mod_actions_t const mod_actions_authorize
Definition mod_action.c:45
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:69
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:168
static const virtual_server_compile_t compile_list[]
Definition base.c:192
static fr_process_state_t const process_state[]
Definition base.c:68
CONF_SECTION * establish_session
Definition base.c:50
fr_process_module_t process_tls
Definition base.c:240
CONF_SECTION * store_session
Definition base.c:46
fr_dict_autoload_t process_tls_dict[]
Definition base.c:31
CONF_SECTION * load_session
Definition base.c:45
CONF_SECTION * clear_session
Definition base.c:47
fr_dict_attr_autoload_t process_tls_dict_attr[]
Definition base.c:39
CONF_SECTION * verify_certificate
Definition base.c:48
CONF_SECTION * new_session
Definition base.c:49
process_tls_sections_t sections
Definition base.c:54
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition process.h:55
#define PROCESS_CONF_OFFSET(_x)
Definition process.h:79
module_t common
Common fields for all loadable modules.
Common public symbol definition for all process modules.
#define fr_assert(_expr)
Definition rad_assert.h:37
#define REDEBUG(fmt,...)
#define RETURN_UNLANG_FAIL
Definition rcode.h:63
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:52
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:56
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:53
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:39
void * data
Module's instance data.
Definition module.h:293
#define MODULE_RCTX(_ctype)
Definition module.h:259
#define MODULE_INST(_ctype)
Definition module.h:257
#define talloc_get_type_abort_const
Definition talloc.h:117
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.