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