|
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 264 |
|
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 // INCLUDE FILES |
|
29 |
|
30 #include <coemain.h> |
|
31 #include <bautils.h> |
|
32 #include <barsc.h> |
|
33 #include "eap_am_memory.h" |
|
34 #include "eap_tools.h" |
|
35 #include "eap_am_type_mschapv2_symbian.h" |
|
36 #include "EapMsChapV2DbParameterNames.h" |
|
37 #include "EapMsChapV2DbDefaults.h" |
|
38 #include "EapMsChapV2DbUtils.h" |
|
39 #include "EapMsChapV2NotifierUids.h" |
|
40 #include "eap_state_notification.h" |
|
41 |
|
42 #include "eap_am_trace_symbian.h" |
|
43 |
|
44 const TUint KMaxSqlQueryLength = 256; |
|
45 const TUint KMaxDBFieldNameLength = 255; |
|
46 const char EAP_MSCHAPV2_CREDENTIAL_HANDLE_KEY[] = "eap_type_mschapv2_c credential_store"; |
|
47 const TInt KDefaultColumnInView_One = 1; // For DB view. |
|
48 const TInt KMicroSecsInASecond = 1000000; // 1000000 micro seconds is 1 second. |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 EAP_FUNC_EXPORT eap_am_type_mschapv2_symbian_c::~eap_am_type_mschapv2_symbian_c() |
|
53 { |
|
54 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
55 |
|
56 EAP_TRACE_DEBUG( |
|
57 m_am_tools, |
|
58 TRACE_FLAGS_DEFAULT, |
|
59 (EAPL("eap_am_type_mschapv2_symbian_c::~eap_am_type_mschapv2_symbian_c(): this = 0x%08x\n"), |
|
60 this)); |
|
61 |
|
62 EAP_ASSERT(m_shutdown_was_called == true); |
|
63 |
|
64 m_database.Close(); |
|
65 m_session.Close(); |
|
66 |
|
67 delete m_username_password_io_ptr; |
|
68 delete m_username_password_io_pckg_ptr; |
|
69 |
|
70 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
71 } |
|
72 |
|
73 //-------------------------------------------------- |
|
74 |
|
75 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::shutdown() |
|
76 { |
|
77 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
78 |
|
79 EAP_TRACE_DEBUG( |
|
80 m_am_tools, |
|
81 TRACE_FLAGS_DEFAULT, |
|
82 (EAPL("eap_am_type_mschapv2_symbian_c::shutdown(): this = 0x%08x\n"), |
|
83 this)); |
|
84 |
|
85 if( IsActive() ) |
|
86 { |
|
87 Cancel(); // Cancel only if active. |
|
88 } |
|
89 else |
|
90 { |
|
91 if( m_is_notifier_connected ) |
|
92 { |
|
93 |
|
94 EAP_TRACE_DEBUG( |
|
95 m_am_tools, |
|
96 TRACE_FLAGS_DEFAULT, |
|
97 (EAPL("eap_am_type_mschapv2_symbian_c::shutdown - calling m_notifier.CancelNotifier(..)\n"))); |
|
98 |
|
99 TInt error = KErrNone; |
|
100 EAP_UNREFERENCED_PARAMETER(error); |
|
101 error = m_notifier.CancelNotifier(KEapMsChapV2UsernamePasswordUid); |
|
102 |
|
103 EAP_TRACE_DEBUG( |
|
104 m_am_tools, |
|
105 TRACE_FLAGS_DEFAULT, |
|
106 (EAPL("eap_am_type_mschapv2_symbian_c::shutdown - calling m_notifier.Close(), prev error=%d\n"), |
|
107 error)); |
|
108 |
|
109 m_notifier.Close(); // Call close only if it is connected. |
|
110 |
|
111 m_is_notifier_connected = false; |
|
112 } |
|
113 } |
|
114 |
|
115 m_shutdown_was_called = true; |
|
116 |
|
117 EAP_TRACE_DEBUG( |
|
118 m_am_tools, |
|
119 TRACE_FLAGS_DEFAULT, |
|
120 (EAPL("eap_am_type_mschapv2_symbian_c::shutdown(): this = 0x%08x returns\n"), |
|
121 this)); |
|
122 |
|
123 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
124 return eap_status_ok; |
|
125 } |
|
126 |
|
127 //-------------------------------------------------- |
|
128 |
|
129 eap_am_type_mschapv2_symbian_c::eap_am_type_mschapv2_symbian_c( |
|
130 abs_eap_am_tools_c * const tools, |
|
131 abs_eap_base_type_c * const partner, |
|
132 const TIndexType aIndexType, |
|
133 const TInt aIndex, |
|
134 const eap_type_value_e aTunnelingType, |
|
135 const bool aIsClient, |
|
136 const eap_am_network_id_c * const receive_network_id) |
|
137 : CActive(CActive::EPriorityStandard) |
|
138 , eap_am_type_mschapv2_c(tools /*, partner */) |
|
139 , m_am_tools(static_cast<eap_am_tools_symbian_c *> (tools)) |
|
140 , m_partner(partner) |
|
141 , m_state(EHandlingUsernamePasswordQuery) |
|
142 , m_username_utf8(0) |
|
143 , m_password_utf8(0) |
|
144 , m_old_password_utf8(0) |
|
145 , m_password_prompt_enabled(0) |
|
146 , m_is_identity_query(false) |
|
147 , m_username_password_io_ptr(0) |
|
148 , m_username_password_io_pckg_ptr(0) |
|
149 , m_receive_network_id(tools) |
|
150 , m_index_type(aIndexType) |
|
151 , m_index(aIndex) |
|
152 , m_tunneling_type(aTunnelingType) |
|
153 , m_is_client(aIsClient) |
|
154 , m_is_valid(false) |
|
155 , m_shutdown_was_called(false) |
|
156 , m_is_notifier_connected(false) |
|
157 , m_max_session_time(0) |
|
158 { |
|
159 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
160 |
|
161 #ifdef USE_EAP_EXPANDED_TYPES |
|
162 |
|
163 m_tunneling_vendor_type = m_tunneling_type.get_vendor_type(); |
|
164 |
|
165 #else |
|
166 |
|
167 m_tunneling_vendor_type = static_cast<TUint>(m_tunneling_type); |
|
168 |
|
169 #endif //#ifdef USE_EAP_EXPANDED_TYPES |
|
170 |
|
171 if (receive_network_id != 0 |
|
172 && receive_network_id->get_is_valid_data() == true) |
|
173 { |
|
174 eap_status_e status = m_receive_network_id.set_copy_of_network_id( |
|
175 receive_network_id); |
|
176 if (status != eap_status_ok) |
|
177 { |
|
178 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
179 (void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
180 return; |
|
181 } |
|
182 } |
|
183 |
|
184 set_is_valid(); |
|
185 |
|
186 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
187 } |
|
188 |
|
189 //-------------------------------------------------- |
|
190 |
|
191 eap_am_type_mschapv2_symbian_c * eap_am_type_mschapv2_symbian_c::NewL( |
|
192 abs_eap_am_tools_c * const aTools, |
|
193 abs_eap_base_type_c * const aPartner, |
|
194 const TIndexType aIndexType, |
|
195 const TInt aIndex, |
|
196 const eap_type_value_e aTunnelingType, |
|
197 const bool aIsClient, |
|
198 const eap_am_network_id_c * const receive_network_id) |
|
199 { |
|
200 eap_am_type_mschapv2_symbian_c * self; |
|
201 |
|
202 self = new(ELeave) eap_am_type_mschapv2_symbian_c( |
|
203 aTools, |
|
204 aPartner, |
|
205 aIndexType, |
|
206 aIndex, |
|
207 aTunnelingType, |
|
208 aIsClient, |
|
209 receive_network_id); |
|
210 |
|
211 CleanupStack::PushL(self); |
|
212 |
|
213 if (self->get_is_valid() != true) |
|
214 { |
|
215 User::Leave(KErrGeneral); |
|
216 } |
|
217 |
|
218 self->ConstructL(); |
|
219 |
|
220 CleanupStack::Pop(); |
|
221 |
|
222 return self; |
|
223 } |
|
224 |
|
225 void eap_am_type_mschapv2_symbian_c::ConstructL() |
|
226 { |
|
227 // NOTE: Do not use m_partner here without null check |
|
228 |
|
229 // Open/create the database |
|
230 EapMsChapV2DbUtils::OpenDatabaseL(m_database, m_session, m_index_type, m_index, m_tunneling_type); |
|
231 |
|
232 m_username_password_io_ptr = new(ELeave) TEapMsChapV2UsernamePasswordInfo; |
|
233 m_username_password_io_pckg_ptr = new(ELeave) TPckg<TEapMsChapV2UsernamePasswordInfo> (*m_username_password_io_ptr); |
|
234 |
|
235 CActiveScheduler::Add(this); |
|
236 |
|
237 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
238 } |
|
239 |
|
240 //-------------------------------------------------- |
|
241 |
|
242 EAP_FUNC_EXPORT void eap_am_type_mschapv2_symbian_c::set_is_valid() |
|
243 { |
|
244 m_is_valid = true; |
|
245 } |
|
246 |
|
247 //-------------------------------------------------- |
|
248 |
|
249 EAP_FUNC_EXPORT bool eap_am_type_mschapv2_symbian_c::get_is_valid() |
|
250 { |
|
251 return m_is_valid; |
|
252 } |
|
253 |
|
254 //-------------------------------------------------- |
|
255 |
|
256 void eap_am_type_mschapv2_symbian_c::send_error_notification(const eap_status_e error) |
|
257 { |
|
258 eap_general_state_variable_e general_state_variable(eap_general_state_authentication_error); |
|
259 |
|
260 if (error == eap_status_user_cancel_authentication) |
|
261 { |
|
262 general_state_variable = eap_general_state_authentication_cancelled; |
|
263 } |
|
264 // Here we swap the addresses. |
|
265 eap_am_network_id_c send_network_id(m_am_tools, |
|
266 m_receive_network_id.get_destination_id(), |
|
267 m_receive_network_id.get_source_id(), |
|
268 m_receive_network_id.get_type()); |
|
269 |
|
270 // Notifies the lower level of an authentication error. |
|
271 eap_state_notification_c notification( |
|
272 m_am_tools, |
|
273 &send_network_id, |
|
274 m_is_client, |
|
275 eap_state_notification_eap, |
|
276 eap_protocol_layer_general, |
|
277 eap_type_mschapv2, |
|
278 eap_state_none, |
|
279 general_state_variable, |
|
280 0, |
|
281 false); |
|
282 |
|
283 notification.set_authentication_error(error); |
|
284 |
|
285 m_partner->state_notification(¬ification); |
|
286 } |
|
287 |
|
288 //-------------------------------------------------- |
|
289 |
|
290 void eap_am_type_mschapv2_symbian_c::RunL() |
|
291 { |
|
292 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
293 |
|
294 EAP_TRACE_DEBUG( |
|
295 m_am_tools, |
|
296 TRACE_FLAGS_DEFAULT, |
|
297 (EAPL("eap_am_type_mschapv2_symbian_c::RunL - start") |
|
298 EAPL("m_state, iStatus.Int()=%d\n"), |
|
299 m_state, iStatus.Int())); |
|
300 |
|
301 if (iStatus.Int() == KErrCancel) |
|
302 { |
|
303 EAP_TRACE_DEBUG( |
|
304 m_am_tools, |
|
305 TRACE_FLAGS_DEFAULT, |
|
306 (EAPL("eap_am_type_mschapv2_symbian_c::RunL - User seems to have cancelled the prompt. Stop Immediately.\n"))); |
|
307 |
|
308 // User cancelled the password prompt. Stop everything. |
|
309 // Appropriate error notification is sent from finish_unsuccessful_authentication. |
|
310 get_am_partner()->finish_unsuccessful_authentication(true); |
|
311 |
|
312 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
313 return; |
|
314 } |
|
315 |
|
316 if (iStatus.Int() != KErrNone) |
|
317 { |
|
318 // Something is very wrong... |
|
319 EAP_TRACE_ERROR( |
|
320 m_am_tools, |
|
321 TRACE_FLAGS_DEFAULT, |
|
322 (EAPL("ERROR: EAP - MS-Chap-V2 notifier or dialog, iStatus.Int()=%d\n"), iStatus.Int())); |
|
323 |
|
324 send_error_notification(eap_status_authentication_failure); |
|
325 |
|
326 get_am_partner()->finish_unsuccessful_authentication(false); |
|
327 |
|
328 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
329 return; |
|
330 } |
|
331 |
|
332 eap_status_e status(eap_status_ok); |
|
333 |
|
334 switch (m_state) |
|
335 { |
|
336 case EHandlingUsernamePasswordQuery: |
|
337 { |
|
338 if (m_username_password_io_ptr->iPasswordPromptEnabled) |
|
339 { |
|
340 *m_password_prompt_enabled = true; |
|
341 } |
|
342 else |
|
343 { |
|
344 *m_password_prompt_enabled = false; |
|
345 } |
|
346 |
|
347 { |
|
348 eap_variable_data_c tmp_username_unicode( |
|
349 m_am_tools); |
|
350 |
|
351 status = tmp_username_unicode.set_buffer( |
|
352 m_username_password_io_ptr->iUsername.Ptr(), |
|
353 m_username_password_io_ptr->iUsername.Size(), |
|
354 false, |
|
355 false); |
|
356 if (status != eap_status_ok) |
|
357 { |
|
358 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
359 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
360 return; |
|
361 } |
|
362 |
|
363 eap_variable_data_c tmp_username_utf8(m_am_tools); |
|
364 status = m_am_tools->convert_unicode_to_utf8(tmp_username_utf8, tmp_username_unicode); |
|
365 if (status != eap_status_ok) |
|
366 { |
|
367 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
368 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
369 return; |
|
370 } |
|
371 |
|
372 status = m_username_utf8->set_copy_of_buffer(&tmp_username_utf8); |
|
373 if (status != eap_status_ok) |
|
374 { |
|
375 get_am_partner()->finish_unsuccessful_authentication(false); |
|
376 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
377 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
378 return; |
|
379 } |
|
380 } |
|
381 |
|
382 { |
|
383 eap_variable_data_c tmp_password_unicode( |
|
384 m_am_tools); |
|
385 |
|
386 status = tmp_password_unicode.set_buffer( |
|
387 m_username_password_io_ptr->iPassword.Ptr(), |
|
388 m_username_password_io_ptr->iPassword.Size(), |
|
389 false, |
|
390 false); |
|
391 if (status != eap_status_ok) |
|
392 { |
|
393 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
394 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
395 return; |
|
396 } |
|
397 |
|
398 eap_variable_data_c tmp_password_utf8(m_am_tools); |
|
399 status = m_am_tools->convert_unicode_to_utf8(tmp_password_utf8, tmp_password_unicode); |
|
400 if (status != eap_status_ok) |
|
401 { |
|
402 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
403 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
404 return; |
|
405 } |
|
406 |
|
407 status = m_password_utf8->set_copy_of_buffer(&tmp_password_utf8); |
|
408 if (status != eap_status_ok) |
|
409 { |
|
410 get_am_partner()->finish_unsuccessful_authentication(false); |
|
411 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
412 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
413 return; |
|
414 } |
|
415 } |
|
416 |
|
417 // Store username and/or password if "Prompt for username" is enabled |
|
418 status = update_username_password(); |
|
419 if (status != eap_status_ok) |
|
420 { |
|
421 get_am_partner()->finish_unsuccessful_authentication(false); |
|
422 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
423 return; |
|
424 } |
|
425 |
|
426 if (m_is_identity_query) |
|
427 { |
|
428 status = get_am_partner()->complete_eap_identity_query(); |
|
429 } |
|
430 else |
|
431 { |
|
432 status = get_am_partner()->complete_failure_retry_response(); |
|
433 } |
|
434 } |
|
435 break; |
|
436 |
|
437 case EHandlingChangePasswordQuery: |
|
438 { |
|
439 { |
|
440 eap_variable_data_c tmp_password_unicode( |
|
441 m_am_tools); |
|
442 |
|
443 status = tmp_password_unicode.set_buffer( |
|
444 m_username_password_io_ptr->iPassword.Ptr(), |
|
445 m_username_password_io_ptr->iPassword.Size(), |
|
446 false, |
|
447 false); |
|
448 if (status != eap_status_ok) |
|
449 { |
|
450 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
451 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
452 return; |
|
453 } |
|
454 |
|
455 eap_variable_data_c tmp_password_utf8(m_am_tools); |
|
456 status = m_am_tools->convert_unicode_to_utf8(tmp_password_utf8, tmp_password_unicode); |
|
457 if (status != eap_status_ok) |
|
458 { |
|
459 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
460 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
461 return; |
|
462 } |
|
463 |
|
464 eap_status_e status = m_password_utf8->set_copy_of_buffer(&tmp_password_utf8); |
|
465 if (status != eap_status_ok) |
|
466 { |
|
467 get_am_partner()->finish_unsuccessful_authentication(false); |
|
468 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
469 return; |
|
470 } |
|
471 } |
|
472 |
|
473 { |
|
474 eap_variable_data_c tmp_old_password_unicode( |
|
475 m_am_tools); |
|
476 |
|
477 status = tmp_old_password_unicode.set_buffer( |
|
478 m_username_password_io_ptr->iOldPassword.Ptr(), |
|
479 m_username_password_io_ptr->iOldPassword.Size(), |
|
480 false, |
|
481 false); |
|
482 if (status != eap_status_ok) |
|
483 { |
|
484 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
485 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
486 return; |
|
487 } |
|
488 |
|
489 eap_variable_data_c tmp_old_password_utf8(m_am_tools); |
|
490 status = m_am_tools->convert_unicode_to_utf8(tmp_old_password_utf8, tmp_old_password_unicode); |
|
491 if (status != eap_status_ok) |
|
492 { |
|
493 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
494 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
495 return; |
|
496 } |
|
497 |
|
498 status = m_old_password_utf8->set_copy_of_buffer(&tmp_old_password_utf8); |
|
499 if (status != eap_status_ok) |
|
500 { |
|
501 get_am_partner()->finish_unsuccessful_authentication(false); |
|
502 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
503 return; |
|
504 } |
|
505 } |
|
506 |
|
507 status = get_am_partner()->complete_change_password_query(); |
|
508 } |
|
509 break; |
|
510 |
|
511 default: |
|
512 EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EAP - MS-Chap-V2 illegal state in RunL.\n"))); |
|
513 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
514 return; |
|
515 } |
|
516 |
|
517 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
518 } |
|
519 |
|
520 //-------------------------------------------------- |
|
521 |
|
522 void eap_am_type_mschapv2_symbian_c::DoCancel() |
|
523 { |
|
524 if( m_is_notifier_connected ) |
|
525 { |
|
526 EAP_TRACE_DEBUG( |
|
527 m_am_tools, |
|
528 TRACE_FLAGS_DEFAULT, |
|
529 (EAPL("eap_am_type_mschapv2_symbian_c::DoCancel - calling m_notifier.CancelNotifier(..)\n"))); |
|
530 |
|
531 TInt error = KErrNone; |
|
532 EAP_UNREFERENCED_PARAMETER(error); |
|
533 error = m_notifier.CancelNotifier(KEapMsChapV2UsernamePasswordUid); |
|
534 |
|
535 EAP_TRACE_DEBUG( |
|
536 m_am_tools, |
|
537 TRACE_FLAGS_DEFAULT, |
|
538 (EAPL("eap_am_type_mschapv2_symbian_c::DoCancel - calling m_notifier.Close(), prev error=%d\n"), |
|
539 error)); |
|
540 |
|
541 m_notifier.Close(); // Call close only if it is connected. |
|
542 |
|
543 m_is_notifier_connected = false; |
|
544 } |
|
545 } |
|
546 |
|
547 //-------------------------------------------------- |
|
548 |
|
549 |
|
550 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::type_configure_read( |
|
551 const eap_configuration_field_c * const field, |
|
552 eap_variable_data_c * const data) |
|
553 { |
|
554 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
555 EAP_ASSERT(data != 0); |
|
556 // Trap must be set here because the OS independent portion of EAP MSCHAPV2 |
|
557 // that calls this function does not know anything about Symbian. |
|
558 eap_status_e status(eap_status_ok); |
|
559 TRAPD(err, type_configure_readL( |
|
560 field->get_field(), |
|
561 field->get_field_length(), |
|
562 data)); |
|
563 if (err != KErrNone) |
|
564 { |
|
565 status = m_am_tools->convert_am_error_to_eapol_error(err); |
|
566 |
|
567 // Read is routed to partner object. |
|
568 status = m_partner->read_configure( |
|
569 field, |
|
570 data); |
|
571 } |
|
572 |
|
573 m_am_tools->trace_configuration( |
|
574 status, |
|
575 field, |
|
576 data); |
|
577 |
|
578 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
579 return EAP_STATUS_RETURN(m_am_tools, status); |
|
580 } |
|
581 |
|
582 //-------------------------------------------------- |
|
583 |
|
584 void eap_am_type_mschapv2_symbian_c::type_configure_readL( |
|
585 eap_config_string field, |
|
586 const u32_t field_length, |
|
587 eap_variable_data_c * const data) |
|
588 { |
|
589 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
590 EAP_UNREFERENCED_PARAMETER(field_length); |
|
591 |
|
592 // Create a buffer for the ascii strings - initialised with the argument |
|
593 HBufC16* unicodeBuf = HBufC16::NewLC(KMaxDBFieldNameLength); |
|
594 TPtr16 unicodeString = unicodeBuf->Des(); |
|
595 |
|
596 TPtrC8 fieldPtr(reinterpret_cast<const TUint8 *> (field), field_length); |
|
597 |
|
598 unicodeString.Copy(fieldPtr); |
|
599 |
|
600 // Now do the database query |
|
601 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
602 TPtr sqlStatement = buf->Des(); |
|
603 |
|
604 _LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
605 sqlStatement.Format(KSQLQueryRow, |
|
606 &unicodeString, |
|
607 &KMsChapV2TableName, |
|
608 &KServiceType, |
|
609 m_index_type, |
|
610 &KServiceIndex, |
|
611 m_index, |
|
612 &KTunnelingType, |
|
613 m_tunneling_vendor_type); |
|
614 |
|
615 RDbView view; |
|
616 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
617 CleanupClosePushL(view); |
|
618 User::LeaveIfError(view.EvaluateAll()); |
|
619 |
|
620 if (view.FirstL()) |
|
621 { |
|
622 eap_status_e status = eap_status_ok; |
|
623 view.GetL(); |
|
624 |
|
625 switch (view.ColType(KDefaultColumnInView_One)) |
|
626 { |
|
627 case EDbColText: |
|
628 { |
|
629 if (view.ColLength(KDefaultColumnInView_One) > 0) |
|
630 { |
|
631 TPtrC16 value = view.ColDes16(KDefaultColumnInView_One); |
|
632 |
|
633 eap_variable_data_c string_unicode(m_am_tools); |
|
634 |
|
635 status = string_unicode.set_copy_of_buffer(value.Ptr(), value.Size()); |
|
636 if (status != eap_status_ok) |
|
637 { |
|
638 User::Leave( |
|
639 m_am_tools->convert_eapol_error_to_am_error( |
|
640 EAP_STATUS_RETURN(m_am_tools, status))); |
|
641 } |
|
642 |
|
643 status = m_am_tools->convert_unicode_to_utf8( |
|
644 *data, |
|
645 string_unicode); |
|
646 if (status != eap_status_ok) |
|
647 { |
|
648 User::Leave( |
|
649 m_am_tools->convert_eapol_error_to_am_error( |
|
650 EAP_STATUS_RETURN(m_am_tools, status))); |
|
651 } |
|
652 } |
|
653 else |
|
654 { |
|
655 data->reset(); |
|
656 status = data->set_copy_of_buffer("", 0); |
|
657 if (status != eap_status_ok) |
|
658 { |
|
659 User::Leave( |
|
660 m_am_tools->convert_eapol_error_to_am_error( |
|
661 EAP_STATUS_RETURN(m_am_tools, status))); |
|
662 } |
|
663 } |
|
664 } |
|
665 break; |
|
666 |
|
667 case EDbColUint32: |
|
668 { |
|
669 TUint value = view.ColUint32(KDefaultColumnInView_One); |
|
670 status = data->set_copy_of_buffer(reinterpret_cast<unsigned char *> (&value), sizeof(value)); |
|
671 if (status != eap_status_ok) |
|
672 { |
|
673 User::Leave( |
|
674 m_am_tools->convert_eapol_error_to_am_error( |
|
675 EAP_STATUS_RETURN(m_am_tools, status))); |
|
676 } |
|
677 } |
|
678 break; |
|
679 |
|
680 default: |
|
681 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("type_configure_readL: Unexpected column type.\n"))); |
|
682 User::Leave(KErrGeneral); |
|
683 break; |
|
684 } |
|
685 } |
|
686 else |
|
687 { |
|
688 // Could not find parameter |
|
689 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("type_configure_readL: Could not find configuration parameter.\n"))); |
|
690 User::Leave(KErrArgument); |
|
691 } |
|
692 |
|
693 CleanupStack::PopAndDestroy(3); // Close view, 2 x buf |
|
694 |
|
695 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
696 } |
|
697 |
|
698 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::type_configure_write( |
|
699 const eap_configuration_field_c * const field, |
|
700 eap_variable_data_c * const data) |
|
701 { |
|
702 // Write is routed to partner object. |
|
703 eap_status_e status = m_partner->write_configure( |
|
704 field, |
|
705 data); |
|
706 return status; |
|
707 } |
|
708 |
|
709 //-------------------------------------------------- |
|
710 |
|
711 eap_status_e eap_am_type_mschapv2_symbian_c::update_username_password() |
|
712 { |
|
713 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
714 eap_status_e status(eap_status_ok); |
|
715 TRAPD(err, type_configure_updateL()); |
|
716 if (err != KErrNone) |
|
717 { |
|
718 status = m_am_tools->convert_am_error_to_eapol_error(err); |
|
719 } |
|
720 |
|
721 // User entered username/password and pressed OK. |
|
722 // Treat this as a full authentication and update the Last Auth Time. |
|
723 status = store_authentication_time(); |
|
724 if (status != eap_status_ok) |
|
725 { |
|
726 // Storing failed. Don't care. |
|
727 EAP_TRACE_ERROR(m_am_tools, |
|
728 TRACE_FLAGS_DEFAULT, ( |
|
729 EAPL("eap_am_type_mschapv2_symbian_c:Storing Last Full Authentication time failed, status=%d, but continuing\n"), |
|
730 status)); |
|
731 |
|
732 status = eap_status_ok; |
|
733 } |
|
734 |
|
735 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
736 |
|
737 return EAP_STATUS_RETURN(m_am_tools, status); |
|
738 } |
|
739 |
|
740 //-------------------------------------------------- |
|
741 |
|
742 void eap_am_type_mschapv2_symbian_c::type_configure_updateL() |
|
743 { |
|
744 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
745 |
|
746 // Now do the database update |
|
747 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
748 TPtr sqlStatement = buf->Des(); |
|
749 |
|
750 _LIT(KSQLUpdate, "SELECT %S,%S,%S FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
751 sqlStatement.Format(KSQLUpdate, |
|
752 &cf_str_EAP_MSCHAPV2_username_literal, |
|
753 &cf_str_EAP_MSCHAPV2_password_prompt_literal, |
|
754 &cf_str_EAP_MSCHAPV2_password_literal, |
|
755 &KMsChapV2TableName, |
|
756 &KServiceType, |
|
757 m_index_type, |
|
758 &KServiceIndex, |
|
759 m_index, |
|
760 &KTunnelingType, |
|
761 m_tunneling_vendor_type); |
|
762 |
|
763 RDbView view; |
|
764 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), RDbView::EUpdatable)); |
|
765 CleanupClosePushL(view); |
|
766 |
|
767 view.FirstL(); |
|
768 view.GetL(); |
|
769 view.UpdateL(); |
|
770 |
|
771 // Get column set so we get the correct column numbers |
|
772 CDbColSet* colSet = view.ColSetL(); |
|
773 CleanupStack::PushL(colSet); |
|
774 |
|
775 EAP_ASSERT(m_username_utf8 != 0); |
|
776 |
|
777 eap_status_e status(eap_status_ok); |
|
778 |
|
779 { |
|
780 eap_variable_data_c tmp_username_unicode(m_am_tools); |
|
781 |
|
782 status = m_am_tools->convert_utf8_to_unicode(tmp_username_unicode, *m_username_utf8); |
|
783 if (status != eap_status_ok) |
|
784 { |
|
785 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
786 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
787 return; |
|
788 } |
|
789 |
|
790 TPtr8 username( |
|
791 static_cast<TUint8*> ( |
|
792 tmp_username_unicode.get_data()), |
|
793 tmp_username_unicode.get_data_length(), |
|
794 tmp_username_unicode.get_data_length()); |
|
795 |
|
796 EAP_TRACE_DATA_DEBUG( |
|
797 m_am_tools, |
|
798 TRACE_FLAGS_DEFAULT, |
|
799 (EAPL("type_configure_updateL - username"), |
|
800 username.Ptr(), |
|
801 username.Size())); |
|
802 |
|
803 // Validate length. |
|
804 if(username.Length() > KMaxUsernameLengthInDB) |
|
805 { |
|
806 // Username too long. Can not be stored in DB. |
|
807 |
|
808 EAP_TRACE_DEBUG_SYMBIAN((_L("eap_am_type_mschapv2_symbian_c::type_configure_updateL: Too long Username. Length=%d \n"), |
|
809 username.Length())); |
|
810 |
|
811 User::Leave(KErrArgument); |
|
812 } |
|
813 |
|
814 // Length is ok. Set the value in DB. |
|
815 view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_username_literal), username); |
|
816 } |
|
817 |
|
818 if (*m_password_prompt_enabled) |
|
819 { |
|
820 // Username and password prompt flag is stored, password is cleared |
|
821 view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EMSCHAPV2PasswordPromptOn); |
|
822 view.SetColNullL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal)); |
|
823 } |
|
824 else |
|
825 { |
|
826 eap_variable_data_c tmp_password_unicode(m_am_tools); |
|
827 |
|
828 status = m_am_tools->convert_utf8_to_unicode(tmp_password_unicode, *m_password_utf8); |
|
829 if (status != eap_status_ok) |
|
830 { |
|
831 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
832 (void) EAP_STATUS_RETURN(m_am_tools, status); |
|
833 return; |
|
834 } |
|
835 |
|
836 TPtr8 password( |
|
837 static_cast<TUint8*> ( |
|
838 tmp_password_unicode.get_data()), |
|
839 tmp_password_unicode.get_data_length(), |
|
840 tmp_password_unicode.get_data_length()); |
|
841 |
|
842 // Validate length. |
|
843 if(password.Length() > KMaxPasswordLengthInDB) |
|
844 { |
|
845 // Password too long. Can not be stored in DB. |
|
846 |
|
847 EAP_TRACE_DEBUG_SYMBIAN((_L("eap_am_type_mschapv2_symbian_c::type_configure_updateL: Too long Password. Length=%d \n"), |
|
848 password.Length())); |
|
849 |
|
850 User::Leave(KErrArgument); |
|
851 } |
|
852 |
|
853 view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_prompt_literal), EMSCHAPV2PasswordPromptOff); |
|
854 |
|
855 // Length is ok. Set the value in DB. |
|
856 view.SetColL(colSet->ColNo(cf_str_EAP_MSCHAPV2_password_literal), password); |
|
857 } |
|
858 |
|
859 view.PutL(); |
|
860 |
|
861 CleanupStack::PopAndDestroy( colSet ); // Delete colSet. |
|
862 |
|
863 CleanupStack::PopAndDestroy(2); // view, buf |
|
864 |
|
865 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
866 } |
|
867 |
|
868 //-------------------------------------------------- |
|
869 |
|
870 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::configure() |
|
871 { |
|
872 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
873 |
|
874 { |
|
875 // Read Maximum Session Validity Time from the config file |
|
876 eap_variable_data_c sessionTimeFromFile(m_am_tools); |
|
877 |
|
878 eap_status_e status = m_partner->read_configure( |
|
879 cf_str_EAP_MSCHAPv2_max_session_validity_time.get_field(), |
|
880 &sessionTimeFromFile); |
|
881 |
|
882 if (status == eap_status_ok |
|
883 && sessionTimeFromFile.get_is_valid_data() == true |
|
884 && sessionTimeFromFile.get_data_length() == sizeof(u32_t)) |
|
885 { |
|
886 u32_t *session = reinterpret_cast<u32_t *>(sessionTimeFromFile.get_data()); |
|
887 if (session != 0) |
|
888 { |
|
889 // Update the max session time (in micro seconds). |
|
890 // configuration file saves the time in seconds. We have to convert it to micro seconds. |
|
891 m_max_session_time = static_cast<TInt64>(*session) * static_cast<TInt64>(KMicroSecsInASecond); |
|
892 } |
|
893 } |
|
894 } |
|
895 |
|
896 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
897 |
|
898 return eap_status_ok; |
|
899 } |
|
900 |
|
901 //-------------------------------------------------- |
|
902 |
|
903 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::reset() |
|
904 { |
|
905 return eap_status_ok; |
|
906 } |
|
907 |
|
908 //-------------------------------------------------- |
|
909 |
|
910 eap_status_e eap_am_type_mschapv2_symbian_c::show_username_password_dialog( |
|
911 eap_variable_data_c & username_utf8, |
|
912 eap_variable_data_c & password_utf8, |
|
913 bool & password_prompt_enabled, |
|
914 bool is_identity_query) |
|
915 { |
|
916 |
|
917 EAP_TRACE_DEBUG( |
|
918 m_am_tools, |
|
919 TRACE_FLAGS_DEFAULT, |
|
920 (EAPL("eap_am_type_mschapv2_symbian_c::show_username_password_dialog - start, password_prompt_enabled=%d,is_identity_query=%d\n"), |
|
921 password_prompt_enabled, is_identity_query)); |
|
922 |
|
923 m_username_utf8 = &username_utf8; |
|
924 m_password_utf8 = &password_utf8; |
|
925 m_password_prompt_enabled = &password_prompt_enabled; |
|
926 m_is_identity_query = is_identity_query; |
|
927 |
|
928 if (!IsActive()) |
|
929 { |
|
930 if (*m_password_prompt_enabled == true) |
|
931 { |
|
932 m_username_password_io_ptr->iPasswordPromptEnabled = ETrue; |
|
933 } |
|
934 else |
|
935 { |
|
936 m_username_password_io_ptr->iPasswordPromptEnabled = EFalse; |
|
937 } |
|
938 |
|
939 if (m_is_identity_query == true) |
|
940 { |
|
941 m_username_password_io_ptr->iIsIdentityQuery = ETrue; |
|
942 } |
|
943 else |
|
944 { |
|
945 m_username_password_io_ptr->iIsIdentityQuery = EFalse; |
|
946 } |
|
947 |
|
948 |
|
949 { |
|
950 eap_variable_data_c tmp_username_unicode(m_am_tools); |
|
951 eap_status_e status = m_am_tools->convert_utf8_to_unicode(tmp_username_unicode, *m_username_utf8); |
|
952 if (status != eap_status_ok) |
|
953 { |
|
954 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
955 return EAP_STATUS_RETURN(m_am_tools, status); |
|
956 } |
|
957 |
|
958 m_username_password_io_ptr->iUsername.Copy( |
|
959 reinterpret_cast<TUint16 *> ( |
|
960 tmp_username_unicode.get_data(tmp_username_unicode.get_data_length())), |
|
961 tmp_username_unicode.get_data_length() / 2); // 8bit -> 16bit |
|
962 } |
|
963 |
|
964 |
|
965 m_state = EHandlingUsernamePasswordQuery; |
|
966 |
|
967 EAP_TRACE_DEBUG( |
|
968 m_am_tools, |
|
969 TRACE_FLAGS_DEFAULT, |
|
970 (EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - before m_notifier.Connect(), m_is_notifier_connected=%d\n"), |
|
971 m_is_notifier_connected)); |
|
972 |
|
973 if( !m_is_notifier_connected ) |
|
974 { |
|
975 TInt error = m_notifier.Connect(); |
|
976 |
|
977 EAP_TRACE_DEBUG( |
|
978 m_am_tools, |
|
979 TRACE_FLAGS_DEFAULT, |
|
980 (EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - m_notifier.Connect() returned error=%d\n"), |
|
981 error)); |
|
982 |
|
983 if( error != KErrNone) |
|
984 { |
|
985 // Can not connect to notifier. |
|
986 return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(error)); |
|
987 } |
|
988 |
|
989 m_is_notifier_connected = true; // Got connectted to notifier. |
|
990 } |
|
991 |
|
992 EAP_TRACE_DEBUG( |
|
993 m_am_tools, |
|
994 TRACE_FLAGS_DEFAULT, |
|
995 (EAPL(" eap_am_type_mschapv2_symbian_c::show_username_password_dialog - before m_notifier.StartNotifierAndGetResponse()\n"))); |
|
996 |
|
997 m_notifier.StartNotifierAndGetResponse( |
|
998 iStatus, |
|
999 KEapMsChapV2UsernamePasswordUid, |
|
1000 *m_username_password_io_pckg_ptr, |
|
1001 *m_username_password_io_pckg_ptr); |
|
1002 |
|
1003 SetActive(); |
|
1004 } |
|
1005 else |
|
1006 { |
|
1007 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c: Already active when tried to show username/password dialog.\n"))); |
|
1008 return eap_status_process_general_error; |
|
1009 } |
|
1010 |
|
1011 return eap_status_pending_request; |
|
1012 } |
|
1013 |
|
1014 //-------------------------------------------------- |
|
1015 |
|
1016 eap_status_e eap_am_type_mschapv2_symbian_c::show_change_password_dialog( |
|
1017 eap_variable_data_c & /* username */, |
|
1018 eap_variable_data_c & /* old_password */, |
|
1019 eap_variable_data_c & /* password */, |
|
1020 bool & /* password_prompt_enabled */) |
|
1021 { |
|
1022 |
|
1023 EAP_TRACE_DEBUG( |
|
1024 m_am_tools, |
|
1025 TRACE_FLAGS_DEFAULT, |
|
1026 (EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - THIS IS NOT SUPPORTED - return eap_status_not_supported \n"))); |
|
1027 |
|
1028 #if !defined (EAP_MSCHAPV2_ENABLE_PASSWORD_CHANGE) |
|
1029 |
|
1030 send_error_notification(eap_status_password_expired); |
|
1031 |
|
1032 // This is not supported. |
|
1033 return eap_status_not_supported; |
|
1034 |
|
1035 #else |
|
1036 |
|
1037 // Don't remove this. May be needed in future. |
|
1038 |
|
1039 m_username_utf8 = &username; |
|
1040 m_password_utf8 = &password; |
|
1041 m_old_password_utf8 = &old_password; |
|
1042 m_password_prompt_enabled = &password_prompt_enabled; |
|
1043 |
|
1044 if (!IsActive()) |
|
1045 { |
|
1046 { |
|
1047 eap_variable_data_c tmp_username_unicode(m_am_tools); |
|
1048 eap_status_e status = m_am_tools->convert_utf8_to_unicode(tmp_username_unicode, *m_username_utf8); |
|
1049 if (status != eap_status_ok) |
|
1050 { |
|
1051 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1052 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1053 } |
|
1054 |
|
1055 m_username_password_io_ptr->iUsername.Copy( |
|
1056 reinterpret_cast<TUint16 *> ( |
|
1057 tmp_username_unicode.get_data(tmp_username_unicode.get_data_length())), |
|
1058 tmp_username_unicode.get_data_length() / 2); // 8bit -> 16bit |
|
1059 } |
|
1060 |
|
1061 m_state = EHandlingChangePasswordQuery; |
|
1062 |
|
1063 EAP_TRACE_DEBUG( |
|
1064 m_am_tools, |
|
1065 TRACE_FLAGS_DEFAULT, |
|
1066 (EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - before m_notifier.Connect(), m_is_notifier_connected=%d\n"), |
|
1067 m_is_notifier_connected)); |
|
1068 |
|
1069 if( !m_is_notifier_connected ) |
|
1070 { |
|
1071 TInt error = m_notifier.Connect(); |
|
1072 |
|
1073 EAP_TRACE_DEBUG( |
|
1074 m_am_tools, |
|
1075 TRACE_FLAGS_DEFAULT, |
|
1076 (EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - m_notifier.Connect() returned error=%d\n"), |
|
1077 error)); |
|
1078 |
|
1079 if( error != KErrNone) |
|
1080 { |
|
1081 // Can not connect to notifier. |
|
1082 return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(error)); |
|
1083 } |
|
1084 |
|
1085 m_is_notifier_connected = true; // Got connectted to notifier. |
|
1086 } |
|
1087 |
|
1088 EAP_TRACE_DEBUG( |
|
1089 m_am_tools, |
|
1090 TRACE_FLAGS_DEFAULT, |
|
1091 (EAPL(" eap_am_type_mschapv2_symbian_c::show_change_password_dialog - before m_notifier.StartNotifierAndGetResponse()\n"))); |
|
1092 |
|
1093 m_notifier.StartNotifierAndGetResponse( |
|
1094 iStatus, |
|
1095 KEapMsChapV2ChangePasswordUid, |
|
1096 *m_username_password_io_pckg_ptr, |
|
1097 *m_username_password_io_pckg_ptr); |
|
1098 |
|
1099 SetActive(); |
|
1100 } |
|
1101 else |
|
1102 { |
|
1103 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c: Already active when tried to show change password dialog.\n"))); |
|
1104 return eap_status_process_general_error; |
|
1105 } |
|
1106 |
|
1107 return eap_status_pending_request; |
|
1108 |
|
1109 #endif |
|
1110 } |
|
1111 |
|
1112 //-------------------------------------------------- |
|
1113 |
|
1114 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::read_auth_failure_string(eap_mschapv2_error_e error_code, eap_variable_data_c &string) |
|
1115 { |
|
1116 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1117 |
|
1118 EAP_UNREFERENCED_PARAMETER(error_code); |
|
1119 EAP_UNREFERENCED_PARAMETER(string); |
|
1120 |
|
1121 return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported); |
|
1122 } |
|
1123 |
|
1124 //-------------------------------------------------- |
|
1125 |
|
1126 EAP_FUNC_EXPORT eap_status_e eap_am_type_mschapv2_symbian_c::get_memory_store_key( |
|
1127 eap_variable_data_c * const memory_store_key) |
|
1128 { |
|
1129 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1130 |
|
1131 eap_status_e status = memory_store_key->set_copy_of_buffer( |
|
1132 EAP_MSCHAPV2_CREDENTIAL_HANDLE_KEY, |
|
1133 sizeof(EAP_MSCHAPV2_CREDENTIAL_HANDLE_KEY)); |
|
1134 if (status != eap_status_ok) |
|
1135 { |
|
1136 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1137 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1138 } |
|
1139 |
|
1140 u8_t fill = ':'; |
|
1141 |
|
1142 status = memory_store_key->add_data( |
|
1143 &m_index_type, |
|
1144 sizeof(m_index_type)); |
|
1145 if (status != eap_status_ok) |
|
1146 { |
|
1147 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1148 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1149 } |
|
1150 |
|
1151 status = memory_store_key->add_data( |
|
1152 &fill, |
|
1153 sizeof(fill)); |
|
1154 if (status != eap_status_ok) |
|
1155 { |
|
1156 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1157 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1158 } |
|
1159 |
|
1160 status = memory_store_key->add_data( |
|
1161 &m_index, |
|
1162 sizeof(m_index)); |
|
1163 if (status != eap_status_ok) |
|
1164 { |
|
1165 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1166 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1167 } |
|
1168 |
|
1169 |
|
1170 status = memory_store_key->add_data( |
|
1171 &fill, |
|
1172 sizeof(fill)); |
|
1173 if (status != eap_status_ok) |
|
1174 { |
|
1175 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1176 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1177 } |
|
1178 |
|
1179 status = memory_store_key->add_data( |
|
1180 &m_tunneling_vendor_type, |
|
1181 sizeof(m_tunneling_vendor_type)); |
|
1182 if (status != eap_status_ok) |
|
1183 { |
|
1184 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1185 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1186 } |
|
1187 |
|
1188 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1189 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1190 } |
|
1191 |
|
1192 //-------------------------------------------------- |
|
1193 |
|
1194 bool eap_am_type_mschapv2_symbian_c::is_session_valid() |
|
1195 { |
|
1196 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1197 |
|
1198 bool sessionValidity(false); |
|
1199 |
|
1200 TRAPD(err, sessionValidity = is_session_validL()); |
|
1201 if (err != KErrNone) |
|
1202 { |
|
1203 EAP_TRACE_ERROR(m_am_tools, |
|
1204 TRACE_FLAGS_DEFAULT, ( |
|
1205 EAPL("eap_am_type_mschapv2_symbian_c::is_session_valid - LEAVE - error=%d, Assuming session is invalid \n"), |
|
1206 err)); |
|
1207 |
|
1208 sessionValidity = false; |
|
1209 } |
|
1210 |
|
1211 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1212 |
|
1213 return sessionValidity; |
|
1214 } |
|
1215 |
|
1216 //-------------------------------------------------- |
|
1217 |
|
1218 bool eap_am_type_mschapv2_symbian_c::is_session_validL() |
|
1219 { |
|
1220 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1221 |
|
1222 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c::is_session_valid - start \n"))); |
|
1223 |
|
1224 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
1225 TPtr sqlStatement = buf->Des(); |
|
1226 |
|
1227 // Query all the relevant parameters |
|
1228 _LIT(KSQLQuery, "SELECT %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
1229 sqlStatement.Format(KSQLQuery, &cf_str_EAP_MSCHAPv2_max_session_validity_time_literal, |
|
1230 &KMSCHAPv2LastFullAuthTime, &KMsChapV2TableName, |
|
1231 &KServiceType, m_index_type, |
|
1232 &KServiceIndex, m_index, &KTunnelingType, m_tunneling_vendor_type); |
|
1233 |
|
1234 RDbView view; |
|
1235 // Evaluate view |
|
1236 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement))); |
|
1237 CleanupClosePushL(view); |
|
1238 User::LeaveIfError(view.EvaluateAll()); |
|
1239 |
|
1240 // Get the first (and only) row |
|
1241 view.FirstL(); |
|
1242 view.GetL(); |
|
1243 |
|
1244 // Get column set so we get the correct column numbers |
|
1245 CDbColSet* colSet = view.ColSetL(); |
|
1246 CleanupStack::PushL(colSet); |
|
1247 |
|
1248 TInt64 maxSessionTime = view.ColInt64(colSet->ColNo(cf_str_EAP_MSCHAPv2_max_session_validity_time_literal)); |
|
1249 TInt64 fullAuthTime = view.ColInt64(colSet->ColNo(KMSCHAPv2LastFullAuthTime)); |
|
1250 |
|
1251 CleanupStack::PopAndDestroy(colSet); // Delete colSet. |
|
1252 CleanupStack::PopAndDestroy(&view); // Close view. |
|
1253 CleanupStack::PopAndDestroy(buf); // Delete buf. |
|
1254 |
|
1255 // If the max session time from DB is zero then we use the |
|
1256 // one read from configuration file. |
|
1257 |
|
1258 if( maxSessionTime == 0) |
|
1259 { |
|
1260 EAP_TRACE_DEBUG(m_am_tools, |
|
1261 TRACE_FLAGS_DEFAULT, ( |
|
1262 EAPL("Session Validity - Using max session validity time from config file\n"))); |
|
1263 |
|
1264 maxSessionTime = m_max_session_time; // value from configuration file. |
|
1265 } |
|
1266 |
|
1267 // Get the current time. |
|
1268 TTime currentTime; |
|
1269 currentTime.UniversalTime(); |
|
1270 |
|
1271 TTime lastFullAuthTime(fullAuthTime); |
|
1272 |
|
1273 #if defined(_DEBUG) || defined(DEBUG) |
|
1274 |
|
1275 TDateTime currentDateTime = currentTime.DateTime(); |
|
1276 |
|
1277 TDateTime fullAuthDateTime = lastFullAuthTime.DateTime(); |
|
1278 |
|
1279 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, |
|
1280 (EAPL("Session Validity - Current Time, %2d-%2d-%4d : %2d-%2d-%2d-%d\n"), |
|
1281 currentDateTime.Day()+1, currentDateTime.Month()+1, currentDateTime.Year(), currentDateTime.Hour(), |
|
1282 currentDateTime.Minute(), currentDateTime.Second(), currentDateTime.MicroSecond())); |
|
1283 |
|
1284 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, |
|
1285 (EAPL("Session Validity - Last Full Auth Time, %2d-%2d-%4d : %2d-%2d-%2d-%d\n"), |
|
1286 fullAuthDateTime.Day()+1, fullAuthDateTime.Month()+1, fullAuthDateTime.Year(), fullAuthDateTime.Hour(), |
|
1287 fullAuthDateTime.Minute(), fullAuthDateTime.Second(), fullAuthDateTime.MicroSecond())); |
|
1288 |
|
1289 #endif |
|
1290 |
|
1291 TTimeIntervalMicroSeconds interval = currentTime.MicroSecondsFrom(lastFullAuthTime); |
|
1292 |
|
1293 EAP_TRACE_DATA_DEBUG( m_am_tools, TRACE_FLAGS_DEFAULT,(EAPL("eap_am_type_mschapv2_symbian_c::is_session_valid:interval in microseconds:"), |
|
1294 &(interval.Int64()), |
|
1295 sizeof(interval.Int64()) ) ); |
|
1296 |
|
1297 EAP_TRACE_DATA_DEBUG( m_am_tools, TRACE_FLAGS_DEFAULT,(EAPL("eap_am_type_mschapv2_symbian_c::is_session_valid:max session time in microseconds:"), |
|
1298 &(maxSessionTime), |
|
1299 sizeof(maxSessionTime) ) ); |
|
1300 |
|
1301 |
|
1302 #if defined(_DEBUG) || defined(DEBUG) |
|
1303 |
|
1304 TTimeIntervalMinutes intervalMins; |
|
1305 TInt error = currentTime.MinutesFrom(lastFullAuthTime, intervalMins); |
|
1306 |
|
1307 if(error == KErrNone) |
|
1308 { |
|
1309 EAP_TRACE_DEBUG( |
|
1310 m_am_tools, |
|
1311 TRACE_FLAGS_DEFAULT, |
|
1312 (EAPL("eap_am_type_mschapv2_symbian_c::is_session_validL()") |
|
1313 EAPL("interval in Minutes =%d\n"), |
|
1314 intervalMins.Int())); |
|
1315 } |
|
1316 |
|
1317 #endif |
|
1318 |
|
1319 |
|
1320 if( maxSessionTime >= interval.Int64() ) |
|
1321 { |
|
1322 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c::is_session_valid - Session Valid \n"))); |
|
1323 |
|
1324 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1325 |
|
1326 return true; |
|
1327 } |
|
1328 else |
|
1329 { |
|
1330 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c::is_session_valid - Session NOT Valid \n"))); |
|
1331 |
|
1332 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1333 |
|
1334 return false; |
|
1335 } |
|
1336 } |
|
1337 |
|
1338 //-------------------------------------------------- |
|
1339 |
|
1340 eap_status_e eap_am_type_mschapv2_symbian_c::store_authentication_time() |
|
1341 { |
|
1342 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1343 |
|
1344 eap_status_e status(eap_status_ok); |
|
1345 |
|
1346 TRAPD(err, store_authentication_timeL()); |
|
1347 if (err != KErrNone) |
|
1348 { |
|
1349 status = m_am_tools->convert_am_error_to_eapol_error(err); |
|
1350 } |
|
1351 |
|
1352 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1353 |
|
1354 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1355 } |
|
1356 |
|
1357 //-------------------------------------------------- |
|
1358 |
|
1359 void eap_am_type_mschapv2_symbian_c::store_authentication_timeL() |
|
1360 { |
|
1361 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1362 |
|
1363 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("eap_am_type_mschapv2_symbian_c::store_authentication_timeL - start \n"))); |
|
1364 |
|
1365 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
1366 TPtr sqlStatement = buf->Des(); |
|
1367 |
|
1368 // Query all the relevant parameters |
|
1369 _LIT(KSQLQuery, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
1370 sqlStatement.Format(KSQLQuery, &KMSCHAPv2LastFullAuthTime, &KMsChapV2TableName, |
|
1371 &KServiceType, m_index_type, |
|
1372 &KServiceIndex, m_index, &KTunnelingType, m_tunneling_vendor_type); |
|
1373 |
|
1374 RDbView view; |
|
1375 // Evaluate view |
|
1376 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
1377 CleanupClosePushL(view); |
|
1378 User::LeaveIfError(view.EvaluateAll()); |
|
1379 |
|
1380 // Get the first (and only) row for updation. |
|
1381 view.FirstL(); |
|
1382 view.UpdateL(); |
|
1383 |
|
1384 // Get column set so we get the correct column numbers |
|
1385 CDbColSet* colSet = view.ColSetL(); |
|
1386 CleanupStack::PushL(colSet); |
|
1387 |
|
1388 // Get the current universal time. |
|
1389 TTime currentTime; |
|
1390 currentTime.UniversalTime(); |
|
1391 |
|
1392 #if defined(_DEBUG) || defined(DEBUG) |
|
1393 |
|
1394 TDateTime currentDateTime = currentTime.DateTime(); |
|
1395 |
|
1396 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, |
|
1397 (EAPL("eap_am_type_mschapv2_symbian_c::store_authentication_time, %2d-%2d-%4d : %2d-%2d-%2d-%d\n"), |
|
1398 currentDateTime.Day()+1, currentDateTime.Month()+1,currentDateTime.Year(), currentDateTime.Hour(), |
|
1399 currentDateTime.Minute(), currentDateTime.Second(), currentDateTime.MicroSecond())); |
|
1400 |
|
1401 #endif |
|
1402 |
|
1403 TInt64 fullAuthTime = currentTime.Int64(); |
|
1404 |
|
1405 view.SetColL(colSet->ColNo(KMSCHAPv2LastFullAuthTime), fullAuthTime); |
|
1406 |
|
1407 view.PutL(); |
|
1408 |
|
1409 CleanupStack::PopAndDestroy(colSet); // Delete colSet. |
|
1410 CleanupStack::PopAndDestroy(&view); // Close view. |
|
1411 CleanupStack::PopAndDestroy(buf); // Delete buf. |
|
1412 |
|
1413 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1414 } |
|
1415 |
|
1416 //-------------------------------------------------- |
|
1417 // End of Files |