1 /* |
|
2 * Copyright (c) 2006-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tpinpluginteststep.h" |
|
20 #include <authserver/authplugininterface.h> |
|
21 #include <test/testexecutelog.h> |
|
22 #include <ecom/ecom.h> |
|
23 #include <ecom/implementationinformation.h> |
|
24 #include <s32file.h> |
|
25 #include <authserver/auth_srv_errs.h> |
|
26 #include <authserver/authpatchdata.h> |
|
27 #include <u32hal.h> |
|
28 #include <e32svr.h> |
|
29 |
|
30 using namespace AuthServer; |
|
31 |
|
32 _LIT(KTrainSuccess, "TrainingSuccess"); |
|
33 _LIT(KReTrainSuccess, "ReTrainingSuccess"); |
|
34 _LIT(KIdentifySuccess, "IdentifySuccess"); |
|
35 _LIT(KIdentifyFailure, "IdentifyFailure"); |
|
36 |
|
37 _LIT(KSuccess, "Success"); |
|
38 _LIT(KFailure, "Failure"); |
|
39 _LIT(KDialogCancel, "Cancel"); |
|
40 _LIT(KDialogQuit, "Quit"); |
|
41 _LIT(KServerCancel, "ServerCancel"); |
|
42 |
|
43 _LIT(KInputFile, "C:\\t_pinplugindlg_in.dat"); |
|
44 _LIT(KOutputFile, "C:\\t_pinplugindlg_out.dat"); |
|
45 |
|
46 const TPluginId KPinPluginImplementationUid = 0x200032E5; |
|
47 const TUint32 KEntropy = 10000; |
|
48 const TUint32 KFalsePositiveRate = 0; |
|
49 const TUint32 KFalseNegativeRate = 0; |
|
50 const TBool KActive = ETrue; |
|
51 const TAuthPluginType KPluginType = EAuthKnowledge; |
|
52 |
|
53 _LIT(KPluginName, "PinPlugin"); |
|
54 _LIT(KPluginDesc, "Pinplugin authenticates device holder using PIN numbers generated from 0-9 digits"); |
|
55 |
|
56 TInt CPinPluginTestActive::KAuthenticationServerStackSize=0x2000; |
|
57 TInt CPinPluginTestActive::KAuthenticationServerInitHeapSize=0x1000; |
|
58 TInt CPinPluginTestActive::KAuthenticationServerMaxHeapSize=0x1000000; |
|
59 |
|
60 CPinPluginTestActive* CPinPluginTestActive::NewL(CTestExecuteLogger& aLogger, AuthServer::TIdentityId& aIdentityId, TPtrC& aPinProcessType, CPinPluginTestStep &aTestStep) |
|
61 { |
|
62 CPinPluginTestActive* pinPlugin = new (ELeave) CPinPluginTestActive(aLogger, aIdentityId, aPinProcessType, aTestStep); |
|
63 pinPlugin->ContructL(); |
|
64 return pinPlugin; |
|
65 } |
|
66 |
|
67 void CPinPluginTestActive::ContructL() |
|
68 { |
|
69 User::LeaveIfError(iFs.Connect()); |
|
70 } |
|
71 |
|
72 CPinPluginTestActive::CPinPluginTestActive(CTestExecuteLogger& aLogger, TIdentityId& aIdentityId,TPtrC& aPinProcessType, CPinPluginTestStep &aTestStep) |
|
73 :CActive(EPriorityStandard), |
|
74 iLogger(aLogger), |
|
75 iOperation(EPinPluginInfo), |
|
76 iIdentityId(aIdentityId), |
|
77 iPinProcessType(aPinProcessType), |
|
78 iTestStep(aTestStep) |
|
79 { |
|
80 CActiveScheduler::Add( this ); |
|
81 } |
|
82 |
|
83 CPinPluginTestActive::~CPinPluginTestActive() |
|
84 { |
|
85 Cancel(); |
|
86 iFs.Close(); |
|
87 if (iPinPlugin) |
|
88 { |
|
89 REComSession::DestroyedImplementation(iDtor_ID_Key); |
|
90 delete iPinPlugin; |
|
91 } |
|
92 REComSession::FinalClose(); |
|
93 } |
|
94 |
|
95 |
|
96 void CPinPluginTestActive::RunL() |
|
97 { |
|
98 iTestStep.SetTestStepError(iStatus.Int()); |
|
99 CActiveScheduler::Stop(); |
|
100 return; |
|
101 } |
|
102 |
|
103 TVerdict CPinPluginTestActive::DoTestPropertyL() |
|
104 { |
|
105 TBool res = ETrue; |
|
106 |
|
107 __UHEAP_MARK; // Check for memory leaks |
|
108 |
|
109 iPinPlugin = LoadPluginL(); |
|
110 if (iPinPlugin != NULL) |
|
111 { |
|
112 if(iPinPlugin->Id() != KPinPluginImplementationUid) |
|
113 res = EFalse; |
|
114 if(iPinPlugin->Name().CompareF(KPluginName) != 0) |
|
115 res = EFalse; |
|
116 if(iPinPlugin->Description().CompareF(KPluginDesc) != 0) |
|
117 res = EFalse; |
|
118 if(iPinPlugin->Type() != KPluginType) |
|
119 res = EFalse; |
|
120 if(iPinPlugin->MinEntropy() != KEntropy) |
|
121 res = EFalse; |
|
122 if(iPinPlugin->FalsePositiveRate() != KFalsePositiveRate) |
|
123 res = EFalse; |
|
124 if(iPinPlugin->FalseNegativeRate() != KFalseNegativeRate) |
|
125 res = EFalse; |
|
126 if(iPinPlugin->IsActive() != KActive) |
|
127 res = EFalse; |
|
128 |
|
129 INFO_PRINTF2(_L("ID : 0x%x"), iPinPlugin->Id()); |
|
130 INFO_PRINTF2(_L("Name : %S"), &iPinPlugin->Name()); |
|
131 INFO_PRINTF2(_L("Description : %S"), &iPinPlugin->Description()); |
|
132 INFO_PRINTF2(_L("MinEntropy : %d"), iPinPlugin->MinEntropy()); |
|
133 INFO_PRINTF2(_L("False Positive Rate : %d"), iPinPlugin->FalsePositiveRate()); |
|
134 INFO_PRINTF2(_L("False Negative Rate : %d"), iPinPlugin->FalseNegativeRate()); |
|
135 _LIT(KETrue, "ETrue"); |
|
136 _LIT(KEFalse, "EFalse"); |
|
137 INFO_PRINTF2(_L("IsActive : %S"), iPinPlugin->IsActive() ? &KETrue : &KEFalse); |
|
138 switch(iPinPlugin->Type()) |
|
139 { |
|
140 case EAuthDefault: |
|
141 INFO_PRINTF1(_L("Type : EAuthDefault")); |
|
142 break; |
|
143 case EAuthBiometric: |
|
144 INFO_PRINTF1(_L("Type : EAuthBiometric")); |
|
145 break; |
|
146 case EAuthKnowledge: |
|
147 INFO_PRINTF1(_L("Type : EAuthKnowledge")); |
|
148 break; |
|
149 case EAuthToken: |
|
150 INFO_PRINTF1(_L("Type : EAuthToken")); |
|
151 break; |
|
152 case EAuthPerformance: |
|
153 INFO_PRINTF1(_L("Type : EAuthPerformance")); |
|
154 break; |
|
155 default: |
|
156 INFO_PRINTF1(_L("Invalid Type")); |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
162 return EFail; |
|
163 } |
|
164 UnLoadPlugin(); |
|
165 |
|
166 __UHEAP_MARKEND; |
|
167 |
|
168 if (!res) |
|
169 { |
|
170 INFO_PRINTF1(_L("PinPlugin returns Unexpected Values")); |
|
171 return EFail; |
|
172 } |
|
173 return EPass; |
|
174 } |
|
175 |
|
176 TVerdict CPinPluginTestActive::DoTestDefaultDataL() |
|
177 { |
|
178 TBool res = ETrue; |
|
179 |
|
180 __UHEAP_MARK; // Check for memory leaks |
|
181 |
|
182 iPinPlugin = LoadPluginL(); |
|
183 if (iPinPlugin != NULL) |
|
184 { |
|
185 HBufC8* result = NULL; |
|
186 TInt err = iPinPlugin->DefaultData(iIdentityId, result); |
|
187 if(result != NULL) |
|
188 { |
|
189 delete result; |
|
190 } |
|
191 if (err != KErrNone) |
|
192 { |
|
193 if (err == KErrNoMemory) |
|
194 { |
|
195 User::Leave(err); |
|
196 } |
|
197 res = EFalse; |
|
198 INFO_PRINTF3(_L("Err :%d while receiving the default data for the identity : %d"), err, iIdentityId); |
|
199 } |
|
200 else |
|
201 { |
|
202 _LIT(KPinValue, "11111"); |
|
203 iPinValue.Copy(KPinValue); |
|
204 INFO_PRINTF2(_L("Requesting Identify the Identity : %d with the default pin"), iIdentityId); |
|
205 TIdentityId identityId = iIdentityId; |
|
206 PreferDialogInputL(KIdentifySuccess, EPinPluginIdentify, 1); |
|
207 res = DoIdentifyL(result); |
|
208 if(result != NULL) |
|
209 { |
|
210 INFO_PRINTF2(_L("The Identity : %d is Successfully identified"), iIdentityId); |
|
211 delete result; |
|
212 } |
|
213 else |
|
214 { |
|
215 INFO_PRINTF2(_L("IdentityId : %d is not identified"), identityId); |
|
216 } |
|
217 } |
|
218 } |
|
219 else |
|
220 { |
|
221 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
222 return EFail; |
|
223 } |
|
224 UnLoadPlugin(); |
|
225 |
|
226 __UHEAP_MARKEND; |
|
227 |
|
228 return ReturnResultL(res); |
|
229 } |
|
230 |
|
231 TVerdict CPinPluginTestActive::DoTestIdentifyL() |
|
232 { |
|
233 if(!ReadDetailsFromIni(iTestStep)) |
|
234 { |
|
235 return EFail; |
|
236 } |
|
237 PreferDialogInputL(iExpectedOutput, EPinPluginIdentify, iDialogNumber); |
|
238 TBool res = ETrue; |
|
239 |
|
240 __UHEAP_MARK; // Check for memory leaks |
|
241 |
|
242 TIdentityId identityId = iIdentityId; |
|
243 iPinPlugin = LoadPluginL(); |
|
244 if (iPinPlugin != NULL) |
|
245 { |
|
246 HBufC8* result = NULL; |
|
247 INFO_PRINTF2(_L("Requesting Identify the Identity : %d"), iIdentityId); |
|
248 res = DoIdentifyL(result); |
|
249 if(result != NULL) |
|
250 { |
|
251 INFO_PRINTF2(_L("The Identity : %d is Successfully identified"), iIdentityId); |
|
252 delete result; |
|
253 } |
|
254 else |
|
255 { |
|
256 INFO_PRINTF2(_L("IdentityId : %d is not identified"), identityId); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
262 return EFail; |
|
263 } |
|
264 UnLoadPlugin(); |
|
265 __UHEAP_MARKEND; |
|
266 |
|
267 return ReturnResultL(res); |
|
268 } |
|
269 |
|
270 TVerdict CPinPluginTestActive::DoTestTrainL() |
|
271 { |
|
272 if(!ReadDetailsFromIni(iTestStep)) |
|
273 { |
|
274 return EFail; |
|
275 } |
|
276 PreferDialogInputL(iExpectedOutput, EPinPluginTraining, iDialogNumber); |
|
277 TBool res = ETrue; |
|
278 |
|
279 __UHEAP_MARK; // Check for memory leaks |
|
280 |
|
281 iPinPlugin = LoadPluginL(); |
|
282 if (iPinPlugin != NULL) |
|
283 { |
|
284 INFO_PRINTF2(_L("Requesting Train the Identity : %d"), iIdentityId); |
|
285 res = TrainIdentifyL(); |
|
286 } |
|
287 else |
|
288 { |
|
289 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
290 return EFail; |
|
291 } |
|
292 UnLoadPlugin(); |
|
293 |
|
294 __UHEAP_MARKEND; |
|
295 |
|
296 return ReturnResultL(res); |
|
297 } |
|
298 |
|
299 TVerdict CPinPluginTestActive::DoTestForgetL() |
|
300 { |
|
301 if(!ReadDetailsFromIni(iTestStep)) |
|
302 { |
|
303 return EFail; |
|
304 } |
|
305 |
|
306 TBool res = ETrue; |
|
307 |
|
308 __UHEAP_MARK; // Check for memory leaks |
|
309 |
|
310 iPinPlugin = LoadPluginL(); |
|
311 if (iPinPlugin != NULL) |
|
312 { |
|
313 ForgetIdentifyL(); |
|
314 } |
|
315 else |
|
316 { |
|
317 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
318 return EFail; |
|
319 } |
|
320 UnLoadPlugin(); |
|
321 __UHEAP_MARKEND; |
|
322 |
|
323 return ReturnResultL(res); |
|
324 } |
|
325 |
|
326 void CPinPluginTestActive::DoCancel() |
|
327 { |
|
328 iPinPlugin->Cancel(); |
|
329 } |
|
330 |
|
331 TVerdict CPinPluginTestActive::DoTestReTrainL() |
|
332 { |
|
333 if(!ReadDetailsFromIni(iTestStep)) |
|
334 { |
|
335 return EFail; |
|
336 } |
|
337 |
|
338 TInt dialogno = iDialogNumber; |
|
339 TBool DialogCancel = EFalse; |
|
340 if (iExpectedOutput.CompareF(KDialogCancel) == 0 |
|
341 || iExpectedOutput.CompareF(KDialogQuit) == 0) |
|
342 { |
|
343 DialogCancel = ETrue; |
|
344 } |
|
345 PreferDialogInputL(KTrainSuccess, EPinPluginTraining, 1); |
|
346 TBool res = ETrue; |
|
347 |
|
348 __UHEAP_MARK; // Check for memory leaks |
|
349 TIdentityId identityId = iIdentityId; |
|
350 iPinPlugin = LoadPluginL(); |
|
351 if (iPinPlugin != NULL) |
|
352 { |
|
353 INFO_PRINTF2(_L("Requesting Train the Identity : %d"), iIdentityId); |
|
354 res = TrainIdentifyL(); |
|
355 if (res) |
|
356 { |
|
357 iTempPinValue.Copy(iPinValue); |
|
358 if (DialogCancel) |
|
359 { |
|
360 PreferDialogInputL(KDialogCancel, EPinPluginTraining, dialogno); |
|
361 } |
|
362 else |
|
363 { |
|
364 PreferDialogInputL(KReTrainSuccess, EPinPluginTraining, dialogno); |
|
365 } |
|
366 INFO_PRINTF2(_L("Requesting ReTrain the Identity : %d"), iIdentityId); |
|
367 res = TrainIdentifyL(); |
|
368 if (res) |
|
369 { |
|
370 iPinValue.Copy(iTempPinValue); |
|
371 iIdentityId = identityId; |
|
372 if (DialogCancel) |
|
373 { |
|
374 PreferDialogInputL(KIdentifySuccess, EPinPluginIdentify, dialogno); |
|
375 } |
|
376 else |
|
377 { |
|
378 PreferDialogInputL(KIdentifyFailure, EPinPluginIdentify, 3); |
|
379 } |
|
380 HBufC8* result = NULL; |
|
381 HBufC* pinVal = HBufC::NewLC(iPinValue.Length()); |
|
382 pinVal->Des().Copy(iPinValue); |
|
383 INFO_PRINTF3(_L("Requesting Identify the Identity : %d with the pin : %S"), iIdentityId, pinVal); |
|
384 CleanupStack::PopAndDestroy(pinVal); |
|
385 res = DoIdentifyL(result); |
|
386 if(result != NULL) |
|
387 { |
|
388 INFO_PRINTF2(_L("The Identity : %d is Successfully identified"), iIdentityId); |
|
389 delete result; |
|
390 } |
|
391 else |
|
392 { |
|
393 INFO_PRINTF2(_L("IdentityId : %d is not identified"), identityId); |
|
394 } |
|
395 } |
|
396 } |
|
397 } |
|
398 else |
|
399 { |
|
400 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
401 return EFail; |
|
402 } |
|
403 UnLoadPlugin(); |
|
404 __UHEAP_MARKEND; |
|
405 |
|
406 return ReturnResultL(res); |
|
407 } |
|
408 |
|
409 TVerdict CPinPluginTestActive::DoTestServerCancelL() |
|
410 { |
|
411 if(!ReadDetailsFromIni(iTestStep)) |
|
412 { |
|
413 return EFail; |
|
414 } |
|
415 PreferDialogInputL(iExpectedOutput, EPinPluginTraining, 1); |
|
416 |
|
417 TBool res = ETrue; |
|
418 |
|
419 __UHEAP_MARK; // Check for memory leaks |
|
420 TIdentityId identityId = iIdentityId; |
|
421 iPinPlugin = LoadPluginL(); |
|
422 if (iPinPlugin != NULL) |
|
423 { |
|
424 if (iPinProcessType.CompareF(KReTrainServerCancel) == 0) |
|
425 { |
|
426 INFO_PRINTF2(_L("Requesting Train the Identity : %d"), iIdentityId); |
|
427 res = TrainIdentifyL(); |
|
428 } |
|
429 HBufC8* result = NULL; |
|
430 if (iPinProcessType.CompareF(KTrainServerCancel) == 0 |
|
431 || iPinProcessType.CompareF(KReTrainServerCancel) == 0) |
|
432 { |
|
433 iTempPinValue.Copy(iPinValue); |
|
434 INFO_PRINTF2(_L("Requesting Train the Identity : %d"), iIdentityId); |
|
435 iPinPlugin->Train(iIdentityId, result, iStatus); |
|
436 SetActive(); |
|
437 } |
|
438 else if (iPinProcessType.CompareF(KIdentifyServerCancel) == 0) |
|
439 { |
|
440 INFO_PRINTF2(_L("Identify the Identity : %d"), iIdentityId); |
|
441 iPinPlugin->Identify(iIdentityId, KNullDesC(), result, iStatus); |
|
442 SetActive(); |
|
443 } |
|
444 |
|
445 INFO_PRINTF1(_L("Cancel the process from the Authentication Server")); |
|
446 |
|
447 Cancel(); |
|
448 |
|
449 if(iStatus.Int() != -3) |
|
450 { |
|
451 res = EFalse; |
|
452 } |
|
453 if (res && iPinProcessType.CompareF(KIdentifyServerCancel) != 0) |
|
454 { |
|
455 iIdentityId = identityId; |
|
456 if (iPinProcessType.CompareF(KTrainServerCancel) == 0) |
|
457 { |
|
458 _LIT(KPinValue, "123456"); |
|
459 iPinValue.Copy(KPinValue); |
|
460 PreferDialogInputL(KIdentifyFailure, EPinPluginIdentify, 3); |
|
461 } |
|
462 else |
|
463 { |
|
464 iPinValue.Copy(iTempPinValue); |
|
465 PreferDialogInputL(KIdentifySuccess, EPinPluginIdentify, 1); |
|
466 } |
|
467 HBufC8* result = NULL; |
|
468 HBufC* pinVal = HBufC::NewLC(iPinValue.Length()); |
|
469 pinVal->Des().Copy(iPinValue); |
|
470 INFO_PRINTF3(_L("Requesting Identify the Identity : %d with the pin : %S"), iIdentityId, pinVal); |
|
471 CleanupStack::PopAndDestroy(pinVal); |
|
472 res = DoIdentifyL(result); |
|
473 if(result != NULL) |
|
474 { |
|
475 INFO_PRINTF2(_L("The Identity : %d is Successfully identified"), iIdentityId); |
|
476 delete result; |
|
477 } |
|
478 else |
|
479 { |
|
480 INFO_PRINTF2(_L("IdentityId : %d is not identified"), identityId); |
|
481 } |
|
482 } |
|
483 } |
|
484 else |
|
485 { |
|
486 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
487 return EFail; |
|
488 } |
|
489 UnLoadPlugin(); |
|
490 |
|
491 __UHEAP_MARKEND; |
|
492 |
|
493 return ReturnResultL(res); |
|
494 } |
|
495 |
|
496 TVerdict CPinPluginTestActive::DoTestSequenceL() |
|
497 { |
|
498 PreferDialogInputL(KTrainSuccess, EPinPluginTraining, 1); |
|
499 |
|
500 TBool res = ETrue; |
|
501 |
|
502 __UHEAP_MARK; // Check for memory leaks |
|
503 |
|
504 iPinPlugin = LoadPluginL(); |
|
505 if (iPinPlugin != NULL) |
|
506 { |
|
507 INFO_PRINTF2(_L("Requesting Train the Identity : %d"), iIdentityId); |
|
508 res = TrainIdentifyL(); |
|
509 if (res) |
|
510 { |
|
511 PreferDialogInputL(KReTrainSuccess, EPinPluginTraining, 1); |
|
512 INFO_PRINTF2(_L("Requesting ReTrain the Identity : %d"), iIdentityId); |
|
513 HBufC8* result = NULL; |
|
514 res = DoTrainL(result); |
|
515 if (result != NULL) |
|
516 { |
|
517 delete result; |
|
518 } |
|
519 if (res) |
|
520 { |
|
521 TIdentityId id = iIdentityId; |
|
522 res = ForgetIdentifyL(); |
|
523 if(res) |
|
524 { |
|
525 for (TInt i = 0; i <= 2; i++) |
|
526 { |
|
527 iIdentityId = id; |
|
528 INFO_PRINTF2(_L("Requesting Train the Identity : %d"), iIdentityId); |
|
529 if (i==2) |
|
530 { |
|
531 PreferDialogInputL(KTrainSuccess, EPinPluginTraining, 1); |
|
532 } |
|
533 else |
|
534 { |
|
535 iInfoMsg = EPinPluginTrainingSuccess; |
|
536 PreferDialogInputL(KDialogCancel, EPinPluginTraining, 1); |
|
537 } |
|
538 res = TrainIdentifyL(); |
|
539 if (!res) |
|
540 { |
|
541 break; |
|
542 } |
|
543 } |
|
544 } |
|
545 } |
|
546 } |
|
547 } |
|
548 else |
|
549 { |
|
550 iLogInfo.Copy( _L("Cannot Load PinPlugin") ); |
|
551 return EFail; |
|
552 } |
|
553 UnLoadPlugin(); |
|
554 |
|
555 __UHEAP_MARKEND; |
|
556 |
|
557 return ReturnResultL(res); |
|
558 } |
|
559 |
|
560 TVerdict CPinPluginTestActive::DoTestOomL() |
|
561 { |
|
562 if(!iTestStep.GetIntFromConfig(iTestStep.ConfigSection(), _L("oomtest"), iOomTest)) |
|
563 { |
|
564 INFO_PRINTF1(_L("Test about which function is needed")); |
|
565 return EFail; |
|
566 } |
|
567 __UHEAP_MARK; |
|
568 TIdentityId id = 1234; |
|
569 HBufC8* result = NULL; |
|
570 switch(iOomTest) |
|
571 { |
|
572 case 1: |
|
573 { |
|
574 iPinPlugin = LoadPluginL(); |
|
575 UnLoadPlugin(); |
|
576 } |
|
577 break; |
|
578 case 2: |
|
579 { |
|
580 iPinPlugin = LoadPluginL(); |
|
581 TInt err = iPinPlugin->DefaultData(id, result); |
|
582 CleanupStack::PushL(result); |
|
583 if (err == KErrNoMemory) |
|
584 { |
|
585 User::Leave(err); |
|
586 } |
|
587 err = iPinPlugin->Forget(id); |
|
588 if (err == KErrNoMemory) |
|
589 { |
|
590 User::Leave(err); |
|
591 } |
|
592 CleanupStack::PopAndDestroy(result); |
|
593 UnLoadPlugin(); |
|
594 } |
|
595 break; |
|
596 case 3: |
|
597 { |
|
598 iPinPlugin = LoadPluginL(); |
|
599 iStatus = KRequestPending; |
|
600 _LIT(KPinValue, "11111"); |
|
601 iPinValue.Copy(KPinValue); |
|
602 PreferDialogInputL(KIdentifySuccess, EPinPluginIdentify, 1); |
|
603 iPinPlugin->Identify(id, KNullDesC(), result, iStatus); |
|
604 CleanupStack::PushL(result); |
|
605 SetActive(); |
|
606 CActiveScheduler::Start(); |
|
607 CleanupStack::PopAndDestroy(result); |
|
608 UnLoadPlugin(); |
|
609 } |
|
610 break; |
|
611 case 4: |
|
612 { |
|
613 iPinPlugin = LoadPluginL(); |
|
614 iStatus = KRequestPending; |
|
615 PreferDialogInputL(KTrainSuccess, EPinPluginTraining, 1); |
|
616 iPinPlugin->Train(id, result, iStatus); |
|
617 SetActive(); |
|
618 CActiveScheduler::Start(); |
|
619 if (result != NULL) |
|
620 { |
|
621 delete result; |
|
622 } |
|
623 TInt err = iPinPlugin->Forget(id); |
|
624 if (err == KErrNoMemory) |
|
625 { |
|
626 User::Leave(err); |
|
627 } |
|
628 UnLoadPlugin(); |
|
629 } |
|
630 break; |
|
631 case 5: |
|
632 { |
|
633 iPinPlugin = LoadPluginL(); |
|
634 iStatus = KRequestPending; |
|
635 PreferDialogInputL(KTrainSuccess, EPinPluginTraining, 1); |
|
636 iPinPlugin->Train(id, result, iStatus); |
|
637 SetActive(); |
|
638 CActiveScheduler::Start(); |
|
639 if (result != NULL) |
|
640 { |
|
641 delete result; |
|
642 } |
|
643 UnLoadPlugin(); |
|
644 } |
|
645 break; |
|
646 case 6: |
|
647 { |
|
648 iPinPlugin = LoadPluginL(); |
|
649 TInt err = iPinPlugin->Forget(id); |
|
650 if (err == KErrNoMemory) |
|
651 { |
|
652 User::Leave(err); |
|
653 } |
|
654 UnLoadPlugin(); |
|
655 } |
|
656 break; |
|
657 } |
|
658 |
|
659 __UHEAP_MARKEND; |
|
660 return EPass; |
|
661 } |
|
662 |
|
663 CPinPlugin* CPinPluginTestActive::LoadPluginL() |
|
664 { |
|
665 TEComResolverParams resolverParams; |
|
666 TBufC8<16> pluginIdTxt; |
|
667 |
|
668 pluginIdTxt.Des().Format(_L8("%x"), KPinPluginImplementationUid); |
|
669 pluginIdTxt.Des().UpperCase(); |
|
670 resolverParams.SetDataType(pluginIdTxt); |
|
671 |
|
672 //To load plugins from sources other than ROM the patch |
|
673 // data KEnablePostMarketAuthenticationPlugins must be set to True. |
|
674 TUint32 enablePostMarketPlugin = KEnablePostMarketAuthenticationPlugins; |
|
675 |
|
676 #ifdef __WINS__ |
|
677 |
|
678 // Default SymbianOS behavior is to only load auth plugins from ROM. |
|
679 enablePostMarketPlugin = 0; |
|
680 |
|
681 // For the emulator allow the constant to be patched via epoc.ini |
|
682 UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty, |
|
683 (TAny*)"KEnablePostMarketAuthenticationPlugins", &enablePostMarketPlugin); // read emulator property (if present) |
|
684 |
|
685 #endif |
|
686 |
|
687 TAny* plugin = 0; |
|
688 TInt err = 0; |
|
689 |
|
690 if(enablePostMarketPlugin == 0) |
|
691 { |
|
692 TRAP(err, plugin = |
|
693 REComSession::CreateImplementationL(KCAuthPluginInterfaceUid, |
|
694 iDtor_ID_Key, |
|
695 resolverParams, |
|
696 KRomOnlyResolverUid)); |
|
697 } |
|
698 |
|
699 else |
|
700 { |
|
701 TRAP(err, plugin = |
|
702 REComSession::CreateImplementationL(KCAuthPluginInterfaceUid, |
|
703 iDtor_ID_Key, |
|
704 resolverParams)); |
|
705 } |
|
706 |
|
707 if (err == KErrNotFound) |
|
708 { |
|
709 err = KErrAuthServNoSuchPlugin; |
|
710 } |
|
711 User::LeaveIfError(err); |
|
712 |
|
713 return reinterpret_cast<CPinPlugin*>(plugin); |
|
714 |
|
715 } |
|
716 |
|
717 void CPinPluginTestActive::UnLoadPlugin() |
|
718 { |
|
719 delete iPinPlugin; |
|
720 iPinPlugin = NULL; |
|
721 REComSession::DestroyedImplementation(iDtor_ID_Key); |
|
722 REComSession::FinalClose(); |
|
723 } |
|
724 |
|
725 TVerdict CPinPluginTestActive::ReturnResultL(TBool aRes) |
|
726 { |
|
727 TVerdict result = EPass; |
|
728 DeleteFileL(); |
|
729 if (!aRes) |
|
730 { |
|
731 result = EFail; |
|
732 } |
|
733 return result; |
|
734 } |
|
735 |
|
736 TBool CPinPluginTestActive::TrainIdentifyL() |
|
737 { |
|
738 TBool res = ETrue; |
|
739 |
|
740 HBufC8* result = NULL; |
|
741 res = DoTrainL(result); |
|
742 if (res) |
|
743 { |
|
744 HBufC* pinVal = HBufC::NewLC(iPinValue.Length()); |
|
745 pinVal->Des().Copy(iPinValue); |
|
746 INFO_PRINTF3(_L("Identify the Identity : %d using pin : %S"), iIdentityId, pinVal); |
|
747 HBufC8* result1 = NULL; |
|
748 TIdentityId identityId = iIdentityId; |
|
749 res = DoIdentifyL(result1); |
|
750 if(res && result1 != NULL) |
|
751 { |
|
752 if (result->Des().CompareF(result1->Des()) != 0) |
|
753 { |
|
754 INFO_PRINTF1( _L("Trained result is different from identification result")); |
|
755 res = EFalse; |
|
756 } |
|
757 else |
|
758 { |
|
759 INFO_PRINTF3(_L("The Identity : %d is Successfully identified with pin : %S"), iIdentityId, pinVal); |
|
760 } |
|
761 delete result1; |
|
762 } |
|
763 else |
|
764 { |
|
765 INFO_PRINTF2(_L("The Identity %d is not trained"), identityId); |
|
766 } |
|
767 CleanupStack::PopAndDestroy(pinVal); |
|
768 } |
|
769 if(result != NULL) |
|
770 { |
|
771 delete result; |
|
772 } |
|
773 |
|
774 return res; |
|
775 } |
|
776 |
|
777 TBool CPinPluginTestActive::ForgetIdentifyL() |
|
778 { |
|
779 INFO_PRINTF2(_L("Requesting Forget the Identity : %d"), iIdentityId); |
|
780 TInt err = iPinPlugin->Forget(iIdentityId); |
|
781 |
|
782 TBool res = CheckResultL(err); |
|
783 if (res) |
|
784 { |
|
785 INFO_PRINTF2(_L("IdentityId :%d is successfully removed"), iIdentityId); |
|
786 INFO_PRINTF1(_L("Verify using Identify Process")); |
|
787 HBufC8* result = NULL; |
|
788 res = DoIdentifyL(result); |
|
789 if(res && result != NULL) |
|
790 { |
|
791 INFO_PRINTF2(_L("The Identity : %d is Successfully identified"), iIdentityId); |
|
792 delete result; |
|
793 } |
|
794 } |
|
795 return res; |
|
796 } |
|
797 |
|
798 TBool CPinPluginTestActive::DoTrainL(HBufC8*& aResult) |
|
799 { |
|
800 TBool res = ETrue; |
|
801 iStatus = KRequestPending; |
|
802 |
|
803 iPinPlugin->Train(iIdentityId, aResult, iStatus); |
|
804 SetActive(); |
|
805 CActiveScheduler::Start(); |
|
806 |
|
807 res = VerifyResultL(iStatus.Int()); |
|
808 return res; |
|
809 } |
|
810 |
|
811 TBool CPinPluginTestActive::DoIdentifyL(HBufC8*& aResult) |
|
812 { |
|
813 TBool res = ETrue; |
|
814 |
|
815 iPinPlugin->Identify(iIdentityId, KNullDesC(), aResult, iStatus); |
|
816 if(!IsActive()) |
|
817 SetActive(); |
|
818 CActiveScheduler::Start(); |
|
819 |
|
820 res = VerifyResultL(iStatus.Int()); |
|
821 return res; |
|
822 } |
|
823 |
|
824 TBool CPinPluginTestActive::VerifyResultL(TInt aOutputVal) |
|
825 { |
|
826 TBool result = ETrue; |
|
827 |
|
828 if ((iExpectedOutput.CompareF(KDialogCancel) == 0) |
|
829 && (aOutputVal != KErrAuthServPluginCancelled)) |
|
830 { |
|
831 INFO_PRINTF1(_L("RequestStatus is not completed with expected result")); |
|
832 result = EFalse; |
|
833 } |
|
834 else if ((iExpectedOutput.CompareF(KDialogQuit) == 0) |
|
835 && (aOutputVal != KErrAuthServPluginQuit)) |
|
836 { |
|
837 INFO_PRINTF1(_L("RequestStatus is not completed with expected result")); |
|
838 result = EFalse; |
|
839 } |
|
840 else if ((iExpectedOutput.CompareF(KTrainSuccess) == 0) |
|
841 && (aOutputVal == KErrAuthServRegistrationFailed)) |
|
842 { |
|
843 INFO_PRINTF2(_L("Authserver registration failed. Returned error code = %d"), aOutputVal); |
|
844 result = EFalse; |
|
845 } |
|
846 else if ((iExpectedOutput.CompareF(KDialogCancel) != 0) |
|
847 && (iExpectedOutput.CompareF(KDialogQuit) != 0) |
|
848 && (iExpectedOutput.CompareF(KServerCancel) != 0) |
|
849 && (aOutputVal != KErrNone)) |
|
850 { |
|
851 INFO_PRINTF1(_L("RequestStatus is not completed with expected result")); |
|
852 result = EFalse; |
|
853 } |
|
854 if (result && aOutputVal == KErrNone) |
|
855 { |
|
856 TInt dialogNumber; |
|
857 TPinValue pinValue; |
|
858 TPinPluginInfoMessage displayedMsg; |
|
859 ReadOutputDetailsL(dialogNumber, pinValue, displayedMsg); |
|
860 TPtrC message; |
|
861 switch(displayedMsg) |
|
862 { |
|
863 case EPinPluginTrainingSuccess: |
|
864 message.Set(_L("EPinPluginTrainingSuccess")); |
|
865 break; |
|
866 case EPinPluginReTrainingSuccess: |
|
867 message.Set(_L("EPinPluginReTrainingSuccess")); |
|
868 break; |
|
869 case EPinPluginIdentificationSuccess: |
|
870 message.Set(_L("EPinPluginIdentificationSuccess")); |
|
871 break; |
|
872 case EPinPluginIdentificationFailure: |
|
873 message.Set(_L("EPinPluginIdentificationFailure")); |
|
874 break; |
|
875 } |
|
876 if(displayedMsg != iInfoMsg) |
|
877 { |
|
878 INFO_PRINTF2(_L("INFO :%S which is not expected"), &message); |
|
879 result = EFalse; |
|
880 } |
|
881 if (iCmdResult == EOk && dialogNumber != iDialogNumber) |
|
882 { |
|
883 INFO_PRINTF3(_L("Number of dialog displayed : %d differ from expected dialog: %d."), dialogNumber,iDialogNumber); |
|
884 result = EFalse; |
|
885 } |
|
886 if (displayedMsg == EPinPluginIdentificationFailure |
|
887 && dialogNumber == 0) |
|
888 { |
|
889 INFO_PRINTF2(_L("INFO :%S because IdentityId is not available in the DB"), &message); |
|
890 } |
|
891 if (displayedMsg == EPinPluginIdentificationFailure |
|
892 && dialogNumber == 3) |
|
893 { |
|
894 INFO_PRINTF2(_L("INFO :%S because wrong pin input for all retries and IdentityId exists in the DB"), &message); |
|
895 } |
|
896 if (displayedMsg == EPinPluginIdentificationFailure |
|
897 && iIdentityId != KUnknownIdentity) |
|
898 { |
|
899 INFO_PRINTF2(_L("IdentityId was not reset for %S"), &message); |
|
900 } |
|
901 if (displayedMsg != EPinPluginIdentificationSuccess |
|
902 && displayedMsg != EPinPluginIdentificationFailure) |
|
903 { |
|
904 iPinValue.Copy(pinValue); |
|
905 if (iInfoMsg == EPinPluginTrainingSuccess |
|
906 || iInfoMsg == EPinPluginReTrainingSuccess) |
|
907 { |
|
908 HBufC* pinVal = HBufC::NewLC(pinValue.Length()); |
|
909 pinVal->Des().Copy(pinValue); |
|
910 INFO_PRINTF3(_L("The Identity %d is trained with pin number %S"), iIdentityId, pinVal); |
|
911 CleanupStack::PopAndDestroy(pinVal); |
|
912 PreferDialogInputL(KIdentifySuccess, EPinPluginIdentify, 1); |
|
913 } |
|
914 else |
|
915 { |
|
916 PreferDialogInputL(KIdentifyFailure, EPinPluginIdentify, 0); |
|
917 } |
|
918 } |
|
919 } |
|
920 if(aOutputVal != KErrNone) |
|
921 { |
|
922 if (aOutputVal == KErrAuthServPluginCancelled) |
|
923 { |
|
924 INFO_PRINTF1(_L("Cancel the process from the Dialog Notifier")); |
|
925 } |
|
926 else if (aOutputVal == KErrAuthServPluginQuit) |
|
927 { |
|
928 INFO_PRINTF1(_L("Quit the process from the Dialog Notifier")); |
|
929 } |
|
930 CheckResultL(aOutputVal); |
|
931 } |
|
932 return result; |
|
933 } |
|
934 |
|
935 TBool CPinPluginTestActive::CheckResultL(TInt aResult) |
|
936 { |
|
937 _LIT(KPinValue, "123456"); |
|
938 if (iExpectedOutput.CompareF(KSuccess) == 0 |
|
939 && aResult == KErrAuthServNoSuchIdentity) |
|
940 { |
|
941 INFO_PRINTF2(_L("IdentityId : %d is not identified when should be"), iIdentityId); |
|
942 return EFalse; |
|
943 } |
|
944 else if(iExpectedOutput.CompareF(KFailure) == 0 |
|
945 && aResult == KErrNone) |
|
946 { |
|
947 INFO_PRINTF2(_L(" IdentityId : %d is identified when should not be"), iIdentityId); |
|
948 return EFalse; |
|
949 } |
|
950 iPinValue.Copy(KPinValue); |
|
951 PreferDialogInputL(KIdentifyFailure, EPinPluginIdentify, 3); |
|
952 return ETrue; |
|
953 } |
|
954 |
|
955 TBool CPinPluginTestActive::ReadDetailsFromIni(CPinPluginTestStep& aStep) |
|
956 { |
|
957 TPtrC pinVal; |
|
958 if(!aStep.GetStringFromConfig(aStep.ConfigSection(), _L("expectedoutput"), iExpectedOutput)) |
|
959 { |
|
960 INFO_PRINTF1(_L("expectedoutput value is missing")); |
|
961 return EFalse; |
|
962 } |
|
963 // Optional input, if the input is not available by default the iIndex is set to 0. |
|
964 if(!aStep.GetIntFromConfig(aStep.ConfigSection(), _L("selectindex"), iIndex)) |
|
965 { |
|
966 iIndex = 0; |
|
967 } |
|
968 // optional input, if not pinplugin use the default pinlength from the config file. |
|
969 aStep.GetIntFromConfig(aStep.ConfigSection(), _L("newpinlength"), iNewPinLength); |
|
970 |
|
971 // optional input, |
|
972 aStep.GetStringFromConfig(aStep.ConfigSection(), _L("pinvalue"), pinVal); |
|
973 iPinValue.Copy(pinVal); |
|
974 |
|
975 // Optional input, if the input is not available by default the resultant output cmd will given |
|
976 // in the dialog No 1. |
|
977 if(!aStep.GetIntFromConfig(aStep.ConfigSection(), _L("outputatdialog"), iDialogNumber)) |
|
978 { |
|
979 if (iExpectedOutput.CompareF(KIdentifyFailure) == 0) |
|
980 { |
|
981 iDialogNumber = 3; |
|
982 } |
|
983 else |
|
984 { |
|
985 iDialogNumber = 1; |
|
986 } |
|
987 } |
|
988 return ETrue; |
|
989 } |
|
990 |
|
991 void CPinPluginTestActive::PreferDialogInputL(const TDesC& aExpectedOutput, |
|
992 TPinPluginDialogOperation aOp, TInt aDialogNo) |
|
993 { |
|
994 // iPinValue, iIndex, iNewPinLength is not changing for every operation. if |
|
995 // any changes occurs , we have to reset just before calling this function. |
|
996 iOperation = aOp; |
|
997 iDialogNumber = aDialogNo; |
|
998 iExpectedOutput.Set(aExpectedOutput); |
|
999 |
|
1000 if (aExpectedOutput.CompareF(KTrainSuccess) == 0) |
|
1001 { |
|
1002 iInfoMsg = EPinPluginTrainingSuccess; |
|
1003 } |
|
1004 else if (aExpectedOutput.CompareF(KReTrainSuccess) == 0) |
|
1005 { |
|
1006 iInfoMsg = EPinPluginReTrainingSuccess; |
|
1007 } |
|
1008 else if (aExpectedOutput.CompareF(KIdentifySuccess) == 0) |
|
1009 { |
|
1010 iInfoMsg = EPinPluginIdentificationSuccess; |
|
1011 } |
|
1012 else if (aExpectedOutput.CompareF(KIdentifyFailure) == 0) |
|
1013 { |
|
1014 iInfoMsg = EPinPluginIdentificationFailure; |
|
1015 } |
|
1016 |
|
1017 if (aExpectedOutput.CompareF(KDialogCancel) == 0) |
|
1018 { |
|
1019 iCmdResult = iCmdFinalResult = ECancel; |
|
1020 } |
|
1021 else if (aExpectedOutput.CompareF(KDialogQuit) == 0) |
|
1022 { |
|
1023 iCmdResult = iCmdFinalResult = EQuit; |
|
1024 } |
|
1025 else |
|
1026 { |
|
1027 iCmdResult = iCmdFinalResult = EOk; |
|
1028 } |
|
1029 |
|
1030 if (iDialogNumber > 1 && |
|
1031 aExpectedOutput.CompareF(KIdentifyFailure) != 0 && |
|
1032 aExpectedOutput.CompareF(KIdentifySuccess) != 0) |
|
1033 { |
|
1034 iCmdResult = ENext; |
|
1035 } |
|
1036 DeleteFileL(); |
|
1037 WriteOutputDetailsL(); |
|
1038 } |
|
1039 |
|
1040 void CPinPluginTestActive::WriteOutputDetailsL() |
|
1041 { |
|
1042 RFileWriteStream stream; |
|
1043 TInt err = stream.Create(iFs, KInputFile, EFileWrite | EFileShareExclusive); |
|
1044 User::LeaveIfError(err); |
|
1045 stream.PushL(); |
|
1046 |
|
1047 MStreamBuf* streamBuf = stream.Sink(); |
|
1048 streamBuf->SeekL(MStreamBuf::EWrite, EStreamEnd); |
|
1049 stream.WriteInt32L(iOperation); |
|
1050 stream.WriteInt32L(iPinValue.Length()); |
|
1051 stream.WriteL(iPinValue); |
|
1052 stream.WriteInt32L(iIndex); |
|
1053 stream.WriteInt32L(iNewPinLength); |
|
1054 stream.WriteInt32L(iCmdResult); |
|
1055 iOperation = EPinPluginInfo; |
|
1056 stream.WriteInt32L(iOperation); |
|
1057 stream.WriteInt32L(iCmdFinalResult); |
|
1058 stream.WriteInt32L(iDialogNumber); |
|
1059 stream.CommitL(); |
|
1060 CleanupStack::PopAndDestroy(); // stream |
|
1061 } |
|
1062 |
|
1063 void CPinPluginTestActive::ReadOutputDetailsL(TInt& aDialogNumber, TPinValue& aPinValue, TPinPluginInfoMessage& aDisplayedMsg) |
|
1064 { |
|
1065 RFileReadStream stream; |
|
1066 User::LeaveIfError(stream.Open(iFs, KOutputFile, EFileRead | EFileShareExclusive)); |
|
1067 stream.PushL(); |
|
1068 |
|
1069 MStreamBuf* streamBuf = stream.Source(); |
|
1070 TPinValue pinvalue; |
|
1071 TInt pinValueSize; |
|
1072 |
|
1073 aDialogNumber = stream.ReadInt32L(); |
|
1074 |
|
1075 pinValueSize = stream.ReadInt32L(); |
|
1076 HBufC8* pinValueBuf = HBufC8::NewMaxLC(pinValueSize); |
|
1077 TPtr8 pinValuePtr(pinValueBuf->Des()); |
|
1078 stream.ReadL(pinValuePtr, pinValueSize); |
|
1079 aPinValue.Copy(pinValuePtr); |
|
1080 CleanupStack::PopAndDestroy(1, pinValueBuf); |
|
1081 |
|
1082 aDisplayedMsg = static_cast<TPinPluginInfoMessage>(stream.ReadInt32L()); |
|
1083 |
|
1084 CleanupStack::PopAndDestroy(&stream); |
|
1085 } |
|
1086 |
|
1087 void CPinPluginTestActive::DeleteFileL() |
|
1088 { |
|
1089 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
1090 CleanupStack::PushL(fileMan); |
|
1091 TInt err = fileMan->Delete(KInputFile); |
|
1092 if ( err != KErrNotFound && err != KErrNone ) |
|
1093 { |
|
1094 User::LeaveIfError(err); |
|
1095 } |
|
1096 err = fileMan->Delete(KOutputFile); |
|
1097 if (err != KErrNotFound && err != KErrNone ) |
|
1098 { |
|
1099 User::LeaveIfError(err); |
|
1100 } |
|
1101 CleanupStack::PopAndDestroy(fileMan); |
|
1102 } |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|