sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "t_certstoreactions.h" sl@0: #include "t_certstoreout.h" sl@0: #include "t_certstoredefs.h" sl@0: #include "t_input.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "testutilclient.h" sl@0: #include sl@0: sl@0: // CCertStoreChangeNotifier ////////////////////////////////////////////////////////////// sl@0: CCertStoreChangeNotifier* CCertStoreChangeNotifier::NewL(TInt& aNotificationFlag) sl@0: { sl@0: CCertStoreChangeNotifier* self = new(ELeave) CCertStoreChangeNotifier(aNotificationFlag); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: CCertStoreChangeNotifier::~CCertStoreChangeNotifier() sl@0: { sl@0: Cancel(); sl@0: iCertStoreChangeProperty.Close(); sl@0: } sl@0: CCertStoreChangeNotifier::CCertStoreChangeNotifier(TInt& aNotificationFlag): CActive(EPriorityHigh), iNotifiedCounter(aNotificationFlag) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: void CCertStoreChangeNotifier::ConstructL() sl@0: { sl@0: TInt r=iCertStoreChangeProperty.Attach(KUnifiedCertStorePropertyCat,EUnifiedCertStoreFlag,EOwnerThread); sl@0: User::LeaveIfError(r); sl@0: } sl@0: void CCertStoreChangeNotifier::StartNotification() sl@0: { sl@0: iCertStoreChangeProperty.Subscribe(iStatus); sl@0: SetActive(); sl@0: } sl@0: void CCertStoreChangeNotifier::DoCancel() sl@0: { sl@0: iCertStoreChangeProperty.Cancel(); sl@0: } sl@0: void CCertStoreChangeNotifier::RunL() sl@0: { sl@0: iNotifiedCounter++; sl@0: if (iCompleteStatus) sl@0: { sl@0: User::RequestComplete(iCompleteStatus, KErrNone); sl@0: } sl@0: } sl@0: void CCertStoreChangeNotifier::SetCompleteStatus(TRequestStatus* aStatus) sl@0: { sl@0: iCompleteStatus=aStatus; sl@0: } sl@0: sl@0: // COpenCertStore ////////////////////////////////////////////////////////////// sl@0: sl@0: _LIT(KCOpenCertStore, "COpenCertStore"); sl@0: sl@0: COpenCertStore::~COpenCertStore() sl@0: { sl@0: if (iSet) sl@0: { sl@0: switch (iType) sl@0: { sl@0: case EUnifiedCertStore: sl@0: delete iUnifiedCertStore; sl@0: break; sl@0: sl@0: case ESWICertStore: sl@0: iSwiCertStore->Release(); sl@0: break; sl@0: sl@0: default: sl@0: User::Panic(KCOpenCertStore, 1); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void COpenCertStore::SetCertStore(CUnifiedCertStore* aCertStore) sl@0: { sl@0: __ASSERT_ALWAYS(!iSet, User::Panic(KCOpenCertStore, 1)); sl@0: iType = EUnifiedCertStore; sl@0: iUnifiedCertStore = aCertStore; sl@0: iSet = ETrue; sl@0: } sl@0: sl@0: CUnifiedCertStore& COpenCertStore::AsUnifiedCertStore() sl@0: { sl@0: __ASSERT_ALWAYS(iSet && iType == EUnifiedCertStore, User::Panic(KCOpenCertStore, 1)); sl@0: return *iUnifiedCertStore; sl@0: } sl@0: sl@0: sl@0: void COpenCertStore::SetCertStore(CSWICertStore* aCertStore) sl@0: { sl@0: __ASSERT_ALWAYS(!iSet, User::Panic(KCOpenCertStore, 1)); sl@0: iType = ESWICertStore; sl@0: iSwiCertStore = aCertStore; sl@0: iSet = ETrue; sl@0: } sl@0: sl@0: CSWICertStore& COpenCertStore::AsSWICertStore() sl@0: { sl@0: __ASSERT_ALWAYS(iSet && iType == ESWICertStore, User::Panic(KCOpenCertStore, 1)); sl@0: return *iSwiCertStore; sl@0: } sl@0: sl@0: sl@0: TCertStoreType COpenCertStore::Type() sl@0: { sl@0: __ASSERT_ALWAYS(iSet, User::Panic(KCOpenCertStore, 1)); sl@0: return iType; sl@0: } sl@0: sl@0: sl@0: MCertStore& COpenCertStore::CertStore() sl@0: { sl@0: __ASSERT_ALWAYS(iSet, User::Panic(KCOpenCertStore, 1)); sl@0: sl@0: MCertStore* result = NULL; sl@0: sl@0: switch (iType) sl@0: { sl@0: case EUnifiedCertStore: sl@0: result = iUnifiedCertStore; sl@0: break; sl@0: sl@0: case ESWICertStore: sl@0: result = iSwiCertStore; sl@0: break; sl@0: sl@0: default: sl@0: User::Panic(KCOpenCertStore, 1); sl@0: } sl@0: sl@0: return *result; sl@0: } sl@0: sl@0: // CSharedData ///////////////////////////////////////////////////////////////// sl@0: sl@0: CSharedData::~CSharedData() sl@0: { sl@0: iCertStores.ResetAndDestroy(); sl@0: iCertStores.Close(); sl@0: DeleteCertificateAppInfoManager(); sl@0: REComSession::FinalClose(); sl@0: } sl@0: sl@0: void CSharedData::InitCertificateAppInfoManagerL() sl@0: { sl@0: ASSERT(!iCertificateAppInfoManager); sl@0: User::LeaveIfError(iFs.Connect()); sl@0: iCertificateAppInfoManager = CCertificateAppInfoManager::NewL(iFs, ETrue); sl@0: } sl@0: sl@0: void CSharedData::DeleteCertificateAppInfoManager() sl@0: { sl@0: if (iCertificateAppInfoManager) sl@0: { sl@0: delete iCertificateAppInfoManager; sl@0: iCertificateAppInfoManager = NULL; sl@0: iFs.Close(); sl@0: } sl@0: } sl@0: sl@0: RPointerArray& CSharedData::CertStores() sl@0: { sl@0: return iCertStores; sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: //CCertStoreTestAction base class sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CCertStoreTestAction::~CCertStoreTestAction() sl@0: { sl@0: } sl@0: sl@0: CCertStoreTestAction::CCertStoreTestAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut) : sl@0: CTestAction(aConsole, aOut), iFs(aFs) sl@0: { sl@0: } sl@0: sl@0: CSharedData& CCertStoreTestAction::CertStoreSharedData() sl@0: { sl@0: if (!SharedData()) sl@0: { sl@0: SetSharedData(new CSharedData); sl@0: } sl@0: sl@0: CSharedData* data = static_cast(SharedData()); sl@0: ASSERT(data); // panic if out of memory sl@0: return *data; sl@0: } sl@0: sl@0: void CCertStoreTestAction::DoPerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: // Ensure shared data is already created to prevent panic in oom test sl@0: CertStoreSharedData(); sl@0: sl@0: iActionState = EAction; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: void CCertStoreTestAction::DoPerformPostrequisite(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: CCertificateAppInfoManager* CCertStoreTestAction::TheCertificateAppInfoManager() sl@0: { sl@0: return CertStoreSharedData().iCertificateAppInfoManager; sl@0: } sl@0: sl@0: void CCertStoreTestAction::InitTheCertificateAppInfoManagerL() sl@0: { sl@0: CertStoreSharedData().InitCertificateAppInfoManagerL(); sl@0: } sl@0: sl@0: void CCertStoreTestAction::DeleteTheCertificateAppInfoManager() sl@0: { sl@0: CertStoreSharedData().DeleteCertificateAppInfoManager(); sl@0: } sl@0: sl@0: RPointerArray& CCertStoreTestAction::CertStores() sl@0: { sl@0: return CertStoreSharedData().CertStores(); sl@0: } sl@0: sl@0: TInt CCertStoreTestAction::CertStoreCount() sl@0: { sl@0: return CertStores().Count(); sl@0: } sl@0: sl@0: TCertStoreType CCertStoreTestAction::CertStoreType(TInt aIndex) sl@0: { sl@0: return CertStores()[aIndex]->Type(); sl@0: } sl@0: sl@0: MCertStore& CCertStoreTestAction::CertStore(TInt aIndex) sl@0: { sl@0: return CertStores()[aIndex]->CertStore(); sl@0: } sl@0: sl@0: void CCertStoreTestAction::AddCertStoreL(CUnifiedCertStore* aCertStore) sl@0: { sl@0: COpenCertStore* openStore = new (ELeave) COpenCertStore; sl@0: CleanupStack::PushL(openStore); sl@0: User::LeaveIfError(CertStores().Append(openStore)); sl@0: CleanupStack::Pop(openStore); sl@0: openStore->SetCertStore(aCertStore); // takes ownership sl@0: } sl@0: sl@0: CUnifiedCertStore& CCertStoreTestAction::UnifiedCertStore(TInt aIndex) sl@0: { sl@0: return CertStores()[aIndex]->AsUnifiedCertStore(); sl@0: } sl@0: sl@0: sl@0: void CCertStoreTestAction::AddCertStoreL(CSWICertStore* aCertStore) sl@0: { sl@0: COpenCertStore* openStore = new (ELeave) COpenCertStore; sl@0: CleanupStack::PushL(openStore); sl@0: User::LeaveIfError(CertStores().Append(openStore)); sl@0: CleanupStack::Pop(openStore); sl@0: openStore->SetCertStore(aCertStore); // takes ownership sl@0: } sl@0: sl@0: CSWICertStore& CCertStoreTestAction::SWICertStore(TInt aIndex) sl@0: { sl@0: return CertStores()[aIndex]->AsSWICertStore(); sl@0: } sl@0: sl@0: sl@0: void CCertStoreTestAction::RemoveCertStore(TInt aIndex) sl@0: { sl@0: COpenCertStore* openStore = CertStores()[aIndex]; sl@0: TBool delCertstore = EFalse; sl@0: sl@0: if (openStore->Type() == ESWICertStore) sl@0: { sl@0: delCertstore = ETrue; sl@0: } sl@0: sl@0: CertStores().Remove(aIndex); sl@0: delete openStore; sl@0: sl@0: if (delCertstore) sl@0: { sl@0: RTestUtilSession testutil; sl@0: User::LeaveIfError(testutil.Connect()); sl@0: CleanupClosePushL(testutil); sl@0: sl@0: TDriveUnit sysDrive (RFs::GetSystemDrive()); sl@0: TDriveName driveName(sysDrive.Name()); sl@0: TBuf<64> certstoreFile (driveName); sl@0: certstoreFile.Append(_L("\\Resource\\SwiCertstore\\")); sl@0: testutil.RmDir(certstoreFile); sl@0: sl@0: CleanupStack::PopAndDestroy(&testutil); sl@0: } sl@0: } sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: //CSubscriberAction base class sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: CSubscriberAction::~CSubscriberAction() sl@0: { sl@0: if (iNotifier) sl@0: delete iNotifier; sl@0: } sl@0: CSubscriberAction::CSubscriberAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut) sl@0: :CCertStoreTestAction(aFs, aConsole, aOut) sl@0: { sl@0: } sl@0: void CSubscriberAction::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: TInt pos = 0; sl@0: TInt err = KErrNone; sl@0: TPtrC8 ptr1 = Input::ParseElement(aTestActionSpec.iActionBody, KChangeNotifiedStart, KChangeNotifiedEnd, pos, err); sl@0: if (ptr1 != KNullDesC8) sl@0: { sl@0: TLex8 lexi(ptr1); sl@0: TInt val; sl@0: TInt ret=lexi.Val(val); sl@0: if (val != 0) sl@0: { sl@0: iNotificationSubscribed=1; sl@0: } sl@0: } sl@0: } sl@0: ///////////////////////////////////////////////////////////////// sl@0: //CInitialiseCertStore:: sl@0: /////////////////////////////////////////////////////////////////// sl@0: CTestAction* CInitialiseCertStore::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CInitialiseCertStore::NewLC(aFs, sl@0: aConsole, aOut, aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CInitialiseCertStore::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CInitialiseCertStore* self = new(ELeave) CInitialiseCertStore(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CInitialiseCertStore::~CInitialiseCertStore() sl@0: { sl@0: delete iNewUnifiedCertStore; sl@0: iFilterOrdering.Close(); sl@0: iExpectedOrderingResult.Close(); sl@0: } sl@0: sl@0: CInitialiseCertStore::CInitialiseCertStore(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: sl@0: :CCertStoreTestAction(aFs, aConsole, aOut), iState(ENew) sl@0: { sl@0: } sl@0: sl@0: void CInitialiseCertStore::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: TPtrC8 ptr = sl@0: Input::ParseElement(aTestActionSpec.iActionBody, KModeStart, KModeEnd, pos, err); sl@0: if (ptr == KNullDesC8) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: if (ptr == _L8("read")) sl@0: { sl@0: iOpenedForWrite = EFalse; sl@0: } sl@0: else if (ptr == _L8("write")) sl@0: { sl@0: iOpenedForWrite = ETrue; sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: pos = 0; sl@0: err = KErrNone; sl@0: TPtrC8 ptr1 = Input::ParseElement(aTestActionSpec.iActionBody, KOrderingFilterStart, KOrderingFilterEnd, pos, err); sl@0: if (ptr1 != KNullDesC8) sl@0: { sl@0: TInt lastPos=0; sl@0: TInt startPos=0; sl@0: TLex8 lexi; sl@0: do sl@0: { sl@0: startPos=lastPos; sl@0: while (lastPosDes()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: } sl@0: sl@0: void CInitialiseCertStore::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: if (aStatus != KErrNone) sl@0: { sl@0: iState = EFinished; sl@0: } sl@0: sl@0: switch (iState) sl@0: { sl@0: case ENew: sl@0: __ASSERT_DEBUG(!iNewUnifiedCertStore, User::Panic(_L("CInitialiseCertStore"), 1)); sl@0: iNewUnifiedCertStore = CUnifiedCertStore::NewL(iFs, iOpenedForWrite, iFilterOrdering); sl@0: sl@0: iNewUnifiedCertStore->Initialize(aStatus); sl@0: iState = EAppend; sl@0: break; sl@0: sl@0: case EAppend: sl@0: { sl@0: AddCertStoreL(iNewUnifiedCertStore); sl@0: iNewUnifiedCertStore = 0; // we don't own this any more sl@0: if (iFilterOrdering.Count()==0) sl@0: { sl@0: iState = EFinished; sl@0: } sl@0: else sl@0: { sl@0: iState = ECheckOrder; sl@0: } sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: break; sl@0: sl@0: case ECheckOrder: sl@0: { sl@0: TInt ret=KErrNone; sl@0: TInt count = UnifiedCertStore().CertStoreCount(); sl@0: MCTCertStore* p=NULL; sl@0: TInt j=-1; sl@0: TInt32 previous=0; sl@0: TInt32 current=0; sl@0: for (TInt i=0;iToken().TokenType().Type().iUid; sl@0: if (previous != current) sl@0: { sl@0: j++; sl@0: previous = current; sl@0: } sl@0: TInt32 l1=iExpectedOrderingResult[j]; sl@0: if (current != iExpectedOrderingResult[j]) sl@0: { sl@0: ret=KErrNotFound; sl@0: break; sl@0: } sl@0: } sl@0: if (countCancelInitialize(); sl@0: break; sl@0: sl@0: default: sl@0: // do nothing sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CInitialiseCertStore::Reset() sl@0: { sl@0: iState = ENew; sl@0: delete iNewUnifiedCertStore; sl@0: iNewUnifiedCertStore = 0; sl@0: } sl@0: sl@0: void CInitialiseCertStore::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Initializing certstore manager...")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void CInitialiseCertStore::DoCheckResult(TInt aError) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (aError == KErrNone) sl@0: { sl@0: iConsole.Write(_L("\tstore manager initialised successfully\n")); sl@0: iOut.writeString(_L("\tstore manager initialised successfully")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else if (aError == KErrInUse) sl@0: { sl@0: iConsole.Write(_L("\tstore manager initialised error : KErrInUse\n")); sl@0: iOut.writeString(_L("\tstore manager initialization error : KErrInUse")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////// sl@0: //COnlyCreateCertStore:: sl@0: /////////////////////////////////////////////////////////////////// sl@0: sl@0: CTestAction* COnlyCreateCertStore::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: COnlyCreateCertStore* self = new(ELeave) COnlyCreateCertStore(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: COnlyCreateCertStore::COnlyCreateCertStore(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: :CCertStoreTestAction(aFs, aConsole, aOut), iState(EInit) sl@0: { sl@0: } sl@0: sl@0: void COnlyCreateCertStore::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: sl@0: HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length()); sl@0: TPtr(result->Des()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: } sl@0: sl@0: void COnlyCreateCertStore::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EInit: sl@0: { sl@0: __ASSERT_DEBUG(!iNewUnifiedCertStore, User::Panic(_L("CInitialiseCertStore"), 1)); sl@0: TRAPD(err, iNewUnifiedCertStore = CUnifiedCertStore::NewL(iFs, ETrue)); sl@0: if (err != KErrNone) sl@0: { sl@0: iState = EFinished; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, err); sl@0: } sl@0: else sl@0: { sl@0: AddCertStoreL(iNewUnifiedCertStore); sl@0: iNewUnifiedCertStore = 0; // we don't own this any more sl@0: iState = EFinished; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, err); sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case EFinished: sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: if (aStatus == iExpectedResult) sl@0: { sl@0: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: if (aStatus == KErrNoMemory) sl@0: { sl@0: iState = EInit; sl@0: } sl@0: else sl@0: { sl@0: iFinished = ETrue; sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void COnlyCreateCertStore::PerformCancel() sl@0: { sl@0: } sl@0: sl@0: void COnlyCreateCertStore::Reset() sl@0: { sl@0: __ASSERT_DEBUG(EFalse, User::Panic(_L("COnlyCreateCertStore::Reset()"), 1)); sl@0: } sl@0: sl@0: void COnlyCreateCertStore::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Only creating certstore manager...")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void COnlyCreateCertStore::DoCheckResult(TInt aError) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (aError == KErrNone) sl@0: { sl@0: iConsole.Write(_L("\tstore manager created successfully\n")); sl@0: iOut.writeString(_L("\tstore manager created successfully")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else if (aError == KErrInUse) sl@0: { sl@0: iConsole.Write(_L("\tstore manager creation error : KErrInUse\n")); sl@0: iOut.writeString(_L("\tstore manager creation error : KErrInUse")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: // CDeleteCertStore sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CTestAction* CDeleteCertStore::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CDeleteCertStore::NewLC(aFs, aConsole, aOut, aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CDeleteCertStore::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CDeleteCertStore* self = new(ELeave) CDeleteCertStore(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CDeleteCertStore::~CDeleteCertStore() sl@0: { sl@0: } sl@0: sl@0: CDeleteCertStore::CDeleteCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut) sl@0: : CCertStoreTestAction(aFs, aConsole, aOut), iState(EDelete) sl@0: { sl@0: } sl@0: sl@0: void CDeleteCertStore::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: sl@0: HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length()); sl@0: TPtr(result->Des()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: } sl@0: sl@0: void CDeleteCertStore::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EDelete: sl@0: { sl@0: TInt err = KErrNotFound; sl@0: TInt count = CertStoreCount(); sl@0: if (count) sl@0: { sl@0: RemoveCertStore(count - 1); sl@0: err = KErrNone; sl@0: } sl@0: iState = EFinished; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, err); sl@0: } sl@0: break; sl@0: sl@0: case EFinished: sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: if (aStatus == iExpectedResult) sl@0: { sl@0: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: if (aStatus == KErrNoMemory) sl@0: { sl@0: iState = EDelete; sl@0: } sl@0: else sl@0: { sl@0: iFinished = ETrue; sl@0: } sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CDeleteCertStore::PerformCancel() sl@0: { sl@0: iState = EDelete; sl@0: } sl@0: sl@0: void CDeleteCertStore::Reset() sl@0: { sl@0: } sl@0: sl@0: void CDeleteCertStore::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Deleting certstore manager...")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void CDeleteCertStore::DoCheckResult(TInt aError) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (aError == KErrNone) sl@0: { sl@0: iConsole.Write(_L("\tstore manager deleted successfully\n")); sl@0: iOut.writeString(_L("\tstore manager deleted successfully")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: iConsole.Write(_L("\tstore manager deleted failed\n")); sl@0: iOut.writeString(_L("\tstore manager deleted failed")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: CSetAppsAndTrust::~CSetAppsAndTrust() sl@0: { sl@0: delete iFilter; sl@0: iCertInfos.Close(); sl@0: } sl@0: sl@0: void CSetAppsAndTrust::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EGetCAEntries: sl@0: iState = ESetAppTrust; sl@0: GetCerts(aStatus); sl@0: break; sl@0: sl@0: case ESetAppTrust: sl@0: { sl@0: // Find the certificate we want to set the trust settings for sl@0: // and edit its trust settings sl@0: iState = EFinished; sl@0: TInt iEnd = iCertInfos.Count(); sl@0: for (TInt i = 0; i < iEnd; i++) sl@0: { sl@0: if (iCertInfos[i]->Label() == iLabel) sl@0: { sl@0: if (iNotificationSubscribed) sl@0: { sl@0: if (!iNotifier) sl@0: { sl@0: iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag); sl@0: iNotifier->StartNotification(); sl@0: } sl@0: iState = ECheckNotification; sl@0: } sl@0: else sl@0: { sl@0: iState = EFinished; sl@0: } sl@0: DoSetAppTrust(*iCertInfos[i], aStatus); sl@0: return; sl@0: } sl@0: } sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNotFound); sl@0: } sl@0: break; sl@0: sl@0: case ECheckNotification: sl@0: { sl@0: iState = EFinished; sl@0: if (iNotifierFlag) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: iNotifier->SetCompleteStatus(&aStatus); sl@0: } sl@0: } sl@0: break; sl@0: case EFinished: sl@0: { sl@0: if (!iNotifierFlag && iNotificationSubscribed) sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: else sl@0: { sl@0: if (aStatus == iExpectedResult) sl@0: { sl@0: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: } sl@0: sl@0: iFinished = ETrue; sl@0: sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Invariant(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CSetAppsAndTrust::PerformCancel() sl@0: { sl@0: switch (iState) sl@0: { sl@0: case ESetAppTrust: sl@0: CertStore().CancelList(); sl@0: break; sl@0: case ECheckNotification: sl@0: case EFinished: sl@0: DoPerformCancel(); sl@0: break; sl@0: sl@0: default: sl@0: // do nothing sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CSetAppsAndTrust::Reset() sl@0: { sl@0: iState = EGetCAEntries; sl@0: iCertInfos.Close(); sl@0: } sl@0: sl@0: CSetAppsAndTrust::CSetAppsAndTrust(RFs& aFs, CConsoleBase& aConsole, Output& aOut) sl@0: : CSubscriberAction(aFs, aConsole, aOut), iState(EGetCAEntries) sl@0: sl@0: { sl@0: } sl@0: sl@0: void CSetAppsAndTrust::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CSubscriberAction::ConstructL(aTestActionSpec); sl@0: iFilter = CCertAttributeFilter::NewL(); sl@0: sl@0: // Let derived class do its own parsing sl@0: } sl@0: sl@0: void CSetAppsAndTrust::GetCerts(TRequestStatus& aStatus) sl@0: { sl@0: CertStore().List(iCertInfos, *iFilter, aStatus); sl@0: } sl@0: sl@0: void CSetAppsAndTrust::SetCertLabel(const TDesC8& aLabel) sl@0: { sl@0: iLabel.Copy(aLabel); sl@0: } sl@0: sl@0: CTestAction* CSetApplications::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CSetApplications* self = new(ELeave) CSetApplications(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CSetApplications::~CSetApplications() sl@0: { sl@0: iApplications.Close(); sl@0: } sl@0: sl@0: CSetApplications::CSetApplications(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CSetAppsAndTrust(aFs, aConsole, aOut) sl@0: { sl@0: } sl@0: sl@0: void CSetApplications::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CSetAppsAndTrust::ConstructL(aTestActionSpec); sl@0: sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody, sl@0: KCertLabelStart, KCertLabelEnd, pos, err)); sl@0: AppendUid(Input::ParseElement(aTestActionSpec.iActionBody, KUIDStart, KUIDEnd, pos, err)); sl@0: // Set expected result sl@0: pos = 0; sl@0: sl@0: HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length()); sl@0: TPtr(result->Des()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: } sl@0: sl@0: void CSetApplications::AppendUid(const TDesC8& aUid) sl@0: { sl@0: TLex8 lex(aUid); sl@0: sl@0: TInt err = KErrNone; sl@0: while (err == KErrNone) sl@0: { sl@0: TUid u ; sl@0: err = lex.Val(u.iUid); sl@0: if (err == KErrNone) sl@0: { sl@0: lex.SkipSpace(); sl@0: User::LeaveIfError(iApplications.Append(u)); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CSetApplications::DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus) sl@0: { sl@0: UnifiedCertStore().SetApplicability(aCertInfo, iApplications, aStatus); sl@0: } sl@0: sl@0: void CSetApplications::DoPerformCancel() sl@0: { sl@0: UnifiedCertStore().CancelSetApplicability(); sl@0: } sl@0: sl@0: void CSetApplications::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Setting Application settings...")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\tLabel = ")); sl@0: iOut.writeString(iLabel); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\tApplications = ")); sl@0: TInt count = iApplications.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: iOut.writeNum(iApplications[i].iUid); sl@0: iOut.writeString(_L(" ")); sl@0: } sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void CSetApplications::DoCheckResult(TInt /*aError*/) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (iResult) sl@0: { sl@0: iConsole.Write(_L("\tapplications set successfully\n")); sl@0: iOut.writeString(_L("\tapplications set successfully")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: iConsole.Write(_L("\tapplications set failed\n")); sl@0: iOut.writeString(_L("\tapplications set failed")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: CTestAction* CSetTrusters::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CSetTrusters* self = new(ELeave) CSetTrusters(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CSetTrusters::~CSetTrusters() sl@0: { sl@0: } sl@0: sl@0: sl@0: CSetTrusters::CSetTrusters(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CSetAppsAndTrust(aFs, aConsole, aOut) sl@0: { sl@0: } sl@0: sl@0: void CSetTrusters::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CSetAppsAndTrust::ConstructL(aTestActionSpec); sl@0: sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err)); sl@0: SetTrusted(Input::ParseElement(aTestActionSpec.iActionBody, KTrustersStart, KTrustersEnd, pos, err)); sl@0: // Set expected result sl@0: pos = 0; sl@0: sl@0: HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length()); sl@0: TPtr(result->Des()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: } sl@0: sl@0: void CSetTrusters::SetTrusted(const TDesC8& aTrusted) sl@0: { sl@0: TLex8 lex(aTrusted); sl@0: sl@0: TInt err = KErrNone; sl@0: while (err == KErrNone) sl@0: { sl@0: TInt val; sl@0: err = lex.Val(val); sl@0: if (err == KErrNone) sl@0: { sl@0: iTrusted = static_cast(val); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CSetTrusters::DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus) sl@0: { sl@0: UnifiedCertStore().SetTrust(aCertInfo, iTrusted, aStatus); sl@0: } sl@0: sl@0: void CSetTrusters::DoPerformCancel() sl@0: { sl@0: UnifiedCertStore().CancelSetTrust(); sl@0: } sl@0: sl@0: void CSetTrusters::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Setting trust...")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\tLabel = ")); sl@0: iOut.writeString(iLabel); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void CSetTrusters::DoCheckResult(TInt aError) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (iResult && aError == KErrNone) sl@0: { sl@0: iConsole.Write(_L("\ttrust set successfully\n")); sl@0: iOut.writeString(_L("\ttrust set successfully")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: iConsole.Write(_L("\ttrust set failed\n")); sl@0: iOut.writeString(_L("\ttrust set failed")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: CTestAction* CGetTrusters::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CGetTrusters* self = new(ELeave) CGetTrusters(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CGetTrusters::~CGetTrusters() sl@0: { sl@0: iCertInfos.Close(); sl@0: iTrusters.Close(); sl@0: iExpectedTrusters.Close(); sl@0: delete iFilter; sl@0: } sl@0: sl@0: void CGetTrusters::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EGetCAEntries: sl@0: iState = EGetTrusters; sl@0: GetCerts(aStatus); sl@0: break; sl@0: sl@0: case EGetTrusters: sl@0: { sl@0: TInt end = iCertInfos.Count(); sl@0: TBool calledCertStore = EFalse; sl@0: for (TInt i = 0; i < end; i++) sl@0: { sl@0: if (iCertInfos[i]->Label() == iLabel) sl@0: { sl@0: CertStore().Trusted(*iCertInfos[i], iTrust, aStatus); sl@0: calledCertStore = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: iState = EFinished; sl@0: if (EFalse==calledCertStore) sl@0: {// None with the appropriate label sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNotFound); sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case EFinished: sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: if (aStatus == iExpectedResult) sl@0: { sl@0: sl@0: if (iTrust == iExpectedTrusters[0].iUid) sl@0: { sl@0: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: sl@0: iFinished = ETrue; sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CGetTrusters::PerformCancel() sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EGetTrusters: sl@0: CertStore().CancelList(); sl@0: break; sl@0: sl@0: case EFinished: sl@0: CertStore().CancelTrusted(); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CGetTrusters::Reset() sl@0: { sl@0: iCertInfos.Close(); sl@0: iState = EGetCAEntries; sl@0: } sl@0: sl@0: CGetTrusters::CGetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut) sl@0: : CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCAEntries) sl@0: { sl@0: } sl@0: sl@0: void CGetTrusters::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: iFilter = CCertAttributeFilter::NewL(); sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: SetCertLabel(Input::ParseElement(aTestActionSpec.iActionBody, sl@0: KCertLabelStart, KCertLabelEnd, pos, err)); sl@0: sl@0: // Set the expected result sl@0: pos = 0; sl@0: HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length()); sl@0: TPtr(result->Des()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: sl@0: SetExpectedTrusters(Input::ParseElement(aTestActionSpec.iActionResult, KTrustersStart, sl@0: KTrustersEnd, pos, err)); sl@0: sl@0: } sl@0: sl@0: void CGetTrusters::GetCerts(TRequestStatus& aStatus) sl@0: { sl@0: CertStore().List(iCertInfos, *iFilter, aStatus); sl@0: } sl@0: sl@0: void CGetTrusters::SetCertLabel(const TDesC8& aLabel) sl@0: { sl@0: iLabel.Copy(aLabel); sl@0: } sl@0: sl@0: void CGetTrusters::SetExpectedTrusters(const TDesC8& aExpectedTrusters) sl@0: { sl@0: TLex8 lex(aExpectedTrusters); sl@0: TInt err = KErrNone; sl@0: while (err == KErrNone) sl@0: { sl@0: TUid uid; sl@0: err = lex.Val(uid.iUid); sl@0: if (err == KErrNone) sl@0: { sl@0: lex.SkipSpace(); sl@0: User::LeaveIfError(iExpectedTrusters.Append(uid)); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CGetTrusters::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Getting trust settings...")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\tLabel = ")); sl@0: iOut.writeString(iLabel); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void CGetTrusters::DoCheckResult(TInt /*aError*/) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: iConsole.Printf(_L("\ttrust Setting : ")); sl@0: iOut.writeString(_L("\tTrust Setting: ")); sl@0: iOut.writeString(_L("\t\t")); sl@0: iConsole.Printf(_L("%D \n"), iTrust); sl@0: iOut.writeNum(iTrust); sl@0: iOut.writeString(_L(" ")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: sl@0: iConsole.Printf(_L("\texpected Trust Setting: ")); sl@0: iOut.writeString(_L("\tExpected Trust Setting: ")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\t\t")); sl@0: iConsole.Printf(_L("%D \n"), iExpectedTrusters[0].iUid); sl@0: iOut.writeNum(iExpectedTrusters[0].iUid); sl@0: iOut.writeString(_L(" ")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: if (iResult) sl@0: { sl@0: iConsole.Printf(_L("\tTrust retrieved successfully\n")); sl@0: iOut.writeString(_L("\tTrust retrieved successfully")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: iConsole.Printf(_L("\tTrust retrieved failed\n")); sl@0: iOut.writeString(_L("\tTrust retrieved failed")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: iOut.writeNewLine(); sl@0: sl@0: } sl@0: }