sl@0: /* sl@0: * Copyright (c) 1998-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: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #ifndef __T_CERTSTOREACTIONS_H__ sl@0: #define __T_CERTSTOREACTIONS_H__ sl@0: sl@0: #include "t_testhandler.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_testaction.h" sl@0: #include sl@0: sl@0: class Output; sl@0: class CSWICertStore; sl@0: sl@0: enum TCertStoreType sl@0: { sl@0: EUnifiedCertStore, sl@0: ESWICertStore sl@0: }; sl@0: sl@0: class CCertStoreChangeNotifier : public CActive sl@0: { sl@0: public: sl@0: static CCertStoreChangeNotifier* NewL(TInt& aNotificationFlag); sl@0: virtual ~CCertStoreChangeNotifier(); sl@0: void StartNotification(); sl@0: TInt& iNotifiedCounter; sl@0: void SetCompleteStatus(TRequestStatus* aStatus); sl@0: private: sl@0: CCertStoreChangeNotifier(TInt& aNotificationFlag); sl@0: void ConstructL(); sl@0: void DoCancel(); sl@0: void RunL(); sl@0: private: sl@0: RProperty iCertStoreChangeProperty; sl@0: TRequestStatus* iCompleteStatus; sl@0: }; sl@0: sl@0: /** sl@0: * Contains either a unified cert store instance or a SWI cert store instance. sl@0: * sl@0: * Either can be accessed through the CertStore() method, but sl@0: * AsUnifiedCertStore() and AsSWICertStore() will panic if the store is the sl@0: * wrong type. sl@0: * sl@0: * This class owns the cert store pointer. sl@0: */ sl@0: class COpenCertStore : public CBase sl@0: { sl@0: public: sl@0: virtual ~COpenCertStore(); sl@0: sl@0: TCertStoreType Type(); sl@0: MCertStore& CertStore(); sl@0: sl@0: void SetCertStore(CUnifiedCertStore* aCertStore); sl@0: CUnifiedCertStore& AsUnifiedCertStore(); sl@0: sl@0: void SetCertStore(CSWICertStore* aCertStore); sl@0: CSWICertStore& AsSWICertStore(); sl@0: sl@0: private: sl@0: sl@0: private: sl@0: sl@0: TBool iSet; sl@0: TCertStoreType iType; sl@0: union sl@0: { sl@0: TAny* iAny; sl@0: CUnifiedCertStore* iUnifiedCertStore; sl@0: CSWICertStore* iSwiCertStore; sl@0: }; sl@0: }; sl@0: sl@0: /** sl@0: * Per-thread shared data. sl@0: * sl@0: * This contains stuff that is shared by more than one test action, eg the cert sl@0: * stores we are testing. sl@0: */ sl@0: class CSharedData : public CBase sl@0: { sl@0: public: sl@0: ~CSharedData(); sl@0: void InitCertificateAppInfoManagerL(); sl@0: void DeleteCertificateAppInfoManager(); sl@0: RPointerArray& CertStores(); sl@0: public: sl@0: RFs iFs; sl@0: RPointerArray iCertStores; sl@0: CCertificateAppInfoManager* iCertificateAppInfoManager; sl@0: }; sl@0: sl@0: class CCertStoreTestAction : public CTestAction sl@0: { sl@0: public: sl@0: virtual ~CCertStoreTestAction(); sl@0: sl@0: protected: sl@0: CCertStoreTestAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: sl@0: // Methods for accessing the shared app info manager sl@0: void InitTheCertificateAppInfoManagerL(); sl@0: void DeleteTheCertificateAppInfoManager(); sl@0: CCertificateAppInfoManager* TheCertificateAppInfoManager(); sl@0: sl@0: // Methods for accessing the shared cert stores sl@0: TInt CertStoreCount(); sl@0: TCertStoreType CertStoreType(TInt aIndex = 0); sl@0: MCertStore& CertStore(TInt aIndex = 0); sl@0: void AddCertStoreL(CUnifiedCertStore* aCertStore); sl@0: CUnifiedCertStore& UnifiedCertStore(TInt aIndex = 0); sl@0: void AddCertStoreL(CSWICertStore* aCertStore); sl@0: CSWICertStore& SWICertStore(TInt aIndex = 0); sl@0: void RemoveCertStore(TInt aIndex); sl@0: sl@0: protected: sl@0: RFs& iFs; sl@0: sl@0: private: sl@0: CSharedData& CertStoreSharedData(); sl@0: RPointerArray& CertStores(); sl@0: void DoPerformPrerequisite(TRequestStatus& aStatus); sl@0: void DoPerformPostrequisite(TRequestStatus& aStatus); sl@0: }; sl@0: sl@0: class CSubscriberAction: public CCertStoreTestAction sl@0: { sl@0: public: sl@0: virtual ~CSubscriberAction(); sl@0: sl@0: protected: sl@0: CSubscriberAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: TInt iNotifierFlag; sl@0: TInt iNotificationSubscribed; sl@0: CCertStoreChangeNotifier* iNotifier; sl@0: }; sl@0: sl@0: /** sl@0: * This action creates and initializes a certificate store manager. sl@0: * It should be used before any action requiring a certificate store manager. sl@0: * All the actions are likely to require one. sl@0: */ sl@0: class CInitialiseCertStore : public CCertStoreTestAction sl@0: { sl@0: public: sl@0: static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut, const TTestActionSpec& aTestActionSpec); sl@0: static CTestAction* NewLC(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut, const TTestActionSpec& aTestActionSpec); sl@0: ~CInitialiseCertStore(); sl@0: sl@0: public: sl@0: virtual void PerformAction(TRequestStatus& aStatus); sl@0: virtual void PerformCancel(); sl@0: virtual void Reset(); sl@0: sl@0: private: sl@0: CInitialiseCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void DoReportAction(); sl@0: void DoCheckResult(TInt aError); sl@0: sl@0: private: sl@0: enum TState sl@0: { sl@0: ENew, sl@0: EAppend, sl@0: ECheckOrder, sl@0: EFinished sl@0: }; sl@0: sl@0: private: sl@0: TState iState; sl@0: TBool iOpenedForWrite; sl@0: RArray iFilterOrdering; sl@0: RArray iExpectedOrderingResult; sl@0: CUnifiedCertStore* iNewUnifiedCertStore; sl@0: }; sl@0: sl@0: class COnlyCreateCertStore : public CCertStoreTestAction sl@0: { sl@0: public: sl@0: static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec); sl@0: ~COnlyCreateCertStore() {}; sl@0: sl@0: public: sl@0: virtual void PerformAction(TRequestStatus& aStatus); sl@0: virtual void PerformCancel(); sl@0: virtual void Reset(); sl@0: sl@0: private: sl@0: enum TState sl@0: { sl@0: EInit, sl@0: EFinished sl@0: }; sl@0: sl@0: private: sl@0: COnlyCreateCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void DoReportAction(); sl@0: void DoCheckResult(TInt aError); sl@0: sl@0: private: sl@0: TState iState; sl@0: TBool iOpenedForWrite; sl@0: sl@0: CUnifiedCertStore* iNewUnifiedCertStore; sl@0: }; sl@0: sl@0: class CDeleteCertStore : public CCertStoreTestAction sl@0: { sl@0: public: sl@0: static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec); sl@0: static CTestAction* NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec); sl@0: ~CDeleteCertStore(); sl@0: virtual void PerformAction(TRequestStatus& aStatus); sl@0: virtual void PerformCancel(); sl@0: virtual void Reset(); sl@0: sl@0: private: sl@0: CDeleteCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void DoReportAction(); sl@0: void DoCheckResult(TInt aError); sl@0: sl@0: private: sl@0: enum TState sl@0: { sl@0: EDelete, sl@0: EFinished sl@0: }; sl@0: sl@0: private: sl@0: TState iState; sl@0: }; sl@0: sl@0: sl@0: class CX509Certificate; sl@0: class CWTLSCertificate; sl@0: sl@0: // This is the base class used by both CSetApplications and CSetTrusters. This sl@0: // is required because of the merging of the SetApplicability and SetTrust API sl@0: // calls on the certstore sl@0: class CSetAppsAndTrust : public CSubscriberAction sl@0: sl@0: { sl@0: public: sl@0: ~CSetAppsAndTrust(); sl@0: virtual void PerformAction(TRequestStatus& aStatus); sl@0: virtual void Reset(); sl@0: virtual void PerformCancel(); sl@0: sl@0: protected: sl@0: CSetAppsAndTrust(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void GetCerts(TRequestStatus& aStatus); sl@0: void SetCertLabel(const TDesC8& aLabel); sl@0: sl@0: /** Implemented by derived classes, called from PerformAction. */ sl@0: virtual void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus) = 0; sl@0: /** Implemented by derived classes, called from PerformCancel. */ sl@0: virtual void DoPerformCancel() = 0; sl@0: sl@0: protected: sl@0: enum TState sl@0: { sl@0: EGetCAEntries, sl@0: ESetAppTrust, sl@0: ECheckNotification, sl@0: EFinished sl@0: }; sl@0: sl@0: protected: sl@0: /** sl@0: * The label of the certificate we want to set the trust settings for sl@0: */ sl@0: TCertLabel iLabel; sl@0: sl@0: // Index into the certinfo list which points to the certificate we sl@0: // are interested in sl@0: TInt iIndex; sl@0: sl@0: TState iState; sl@0: CCertAttributeFilter *iFilter; sl@0: RMPointerArray iCertInfos; sl@0: }; sl@0: sl@0: sl@0: sl@0: /** sl@0: * This class is used to test the trust settings of a certificate. sl@0: */ sl@0: class CSetApplications : public CSetAppsAndTrust sl@0: { sl@0: public: sl@0: /** sl@0: * @param aInfo This is what is enclosed in the and tags sl@0: * of the test script. sl@0: */ sl@0: static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec); sl@0: ~CSetApplications(); sl@0: sl@0: private: sl@0: CSetApplications(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void DoReportAction(); sl@0: void DoCheckResult(TInt aError); sl@0: void AppendUid(const TDesC8& aUid); sl@0: void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus); sl@0: void DoPerformCancel(); sl@0: sl@0: private: sl@0: /** sl@0: * The array of applications that trust this certificate. sl@0: */ sl@0: RArray iApplications; sl@0: }; sl@0: sl@0: /** sl@0: * This class is used to test the trust settings of a certificate. sl@0: */ sl@0: class CSetTrusters : public CSetAppsAndTrust sl@0: { sl@0: public: sl@0: /** sl@0: * @param aInfo This is what is enclosed in the and tags sl@0: * of the test script. sl@0: */ sl@0: static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec); sl@0: ~CSetTrusters(); sl@0: sl@0: private: sl@0: CSetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void DoReportAction(); sl@0: void DoCheckResult(TInt aError); sl@0: void SetTrusted(const TDesC8& aTrusted); sl@0: void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus); sl@0: void DoPerformCancel(); sl@0: sl@0: private: sl@0: // The trusted setting to set sl@0: TBool iTrusted; sl@0: }; sl@0: sl@0: /** sl@0: * This class is used to test the trust settings of a certificate. sl@0: */ sl@0: class CGetTrusters : public CCertStoreTestAction sl@0: { sl@0: public: sl@0: /** sl@0: * @param aInfo This is what is enclosed in the and tags sl@0: * of the test script. sl@0: */ sl@0: static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec); sl@0: ~CGetTrusters(); sl@0: virtual void PerformAction(TRequestStatus& aStatus); sl@0: virtual void PerformCancel(); sl@0: virtual void Reset(); sl@0: sl@0: private: sl@0: CGetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut); sl@0: void ConstructL(const TTestActionSpec& aTestActionSpec); sl@0: void GetCerts(TRequestStatus& aStatus); sl@0: void SetCertLabel(const TDesC8& aLabel); sl@0: void SetExpectedTrusters(const TDesC8& aExpectedTrusters); sl@0: void DoReportAction(); sl@0: void DoCheckResult(TInt aError); sl@0: sl@0: private: sl@0: enum TState sl@0: { sl@0: EGetCAEntries, sl@0: EGetTrusters, sl@0: EFinished sl@0: }; sl@0: sl@0: private: sl@0: /** sl@0: * The label of the certificate we want to get the trust settings of sl@0: */ sl@0: TCertLabel iLabel; sl@0: TState iState; sl@0: TBool iTrust; sl@0: TBool iExpectedTrust; sl@0: CCertAttributeFilter *iFilter; sl@0: RMPointerArray iCertInfos; sl@0: RArray iTrusters; sl@0: RArray iExpectedTrusters; sl@0: }; sl@0: sl@0: #endif