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