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