|
1 /* |
|
2 * Copyright (c) 2002 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: Reads certificates bypassing crypto token framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef WIMCERT_H |
|
20 #define WIMCERT_H |
|
21 |
|
22 |
|
23 //INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <e32std.h> |
|
26 #include <ct.h> |
|
27 |
|
28 //TYPE DEFINITIONS |
|
29 typedef HBufC8* PHBufC8; |
|
30 typedef TPtr8* PTPtr8; |
|
31 |
|
32 enum TCertLocation |
|
33 { |
|
34 EUnknown_CDF, |
|
35 ECertificates_CDF, |
|
36 ETrustedCerts_CDF, |
|
37 EUsefulCerts_CDF |
|
38 }; |
|
39 |
|
40 //FORWARD DECLARATIONS |
|
41 class RWimCertMgmt; |
|
42 class RWimMgmt; |
|
43 |
|
44 |
|
45 |
|
46 //CLASS DECLARATION |
|
47 /** |
|
48 * Reads certificate extra information from Smart Card |
|
49 * |
|
50 * @lib WimClient |
|
51 * @since Series60 2.1 |
|
52 */ |
|
53 class CWimCert : public CActive |
|
54 { |
|
55 public: // Member functions |
|
56 |
|
57 /** |
|
58 * Two-phased constructor. |
|
59 */ |
|
60 IMPORT_C static CWimCert* NewL(); |
|
61 |
|
62 /** |
|
63 * Destructor |
|
64 */ |
|
65 IMPORT_C virtual ~CWimCert(); |
|
66 |
|
67 /** |
|
68 * Initializes the WIM server cache and restores certificates to |
|
69 * WimClient memory area. This is the most time consuming call. |
|
70 * @param aStatus Indicates the result of this call. Values: |
|
71 * KErrNotFound, no certificates was found |
|
72 * KErrNone, call was successull and at least one certificate |
|
73 * found. |
|
74 * KErrGeneral, any other error |
|
75 * KErrNoMemory, no memory |
|
76 * @return void |
|
77 */ |
|
78 IMPORT_C void Initialize( TRequestStatus& aStatus ); |
|
79 |
|
80 /** |
|
81 * Cancels outgoing Initialize operation. |
|
82 * After necessary cleanup, caller (given aStatus) is signalled with |
|
83 * KErrCancel |
|
84 * @return void |
|
85 */ |
|
86 IMPORT_C void CancelInitialize(); |
|
87 |
|
88 /** |
|
89 * Fetches trusted usages and location information for Key ID. |
|
90 * @param aKeyId (IN) Key identifier (hash), which points to a |
|
91 * certificate. |
|
92 * @param aTrustedUsages (OUT) An array of OID strings indicating |
|
93 * trusted usage. The notation is dot delimited |
|
94 * (for example 1.23.456.7), the length of OÌD can vary. |
|
95 * (OID=Object IDentifier). Caller is responsible of |
|
96 * destroying array. |
|
97 * @param aLocation (OUT) Indicates certificate directory location |
|
98 * in Smart Card. |
|
99 * @param aStatus Indicates the result of this call. Values: |
|
100 * KErrNotFound, given certificate KeyId was not found from card |
|
101 * KErrNone, no errors, given certificate was found and trusted |
|
102 * usage was present and location were known |
|
103 * KErrPathNotFound, trusted usage was not found or location |
|
104 * was not known |
|
105 * KErrGeneral, any other error |
|
106 * KErrNoMemory, No memory |
|
107 * @return void |
|
108 */ |
|
109 IMPORT_C void GetExtras( const TDesC8& aKeyId, |
|
110 RCPointerArray<HBufC>& aTrustedUsages, |
|
111 TCertLocation& aLocation, |
|
112 TRequestStatus& aStatus ); |
|
113 |
|
114 /** |
|
115 * Cancels outgoing GetExtras operation. |
|
116 * After necessary cleanup, caller is signalled with KErrCancel |
|
117 * @return void |
|
118 */ |
|
119 IMPORT_C void CancelGetExtras(); |
|
120 |
|
121 private: |
|
122 |
|
123 /** |
|
124 * Symbian constructor |
|
125 */ |
|
126 void ConstructL(); |
|
127 |
|
128 /** |
|
129 * C++ default constructor. |
|
130 */ |
|
131 CWimCert(); |
|
132 |
|
133 private: //from CActive |
|
134 |
|
135 /** |
|
136 * Different phases are handled here. |
|
137 * @return void |
|
138 */ |
|
139 void RunL(); |
|
140 |
|
141 /** |
|
142 * Cancellation function |
|
143 * Deallocates member variables and completes client status with |
|
144 * KErrCancel error code. |
|
145 * @return void |
|
146 */ |
|
147 void DoCancel(); |
|
148 |
|
149 /** |
|
150 * The active scheduler calls this function if this active |
|
151 * object's RunL() function leaves. |
|
152 * Handles necessary cleanup and completes request with |
|
153 * received error code. |
|
154 * @param aError -Error code which launched this event. |
|
155 * @return TInt Error code to active scheduler, is always KErrNone. |
|
156 */ |
|
157 TInt RunError( TInt aError ); |
|
158 |
|
159 private: // functions |
|
160 |
|
161 /** |
|
162 * Tries to locate certificate by using retrieved KeyId. |
|
163 * @return boolean -If certificate is found and it has extra data, |
|
164 * @return ETrue. Else return EFalse. |
|
165 */ |
|
166 TBool CertificateLocated(); |
|
167 |
|
168 /** |
|
169 * Fills caller's data area with requested extra data |
|
170 * @return void |
|
171 */ |
|
172 void ExtraDataFoundL(); |
|
173 |
|
174 /** |
|
175 * Handles cleanup for an object which is not derived from CBase |
|
176 * @param aObject -object to be cleaned up |
|
177 * @return void |
|
178 */ |
|
179 static void Cleanup( TAny* aObject ); |
|
180 |
|
181 /** |
|
182 * Handles cleanup for an object which is not derived from CBase |
|
183 * @param aObject -object to be cleaned up |
|
184 * @return void |
|
185 */ |
|
186 static void CleanupRefLst( TAny* aObject ); |
|
187 |
|
188 /** |
|
189 * Deallocates memory from the array. |
|
190 * @return void |
|
191 */ |
|
192 void DeallocWimCertInfo(); |
|
193 |
|
194 /** |
|
195 * Sets own iStatus to KRequestPending, and signals it |
|
196 * with User::RequestComplete() request. This gives chance |
|
197 * to active scheduler to run other active objects. After a quick |
|
198 * visit in actives cheduler, signal returns to RunL() and starts next |
|
199 * phase of operation. |
|
200 * @return void |
|
201 */ |
|
202 void SignalOwnStatusAndComplete(); |
|
203 |
|
204 /** |
|
205 * Allocates variables when retrieving extra certificate data |
|
206 * from WimServer. |
|
207 * @return void |
|
208 */ |
|
209 void AllocMemoryForExtraDataRetrieveL(); |
|
210 |
|
211 /* |
|
212 * DeAllocates variables after extra data retrieving operation. |
|
213 * @return void |
|
214 */ |
|
215 void DeAllocMemoryForExtraDataRetrieve(); |
|
216 |
|
217 /* |
|
218 * DeAllocates member variable RArrays. |
|
219 * @return void |
|
220 */ |
|
221 void DeallocRArrays(); |
|
222 |
|
223 private: // data |
|
224 |
|
225 /** |
|
226 * Different states of this state machine |
|
227 */ |
|
228 enum TPhase |
|
229 { |
|
230 EConnectClientSession, |
|
231 ECreateNewSession, |
|
232 EInitializeWim, |
|
233 EListCertsFromWim, |
|
234 EGetCertClientSession, |
|
235 ELocateCertificate, |
|
236 EGiveExtraData |
|
237 }; |
|
238 |
|
239 //Client status is stored here while operation |
|
240 //on the server side is done. |
|
241 TRequestStatus* iClientStatus; |
|
242 |
|
243 //Handle to connection with server. Owned. |
|
244 RWimCertMgmt* iConnectionHandle; |
|
245 |
|
246 // Pointer to Client Session. Owned. |
|
247 // Valid as long as CWimSecModuleMgr is valid. |
|
248 RWimMgmt* iClientSession; |
|
249 |
|
250 //Used to handle different phases. |
|
251 TPhase iPhase; |
|
252 |
|
253 //The count of certificates |
|
254 TUint8 iCertCount; |
|
255 |
|
256 //Buffer, which is used when fetching trustedusage from Server. Owned |
|
257 HBufC* iCertHBufTrustedUsageFromServer; |
|
258 |
|
259 //Pointer, which used to point iCertHBufTrustedUsageFromServer. Owned |
|
260 TPtr* iCertHBufTrustedUsageFromServerPtr; |
|
261 |
|
262 //Array which is filled with trusted usage strings. Not owned. |
|
263 RCPointerArray<HBufC>* iTrustedUsages; |
|
264 |
|
265 // Informs the certificate location to caller. |
|
266 // Used when user has called GetExtras |
|
267 TCertLocation* iLocation; |
|
268 |
|
269 //The KeyId, which is received from caller. Used when user has called |
|
270 //GetExtras |
|
271 HBufC8* iKeyIdToBeMatched; |
|
272 |
|
273 //This tells the index of the certificate, from which we want |
|
274 //the trusted usages taken out. |
|
275 TUint8 iCertIndex; |
|
276 |
|
277 //Flag to indicate errors during WIM -initialization. |
|
278 TInt iWimStartErr; |
|
279 |
|
280 //Array for certificate type. |
|
281 RArray<TUint> iCertTypes; |
|
282 |
|
283 //Array for trusted usage lengths |
|
284 RArray<TUint> iTrustedUsageLengths; |
|
285 |
|
286 //Arrray for usages |
|
287 RArray<TUint> iUsages; |
|
288 |
|
289 //Array for KeyIds.Owned |
|
290 RArray<HBufC8*> iKeyIds; |
|
291 |
|
292 //Used to point right keyId when retrieving extra data |
|
293 TPtr8* iKeyIdPointer; |
|
294 |
|
295 //Pointer to HBufC8*. This is used as an array when listing every |
|
296 //certificate from WIM to an array during startup. Owned. |
|
297 PHBufC8* iLabel; |
|
298 |
|
299 //Pointer to HBufC8*. This is used as an array when listing every |
|
300 //certificate from WIM to an array during startup. Owned. |
|
301 PHBufC8* iKeyId; |
|
302 |
|
303 //Pointer to HBufC8*. This is used as an array when listing every |
|
304 //certificate from WIM to an array during startup. Owned. |
|
305 PHBufC8* iCAId; |
|
306 |
|
307 //Pointer to HBufC8*. This is used as an array when listing every |
|
308 //certificate from WIM to an array during startup. Owned. |
|
309 PHBufC8* iIssuerHash; |
|
310 |
|
311 //Pointer to iLabel. Also used as an array. Owned. |
|
312 PTPtr8* iLabelPtr; |
|
313 |
|
314 //Pointer to iKeyId. Also used as an array. Owned. |
|
315 PTPtr8* iKeyIdPtr; |
|
316 |
|
317 //Pointer to iCAId. Also used as an array. Owned. |
|
318 PTPtr8* iCAIdPtr; |
|
319 |
|
320 //Pointer to iIssuerHash. Also used as an array. Owned. |
|
321 PTPtr8* iIssuerHashPtr; |
|
322 }; |
|
323 |
|
324 #endif // WIMCERT_H |
|
325 |
|
326 // End of File |