|
1 /* |
|
2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // This is enumeration of EAPOL source code. |
|
20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
21 #undef EAP_FILE_NUMBER_ENUM |
|
22 #define EAP_FILE_NUMBER_ENUM 109 |
|
23 #undef EAP_FILE_NUMBER_DATE |
|
24 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
26 |
|
27 |
|
28 |
|
29 #include "eap_am_memory.h" |
|
30 #include "eap_radius_payloads.h" |
|
31 #include "abs_eap_am_tools.h" |
|
32 #include "eap_tools.h" |
|
33 |
|
34 |
|
35 |
|
36 EAP_FUNC_EXPORT eap_radius_variable_data_c::~eap_radius_variable_data_c() |
|
37 { |
|
38 } |
|
39 |
|
40 EAP_FUNC_EXPORT eap_radius_variable_data_c::eap_radius_variable_data_c(abs_eap_am_tools_c * const tools) |
|
41 : m_am_tools(tools) |
|
42 , m_data(tools) |
|
43 , m_payload_type(eap_diameter_avp_code_none) |
|
44 { |
|
45 } |
|
46 |
|
47 EAP_FUNC_EXPORT eap_status_e eap_radius_variable_data_c::set_buffer( |
|
48 const eap_diameter_avp_code_c current_payload, |
|
49 const u8_t * const buffer, |
|
50 const u32_t buffer_length, |
|
51 const bool free_buffer, |
|
52 const bool is_writable) |
|
53 { |
|
54 eap_status_e status = m_data.set_buffer( |
|
55 buffer, |
|
56 buffer_length, |
|
57 free_buffer, |
|
58 is_writable); |
|
59 if (status != eap_status_ok) |
|
60 { |
|
61 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
62 return EAP_STATUS_RETURN(m_am_tools, status); |
|
63 } |
|
64 |
|
65 m_payload_type = current_payload; |
|
66 |
|
67 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
68 return EAP_STATUS_RETURN(m_am_tools, status); |
|
69 } |
|
70 |
|
71 EAP_FUNC_EXPORT eap_status_e eap_radius_variable_data_c::add_data( |
|
72 const u8_t * const buffer, |
|
73 const u32_t buffer_length) |
|
74 { |
|
75 eap_status_e status = m_data.add_data( |
|
76 buffer, |
|
77 buffer_length); |
|
78 |
|
79 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
80 return EAP_STATUS_RETURN(m_am_tools, status); |
|
81 } |
|
82 |
|
83 EAP_FUNC_EXPORT u32_t eap_radius_variable_data_c::get_data_length() const |
|
84 { |
|
85 return m_data.get_data_length(); |
|
86 } |
|
87 |
|
88 EAP_FUNC_EXPORT u8_t * eap_radius_variable_data_c::get_data(const u32_t data_length) const |
|
89 { |
|
90 return m_data.get_data(data_length); |
|
91 } |
|
92 |
|
93 EAP_FUNC_EXPORT eap_variable_data_c * eap_radius_variable_data_c::get_payload_buffer() |
|
94 { |
|
95 return &m_data; |
|
96 } |
|
97 |
|
98 EAP_FUNC_EXPORT eap_diameter_avp_code_c eap_radius_variable_data_c::get_payload_type() const |
|
99 { |
|
100 return m_payload_type; |
|
101 } |
|
102 |
|
103 EAP_FUNC_EXPORT void eap_radius_variable_data_c::set_payload_type(const eap_diameter_avp_code_c type) |
|
104 { |
|
105 m_payload_type = type; |
|
106 } |
|
107 |
|
108 EAP_FUNC_EXPORT eap_radius_variable_data_c * eap_radius_variable_data_c::copy() const |
|
109 { |
|
110 eap_radius_variable_data_c * new_data = new eap_radius_variable_data_c(m_am_tools); |
|
111 |
|
112 if (new_data != 0) |
|
113 { |
|
114 eap_status_e status = new_data->get_payload_buffer()->add_data(&m_data); |
|
115 if (status != eap_status_ok) |
|
116 { |
|
117 delete new_data; |
|
118 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
119 (void) EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
120 return 0; |
|
121 } |
|
122 |
|
123 new_data->set_payload_type(get_payload_type()); |
|
124 } |
|
125 |
|
126 return new_data; |
|
127 } |
|
128 |
|
129 EAP_FUNC_EXPORT void eap_radius_variable_data_c::object_increase_reference_count() |
|
130 { |
|
131 } |
|
132 |
|
133 |
|
134 |
|
135 EAP_FUNC_EXPORT eap_radius_payloads_c::~eap_radius_payloads_c() |
|
136 { |
|
137 } |
|
138 |
|
139 EAP_FUNC_EXPORT eap_radius_payloads_c::eap_radius_payloads_c( |
|
140 abs_eap_am_tools_c * const tools) |
|
141 : m_am_tools(tools) |
|
142 , m_payload_map(tools, this) |
|
143 , m_is_valid(false) |
|
144 { |
|
145 m_is_valid = true; |
|
146 } |
|
147 |
|
148 EAP_FUNC_EXPORT eap_radius_variable_data_c * eap_radius_payloads_c::get_payload( |
|
149 const eap_diameter_avp_code_c current_payload) |
|
150 { |
|
151 eap_variable_data_c selector(m_am_tools); |
|
152 |
|
153 selector.set_buffer( |
|
154 ¤t_payload, |
|
155 sizeof(current_payload), |
|
156 false, |
|
157 false); |
|
158 |
|
159 eap_radius_variable_data_c *payload = m_payload_map.get_handler(&selector); |
|
160 |
|
161 return payload; |
|
162 } |
|
163 |
|
164 |
|
165 EAP_FUNC_EXPORT eap_status_e eap_radius_payloads_c::add_payload( |
|
166 const eap_diameter_avp_code_c current_payload, |
|
167 const u8_t * const data, |
|
168 const u32_t data_length, |
|
169 const bool free_buffer, |
|
170 const bool is_writable, |
|
171 const bool fragments_allowed) |
|
172 { |
|
173 eap_status_e status(eap_status_process_general_error); |
|
174 |
|
175 eap_radius_variable_data_c *payload = get_payload( |
|
176 current_payload); |
|
177 if (payload != 0) |
|
178 { |
|
179 if (fragments_allowed == true) |
|
180 { |
|
181 // Add fragment to the end of the existing payload. |
|
182 status = payload->add_data(data, data_length); |
|
183 if (status != eap_status_ok) |
|
184 { |
|
185 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
186 return EAP_STATUS_RETURN(m_am_tools, status); |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 // Caanot add fragment. |
|
192 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
193 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_payload); |
|
194 } |
|
195 } |
|
196 else |
|
197 { |
|
198 eap_variable_data_c selector(m_am_tools); |
|
199 |
|
200 selector.set_buffer( |
|
201 ¤t_payload, |
|
202 sizeof(current_payload), |
|
203 false, |
|
204 false); |
|
205 |
|
206 eap_radius_variable_data_c *payload = new eap_radius_variable_data_c( |
|
207 m_am_tools); |
|
208 if (payload == 0) |
|
209 { |
|
210 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
211 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
212 } |
|
213 |
|
214 status = payload->set_buffer( |
|
215 current_payload, |
|
216 data, |
|
217 data_length, |
|
218 free_buffer, |
|
219 is_writable); |
|
220 if (status != eap_status_ok) |
|
221 { |
|
222 delete payload; |
|
223 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
224 return EAP_STATUS_RETURN(m_am_tools, status); |
|
225 } |
|
226 |
|
227 status = m_payload_map.add_handler(&selector, payload); |
|
228 if (status != eap_status_ok) |
|
229 { |
|
230 delete payload; |
|
231 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
232 return EAP_STATUS_RETURN(m_am_tools, status); |
|
233 } |
|
234 } |
|
235 |
|
236 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
237 return EAP_STATUS_RETURN(m_am_tools, status); |
|
238 } |
|
239 |
|
240 |
|
241 EAP_FUNC_EXPORT bool eap_radius_payloads_c::get_is_valid() const |
|
242 { |
|
243 return m_is_valid; |
|
244 } |
|
245 |
|
246 |
|
247 //-------------------------------------------------- |
|
248 |
|
249 //eap_radius_payloads_c |
|
250 EAP_FUNC_EXPORT eap_status_e eap_radius_payloads_c::parse_generic_payload( |
|
251 const eap_diameter_avp_code_c payload_type, |
|
252 const eap_radius_attribute_header_c * const payload) |
|
253 { |
|
254 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
255 |
|
256 EAP_RADIUS_TRACE_PAYLOAD("Parsing payload", payload); |
|
257 |
|
258 eap_status_e status(eap_status_process_general_error); |
|
259 |
|
260 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
261 // | Type | Length | Data ... |
|
262 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
263 if (payload->get_data_length() < eap_radius_attribute_header_c::get_header_length()) |
|
264 { |
|
265 EAP_TRACE_ERROR( |
|
266 m_am_tools, |
|
267 TRACE_FLAGS_RADIUS_ERROR, |
|
268 (EAPL("ERROR: eap_radius_payloads_c::parse_generic_payload(0x%08x): ") |
|
269 EAPL("current payload 0x%08x=%s, length 0x%04x, data length incorrect 0x%04x.\n"), |
|
270 payload, |
|
271 payload_type.get_vendor_code(), |
|
272 payload->get_payload_type_string(), |
|
273 payload->get_length(), |
|
274 payload->get_data_length())); |
|
275 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
276 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
277 } |
|
278 |
|
279 u32_t data_length = payload->get_data_length(); |
|
280 |
|
281 u8_t * const data |
|
282 = static_cast<u8_t *>(payload->get_data_offset(0ul, data_length)); |
|
283 |
|
284 if (data == 0) |
|
285 { |
|
286 EAP_TRACE_ERROR( |
|
287 m_am_tools, |
|
288 TRACE_FLAGS_RADIUS_ERROR, |
|
289 (EAPL("ERROR: eap_radius_payloads_c::parse_generic_payload(0x%08x): ") |
|
290 EAPL("current payload 0x%08x=%s, length 0x%04x, data buffer incorrect.\n"), |
|
291 payload, |
|
292 payload_type.get_vendor_code(), |
|
293 payload->get_payload_type_string(), |
|
294 payload->get_length())); |
|
295 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
296 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
297 } |
|
298 |
|
299 status = add_payload( |
|
300 payload_type, |
|
301 data, |
|
302 data_length, |
|
303 false, |
|
304 false, |
|
305 true); // This can be fragmented. |
|
306 |
|
307 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
308 return EAP_STATUS_RETURN(m_am_tools, status); |
|
309 } |
|
310 |
|
311 //-------------------------------------------------- |
|
312 |
|
313 // |
|
314 EAP_FUNC_EXPORT eap_status_e eap_radius_payloads_c::parse_radius_payload( |
|
315 const eap_radius_attribute_header_c * const p_payload, |
|
316 u32_t * const buffer_length) |
|
317 { |
|
318 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
319 |
|
320 eap_radius_attribute_header_c payload( |
|
321 m_am_tools, |
|
322 p_payload->get_header_buffer(*buffer_length), |
|
323 *buffer_length); // Const correctness is gone. |
|
324 |
|
325 eap_diameter_avp_code_c current_payload = payload.get_current_payload(); |
|
326 |
|
327 eap_status_e status = eap_status_header_corrupted; |
|
328 |
|
329 if (payload.get_is_valid() == true |
|
330 && current_payload != eap_diameter_avp_code_none) |
|
331 { |
|
332 if (*buffer_length < payload.get_header_length()+payload.get_data_length()) |
|
333 { |
|
334 EAP_TRACE_ERROR( |
|
335 m_am_tools, |
|
336 TRACE_FLAGS_RADIUS_ERROR, |
|
337 (EAPL("ERROR: eap_radius_payloads_c::parse_radius_payload(0x%08x): current payload 0x%08x=%s, data length 0x%04x, buffer length 0x%04x.\n"), |
|
338 payload.get_header_buffer(0ul), |
|
339 current_payload.get_vendor_code(), |
|
340 payload.get_payload_type_string(), |
|
341 payload.get_data_length(), |
|
342 *buffer_length)); |
|
343 EAP_TRACE_ERROR( |
|
344 m_am_tools, |
|
345 TRACE_FLAGS_RADIUS_ERROR, |
|
346 (EAPL("ERROR: eap_radius_payloads_c::parse_radius_payload(): RADIUS-payload header is corrupted.\n"))); |
|
347 EAP_TRACE_DATA_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("payload"), |
|
348 payload.get_header_buffer(*buffer_length), |
|
349 *buffer_length)); |
|
350 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
351 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
352 } |
|
353 |
|
354 status = parse_generic_payload(current_payload, &payload); |
|
355 if (status != eap_status_ok) |
|
356 { |
|
357 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
358 return EAP_STATUS_RETURN(m_am_tools, status); |
|
359 } |
|
360 |
|
361 EAP_ASSERT_ALWAYS(*buffer_length >= payload.get_header_length()+payload.get_data_length()); |
|
362 *buffer_length -= payload.get_header_length()+payload.get_data_length(); |
|
363 |
|
364 while(*buffer_length >= payload.get_header_length() |
|
365 && payload.get_is_valid() == true |
|
366 && payload.get_header_buffer_length() >= (payload.get_header_length()+payload.get_data_length())) |
|
367 { |
|
368 payload.set_header_buffer( |
|
369 payload.get_next_header(), |
|
370 payload.get_header_buffer_length()-(payload.get_header_length()+payload.get_data_length())); |
|
371 if (payload.get_is_valid() == false) |
|
372 { |
|
373 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
374 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
375 } |
|
376 |
|
377 current_payload = payload.get_current_payload(); |
|
378 |
|
379 if (*buffer_length < payload.get_header_length()+payload.get_data_length()) |
|
380 { |
|
381 EAP_TRACE_ERROR( |
|
382 m_am_tools, |
|
383 TRACE_FLAGS_RADIUS_ERROR, |
|
384 (EAPL("ERROR: eap_radius_payloads_c::parse_radius_payload(0x%08x): current payload 0x%08x=%s, data length 0x%04x, buffer length 0x%04x.\n"), |
|
385 payload.get_header_buffer(0ul), |
|
386 current_payload.get_vendor_code(), |
|
387 payload.get_payload_type_string(), |
|
388 payload.get_data_length(), |
|
389 *buffer_length)); |
|
390 EAP_TRACE_ERROR( |
|
391 m_am_tools, |
|
392 TRACE_FLAGS_RADIUS_ERROR, |
|
393 (EAPL("ERROR: eap_radius_payloads_c::parse_radius_payload(): RADIUS-payload header is corrupted.\n"))); |
|
394 EAP_TRACE_DATA_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("payload"), |
|
395 payload.get_header_buffer(*buffer_length), |
|
396 *buffer_length)); |
|
397 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
398 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
399 } |
|
400 |
|
401 status = parse_generic_payload(current_payload, &payload); |
|
402 if (status != eap_status_ok) |
|
403 { |
|
404 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
405 return EAP_STATUS_RETURN(m_am_tools, status); |
|
406 } |
|
407 |
|
408 EAP_ASSERT_ALWAYS(*buffer_length >= payload.get_header_length()+payload.get_data_length()); |
|
409 *buffer_length -= payload.get_header_length()+payload.get_data_length(); |
|
410 } |
|
411 } |
|
412 |
|
413 if (*buffer_length != 0u) |
|
414 { |
|
415 EAP_TRACE_ERROR( |
|
416 m_am_tools, |
|
417 TRACE_FLAGS_RADIUS_ERROR, |
|
418 (EAPL("ERROR: eap_radius_payloads_c::parse_radius_payload(): ") |
|
419 EAPL("RADIUS-header is corrupted. Buffer length and payload length does not match. %lu illegal bytes.\n"), |
|
420 *buffer_length)); |
|
421 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
422 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
423 } |
|
424 |
|
425 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
426 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
427 } |
|
428 |
|
429 //-------------------------------------------------- |
|
430 |
|
431 |
|
432 |
|
433 // End. |