os/security/cryptoservices/certificateandkeymgmt/tcertstore/t_certstoreactions.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004-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 "t_certstoreactions.h"
    20 #include "t_certstoreout.h"
    21 #include "t_certstoredefs.h"
    22 #include "t_input.h"
    23 #include <x509cert.h>
    24 #include <wtlscert.h>
    25 #include <securityerr.h>
    26 #include <ecom/ecom.h>
    27 #include "testutilclient.h"
    28 #include <swicertstore.h>
    29 
    30 // CCertStoreChangeNotifier ////////////////////////////////////////////////////////////// 
    31  CCertStoreChangeNotifier* CCertStoreChangeNotifier::NewL(TInt& aNotificationFlag)
    32  	{
    33  	CCertStoreChangeNotifier* self = new(ELeave) CCertStoreChangeNotifier(aNotificationFlag);
    34  	CleanupStack::PushL(self);
    35  	self->ConstructL();
    36  	CleanupStack::Pop();
    37  	return self;
    38  	}
    39  CCertStoreChangeNotifier::~CCertStoreChangeNotifier()
    40  	{
    41  	Cancel();
    42 	iCertStoreChangeProperty.Close();
    43  	}
    44  CCertStoreChangeNotifier::CCertStoreChangeNotifier(TInt& aNotificationFlag): CActive(EPriorityHigh), iNotifiedCounter(aNotificationFlag)
    45  	{
    46  	CActiveScheduler::Add(this);
    47  	}	
    48  void CCertStoreChangeNotifier::ConstructL()
    49   	{
    50  	TInt r=iCertStoreChangeProperty.Attach(KUnifiedCertStorePropertyCat,EUnifiedCertStoreFlag,EOwnerThread);
    51  	User::LeaveIfError(r);
    52  	}
    53  void CCertStoreChangeNotifier::StartNotification()
    54  	{
    55  	iCertStoreChangeProperty.Subscribe(iStatus);
    56  	SetActive();
    57  	}	
    58  void CCertStoreChangeNotifier::DoCancel()
    59  	{
    60  	iCertStoreChangeProperty.Cancel();
    61  	}
    62  void CCertStoreChangeNotifier::RunL()
    63  	{
    64  	iNotifiedCounter++;
    65  	if (iCompleteStatus)
    66 	 	{
    67 	 	 User::RequestComplete(iCompleteStatus, KErrNone);	
    68 	 	}
    69  	}
    70 void CCertStoreChangeNotifier::SetCompleteStatus(TRequestStatus* aStatus)
    71 	{
    72 	iCompleteStatus=aStatus;
    73 	}
    74 
    75 // COpenCertStore //////////////////////////////////////////////////////////////
    76 
    77 _LIT(KCOpenCertStore, "COpenCertStore");
    78 
    79 COpenCertStore::~COpenCertStore()
    80 	{
    81 	if (iSet)
    82 		{
    83 		switch (iType)
    84 			{
    85 			case EUnifiedCertStore:
    86 				delete iUnifiedCertStore;
    87 				break;
    88 			
    89 			case ESWICertStore:
    90 				iSwiCertStore->Release();
    91 				break;
    92 			
    93 			default:
    94 				User::Panic(KCOpenCertStore, 1);
    95 			}
    96 		}
    97 	}
    98 
    99 void COpenCertStore::SetCertStore(CUnifiedCertStore* aCertStore)
   100 	{
   101 	__ASSERT_ALWAYS(!iSet, User::Panic(KCOpenCertStore, 1));
   102 	iType = EUnifiedCertStore;
   103 	iUnifiedCertStore = aCertStore;
   104 	iSet = ETrue;
   105 	}
   106    
   107 CUnifiedCertStore& COpenCertStore::AsUnifiedCertStore()
   108 	{
   109 	__ASSERT_ALWAYS(iSet && iType == EUnifiedCertStore, User::Panic(KCOpenCertStore, 1));
   110 	return *iUnifiedCertStore;
   111 	}
   112 
   113 
   114 void COpenCertStore::SetCertStore(CSWICertStore* aCertStore)
   115 	{
   116 	__ASSERT_ALWAYS(!iSet, User::Panic(KCOpenCertStore, 1));
   117 	iType = ESWICertStore;
   118 	iSwiCertStore = aCertStore;
   119 	iSet = ETrue;
   120 	}
   121 
   122 CSWICertStore& COpenCertStore::AsSWICertStore()
   123 	{
   124 	__ASSERT_ALWAYS(iSet && iType == ESWICertStore, User::Panic(KCOpenCertStore, 1));
   125 	return *iSwiCertStore;
   126 	}
   127 
   128 
   129 TCertStoreType COpenCertStore::Type()
   130 	{
   131 	__ASSERT_ALWAYS(iSet, User::Panic(KCOpenCertStore, 1));
   132 	return iType;
   133 	}
   134 
   135 
   136 MCertStore& COpenCertStore::CertStore()
   137 	{
   138 	__ASSERT_ALWAYS(iSet, User::Panic(KCOpenCertStore, 1));
   139 	
   140 	MCertStore* result = NULL;
   141 
   142 	switch (iType)
   143 		{
   144 		case EUnifiedCertStore:
   145 			result = iUnifiedCertStore;
   146 			break;
   147 			
   148 		case ESWICertStore:
   149 			result = iSwiCertStore;
   150 			break;
   151 			
   152 		default:
   153 			User::Panic(KCOpenCertStore, 1);
   154 		}
   155 
   156 	return *result;
   157 	}
   158 
   159 // CSharedData /////////////////////////////////////////////////////////////////
   160 
   161 CSharedData::~CSharedData()
   162 	{
   163 	iCertStores.ResetAndDestroy();
   164 	iCertStores.Close();
   165 	DeleteCertificateAppInfoManager();
   166 	REComSession::FinalClose();
   167 	}
   168 
   169 void CSharedData::InitCertificateAppInfoManagerL()
   170 	{
   171 	ASSERT(!iCertificateAppInfoManager);
   172 	User::LeaveIfError(iFs.Connect());
   173 	iCertificateAppInfoManager = CCertificateAppInfoManager::NewL(iFs, ETrue);
   174 	}
   175 
   176 void CSharedData::DeleteCertificateAppInfoManager()
   177 	{
   178 	if (iCertificateAppInfoManager)
   179 		{
   180 		delete iCertificateAppInfoManager;
   181 		iCertificateAppInfoManager = NULL;
   182 		iFs.Close();
   183 		}
   184 	}
   185 
   186 RPointerArray<COpenCertStore>& CSharedData::CertStores()
   187 	{
   188 	return iCertStores;
   189 	}
   190 
   191 /////////////////////////////////////////////////////////////////////////////////
   192 //CCertStoreTestAction base class
   193 /////////////////////////////////////////////////////////////////////////////////
   194 
   195 CCertStoreTestAction::~CCertStoreTestAction()
   196 	{
   197 	}
   198 
   199 CCertStoreTestAction::CCertStoreTestAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
   200 	CTestAction(aConsole, aOut), iFs(aFs)
   201 	{
   202 	}
   203 
   204 CSharedData& CCertStoreTestAction::CertStoreSharedData()
   205 	{
   206 	if (!SharedData())
   207 		{
   208 		SetSharedData(new CSharedData);
   209 		}
   210 
   211     CSharedData* data = static_cast<CSharedData*>(SharedData());
   212 	ASSERT(data); // panic if out of memory
   213 	return *data;
   214 	}
   215 
   216 void CCertStoreTestAction::DoPerformPrerequisite(TRequestStatus& aStatus)
   217 	{
   218 	// Ensure shared data is already created to prevent panic in oom test
   219 	CertStoreSharedData();
   220 	
   221 	iActionState = EAction;
   222 	TRequestStatus* status = &aStatus;
   223 	User::RequestComplete(status, KErrNone);
   224 	}
   225 
   226 void CCertStoreTestAction::DoPerformPostrequisite(TRequestStatus& aStatus)
   227 	{
   228 	TRequestStatus* status = &aStatus;
   229 	User::RequestComplete(status, KErrNone);
   230 	}
   231 
   232 CCertificateAppInfoManager* CCertStoreTestAction::TheCertificateAppInfoManager()
   233 	{
   234 	return CertStoreSharedData().iCertificateAppInfoManager;
   235 	}
   236 
   237 void CCertStoreTestAction::InitTheCertificateAppInfoManagerL()
   238 	{
   239 	CertStoreSharedData().InitCertificateAppInfoManagerL();
   240 	}
   241 
   242 void CCertStoreTestAction::DeleteTheCertificateAppInfoManager()
   243 	{
   244 	CertStoreSharedData().DeleteCertificateAppInfoManager();
   245 	}
   246 
   247 RPointerArray<COpenCertStore>& CCertStoreTestAction::CertStores()
   248 	{
   249 	return CertStoreSharedData().CertStores();
   250 	}
   251 
   252 TInt CCertStoreTestAction::CertStoreCount()
   253 	{
   254 	return CertStores().Count();
   255 	}
   256 
   257 TCertStoreType CCertStoreTestAction::CertStoreType(TInt aIndex)
   258 	{
   259 	return CertStores()[aIndex]->Type();
   260 	}
   261 
   262 MCertStore& CCertStoreTestAction::CertStore(TInt aIndex)
   263 	{
   264 	return CertStores()[aIndex]->CertStore();
   265 	}
   266 
   267 void CCertStoreTestAction::AddCertStoreL(CUnifiedCertStore* aCertStore)
   268 	{
   269 	COpenCertStore* openStore = new (ELeave) COpenCertStore;
   270 	CleanupStack::PushL(openStore);
   271   	User::LeaveIfError(CertStores().Append(openStore));
   272 	CleanupStack::Pop(openStore);
   273 	openStore->SetCertStore(aCertStore); // takes ownership
   274 	}
   275 
   276 CUnifiedCertStore& CCertStoreTestAction::UnifiedCertStore(TInt aIndex)
   277 	{
   278 	return CertStores()[aIndex]->AsUnifiedCertStore();
   279 	}
   280 
   281 
   282 void CCertStoreTestAction::AddCertStoreL(CSWICertStore* aCertStore)
   283 	{
   284 	COpenCertStore* openStore = new (ELeave) COpenCertStore;
   285 	CleanupStack::PushL(openStore);
   286 	User::LeaveIfError(CertStores().Append(openStore));
   287 	CleanupStack::Pop(openStore);
   288 	openStore->SetCertStore(aCertStore); // takes ownership
   289 	}
   290 
   291 CSWICertStore& CCertStoreTestAction::SWICertStore(TInt aIndex)
   292 	{
   293 	return CertStores()[aIndex]->AsSWICertStore();
   294 	}
   295 
   296 
   297 void CCertStoreTestAction::RemoveCertStore(TInt aIndex)
   298 	{
   299 	COpenCertStore* openStore = CertStores()[aIndex];
   300 	TBool delCertstore = EFalse;
   301 	
   302 	if (openStore->Type() == ESWICertStore)
   303 			{
   304 			delCertstore = ETrue;
   305 			}
   306 			
   307 	CertStores().Remove(aIndex);
   308 	delete openStore;
   309 	
   310 	if (delCertstore)
   311 			{
   312 			RTestUtilSession testutil;
   313 			User::LeaveIfError(testutil.Connect());
   314 			CleanupClosePushL(testutil);
   315 			
   316 			TDriveUnit sysDrive (RFs::GetSystemDrive());
   317 			TDriveName driveName(sysDrive.Name());			
   318 			TBuf<64> certstoreFile (driveName);
   319 			certstoreFile.Append(_L("\\Resource\\SwiCertstore\\"));
   320 			testutil.RmDir(certstoreFile);
   321 
   322 			CleanupStack::PopAndDestroy(&testutil);
   323 			}
   324 	}
   325 /////////////////////////////////////////////////////////////////////////////////
   326 //CSubscriberAction base class
   327 /////////////////////////////////////////////////////////////////////////////////
   328 CSubscriberAction::~CSubscriberAction()
   329 	{
   330 	if (iNotifier)
   331 		delete iNotifier;
   332 	}
   333 CSubscriberAction::CSubscriberAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
   334 :CCertStoreTestAction(aFs, aConsole, aOut)
   335 	{	
   336 	}
   337 void CSubscriberAction::ConstructL(const TTestActionSpec& aTestActionSpec)
   338 	{
   339 	CCertStoreTestAction::ConstructL(aTestActionSpec);
   340 	TInt pos = 0;
   341 	TInt err = KErrNone;
   342 	TPtrC8 ptr1 = Input::ParseElement(aTestActionSpec.iActionBody, KChangeNotifiedStart, KChangeNotifiedEnd, pos, err);
   343 	if (ptr1 != KNullDesC8)
   344 		{
   345 		TLex8 lexi(ptr1);
   346 		TInt val;
   347 		TInt ret=lexi.Val(val);
   348 		if (val != 0)
   349 			{
   350 			iNotificationSubscribed=1;
   351 			}
   352 		}		
   353 	}
   354 /////////////////////////////////////////////////////////////////
   355 //CInitialiseCertStore::
   356 ///////////////////////////////////////////////////////////////////
   357 CTestAction* CInitialiseCertStore::NewL(RFs& aFs,
   358 										CConsoleBase& aConsole,
   359 										Output& aOut,
   360 										const TTestActionSpec& aTestActionSpec)
   361 	{
   362 	CTestAction* self = CInitialiseCertStore::NewLC(aFs, 
   363 		aConsole, aOut,	aTestActionSpec);
   364 	CleanupStack::Pop(self);
   365 	return self;
   366 	}
   367 
   368 CTestAction* CInitialiseCertStore::NewLC(RFs& aFs,
   369 										 CConsoleBase& aConsole, 
   370 										 Output& aOut, 
   371 										 const TTestActionSpec& aTestActionSpec)
   372 	{
   373 	CInitialiseCertStore* self = new(ELeave) CInitialiseCertStore(aFs, aConsole, aOut);
   374 	CleanupStack::PushL(self);
   375 	self->ConstructL(aTestActionSpec);
   376 	return self;
   377 	}
   378 
   379 CInitialiseCertStore::~CInitialiseCertStore()
   380 	{
   381 	delete iNewUnifiedCertStore;
   382  	iFilterOrdering.Close();
   383  	iExpectedOrderingResult.Close();	
   384 	}
   385 
   386 CInitialiseCertStore::CInitialiseCertStore(RFs& aFs, 
   387 										   CConsoleBase& aConsole, 
   388 										   Output& aOut)
   389 
   390 	:CCertStoreTestAction(aFs, aConsole, aOut), iState(ENew)
   391 	{
   392 	}
   393 
   394 void CInitialiseCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
   395 	{
   396 	CCertStoreTestAction::ConstructL(aTestActionSpec);
   397 
   398 	TInt err = KErrNone;
   399 	TInt pos = 0;
   400 	TPtrC8 ptr = 
   401 		Input::ParseElement(aTestActionSpec.iActionBody, KModeStart, KModeEnd, pos, err);
   402 	if (ptr == KNullDesC8)
   403 		{
   404 		User::Leave(KErrNotFound);
   405 		}
   406 
   407 	if (ptr == _L8("read"))
   408 		{
   409 		iOpenedForWrite = EFalse;
   410 		}
   411 	else if (ptr == _L8("write"))
   412 		{
   413 		iOpenedForWrite = ETrue;
   414 		}
   415 	else
   416 		{
   417 		User::Leave(KErrNotSupported);
   418 		}
   419 	pos = 0;
   420 	err = KErrNone;
   421 	TPtrC8 ptr1 = Input::ParseElement(aTestActionSpec.iActionBody, KOrderingFilterStart, KOrderingFilterEnd, pos, err);
   422 	if (ptr1 != KNullDesC8)
   423 		{
   424 		TInt lastPos=0;
   425 		TInt startPos=0;
   426 		TLex8 lexi;
   427 		do 
   428 			{
   429 			startPos=lastPos;
   430 			while (lastPos<ptr1.Length() && ptr1[lastPos]!=',')
   431 				{
   432 				lastPos++;
   433 				}
   434 			TPtrC8 uidInA(&ptr1[startPos], lastPos-startPos);
   435 			TLex8 lexi(uidInA);
   436 			TInt32 uidInD=0;
   437 			TInt err=lexi.Val(uidInD);
   438 			User::LeaveIfError(iFilterOrdering.Append(uidInD));
   439 			lastPos++;
   440 			}
   441 		while (lastPos < ptr1.Length());	
   442 		}
   443 	pos = 0;
   444 	err = KErrNone;		
   445 	TPtrC8 ptr2 = Input::ParseElement(aTestActionSpec.iActionResult, KOrderingResultStart, KOrderingResultEnd, pos, err);	
   446 	if (ptr2 != KNullDesC8)
   447 		{
   448 		TInt lastPos=0;
   449 		TInt startPos=0;
   450 		TLex8 lexi;
   451 		do 
   452 			{
   453 			startPos=lastPos;
   454 			while (lastPos<ptr2.Length() && ptr2[lastPos]!=',')
   455 				{
   456 				lastPos++;
   457 				}
   458 			TPtrC8 uidInA(&ptr2[startPos], lastPos-startPos);
   459 			TLex8 lexi(uidInA);
   460 			TInt32 uidInD=0;
   461 			TInt err=lexi.Val(uidInD);
   462 			User::LeaveIfError(iExpectedOrderingResult.Append(uidInD));
   463 			lastPos++;
   464 			}
   465 		while (lastPos < ptr2.Length());	
   466 		}		
   467 	pos = 0;
   468 	err = KErrNone;
   469 	
   470 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
   471 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
   472 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
   473 	CleanupStack::PopAndDestroy(result);
   474 	}
   475 
   476 void CInitialiseCertStore::PerformAction(TRequestStatus& aStatus)
   477 	{
   478 	if (aStatus != KErrNone)
   479 		{
   480 		iState = EFinished;
   481 		}
   482 	
   483 	switch (iState)
   484 		{
   485 		case ENew:
   486 			__ASSERT_DEBUG(!iNewUnifiedCertStore, User::Panic(_L("CInitialiseCertStore"), 1));
   487  			iNewUnifiedCertStore = CUnifiedCertStore::NewL(iFs, iOpenedForWrite, iFilterOrdering);
   488  			
   489  			iNewUnifiedCertStore->Initialize(aStatus);		
   490 			iState = EAppend;
   491 			break;
   492 
   493 		case EAppend:
   494 			{	
   495 			AddCertStoreL(iNewUnifiedCertStore);
   496 			iNewUnifiedCertStore = 0; // we don't own this any more
   497 			if (iFilterOrdering.Count()==0)
   498 				{
   499 				iState = EFinished;
   500 				}
   501 			else
   502 				{
   503 				iState = ECheckOrder;
   504 				}
   505 			TRequestStatus* status = &aStatus;
   506 			User::RequestComplete(status, KErrNone);		
   507 			}
   508 			break;
   509 
   510 		case ECheckOrder:
   511 			{
   512 			TInt ret=KErrNone;
   513 			TInt count = UnifiedCertStore().CertStoreCount();
   514 			MCTCertStore* p=NULL;
   515 			TInt j=-1;
   516 			TInt32 previous=0;
   517 			TInt32 current=0;			
   518 			for (TInt i=0;i<count;i++)
   519 				{
   520 				p=&(UnifiedCertStore().CertStore(i));
   521 				current = p->Token().TokenType().Type().iUid;
   522 				if (previous != current)
   523 					{
   524 					j++;
   525 					previous = current;
   526 					}
   527 				TInt32 l1=iExpectedOrderingResult[j];
   528 				if (current != iExpectedOrderingResult[j])
   529 					{
   530 					ret=KErrNotFound;
   531 					break;
   532 					}
   533 				}
   534 			if (count<iExpectedOrderingResult.Count())
   535 				{
   536 				ret=KErrNotFound;
   537 				}
   538 			iState = EFinished;
   539 			TRequestStatus* status = &aStatus;		
   540 			User::RequestComplete(status, ret);
   541 			}
   542 			break;
   543 		case EFinished:
   544 			{
   545 			TRequestStatus* status = &aStatus;
   546 			User::RequestComplete(status, aStatus.Int());
   547 			if (aStatus == iExpectedResult)
   548 				{
   549 				iResult = ETrue;
   550 				}
   551 			else
   552 				{
   553 				iResult = EFalse;
   554 				}
   555 			if (aStatus == KErrNoMemory)
   556 				{	
   557 				iState = ENew;
   558 				}
   559 			else
   560 				{
   561 				iFinished = ETrue;
   562 				}
   563 			}
   564 			break;
   565 		}
   566 	}
   567 
   568 void CInitialiseCertStore::PerformCancel()
   569 	{
   570 	switch (iState)
   571 		{
   572 		case EAppend:
   573 			ASSERT(iNewUnifiedCertStore);
   574 			iNewUnifiedCertStore->CancelInitialize();
   575 			break;
   576 
   577 		default:
   578 			// do nothing
   579 			break;
   580 		}
   581 	}
   582 
   583 void CInitialiseCertStore::Reset()
   584 	{
   585 	iState = ENew;
   586 	delete iNewUnifiedCertStore;
   587 	iNewUnifiedCertStore = 0;
   588 	}
   589 
   590 void CInitialiseCertStore::DoReportAction()
   591 	{
   592 	iOut.writeString(_L("Initializing certstore manager..."));
   593 	iOut.writeNewLine();
   594 	}
   595 
   596 void CInitialiseCertStore::DoCheckResult(TInt aError)
   597 	{
   598 	if (iFinished)
   599 		{
   600 		if (aError == KErrNone)
   601 			{
   602 			iConsole.Write(_L("\tstore manager initialised successfully\n"));
   603 			iOut.writeString(_L("\tstore manager initialised successfully"));
   604 			iOut.writeNewLine();
   605 			iOut.writeNewLine();
   606 			}
   607 		else if (aError == KErrInUse)
   608 			{
   609 			iConsole.Write(_L("\tstore manager initialised error : KErrInUse\n"));
   610 			iOut.writeString(_L("\tstore manager initialization error : KErrInUse"));
   611 			iOut.writeNewLine();
   612 			iOut.writeNewLine();
   613 			}
   614 		}
   615 	}
   616 
   617 /////////////////////////////////////////////////////////////////
   618 //COnlyCreateCertStore::
   619 ///////////////////////////////////////////////////////////////////
   620 
   621 CTestAction* COnlyCreateCertStore::NewL(RFs& aFs,
   622 										CConsoleBase& aConsole, 
   623 										Output& aOut, 
   624 										const TTestActionSpec& aTestActionSpec)
   625 	{
   626 	COnlyCreateCertStore* self = new(ELeave) COnlyCreateCertStore(aFs, aConsole, aOut);
   627 	CleanupStack::PushL(self);
   628 	self->ConstructL(aTestActionSpec);
   629 	CleanupStack::Pop(self);
   630 	return self;
   631 	}
   632 
   633 COnlyCreateCertStore::COnlyCreateCertStore(RFs& aFs, 
   634 										   CConsoleBase& aConsole, 
   635 										   Output& aOut)
   636 	:CCertStoreTestAction(aFs, aConsole, aOut), iState(EInit)
   637 	{
   638 	}
   639 
   640 void COnlyCreateCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
   641 	{
   642 	CCertStoreTestAction::ConstructL(aTestActionSpec);
   643 	
   644 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
   645 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
   646 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
   647 	CleanupStack::PopAndDestroy(result);
   648 	}
   649 
   650 void COnlyCreateCertStore::PerformAction(TRequestStatus& aStatus)
   651 	{
   652 	switch (iState)
   653 		{
   654 		case EInit:
   655 			{
   656 			__ASSERT_DEBUG(!iNewUnifiedCertStore, User::Panic(_L("CInitialiseCertStore"), 1));
   657 			TRAPD(err, iNewUnifiedCertStore = CUnifiedCertStore::NewL(iFs, ETrue));
   658 				if (err != KErrNone)
   659 					{
   660 					iState = EFinished;
   661 					TRequestStatus* status = &aStatus;
   662 					User::RequestComplete(status, err);
   663 					}
   664 				else
   665 					{
   666 					AddCertStoreL(iNewUnifiedCertStore);
   667 					iNewUnifiedCertStore = 0; // we don't own this any more
   668 					iState = EFinished;
   669 					TRequestStatus* status = &aStatus;
   670 					User::RequestComplete(status, err);
   671 					}
   672 			}
   673 			break;
   674 
   675 		case EFinished:
   676 			{
   677 			TRequestStatus* status = &aStatus;
   678 			User::RequestComplete(status, aStatus.Int());
   679 			if (aStatus == iExpectedResult)
   680 				{
   681 				iResult = ETrue;
   682 				}
   683 			else
   684 				{
   685 				iResult = EFalse;
   686 				}
   687 			if (aStatus == KErrNoMemory)
   688 				{	
   689 				iState = EInit;
   690 				}
   691 			else
   692 				{
   693 				iFinished = ETrue;
   694 				}
   695 			}
   696 			break;
   697 		}
   698 	}
   699 
   700 void COnlyCreateCertStore::PerformCancel()
   701 {
   702 }
   703 
   704 void COnlyCreateCertStore::Reset()
   705 	{
   706 	__ASSERT_DEBUG(EFalse, User::Panic(_L("COnlyCreateCertStore::Reset()"), 1));
   707 	}
   708 
   709 void COnlyCreateCertStore::DoReportAction()
   710 	{
   711 	iOut.writeString(_L("Only creating certstore manager..."));
   712 	iOut.writeNewLine();
   713 	}
   714 
   715 void COnlyCreateCertStore::DoCheckResult(TInt aError)
   716 	{
   717 	if (iFinished)
   718 		{
   719 		if (aError == KErrNone)
   720 			{
   721 			iConsole.Write(_L("\tstore manager created successfully\n"));
   722 			iOut.writeString(_L("\tstore manager created successfully"));
   723 			iOut.writeNewLine();
   724 			iOut.writeNewLine();
   725 			}
   726 		else if (aError == KErrInUse)
   727 			{
   728 			iConsole.Write(_L("\tstore manager creation error : KErrInUse\n"));
   729 			iOut.writeString(_L("\tstore manager creation error : KErrInUse"));
   730 			iOut.writeNewLine();
   731 			iOut.writeNewLine();
   732 			}
   733 		}
   734 	}
   735 
   736 /////////////////////////////////////////////////////////////////////////////////
   737 // CDeleteCertStore
   738 /////////////////////////////////////////////////////////////////////////////////
   739 
   740 CTestAction* CDeleteCertStore::NewL(RFs& aFs, 
   741 									CConsoleBase& aConsole, 
   742 									Output& aOut,
   743 									const TTestActionSpec& aTestActionSpec)
   744 	{
   745 	CTestAction* self = CDeleteCertStore::NewLC(aFs, aConsole, aOut, aTestActionSpec);
   746 	CleanupStack::Pop(self);
   747 	return self;
   748 	}
   749 
   750 CTestAction* CDeleteCertStore::NewLC(RFs& aFs, 
   751 									 CConsoleBase& aConsole, 
   752 									 Output& aOut,
   753 									 const TTestActionSpec& aTestActionSpec)
   754 	{
   755 	CDeleteCertStore* self = new(ELeave) CDeleteCertStore(aFs, aConsole, aOut);
   756 	CleanupStack::PushL(self);
   757 	self->ConstructL(aTestActionSpec);
   758 	return self;
   759 	}
   760 
   761 CDeleteCertStore::~CDeleteCertStore()
   762 	{
   763 	}
   764 
   765 CDeleteCertStore::CDeleteCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
   766 	: CCertStoreTestAction(aFs, aConsole, aOut), iState(EDelete)
   767 	{
   768 	}
   769 
   770 void CDeleteCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
   771 	{
   772 	CCertStoreTestAction::ConstructL(aTestActionSpec);
   773 	
   774 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
   775 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
   776 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
   777 	CleanupStack::PopAndDestroy(result);
   778 	}
   779 
   780 void CDeleteCertStore::PerformAction(TRequestStatus& aStatus)
   781 	{
   782 	switch (iState)
   783 		{
   784 		case EDelete:
   785 			{
   786 			TInt err = KErrNotFound;
   787 			TInt count = CertStoreCount();
   788 			if (count)
   789 				{
   790 				RemoveCertStore(count - 1);
   791 				err = KErrNone;
   792 				}
   793 			iState = EFinished;
   794 			TRequestStatus* status = &aStatus;
   795 			User::RequestComplete(status, err);
   796 			}
   797 			break;
   798 
   799 		case EFinished:
   800 			{
   801 			TRequestStatus* status = &aStatus;
   802 			User::RequestComplete(status, aStatus.Int());
   803 			if (aStatus == iExpectedResult)
   804 				{
   805 				iResult = ETrue;
   806 				}
   807 			else
   808 				{
   809 				iResult = EFalse;
   810 				}
   811 			if (aStatus == KErrNoMemory)
   812 				{	
   813 				iState = EDelete;
   814 				}
   815 			else
   816 				{
   817 				iFinished = ETrue;
   818 				}
   819 			}
   820 			break;
   821 		}
   822 	}
   823 
   824 void CDeleteCertStore::PerformCancel()
   825 	{
   826 	iState = EDelete;
   827 	}
   828 
   829 void CDeleteCertStore::Reset()
   830 	{
   831 	}
   832 
   833 void CDeleteCertStore::DoReportAction()
   834 	{
   835 	iOut.writeString(_L("Deleting certstore manager..."));
   836 	iOut.writeNewLine();
   837 	}
   838 
   839 void CDeleteCertStore::DoCheckResult(TInt aError)
   840 	{
   841 	if (iFinished)
   842 		{
   843 		if (aError == KErrNone)
   844 			{
   845 			iConsole.Write(_L("\tstore manager deleted successfully\n"));
   846 			iOut.writeString(_L("\tstore manager deleted successfully"));
   847 			iOut.writeNewLine();
   848 			iOut.writeNewLine();
   849 			}
   850 		else
   851 			{
   852 			iConsole.Write(_L("\tstore manager deleted failed\n"));
   853 			iOut.writeString(_L("\tstore manager deleted failed"));
   854 			iOut.writeNewLine();
   855 			iOut.writeNewLine();
   856 			}
   857 		}
   858 	}
   859 
   860 CSetAppsAndTrust::~CSetAppsAndTrust()
   861 	{
   862 	delete iFilter;
   863 	iCertInfos.Close();
   864 	}
   865 
   866 void CSetAppsAndTrust::PerformAction(TRequestStatus& aStatus)
   867 	{
   868 	switch (iState)
   869 		{
   870 		case EGetCAEntries:
   871 			iState = ESetAppTrust;
   872 			GetCerts(aStatus);
   873 			break;
   874 
   875 		case ESetAppTrust:
   876 			{
   877             // Find the certificate we want to set the trust settings for
   878             // and edit its trust settings
   879             iState = EFinished;    
   880             TInt iEnd =  iCertInfos.Count();
   881             for (TInt i = 0; i < iEnd; i++)
   882                 {
   883                 if (iCertInfos[i]->Label() == iLabel)
   884                     {
   885  					if (iNotificationSubscribed)
   886  						{
   887  						if (!iNotifier)
   888  							{
   889  							iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
   890  							iNotifier->StartNotification();
   891  							}
   892  						iState = ECheckNotification;
   893  						}
   894  					else
   895  						{
   896  						iState = EFinished;
   897  						}    
   898                     DoSetAppTrust(*iCertInfos[i], aStatus);
   899                     return;
   900                     }
   901                 }
   902             TRequestStatus* status = &aStatus;
   903             User::RequestComplete(status, KErrNotFound);
   904             }
   905 			break;
   906 
   907  		case ECheckNotification:
   908  			{
   909  			iState = EFinished;
   910  			if (iNotifierFlag)
   911 	 			{
   912  				TRequestStatus* status = &aStatus;
   913  				User::RequestComplete(status, KErrNone);
   914 	 			}
   915 			else
   916 				{
   917 				iNotifier->SetCompleteStatus(&aStatus);
   918 				}
   919  			}
   920  			break;
   921 		case EFinished:
   922 			{
   923 			if (!iNotifierFlag && iNotificationSubscribed)
   924 				{
   925 				iResult = EFalse;
   926 				}
   927 			else
   928 				{
   929 				if (aStatus == iExpectedResult)
   930 					{
   931 					iResult = ETrue;
   932 					}
   933 				else
   934 					{
   935 					iResult = EFalse;
   936 					}				
   937 				}
   938             
   939             iFinished = ETrue;
   940             
   941             TRequestStatus* status = &aStatus;
   942             User::RequestComplete(status, aStatus.Int());
   943 			}
   944 			break;
   945 			
   946 		default:
   947 			User::Invariant();
   948 			break;
   949 		}
   950 	}
   951 
   952 void CSetAppsAndTrust::PerformCancel()
   953 	{
   954 	switch (iState)
   955 		{
   956 		case ESetAppTrust:
   957 			CertStore().CancelList();
   958 			break;
   959 		case ECheckNotification:
   960 		case EFinished:
   961 			DoPerformCancel();
   962 			break;
   963 
   964 		default:
   965 			// do nothing
   966 			break;
   967 		}
   968 	}
   969 
   970 void CSetAppsAndTrust::Reset()
   971 	{
   972     iState = EGetCAEntries;
   973 	iCertInfos.Close();
   974 	}
   975 
   976 CSetAppsAndTrust::CSetAppsAndTrust(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
   977 	: CSubscriberAction(aFs, aConsole, aOut), iState(EGetCAEntries)
   978 	
   979 	{
   980 	}
   981 
   982 void CSetAppsAndTrust::ConstructL(const TTestActionSpec& aTestActionSpec)
   983 	{
   984 	CSubscriberAction::ConstructL(aTestActionSpec);
   985 	iFilter = CCertAttributeFilter::NewL();
   986 
   987 	// Let derived class do its own parsing
   988 	}
   989 
   990 void CSetAppsAndTrust::GetCerts(TRequestStatus& aStatus)
   991 	{
   992 	CertStore().List(iCertInfos, *iFilter, aStatus);
   993 	}
   994 
   995 void CSetAppsAndTrust::SetCertLabel(const TDesC8& aLabel)
   996 	{
   997 	iLabel.Copy(aLabel);
   998 	}
   999 
  1000 CTestAction* CSetApplications::NewL(RFs& aFs, 
  1001 									CConsoleBase& aConsole,
  1002 									Output& aOut,
  1003 									const TTestActionSpec& aTestActionSpec)
  1004 	{
  1005 	CSetApplications* self = new(ELeave) CSetApplications(aFs, aConsole, aOut);
  1006 	CleanupStack::PushL(self);
  1007 	self->ConstructL(aTestActionSpec);
  1008 	CleanupStack::Pop(self);
  1009 	return self;
  1010 	}
  1011 
  1012 CSetApplications::~CSetApplications()
  1013 	{
  1014 	iApplications.Close();
  1015 	}
  1016 
  1017 CSetApplications::CSetApplications(RFs& aFs, CConsoleBase& aConsole, 
  1018 								   Output& aOut)
  1019 : CSetAppsAndTrust(aFs, aConsole, aOut)
  1020 	{
  1021 	}
  1022 
  1023 void CSetApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
  1024 	{
  1025 	CSetAppsAndTrust::ConstructL(aTestActionSpec);
  1026 
  1027 	TInt err = KErrNone;
  1028 	TInt pos = 0;
  1029 	SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody,
  1030 		KCertLabelStart, KCertLabelEnd, pos, err));
  1031 	AppendUid(Input::ParseElement(aTestActionSpec.iActionBody, KUIDStart, KUIDEnd, pos, err));
  1032 	// Set expected result
  1033 	pos = 0;
  1034 	
  1035 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
  1036 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
  1037 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
  1038 	CleanupStack::PopAndDestroy(result);
  1039 	}
  1040 
  1041 void CSetApplications::AppendUid(const TDesC8& aUid)
  1042 	{
  1043 	TLex8 lex(aUid);
  1044 
  1045 	TInt err = KErrNone;
  1046 	while (err == KErrNone)
  1047 		{
  1048 		TUid u ;
  1049 		err = lex.Val(u.iUid);
  1050 		if (err == KErrNone)
  1051 			{
  1052 			lex.SkipSpace();
  1053 			User::LeaveIfError(iApplications.Append(u));
  1054 			}
  1055 		}
  1056 	}
  1057 
  1058 void CSetApplications::DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus)
  1059 	{
  1060 	UnifiedCertStore().SetApplicability(aCertInfo, iApplications, aStatus);
  1061 	}
  1062 
  1063 void CSetApplications::DoPerformCancel()
  1064 	{
  1065 	UnifiedCertStore().CancelSetApplicability();
  1066 	}
  1067 
  1068 void CSetApplications::DoReportAction()
  1069 	{
  1070 	iOut.writeString(_L("Setting Application settings..."));
  1071 	iOut.writeNewLine();
  1072 	iOut.writeString(_L("\tLabel = "));
  1073 	iOut.writeString(iLabel);
  1074 	iOut.writeNewLine();
  1075 	iOut.writeString(_L("\tApplications = "));
  1076 	TInt count = iApplications.Count();
  1077 	for (TInt i = 0; i < count; i++)
  1078 		{
  1079 		iOut.writeNum(iApplications[i].iUid);
  1080 		iOut.writeString(_L(" "));
  1081 		}
  1082 	iOut.writeNewLine();
  1083 	iOut.writeNewLine();
  1084 	}
  1085 
  1086 void CSetApplications::DoCheckResult(TInt /*aError*/)
  1087 	{
  1088 	if (iFinished)
  1089 		{
  1090 		if (iResult)
  1091 			{
  1092 			iConsole.Write(_L("\tapplications set successfully\n"));
  1093 			iOut.writeString(_L("\tapplications set successfully"));
  1094 			iOut.writeNewLine();
  1095 			iOut.writeNewLine();
  1096 			}
  1097 		else
  1098 			{
  1099 			iConsole.Write(_L("\tapplications set failed\n"));
  1100 			iOut.writeString(_L("\tapplications set failed"));
  1101 			iOut.writeNewLine();
  1102 			iOut.writeNewLine();
  1103 			}
  1104 		}
  1105 	}
  1106 
  1107 CTestAction* CSetTrusters::NewL(RFs& aFs,
  1108 								CConsoleBase& aConsole,
  1109 								Output& aOut,
  1110 								const TTestActionSpec& aTestActionSpec)
  1111 	{
  1112 	CSetTrusters* self = new(ELeave) CSetTrusters(aFs, aConsole, aOut);
  1113 	CleanupStack::PushL(self);
  1114 	self->ConstructL(aTestActionSpec);
  1115 	CleanupStack::Pop(self);
  1116 	return self;
  1117 	}
  1118 
  1119 CSetTrusters::~CSetTrusters()
  1120 	{
  1121 	}
  1122 
  1123 
  1124 CSetTrusters::CSetTrusters(RFs& aFs, CConsoleBase& aConsole, 
  1125 						   Output& aOut)
  1126 : CSetAppsAndTrust(aFs, aConsole, aOut)
  1127 	{
  1128 	}
  1129 
  1130 void CSetTrusters::ConstructL(const TTestActionSpec& aTestActionSpec)
  1131 	{
  1132 	CSetAppsAndTrust::ConstructL(aTestActionSpec);
  1133 
  1134 	TInt err = KErrNone;
  1135 	TInt pos = 0;
  1136 	SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err));
  1137 	SetTrusted(Input::ParseElement(aTestActionSpec.iActionBody, KTrustersStart, KTrustersEnd, pos, err));
  1138 	// Set expected result
  1139 	pos = 0;
  1140 	
  1141 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
  1142 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
  1143 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
  1144 	CleanupStack::PopAndDestroy(result);
  1145 	}
  1146 
  1147 void CSetTrusters::SetTrusted(const TDesC8& aTrusted)
  1148 	{
  1149 	TLex8 lex(aTrusted);
  1150 
  1151 	TInt err = KErrNone;
  1152 	while (err == KErrNone)
  1153 		{
  1154 		TInt val;
  1155 		err = lex.Val(val);
  1156 		if (err == KErrNone)
  1157 			{
  1158 			iTrusted = static_cast<TBool>(val);
  1159 			}
  1160 		}
  1161 	}
  1162 
  1163 void CSetTrusters::DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus)
  1164 	{
  1165 	UnifiedCertStore().SetTrust(aCertInfo, iTrusted, aStatus);
  1166 	}
  1167 
  1168 void CSetTrusters::DoPerformCancel()
  1169 	{
  1170 	UnifiedCertStore().CancelSetTrust();
  1171 	}
  1172 
  1173 void CSetTrusters::DoReportAction()
  1174 	{
  1175 	iOut.writeString(_L("Setting trust..."));
  1176 	iOut.writeNewLine();
  1177 	iOut.writeString(_L("\tLabel = "));
  1178 	iOut.writeString(iLabel);
  1179 	iOut.writeNewLine();
  1180 	iOut.writeNewLine();
  1181 	}
  1182 
  1183 void CSetTrusters::DoCheckResult(TInt aError)
  1184 	{
  1185 	if (iFinished)
  1186 		{
  1187 		if (iResult && aError == KErrNone)
  1188 			{
  1189 			iConsole.Write(_L("\ttrust set successfully\n"));
  1190 			iOut.writeString(_L("\ttrust set successfully"));
  1191 			iOut.writeNewLine();
  1192 			iOut.writeNewLine();
  1193 			}
  1194 		else
  1195 			{
  1196 			iConsole.Write(_L("\ttrust set failed\n"));
  1197 			iOut.writeString(_L("\ttrust set failed"));
  1198 			iOut.writeNewLine();
  1199 			iOut.writeNewLine();
  1200 			}
  1201 		}
  1202 	}
  1203 
  1204 CTestAction* CGetTrusters::NewL(RFs& aFs,
  1205 								CConsoleBase& aConsole,
  1206 								Output& aOut,
  1207 								const TTestActionSpec& aTestActionSpec)
  1208 	{
  1209 	CGetTrusters* self = new(ELeave) CGetTrusters(aFs, aConsole, aOut);
  1210 	CleanupStack::PushL(self);
  1211 	self->ConstructL(aTestActionSpec);
  1212 	CleanupStack::Pop(self);
  1213 	return self;
  1214 	}
  1215 
  1216 CGetTrusters::~CGetTrusters()
  1217 	{
  1218 	iCertInfos.Close();
  1219 	iTrusters.Close();
  1220 	iExpectedTrusters.Close();
  1221 	delete iFilter;
  1222 	}
  1223 
  1224 void CGetTrusters::PerformAction(TRequestStatus& aStatus)
  1225 	{
  1226 	switch (iState)
  1227 		{
  1228 		case EGetCAEntries:
  1229 			iState = EGetTrusters;
  1230 			GetCerts(aStatus);
  1231 			break;
  1232 
  1233 		case EGetTrusters:
  1234 			{
  1235             TInt end =  iCertInfos.Count();
  1236             TBool calledCertStore = EFalse;
  1237             for (TInt i = 0; i < end; i++)
  1238                 {
  1239                 if (iCertInfos[i]->Label() == iLabel)
  1240                     {
  1241                     CertStore().Trusted(*iCertInfos[i], iTrust, aStatus);
  1242                     calledCertStore = ETrue;
  1243                     break;
  1244                     }
  1245                 }
  1246             iState = EFinished;
  1247             if (EFalse==calledCertStore)
  1248 				{//	None with the appropriate label
  1249                 TRequestStatus* status = &aStatus;
  1250                 User::RequestComplete(status, KErrNotFound);
  1251 				}
  1252 			}
  1253 			break;
  1254             
  1255 		case EFinished:
  1256 			{
  1257 			TRequestStatus* status = &aStatus;
  1258 			User::RequestComplete(status, aStatus.Int());
  1259             if (aStatus == iExpectedResult)
  1260                 {
  1261 
  1262                 if (iTrust == iExpectedTrusters[0].iUid)
  1263                     {
  1264                     iResult = ETrue;
  1265                     }
  1266                 else
  1267                     {
  1268                     iResult = EFalse;
  1269                     }
  1270                 }
  1271             else
  1272                 {
  1273                 iResult = EFalse;
  1274                 }
  1275 
  1276             iFinished = ETrue;				
  1277 			}
  1278 			break;
  1279             
  1280 		default:
  1281 			break;
  1282 		}
  1283 	}
  1284 
  1285 void CGetTrusters::PerformCancel()
  1286 	{
  1287 	switch (iState)
  1288 		{
  1289 		case EGetTrusters:
  1290 			CertStore().CancelList();
  1291 			break;
  1292 
  1293 		case EFinished:
  1294 			CertStore().CancelTrusted();
  1295 			break;
  1296 
  1297 		default:
  1298 			break;
  1299 		}
  1300 	}
  1301 
  1302 void CGetTrusters::Reset()
  1303 	{
  1304     iCertInfos.Close();
  1305     iState = EGetCAEntries;
  1306 	}
  1307 
  1308 CGetTrusters::CGetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
  1309 	: CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCAEntries)
  1310 	{
  1311 	}
  1312 
  1313 void CGetTrusters::ConstructL(const TTestActionSpec& aTestActionSpec)
  1314 	{
  1315 	CCertStoreTestAction::ConstructL(aTestActionSpec);
  1316 	iFilter = CCertAttributeFilter::NewL();
  1317 	TInt err = KErrNone;
  1318 	TInt pos = 0;
  1319 	SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody,
  1320 		KCertLabelStart, KCertLabelEnd, pos, err));
  1321 	
  1322 	// Set the expected result
  1323 	pos = 0;
  1324 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
  1325 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
  1326 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
  1327 	CleanupStack::PopAndDestroy(result);
  1328 	
  1329 	SetExpectedTrusters(Input::ParseElement(aTestActionSpec.iActionResult, KTrustersStart,
  1330 		KTrustersEnd, pos, err));
  1331 		
  1332 	}
  1333 
  1334 void CGetTrusters::GetCerts(TRequestStatus& aStatus)
  1335 	{
  1336 	CertStore().List(iCertInfos, *iFilter, aStatus);
  1337 	}
  1338 
  1339 void CGetTrusters::SetCertLabel(const TDesC8& aLabel)
  1340 	{
  1341 	iLabel.Copy(aLabel);
  1342 	}
  1343 
  1344 void CGetTrusters::SetExpectedTrusters(const TDesC8& aExpectedTrusters)
  1345 	{
  1346 	TLex8 lex(aExpectedTrusters);
  1347 	TInt err = KErrNone;
  1348 	while (err == KErrNone)
  1349 		{
  1350 		TUid uid;
  1351 		err = lex.Val(uid.iUid);
  1352 		if (err == KErrNone)
  1353 			{
  1354 			lex.SkipSpace();
  1355 			User::LeaveIfError(iExpectedTrusters.Append(uid));
  1356 			}
  1357 		}
  1358 	}
  1359 
  1360 void CGetTrusters::DoReportAction()
  1361 	{
  1362 	iOut.writeString(_L("Getting trust settings..."));
  1363 	iOut.writeNewLine();
  1364 	iOut.writeString(_L("\tLabel = "));
  1365 	iOut.writeString(iLabel);
  1366 	iOut.writeNewLine();
  1367 	iOut.writeNewLine();
  1368 	}
  1369 
  1370 void CGetTrusters::DoCheckResult(TInt /*aError*/)
  1371 	{
  1372 	if (iFinished)
  1373 		{
  1374 		iConsole.Printf(_L("\ttrust Setting : "));
  1375 		iOut.writeString(_L("\tTrust Setting: "));
  1376 		iOut.writeString(_L("\t\t"));
  1377 		iConsole.Printf(_L("%D \n"), iTrust);
  1378 		iOut.writeNum(iTrust);
  1379 		iOut.writeString(_L(" "));
  1380 		iOut.writeNewLine();
  1381 		iOut.writeNewLine();
  1382 
  1383 		iConsole.Printf(_L("\texpected Trust Setting: "));
  1384 		iOut.writeString(_L("\tExpected Trust Setting: "));
  1385 		iOut.writeNewLine();
  1386 		iOut.writeString(_L("\t\t"));
  1387 		iConsole.Printf(_L("%D \n"), iExpectedTrusters[0].iUid);
  1388 		iOut.writeNum(iExpectedTrusters[0].iUid);
  1389 		iOut.writeString(_L(" "));
  1390 		iOut.writeNewLine();
  1391 		iOut.writeNewLine();
  1392 		if (iResult)
  1393 			{
  1394 			iConsole.Printf(_L("\tTrust retrieved successfully\n"));
  1395 			iOut.writeString(_L("\tTrust retrieved successfully"));
  1396 			iOut.writeNewLine();
  1397 			}
  1398 		else
  1399 			{
  1400 			iConsole.Printf(_L("\tTrust retrieved failed\n"));
  1401 			iOut.writeString(_L("\tTrust retrieved failed"));
  1402 			iOut.writeNewLine();
  1403 			}
  1404 		iOut.writeNewLine();
  1405 
  1406 		}
  1407 	}