First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
26 #ifndef __TCERTUTILS_H__
27 #define __TCERTUTILS_H__
31 #include <unifiedcertstore.h>
32 #include <pkixcertchain.h>
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
41 class CCertUtils : public CActive
45 * This enumeration enumerates all the states used for the
54 EAddCACertSetApplications,
58 ERemoveCertsGetCACerts,
59 ERemoveCertsCACertsRetrieved,
60 ERemoveCertsRemoveCACerts,
61 ERemoveCertsGetUserCerts,
62 ERemoveCertsUserCertsRetrieved,
63 ERemoveCertsRemoveUserCerts,
68 IMPORT_C static CCertUtils* NewL(RFs& aFs);
69 IMPORT_C static CCertUtils* NewLC(RFs& aFs);
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
76 IMPORT_C virtual ~CCertUtils();
80 Certificate handling functions
82 IMPORT_C void AddCertL(const TDesC& aLabel,
83 TCertificateFormat aFormat,
84 TCertificateOwnerType aCertificateOwnerType,
86 const TDesC& aCertificatePath,
87 const TDesC& aCertificateFileName,
88 TRequestStatus& aStatus);
90 IMPORT_C void AddCert(const TDesC& aLabel,
91 TCertificateFormat aFormat,
92 TCertificateOwnerType aCertificateOwnerType,
94 const TDesC& aCertificatePath,
95 const TDesC& aCertificateFileName,
96 CUnifiedCertStore& aUnifiedCertStore,
97 TRequestStatus& aStatus);
99 IMPORT_C void AddCACertsL(const CDesCArray& aRoots,
100 const CDesCArray& aLabels,
101 TCertificateFormat aFormat,
104 TRequestStatus& aStatus);
106 IMPORT_C void AddCACertsL(const CDesCArray& aRoots,
107 const CDesCArray& aLabels,
108 TCertificateFormat aFormat,
111 CUnifiedCertStore& aUnifiedCertStore,
112 TRequestStatus& aStatus);
114 IMPORT_C void RemoveCertsL(TRequestStatus& aStatus);
115 IMPORT_C void RemoveCertsL(CUnifiedCertStore& aUnifiedCertStore,
116 TRequestStatus& aStatus);
118 IMPORT_C static CCertificate* CertFromFileLC(const TDesC& aFilename,
119 const TDesC& aPathname,
121 TCertificateFormat aFormat);
123 IMPORT_C static CCertificate* CertFromFileL(const TDesC& aFilename,
124 const TDesC& aPathname,
126 TCertificateFormat aFormat);
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);
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;
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.
144 CCertUtils(RFs& aFs);
147 //Virtual from CActive
150 TInt RunError(TInt aError);
154 // The following functions handle the different RunL states
155 void HandleEAddCACertsL();
157 void HandleEAddCACertL();
158 void HandleEAddCACertGetCAEntry();
159 void HandleEAddCACertSetApplicationsL();
160 void HandleEAddCACertSetTrust();
161 void HandleEAddCACertFinishedL();
163 void HandleERemoveCertsGetCACerts();
164 void HandleERemoveCertsCACertsRetrieved();
165 void HandleERemoveCertsRemoveCACerts();
166 void HandleERemoveCertsGetUserCerts();
167 void HandleERemoveCertsUserCertsRetrieved();
168 void HandleERemoveCertsRemoveUserCerts();
169 void HandleERemoveCertsFinished();
179 The state used to know what RunL should do
184 The store managers will be used for certificate store operations,
186 CUnifiedCertStore* iUnifiedCertStore;
187 CUnifiedCertStore* iCreatedUnifiedCertStore;
190 These members are used to store the arguments of the functions
191 because most of the things are handled in a RunL.
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
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
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.
219 CCertAttributeFilter* iCAFilter; // Used by RemoveCerts
220 RMPointerArray<CCTCertInfo> iCACertStoreEntries; // Used by RemoveCerts
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.
226 CCertAttributeFilter* iUserFilter; // Used by RemoveCerts
227 RMPointerArray<CCTCertInfo> iUserCertStoreEntries; // Used by RemoveCerts
231 A diagnostic variable for when an error occurs. It stores the state at which
234 TState iDiagnosticState;
237 A diagnostic variable for when an error occurs. It is an info message set
238 to whatever is relevant for the error.
240 TBuf<400> iDiagnosticMessage;