|
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 122 |
|
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_tools.h" |
|
30 #include "eap_array.h" |
|
31 #include "eap_array_algorithms.h" |
|
32 #include "tls_alert_message.h" |
|
33 #include "tls_record_header.h" |
|
34 #include "tls_peap_types.h" |
|
35 |
|
36 |
|
37 /** @file */ |
|
38 |
|
39 //-------------------------------------------------- |
|
40 |
|
41 EAP_FUNC_EXPORT tls_alert_message_c::~tls_alert_message_c() |
|
42 { |
|
43 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
44 |
|
45 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
46 } |
|
47 |
|
48 //-------------------------------------------------- |
|
49 |
|
50 EAP_FUNC_EXPORT tls_alert_message_c::tls_alert_message_c( |
|
51 abs_eap_am_tools_c * const tools, |
|
52 const bool is_client) |
|
53 : m_am_tools(tools) |
|
54 , m_tls_alert_message_buffer(tools) |
|
55 , m_alert_level(tls_alert_level_none) |
|
56 , m_alert_description(tls_alert_description_none) |
|
57 , m_is_client(is_client) |
|
58 , m_is_valid(false) |
|
59 { |
|
60 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
61 |
|
62 set_is_valid(); |
|
63 |
|
64 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
65 } |
|
66 |
|
67 //-------------------------------------------------- |
|
68 |
|
69 EAP_FUNC_EXPORT void tls_alert_message_c::set_is_valid() |
|
70 { |
|
71 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
72 |
|
73 m_is_valid = true; |
|
74 |
|
75 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
76 } |
|
77 |
|
78 //-------------------------------------------------- |
|
79 |
|
80 EAP_FUNC_EXPORT bool tls_alert_message_c::get_is_valid() |
|
81 { |
|
82 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
83 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
84 return m_is_valid; |
|
85 } |
|
86 |
|
87 //-------------------------------------------------- |
|
88 |
|
89 EAP_FUNC_EXPORT eap_status_e tls_alert_message_c::set_alert_level(const tls_alert_level_e alert_level) |
|
90 { |
|
91 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
92 |
|
93 m_alert_level = alert_level; |
|
94 |
|
95 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
96 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
97 } |
|
98 |
|
99 //-------------------------------------------------- |
|
100 |
|
101 EAP_FUNC_EXPORT tls_alert_level_e tls_alert_message_c::get_alert_level() const |
|
102 { |
|
103 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
104 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
105 return m_alert_level; |
|
106 } |
|
107 |
|
108 //-------------------------------------------------- |
|
109 |
|
110 EAP_FUNC_EXPORT eap_status_e tls_alert_message_c::set_alert_description(const tls_alert_description_e alert_description) |
|
111 { |
|
112 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
113 |
|
114 m_alert_description = alert_description; |
|
115 |
|
116 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
117 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
118 } |
|
119 |
|
120 //-------------------------------------------------- |
|
121 |
|
122 EAP_FUNC_EXPORT tls_alert_description_e tls_alert_message_c::get_alert_description() const |
|
123 { |
|
124 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
125 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
126 return m_alert_description; |
|
127 } |
|
128 |
|
129 |
|
130 //-------------------------------------------------- |
|
131 |
|
132 EAP_FUNC_EXPORT eap_status_e tls_alert_message_c::create_message_data() |
|
133 { |
|
134 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
135 |
|
136 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("\n"))); |
|
137 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("TLS: %s: data_function: tls_alert_description_e::create_message_data()\n"), |
|
138 (m_is_client == true ? "client": "server"))); |
|
139 |
|
140 eap_status_e status = eap_status_not_supported; |
|
141 |
|
142 m_tls_alert_message_buffer.reset(); |
|
143 status = m_tls_alert_message_buffer.set_buffer_length(TLS_PEAP_DEFAULT_RECORD_LENGTH); |
|
144 if (status != eap_status_ok) |
|
145 { |
|
146 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
147 return EAP_STATUS_RETURN(m_am_tools, status); |
|
148 } |
|
149 |
|
150 u32_t alert_data_length_start = m_tls_alert_message_buffer.get_data_length(); |
|
151 |
|
152 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
153 |
|
154 { |
|
155 u8_t alert_level = static_cast<u8_t>(m_alert_level); |
|
156 |
|
157 status = m_tls_alert_message_buffer.add_data( |
|
158 &alert_level, |
|
159 sizeof(alert_level)); |
|
160 if (status != eap_status_ok) |
|
161 { |
|
162 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
163 return EAP_STATUS_RETURN(m_am_tools, status); |
|
164 } |
|
165 |
|
166 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("TLS-alert alert_level"), |
|
167 &alert_level, |
|
168 sizeof(alert_level))); |
|
169 } |
|
170 |
|
171 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
172 |
|
173 { |
|
174 u8_t alert_description = static_cast<u8_t>(m_alert_description); |
|
175 |
|
176 status = m_tls_alert_message_buffer.add_data( |
|
177 &alert_description, |
|
178 sizeof(alert_description)); |
|
179 if (status != eap_status_ok) |
|
180 { |
|
181 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
182 return EAP_STATUS_RETURN(m_am_tools, status); |
|
183 } |
|
184 |
|
185 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("TLS-alert alert_description"), |
|
186 &alert_description, |
|
187 sizeof(alert_description))); |
|
188 } |
|
189 |
|
190 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
191 |
|
192 if (status == eap_status_ok) |
|
193 { |
|
194 u32_t alert_data_length = m_tls_alert_message_buffer.get_data_length() - alert_data_length_start; |
|
195 EAP_UNREFERENCED_PARAMETER(alert_data_length); // in release |
|
196 EAP_TRACE_DEBUG( |
|
197 m_am_tools, |
|
198 TRACE_FLAGS_DEFAULT, |
|
199 (EAPL("alert length %d bytes.\n"), |
|
200 alert_data_length)); |
|
201 } |
|
202 |
|
203 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
204 return EAP_STATUS_RETURN(m_am_tools, status); |
|
205 } |
|
206 |
|
207 //-------------------------------------------------- |
|
208 |
|
209 EAP_FUNC_EXPORT eap_status_e tls_alert_message_c::add_message_data( |
|
210 eap_variable_data_c * const tls_message_buffer) |
|
211 { |
|
212 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
213 |
|
214 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("\n"))); |
|
215 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("TLS: %s: data_function: tls_alert_message_c::add_message_data()\n"), |
|
216 (m_is_client == true ? "client": "server"))); |
|
217 |
|
218 eap_status_e status = eap_status_not_supported; |
|
219 |
|
220 if (m_tls_alert_message_buffer.get_is_valid() == false) |
|
221 { |
|
222 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
223 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_payload); |
|
224 } |
|
225 |
|
226 status = tls_message_buffer->add_data( |
|
227 m_tls_alert_message_buffer.get_data(m_tls_alert_message_buffer.get_data_length()), |
|
228 m_tls_alert_message_buffer.get_data_length()); |
|
229 if (status != eap_status_ok) |
|
230 { |
|
231 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
232 return EAP_STATUS_RETURN(m_am_tools, status); |
|
233 } |
|
234 |
|
235 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
236 return EAP_STATUS_RETURN(m_am_tools, status); |
|
237 } |
|
238 |
|
239 //-------------------------------------------------- |
|
240 |
|
241 |
|
242 |
|
243 // End. |