os/security/cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreremove.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreremove.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,755 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 +*/
1.25 +
1.26 +#include "t_unifiedcertstoreremove.h"
1.27 +#include "t_certstoredefs.h"
1.28 +#include "t_input.h"
1.29 +#include "t_certstoreout.h"
1.30 +#include <ccertattributefilter.h>
1.31 +
1.32 +
1.33 +/////////////////////////////////////////////////////////////////////////////////
1.34 +//CDeleteCertificate
1.35 +/////////////////////////////////////////////////////////////////////////////////
1.36 +
1.37 +
1.38 +CTestAction* CDeleteCertificate::NewL(RFs& aFs,
1.39 + CConsoleBase& aConsole,
1.40 + Output& aOut,
1.41 + const TTestActionSpec& aTestActionSpec)
1.42 + {
1.43 + CDeleteCertificate* self = new(ELeave) CDeleteCertificate(aFs, aConsole, aOut);
1.44 + CleanupStack::PushL(self);
1.45 + self->ConstructL(aTestActionSpec);
1.46 + CleanupStack::Pop(self);
1.47 + return self;
1.48 + }
1.49 +
1.50 +CDeleteCertificate::CDeleteCertificate(RFs& aFs, CConsoleBase& aConsole,
1.51 + Output& aOut)
1.52 +: CSubscriberAction(aFs, aConsole, aOut), iState(EIdle),iCertDeleteType(NULL)
1.53 + {
1.54 + }
1.55 +
1.56 +void CDeleteCertificate::PerformAction(TRequestStatus& aStatus)
1.57 + {
1.58 + if (aStatus != KErrNone)
1.59 + {
1.60 + iState = EFinished;
1.61 + }
1.62 +
1.63 + switch (iState)
1.64 + {
1.65 + case EIdle:
1.66 + //get the certs
1.67 + if (iCertInfos.Count() > 0)
1.68 + {
1.69 + iCertInfos.Close(); // JCS added for multiple delete case
1.70 + }
1.71 +
1.72 + iState = EGettingCerts;
1.73 + //get the certs
1.74 + GetCerts(aStatus);
1.75 + break;
1.76 +
1.77 + case EGettingCerts:
1.78 + {
1.79 + if (iNotificationSubscribed)
1.80 + {
1.81 + if (!iNotifier)
1.82 + {
1.83 + iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
1.84 + iNotifier->StartNotification();
1.85 + }
1.86 + iState = ECheckNotification;
1.87 + }
1.88 + else
1.89 + {
1.90 + iState = EFinished;
1.91 + }
1.92 + DeleteCert(aStatus);
1.93 + }
1.94 + break;
1.95 +
1.96 + case ECheckNotification:
1.97 + {
1.98 + iState = EFinished;
1.99 + if (iNotifierFlag)
1.100 + {
1.101 + TRequestStatus* status = &aStatus;
1.102 + User::RequestComplete(status, KErrNone);
1.103 + }
1.104 + else
1.105 + {
1.106 + iNotifier->SetCompleteStatus(&aStatus);
1.107 + }
1.108 + }
1.109 +
1.110 + break;
1.111 +
1.112 + case EFinished:
1.113 + {
1.114 + if (aStatus == iExpectedResult)
1.115 + {
1.116 + iResult = ETrue;
1.117 + }
1.118 + else
1.119 + {
1.120 + iResult = EFalse;
1.121 + }
1.122 + if (aStatus == KErrNoMemory)
1.123 + {
1.124 + iState = EIdle;
1.125 + }
1.126 + else
1.127 + {
1.128 + iFinished = ETrue;
1.129 + }
1.130 + TRequestStatus* status = &aStatus;
1.131 + User::RequestComplete(status, aStatus.Int());
1.132 + }
1.133 + break;
1.134 +
1.135 + default:
1.136 + User::Invariant();
1.137 + }
1.138 + }
1.139 +
1.140 +void CDeleteCertificate::PerformCancel()
1.141 + {
1.142 + switch (iState)
1.143 + {
1.144 + case EGettingCerts:
1.145 + CertStore().CancelList();
1.146 + break;
1.147 + case ECheckNotification:
1.148 + case EIdle:
1.149 + case EFinished:
1.150 + // We /may/ be deleting a cert in these states - fortunately cancel is lenient
1.151 + UnifiedCertStore().CancelRemove();
1.152 + break;
1.153 +
1.154 + default:
1.155 + User::Invariant();
1.156 + }
1.157 + }
1.158 +
1.159 +void CDeleteCertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
1.160 + {
1.161 + CSubscriberAction::ConstructL(aTestActionSpec);
1.162 +
1.163 + iFilter = CCertAttributeFilter::NewL();
1.164 + TInt pos = 0;
1.165 + TInt err1 = KErrNone;
1.166 +
1.167 + TPtrC8 pLabel1 = Input::ParseElement(aTestActionSpec.iActionBody, KCertTypeStart, KCertTypeEnd, pos, err1);
1.168 +
1.169 + if(err1 == KErrNone)
1.170 + {
1.171 + iCertDeleteType = HBufC8::NewL(pLabel1.Size());
1.172 + *iCertDeleteType = pLabel1;
1.173 + }
1.174 +
1.175 + pos=0;
1.176 + TInt err2 = KErrNone;
1.177 + TPtrC8 pLabel2 = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err2);
1.178 + if (err2 != KErrNone)
1.179 + {
1.180 + User::Leave(err2);
1.181 + }
1.182 +
1.183 + iCertLabel.Copy(pLabel2);
1.184 + if (iCertLabel.Compare(_L("*.*"))==0) // delete all certs
1.185 + {// Check that the flag has been set
1.186 + TPtrC8 pDeleteAll = Input::ParseElement(aTestActionSpec.iActionBody, KDeleteAllStart, KDeleteAllEnd, pos, err1);
1.187 + if (pDeleteAll!=KNullDesC8)
1.188 + {
1.189 + TLex8 lexer(pDeleteAll);
1.190 + TInt boolVal = 0;
1.191 + lexer.Val(boolVal);
1.192 + iDeleteAllCerts = (boolVal > 0) ? ETrue : EFalse;
1.193 + }
1.194 + }
1.195 + else if( err1 != KErrNone && err1 != KErrNotFound)
1.196 + {
1.197 + User::Leave(err1);
1.198 + }
1.199 +
1.200 + // Set expected result
1.201 + HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
1.202 + TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
1.203 + Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
1.204 + CleanupStack::PopAndDestroy(result);
1.205 + }
1.206 +
1.207 +void CDeleteCertificate::GetCerts(TRequestStatus& aStatus)
1.208 + {
1.209 + CertStore().List(iCertInfos, *iFilter, aStatus);
1.210 + }
1.211 +
1.212 +CDeleteCertificate::~CDeleteCertificate()
1.213 + {
1.214 + delete iCertDeleteType;
1.215 + iCertInfos.Close();
1.216 + delete iFilter;
1.217 + }
1.218 +
1.219 +void CDeleteCertificate::DeleteCert(TRequestStatus& aStatus)
1.220 + {
1.221 + TInt ix = KErrNotFound;
1.222 + TInt count = iCertInfos.Count();
1.223 + for (TInt i = count-1; i >= 0 ; i--)
1.224 + {
1.225 + if (iDeleteAllCerts)
1.226 + {// Just delete the first one we come across
1.227 + if (i>=0) // Still some certificates to delete
1.228 + { // Set the state back to continue
1.229 + iState = EIdle;
1.230 + }
1.231 +
1.232 + ix = i;
1.233 + break;
1.234 + }
1.235 + // Only delete if there's a label match and the certificate is of specified type
1.236 + else if (iCertInfos[i]->Label() == iCertLabel && CheckCertType(*iCertInfos[i]) )
1.237 + {
1.238 + ix = i;
1.239 + break;
1.240 + }
1.241 + }
1.242 +
1.243 + TRequestStatus* status = &aStatus;
1.244 + if (ix == KErrNotFound)
1.245 + {
1.246 + TInt result = KErrNone;
1.247 +
1.248 + if(iDeleteAllCerts)
1.249 + result = KErrNone;
1.250 + else if(iCertDeleteType == NULL)
1.251 + result = KErrNotSupported;
1.252 + else
1.253 + result = KErrNotFound;
1.254 +
1.255 + User::RequestComplete(status, result);
1.256 + }
1.257 + else
1.258 + {
1.259 + iCertInfoToDelete = iCertInfos[ix];
1.260 + UnifiedCertStore().Remove(*iCertInfos[ix], aStatus);
1.261 + }
1.262 + }
1.263 +
1.264 +TBool CDeleteCertificate::CheckCertType( CCTCertInfo& aCertInfo )
1.265 + {
1.266 + if(iCertDeleteType == NULL)
1.267 + return EFalse;
1.268 +
1.269 + TBool returnValue = EFalse;
1.270 + switch(aCertInfo.CertificateOwnerType())
1.271 + {
1.272 + case ECACertificate:
1.273 + if(iCertDeleteType->Compare(KCACert) == 0 )
1.274 + returnValue = ETrue;
1.275 + break;
1.276 + case EUserCertificate:
1.277 + if(iCertDeleteType->Compare(KUserCert) == 0 )
1.278 + returnValue = ETrue;
1.279 + break;
1.280 + case EPeerCertificate:
1.281 + if(iCertDeleteType->Compare(KPeerCert) == 0 )
1.282 + returnValue = ETrue;
1.283 + break;
1.284 + }
1.285 + return returnValue;
1.286 + }
1.287 +
1.288 +void CDeleteCertificate::DoReportAction()
1.289 + {
1.290 + iOut.writeString(_L("Deleting certificate..."));
1.291 + iOut.writeNewLine();
1.292 + iOut.writeString(_L("\tLabel = "));
1.293 + iOut.writeString(iCertLabel);
1.294 + iOut.writeNewLine();
1.295 + iOut.writeNewLine();
1.296 + }
1.297 +
1.298 +void CDeleteCertificate::DoCheckResult(TInt aError)
1.299 + {
1.300 + if (iFinished)
1.301 + {
1.302 + if (aError == KErrNone && iCertInfoToDelete)
1.303 + {
1.304 + switch (iCertInfoToDelete->CertificateOwnerType())
1.305 + {
1.306 + case ECACertificate:
1.307 + iConsole.Write(_L("\tCA certificate deleted successfully\n"));
1.308 + iOut.writeString(_L("\tCA certificate deleted successfully"));
1.309 + break;
1.310 +
1.311 + case EUserCertificate:
1.312 + iConsole.Write(_L("\tUser certificate deleted successfully\n"));
1.313 + iOut.writeString(_L("\tUser certificate deleted successfully"));
1.314 + break;
1.315 +
1.316 + case EPeerCertificate:
1.317 + iConsole.Write(_L("\tPeer certificate deleted successfully\n"));
1.318 + iOut.writeString(_L("\tPeer certificate deleted successfully"));
1.319 + break;
1.320 + default:
1.321 + iConsole.Write(_L("\tUnknown owner certificate deleted successfully\n"));
1.322 + iOut.writeString(_L("\tUnknown owner certificate deleted successfully"));
1.323 + break;
1.324 + }
1.325 + }
1.326 + iOut.writeNewLine();
1.327 + iOut.writeNewLine();
1.328 + }
1.329 + }
1.330 +
1.331 +void CDeleteCertificate::Reset()
1.332 + {
1.333 + iState = EIdle;
1.334 + iCertInfos.Close();
1.335 + }
1.336 +
1.337 +
1.338 +/////////////////////////////////////////////////////////////////////////////////
1.339 +//CDeleteRetrieveCertificate
1.340 +/////////////////////////////////////////////////////////////////////////////////
1.341 +CDeleteRetrieveCertificate::CDeleteRetrieveCertificate(RFs& aFs, CConsoleBase& aConsole,
1.342 + Output& aOut)
1.343 +: CSubscriberAction(aFs, aConsole, aOut), iState(EIdle)
1.344 + {
1.345 + }
1.346 +
1.347 +void CDeleteRetrieveCertificate::PerformAction(TRequestStatus& aStatus)
1.348 + {
1.349 + TRequestStatus* status = &aStatus;
1.350 + switch (iState)
1.351 + {
1.352 + case EIdle:
1.353 + //get the certs
1.354 + iState = EDeletingCert;
1.355 + //get the certs
1.356 + GetCerts(aStatus);
1.357 + if (aStatus == KErrNoMemory)
1.358 + {
1.359 + iState = EFinished;
1.360 + }
1.361 + break;
1.362 +
1.363 + case EDeletingCert:
1.364 + {
1.365 + if (iNotificationSubscribed)
1.366 + {
1.367 + iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
1.368 + iNotifier->StartNotification();
1.369 + iState = ECheckNotification;
1.370 + }
1.371 + else
1.372 + {
1.373 + iState = EGettingCerts;
1.374 + }
1.375 + //delete the cert
1.376 + DeleteCert(aStatus);
1.377 + break;
1.378 + }
1.379 +
1.380 + case ECheckNotification:
1.381 + {
1.382 + TInt ret=KErrNone;
1.383 + if (!iNotifierFlag)
1.384 + {
1.385 + ret=KErrGeneral;
1.386 + }
1.387 + if (ret!=KErrNone)
1.388 + {
1.389 + iState = EFinished;
1.390 + }
1.391 + else
1.392 + {
1.393 + iState = EGettingCerts;
1.394 + }
1.395 + TRequestStatus* status = &aStatus;
1.396 + User::RequestComplete(status, ret);
1.397 + }
1.398 + break;
1.399 + case EGettingCerts:
1.400 + {
1.401 + iState = EFinished;
1.402 + //get the cert
1.403 + RetrieveCerts(aStatus);
1.404 + break;
1.405 + }
1.406 + case EFinished:
1.407 + {
1.408 + if (aStatus == iExpectedResult)
1.409 + {
1.410 + iResult = ETrue;
1.411 + }
1.412 + else
1.413 + {
1.414 + iResult = EFalse;
1.415 + }
1.416 + if (aStatus == KErrNoMemory)
1.417 + {
1.418 + iState = EIdle;
1.419 + }
1.420 + else
1.421 + {
1.422 + iFinished = ETrue;
1.423 + }
1.424 + User::RequestComplete(status, aStatus.Int());
1.425 + }
1.426 + break;
1.427 + default:
1.428 + {
1.429 + //some kind of error behaviour
1.430 + }
1.431 + }
1.432 + }
1.433 +
1.434 +void CDeleteRetrieveCertificate::PerformCancel()
1.435 + {
1.436 + }
1.437 +
1.438 +void CDeleteRetrieveCertificate::Reset()
1.439 + {
1.440 + __ASSERT_DEBUG(EFalse, User::Panic(_L("CDeleteRetrieveCertificate::Reset()"), 1));
1.441 + }
1.442 +
1.443 +////////////////////////////////////////////////////////////////////////////////
1.444 +//CDeleteCACertificate
1.445 +//////////////////////////////////////////////////////////////////////////////////
1.446 +
1.447 +CTestAction* CDeleteRetrieveCACertificate::NewL(RFs& aFs,
1.448 + CConsoleBase& aConsole,
1.449 + Output& aOut,
1.450 + const TTestActionSpec& aTestActionSpec)
1.451 + {
1.452 + CDeleteRetrieveCACertificate* self =
1.453 + new(ELeave) CDeleteRetrieveCACertificate(aFs, aConsole, aOut);
1.454 + CleanupStack::PushL(self);
1.455 + self->ConstructL(aTestActionSpec);
1.456 + CleanupStack::Pop(self);
1.457 + return self;
1.458 + }
1.459 +
1.460 +CDeleteRetrieveCACertificate::CDeleteRetrieveCACertificate(RFs& aFs, CConsoleBase& aConsole,
1.461 + Output& aOut)
1.462 + :CDeleteRetrieveCertificate(aFs, aConsole, aOut)
1.463 + {
1.464 + }
1.465 +
1.466 +void CDeleteRetrieveCACertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
1.467 + {
1.468 + CSubscriberAction::ConstructL(aTestActionSpec);
1.469 + iCertlisted = new(ELeave) RPointerArray<HBufC8>;
1.470 + iFilter = CCertAttributeFilter::NewL();
1.471 + TInt pos = 0;
1.472 + TInt err = KErrNone;
1.473 + TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
1.474 + if (err != KErrNone)
1.475 + {
1.476 + User::Leave(err);
1.477 + }
1.478 + iCertLabel.Copy(pLabel);
1.479 +
1.480 + // Set expected result
1.481 + pos = 0;
1.482 +
1.483 + HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
1.484 + TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
1.485 + Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
1.486 + CleanupStack::PopAndDestroy(result);
1.487 + }
1.488 +
1.489 +void CDeleteRetrieveCACertificate::GetCerts(TRequestStatus& aStatus)
1.490 + {
1.491 + CertStore().List(iCertInfos, *iFilter, aStatus);
1.492 + }
1.493 +
1.494 +void CDeleteRetrieveCACertificate::RetrieveCerts(TRequestStatus& aStatus)
1.495 + {
1.496 + TRequestStatus* status = &aStatus;
1.497 + TInt ix = KErrNotFound;
1.498 + TInt count = iCertInfos.Count();
1.499 + for (TInt i = 0; i < count; i++)
1.500 + {
1.501 + if (iCertInfos[i]->Label() == iCertLabel)
1.502 + {
1.503 + ix = i;
1.504 + break;
1.505 + }
1.506 + }
1.507 + if (ix == KErrNotFound)
1.508 + {
1.509 + User::RequestComplete(status, ix);
1.510 + }
1.511 + else
1.512 + {
1.513 + iCertInfoToRetrieve = iCertInfos[ix];
1.514 +
1.515 + HBufC8* buf = HBufC8::NewLC(iCertInfoToRetrieve->Size());
1.516 + User::LeaveIfError(iCertlisted->Append(buf));
1.517 + CleanupStack::Pop();//buf
1.518 + __ASSERT_DEBUG(!iBuf, User::Panic(_L("CListCACertificates"), 1));
1.519 + iBuf = new(ELeave) TPtr8(buf->Des());
1.520 + CertStore().Retrieve(*iCertInfoToRetrieve, *iBuf, aStatus);
1.521 + }
1.522 + }
1.523 +
1.524 +CDeleteRetrieveCACertificate::~CDeleteRetrieveCACertificate()
1.525 + {
1.526 + iCertInfos.Close();
1.527 + delete iFilter;
1.528 + if (iCertlisted)
1.529 + {
1.530 + iCertlisted->ResetAndDestroy();
1.531 + delete iCertlisted;
1.532 + }
1.533 + delete iBuf;
1.534 + }
1.535 +
1.536 +void CDeleteRetrieveCACertificate::DeleteCert(TRequestStatus& aStatus)
1.537 + {
1.538 + TRequestStatus* status = &aStatus;
1.539 + TInt ix = KErrNotFound;
1.540 + TInt count = iCertInfos.Count();
1.541 + for (TInt i = 0; i < count; i++)
1.542 + {
1.543 + if (iCertInfos[i]->Label() == iCertLabel)
1.544 + {
1.545 + ix = i;
1.546 + break;
1.547 + }
1.548 + }
1.549 + if (ix == KErrNotFound)
1.550 + {
1.551 + User::RequestComplete(status, ix);
1.552 + }
1.553 + else
1.554 + {
1.555 + iCertInfoToDelete = iCertInfos[ix];
1.556 + UnifiedCertStore().Remove(*iCertInfoToDelete, aStatus);
1.557 + }
1.558 + }
1.559 +
1.560 +void CDeleteRetrieveCACertificate::DoReportAction()
1.561 + {
1.562 + iOut.writeString(_L("Deleting certificate..."));
1.563 + iOut.writeNewLine();
1.564 + iOut.writeString(_L("\tLabel = "));
1.565 + iOut.writeString(iCertLabel);
1.566 + iOut.writeNewLine();
1.567 + iOut.writeNewLine();
1.568 + }
1.569 +
1.570 +void CDeleteRetrieveCACertificate::DoCheckResult(TInt aError)
1.571 + {
1.572 + if (iFinished)
1.573 + {
1.574 + if (aError == KErrNone && iResult)
1.575 + {
1.576 + switch (iCertInfoToDelete->CertificateOwnerType())
1.577 + {
1.578 + case ECACertificate:
1.579 + iConsole.Write(_L("\tCA certificate deleted successfully\n"));
1.580 + iOut.writeString(_L("\tCA certificate deleted successfully"));
1.581 + break;
1.582 +
1.583 + case EUserCertificate:
1.584 + iConsole.Write(_L("\tUser certificate deleted successfully\n"));
1.585 + iOut.writeString(_L("\tUser certificate deleted successfully"));
1.586 + break;
1.587 +
1.588 + default:
1.589 + iConsole.Write(_L("\tUnknown owner certificate deleted successfully\n"));
1.590 + iOut.writeString(_L("\tUnknown owner certificate deleted successfully"));
1.591 + break;
1.592 + }
1.593 + }
1.594 + else
1.595 + {
1.596 + if (iResult)
1.597 + {
1.598 + iConsole.Write(_L("\tCA OK\n"));
1.599 + iOut.writeString(_L("\tCA OK"));
1.600 + }
1.601 + }
1.602 + iOut.writeNewLine();
1.603 + iOut.writeNewLine();
1.604 + }
1.605 + }
1.606 +
1.607 +////////////////////////////////////////////////////////////////////////////////
1.608 +//CDeleteUserCertificate
1.609 +//////////////////////////////////////////////////////////////////////////////////
1.610 +CTestAction* CDeleteRetrieveUserCertificate::NewL(RFs& aFs,
1.611 + CConsoleBase& aConsole,
1.612 + Output& aOut,
1.613 + const TTestActionSpec& aTestActionSpec)
1.614 + {
1.615 + CDeleteRetrieveUserCertificate* self =
1.616 + new(ELeave) CDeleteRetrieveUserCertificate(aFs, aConsole, aOut);
1.617 + CleanupStack::PushL(self);
1.618 + self->ConstructL(aTestActionSpec);
1.619 + CleanupStack::Pop(self);
1.620 + return self;
1.621 + }
1.622 +
1.623 +CDeleteRetrieveUserCertificate::CDeleteRetrieveUserCertificate(RFs& aFs, CConsoleBase& aConsole,
1.624 + Output& aOut)
1.625 + :CDeleteRetrieveCertificate(aFs, aConsole, aOut)
1.626 + {
1.627 + }
1.628 +
1.629 +void CDeleteRetrieveUserCertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
1.630 + {
1.631 + CSubscriberAction::ConstructL(aTestActionSpec);
1.632 + iCertlisted = new(ELeave) RPointerArray<HBufC8>;
1.633 + iFilter = CCertAttributeFilter::NewL();
1.634 + TInt pos = 0;
1.635 + TInt err = KErrNone;
1.636 + TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
1.637 + if (err != KErrNone)
1.638 + {
1.639 + User::Leave(err);
1.640 + }
1.641 + iCertLabel.Copy(pLabel);
1.642 +
1.643 + // Set expected result
1.644 + HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
1.645 + TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
1.646 + Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
1.647 + CleanupStack::PopAndDestroy(result);
1.648 + }
1.649 +
1.650 +void CDeleteRetrieveUserCertificate::GetCerts(TRequestStatus& aStatus)
1.651 + {
1.652 + CertStore().List(iCertInfos, *iFilter, aStatus);
1.653 + }
1.654 +
1.655 +void CDeleteRetrieveUserCertificate::RetrieveCerts(TRequestStatus& aStatus)
1.656 + {
1.657 + TRequestStatus* status = &aStatus;
1.658 + TInt ix = KErrNotFound;
1.659 + TInt count = iCertInfos.Count();
1.660 + for (TInt i = 0; i < count; i++)
1.661 + {
1.662 + if (iCertInfos[i]->Label() == iCertLabel)
1.663 + {
1.664 + ix = i;
1.665 + break;
1.666 + }
1.667 + }
1.668 + if (ix == KErrNotFound)
1.669 + {
1.670 + User::RequestComplete(status, ix);
1.671 + }
1.672 + else
1.673 + {
1.674 + iCertInfoToRetrieve = iCertInfos[ix];
1.675 +
1.676 + HBufC8* buf = HBufC8::NewLC(iCertInfoToRetrieve->Size());
1.677 + User::LeaveIfError(iCertlisted->Append(buf));
1.678 + CleanupStack::Pop();//buf
1.679 + //__ASSERT_DEBUG(!iBuf, User::Panic(_L("CListCACertificates"), 1));
1.680 + iBuf = new(ELeave) TPtr8(buf->Des());
1.681 + CertStore().Retrieve(*iCertInfoToRetrieve, *iBuf, aStatus);
1.682 + }
1.683 + }
1.684 +
1.685 +CDeleteRetrieveUserCertificate::~CDeleteRetrieveUserCertificate()
1.686 + {
1.687 + iCertInfos.Close();
1.688 + delete iFilter;
1.689 + if (iCertlisted)
1.690 + {
1.691 + iCertlisted->ResetAndDestroy();
1.692 + delete iCertlisted;
1.693 + }
1.694 + delete iBuf;
1.695 + }
1.696 +
1.697 +void CDeleteRetrieveUserCertificate::DeleteCert(TRequestStatus& aStatus)
1.698 + {
1.699 + TRequestStatus* status = &aStatus;
1.700 + TInt ix = KErrNotFound;
1.701 + TInt count = iCertInfos.Count();
1.702 + for (TInt i = 0; i < count; i++)
1.703 + {
1.704 + if (iCertInfos[i]->Label() == iCertLabel)
1.705 + {
1.706 + ix = i;
1.707 + break;
1.708 + }
1.709 + }
1.710 + if (ix == KErrNotFound)
1.711 + {
1.712 + User::RequestComplete(status, ix);
1.713 + }
1.714 + else
1.715 + {
1.716 + CCTCertInfo* certInfo = iCertInfos[ix];
1.717 + UnifiedCertStore().Remove(*certInfo, aStatus);
1.718 + }
1.719 + }
1.720 +
1.721 +void CDeleteRetrieveUserCertificate::DoReportAction()
1.722 + {
1.723 + iOut.writeString(_L("Deleting user certificate..."));
1.724 + iOut.writeNewLine();
1.725 + iOut.writeString(_L("\tLabel = "));
1.726 + iOut.writeString(iCertLabel);
1.727 + iOut.writeNewLine();
1.728 + iOut.writeNewLine();
1.729 + }
1.730 +
1.731 +void CDeleteRetrieveUserCertificate::DoCheckResult(TInt aError)
1.732 + {
1.733 + if (iFinished)
1.734 + {
1.735 + if (aError == KErrNone && iResult)
1.736 + {
1.737 + iConsole.Write(_L("\tuser cert deleted successfully\n"));
1.738 + iOut.writeString(_L("\tuser cert deleted successfully"));
1.739 + iOut.writeNewLine();
1.740 + iOut.writeNewLine();
1.741 + }
1.742 + else
1.743 + {
1.744 + if (iResult)
1.745 + {
1.746 + iConsole.Write(_L("\tnot retrieved but expected\n"));
1.747 + iOut.writeString(_L("\tCA OK"));
1.748 + }
1.749 + else
1.750 + {
1.751 + iConsole.Write(_L("\tuser cert deleted successfully\n"));
1.752 + iOut.writeString(_L("\tuser cert deleted successfully"));
1.753 + iOut.writeNewLine();
1.754 + iOut.writeNewLine();
1.755 + }
1.756 + }
1.757 + }
1.758 + }