|
1 /* |
|
2 * Copyright (c) 2004-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 "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: Interface which handles certificate related operations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef WIMCERTUTIL_H |
|
21 #define WIMCERTUTIL_H |
|
22 |
|
23 |
|
24 //INCLUDES |
|
25 #include "WimClsv.h" |
|
26 #include "Wimi.h" |
|
27 #include <ct.h> |
|
28 |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CWimCertInfo; |
|
32 class CCTCertInfo; |
|
33 class CWimUtilityFuncs; |
|
34 |
|
35 // CONSTANTS |
|
36 typedef HBufC8* PHBufC8; |
|
37 typedef TPtr8* PTPtr8; |
|
38 |
|
39 |
|
40 // CLASS DECLARATION |
|
41 /** |
|
42 * Utility class that handles certificate related operations. |
|
43 |
|
44 * @since Series60 3.0 |
|
45 */ |
|
46 class CWimCertUtil : public CActive |
|
47 { |
|
48 public: // Constructors and destructor |
|
49 |
|
50 /** |
|
51 * Two-phased constructor. |
|
52 * @param aToken -Reference to current token |
|
53 */ |
|
54 static CWimCertUtil* NewL( MCTToken& aToken ); |
|
55 |
|
56 /** |
|
57 * Destructor |
|
58 */ |
|
59 virtual ~CWimCertUtil(); |
|
60 |
|
61 public: // New functions |
|
62 |
|
63 /** |
|
64 * Restores certificates from WIM cache. If Restore cannot find |
|
65 * any certificate, it will return KErrNotFound to caller. |
|
66 * @param aArray -Array where new certificates are |
|
67 * inserted. Caller is responsible |
|
68 * to deallocate CWimCertInfo -objects |
|
69 * by calling ResetAndDestroy.(IN/OUT) |
|
70 * @param aStatus -Status from caller. |
|
71 */ |
|
72 void Restore( RPointerArray<CWimCertInfo>& aArray, |
|
73 TRequestStatus& aStatus ); |
|
74 |
|
75 |
|
76 /** |
|
77 * Cancels outgoing Restore operation. Sets an internal flag to true. |
|
78 * After necessary cleanup, caller is signalled with KErrCancel |
|
79 * -error code. |
|
80 */ |
|
81 void CancelRestore(); |
|
82 |
|
83 /** |
|
84 * Retrieves the actual certificate. In case of other cert than |
|
85 * Url cert the binary encoded certificate is written into the |
|
86 * aEncodedCert parameter. In case of Url cert the data is |
|
87 * the actual url. |
|
88 * @param aIndex. Used to point iCertRefLst and iCertInfoArr |
|
89 * -arrays for correct certificate. |
|
90 * @param aEncodedCert. A buffer to put the certificate in. |
|
91 * @param aStatus. A request status that is completed when the |
|
92 * operation has finished.(IN/OUT) |
|
93 */ |
|
94 void RetrieveCertByIndexL( const TInt aIndex, |
|
95 TDes8& aEncodedCert, |
|
96 TRequestStatus& aStatus ); |
|
97 |
|
98 private: |
|
99 |
|
100 /** |
|
101 * By default Symbian 2nd phase constructor is private. |
|
102 */ |
|
103 void ConstructL(); |
|
104 |
|
105 /** |
|
106 * C++ default constructor. |
|
107 * @param aToken -Reference to current token |
|
108 */ |
|
109 CWimCertUtil( MCTToken& aToken ); |
|
110 |
|
111 /** |
|
112 * Get count of certificates in WIM |
|
113 * @param aRef WIM card reference pointer. |
|
114 * @param aCertCount Count of certificates in WIM card pointed by aRef |
|
115 * @param aUsage Certificate usage. |
|
116 * @return Status returned by WIMI. See in WimClsv.h. |
|
117 */ |
|
118 WIMI_STAT GetCertificateCountByWIM( WIMI_Ref_t* aRef, |
|
119 TUint8& aCertCount, |
|
120 TUint8 aUsage ) const; |
|
121 /** |
|
122 * Get certificate extra data |
|
123 * @param aWimRef WIM card reference pointer. |
|
124 * @param aUsage Certificate usage. |
|
125 * @param aKeyHash Key hash of certificate |
|
126 * @param aCertExtrasInfo Returned extra data |
|
127 * @return Status returned by WIMI. |
|
128 */ |
|
129 WIMI_STAT GetExtrasFromWimRefL( |
|
130 WIMI_Ref_t* aWimRef, |
|
131 TInt8 aUsage, |
|
132 TDesC8& aKeyHash, |
|
133 TCertExtrasInfo& aCertExtrasInfo ) const; |
|
134 |
|
135 /** |
|
136 * Allocates memory for the array which is filled by server. |
|
137 * @param aWimCertInfoArr -Array to be initialized |
|
138 * @param aCount -Count of elements in the array |
|
139 */ |
|
140 void AllocWimCertInfoL( TWimCertInfo* aWimCertInfoArr, TInt aCount ); |
|
141 |
|
142 /** |
|
143 * Deallocates memory from the array. |
|
144 */ |
|
145 void DeallocWimCertInfo(); |
|
146 |
|
147 /** |
|
148 * Allocates memory for a struct which is filled by server. |
|
149 */ |
|
150 void AllocMemoryForCertDetailsL(); |
|
151 |
|
152 /** |
|
153 * Creates new certificate objects which can be returned to the caller. |
|
154 */ |
|
155 void CreateNewCertObjectsL(); |
|
156 |
|
157 /** |
|
158 * Creates new wim certificate objects. |
|
159 */ |
|
160 void CreateNewWimCertObjectL(); |
|
161 |
|
162 /** |
|
163 * Gets trusted usages. |
|
164 */ |
|
165 void GetTrustedUsagesL(); |
|
166 |
|
167 /** |
|
168 * Completion of trusted usages. |
|
169 */ |
|
170 void TrustedUsagesDoneL(); |
|
171 |
|
172 /** |
|
173 * Sets own iStatus to KRequestPending, and signals it |
|
174 * with User::RequestComplete() -request. This gives chance |
|
175 * to activescheduler to run other active objects. After a quick |
|
176 * visit in activescheduler, signal returns to RunL() and starts next |
|
177 * phase of operation. |
|
178 */ |
|
179 void SignalOwnStatusAndComplete(); |
|
180 |
|
181 /** |
|
182 * Copies data to caller's buffer by using pointer. |
|
183 */ |
|
184 void CopyRetrievedCertData(); |
|
185 |
|
186 /** |
|
187 * DeAllocates memory from member variables, which are used |
|
188 * when communicating with WIM. |
|
189 */ |
|
190 void DeallocCertHBufs(); |
|
191 |
|
192 /** |
|
193 * If user has cancelled initialization process, dealloc references |
|
194 * from loaded certs. |
|
195 */ |
|
196 void DeallocReferences(); |
|
197 |
|
198 /** |
|
199 * Returns certificate format according to received index. |
|
200 * @param aIndex -index of the certificate to be returned. |
|
201 * @return TCertificateFormat -format of the certificate |
|
202 */ |
|
203 TCertificateFormat GetCertFormatByIndex( TInt aIndex ); |
|
204 |
|
205 /** |
|
206 * Copy certificate extra data |
|
207 * @param aCert Reference to certificate |
|
208 * @param aCertExtrasInfo Returned extra data |
|
209 */ |
|
210 void CopyCertExtrasInfoL( WIMI_Ref_t* aCert, |
|
211 TCertExtrasInfo& aCertExtrasInfo ) const; |
|
212 |
|
213 /** |
|
214 * Return count of certificates in WIM |
|
215 * @param aType Certificate type |
|
216 * @return Count of certificates |
|
217 */ |
|
218 TUint8 CertCount( TWimEntryType aType ); |
|
219 |
|
220 /** |
|
221 * Get certificate reference list |
|
222 * @param aCertAddrLst |
|
223 * @param aCertInfoArr |
|
224 * @param aCertEntryType |
|
225 */ |
|
226 void CertRefLstL( TCertificateAddressList aCertAddrLst, |
|
227 TWimCertInfo* aCertInfoArr, |
|
228 TWimEntryType aCertEntryType ); |
|
229 |
|
230 /** |
|
231 * Get certificate extra data |
|
232 * @param aKeyId |
|
233 * @param aCertExtrasInfo |
|
234 * @param aUsage |
|
235 * @param aStatus |
|
236 */ |
|
237 void GetCertExtrasL( const TPtr8* aKeyId, |
|
238 TCertExtrasInfo& aCertExtrasInfo, |
|
239 TUint aUsage, |
|
240 TRequestStatus& aStatus ); |
|
241 |
|
242 /** |
|
243 * Get certificate details |
|
244 * @param aCertAddr |
|
245 * @param aWimCertDetails |
|
246 */ |
|
247 void CertDetailsL( const TCertificateAddress aCertAddr, |
|
248 TWimCertDetails& aWimCertDetails ); |
|
249 |
|
250 /** |
|
251 * |
|
252 * @param aTmpWimRef |
|
253 * @param aUsage |
|
254 * @param aCertNum |
|
255 * @param aCertRefLst |
|
256 * @param aCertInfoLst |
|
257 * @return Error code returned by WIMI |
|
258 */ |
|
259 WIMI_STAT GetCertificateFromWimRefL( WIMI_Ref_t* aTmpWimRef, |
|
260 TInt8 aUsage, |
|
261 TUint8& aCertNum, |
|
262 TUint32* aCertRefLst, |
|
263 TWimCertInfo* aCertInfoLst ); |
|
264 |
|
265 /** |
|
266 * Copy certificate info |
|
267 * @param aCertInfo |
|
268 * @param aCert |
|
269 */ |
|
270 void CopyCertificateInfo( TWimCertInfo& aCertInfo, |
|
271 WIMI_Ref_t* aCert ); |
|
272 |
|
273 private: //from CActive |
|
274 |
|
275 /** |
|
276 * Different phases are handled here. |
|
277 */ |
|
278 void RunL(); |
|
279 |
|
280 /** |
|
281 * Cancellation function |
|
282 * Deallocates member variables and completes client status with |
|
283 * KErrCancel error code. |
|
284 */ |
|
285 void DoCancel(); |
|
286 |
|
287 /** |
|
288 * The active scheduler calls this function if this active |
|
289 * object's RunL() function leaves. |
|
290 * Handles necessary cleanup and completes request with |
|
291 * received error code. |
|
292 * @param aError -The error code which caused this function call. |
|
293 * @return TInt -Error code to activescheduler, is always KErrNone. |
|
294 */ |
|
295 TInt RunError( TInt aError ); |
|
296 |
|
297 private: |
|
298 |
|
299 /** |
|
300 * Seven different phases, which are used to |
|
301 * Read certificates from WIM cache, create new certificate objects and |
|
302 * retrieve certificate |
|
303 */ |
|
304 enum TPhase |
|
305 { |
|
306 EListCertsFromWim, |
|
307 ECreateNewCertObjects, |
|
308 EGetTrustedUsages, |
|
309 ECertObjectsDone, |
|
310 ETrustedUsagesDone, |
|
311 ERetrieveCertificate, |
|
312 ERetrievingCompleted |
|
313 }; |
|
314 |
|
315 //Client status is stored here while operation |
|
316 //on the server side is done. |
|
317 TRequestStatus* iClientStatus; |
|
318 //Array which is used to contain new certificate objects. |
|
319 //Not owned. Caller is responsible to destroy array. |
|
320 RPointerArray<CWimCertInfo>* iArray; |
|
321 //Details of the certificate. Owned. |
|
322 TWimCertDetails iWimCertDetails; |
|
323 //Reference to current token. Needed in CCTCertInfo creation. |
|
324 MCTToken& iToken; |
|
325 //Typedefs for the reference to certificate. Owned. |
|
326 TCertificateAddressList iCertRefLst; |
|
327 // Certificate information structure. Owned. |
|
328 TWimCertInfo* iCertInfoArr; |
|
329 //Used to handle different phases. |
|
330 TPhase iPhase; |
|
331 //Index to point which certificate we want to be retrieved |
|
332 TInt iCertRetrieveIndex; |
|
333 //Used to inform the size of the array, needed in array construction/ |
|
334 //destruction. |
|
335 TInt iArraySize; |
|
336 //The count of certificates |
|
337 TUint8 iCertCount; |
|
338 //Pointer to HBufC8*. This is used as an array when listing every |
|
339 //certificate from WIM to an array during startup. Owned. |
|
340 PHBufC8* iLabel; |
|
341 //Pointer to HBufC8*. This is used as an array when listing every |
|
342 //certificate from WIM to an array during startup. Owned. |
|
343 PHBufC8* iKeyId; |
|
344 //Pointer to HBufC8*. This is used as an array when listing every |
|
345 //certificate from WIM to an array during startup. Owned. |
|
346 PHBufC8* iCAId; |
|
347 //Pointer to HBufC8*. This is used as an array when listing every |
|
348 //certificate from WIM to an array during startup. Owned. |
|
349 PHBufC8* iIssuerHash; |
|
350 //Pointer to iLabel. Also used as an array. Owned. |
|
351 PTPtr8* iLabelPtr; |
|
352 //Pointer to iKeyId. Also used as an array. Owned. |
|
353 PTPtr8* iKeyIdPtr; |
|
354 //Pointer to iCAId. Also used as an array. Owned. |
|
355 PTPtr8* iCAIdPtr; |
|
356 //Pointer to iIssuerHash. Also used as an array. Owned. |
|
357 PTPtr8* iIssuerHashPtr; |
|
358 //Modifiable 8-bit descriptor which points |
|
359 //to caller's descriptor. We copy retrieved certificate |
|
360 //data to this descriptor. Owned. |
|
361 TDes8* iEncodedCert; |
|
362 //Buffer which is used to contain certificate data. Owned. |
|
363 HBufC8* iCertHBufOne; |
|
364 //Pointer to iCertHBufOne. Owned. |
|
365 TPtr8* iCertHBufOnePtr; |
|
366 //Buffer which is used to contain certificate data. Owned. |
|
367 HBufC8* iCertHBufTwo; |
|
368 //Pointer to iCertHBufTwo. Owned. |
|
369 TPtr8* iCertHBufTwoPtr; |
|
370 //Buffer which is used to contain certificate data. Owned. |
|
371 HBufC8* iCertHBufThree; |
|
372 //Pointer to iCertHBufThree. Owned. |
|
373 TPtr8* iCertHBufThreePtr; |
|
374 //Buffer which is used to contain certificate data. Owned. |
|
375 HBufC8* iCertHBufFour; |
|
376 //Pointer to iCertHBufFour. Owned. |
|
377 TPtr8* iCertHBufFourPtr; |
|
378 //ActiveSchedulerWaiter for certificate extra information |
|
379 //fetching. |
|
380 CActiveSchedulerWait iActiveSchedulerWait; |
|
381 //Pointer for trusted usage buffer |
|
382 HBufC* iTrustedUsages; |
|
383 //Pointer to trusted usage buffer pointer |
|
384 TPtr* iTrustedUsagesPtr; |
|
385 //Index pointing to certificate elements |
|
386 TUint8 iIndex; |
|
387 //Pointer to one certificate info, owned |
|
388 CCTCertInfo* iCert; |
|
389 //Pointer to one WIM specific certificate info, owned |
|
390 CWimCertInfo* iCertInfo; |
|
391 //An array of trusted usage oids |
|
392 RArray<HBufC*>* iOids; |
|
393 //Package structure for certificate extra info |
|
394 TCertExtrasInfo iCertExtrasInfo; |
|
395 //Pointer for key identifier buffer |
|
396 HBufC8* iKeyIdBuf; |
|
397 //Used to point right keyId when retrieving extra data |
|
398 TPtr8* iKeyIdPointer; |
|
399 //Pointer to utility functions. Owned. |
|
400 CWimUtilityFuncs* iWimUtilFuncs; |
|
401 }; |
|
402 |
|
403 #endif //WIMCERTUTIL_H |
|
404 |
|
405 // End of File |