1 /* |
|
2 * Copyright (c) 2005-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 <test/testexecutelog.h> |
|
20 #include "tauthcliservstep.h" |
|
21 #include "authserver/aspubsubdefs.h" |
|
22 #include <e32property.h> |
|
23 #include <authserver/authpatchdata.h> |
|
24 #include <u32hal.h> |
|
25 #include <e32svr.h> |
|
26 |
|
27 using namespace AuthServer; |
|
28 |
|
29 class CAuthActive : CActive |
|
30 { |
|
31 public: |
|
32 CAuthActive(RAuthClient& aClient, CIdentity*& aResult, CTStepClient* aStep, |
|
33 TBool aStop = ETrue) : |
|
34 CActive(EPriorityNormal), |
|
35 iFirstTime(true), |
|
36 iClient(aClient), |
|
37 iResult(aResult), |
|
38 iStep(aStep), |
|
39 iStop(aStop) |
|
40 { |
|
41 CActiveScheduler::Add(this); |
|
42 } |
|
43 |
|
44 void doAuthenticate(TPluginId aPlugin, TTimeIntervalSeconds aTime ) |
|
45 { |
|
46 iPlugin = aPlugin; |
|
47 SetActive(); |
|
48 TRequestStatus* status = &iStatus; |
|
49 User::RequestComplete(status, KErrNone); |
|
50 iFirstTime = ETrue; |
|
51 iTime = aTime; |
|
52 } |
|
53 |
|
54 void DoCancel() |
|
55 { |
|
56 } |
|
57 void RunL() |
|
58 { |
|
59 static TBool client = ETrue; |
|
60 static TBool withString = ETrue; |
|
61 client = !client; |
|
62 if (iFirstTime) |
|
63 { |
|
64 // inactive | plugin id |
|
65 iAe = AuthExpr(0x10274106) | AuthExpr(iPlugin); |
|
66 User::LeaveIfNull(iAe); |
|
67 SetActive(); |
|
68 iStatus = KRequestPending; |
|
69 iClient.AuthenticateL(*iAe, iTime, client, withString, |
|
70 iResult, iStatus); |
|
71 iFirstTime = false; |
|
72 } |
|
73 else |
|
74 { |
|
75 if (iStop) |
|
76 { |
|
77 CActiveScheduler::Stop(); |
|
78 } |
|
79 delete iAe; |
|
80 } |
|
81 iErr = iStatus.Int(); |
|
82 } |
|
83 TBool iFirstTime; |
|
84 RAuthClient& iClient; |
|
85 CIdentity*& iResult; |
|
86 CTStepClient* iStep; |
|
87 CAuthExpression* iAe; |
|
88 TPluginId iPlugin; |
|
89 TTimeIntervalSeconds iTime; |
|
90 TInt iErr; |
|
91 TBool iStop; |
|
92 }; |
|
93 |
|
94 |
|
95 |
|
96 const TPluginId KIdentity1Id = 'I1ID'; |
|
97 _LIT(KIdentity1Desc, "identity-1-desc"); |
|
98 const TPluginId KIdentity2Id = 'I2ID'; |
|
99 _LIT(KIdentity2Desc, "identity-2-desc"); |
|
100 const TPluginId KIdentity3Id = 'I3ID'; |
|
101 |
|
102 |
|
103 CTStepClient::CTStepClient() |
|
104 /** |
|
105 Record this test step's name. |
|
106 */ |
|
107 { |
|
108 SetTestStepName(KTStepClient); |
|
109 } |
|
110 |
|
111 |
|
112 void CTStepClient::TestIdentitiesL() |
|
113 /** |
|
114 Test can retrieve correct identity arrays and |
|
115 descritptinos from auth db. |
|
116 */ |
|
117 { |
|
118 __UHEAP_MARK; |
|
119 RemoveExistingDbL(); |
|
120 |
|
121 RArray<TIdentityId> ids; |
|
122 |
|
123 |
|
124 // one identities (first start adds one) |
|
125 GetIdentitiesLC(ids); |
|
126 TESTL(ids.Count() == 1); |
|
127 CleanupStack::PopAndDestroy(&ids); |
|
128 |
|
129 |
|
130 // two identity |
|
131 AddIdentityL(KIdentity1Id, KIdentity1Desc); |
|
132 GetIdentitiesLC(ids); |
|
133 TESTL(ids.Count() == 2); |
|
134 TESTL(ids[0] == KIdentity1Id || ids[1] == KIdentity1Id); |
|
135 CleanupStack::PopAndDestroy(&ids); |
|
136 TestIdentityL(KIdentity1Id, KIdentity1Desc); |
|
137 |
|
138 |
|
139 // three identities |
|
140 AddIdentityL(KIdentity2Id, KIdentity2Desc); |
|
141 GetIdentitiesLC(ids); |
|
142 TESTL(ids.Count() == 3); |
|
143 TESTL( ids.Find(KIdentity1Id) >= 0 && |
|
144 ids.Find(KIdentity2Id) >= 0); |
|
145 CleanupStack::PopAndDestroy(&ids); |
|
146 TestIdentityL(KIdentity1Id, KIdentity1Desc); |
|
147 TestIdentityL(KIdentity2Id, KIdentity2Desc); |
|
148 |
|
149 // test fail to get description for non-existent identity |
|
150 RAuthClient ac; |
|
151 User::LeaveIfError(ac.Connect()); |
|
152 CleanupClosePushL(ac); |
|
153 |
|
154 |
|
155 TRAPD(r, ac.IdentityStringL(KIdentity3Id)); |
|
156 TESTL(r == KErrAuthServIdentityNotFound); |
|
157 |
|
158 // check id and string retrieval |
|
159 RIdAndStringArray idWithString; |
|
160 ac.IdentitiesWithStringL(idWithString); |
|
161 CleanupClosePushL(idWithString); |
|
162 |
|
163 for (TInt i = 0 ; i < idWithString.Count() ; ++i) |
|
164 { |
|
165 TestIdentityL(idWithString[i]->Id(), *idWithString[i]->String()); |
|
166 INFO_PRINTF3(_L("0x%x - %S"), idWithString[i]->Id(), idWithString[i]->String()); |
|
167 } |
|
168 |
|
169 CleanupStack::PopAndDestroy(2,&ac); |
|
170 |
|
171 __UHEAP_MARKEND; |
|
172 } |
|
173 |
|
174 |
|
175 void CTStepClient::GetIdentitiesLC(RArray<TIdentityId>& aIds) |
|
176 /** |
|
177 Populate the supplied array with the currently available |
|
178 identities, as returned by the server. |
|
179 |
|
180 @param aIds Array to populate. Any existing entries |
|
181 are removed when this function is called. |
|
182 On success, the array is placed on the |
|
183 cleanup stack. |
|
184 */ |
|
185 { |
|
186 aIds.Reset(); |
|
187 CleanupClosePushL(aIds); |
|
188 |
|
189 RAuthClient ac; |
|
190 User::LeaveIfError(ac.Connect()); |
|
191 CleanupClosePushL(ac); |
|
192 ac.IdentitiesL(aIds); // clears array on failure? |
|
193 CleanupStack::PopAndDestroy(&ac); |
|
194 } |
|
195 |
|
196 |
|
197 void CTStepClient::AddIdentityL(TIdentityId aIdentityId, const TDesC& aDesc) |
|
198 /** |
|
199 Add the described identity directly to the database. |
|
200 |
|
201 This function does not use the authentication manager APIs. |
|
202 */ |
|
203 { |
|
204 WaitForServerToReleaseDb(); |
|
205 CAuthDb2* db = CAuthDb2::NewL(iFs); |
|
206 CleanupStack::PushL(db); |
|
207 db->AddIdentityL(aIdentityId, aDesc); |
|
208 CleanupStack::PopAndDestroy(db); |
|
209 } |
|
210 |
|
211 |
|
212 void CTStepClient::TestIdentityL(TIdentityId aIdentityId, const TDesC& aExpDesc) |
|
213 /** |
|
214 Test the supplied identity has the supplied description, |
|
215 as read via the RAuthClient API. |
|
216 |
|
217 @param aIdentityId Identity to retrieve description for. |
|
218 @param aExpDesc The expected description. |
|
219 */ |
|
220 { |
|
221 RAuthClient ac; |
|
222 CleanupClosePushL(ac); |
|
223 User::LeaveIfError(ac.Connect()); |
|
224 HBufC* desc = ac.IdentityStringL(aIdentityId); |
|
225 CleanupStack::PushL(desc); |
|
226 TESTL(*desc == aExpDesc); |
|
227 CleanupStack::PopAndDestroy(2, &ac); |
|
228 } |
|
229 |
|
230 |
|
231 /** |
|
232 TestClientPluginListsL poulates this with a description for |
|
233 every plugin that can be seen with ECOM. |
|
234 */ |
|
235 static RCPointerArray<CPluginDesc> allPlugins; |
|
236 |
|
237 /** |
|
238 Total number of plugins on the device. Should be equal to |
|
239 allPlugins.Count(). |
|
240 */ |
|
241 static TInt totalCount; |
|
242 |
|
243 /** |
|
244 Maximum number of plugins which can are expected. This is |
|
245 an arbitrary value which is used to size an array. It can be |
|
246 changed if required. |
|
247 */ |
|
248 const TInt KMaxSeenCount = 17; |
|
249 |
|
250 /** |
|
251 This array stores how many times each plugin from allPlugins |
|
252 has been seen. It is set by SetSeenCountsL. |
|
253 */ |
|
254 static TFixedArray<TInt, KMaxSeenCount> seenCounts; |
|
255 |
|
256 |
|
257 void CTStepClient::GetDescriptionsFromEComL(RPointerArray<CPluginDesc>& aDescs) |
|
258 /** |
|
259 Populate the supplied array with plugin descriptions generated |
|
260 from the available ECOM plugins. The array can then be used to |
|
261 check the results from the server. |
|
262 */ |
|
263 { |
|
264 WaitForServerToReleaseDb(); |
|
265 |
|
266 CAuthDb2* db = CAuthDb2::NewL(iFs); |
|
267 CleanupStack::PushL(db); |
|
268 |
|
269 // typedef RPointerArray<CImplementationInformation> RImplInfoPtrArray; |
|
270 RCPointerArray<CImplementationInformation> implInfo; |
|
271 REComSession::ListImplementationsL(KCAuthPluginInterfaceUid, implInfo); |
|
272 CleanupClosePushL(implInfo); |
|
273 |
|
274 TInt implCount = implInfo.Count(); |
|
275 TInt err = 0; |
|
276 for (TInt i = 0; i < implCount; ++i) |
|
277 { |
|
278 // avoid RVCT warning C2874W: pi may be used before being set |
|
279 CAuthPluginInterface* pi = 0; |
|
280 |
|
281 TEComResolverParams resolverParams; |
|
282 TBufC8<16> pluginIdTxt; |
|
283 |
|
284 pluginIdTxt.Des().Format(_L8("%x"), implInfo[i]->ImplementationUid().iUid); |
|
285 pluginIdTxt.Des().UpperCase(); |
|
286 resolverParams.SetDataType(pluginIdTxt); |
|
287 |
|
288 //To load plugins from sources other than ROM the patch |
|
289 // data KEnablePostMarketAuthenticationPlugins must be set to True. |
|
290 TUint32 enablePostMarketPlugin = KEnablePostMarketAuthenticationPlugins; |
|
291 |
|
292 #ifdef __WINS__ |
|
293 |
|
294 // Default SymbianOS behavior is to only load auth plugins from ROM. |
|
295 enablePostMarketPlugin = 0; |
|
296 |
|
297 // For the emulator allow the constant to be patched via epoc.ini |
|
298 UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty, |
|
299 (TAny*)"KEnablePostMarketAuthenticationPlugins", &enablePostMarketPlugin); // read emulator property (if present) |
|
300 |
|
301 #endif |
|
302 TAny* plugin = 0; |
|
303 TUid Dtor_ID_Key = TUid::Null(); |
|
304 if(enablePostMarketPlugin == 0) |
|
305 { |
|
306 TRAP(err, plugin = |
|
307 REComSession::CreateImplementationL(KCAuthPluginInterfaceUid, |
|
308 Dtor_ID_Key, |
|
309 resolverParams, |
|
310 KRomOnlyResolverUid)); |
|
311 } |
|
312 |
|
313 else |
|
314 { |
|
315 TRAP(err, plugin = |
|
316 REComSession::CreateImplementationL(KCAuthPluginInterfaceUid, |
|
317 Dtor_ID_Key, |
|
318 resolverParams)); |
|
319 } |
|
320 |
|
321 if (err == KErrAuthServNoSuchPlugin) |
|
322 continue; |
|
323 User::LeaveIfError(err); |
|
324 pi = reinterpret_cast<CAuthPluginInterface*>(plugin); |
|
325 |
|
326 // get training status from db |
|
327 TAuthTrainingStatus ts = db->PluginStatusL(pi->Id()); |
|
328 |
|
329 CleanupStack::PushL(pi); |
|
330 CPluginDesc* pd = CPluginDesc::NewL( |
|
331 pi->Id(), pi->Name(), pi->Type(), |
|
332 ts, pi->MinEntropy(), |
|
333 pi->FalsePositiveRate(), pi->FalseNegativeRate() ); |
|
334 CleanupStack::PopAndDestroy(pi); |
|
335 REComSession::DestroyedImplementation(Dtor_ID_Key); |
|
336 |
|
337 CleanupStack::PushL(pd); |
|
338 aDescs.AppendL(pd); |
|
339 CleanupStack::Pop(pd); |
|
340 } |
|
341 |
|
342 CleanupStack::PopAndDestroy(2, db); |
|
343 REComSession::FinalClose(); |
|
344 } |
|
345 |
|
346 |
|
347 static TBool AreDescsEqual(const CPluginDesc& aLeft, const CPluginDesc& aRight) |
|
348 /** |
|
349 Predicate function determines whether the two supplied |
|
350 plugin descriptions contain the same information. |
|
351 |
|
352 @param aLeft Plugin description to compare to aRight. |
|
353 @param aRight Plugin description to compare to aLeft. |
|
354 @return Zero if the two descriptions contains different |
|
355 information, non-zero otherwise. |
|
356 */ |
|
357 { |
|
358 return aLeft.Id() == aRight.Id() |
|
359 && *aLeft.Name() == *aRight.Name() |
|
360 && aLeft.Type() == aRight.Type() |
|
361 && aLeft.TrainingStatus() == aRight.TrainingStatus() |
|
362 && aLeft.MinEntropy() == aRight.MinEntropy() |
|
363 && aLeft.FalsePositiveRate() == aRight.FalsePositiveRate() |
|
364 && aLeft.FalseNegativeRate() == aRight.FalseNegativeRate(); |
|
365 } |
|
366 |
|
367 |
|
368 inline TBool AreDescsEqual(const CPluginDesc* aLeftP, const CPluginDesc* aRightP) |
|
369 { |
|
370 return AreDescsEqual(*aLeftP, *aRightP); |
|
371 } |
|
372 |
|
373 |
|
374 void CTStepClient::SetSeenCountsL(const RCPointerArray<const CPluginDesc>& aPlugins) |
|
375 /** |
|
376 Update seenCounts array so each entry contains the |
|
377 number of times that plugin was seen in aPlugins. |
|
378 */ |
|
379 { |
|
380 const TInt suppliedCount = aPlugins.Count(); |
|
381 const TInt totalCount = allPlugins.Count(); |
|
382 |
|
383 // i = index into seenCounts |
|
384 for (TInt i = 0; i < totalCount; ++i) |
|
385 { |
|
386 seenCounts[i] = 0; |
|
387 |
|
388 // j = index into aPlugins |
|
389 TInt j = 0; |
|
390 for (; j < suppliedCount; ++j) |
|
391 { |
|
392 if (AreDescsEqual(*allPlugins[i], *aPlugins[j])) |
|
393 { |
|
394 ++seenCounts[i]; |
|
395 break; // assume plugins in allPlugins are unique |
|
396 } |
|
397 } |
|
398 |
|
399 // if plugin not found in reference set then abort |
|
400 TESTL(j < totalCount); |
|
401 } |
|
402 } |
|
403 |
|
404 |
|
405 void CTStepClient::TestClientPluginListsL() |
|
406 /** |
|
407 Test the expected plugins are returned when the |
|
408 client asks the server to list them. |
|
409 */ |
|
410 { |
|
411 __UHEAP_MARK; |
|
412 |
|
413 CleanupClosePushL(allPlugins); |
|
414 GetDescriptionsFromEComL(allPlugins); |
|
415 PrepareTrainedPluginsL(); |
|
416 |
|
417 // re-read plugins now training statuses have been set |
|
418 allPlugins.ResetAndDestroy(); |
|
419 GetDescriptionsFromEComL(allPlugins); |
|
420 CleanupClosePushL(allPlugins); |
|
421 |
|
422 totalCount = allPlugins.Count(); |
|
423 TESTL(totalCount <= KMaxSeenCount); |
|
424 |
|
425 RAuthClient ac; |
|
426 User::LeaveIfError(ac.Connect()); |
|
427 CleanupClosePushL(ac); |
|
428 |
|
429 // ensure all plugins are returned by PluginsL |
|
430 RCPointerArray<const CPluginDesc> fullPlugins; |
|
431 ac.PluginsL(fullPlugins); |
|
432 CleanupClosePushL(fullPlugins); |
|
433 TESTL(fullPlugins.Count() == totalCount); |
|
434 SetSeenCountsL(fullPlugins); |
|
435 for (TInt k = 0; k < totalCount; ++k) |
|
436 { |
|
437 TESTL(seenCounts[k] == 1); |
|
438 } |
|
439 CleanupStack::PopAndDestroy(&fullPlugins); |
|
440 |
|
441 // ensure expected plugins are returned for each type |
|
442 TestTypedPluginsL(ac, EAuthKnowledge); |
|
443 TestTypedPluginsL(ac, EAuthBiometric); |
|
444 TestTypedPluginsL(ac, EAuthToken); |
|
445 |
|
446 TestActivePluginsL(ac); |
|
447 |
|
448 CleanupStack::PopAndDestroy(&ac); |
|
449 |
|
450 TestTrainedPluginsL(); |
|
451 |
|
452 CleanupStack::PopAndDestroy(2, &allPlugins); |
|
453 |
|
454 __UHEAP_MARKEND; |
|
455 } |
|
456 |
|
457 |
|
458 void CTStepClient::TestTypedPluginsL(RAuthClient& aClient, |
|
459 TAuthPluginType aPluginType) |
|
460 /** |
|
461 Ensure the plugin descriptions returned by the server |
|
462 match those directly seen by ECOM. |
|
463 |
|
464 @param aPluginType Type of plugin to retrieve. |
|
465 */ |
|
466 { |
|
467 __UHEAP_MARK; |
|
468 RCPointerArray<const CPluginDesc> typedPlugins; |
|
469 aClient.PluginsOfTypeL(aPluginType, typedPlugins); |
|
470 CleanupClosePushL(typedPlugins); |
|
471 SetSeenCountsL(typedPlugins); |
|
472 |
|
473 for (TInt k = 0; k < totalCount; ++k) |
|
474 { |
|
475 TInt& recCount = seenCounts[k]; |
|
476 TESTL(recCount == (allPlugins[k]->Type() == aPluginType) ? 1 : 0); |
|
477 } |
|
478 |
|
479 CleanupStack::PopAndDestroy(&typedPlugins); |
|
480 __UHEAP_MARKEND; |
|
481 } |
|
482 |
|
483 |
|
484 void CTStepClient::TestActivePluginsL(RAuthClient& aClient) |
|
485 /** |
|
486 Ensure the plugin descriptions returned by the server |
|
487 match those directly seen by ECOM. |
|
488 */ |
|
489 { |
|
490 __UHEAP_MARK; |
|
491 RCPointerArray<const CPluginDesc> activePlugins; |
|
492 aClient.ActivePluginsL(activePlugins); |
|
493 CleanupClosePushL(activePlugins); |
|
494 |
|
495 CleanupStack::PopAndDestroy(&activePlugins); |
|
496 __UHEAP_MARKEND; |
|
497 } |
|
498 |
|
499 void CTStepClient::TestTrainedPluginsL() |
|
500 /** |
|
501 Test the expected plugins are returned when filtering |
|
502 for training types. |
|
503 |
|
504 @param aClient Client with open connection to auth server. |
|
505 */ |
|
506 { |
|
507 RCPointerArray<const CPluginDesc> pids; |
|
508 CleanupClosePushL(pids); |
|
509 |
|
510 RAuthClient ac; |
|
511 User::LeaveIfError(ac.Connect()); |
|
512 CleanupClosePushL(ac); |
|
513 |
|
514 const CPluginDesc* pdsc0 = allPlugins[0]; |
|
515 const CPluginDesc* pdsc1 = allPlugins[1]; |
|
516 const CPluginDesc* pdsc2 = allPlugins[2]; |
|
517 const CPluginDesc* pdsc3 = allPlugins[3]; |
|
518 |
|
519 ac.PluginsWithTrainingStatusL(EAuthUntrained, pids); |
|
520 TInt filterCount = pids.Count(); |
|
521 TESTL(filterCount == totalCount - 4); |
|
522 for (TInt i = 0; i < filterCount; ++i) |
|
523 { |
|
524 const CPluginDesc* pidF = pids[i]; |
|
525 TBool eq0 = AreDescsEqual(pidF, pdsc0); |
|
526 TBool eq1 = AreDescsEqual(pidF, pdsc1); |
|
527 TBool eq2 = AreDescsEqual(pidF, pdsc2); |
|
528 TBool eq3 = AreDescsEqual(pidF, pdsc3); |
|
529 TESTL(!eq0 && !eq1 && !eq2 && !eq3); |
|
530 } |
|
531 |
|
532 pids.ResetAndDestroy(); |
|
533 ac.PluginsWithTrainingStatusL(EAuthTrained, pids); |
|
534 TESTL(pids.Count() == 2); |
|
535 TESTL( (AreDescsEqual(pids[0], pdsc0) && AreDescsEqual(pids[1], pdsc1)) |
|
536 || (AreDescsEqual(pids[0], pdsc1) && AreDescsEqual(pids[1], pdsc0)) ); |
|
537 |
|
538 pids.ResetAndDestroy(); |
|
539 ac.PluginsWithTrainingStatusL(EAuthFullyTrained, pids); |
|
540 TESTL(pids.Count() == 2); |
|
541 TESTL( (AreDescsEqual(pids[0], pdsc2) && AreDescsEqual(pids[1], pdsc3)) |
|
542 || (AreDescsEqual(pids[0], pdsc3) && AreDescsEqual(pids[1], pdsc2)) ); |
|
543 |
|
544 CleanupStack::PopAndDestroy(2, &pids); |
|
545 } |
|
546 |
|
547 |
|
548 void CTStepClient::PrepareTrainedPluginsL() |
|
549 /** |
|
550 Helper function for TestTrainedPluginsL. |
|
551 |
|
552 Train some plugins so they can be filtered out later. |
|
553 This function replaces the database. |
|
554 */ |
|
555 { |
|
556 // There have to be at least four available plugins |
|
557 // to run the training status test. |
|
558 TESTL(allPlugins.Count() >= 4); |
|
559 |
|
560 RemoveExistingDbL(); |
|
561 CAuthDb2* db = CAuthDb2::NewLC(iFs); |
|
562 |
|
563 db->AddIdentityL(KIdentity1Id, KIdentity1Desc); |
|
564 db->AddIdentityL(KIdentity2Id, KIdentity2Desc); |
|
565 |
|
566 const CTransientKeyInfo& tki = *iId1Keys[0]; |
|
567 |
|
568 // partially train plugins zero and one |
|
569 TPluginId pid0 = allPlugins[0]->Id(); |
|
570 TPluginId pid1 = allPlugins[1]->Id(); |
|
571 db->SetTrainedPluginL(KIdentity1Id, pid0, tki); |
|
572 db->SetTrainedPluginL(KIdentity2Id, pid1, tki); |
|
573 |
|
574 // fully train plugins two and three |
|
575 TPluginId pid2 = allPlugins[2]->Id(); |
|
576 TPluginId pid3 = allPlugins[3]->Id(); |
|
577 db->SetTrainedPluginL(KIdentity1Id, pid2, tki); |
|
578 db->SetTrainedPluginL(KIdentity2Id, pid2, tki); |
|
579 db->SetTrainedPluginL(KIdentity1Id, pid3, tki); |
|
580 db->SetTrainedPluginL(KIdentity2Id, pid3, tki); |
|
581 |
|
582 CleanupStack::PopAndDestroy(db); |
|
583 } |
|
584 |
|
585 TBool CTStepClient::TestMultiAuthL() |
|
586 { |
|
587 INFO_PRINTF1(_L("Testing only a single client can make an auth ")); |
|
588 INFO_PRINTF1(_L("request at any one time")); |
|
589 |
|
590 RAuthClient ac1; |
|
591 User::LeaveIfError(ac1.Connect()); |
|
592 CleanupClosePushL(ac1); |
|
593 |
|
594 RAuthClient ac2; |
|
595 User::LeaveIfError(ac2.Connect()); |
|
596 CleanupClosePushL(ac2); |
|
597 |
|
598 CIdentity* result1 = 0; |
|
599 CAuthActive active1(ac1, result1, this); |
|
600 active1.doAuthenticate(KTestPluginBlocking,0); |
|
601 |
|
602 CIdentity* result2 = 0; |
|
603 CAuthActive active2(ac2, result2, this, EFalse); |
|
604 active2.doAuthenticate(KTestPluginBlocking,0); |
|
605 |
|
606 CActiveScheduler::Start(); |
|
607 |
|
608 TEST(active1.iErr == KErrNone); |
|
609 TEST(active2.iErr == KErrServerBusy); |
|
610 |
|
611 delete result1; |
|
612 delete result2; |
|
613 |
|
614 CleanupStack::PopAndDestroy(2,&ac1); |
|
615 return ETrue; |
|
616 } |
|
617 |
|
618 |
|
619 TBool CTStepClient::TestAuthenticateL() |
|
620 /** |
|
621 Send simple authentication request. |
|
622 */ |
|
623 { |
|
624 // create a transient key |
|
625 CProtectionKey* key = CProtectionKey::NewLC(8); |
|
626 CTransientKeyInfo* tki = CTransientKeyInfo::NewLC(KTestPluginId22); |
|
627 |
|
628 CTransientKey* tk = tki->CreateTransientKeyL(KIdentifyData); |
|
629 CleanupStack::PushL(tk); |
|
630 |
|
631 CEncryptedProtectionKey* epKey = tk->EncryptL(*key); |
|
632 CleanupStack::PushL(epKey); |
|
633 |
|
634 tki->SetEncryptedProtectionKeyL(epKey); |
|
635 CleanupStack::Pop(epKey); // now owned by tki |
|
636 |
|
637 // create identity 22, which identified by test plugin |
|
638 WaitForServerToReleaseDb(); |
|
639 CAuthDb2* db = CAuthDb2::NewL(iFs); |
|
640 CleanupStack::PushL(db); |
|
641 db->AddIdentityL(22, _L("22-desc")); |
|
642 db->SetTrainedPluginL(22, KTestPluginId22, *tki); |
|
643 |
|
644 CleanupStack::PopAndDestroy(4, key); // tki, tk, db |
|
645 |
|
646 RAuthClient ac; |
|
647 User::LeaveIfError(ac.Connect()); |
|
648 CleanupClosePushL(ac); |
|
649 |
|
650 RAuthMgrClient amc; |
|
651 User::LeaveIfError(amc.Connect()); |
|
652 CleanupClosePushL(amc); |
|
653 |
|
654 TInt eventId = KUnknownIdentity; |
|
655 TLastAuth lastAuth; |
|
656 TPckg<TLastAuth> lastAuthPckg(lastAuth); |
|
657 |
|
658 TInt err = RProperty::Get(KAuthServerSecureId, KUidAuthServerLastAuth, |
|
659 lastAuthPckg); |
|
660 RProperty::Get(KAuthServerSecureId, KUidAuthServerAuthChangeEvent, eventId); |
|
661 TESTL(eventId == KUnknownIdentity); |
|
662 TESTL(lastAuth.iId == KUnknownIdentity); |
|
663 TESTL(lastAuth.iAuthTime == 0); |
|
664 TESTL(lastAuth.iMaxCombinations == 0); |
|
665 TESTL(lastAuth.iFalsePositiveRate == 0); |
|
666 TESTL(lastAuth.iFalseNegativeRate == 0); |
|
667 TESTL(lastAuth.iNumFactors == 0); |
|
668 |
|
669 // authenticate the client with the test plugin but using type |
|
670 |
|
671 amc.SetPreferredTypePluginL(EAuthKnowledge, |
|
672 KTestPluginId22); |
|
673 CleanupStack::PopAndDestroy(&amc); |
|
674 TESTL(KTestPluginId22 == ac.PreferredTypePluginL(EAuthKnowledge)); |
|
675 |
|
676 CAuthExpression* ae = AuthExpr(EAuthKnowledge); // plugin type |
|
677 User::LeaveIfNull(ae); |
|
678 CleanupStack::PushL(ae); |
|
679 |
|
680 CIdentity* result = 0; |
|
681 result = ac.AuthenticateL( |
|
682 *ae, // aExpression |
|
683 0, // aTimeout |
|
684 ETrue, // aClientSpecificKey |
|
685 EFalse); // aWithString |
|
686 INFO_PRINTF3(_L("1. Id = 0x%x , KeyLength = %d\n"), result->Id(), |
|
687 result->Key().KeyData().Size()); |
|
688 TESTL(result->Id() == 22); |
|
689 delete result; |
|
690 |
|
691 RProperty::Get(KAuthServerSecureId, KUidAuthServerLastAuth, lastAuthPckg); |
|
692 RProperty::Get(KAuthServerSecureId, KUidAuthServerAuthChangeEvent, eventId); |
|
693 TESTL(eventId == eventId); |
|
694 TESTL(lastAuth.iId == 22); |
|
695 TTime now; |
|
696 TTimeIntervalSeconds since; |
|
697 now.UniversalTime(); |
|
698 now.SecondsFrom(lastAuth.iAuthTime, since); |
|
699 TESTL(since < TTimeIntervalSeconds(5)); |
|
700 TESTL(lastAuth.iMaxCombinations == KEntropy); |
|
701 TESTL(lastAuth.iFalsePositiveRate == KFalsePos); |
|
702 TESTL(lastAuth.iFalseNegativeRate == KFalseNeg); |
|
703 TESTL(lastAuth.iNumFactors == 1); |
|
704 |
|
705 |
|
706 // authenticate again, to get cached value |
|
707 result = ac.AuthenticateL( |
|
708 *ae, // aExpression |
|
709 55, // aTimeout |
|
710 ETrue, // aClientSpecificKey |
|
711 ETrue); // aWithString |
|
712 TDesC p = result->String(); |
|
713 INFO_PRINTF4(_L("2. Id = 0x%x , KeyLength = %d, String = %S\n"), result->Id(), |
|
714 result->Key().KeyData().Size(), &p); |
|
715 TESTL(result->Id() == 22); |
|
716 delete result; |
|
717 |
|
718 |
|
719 // deauthenticate |
|
720 TRAP(err, ac.DeauthenticateL()); |
|
721 TESTL(err == KErrNone); |
|
722 |
|
723 RProperty::Get(KAuthServerSecureId, KUidAuthServerLastAuth, lastAuthPckg); |
|
724 RProperty::Get(KAuthServerSecureId, KUidAuthServerAuthChangeEvent, eventId); |
|
725 TESTL(eventId == KUnknownIdentity); |
|
726 TESTL(lastAuth.iId == KUnknownIdentity); |
|
727 TESTL(lastAuth.iAuthTime == 0); |
|
728 TESTL(lastAuth.iMaxCombinations == 0); |
|
729 TESTL(lastAuth.iFalsePositiveRate == 0); |
|
730 TESTL(lastAuth.iFalseNegativeRate == 0); |
|
731 TESTL(lastAuth.iNumFactors == 0); |
|
732 |
|
733 result = 0; |
|
734 CAuthActive active(ac, result, this); |
|
735 active.doAuthenticate(KTestPluginId22,0); |
|
736 CActiveScheduler::Start(); |
|
737 INFO_PRINTF3(_L("3. Id = 0x%x , KeyLength = %d"), result->Id(), |
|
738 result->Key().KeyData().Size()); |
|
739 TESTL(result->Id() == 22); |
|
740 delete result; |
|
741 |
|
742 |
|
743 // unknown |
|
744 result = 0; |
|
745 active.doAuthenticate(KTestPluginIdUnknown,0); |
|
746 CActiveScheduler::Start(); |
|
747 INFO_PRINTF2(_L("4. Id = 0x%x"),result->Id()); |
|
748 TESTL(result->Id() == KUnknownIdentity); |
|
749 delete result; |
|
750 |
|
751 |
|
752 // failure (bad plugin) |
|
753 result = 0; |
|
754 active.doAuthenticate(0xD0DAD0DA,0); |
|
755 CActiveScheduler::Start(); |
|
756 INFO_PRINTF3(_L("5. CAuthActive:RunL err %d : res = 0x%x"), |
|
757 active.iErr, result); |
|
758 TESTL(active.iErr == KErrAuthServNoSuchPlugin && result == 0); |
|
759 |
|
760 CleanupStack::PopAndDestroy(2, &ac); // ae, ac |
|
761 return ETrue; |
|
762 } |
|
763 |
|
764 void CTStepClient::TestSetIdentityStrL() |
|
765 { |
|
766 // assumes TestAuthenticateL has been called and id 22 is created |
|
767 RAuthClient ac; |
|
768 User::LeaveIfError(ac.Connect()); |
|
769 CleanupClosePushL(ac); |
|
770 |
|
771 _LIT(KId22DescNew, "ID22NewDesc"); |
|
772 |
|
773 HBufC* desc = ac.IdentityStringL(22); |
|
774 CleanupStack::PushL(desc); |
|
775 TESTL(*desc == _L("22-desc")); |
|
776 CleanupStack::PopAndDestroy(desc); |
|
777 |
|
778 ac.SetIdentityStringL(22, KId22DescNew); |
|
779 |
|
780 desc = ac.IdentityStringL(22); |
|
781 CleanupStack::PushL(desc); |
|
782 TESTL(*desc == KId22DescNew); |
|
783 CleanupStack::PopAndDestroy(desc); |
|
784 |
|
785 CleanupStack::PopAndDestroy(&ac); |
|
786 } |
|
787 |
|
788 |
|
789 |
|
790 TVerdict CTStepClient::doTestStepL() |
|
791 { |
|
792 if (TestStepResult() != EPass) |
|
793 return TestStepResult(); |
|
794 SetTestStepResult(EPass); |
|
795 __UHEAP_MARK; |
|
796 |
|
797 CActiveScheduler::Install(iActSchd); |
|
798 |
|
799 INFO_PRINTF1(_L("Test identities")); |
|
800 TestIdentitiesL(); |
|
801 |
|
802 INFO_PRINTF1(_L("Test ClientPluginLists")); |
|
803 TestClientPluginListsL(); |
|
804 |
|
805 INFO_PRINTF1(_L("Test Authenticate")); |
|
806 TestAuthenticateL(); |
|
807 |
|
808 INFO_PRINTF1(_L("Test MultiAuth")); |
|
809 TestMultiAuthL(); |
|
810 |
|
811 INFO_PRINTF1(_L("Test SetIdentityStr")); |
|
812 TestSetIdentityStrL(); |
|
813 |
|
814 __UHEAP_MARKEND; |
|
815 |
|
816 return EPass; |
|
817 } |
|
818 |
|
819 |
|