|
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 52 |
|
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 "eapol_rc4_key_header.h" |
|
30 |
|
31 |
|
32 //------------------------------------------------------ |
|
33 |
|
34 // |
|
35 EAP_FUNC_EXPORT eapol_RC4_key_header_c::~eapol_RC4_key_header_c() |
|
36 { |
|
37 } |
|
38 |
|
39 //------------------------------------------------------ |
|
40 |
|
41 // |
|
42 EAP_FUNC_EXPORT eapol_RC4_key_header_c::eapol_RC4_key_header_c( |
|
43 abs_eap_am_tools_c * const tools, |
|
44 void * const header_begin, |
|
45 const u32_t header_buffer_length) |
|
46 : eap_general_header_base_c(tools, header_begin, header_buffer_length) |
|
47 , m_am_tools(tools) |
|
48 { |
|
49 } |
|
50 |
|
51 //------------------------------------------------------ |
|
52 |
|
53 // |
|
54 EAP_FUNC_EXPORT eapol_protocol_version_e eapol_RC4_key_header_c::get_eapol_protocol_version() const |
|
55 { |
|
56 const u8_t * const data = get_header_offset(m_offset_eapol_version, sizeof(u8_t)); |
|
57 if (data != 0) |
|
58 { |
|
59 return static_cast<eapol_protocol_version_e>(*data); |
|
60 } |
|
61 else |
|
62 { |
|
63 return eapol_protocol_version_none; |
|
64 } |
|
65 } |
|
66 |
|
67 //------------------------------------------------------ |
|
68 |
|
69 // |
|
70 EAP_FUNC_EXPORT eapol_packet_type_e eapol_RC4_key_header_c::get_eapol_packet_type() const |
|
71 { |
|
72 const u8_t * const data = get_header_offset(m_offset_eapol_type, sizeof(u8_t)); |
|
73 if (data != 0) |
|
74 { |
|
75 return static_cast<eapol_packet_type_e>(*data); |
|
76 } |
|
77 else |
|
78 { |
|
79 return eapol_packet_type_no_type; |
|
80 } |
|
81 } |
|
82 |
|
83 //------------------------------------------------------ |
|
84 |
|
85 // |
|
86 EAP_FUNC_EXPORT u16_t eapol_RC4_key_header_c::get_eapol_packet_body_length() const |
|
87 { |
|
88 const u8_t * const data = get_header_offset(m_offset_eapol_packet_body_length, sizeof(u16_t)); |
|
89 if (data != 0) |
|
90 { |
|
91 return eap_read_u16_t_network_order(data, sizeof(u16_t)); |
|
92 } |
|
93 else |
|
94 { |
|
95 return 0ul; |
|
96 } |
|
97 } |
|
98 |
|
99 //------------------------------------------------------ |
|
100 |
|
101 // |
|
102 EAP_FUNC_EXPORT eapol_key_descriptor_type_e eapol_RC4_key_header_c::get_key_descriptor_type() const |
|
103 { |
|
104 const u8_t * const data = get_header_offset(m_offset_key_descriptor_type, sizeof(u8_t)); |
|
105 if (data != 0) |
|
106 { |
|
107 return static_cast<eapol_key_descriptor_type_e>(*data); |
|
108 } |
|
109 else |
|
110 { |
|
111 return eapol_key_descriptor_type_none; |
|
112 } |
|
113 } |
|
114 |
|
115 //------------------------------------------------------ |
|
116 |
|
117 // |
|
118 EAP_FUNC_EXPORT u16_t eapol_RC4_key_header_c::get_key_length() const |
|
119 { |
|
120 const u8_t * const data = get_header_offset(m_offset_key_length, sizeof(u16_t)); |
|
121 if (data != 0) |
|
122 { |
|
123 return eap_read_u16_t_network_order(data, sizeof(u16_t)); |
|
124 } |
|
125 else |
|
126 { |
|
127 return 0ul; |
|
128 } |
|
129 } |
|
130 |
|
131 //------------------------------------------------------ |
|
132 |
|
133 // |
|
134 EAP_FUNC_EXPORT u8_t *eapol_RC4_key_header_c::get_replay_counter() |
|
135 { |
|
136 u8_t * const data = get_header_offset(m_offset_replay_counter, EAPOL_RC4_KEY_REPLAY_COUNTER_LENGTH); |
|
137 return data; |
|
138 } |
|
139 |
|
140 //------------------------------------------------------ |
|
141 |
|
142 // |
|
143 EAP_FUNC_EXPORT u8_t *eapol_RC4_key_header_c::get_key_IV() |
|
144 { |
|
145 u8_t * const data = get_header_offset(m_offset_key_IV, EAPOL_RC4_KEY_IV_LENGTH); |
|
146 return data; |
|
147 } |
|
148 |
|
149 //------------------------------------------------------ |
|
150 |
|
151 // |
|
152 EAP_FUNC_EXPORT eapol_RC4_key_flags_e eapol_RC4_key_header_c::get_key_flag() const |
|
153 { |
|
154 const u8_t * const data = get_header_offset(m_offset_key_index, sizeof(u8_t)); |
|
155 if (data != 0) |
|
156 { |
|
157 return static_cast<eapol_RC4_key_flags_e>((((*data) & m_flag_mask_key_flag) >> m_flag_shift_key_flag)); |
|
158 } |
|
159 else |
|
160 { |
|
161 return eapol_RC4_key_flag_none; |
|
162 } |
|
163 } |
|
164 |
|
165 //------------------------------------------------------ |
|
166 |
|
167 // |
|
168 EAP_FUNC_EXPORT u8_t eapol_RC4_key_header_c::get_key_index() const |
|
169 { |
|
170 const u8_t * const data = get_header_offset(m_offset_key_index, sizeof(u8_t)); |
|
171 if (data != 0) |
|
172 { |
|
173 return static_cast<u8_t>(((*data) & ~m_flag_mask_key_flag)); |
|
174 } |
|
175 else |
|
176 { |
|
177 // This is illegal index. |
|
178 return 0xff; |
|
179 } |
|
180 } |
|
181 |
|
182 //------------------------------------------------------ |
|
183 |
|
184 // |
|
185 EAP_FUNC_EXPORT u8_t *eapol_RC4_key_header_c::get_key_signature() const |
|
186 { |
|
187 u8_t * const data = get_header_offset(m_offset_key_signature, EAPOL_RC4_KEY_SIGNATURE_LENGTH); |
|
188 return data; |
|
189 } |
|
190 |
|
191 //------------------------------------------------------ |
|
192 |
|
193 // |
|
194 EAP_FUNC_EXPORT u16_t eapol_RC4_key_header_c::get_header_length() |
|
195 { |
|
196 return m_offset_data; |
|
197 } |
|
198 |
|
199 //------------------------------------------------------ |
|
200 |
|
201 // |
|
202 EAP_FUNC_EXPORT u8_t * eapol_RC4_key_header_c::get_key() const |
|
203 { |
|
204 if (get_eapol_packet_body_length() > SIZE_OF_EMPTY_EAPOL_RC4_KEY_BODY) |
|
205 { |
|
206 u8_t * const data = get_header_offset( |
|
207 m_offset_data, |
|
208 get_header_buffer_length() - SIZE_OF_EMPTY_EAPOL_RC4_KEY_FRAME); |
|
209 return data; // Data begins after the header. |
|
210 } |
|
211 return 0; |
|
212 } |
|
213 |
|
214 //------------------------------------------------------ |
|
215 //------------------------------------------------------ |
|
216 //------------------------------------------------------ |
|
217 |
|
218 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_eapol_protocol_version(eapol_protocol_version_e version) |
|
219 { |
|
220 u8_t * const data = get_header_offset(m_offset_eapol_version, sizeof(u8_t)); |
|
221 if (data != 0) |
|
222 { |
|
223 *data = static_cast<u8_t>(version); |
|
224 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
225 } |
|
226 else |
|
227 { |
|
228 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
229 } |
|
230 } |
|
231 |
|
232 //------------------------------------------------------ |
|
233 |
|
234 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_eapol_packet_type(eapol_packet_type_e type) |
|
235 { |
|
236 u8_t * const data = get_header_offset(m_offset_eapol_type, sizeof(u8_t)); |
|
237 if (data != 0) |
|
238 { |
|
239 *data = static_cast<u8_t>(type); |
|
240 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
241 } |
|
242 else |
|
243 { |
|
244 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
245 } |
|
246 } |
|
247 |
|
248 //------------------------------------------------------ |
|
249 |
|
250 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_eapol_packet_body_length(u16_t eapol_length) |
|
251 { |
|
252 if (eapol_length - eapol_header_base_c::get_header_length() > eapol_RC4_key_header_c::EAPOL_RC4_EAPOL_KEY_MAXIMUM_SIZE) |
|
253 { |
|
254 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
255 return EAP_STATUS_RETURN(m_am_tools, eap_status_too_long_message); |
|
256 } |
|
257 |
|
258 u8_t * const data = get_header_offset(m_offset_eapol_packet_body_length, sizeof(u16_t)); |
|
259 if (data != 0) |
|
260 { |
|
261 const u16_t eapol_length_u16_t = static_cast<u16_t>(eapol_length); |
|
262 return eap_write_u16_t_network_order(data, sizeof(u16_t), eapol_length_u16_t); |
|
263 } |
|
264 else |
|
265 { |
|
266 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
267 } |
|
268 } |
|
269 |
|
270 //------------------------------------------------------ |
|
271 |
|
272 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_key_descriptor_type(eapol_key_descriptor_type_e eapol_key_descriptor_type) |
|
273 { |
|
274 u8_t * const data = get_header_offset(m_offset_key_descriptor_type, sizeof(u8_t)); |
|
275 if (data != 0) |
|
276 { |
|
277 *data = static_cast<u8_t>(eapol_key_descriptor_type); |
|
278 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
279 } |
|
280 else |
|
281 { |
|
282 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
283 } |
|
284 } |
|
285 |
|
286 //------------------------------------------------------ |
|
287 |
|
288 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_key_length(u16_t length) |
|
289 { |
|
290 u8_t * const data = get_header_offset(m_offset_key_length, sizeof(u16_t)); |
|
291 if (data != 0) |
|
292 { |
|
293 return eap_write_u16_t_network_order(data, sizeof(u16_t), length); |
|
294 } |
|
295 else |
|
296 { |
|
297 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
298 } |
|
299 } |
|
300 |
|
301 //------------------------------------------------------ |
|
302 |
|
303 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_key_flag(eapol_RC4_key_flags_e flags) |
|
304 { |
|
305 u8_t * const data = get_header_offset(m_offset_key_index, sizeof(u8_t)); |
|
306 if (data != 0) |
|
307 { |
|
308 *data = ((*data) & ~m_flag_mask_key_flag) | static_cast<u8_t>((((flags << m_flag_shift_key_flag) & m_flag_mask_key_flag))); |
|
309 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
310 } |
|
311 else |
|
312 { |
|
313 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
314 } |
|
315 } |
|
316 |
|
317 //------------------------------------------------------ |
|
318 |
|
319 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::set_key_index(u8_t index) |
|
320 { |
|
321 u8_t * const data = get_header_offset(m_offset_key_index, sizeof(u8_t)); |
|
322 if (data != 0) |
|
323 { |
|
324 *data = ((*data) & m_flag_mask_key_flag) | static_cast<u8_t>((index & ~m_flag_mask_key_flag)); |
|
325 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
326 } |
|
327 else |
|
328 { |
|
329 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
330 } |
|
331 } |
|
332 |
|
333 |
|
334 //------------------------------------------------------ |
|
335 //------------------------------------------------------ |
|
336 //------------------------------------------------------ |
|
337 |
|
338 // |
|
339 EAP_FUNC_EXPORT void eapol_RC4_key_header_c::zero_key_signature( |
|
340 abs_eap_am_tools_c * const m_am_tools |
|
341 ) |
|
342 { |
|
343 u8_t * const signature = get_key_signature(); |
|
344 m_am_tools->memset(signature, 0, EAPOL_RC4_KEY_SIGNATURE_LENGTH); |
|
345 } |
|
346 |
|
347 //------------------------------------------------------ |
|
348 |
|
349 // |
|
350 EAP_FUNC_EXPORT eap_status_e eapol_RC4_key_header_c::check_header() const |
|
351 { |
|
352 if (get_eapol_protocol_version() == eapol_protocol_version_none) |
|
353 { |
|
354 return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_eapol_version); |
|
355 } |
|
356 else if (get_eapol_packet_type() > eapol_packet_type_enc_asf_alert) |
|
357 { |
|
358 return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_eapol_type); |
|
359 } |
|
360 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
361 } |
|
362 |
|
363 //------------------------------------------------------ |
|
364 //------------------------------------------------------ |
|
365 //------------------------------------------------------ |
|
366 |
|
367 |
|
368 |
|
369 // End. |