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