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