os/security/cryptoservices/certificateandkeymgmt/tcertstore/t_certstoreactions.cpp
First public contribution.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "t_certstoreactions.h"
20 #include "t_certstoreout.h"
21 #include "t_certstoredefs.h"
25 #include <securityerr.h>
26 #include <ecom/ecom.h>
27 #include "testutilclient.h"
28 #include <swicertstore.h>
30 // CCertStoreChangeNotifier //////////////////////////////////////////////////////////////
31 CCertStoreChangeNotifier* CCertStoreChangeNotifier::NewL(TInt& aNotificationFlag)
33 CCertStoreChangeNotifier* self = new(ELeave) CCertStoreChangeNotifier(aNotificationFlag);
34 CleanupStack::PushL(self);
39 CCertStoreChangeNotifier::~CCertStoreChangeNotifier()
42 iCertStoreChangeProperty.Close();
44 CCertStoreChangeNotifier::CCertStoreChangeNotifier(TInt& aNotificationFlag): CActive(EPriorityHigh), iNotifiedCounter(aNotificationFlag)
46 CActiveScheduler::Add(this);
48 void CCertStoreChangeNotifier::ConstructL()
50 TInt r=iCertStoreChangeProperty.Attach(KUnifiedCertStorePropertyCat,EUnifiedCertStoreFlag,EOwnerThread);
51 User::LeaveIfError(r);
53 void CCertStoreChangeNotifier::StartNotification()
55 iCertStoreChangeProperty.Subscribe(iStatus);
58 void CCertStoreChangeNotifier::DoCancel()
60 iCertStoreChangeProperty.Cancel();
62 void CCertStoreChangeNotifier::RunL()
67 User::RequestComplete(iCompleteStatus, KErrNone);
70 void CCertStoreChangeNotifier::SetCompleteStatus(TRequestStatus* aStatus)
72 iCompleteStatus=aStatus;
75 // COpenCertStore //////////////////////////////////////////////////////////////
77 _LIT(KCOpenCertStore, "COpenCertStore");
79 COpenCertStore::~COpenCertStore()
85 case EUnifiedCertStore:
86 delete iUnifiedCertStore;
90 iSwiCertStore->Release();
94 User::Panic(KCOpenCertStore, 1);
99 void COpenCertStore::SetCertStore(CUnifiedCertStore* aCertStore)
101 __ASSERT_ALWAYS(!iSet, User::Panic(KCOpenCertStore, 1));
102 iType = EUnifiedCertStore;
103 iUnifiedCertStore = aCertStore;
107 CUnifiedCertStore& COpenCertStore::AsUnifiedCertStore()
109 __ASSERT_ALWAYS(iSet && iType == EUnifiedCertStore, User::Panic(KCOpenCertStore, 1));
110 return *iUnifiedCertStore;
114 void COpenCertStore::SetCertStore(CSWICertStore* aCertStore)
116 __ASSERT_ALWAYS(!iSet, User::Panic(KCOpenCertStore, 1));
117 iType = ESWICertStore;
118 iSwiCertStore = aCertStore;
122 CSWICertStore& COpenCertStore::AsSWICertStore()
124 __ASSERT_ALWAYS(iSet && iType == ESWICertStore, User::Panic(KCOpenCertStore, 1));
125 return *iSwiCertStore;
129 TCertStoreType COpenCertStore::Type()
131 __ASSERT_ALWAYS(iSet, User::Panic(KCOpenCertStore, 1));
136 MCertStore& COpenCertStore::CertStore()
138 __ASSERT_ALWAYS(iSet, User::Panic(KCOpenCertStore, 1));
140 MCertStore* result = NULL;
144 case EUnifiedCertStore:
145 result = iUnifiedCertStore;
149 result = iSwiCertStore;
153 User::Panic(KCOpenCertStore, 1);
159 // CSharedData /////////////////////////////////////////////////////////////////
161 CSharedData::~CSharedData()
163 iCertStores.ResetAndDestroy();
165 DeleteCertificateAppInfoManager();
166 REComSession::FinalClose();
169 void CSharedData::InitCertificateAppInfoManagerL()
171 ASSERT(!iCertificateAppInfoManager);
172 User::LeaveIfError(iFs.Connect());
173 iCertificateAppInfoManager = CCertificateAppInfoManager::NewL(iFs, ETrue);
176 void CSharedData::DeleteCertificateAppInfoManager()
178 if (iCertificateAppInfoManager)
180 delete iCertificateAppInfoManager;
181 iCertificateAppInfoManager = NULL;
186 RPointerArray<COpenCertStore>& CSharedData::CertStores()
191 /////////////////////////////////////////////////////////////////////////////////
192 //CCertStoreTestAction base class
193 /////////////////////////////////////////////////////////////////////////////////
195 CCertStoreTestAction::~CCertStoreTestAction()
199 CCertStoreTestAction::CCertStoreTestAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
200 CTestAction(aConsole, aOut), iFs(aFs)
204 CSharedData& CCertStoreTestAction::CertStoreSharedData()
208 SetSharedData(new CSharedData);
211 CSharedData* data = static_cast<CSharedData*>(SharedData());
212 ASSERT(data); // panic if out of memory
216 void CCertStoreTestAction::DoPerformPrerequisite(TRequestStatus& aStatus)
218 // Ensure shared data is already created to prevent panic in oom test
219 CertStoreSharedData();
221 iActionState = EAction;
222 TRequestStatus* status = &aStatus;
223 User::RequestComplete(status, KErrNone);
226 void CCertStoreTestAction::DoPerformPostrequisite(TRequestStatus& aStatus)
228 TRequestStatus* status = &aStatus;
229 User::RequestComplete(status, KErrNone);
232 CCertificateAppInfoManager* CCertStoreTestAction::TheCertificateAppInfoManager()
234 return CertStoreSharedData().iCertificateAppInfoManager;
237 void CCertStoreTestAction::InitTheCertificateAppInfoManagerL()
239 CertStoreSharedData().InitCertificateAppInfoManagerL();
242 void CCertStoreTestAction::DeleteTheCertificateAppInfoManager()
244 CertStoreSharedData().DeleteCertificateAppInfoManager();
247 RPointerArray<COpenCertStore>& CCertStoreTestAction::CertStores()
249 return CertStoreSharedData().CertStores();
252 TInt CCertStoreTestAction::CertStoreCount()
254 return CertStores().Count();
257 TCertStoreType CCertStoreTestAction::CertStoreType(TInt aIndex)
259 return CertStores()[aIndex]->Type();
262 MCertStore& CCertStoreTestAction::CertStore(TInt aIndex)
264 return CertStores()[aIndex]->CertStore();
267 void CCertStoreTestAction::AddCertStoreL(CUnifiedCertStore* aCertStore)
269 COpenCertStore* openStore = new (ELeave) COpenCertStore;
270 CleanupStack::PushL(openStore);
271 User::LeaveIfError(CertStores().Append(openStore));
272 CleanupStack::Pop(openStore);
273 openStore->SetCertStore(aCertStore); // takes ownership
276 CUnifiedCertStore& CCertStoreTestAction::UnifiedCertStore(TInt aIndex)
278 return CertStores()[aIndex]->AsUnifiedCertStore();
282 void CCertStoreTestAction::AddCertStoreL(CSWICertStore* aCertStore)
284 COpenCertStore* openStore = new (ELeave) COpenCertStore;
285 CleanupStack::PushL(openStore);
286 User::LeaveIfError(CertStores().Append(openStore));
287 CleanupStack::Pop(openStore);
288 openStore->SetCertStore(aCertStore); // takes ownership
291 CSWICertStore& CCertStoreTestAction::SWICertStore(TInt aIndex)
293 return CertStores()[aIndex]->AsSWICertStore();
297 void CCertStoreTestAction::RemoveCertStore(TInt aIndex)
299 COpenCertStore* openStore = CertStores()[aIndex];
300 TBool delCertstore = EFalse;
302 if (openStore->Type() == ESWICertStore)
304 delCertstore = ETrue;
307 CertStores().Remove(aIndex);
312 RTestUtilSession testutil;
313 User::LeaveIfError(testutil.Connect());
314 CleanupClosePushL(testutil);
316 TDriveUnit sysDrive (RFs::GetSystemDrive());
317 TDriveName driveName(sysDrive.Name());
318 TBuf<64> certstoreFile (driveName);
319 certstoreFile.Append(_L("\\Resource\\SwiCertstore\\"));
320 testutil.RmDir(certstoreFile);
322 CleanupStack::PopAndDestroy(&testutil);
325 /////////////////////////////////////////////////////////////////////////////////
326 //CSubscriberAction base class
327 /////////////////////////////////////////////////////////////////////////////////
328 CSubscriberAction::~CSubscriberAction()
333 CSubscriberAction::CSubscriberAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
334 :CCertStoreTestAction(aFs, aConsole, aOut)
337 void CSubscriberAction::ConstructL(const TTestActionSpec& aTestActionSpec)
339 CCertStoreTestAction::ConstructL(aTestActionSpec);
342 TPtrC8 ptr1 = Input::ParseElement(aTestActionSpec.iActionBody, KChangeNotifiedStart, KChangeNotifiedEnd, pos, err);
343 if (ptr1 != KNullDesC8)
347 TInt ret=lexi.Val(val);
350 iNotificationSubscribed=1;
354 /////////////////////////////////////////////////////////////////
355 //CInitialiseCertStore::
356 ///////////////////////////////////////////////////////////////////
357 CTestAction* CInitialiseCertStore::NewL(RFs& aFs,
358 CConsoleBase& aConsole,
360 const TTestActionSpec& aTestActionSpec)
362 CTestAction* self = CInitialiseCertStore::NewLC(aFs,
363 aConsole, aOut, aTestActionSpec);
364 CleanupStack::Pop(self);
368 CTestAction* CInitialiseCertStore::NewLC(RFs& aFs,
369 CConsoleBase& aConsole,
371 const TTestActionSpec& aTestActionSpec)
373 CInitialiseCertStore* self = new(ELeave) CInitialiseCertStore(aFs, aConsole, aOut);
374 CleanupStack::PushL(self);
375 self->ConstructL(aTestActionSpec);
379 CInitialiseCertStore::~CInitialiseCertStore()
381 delete iNewUnifiedCertStore;
382 iFilterOrdering.Close();
383 iExpectedOrderingResult.Close();
386 CInitialiseCertStore::CInitialiseCertStore(RFs& aFs,
387 CConsoleBase& aConsole,
390 :CCertStoreTestAction(aFs, aConsole, aOut), iState(ENew)
394 void CInitialiseCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
396 CCertStoreTestAction::ConstructL(aTestActionSpec);
401 Input::ParseElement(aTestActionSpec.iActionBody, KModeStart, KModeEnd, pos, err);
402 if (ptr == KNullDesC8)
404 User::Leave(KErrNotFound);
407 if (ptr == _L8("read"))
409 iOpenedForWrite = EFalse;
411 else if (ptr == _L8("write"))
413 iOpenedForWrite = ETrue;
417 User::Leave(KErrNotSupported);
421 TPtrC8 ptr1 = Input::ParseElement(aTestActionSpec.iActionBody, KOrderingFilterStart, KOrderingFilterEnd, pos, err);
422 if (ptr1 != KNullDesC8)
430 while (lastPos<ptr1.Length() && ptr1[lastPos]!=',')
434 TPtrC8 uidInA(&ptr1[startPos], lastPos-startPos);
437 TInt err=lexi.Val(uidInD);
438 User::LeaveIfError(iFilterOrdering.Append(uidInD));
441 while (lastPos < ptr1.Length());
445 TPtrC8 ptr2 = Input::ParseElement(aTestActionSpec.iActionResult, KOrderingResultStart, KOrderingResultEnd, pos, err);
446 if (ptr2 != KNullDesC8)
454 while (lastPos<ptr2.Length() && ptr2[lastPos]!=',')
458 TPtrC8 uidInA(&ptr2[startPos], lastPos-startPos);
461 TInt err=lexi.Val(uidInD);
462 User::LeaveIfError(iExpectedOrderingResult.Append(uidInD));
465 while (lastPos < ptr2.Length());
470 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
471 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
472 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
473 CleanupStack::PopAndDestroy(result);
476 void CInitialiseCertStore::PerformAction(TRequestStatus& aStatus)
478 if (aStatus != KErrNone)
486 __ASSERT_DEBUG(!iNewUnifiedCertStore, User::Panic(_L("CInitialiseCertStore"), 1));
487 iNewUnifiedCertStore = CUnifiedCertStore::NewL(iFs, iOpenedForWrite, iFilterOrdering);
489 iNewUnifiedCertStore->Initialize(aStatus);
495 AddCertStoreL(iNewUnifiedCertStore);
496 iNewUnifiedCertStore = 0; // we don't own this any more
497 if (iFilterOrdering.Count()==0)
503 iState = ECheckOrder;
505 TRequestStatus* status = &aStatus;
506 User::RequestComplete(status, KErrNone);
513 TInt count = UnifiedCertStore().CertStoreCount();
514 MCTCertStore* p=NULL;
518 for (TInt i=0;i<count;i++)
520 p=&(UnifiedCertStore().CertStore(i));
521 current = p->Token().TokenType().Type().iUid;
522 if (previous != current)
527 TInt32 l1=iExpectedOrderingResult[j];
528 if (current != iExpectedOrderingResult[j])
534 if (count<iExpectedOrderingResult.Count())
539 TRequestStatus* status = &aStatus;
540 User::RequestComplete(status, ret);
545 TRequestStatus* status = &aStatus;
546 User::RequestComplete(status, aStatus.Int());
547 if (aStatus == iExpectedResult)
555 if (aStatus == KErrNoMemory)
568 void CInitialiseCertStore::PerformCancel()
573 ASSERT(iNewUnifiedCertStore);
574 iNewUnifiedCertStore->CancelInitialize();
583 void CInitialiseCertStore::Reset()
586 delete iNewUnifiedCertStore;
587 iNewUnifiedCertStore = 0;
590 void CInitialiseCertStore::DoReportAction()
592 iOut.writeString(_L("Initializing certstore manager..."));
596 void CInitialiseCertStore::DoCheckResult(TInt aError)
600 if (aError == KErrNone)
602 iConsole.Write(_L("\tstore manager initialised successfully\n"));
603 iOut.writeString(_L("\tstore manager initialised successfully"));
607 else if (aError == KErrInUse)
609 iConsole.Write(_L("\tstore manager initialised error : KErrInUse\n"));
610 iOut.writeString(_L("\tstore manager initialization error : KErrInUse"));
617 /////////////////////////////////////////////////////////////////
618 //COnlyCreateCertStore::
619 ///////////////////////////////////////////////////////////////////
621 CTestAction* COnlyCreateCertStore::NewL(RFs& aFs,
622 CConsoleBase& aConsole,
624 const TTestActionSpec& aTestActionSpec)
626 COnlyCreateCertStore* self = new(ELeave) COnlyCreateCertStore(aFs, aConsole, aOut);
627 CleanupStack::PushL(self);
628 self->ConstructL(aTestActionSpec);
629 CleanupStack::Pop(self);
633 COnlyCreateCertStore::COnlyCreateCertStore(RFs& aFs,
634 CConsoleBase& aConsole,
636 :CCertStoreTestAction(aFs, aConsole, aOut), iState(EInit)
640 void COnlyCreateCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
642 CCertStoreTestAction::ConstructL(aTestActionSpec);
644 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
645 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
646 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
647 CleanupStack::PopAndDestroy(result);
650 void COnlyCreateCertStore::PerformAction(TRequestStatus& aStatus)
656 __ASSERT_DEBUG(!iNewUnifiedCertStore, User::Panic(_L("CInitialiseCertStore"), 1));
657 TRAPD(err, iNewUnifiedCertStore = CUnifiedCertStore::NewL(iFs, ETrue));
661 TRequestStatus* status = &aStatus;
662 User::RequestComplete(status, err);
666 AddCertStoreL(iNewUnifiedCertStore);
667 iNewUnifiedCertStore = 0; // we don't own this any more
669 TRequestStatus* status = &aStatus;
670 User::RequestComplete(status, err);
677 TRequestStatus* status = &aStatus;
678 User::RequestComplete(status, aStatus.Int());
679 if (aStatus == iExpectedResult)
687 if (aStatus == KErrNoMemory)
700 void COnlyCreateCertStore::PerformCancel()
704 void COnlyCreateCertStore::Reset()
706 __ASSERT_DEBUG(EFalse, User::Panic(_L("COnlyCreateCertStore::Reset()"), 1));
709 void COnlyCreateCertStore::DoReportAction()
711 iOut.writeString(_L("Only creating certstore manager..."));
715 void COnlyCreateCertStore::DoCheckResult(TInt aError)
719 if (aError == KErrNone)
721 iConsole.Write(_L("\tstore manager created successfully\n"));
722 iOut.writeString(_L("\tstore manager created successfully"));
726 else if (aError == KErrInUse)
728 iConsole.Write(_L("\tstore manager creation error : KErrInUse\n"));
729 iOut.writeString(_L("\tstore manager creation error : KErrInUse"));
736 /////////////////////////////////////////////////////////////////////////////////
738 /////////////////////////////////////////////////////////////////////////////////
740 CTestAction* CDeleteCertStore::NewL(RFs& aFs,
741 CConsoleBase& aConsole,
743 const TTestActionSpec& aTestActionSpec)
745 CTestAction* self = CDeleteCertStore::NewLC(aFs, aConsole, aOut, aTestActionSpec);
746 CleanupStack::Pop(self);
750 CTestAction* CDeleteCertStore::NewLC(RFs& aFs,
751 CConsoleBase& aConsole,
753 const TTestActionSpec& aTestActionSpec)
755 CDeleteCertStore* self = new(ELeave) CDeleteCertStore(aFs, aConsole, aOut);
756 CleanupStack::PushL(self);
757 self->ConstructL(aTestActionSpec);
761 CDeleteCertStore::~CDeleteCertStore()
765 CDeleteCertStore::CDeleteCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
766 : CCertStoreTestAction(aFs, aConsole, aOut), iState(EDelete)
770 void CDeleteCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
772 CCertStoreTestAction::ConstructL(aTestActionSpec);
774 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
775 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
776 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
777 CleanupStack::PopAndDestroy(result);
780 void CDeleteCertStore::PerformAction(TRequestStatus& aStatus)
786 TInt err = KErrNotFound;
787 TInt count = CertStoreCount();
790 RemoveCertStore(count - 1);
794 TRequestStatus* status = &aStatus;
795 User::RequestComplete(status, err);
801 TRequestStatus* status = &aStatus;
802 User::RequestComplete(status, aStatus.Int());
803 if (aStatus == iExpectedResult)
811 if (aStatus == KErrNoMemory)
824 void CDeleteCertStore::PerformCancel()
829 void CDeleteCertStore::Reset()
833 void CDeleteCertStore::DoReportAction()
835 iOut.writeString(_L("Deleting certstore manager..."));
839 void CDeleteCertStore::DoCheckResult(TInt aError)
843 if (aError == KErrNone)
845 iConsole.Write(_L("\tstore manager deleted successfully\n"));
846 iOut.writeString(_L("\tstore manager deleted successfully"));
852 iConsole.Write(_L("\tstore manager deleted failed\n"));
853 iOut.writeString(_L("\tstore manager deleted failed"));
860 CSetAppsAndTrust::~CSetAppsAndTrust()
866 void CSetAppsAndTrust::PerformAction(TRequestStatus& aStatus)
871 iState = ESetAppTrust;
877 // Find the certificate we want to set the trust settings for
878 // and edit its trust settings
880 TInt iEnd = iCertInfos.Count();
881 for (TInt i = 0; i < iEnd; i++)
883 if (iCertInfos[i]->Label() == iLabel)
885 if (iNotificationSubscribed)
889 iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
890 iNotifier->StartNotification();
892 iState = ECheckNotification;
898 DoSetAppTrust(*iCertInfos[i], aStatus);
902 TRequestStatus* status = &aStatus;
903 User::RequestComplete(status, KErrNotFound);
907 case ECheckNotification:
912 TRequestStatus* status = &aStatus;
913 User::RequestComplete(status, KErrNone);
917 iNotifier->SetCompleteStatus(&aStatus);
923 if (!iNotifierFlag && iNotificationSubscribed)
929 if (aStatus == iExpectedResult)
941 TRequestStatus* status = &aStatus;
942 User::RequestComplete(status, aStatus.Int());
952 void CSetAppsAndTrust::PerformCancel()
957 CertStore().CancelList();
959 case ECheckNotification:
970 void CSetAppsAndTrust::Reset()
972 iState = EGetCAEntries;
976 CSetAppsAndTrust::CSetAppsAndTrust(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
977 : CSubscriberAction(aFs, aConsole, aOut), iState(EGetCAEntries)
982 void CSetAppsAndTrust::ConstructL(const TTestActionSpec& aTestActionSpec)
984 CSubscriberAction::ConstructL(aTestActionSpec);
985 iFilter = CCertAttributeFilter::NewL();
987 // Let derived class do its own parsing
990 void CSetAppsAndTrust::GetCerts(TRequestStatus& aStatus)
992 CertStore().List(iCertInfos, *iFilter, aStatus);
995 void CSetAppsAndTrust::SetCertLabel(const TDesC8& aLabel)
1000 CTestAction* CSetApplications::NewL(RFs& aFs,
1001 CConsoleBase& aConsole,
1003 const TTestActionSpec& aTestActionSpec)
1005 CSetApplications* self = new(ELeave) CSetApplications(aFs, aConsole, aOut);
1006 CleanupStack::PushL(self);
1007 self->ConstructL(aTestActionSpec);
1008 CleanupStack::Pop(self);
1012 CSetApplications::~CSetApplications()
1014 iApplications.Close();
1017 CSetApplications::CSetApplications(RFs& aFs, CConsoleBase& aConsole,
1019 : CSetAppsAndTrust(aFs, aConsole, aOut)
1023 void CSetApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
1025 CSetAppsAndTrust::ConstructL(aTestActionSpec);
1027 TInt err = KErrNone;
1029 SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody,
1030 KCertLabelStart, KCertLabelEnd, pos, err));
1031 AppendUid(Input::ParseElement(aTestActionSpec.iActionBody, KUIDStart, KUIDEnd, pos, err));
1032 // Set expected result
1035 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
1036 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
1037 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
1038 CleanupStack::PopAndDestroy(result);
1041 void CSetApplications::AppendUid(const TDesC8& aUid)
1045 TInt err = KErrNone;
1046 while (err == KErrNone)
1049 err = lex.Val(u.iUid);
1050 if (err == KErrNone)
1053 User::LeaveIfError(iApplications.Append(u));
1058 void CSetApplications::DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus)
1060 UnifiedCertStore().SetApplicability(aCertInfo, iApplications, aStatus);
1063 void CSetApplications::DoPerformCancel()
1065 UnifiedCertStore().CancelSetApplicability();
1068 void CSetApplications::DoReportAction()
1070 iOut.writeString(_L("Setting Application settings..."));
1071 iOut.writeNewLine();
1072 iOut.writeString(_L("\tLabel = "));
1073 iOut.writeString(iLabel);
1074 iOut.writeNewLine();
1075 iOut.writeString(_L("\tApplications = "));
1076 TInt count = iApplications.Count();
1077 for (TInt i = 0; i < count; i++)
1079 iOut.writeNum(iApplications[i].iUid);
1080 iOut.writeString(_L(" "));
1082 iOut.writeNewLine();
1083 iOut.writeNewLine();
1086 void CSetApplications::DoCheckResult(TInt /*aError*/)
1092 iConsole.Write(_L("\tapplications set successfully\n"));
1093 iOut.writeString(_L("\tapplications set successfully"));
1094 iOut.writeNewLine();
1095 iOut.writeNewLine();
1099 iConsole.Write(_L("\tapplications set failed\n"));
1100 iOut.writeString(_L("\tapplications set failed"));
1101 iOut.writeNewLine();
1102 iOut.writeNewLine();
1107 CTestAction* CSetTrusters::NewL(RFs& aFs,
1108 CConsoleBase& aConsole,
1110 const TTestActionSpec& aTestActionSpec)
1112 CSetTrusters* self = new(ELeave) CSetTrusters(aFs, aConsole, aOut);
1113 CleanupStack::PushL(self);
1114 self->ConstructL(aTestActionSpec);
1115 CleanupStack::Pop(self);
1119 CSetTrusters::~CSetTrusters()
1124 CSetTrusters::CSetTrusters(RFs& aFs, CConsoleBase& aConsole,
1126 : CSetAppsAndTrust(aFs, aConsole, aOut)
1130 void CSetTrusters::ConstructL(const TTestActionSpec& aTestActionSpec)
1132 CSetAppsAndTrust::ConstructL(aTestActionSpec);
1134 TInt err = KErrNone;
1136 SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err));
1137 SetTrusted(Input::ParseElement(aTestActionSpec.iActionBody, KTrustersStart, KTrustersEnd, pos, err));
1138 // Set expected result
1141 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
1142 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
1143 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
1144 CleanupStack::PopAndDestroy(result);
1147 void CSetTrusters::SetTrusted(const TDesC8& aTrusted)
1149 TLex8 lex(aTrusted);
1151 TInt err = KErrNone;
1152 while (err == KErrNone)
1156 if (err == KErrNone)
1158 iTrusted = static_cast<TBool>(val);
1163 void CSetTrusters::DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus)
1165 UnifiedCertStore().SetTrust(aCertInfo, iTrusted, aStatus);
1168 void CSetTrusters::DoPerformCancel()
1170 UnifiedCertStore().CancelSetTrust();
1173 void CSetTrusters::DoReportAction()
1175 iOut.writeString(_L("Setting trust..."));
1176 iOut.writeNewLine();
1177 iOut.writeString(_L("\tLabel = "));
1178 iOut.writeString(iLabel);
1179 iOut.writeNewLine();
1180 iOut.writeNewLine();
1183 void CSetTrusters::DoCheckResult(TInt aError)
1187 if (iResult && aError == KErrNone)
1189 iConsole.Write(_L("\ttrust set successfully\n"));
1190 iOut.writeString(_L("\ttrust set successfully"));
1191 iOut.writeNewLine();
1192 iOut.writeNewLine();
1196 iConsole.Write(_L("\ttrust set failed\n"));
1197 iOut.writeString(_L("\ttrust set failed"));
1198 iOut.writeNewLine();
1199 iOut.writeNewLine();
1204 CTestAction* CGetTrusters::NewL(RFs& aFs,
1205 CConsoleBase& aConsole,
1207 const TTestActionSpec& aTestActionSpec)
1209 CGetTrusters* self = new(ELeave) CGetTrusters(aFs, aConsole, aOut);
1210 CleanupStack::PushL(self);
1211 self->ConstructL(aTestActionSpec);
1212 CleanupStack::Pop(self);
1216 CGetTrusters::~CGetTrusters()
1220 iExpectedTrusters.Close();
1224 void CGetTrusters::PerformAction(TRequestStatus& aStatus)
1229 iState = EGetTrusters;
1235 TInt end = iCertInfos.Count();
1236 TBool calledCertStore = EFalse;
1237 for (TInt i = 0; i < end; i++)
1239 if (iCertInfos[i]->Label() == iLabel)
1241 CertStore().Trusted(*iCertInfos[i], iTrust, aStatus);
1242 calledCertStore = ETrue;
1247 if (EFalse==calledCertStore)
1248 {// None with the appropriate label
1249 TRequestStatus* status = &aStatus;
1250 User::RequestComplete(status, KErrNotFound);
1257 TRequestStatus* status = &aStatus;
1258 User::RequestComplete(status, aStatus.Int());
1259 if (aStatus == iExpectedResult)
1262 if (iTrust == iExpectedTrusters[0].iUid)
1285 void CGetTrusters::PerformCancel()
1290 CertStore().CancelList();
1294 CertStore().CancelTrusted();
1302 void CGetTrusters::Reset()
1305 iState = EGetCAEntries;
1308 CGetTrusters::CGetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
1309 : CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCAEntries)
1313 void CGetTrusters::ConstructL(const TTestActionSpec& aTestActionSpec)
1315 CCertStoreTestAction::ConstructL(aTestActionSpec);
1316 iFilter = CCertAttributeFilter::NewL();
1317 TInt err = KErrNone;
1319 SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody,
1320 KCertLabelStart, KCertLabelEnd, pos, err));
1322 // Set the expected result
1324 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
1325 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
1326 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
1327 CleanupStack::PopAndDestroy(result);
1329 SetExpectedTrusters(Input::ParseElement(aTestActionSpec.iActionResult, KTrustersStart,
1330 KTrustersEnd, pos, err));
1334 void CGetTrusters::GetCerts(TRequestStatus& aStatus)
1336 CertStore().List(iCertInfos, *iFilter, aStatus);
1339 void CGetTrusters::SetCertLabel(const TDesC8& aLabel)
1341 iLabel.Copy(aLabel);
1344 void CGetTrusters::SetExpectedTrusters(const TDesC8& aExpectedTrusters)
1346 TLex8 lex(aExpectedTrusters);
1347 TInt err = KErrNone;
1348 while (err == KErrNone)
1351 err = lex.Val(uid.iUid);
1352 if (err == KErrNone)
1355 User::LeaveIfError(iExpectedTrusters.Append(uid));
1360 void CGetTrusters::DoReportAction()
1362 iOut.writeString(_L("Getting trust settings..."));
1363 iOut.writeNewLine();
1364 iOut.writeString(_L("\tLabel = "));
1365 iOut.writeString(iLabel);
1366 iOut.writeNewLine();
1367 iOut.writeNewLine();
1370 void CGetTrusters::DoCheckResult(TInt /*aError*/)
1374 iConsole.Printf(_L("\ttrust Setting : "));
1375 iOut.writeString(_L("\tTrust Setting: "));
1376 iOut.writeString(_L("\t\t"));
1377 iConsole.Printf(_L("%D \n"), iTrust);
1378 iOut.writeNum(iTrust);
1379 iOut.writeString(_L(" "));
1380 iOut.writeNewLine();
1381 iOut.writeNewLine();
1383 iConsole.Printf(_L("\texpected Trust Setting: "));
1384 iOut.writeString(_L("\tExpected Trust Setting: "));
1385 iOut.writeNewLine();
1386 iOut.writeString(_L("\t\t"));
1387 iConsole.Printf(_L("%D \n"), iExpectedTrusters[0].iUid);
1388 iOut.writeNum(iExpectedTrusters[0].iUid);
1389 iOut.writeString(_L(" "));
1390 iOut.writeNewLine();
1391 iOut.writeNewLine();
1394 iConsole.Printf(_L("\tTrust retrieved successfully\n"));
1395 iOut.writeString(_L("\tTrust retrieved successfully"));
1396 iOut.writeNewLine();
1400 iConsole.Printf(_L("\tTrust retrieved failed\n"));
1401 iOut.writeString(_L("\tTrust retrieved failed"));
1402 iOut.writeNewLine();
1404 iOut.writeNewLine();