sl@0: /* sl@0: * Copyright (c) 2005-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: * tcertuils.h sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: sl@0: #ifndef __TCERTUTILS_H__ sl@0: #define __TCERTUTILS_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_output.h" sl@0: sl@0: /** sl@0: CCertUtils provides various functions often used in tests. sl@0: This class has changed because the functions are asynchronous now. sl@0: The function are no longer static as we need an instance to serve as sl@0: an active object. sl@0: */ sl@0: class CCertUtils : public CActive sl@0: { sl@0: public: sl@0: /** sl@0: * This enumeration enumerates all the states used for the sl@0: * RunL function. sl@0: */ sl@0: enum TState sl@0: { sl@0: EAddCACerts, sl@0: sl@0: EAddCert, sl@0: EAddCACertGetCAEntry, sl@0: EAddCACertSetApplications, sl@0: EAddCACertSetTrust, sl@0: EAddCACertFinished, sl@0: sl@0: ERemoveCertsGetCACerts, sl@0: ERemoveCertsCACertsRetrieved, sl@0: ERemoveCertsRemoveCACerts, sl@0: ERemoveCertsGetUserCerts, sl@0: ERemoveCertsUserCertsRetrieved, sl@0: ERemoveCertsRemoveUserCerts, sl@0: ERemoveCertsFinished sl@0: }; sl@0: sl@0: public: sl@0: IMPORT_C static CCertUtils* NewL(RFs& aFs); sl@0: IMPORT_C static CCertUtils* NewLC(RFs& aFs); sl@0: /** sl@0: The destructor destroys all the members of CCertUtils but only destroys sl@0: iStoreManager if the CCertStoreManager instance was created by this CCertUtils sl@0: instance. It doesn't destroy it if it was passed as an argument in the sl@0: constructor. sl@0: */ sl@0: IMPORT_C virtual ~CCertUtils(); sl@0: sl@0: sl@0: /** sl@0: Certificate handling functions sl@0: */ sl@0: IMPORT_C void AddCertL(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aTrustedUsage, sl@0: const TDesC& aCertificatePath, sl@0: const TDesC& aCertificateFileName, sl@0: TRequestStatus& aStatus); sl@0: sl@0: IMPORT_C void AddCert(const TDesC& aLabel, sl@0: TCertificateFormat aFormat, sl@0: TCertificateOwnerType aCertificateOwnerType, sl@0: TInt aTrustedUsage, sl@0: const TDesC& aCertificatePath, sl@0: const TDesC& aCertificateFileName, sl@0: CUnifiedCertStore& aUnifiedCertStore, sl@0: TRequestStatus& aStatus); sl@0: sl@0: IMPORT_C void AddCACertsL(const CDesCArray& aRoots, sl@0: const CDesCArray& aLabels, sl@0: TCertificateFormat aFormat, sl@0: TInt aTrustedUsage, sl@0: const TDesC& aPath, sl@0: TRequestStatus& aStatus); sl@0: sl@0: IMPORT_C void AddCACertsL(const CDesCArray& aRoots, sl@0: const CDesCArray& aLabels, sl@0: TCertificateFormat aFormat, sl@0: TInt aTrustedUsage, sl@0: const TDesC& aPath, sl@0: CUnifiedCertStore& aUnifiedCertStore, sl@0: TRequestStatus& aStatus); sl@0: sl@0: IMPORT_C void RemoveCertsL(TRequestStatus& aStatus); sl@0: IMPORT_C void RemoveCertsL(CUnifiedCertStore& aUnifiedCertStore, sl@0: TRequestStatus& aStatus); sl@0: sl@0: IMPORT_C static CCertificate* CertFromFileLC(const TDesC& aFilename, sl@0: const TDesC& aPathname, sl@0: RFs& aFs, sl@0: TCertificateFormat aFormat); sl@0: sl@0: IMPORT_C static CCertificate* CertFromFileL(const TDesC& aFilename, sl@0: const TDesC& aPathname, sl@0: RFs& aFs, sl@0: TCertificateFormat aFormat); sl@0: sl@0: IMPORT_C static void WriteError(TValidationError aError, Output& aOut); sl@0: IMPORT_C static TPtrC MapError(TValidationError aError); sl@0: IMPORT_C static TValidationError MapError(const TDesC& aError); sl@0: IMPORT_C static TPtrC ParseElement(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, TInt& aPos, TInt& aError); sl@0: sl@0: IMPORT_C HBufC* DiagnosticLC() const; sl@0: IMPORT_C void AddApplicationL(const TDesC& aName, TUid aUid) const; sl@0: IMPORT_C void RemoveApplicationL(TUid aUid) const; sl@0: sl@0: private: sl@0: /** sl@0: This constructor constructs a CCertUtils instance without initializing sl@0: iStoreManager. A store manager will be created if one is needed and sl@0: will be destroyed by the destructor. sl@0: @param aFs A file server session. The file server session must have opened. sl@0: */ sl@0: CCertUtils(RFs& aFs); sl@0: void ConstructL(); sl@0: sl@0: //Virtual from CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: sl@0: private: sl@0: // The following functions handle the different RunL states sl@0: void HandleEAddCACertsL(); sl@0: sl@0: void HandleEAddCACertL(); sl@0: void HandleEAddCACertGetCAEntry(); sl@0: void HandleEAddCACertSetApplicationsL(); sl@0: void HandleEAddCACertSetTrust(); sl@0: void HandleEAddCACertFinishedL(); sl@0: sl@0: void HandleERemoveCertsGetCACerts(); sl@0: void HandleERemoveCertsCACertsRetrieved(); sl@0: void HandleERemoveCertsRemoveCACerts(); sl@0: void HandleERemoveCertsGetUserCerts(); sl@0: void HandleERemoveCertsUserCertsRetrieved(); sl@0: void HandleERemoveCertsRemoveUserCerts(); sl@0: void HandleERemoveCertsFinished(); sl@0: sl@0: sl@0: private: sl@0: /** sl@0: File Server Sessioin sl@0: */ sl@0: RFs& iFs; sl@0: sl@0: /** sl@0: The state used to know what RunL should do sl@0: */ sl@0: TState iState; sl@0: sl@0: /** sl@0: The store managers will be used for certificate store operations, sl@0: */ sl@0: CUnifiedCertStore* iUnifiedCertStore; sl@0: CUnifiedCertStore* iCreatedUnifiedCertStore; sl@0: sl@0: /** sl@0: These members are used to store the arguments of the functions sl@0: because most of the things are handled in a RunL. sl@0: */ sl@0: const CDesCArray* iRoots; // Used by AddCertsL sl@0: const CDesCArray* iLabels; // Used by AddCertsL sl@0: TCertificateFormat iFormat; sl@0: TInt iTrustedUsage; // Used by AddCertsL, AddCert sl@0: RArray iTrusters; // Used by AddCertsL, AddCert sl@0: const TDesC* iPath; // Used by AddCertsL, AddCert sl@0: TRequestStatus* iOriginalRequestStatus; // Used by AddCertsL, AddCert sl@0: TInt iIndex; // Used by AddCertsL to know sl@0: // which certificate to add next sl@0: // Used by RemoveCerts sl@0: CCertUtils* iSecondCertUtils; // Used by AddCertsL to add each individual sl@0: // certificate sl@0: const TDesC* iLabel; // Used by AddCert sl@0: TCertificateOwnerType iCertificateOwnerType; sl@0: const TDesC* iCertificateFileName; // Used by AddCert sl@0: CCertificate* iCertificate; // Used by AddCACert sl@0: MCTWritableCertStore *iStore; // Used by AddCACert sl@0: TPtrC8 iEncoding; // Used by AddCACert sl@0: sl@0: HBufC* iCertData; sl@0: HBufC* iLabelData; sl@0: sl@0: /** sl@0: This is a filter used by the GetCACerts function. We use the filter constructed sl@0: by the constructor with no argument, the filter doesn't filter anything. sl@0: */ sl@0: CCertAttributeFilter* iCAFilter; // Used by RemoveCerts sl@0: RMPointerArray iCACertStoreEntries; // Used by RemoveCerts sl@0: sl@0: /** sl@0: This is a filter used by the GetUserCerts function. We use the filter constructed sl@0: by the constructot with no argument, the filter doesn't filter anything. sl@0: */ sl@0: CCertAttributeFilter* iUserFilter; // Used by RemoveCerts sl@0: RMPointerArray iUserCertStoreEntries; // Used by RemoveCerts sl@0: sl@0: public: sl@0: /** sl@0: A diagnostic variable for when an error occurs. It stores the state at which sl@0: the error occurred. sl@0: */ sl@0: TState iDiagnosticState; sl@0: sl@0: /** sl@0: A diagnostic variable for when an error occurs. It is an info message set sl@0: to whatever is relevant for the error. sl@0: */ sl@0: TBuf<400> iDiagnosticMessage; sl@0: }; sl@0: sl@0: #endif