pkiutilities/ocsp/inc/tcertutils.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // tcertuils.h
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 
       
    24 #ifndef __TCERTUTILS_H__
       
    25 #define __TCERTUTILS_H__
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <x509cert.h>
       
    29 #include <unifiedcertstore.h>
       
    30 #include <pkixcertchain.h>
       
    31 #include "t_output.h"
       
    32 
       
    33 /**
       
    34 CCertUtils provides various functions often used in tests.
       
    35 This class has changed because the functions are asynchronous now. 
       
    36 The function are no longer static as we need an instance to serve as
       
    37 an active object.
       
    38 */
       
    39 class CCertUtils : public CActive
       
    40 	{
       
    41 public:
       
    42 	/**
       
    43 	 * This enumeration enumerates all the states used for the
       
    44 	 * RunL function.
       
    45 	 */
       
    46 	enum TState
       
    47 		{
       
    48 		EAddCACerts,
       
    49 
       
    50 		EAddCert,
       
    51 		EAddCACertGetCAEntry,
       
    52 		EAddCACertSetApplications,
       
    53 		EAddCACertSetTrust,
       
    54 		EAddCACertFinished,
       
    55 
       
    56 		ERemoveCertsGetCACerts,
       
    57 		ERemoveCertsCACertsRetrieved,
       
    58 		ERemoveCertsRemoveCACerts,
       
    59 		ERemoveCertsGetUserCerts,
       
    60 		ERemoveCertsUserCertsRetrieved,
       
    61 		ERemoveCertsRemoveUserCerts,
       
    62 		ERemoveCertsFinished
       
    63 		};	
       
    64 	
       
    65 public:
       
    66 	IMPORT_C static CCertUtils* NewL(RFs& aFs);
       
    67 	IMPORT_C static CCertUtils* NewLC(RFs& aFs);
       
    68 	/**
       
    69 	The destructor destroys all the members of CCertUtils but only destroys
       
    70 	iStoreManager if the CCertStoreManager instance was created by this CCertUtils
       
    71 	instance. It doesn't destroy it if it was passed as an argument in the 
       
    72 	constructor.
       
    73 	*/
       
    74 	IMPORT_C virtual ~CCertUtils();
       
    75 
       
    76 
       
    77 	/**
       
    78 	Certificate handling functions
       
    79 	*/
       
    80 	IMPORT_C void AddCertL(const TDesC& aLabel, 
       
    81 							TCertificateFormat aFormat,
       
    82 							TCertificateOwnerType aCertificateOwnerType, 
       
    83 							TInt aTrustedUsage, 
       
    84 							const TDesC& aCertificatePath, 
       
    85 							const TDesC& aCertificateFileName, 
       
    86 							TRequestStatus& aStatus);
       
    87 							
       
    88 	IMPORT_C void AddCert(const TDesC& aLabel, 
       
    89 							TCertificateFormat aFormat,
       
    90 							TCertificateOwnerType aCertificateOwnerType, 
       
    91 							TInt aTrustedUsage, 
       
    92 							const TDesC& aCertificatePath, 
       
    93 							const TDesC& aCertificateFileName, 
       
    94 							CUnifiedCertStore& aUnifiedCertStore, 
       
    95 							TRequestStatus& aStatus);
       
    96 						
       
    97 	IMPORT_C void AddCACertsL(const CDesCArray& aRoots, 
       
    98 							const CDesCArray& aLabels,
       
    99 							TCertificateFormat aFormat, 
       
   100 							TInt aTrustedUsage, 
       
   101 							const TDesC& aPath, 
       
   102 							TRequestStatus& aStatus);
       
   103 							
       
   104 	IMPORT_C void AddCACertsL(const CDesCArray& aRoots, 
       
   105 							const CDesCArray& aLabels,
       
   106 							TCertificateFormat aFormat, 
       
   107 							TInt aTrustedUsage, 
       
   108 							const TDesC& aPath, 
       
   109 							CUnifiedCertStore& aUnifiedCertStore, 
       
   110 							TRequestStatus& aStatus);
       
   111 							
       
   112 	IMPORT_C void RemoveCertsL(TRequestStatus& aStatus);
       
   113 	IMPORT_C void RemoveCertsL(CUnifiedCertStore& aUnifiedCertStore, 
       
   114 							TRequestStatus& aStatus);
       
   115 
       
   116 	IMPORT_C static CCertificate* CertFromFileLC(const TDesC& aFilename, 
       
   117 							const TDesC& aPathname, 
       
   118 							RFs& aFs, 
       
   119 							TCertificateFormat aFormat);
       
   120 							
       
   121 	IMPORT_C static CCertificate* CertFromFileL(const TDesC& aFilename,
       
   122 							const TDesC& aPathname, 
       
   123 							RFs& aFs, 
       
   124 							TCertificateFormat aFormat);
       
   125 							
       
   126 	IMPORT_C static void WriteError(TValidationError aError, Output& aOut);
       
   127 	IMPORT_C static TPtrC MapError(TValidationError aError);
       
   128 	IMPORT_C static TValidationError MapError(const TDesC& aError);
       
   129 	IMPORT_C static TPtrC ParseElement(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, TInt& aPos, TInt& aError);
       
   130 
       
   131 	IMPORT_C HBufC* DiagnosticLC() const;
       
   132 	IMPORT_C void AddApplicationL(const TDesC& aName, TUid aUid) const;
       
   133 	IMPORT_C void RemoveApplicationL(TUid aUid) const;
       
   134 
       
   135 private:
       
   136 	/**
       
   137 	This constructor constructs a CCertUtils instance without initializing
       
   138 	iStoreManager. A store manager will be created if one is needed and
       
   139 	will be destroyed by the destructor.
       
   140 	@param aFs A file server session. The file server session must have opened.
       
   141 	*/
       
   142 	CCertUtils(RFs& aFs);
       
   143 	void ConstructL();
       
   144 
       
   145 	//Virtual from CActive
       
   146 	void RunL();
       
   147 	void DoCancel();
       
   148     TInt RunError(TInt aError);
       
   149 
       
   150 
       
   151 private:
       
   152 	// The following functions handle the different RunL states
       
   153 	void HandleEAddCACertsL();
       
   154 
       
   155 	void HandleEAddCACertL();
       
   156 	void HandleEAddCACertGetCAEntry();
       
   157 	void HandleEAddCACertSetApplicationsL();
       
   158 	void HandleEAddCACertSetTrust();
       
   159 	void HandleEAddCACertFinishedL();
       
   160 	
       
   161 	void HandleERemoveCertsGetCACerts();
       
   162 	void HandleERemoveCertsCACertsRetrieved();
       
   163 	void HandleERemoveCertsRemoveCACerts();
       
   164 	void HandleERemoveCertsGetUserCerts();
       
   165 	void HandleERemoveCertsUserCertsRetrieved();
       
   166 	void HandleERemoveCertsRemoveUserCerts();
       
   167 	void HandleERemoveCertsFinished();
       
   168 
       
   169 
       
   170 private:
       
   171 	/**
       
   172 	File Server Sessioin
       
   173 	*/
       
   174 	RFs& iFs;
       
   175 
       
   176 	/**
       
   177 	The state used to know what RunL should do
       
   178 	*/
       
   179 	TState iState;
       
   180 	
       
   181 	/**
       
   182 	The store managers will be used for certificate store operations,
       
   183 	*/
       
   184 	CUnifiedCertStore* iUnifiedCertStore;
       
   185 	CUnifiedCertStore* iCreatedUnifiedCertStore;
       
   186 	
       
   187 	/**
       
   188 	These members are used to store the arguments of the functions
       
   189 	because most of the things are handled in a RunL.
       
   190 	*/
       
   191 	const CDesCArray* iRoots;					// Used by AddCertsL
       
   192 	const CDesCArray* iLabels;					// Used by AddCertsL
       
   193 	TCertificateFormat iFormat;
       
   194 	TInt iTrustedUsage;							// Used by AddCertsL, AddCert
       
   195 	RArray<TUid> iTrusters;						// Used by AddCertsL, AddCert
       
   196 	const TDesC* iPath;							// Used by AddCertsL, AddCert
       
   197 	TRequestStatus* iOriginalRequestStatus;		// Used by AddCertsL, AddCert
       
   198 	TInt iIndex;								// Used by AddCertsL to know 
       
   199 												// which certificate to add next
       
   200 												// Used by RemoveCerts
       
   201 	CCertUtils* iSecondCertUtils;				// Used by AddCertsL to add each individual
       
   202 												// certificate
       
   203 	const TDesC* iLabel;						// Used by AddCert
       
   204 	TCertificateOwnerType iCertificateOwnerType;
       
   205 	const TDesC* iCertificateFileName;			// Used by AddCert 
       
   206 	CCertificate* iCertificate;					// Used by AddCACert
       
   207 	MCTWritableCertStore *iStore;				// Used by AddCACert
       
   208 	TPtrC8 iEncoding;							// Used by AddCACert
       
   209 
       
   210 	HBufC* iCertData;
       
   211 	HBufC* iLabelData;
       
   212 
       
   213 	/**
       
   214 	This is a filter used by the GetCACerts function. We use the filter constructed
       
   215 	by the constructor with no argument, the filter doesn't filter anything.
       
   216 	*/
       
   217 	CCertAttributeFilter* iCAFilter;				// Used by RemoveCerts
       
   218 	RMPointerArray<CCTCertInfo> iCACertStoreEntries;	// Used by RemoveCerts
       
   219 	
       
   220 	/**
       
   221 	This is a filter used by the GetUserCerts function. We use the filter constructed
       
   222 	by the constructot with no argument, the filter doesn't filter anything.
       
   223 	*/
       
   224 	CCertAttributeFilter* iUserFilter;			// Used by RemoveCerts
       
   225 	RMPointerArray<CCTCertInfo> iUserCertStoreEntries; // Used by RemoveCerts
       
   226 
       
   227 public:
       
   228 	/**
       
   229 	A diagnostic variable for when an error occurs. It stores the state at which
       
   230 	the error occurred.
       
   231 	*/
       
   232 	TState iDiagnosticState;
       
   233 	
       
   234 	/** 
       
   235 	A diagnostic variable for when an error occurs. It is an info message set
       
   236 	to whatever is relevant for the error.
       
   237 	*/
       
   238 	TBuf<400> iDiagnosticMessage;
       
   239 	};
       
   240 
       
   241 #endif