cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreremove.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "t_unifiedcertstoreremove.h"
       
    26 #include "t_certstoredefs.h"
       
    27 #include "t_input.h"
       
    28 #include "t_certstoreout.h"
       
    29 #include <ccertattributefilter.h>
       
    30 
       
    31 
       
    32 /////////////////////////////////////////////////////////////////////////////////
       
    33 //CDeleteCertificate
       
    34 /////////////////////////////////////////////////////////////////////////////////
       
    35 
       
    36 
       
    37 CTestAction* CDeleteCertificate::NewL(RFs& aFs,
       
    38 										CConsoleBase& aConsole, 
       
    39 										Output& aOut,
       
    40 										const TTestActionSpec& aTestActionSpec)
       
    41 	{
       
    42 	CDeleteCertificate* self = new(ELeave) CDeleteCertificate(aFs, aConsole, aOut);
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL(aTestActionSpec);
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 CDeleteCertificate::CDeleteCertificate(RFs& aFs, CConsoleBase& aConsole, 
       
    50 									   Output& aOut)
       
    51 : CSubscriberAction(aFs, aConsole, aOut), iState(EIdle),iCertDeleteType(NULL)
       
    52 	{
       
    53 	}
       
    54 
       
    55 void CDeleteCertificate::PerformAction(TRequestStatus& aStatus)
       
    56 	{
       
    57 	if (aStatus != KErrNone)
       
    58 		{
       
    59 		iState = EFinished;
       
    60 		}
       
    61 	
       
    62 	switch (iState)
       
    63 		{
       
    64 		case EIdle:
       
    65 			//get the certs
       
    66 			if (iCertInfos.Count() > 0)
       
    67 				{
       
    68 				iCertInfos.Close();	//	JCS added for multiple delete case
       
    69 				}
       
    70 
       
    71 			iState = EGettingCerts;
       
    72 			//get the certs
       
    73 			GetCerts(aStatus);
       
    74 			break;
       
    75 			
       
    76 		case EGettingCerts:
       
    77 			{
       
    78  			if (iNotificationSubscribed)
       
    79  				{
       
    80  				if (!iNotifier)
       
    81  					{
       
    82 	 				iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
       
    83  					iNotifier->StartNotification();			
       
    84  					}
       
    85  				iState = ECheckNotification;
       
    86  				}
       
    87  			else
       
    88  				{
       
    89  				iState = EFinished;
       
    90  				}
       
    91 			DeleteCert(aStatus);
       
    92 			}
       
    93 			break;
       
    94 
       
    95  		case ECheckNotification:
       
    96  			{
       
    97  			TInt ret=KErrNone;
       
    98  			if (!iNotifierFlag)
       
    99  				{
       
   100  				ret=KErrGeneral;
       
   101  				}
       
   102  			iState = EFinished;
       
   103  			TRequestStatus* status = &aStatus;
       
   104  			User::RequestComplete(status, ret);
       
   105  			}
       
   106  			break;
       
   107 			
       
   108 		case EFinished:
       
   109 			{
       
   110 			if (aStatus == iExpectedResult)
       
   111 				{
       
   112 				iResult = ETrue;
       
   113 				}
       
   114 			else
       
   115 				{
       
   116 				iResult = EFalse;
       
   117 				}
       
   118 			if (aStatus == KErrNoMemory)
       
   119 				{	
       
   120 				iState = EIdle;
       
   121 				}
       
   122 			else
       
   123 				{
       
   124 				iFinished = ETrue;
       
   125 				}
       
   126 			TRequestStatus* status = &aStatus;
       
   127 			User::RequestComplete(status, aStatus.Int());
       
   128 			}
       
   129 			break;
       
   130 			
       
   131 		default:
       
   132 			User::Invariant();
       
   133 		}
       
   134 	}
       
   135 
       
   136 void CDeleteCertificate::PerformCancel()
       
   137 	{
       
   138 	switch (iState)
       
   139 		{
       
   140 		case EGettingCerts:
       
   141 			CertStore().CancelList();
       
   142 			break;
       
   143 		case ECheckNotification:
       
   144 		case EIdle:
       
   145 		case EFinished:
       
   146 			// We /may/ be deleting a cert in these states - fortunately cancel is lenient
       
   147 			UnifiedCertStore().CancelRemove();
       
   148 			break;
       
   149 
       
   150 		default:
       
   151 			User::Invariant();
       
   152 		}
       
   153 	}
       
   154 
       
   155 void CDeleteCertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
       
   156 	{
       
   157 	CSubscriberAction::ConstructL(aTestActionSpec);
       
   158 
       
   159 	iFilter = CCertAttributeFilter::NewL();
       
   160 	TInt pos = 0;
       
   161 	TInt err1 = KErrNone;
       
   162 	
       
   163 	TPtrC8 pLabel1 = Input::ParseElement(aTestActionSpec.iActionBody, KCertTypeStart, KCertTypeEnd, pos, err1);
       
   164 	
       
   165 	if(err1 == KErrNone)
       
   166 		{
       
   167 		iCertDeleteType = HBufC8::NewL(pLabel1.Size());
       
   168 		*iCertDeleteType = pLabel1;
       
   169 		}
       
   170 		
       
   171 	pos=0;
       
   172 	TInt err2 = KErrNone;
       
   173 	TPtrC8 pLabel2 = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err2);
       
   174 	if (err2 != KErrNone)
       
   175 		{
       
   176 		User::Leave(err2);
       
   177 		}
       
   178 	
       
   179 	iCertLabel.Copy(pLabel2);
       
   180 	if (iCertLabel.Compare(_L("*.*"))==0)	//	delete all certs
       
   181 	{//	Check that the flag has been set
       
   182 		TPtrC8 pDeleteAll = Input::ParseElement(aTestActionSpec.iActionBody, KDeleteAllStart, KDeleteAllEnd, pos, err1);
       
   183 		if (pDeleteAll!=KNullDesC8)
       
   184 		{
       
   185 			TLex8 lexer(pDeleteAll);
       
   186 			TInt boolVal = 0;
       
   187 			lexer.Val(boolVal);
       
   188 			iDeleteAllCerts = (boolVal > 0) ? ETrue : EFalse;
       
   189 		}
       
   190 	}
       
   191 	else if( err1 != KErrNone && err1 != KErrNotFound)
       
   192 		{
       
   193 		User::Leave(err1);
       
   194 		}
       
   195 
       
   196 	// Set expected result
       
   197 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
       
   198 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
       
   199 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
       
   200 	CleanupStack::PopAndDestroy(result);
       
   201 	}
       
   202 
       
   203 void CDeleteCertificate::GetCerts(TRequestStatus& aStatus)
       
   204 	{
       
   205 	CertStore().List(iCertInfos, *iFilter, aStatus);
       
   206 	}
       
   207 
       
   208 CDeleteCertificate::~CDeleteCertificate()
       
   209 	{
       
   210 	delete iCertDeleteType;
       
   211 	iCertInfos.Close();
       
   212 	delete iFilter;
       
   213 	}
       
   214 
       
   215 void CDeleteCertificate::DeleteCert(TRequestStatus& aStatus)
       
   216 	{
       
   217 	TInt ix = KErrNotFound;
       
   218 	TInt count = iCertInfos.Count();
       
   219 	for (TInt i = count-1; i >= 0 ; i--)
       
   220 		{
       
   221 		if (iDeleteAllCerts)
       
   222 			{//	Just delete the first one we come across
       
   223 			if (i>=0)					//	Still some certificates to delete
       
   224 				{							//	Set the state back to continue
       
   225 				iState = EIdle;	
       
   226 				}
       
   227 
       
   228 			ix = i;
       
   229 			break;
       
   230 			}
       
   231 		//	Only delete if there's a label match and the certificate is of specified type
       
   232 		else if (iCertInfos[i]->Label() == iCertLabel && CheckCertType(*iCertInfos[i]) )
       
   233 			{
       
   234 			ix = i;
       
   235 			break;
       
   236 			}
       
   237 		}
       
   238 	
       
   239 	TRequestStatus* status = &aStatus;
       
   240 	if (ix == KErrNotFound)
       
   241 		{
       
   242 		TInt result = KErrNone;
       
   243 		
       
   244 		if(iDeleteAllCerts) 
       
   245 			result = KErrNone; 
       
   246 		else if(iCertDeleteType == NULL)
       
   247 			result = KErrNotSupported;
       
   248 		else
       
   249 			result = KErrNotFound;
       
   250 		
       
   251 		User::RequestComplete(status, result);
       
   252 		}	
       
   253 	else
       
   254 		{
       
   255 		iCertInfoToDelete = iCertInfos[ix];
       
   256 		UnifiedCertStore().Remove(*iCertInfos[ix], aStatus);
       
   257 		}
       
   258 	}
       
   259 
       
   260 TBool CDeleteCertificate::CheckCertType( CCTCertInfo& aCertInfo )
       
   261 	{
       
   262 	if(iCertDeleteType == NULL)
       
   263 		return EFalse;
       
   264 	
       
   265 	TBool returnValue = EFalse;
       
   266 	switch(aCertInfo.CertificateOwnerType())
       
   267 		{
       
   268 		case ECACertificate:
       
   269 			if(iCertDeleteType->Compare(KCACert) == 0 )
       
   270 				returnValue = ETrue;
       
   271 			break;
       
   272 		case EUserCertificate:
       
   273 			if(iCertDeleteType->Compare(KUserCert) == 0 )
       
   274 				returnValue = ETrue;
       
   275 			break;
       
   276 		case EPeerCertificate:
       
   277 			if(iCertDeleteType->Compare(KPeerCert) == 0 )
       
   278 				returnValue = ETrue;
       
   279 			break;
       
   280 		}
       
   281 	return returnValue;
       
   282 	}
       
   283 
       
   284 void CDeleteCertificate::DoReportAction()
       
   285 	{
       
   286 	iOut.writeString(_L("Deleting certificate..."));
       
   287 	iOut.writeNewLine();
       
   288 	iOut.writeString(_L("\tLabel = "));
       
   289 	iOut.writeString(iCertLabel);
       
   290 	iOut.writeNewLine();
       
   291 	iOut.writeNewLine();
       
   292 	}
       
   293 
       
   294 void CDeleteCertificate::DoCheckResult(TInt aError)
       
   295 	{
       
   296 	if (iFinished)
       
   297 		{
       
   298 		if (aError == KErrNone && iCertInfoToDelete)
       
   299 			{
       
   300 			switch (iCertInfoToDelete->CertificateOwnerType())
       
   301 				{
       
   302 			case ECACertificate:
       
   303 				iConsole.Write(_L("\tCA certificate deleted successfully\n"));
       
   304 				iOut.writeString(_L("\tCA certificate deleted successfully"));
       
   305 				break;
       
   306 
       
   307 			case EUserCertificate:
       
   308 				iConsole.Write(_L("\tUser certificate deleted successfully\n"));
       
   309 				iOut.writeString(_L("\tUser certificate deleted successfully"));
       
   310 				break;
       
   311 			
       
   312 			case EPeerCertificate:
       
   313 				iConsole.Write(_L("\tPeer certificate deleted successfully\n"));
       
   314 				iOut.writeString(_L("\tPeer certificate deleted successfully"));
       
   315 				break;
       
   316 			default:
       
   317 				iConsole.Write(_L("\tUnknown owner certificate deleted successfully\n"));
       
   318 				iOut.writeString(_L("\tUnknown owner certificate deleted successfully"));
       
   319 				break;
       
   320 				}
       
   321 			}
       
   322 		iOut.writeNewLine();
       
   323 		iOut.writeNewLine();
       
   324 		}
       
   325 	}
       
   326 
       
   327 void CDeleteCertificate::Reset()
       
   328 	{
       
   329 	iState = EIdle;
       
   330 	iCertInfos.Close();
       
   331 	}
       
   332 
       
   333 
       
   334 /////////////////////////////////////////////////////////////////////////////////
       
   335 //CDeleteRetrieveCertificate
       
   336 /////////////////////////////////////////////////////////////////////////////////
       
   337 CDeleteRetrieveCertificate::CDeleteRetrieveCertificate(RFs& aFs, CConsoleBase& aConsole, 
       
   338 													   Output& aOut)
       
   339 : CSubscriberAction(aFs, aConsole, aOut), iState(EIdle)
       
   340 	{
       
   341 	}
       
   342 
       
   343 void CDeleteRetrieveCertificate::PerformAction(TRequestStatus& aStatus)
       
   344 	{
       
   345 	TRequestStatus* status = &aStatus;
       
   346 	switch (iState)
       
   347 		{
       
   348 		case EIdle:
       
   349 			//get the certs
       
   350 			iState = EDeletingCert;
       
   351 			//get the certs
       
   352 			GetCerts(aStatus);
       
   353 			if (aStatus == KErrNoMemory)
       
   354 				{
       
   355 				iState = EFinished;
       
   356 				}
       
   357 			break;
       
   358 
       
   359 		case EDeletingCert:
       
   360 			{
       
   361  			if (iNotificationSubscribed)
       
   362  				{
       
   363  				iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
       
   364  				iNotifier->StartNotification();
       
   365  				iState = ECheckNotification;
       
   366  				}
       
   367  			else
       
   368  				{
       
   369  				iState = EGettingCerts;
       
   370  				}
       
   371 			//delete the cert
       
   372 			DeleteCert(aStatus);
       
   373 			break;
       
   374 			}
       
   375 
       
   376  		case ECheckNotification:
       
   377  			{
       
   378  			TInt ret=KErrNone;
       
   379  			if (!iNotifierFlag)
       
   380  				{
       
   381  				ret=KErrGeneral;
       
   382  				}
       
   383  			if (ret!=KErrNone)
       
   384  				{
       
   385  				iState = EFinished;	
       
   386  				}
       
   387  			else
       
   388  				{
       
   389  				iState = EGettingCerts;
       
   390  				}
       
   391  			TRequestStatus* status = &aStatus;
       
   392  			User::RequestComplete(status, ret);
       
   393  			}
       
   394  			break;
       
   395 		case EGettingCerts:
       
   396 			{
       
   397 			iState = EFinished;
       
   398 			//get the cert
       
   399 			RetrieveCerts(aStatus);
       
   400 			break;
       
   401 			}
       
   402 		case EFinished:
       
   403 			{
       
   404 			if (aStatus == iExpectedResult)
       
   405 				{
       
   406 				iResult = ETrue;
       
   407 				}
       
   408 			else
       
   409 				{
       
   410 				iResult = EFalse;
       
   411 				}
       
   412 			if (aStatus == KErrNoMemory)
       
   413 				{	
       
   414 				iState = EIdle;
       
   415 				}
       
   416 			else
       
   417 				{
       
   418 				iFinished = ETrue;
       
   419 				}
       
   420 			User::RequestComplete(status, aStatus.Int());
       
   421 			}
       
   422 			break;
       
   423 		default:
       
   424 			{
       
   425 			//some kind of error behaviour
       
   426 			}
       
   427 		}
       
   428 	}
       
   429 
       
   430 void CDeleteRetrieveCertificate::PerformCancel()
       
   431 	{
       
   432 	}
       
   433 
       
   434 void CDeleteRetrieveCertificate::Reset()
       
   435 	{
       
   436 	__ASSERT_DEBUG(EFalse, User::Panic(_L("CDeleteRetrieveCertificate::Reset()"), 1));
       
   437 	}
       
   438 
       
   439 ////////////////////////////////////////////////////////////////////////////////
       
   440 //CDeleteCACertificate
       
   441 //////////////////////////////////////////////////////////////////////////////////
       
   442 
       
   443 CTestAction* CDeleteRetrieveCACertificate::NewL(RFs& aFs,
       
   444 												CConsoleBase& aConsole, 
       
   445 												Output& aOut,
       
   446 												const TTestActionSpec& aTestActionSpec)
       
   447 	{
       
   448 	CDeleteRetrieveCACertificate* self = 
       
   449 		new(ELeave) CDeleteRetrieveCACertificate(aFs, aConsole, aOut);
       
   450 	CleanupStack::PushL(self);
       
   451 	self->ConstructL(aTestActionSpec);
       
   452 	CleanupStack::Pop(self);
       
   453 	return self;
       
   454 	}
       
   455 
       
   456 CDeleteRetrieveCACertificate::CDeleteRetrieveCACertificate(RFs& aFs, CConsoleBase& aConsole, 
       
   457 														   Output& aOut)
       
   458 	:CDeleteRetrieveCertificate(aFs, aConsole, aOut)
       
   459 	{
       
   460 	}
       
   461 
       
   462 void CDeleteRetrieveCACertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
       
   463 	{
       
   464 	CSubscriberAction::ConstructL(aTestActionSpec);
       
   465 	iCertlisted = new(ELeave) RPointerArray<HBufC8>;
       
   466 	iFilter = CCertAttributeFilter::NewL();
       
   467 	TInt pos = 0;
       
   468 	TInt err = KErrNone;
       
   469 	TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
       
   470 	if (err != KErrNone)
       
   471 		{
       
   472 		User::Leave(err);
       
   473 		}
       
   474 	iCertLabel.Copy(pLabel);
       
   475 
       
   476 	// Set expected result
       
   477 	pos = 0;
       
   478 	
       
   479 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
       
   480 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
       
   481 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
       
   482 	CleanupStack::PopAndDestroy(result);
       
   483 	}
       
   484 
       
   485 void CDeleteRetrieveCACertificate::GetCerts(TRequestStatus& aStatus)
       
   486 	{
       
   487 	CertStore().List(iCertInfos, *iFilter, aStatus);
       
   488 	}
       
   489 
       
   490 void CDeleteRetrieveCACertificate::RetrieveCerts(TRequestStatus& aStatus)
       
   491 	{
       
   492 	TRequestStatus* status = &aStatus;
       
   493 	TInt ix = KErrNotFound;
       
   494 	TInt count = iCertInfos.Count();
       
   495 	for (TInt i = 0; i < count; i++)
       
   496 		{
       
   497 		if (iCertInfos[i]->Label() == iCertLabel)
       
   498 			{
       
   499 			ix = i;
       
   500 			break;
       
   501 			}
       
   502 		}
       
   503 	if (ix == KErrNotFound)
       
   504 		{
       
   505 		User::RequestComplete(status, ix);
       
   506 		}	
       
   507 	else
       
   508 		{
       
   509 		iCertInfoToRetrieve = iCertInfos[ix];
       
   510 
       
   511 		HBufC8* buf = HBufC8::NewLC(iCertInfoToRetrieve->Size());
       
   512 		User::LeaveIfError(iCertlisted->Append(buf));
       
   513 		CleanupStack::Pop();//buf
       
   514 		__ASSERT_DEBUG(!iBuf, User::Panic(_L("CListCACertificates"), 1));
       
   515 		iBuf = new(ELeave) TPtr8(buf->Des());
       
   516 		CertStore().Retrieve(*iCertInfoToRetrieve, *iBuf, aStatus);
       
   517 		}
       
   518 	}
       
   519 
       
   520 CDeleteRetrieveCACertificate::~CDeleteRetrieveCACertificate()
       
   521 	{
       
   522 	iCertInfos.Close();
       
   523 	delete iFilter;
       
   524 	if (iCertlisted)
       
   525 		{
       
   526 		iCertlisted->ResetAndDestroy();
       
   527 		delete iCertlisted;
       
   528 		}
       
   529 	delete iBuf;
       
   530 	}
       
   531 	
       
   532 void CDeleteRetrieveCACertificate::DeleteCert(TRequestStatus& aStatus)
       
   533 	{
       
   534 	TRequestStatus* status = &aStatus;
       
   535 	TInt ix = KErrNotFound;
       
   536 	TInt count = iCertInfos.Count();
       
   537 	for (TInt i = 0; i < count; i++)
       
   538 		{
       
   539 		if (iCertInfos[i]->Label() == iCertLabel)
       
   540 			{
       
   541 			ix = i;
       
   542 			break;
       
   543 			}
       
   544 		}
       
   545 	if (ix == KErrNotFound)
       
   546 		{
       
   547 		User::RequestComplete(status, ix);
       
   548 		}	
       
   549 	else
       
   550 		{
       
   551 		iCertInfoToDelete = iCertInfos[ix];
       
   552 		UnifiedCertStore().Remove(*iCertInfoToDelete, aStatus);
       
   553 		}
       
   554 	}
       
   555 
       
   556 void CDeleteRetrieveCACertificate::DoReportAction()
       
   557 	{
       
   558 	iOut.writeString(_L("Deleting certificate..."));
       
   559 	iOut.writeNewLine();
       
   560 	iOut.writeString(_L("\tLabel = "));
       
   561 	iOut.writeString(iCertLabel);
       
   562 	iOut.writeNewLine();
       
   563 	iOut.writeNewLine();
       
   564 	}
       
   565 
       
   566 void CDeleteRetrieveCACertificate::DoCheckResult(TInt aError)
       
   567 	{
       
   568 	if (iFinished)
       
   569 		{
       
   570 		if (aError == KErrNone && iResult)
       
   571 			{
       
   572 			switch (iCertInfoToDelete->CertificateOwnerType())
       
   573 				{
       
   574 			case ECACertificate:
       
   575 				iConsole.Write(_L("\tCA certificate deleted successfully\n"));
       
   576 				iOut.writeString(_L("\tCA certificate deleted successfully"));
       
   577 				break;
       
   578 
       
   579 			case EUserCertificate:
       
   580 				iConsole.Write(_L("\tUser certificate deleted successfully\n"));
       
   581 				iOut.writeString(_L("\tUser certificate deleted successfully"));
       
   582 				break;
       
   583 
       
   584 			default:
       
   585 				iConsole.Write(_L("\tUnknown owner certificate deleted successfully\n"));
       
   586 				iOut.writeString(_L("\tUnknown owner certificate deleted successfully"));
       
   587 				break;
       
   588 				}
       
   589 			}
       
   590 		else
       
   591 			{
       
   592 			if (iResult)
       
   593 				{
       
   594 				iConsole.Write(_L("\tCA OK\n"));
       
   595 				iOut.writeString(_L("\tCA OK"));
       
   596 				}
       
   597 			}
       
   598 		iOut.writeNewLine();
       
   599 		iOut.writeNewLine();
       
   600 		}
       
   601 	}
       
   602 
       
   603 ////////////////////////////////////////////////////////////////////////////////
       
   604 //CDeleteUserCertificate
       
   605 //////////////////////////////////////////////////////////////////////////////////
       
   606 CTestAction* CDeleteRetrieveUserCertificate::NewL(RFs& aFs, 
       
   607 												  CConsoleBase& aConsole,
       
   608 												  Output& aOut, 
       
   609 												  const TTestActionSpec& aTestActionSpec)
       
   610 	{
       
   611 	CDeleteRetrieveUserCertificate* self = 
       
   612 		new(ELeave) CDeleteRetrieveUserCertificate(aFs, aConsole, aOut);
       
   613 	CleanupStack::PushL(self);
       
   614 	self->ConstructL(aTestActionSpec);
       
   615 	CleanupStack::Pop(self);
       
   616 	return self;
       
   617 	}
       
   618 
       
   619 CDeleteRetrieveUserCertificate::CDeleteRetrieveUserCertificate(RFs& aFs, CConsoleBase& aConsole, 
       
   620 															   Output& aOut)
       
   621 	:CDeleteRetrieveCertificate(aFs, aConsole, aOut)
       
   622 	{
       
   623 	}
       
   624 
       
   625 void CDeleteRetrieveUserCertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
       
   626 	{
       
   627 	CSubscriberAction::ConstructL(aTestActionSpec);
       
   628 	iCertlisted = new(ELeave) RPointerArray<HBufC8>;
       
   629 	iFilter = CCertAttributeFilter::NewL();
       
   630 	TInt pos = 0;
       
   631 	TInt err = KErrNone;
       
   632 	TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
       
   633 	if (err != KErrNone)
       
   634 		{
       
   635 		User::Leave(err);
       
   636 		}
       
   637 	iCertLabel.Copy(pLabel);
       
   638 
       
   639 	// Set expected result
       
   640 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
       
   641 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
       
   642 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
       
   643 	CleanupStack::PopAndDestroy(result);
       
   644 	}
       
   645 
       
   646 void CDeleteRetrieveUserCertificate::GetCerts(TRequestStatus& aStatus)
       
   647 	{
       
   648 	CertStore().List(iCertInfos, *iFilter, aStatus);
       
   649 	}
       
   650 
       
   651 void CDeleteRetrieveUserCertificate::RetrieveCerts(TRequestStatus& aStatus)
       
   652 	{
       
   653 	TRequestStatus* status = &aStatus;
       
   654 	TInt ix = KErrNotFound;
       
   655 	TInt count = iCertInfos.Count();
       
   656 	for (TInt i = 0; i < count; i++)
       
   657 		{
       
   658 		if (iCertInfos[i]->Label() == iCertLabel)
       
   659 			{
       
   660 			ix = i;
       
   661 			break;
       
   662 			}
       
   663 		}
       
   664 	if (ix == KErrNotFound)
       
   665 		{
       
   666 		User::RequestComplete(status, ix);
       
   667 		}	
       
   668 	else
       
   669 		{
       
   670 		iCertInfoToRetrieve = iCertInfos[ix];
       
   671 
       
   672 		HBufC8* buf = HBufC8::NewLC(iCertInfoToRetrieve->Size());
       
   673 		User::LeaveIfError(iCertlisted->Append(buf));
       
   674 		CleanupStack::Pop();//buf
       
   675 		//__ASSERT_DEBUG(!iBuf, User::Panic(_L("CListCACertificates"), 1));
       
   676 		iBuf = new(ELeave) TPtr8(buf->Des());
       
   677 		CertStore().Retrieve(*iCertInfoToRetrieve, *iBuf, aStatus);
       
   678 		}
       
   679 	}
       
   680 
       
   681 CDeleteRetrieveUserCertificate::~CDeleteRetrieveUserCertificate()
       
   682 	{
       
   683 	iCertInfos.Close();
       
   684 	delete iFilter;
       
   685 	if (iCertlisted)
       
   686 		{
       
   687 		iCertlisted->ResetAndDestroy();
       
   688 		delete iCertlisted;
       
   689 		}
       
   690 	delete iBuf;
       
   691 	}
       
   692 	
       
   693 void CDeleteRetrieveUserCertificate::DeleteCert(TRequestStatus& aStatus)
       
   694 	{
       
   695 	TRequestStatus* status = &aStatus;
       
   696 	TInt ix = KErrNotFound;
       
   697 	TInt count = iCertInfos.Count();
       
   698 	for (TInt i = 0; i < count; i++)
       
   699 		{
       
   700 		if (iCertInfos[i]->Label() == iCertLabel)
       
   701 			{
       
   702 			ix = i;
       
   703 			break;
       
   704 			}
       
   705 		}
       
   706 	if (ix == KErrNotFound)
       
   707 		{
       
   708 		User::RequestComplete(status, ix);
       
   709 		}	
       
   710 	else
       
   711 		{
       
   712 		CCTCertInfo* certInfo = iCertInfos[ix];
       
   713 		UnifiedCertStore().Remove(*certInfo, aStatus);
       
   714 		}
       
   715 	}
       
   716 
       
   717 void CDeleteRetrieveUserCertificate::DoReportAction()
       
   718 	{
       
   719 	iOut.writeString(_L("Deleting user certificate..."));
       
   720 	iOut.writeNewLine();
       
   721 	iOut.writeString(_L("\tLabel = "));
       
   722 	iOut.writeString(iCertLabel);
       
   723 	iOut.writeNewLine();
       
   724 	iOut.writeNewLine();
       
   725 	}
       
   726 
       
   727 void CDeleteRetrieveUserCertificate::DoCheckResult(TInt aError)
       
   728 	{
       
   729 	if (iFinished)
       
   730 		{
       
   731 		if (aError == KErrNone && iResult)
       
   732 			{
       
   733 			iConsole.Write(_L("\tuser cert deleted successfully\n"));
       
   734 			iOut.writeString(_L("\tuser cert deleted successfully"));
       
   735 			iOut.writeNewLine();
       
   736 			iOut.writeNewLine();
       
   737 			}
       
   738 		else
       
   739 			{
       
   740 			if (iResult)
       
   741 				{
       
   742 				iConsole.Write(_L("\tnot retrieved but expected\n"));
       
   743 				iOut.writeString(_L("\tCA OK"));
       
   744 				}
       
   745 			else
       
   746 				{
       
   747 				iConsole.Write(_L("\tuser cert deleted successfully\n"));
       
   748 				iOut.writeString(_L("\tuser cert deleted successfully"));
       
   749 				iOut.writeNewLine();
       
   750 				iOut.writeNewLine();
       
   751 				}
       
   752 			}
       
   753 		}
       
   754 	}