|
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 |
|
20 #if defined(USE_EAP_TLS_SESSION_TICKET) |
|
21 |
|
22 #include "tls_extension.h" |
|
23 |
|
24 /** @file */ |
|
25 |
|
26 //---------------------------------------------------------------------------- |
|
27 |
|
28 EAP_FUNC_EXPORT void tls_extension_c::set_is_valid() |
|
29 { |
|
30 m_is_valid = true; |
|
31 } |
|
32 |
|
33 //---------------------------------------------------------------------------- |
|
34 |
|
35 EAP_FUNC_EXPORT tls_extension_c::~tls_extension_c() |
|
36 { |
|
37 } |
|
38 |
|
39 //---------------------------------------------------------------------------- |
|
40 |
|
41 EAP_FUNC_EXPORT tls_extension_c::tls_extension_c( |
|
42 abs_eap_am_tools_c * const tools) |
|
43 : eap_variable_data_c(tools) |
|
44 , m_am_tools(tools) |
|
45 , m_lifetime_hint(0ul) |
|
46 , m_type(tls_extension_type_none) |
|
47 #if defined(USE_FAST_EAP_TYPE) |
|
48 , m_pac_type(eap_fast_pac_type_none) |
|
49 #endif //#if defined(USE_FAST_EAP_TYPE) |
|
50 , m_is_valid(false) |
|
51 { |
|
52 if (eap_variable_data_c::get_is_valid() == false) |
|
53 { |
|
54 return; |
|
55 } |
|
56 |
|
57 set_is_valid(); |
|
58 } |
|
59 |
|
60 //---------------------------------------------------------------------------- |
|
61 |
|
62 tls_extension_c * tls_extension_c::copy() const |
|
63 { |
|
64 tls_extension_c * const copy_object = new tls_extension_c(m_am_tools); |
|
65 |
|
66 if (copy_object == 0 |
|
67 || copy_object->get_is_valid() == false) |
|
68 { |
|
69 delete copy_object; |
|
70 return 0; |
|
71 } |
|
72 |
|
73 copy_object->set_type(get_type()); |
|
74 |
|
75 #if defined(USE_FAST_EAP_TYPE) |
|
76 copy_object->set_pac_type(get_pac_type()); |
|
77 #endif //#if defined(USE_FAST_EAP_TYPE) |
|
78 |
|
79 eap_status_e status = copy_object->set_copy_of_buffer(this); |
|
80 |
|
81 if (status != eap_status_ok) |
|
82 { |
|
83 delete copy_object; |
|
84 return 0; |
|
85 } |
|
86 |
|
87 return copy_object; |
|
88 } |
|
89 |
|
90 //---------------------------------------------------------------------------- |
|
91 |
|
92 EAP_FUNC_EXPORT bool tls_extension_c::get_is_valid() |
|
93 { |
|
94 return m_is_valid; |
|
95 } |
|
96 |
|
97 //---------------------------------------------------------------------------- |
|
98 |
|
99 EAP_FUNC_EXPORT void tls_extension_c::set_lifetime_hint(const u32_t lifetime_hint) |
|
100 { |
|
101 m_lifetime_hint = lifetime_hint; |
|
102 } |
|
103 |
|
104 //---------------------------------------------------------------------------- |
|
105 |
|
106 EAP_FUNC_EXPORT u32_t tls_extension_c::get_lifetime_hint() const |
|
107 { |
|
108 return m_lifetime_hint; |
|
109 } |
|
110 |
|
111 //---------------------------------------------------------------------------- |
|
112 |
|
113 EAP_FUNC_EXPORT void tls_extension_c::set_type(const tls_extension_type_e type) |
|
114 { |
|
115 m_type = type; |
|
116 } |
|
117 |
|
118 //---------------------------------------------------------------------------- |
|
119 |
|
120 EAP_FUNC_EXPORT tls_extension_type_e tls_extension_c::get_type() const |
|
121 { |
|
122 return m_type; |
|
123 } |
|
124 |
|
125 //---------------------------------------------------------------------------- |
|
126 |
|
127 #if defined(USE_FAST_EAP_TYPE) |
|
128 |
|
129 EAP_FUNC_EXPORT void tls_extension_c::set_pac_type(const eap_fast_pac_type_e pac_type) |
|
130 { |
|
131 m_pac_type = pac_type; |
|
132 } |
|
133 |
|
134 #endif //#if defined(USE_FAST_EAP_TYPE) |
|
135 |
|
136 //---------------------------------------------------------------------------- |
|
137 |
|
138 #if defined(USE_FAST_EAP_TYPE) |
|
139 |
|
140 EAP_FUNC_EXPORT eap_fast_pac_type_e tls_extension_c::get_pac_type() const |
|
141 { |
|
142 return m_pac_type; |
|
143 } |
|
144 |
|
145 #endif //#if defined(USE_FAST_EAP_TYPE) |
|
146 |
|
147 //---------------------------------------------------------------------------- |
|
148 |
|
149 EAP_FUNC_EXPORT eap_const_string tls_extension_c::get_type_string(tls_extension_type_e type) |
|
150 { |
|
151 #if defined(USE_EAP_TRACE_STRINGS) |
|
152 EAP_IF_RETURN_STRING(type, tls_extension_type_none) |
|
153 else EAP_IF_RETURN_STRING(type, tls_extension_type_server_name) |
|
154 else EAP_IF_RETURN_STRING(type, tls_extension_type_max_frame_length) |
|
155 else EAP_IF_RETURN_STRING(type, tls_extension_type_client_certificate_url) |
|
156 else EAP_IF_RETURN_STRING(type, tls_extension_type_trusted_ca_keys) |
|
157 else EAP_IF_RETURN_STRING(type, tls_extension_type_truncated_hmac) |
|
158 else EAP_IF_RETURN_STRING(type, tls_extension_type_status_request) |
|
159 else EAP_IF_RETURN_STRING(type, tls_extension_type_session_ticket) |
|
160 else |
|
161 #endif // #if defined(USE_EAP_TRACE_STRINGS) |
|
162 { |
|
163 EAP_UNREFERENCED_PARAMETER(type); |
|
164 return EAPL("Unknown TLS extension type"); |
|
165 } |
|
166 } |
|
167 |
|
168 //---------------------------------------------------------------------------- |
|
169 |
|
170 const tls_extension_c * tls_extension_c::get_tls_extension( |
|
171 const tls_extension_type_e tls_extension_type, |
|
172 EAP_TEMPLATE_CONST eap_array_c<tls_extension_c> * const tls_extensions, |
|
173 abs_eap_am_tools_c * const am_tools) |
|
174 { |
|
175 if (tls_extensions == 0) |
|
176 { |
|
177 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
178 (void) EAP_STATUS_RETURN(am_tools, eap_status_not_found); |
|
179 return 0; |
|
180 } |
|
181 |
|
182 for (u32_t ind = 0ul; ind < tls_extensions->get_object_count(); ++ind) |
|
183 { |
|
184 const tls_extension_c * extension = tls_extensions->get_object(ind); |
|
185 |
|
186 if (extension == 0) |
|
187 { |
|
188 (void) EAP_STATUS_RETURN(am_tools, eap_status_not_found); |
|
189 return 0; |
|
190 } |
|
191 |
|
192 if (extension->get_type() == tls_extension_type) |
|
193 { |
|
194 return extension; |
|
195 } |
|
196 } // for() |
|
197 |
|
198 (void) EAP_STATUS_RETURN(am_tools, eap_status_not_found); |
|
199 return 0; |
|
200 } |
|
201 |
|
202 //---------------------------------------------------------------------------- |
|
203 |
|
204 #if defined(USE_FAST_EAP_TYPE) |
|
205 |
|
206 const tls_extension_c * tls_extension_c::get_tls_extension( |
|
207 const tls_extension_type_e tls_extension_type, |
|
208 const eap_fast_pac_type_e pac_type, |
|
209 EAP_TEMPLATE_CONST eap_array_c<tls_extension_c> * const tls_extensions, |
|
210 abs_eap_am_tools_c * const am_tools) |
|
211 { |
|
212 if (tls_extensions == 0) |
|
213 { |
|
214 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
215 (void) EAP_STATUS_RETURN(am_tools, eap_status_not_found); |
|
216 return 0; |
|
217 } |
|
218 |
|
219 for (u32_t ind = 0ul; ind < tls_extensions->get_object_count(); ++ind) |
|
220 { |
|
221 const tls_extension_c * extension = tls_extensions->get_object(ind); |
|
222 |
|
223 if (extension == 0) |
|
224 { |
|
225 (void) EAP_STATUS_RETURN(am_tools, eap_status_not_found); |
|
226 return 0; |
|
227 } |
|
228 |
|
229 if (extension->get_type() == tls_extension_type) |
|
230 { |
|
231 if (pac_type == eap_fast_pac_type_none |
|
232 || pac_type == extension->get_pac_type()) |
|
233 { |
|
234 return extension; |
|
235 } |
|
236 } |
|
237 } // for() |
|
238 |
|
239 (void) EAP_STATUS_RETURN(am_tools, eap_status_not_found); |
|
240 return 0; |
|
241 } |
|
242 |
|
243 #endif //#if defined(USE_FAST_EAP_TYPE) |
|
244 |
|
245 //---------------------------------------------------------------------------- |
|
246 |
|
247 #endif // #if defined(USE_EAP_TLS_SESSION_TICKET) |
|
248 |
|
249 // End. |