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