os/security/cryptoservices/certificateandkeymgmt/tcertcommon/tcertutils.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tcertcommon/tcertutils.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,243 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* tcertuils.h
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file 
    1.25 + @internalTechnology
    1.26 +*/
    1.27 +
    1.28 +
    1.29 +#ifndef __TCERTUTILS_H__
    1.30 +#define __TCERTUTILS_H__
    1.31 +
    1.32 +#include <e32base.h>
    1.33 +#include <x509cert.h>
    1.34 +#include <unifiedcertstore.h>
    1.35 +#include <pkixcertchain.h>
    1.36 +#include "t_output.h"
    1.37 +
    1.38 +/**
    1.39 +CCertUtils provides various functions often used in tests.
    1.40 +This class has changed because the functions are asynchronous now. 
    1.41 +The function are no longer static as we need an instance to serve as
    1.42 +an active object.
    1.43 +*/
    1.44 +class CCertUtils : public CActive
    1.45 +	{
    1.46 +public:
    1.47 +	/**
    1.48 +	 * This enumeration enumerates all the states used for the
    1.49 +	 * RunL function.
    1.50 +	 */
    1.51 +	enum TState
    1.52 +		{
    1.53 +		EAddCACerts,
    1.54 +
    1.55 +		EAddCert,
    1.56 +		EAddCACertGetCAEntry,
    1.57 +		EAddCACertSetApplications,
    1.58 +		EAddCACertSetTrust,
    1.59 +		EAddCACertFinished,
    1.60 +
    1.61 +		ERemoveCertsGetCACerts,
    1.62 +		ERemoveCertsCACertsRetrieved,
    1.63 +		ERemoveCertsRemoveCACerts,
    1.64 +		ERemoveCertsGetUserCerts,
    1.65 +		ERemoveCertsUserCertsRetrieved,
    1.66 +		ERemoveCertsRemoveUserCerts,
    1.67 +		ERemoveCertsFinished
    1.68 +		};	
    1.69 +	
    1.70 +public:
    1.71 +	IMPORT_C static CCertUtils* NewL(RFs& aFs);
    1.72 +	IMPORT_C static CCertUtils* NewLC(RFs& aFs);
    1.73 +	/**
    1.74 +	The destructor destroys all the members of CCertUtils but only destroys
    1.75 +	iStoreManager if the CCertStoreManager instance was created by this CCertUtils
    1.76 +	instance. It doesn't destroy it if it was passed as an argument in the 
    1.77 +	constructor.
    1.78 +	*/
    1.79 +	IMPORT_C virtual ~CCertUtils();
    1.80 +
    1.81 +
    1.82 +	/**
    1.83 +	Certificate handling functions
    1.84 +	*/
    1.85 +	IMPORT_C void AddCertL(const TDesC& aLabel, 
    1.86 +							TCertificateFormat aFormat,
    1.87 +							TCertificateOwnerType aCertificateOwnerType, 
    1.88 +							TInt aTrustedUsage, 
    1.89 +							const TDesC& aCertificatePath, 
    1.90 +							const TDesC& aCertificateFileName, 
    1.91 +							TRequestStatus& aStatus);
    1.92 +							
    1.93 +	IMPORT_C void AddCert(const TDesC& aLabel, 
    1.94 +							TCertificateFormat aFormat,
    1.95 +							TCertificateOwnerType aCertificateOwnerType, 
    1.96 +							TInt aTrustedUsage, 
    1.97 +							const TDesC& aCertificatePath, 
    1.98 +							const TDesC& aCertificateFileName, 
    1.99 +							CUnifiedCertStore& aUnifiedCertStore, 
   1.100 +							TRequestStatus& aStatus);
   1.101 +						
   1.102 +	IMPORT_C void AddCACertsL(const CDesCArray& aRoots, 
   1.103 +							const CDesCArray& aLabels,
   1.104 +							TCertificateFormat aFormat, 
   1.105 +							TInt aTrustedUsage, 
   1.106 +							const TDesC& aPath, 
   1.107 +							TRequestStatus& aStatus);
   1.108 +							
   1.109 +	IMPORT_C void AddCACertsL(const CDesCArray& aRoots, 
   1.110 +							const CDesCArray& aLabels,
   1.111 +							TCertificateFormat aFormat, 
   1.112 +							TInt aTrustedUsage, 
   1.113 +							const TDesC& aPath, 
   1.114 +							CUnifiedCertStore& aUnifiedCertStore, 
   1.115 +							TRequestStatus& aStatus);
   1.116 +							
   1.117 +	IMPORT_C void RemoveCertsL(TRequestStatus& aStatus);
   1.118 +	IMPORT_C void RemoveCertsL(CUnifiedCertStore& aUnifiedCertStore, 
   1.119 +							TRequestStatus& aStatus);
   1.120 +
   1.121 +	IMPORT_C static CCertificate* CertFromFileLC(const TDesC& aFilename, 
   1.122 +							const TDesC& aPathname, 
   1.123 +							RFs& aFs, 
   1.124 +							TCertificateFormat aFormat);
   1.125 +							
   1.126 +	IMPORT_C static CCertificate* CertFromFileL(const TDesC& aFilename,
   1.127 +							const TDesC& aPathname, 
   1.128 +							RFs& aFs, 
   1.129 +							TCertificateFormat aFormat);
   1.130 +							
   1.131 +	IMPORT_C static void WriteError(TValidationError aError, Output& aOut);
   1.132 +	IMPORT_C static TPtrC MapError(TValidationError aError);
   1.133 +	IMPORT_C static TValidationError MapError(const TDesC& aError);
   1.134 +	IMPORT_C static TPtrC ParseElement(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, TInt& aPos, TInt& aError);
   1.135 +
   1.136 +	IMPORT_C HBufC* DiagnosticLC() const;
   1.137 +	IMPORT_C void AddApplicationL(const TDesC& aName, TUid aUid) const;
   1.138 +	IMPORT_C void RemoveApplicationL(TUid aUid) const;
   1.139 +
   1.140 +private:
   1.141 +	/**
   1.142 +	This constructor constructs a CCertUtils instance without initializing
   1.143 +	iStoreManager. A store manager will be created if one is needed and
   1.144 +	will be destroyed by the destructor.
   1.145 +	@param aFs A file server session. The file server session must have opened.
   1.146 +	*/
   1.147 +	CCertUtils(RFs& aFs);
   1.148 +	void ConstructL();
   1.149 +
   1.150 +	//Virtual from CActive
   1.151 +	void RunL();
   1.152 +	void DoCancel();
   1.153 +    TInt RunError(TInt aError);
   1.154 +
   1.155 +
   1.156 +private:
   1.157 +	// The following functions handle the different RunL states
   1.158 +	void HandleEAddCACertsL();
   1.159 +
   1.160 +	void HandleEAddCACertL();
   1.161 +	void HandleEAddCACertGetCAEntry();
   1.162 +	void HandleEAddCACertSetApplicationsL();
   1.163 +	void HandleEAddCACertSetTrust();
   1.164 +	void HandleEAddCACertFinishedL();
   1.165 +	
   1.166 +	void HandleERemoveCertsGetCACerts();
   1.167 +	void HandleERemoveCertsCACertsRetrieved();
   1.168 +	void HandleERemoveCertsRemoveCACerts();
   1.169 +	void HandleERemoveCertsGetUserCerts();
   1.170 +	void HandleERemoveCertsUserCertsRetrieved();
   1.171 +	void HandleERemoveCertsRemoveUserCerts();
   1.172 +	void HandleERemoveCertsFinished();
   1.173 +
   1.174 +
   1.175 +private:
   1.176 +	/**
   1.177 +	File Server Sessioin
   1.178 +	*/
   1.179 +	RFs& iFs;
   1.180 +
   1.181 +	/**
   1.182 +	The state used to know what RunL should do
   1.183 +	*/
   1.184 +	TState iState;
   1.185 +	
   1.186 +	/**
   1.187 +	The store managers will be used for certificate store operations,
   1.188 +	*/
   1.189 +	CUnifiedCertStore* iUnifiedCertStore;
   1.190 +	CUnifiedCertStore* iCreatedUnifiedCertStore;
   1.191 +	
   1.192 +	/**
   1.193 +	These members are used to store the arguments of the functions
   1.194 +	because most of the things are handled in a RunL.
   1.195 +	*/
   1.196 +	const CDesCArray* iRoots;					// Used by AddCertsL
   1.197 +	const CDesCArray* iLabels;					// Used by AddCertsL
   1.198 +	TCertificateFormat iFormat;
   1.199 +	TInt iTrustedUsage;							// Used by AddCertsL, AddCert
   1.200 +	RArray<TUid> iTrusters;						// Used by AddCertsL, AddCert
   1.201 +	const TDesC* iPath;							// Used by AddCertsL, AddCert
   1.202 +	TRequestStatus* iOriginalRequestStatus;		// Used by AddCertsL, AddCert
   1.203 +	TInt iIndex;								// Used by AddCertsL to know 
   1.204 +												// which certificate to add next
   1.205 +												// Used by RemoveCerts
   1.206 +	CCertUtils* iSecondCertUtils;				// Used by AddCertsL to add each individual
   1.207 +												// certificate
   1.208 +	const TDesC* iLabel;						// Used by AddCert
   1.209 +	TCertificateOwnerType iCertificateOwnerType;
   1.210 +	const TDesC* iCertificateFileName;			// Used by AddCert 
   1.211 +	CCertificate* iCertificate;					// Used by AddCACert
   1.212 +	MCTWritableCertStore *iStore;				// Used by AddCACert
   1.213 +	TPtrC8 iEncoding;							// Used by AddCACert
   1.214 +
   1.215 +	HBufC* iCertData;
   1.216 +	HBufC* iLabelData;
   1.217 +
   1.218 +	/**
   1.219 +	This is a filter used by the GetCACerts function. We use the filter constructed
   1.220 +	by the constructor with no argument, the filter doesn't filter anything.
   1.221 +	*/
   1.222 +	CCertAttributeFilter* iCAFilter;				// Used by RemoveCerts
   1.223 +	RMPointerArray<CCTCertInfo> iCACertStoreEntries;	// Used by RemoveCerts
   1.224 +	
   1.225 +	/**
   1.226 +	This is a filter used by the GetUserCerts function. We use the filter constructed
   1.227 +	by the constructot with no argument, the filter doesn't filter anything.
   1.228 +	*/
   1.229 +	CCertAttributeFilter* iUserFilter;			// Used by RemoveCerts
   1.230 +	RMPointerArray<CCTCertInfo> iUserCertStoreEntries; // Used by RemoveCerts
   1.231 +
   1.232 +public:
   1.233 +	/**
   1.234 +	A diagnostic variable for when an error occurs. It stores the state at which
   1.235 +	the error occurred.
   1.236 +	*/
   1.237 +	TState iDiagnosticState;
   1.238 +	
   1.239 +	/** 
   1.240 +	A diagnostic variable for when an error occurs. It is an info message set
   1.241 +	to whatever is relevant for the error.
   1.242 +	*/
   1.243 +	TBuf<400> iDiagnosticMessage;
   1.244 +	};
   1.245 +
   1.246 +#endif