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