|
1 /* |
|
2 * Copyright (c) 2003 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: Implements WIM TrustSettingsStore for WIM certificates |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CWIMTRUSTSETTINGSSTORE_H |
|
21 #define CWIMTRUSTSETTINGSSTORE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <cctcertinfo.h> |
|
26 #include <f32file.h> |
|
27 #include <d32dbms.h> |
|
28 #include "WimDefs.h" // TTSSCertLocation |
|
29 #include <data_caging_path_literals.hrh> |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // The location of wim trust setting storage |
|
34 // The path is taken from data_caging_path_literals |
|
35 _LIT( KWimTrustSettingsDBFile, "WimTrustSettingsStore.dat" ); |
|
36 |
|
37 // Object identifier (OID) for server authentication |
|
38 _LIT( KIpKpServerAuth, "2.5.29.37.1" ); |
|
39 // Object identifier (OID) for JavaMidlet certificates |
|
40 _LIT( KIpKpJavaMidlet, "1.3.6.1.4.1.42.2.110.2.2.2.1" ); |
|
41 // Object identifier (OID) for code signer certificates |
|
42 _LIT( KWimCodeSigningOID, "1.3.6.1.5.5.7.3.3" ); |
|
43 |
|
44 // Default value for trusted flag |
|
45 const TBool KDefaultTrustFlag = ETrue; |
|
46 // Maximum length of SQL query clause |
|
47 const TInt KMaxSQLLength = 100; |
|
48 // Trusting applications |
|
49 const TInt KTrustUidWapBearer = 268479059; |
|
50 const TInt KTrustUidAppController = 268452523; |
|
51 const TInt KTrustUidInternet = 268441661; |
|
52 const TInt KTrustUidJavaMidlet = 270506792; |
|
53 |
|
54 // FORWARD DECLARATION |
|
55 |
|
56 class CWimCertUtil; |
|
57 class CWimCertInfo; |
|
58 |
|
59 // CLASS DECLARATION |
|
60 |
|
61 /** |
|
62 * This class implements services for trust settings. |
|
63 * Class includes functions for creating DB, fetching, updating and |
|
64 * deleting trust settings. |
|
65 * |
|
66 * @lib WimPlugin.lib |
|
67 * @since Series60 2.1 |
|
68 */ |
|
69 class CWimTrustSettingsStore : public CActive |
|
70 { |
|
71 public: // Constructor and destructor |
|
72 |
|
73 /** |
|
74 * Two-phased constructor. |
|
75 */ |
|
76 static CWimTrustSettingsStore* NewL(); |
|
77 |
|
78 /** |
|
79 * Destructor. |
|
80 */ |
|
81 virtual ~CWimTrustSettingsStore(); |
|
82 |
|
83 public: // New functions |
|
84 |
|
85 /** |
|
86 * Fetches trust settings for given certificate. |
|
87 * Acts like an asynchronous for caller but not activates itself. |
|
88 * @param aCert (IN) Certificate |
|
89 * @param aTrusted (OUT) Is certificate trusted |
|
90 * @param aApplications (OUT) Array of applications supported |
|
91 * by certificate |
|
92 * @param aStatus (IN/OUT) Request Status of asynchronous call |
|
93 * @return void |
|
94 */ |
|
95 void GetTrustSettings( const CWimCertInfo& aCert, |
|
96 TBool& aTrusted, |
|
97 RArray<TUid>& aApplications, |
|
98 TRequestStatus& aStatus ); |
|
99 |
|
100 /** |
|
101 * Set applicability for given certificate. Calls DoSetApplicabilityL, |
|
102 * which handles actual operation. New certificate entry is set if |
|
103 * one not found from database (trust flag is set to EFalse). |
|
104 * Acts like an asynchronous for caller but not activates itself. |
|
105 * @param aCert (IN) Certificate |
|
106 * @param aApplications (IN) Array of applications supported by |
|
107 * certificate |
|
108 * @param aStatus Request (IN/OUT) Status of asynchronous call. |
|
109 * @return void |
|
110 */ |
|
111 void SetApplicability( const CWimCertInfo& aCert, |
|
112 const RArray<TUid>& aApplications, |
|
113 TRequestStatus& aStatus ); |
|
114 |
|
115 /** |
|
116 * Set trust flag for given certificate. Calls DoSetTrustL, |
|
117 * which handles actual operation. New certificate entry is set if |
|
118 * one not found from database. |
|
119 * Acts like an asynchronous for caller but not activates itself. |
|
120 * @param aCert (IN) Certificate |
|
121 * @param aTrusted (IN) Is certificate trusted |
|
122 * @param aStatus (IN/OUT) Request Status of asynchronous call. |
|
123 * @return void |
|
124 */ |
|
125 void SetTrust( const CWimCertInfo& aCert, |
|
126 TBool aTrusted, |
|
127 TRequestStatus& aStatus ); |
|
128 |
|
129 /** |
|
130 * Set default trust settings for given certificate. If certificate not |
|
131 * found from database new entry is inserted. |
|
132 * Acts like an asynchronous for caller but not activate itself. |
|
133 * @param aCert (IN) Certificate |
|
134 * @param aAddApps (IN) Are default applications inserted |
|
135 * (ETrue means yes) |
|
136 * @param aStatus (IN/OUT) Request Status of asynchronous call |
|
137 * @return void |
|
138 */ |
|
139 void SetDefaultTrustSettings( const CWimCertInfo& aCert, |
|
140 TBool aAddApps, |
|
141 TRequestStatus& aStatus ); |
|
142 |
|
143 /** |
|
144 * Remove trust settings of given certificate. If certificate |
|
145 * is not found, return with status.Int() = KErrNotFound |
|
146 * Acts like an asynchronous for caller but not activates itself. |
|
147 * @param aCert (IN) Certificate |
|
148 * @param aStatus (IN/OUT) Request Status of asynchronous call |
|
149 * @return void |
|
150 */ |
|
151 void RemoveTrustSettings( const CWimCertInfo& aCert, |
|
152 TRequestStatus& aStatus ); |
|
153 |
|
154 /** |
|
155 * Delete TrustSettingsStore instance and release all resources |
|
156 * @return void |
|
157 */ |
|
158 void CloseD(); |
|
159 |
|
160 /** |
|
161 * Cancel any issued asynchronous call |
|
162 * @return void |
|
163 */ |
|
164 void CancelDoing(); |
|
165 |
|
166 private: |
|
167 |
|
168 /** |
|
169 * Default constructor. |
|
170 */ |
|
171 CWimTrustSettingsStore(); |
|
172 |
|
173 /** |
|
174 * 2nd phase constructor |
|
175 */ |
|
176 void ConstructL(); |
|
177 |
|
178 /** |
|
179 * Fetches trust settings for given certificate |
|
180 * @param aCert (IN) Certificate |
|
181 * @param aTrusted (OUT) Is certificate trusted |
|
182 * @param aApplications (OUT) Array of applications supported |
|
183 * by certificate |
|
184 * @return void |
|
185 */ |
|
186 void DoGetTrustSettingsL( const CWimCertInfo& aCert, |
|
187 TBool& aTrusted, |
|
188 RArray<TUid>& aApplications ); |
|
189 |
|
190 /** |
|
191 * Set applicability for given certificate. If certificate is not |
|
192 * allready in database insert new entry. |
|
193 * @param aCert (IN) Certificate |
|
194 * @param aTrusted (IN) Is certificate trusted |
|
195 * @param aApplications (IN) Array of applications supported |
|
196 * by certificate |
|
197 * @return void |
|
198 */ |
|
199 void DoSetApplicabilityL( const CWimCertInfo& aCert, |
|
200 const RArray<TUid>& aApplications ); |
|
201 |
|
202 /** |
|
203 * Set trust flag for given certificate. If certificate is not |
|
204 * allready in database insert new entry. |
|
205 * @param aCert (IN) Certificate |
|
206 * @param aTrusted (IN) Is certificate trusted |
|
207 * @return void |
|
208 */ |
|
209 void DoSetTrustL( const CWimCertInfo& aCert, |
|
210 TBool aTrusted ); |
|
211 |
|
212 /** |
|
213 * Set default trust settings for given certificate |
|
214 * @param aCert (IN) Certificate |
|
215 * @param aAddApps (IN) Are default applications inserted |
|
216 * (ETrue means yes) |
|
217 * @return void |
|
218 */ |
|
219 void DoSetDefaultTrustSettingsL( const CWimCertInfo& aCert, |
|
220 TBool aAddApps ); |
|
221 |
|
222 /** |
|
223 * Remove trust settings of given certificate. If certificate not |
|
224 * found, leave with error code KErrNotFound |
|
225 * @param aCert (IN) Certificate |
|
226 * @return void |
|
227 */ |
|
228 void DoRemoveTrustSettingsL( const CWimCertInfo& aCert ); |
|
229 |
|
230 /** |
|
231 * Get database ID for given certificate. |
|
232 * Returns certificate ID = KErrNotFound if matching ID not found. |
|
233 * @param aCert (IN) Certificate |
|
234 * @param aCertID (OUT) Certificate's database ID |
|
235 * @return void |
|
236 */ |
|
237 void GetCertificateIDL( const CWimCertInfo& aCert, |
|
238 TInt& aCertificateID ); |
|
239 |
|
240 /** |
|
241 * Insert certificate to Certificates table |
|
242 * @param aCert (IN) Certificate |
|
243 * @param aTrusted (IN) Is certificate trusted or not |
|
244 * @return void |
|
245 */ |
|
246 void InsertCertificateL( const CWimCertInfo& aCert, |
|
247 TBool aTrusted ); |
|
248 |
|
249 |
|
250 /** |
|
251 * Fetch certificates trusted flag |
|
252 * @param aCertificateID (IN) Certificate's database ID |
|
253 * @param aTrusted (OUT) Is certificate trusted or not |
|
254 * @return void |
|
255 */ |
|
256 void GetTrustedL( TInt aCertificateID, |
|
257 TBool& aTrusted ); |
|
258 |
|
259 /** |
|
260 * Set trusted flag for certificate |
|
261 * @param aCertificateID (IN) Certificate's database ID |
|
262 * @param aTrusted (IN) Is certificate trusted or not |
|
263 * @return void |
|
264 */ |
|
265 void SetTrustedL( TInt aCertificateID, |
|
266 TBool aTrusted ); |
|
267 /** |
|
268 * Remove certificate from Certificates table |
|
269 * @param aCertificateID (IN) Certificate's database ID |
|
270 * @return void |
|
271 */ |
|
272 void RemoveCertificateL( TInt aCertificateID ); |
|
273 |
|
274 /** |
|
275 * Remove all applications of given certificate |
|
276 * @param aCertificateID (IN) Certificate |
|
277 * @return void |
|
278 */ |
|
279 void RemoveApplicationsL( TInt aCertificateID ); |
|
280 |
|
281 /** |
|
282 * Get all applications of given certificate |
|
283 * @param aCertificateID (IN) Certificate's database ID |
|
284 * @param aApplications (OUT) Array of applications supported |
|
285 * by certificate |
|
286 * @return void |
|
287 */ |
|
288 void GetApplicationsL( TInt aCertificateID, |
|
289 RArray<TUid>& aApplications ); |
|
290 |
|
291 /** |
|
292 * Set applications for given certificate |
|
293 * @param aCertificateID (IN) Certificate database ID |
|
294 * @param aApplications (IN) Array of applications supported |
|
295 * by certificate |
|
296 * @return void |
|
297 */ |
|
298 void InsertApplicationsL( TInt aCertificateID, |
|
299 const RArray<TUid>& aApplications ); |
|
300 |
|
301 /** |
|
302 * Decide default applications for given certificate. |
|
303 * Default applications are decided regarding the certificate's: |
|
304 * - format |
|
305 * - extented usage data |
|
306 * - trusted usage data |
|
307 * @param aCert (IN) Certificate |
|
308 * @param aApplications (OUT) List of applications returned |
|
309 * @return void |
|
310 */ |
|
311 void DefaultApplicationsL( const CWimCertInfo& aCert, |
|
312 RArray<TUid>& aApplications ); |
|
313 |
|
314 /** |
|
315 * Decide default applications by OID's. |
|
316 * @param aCert (IN) Certificate |
|
317 * @param aApplications (OUT) List of applications returned |
|
318 * @return void |
|
319 */ |
|
320 void DefaultAppsByOIDsL( const CWimCertInfo& aCert, |
|
321 RArray<TUid>& aApplications ); |
|
322 |
|
323 /** |
|
324 * Create database. Leaves if error occurs. |
|
325 * @return void |
|
326 */ |
|
327 void CreateDBL() const; |
|
328 |
|
329 /** |
|
330 * Insert default appUid selection rules. Leaves if error occurs. |
|
331 * @return void |
|
332 */ |
|
333 void InsertDefaultAppRulesL() const; |
|
334 |
|
335 /** |
|
336 * Extracts certificate extensions. Leaves if error occurs. |
|
337 * @return void |
|
338 */ |
|
339 void ExtractExtensionL(); |
|
340 |
|
341 /** |
|
342 * Makes a SHA-1 hash of certificate label |
|
343 * @param aString (IN) String to be hashed |
|
344 * @return 8 bit string of label hash |
|
345 */ |
|
346 HBufC8* GetHashL( TDesC8& aString ); |
|
347 |
|
348 private: // From base class CActive |
|
349 |
|
350 /** |
|
351 * Handle asyncronous response |
|
352 * @return void |
|
353 */ |
|
354 void RunL(); |
|
355 |
|
356 /** |
|
357 * Handle asyncronous call cancel |
|
358 * @return void |
|
359 */ |
|
360 void DoCancel(); |
|
361 |
|
362 /** |
|
363 * Handles RunL function leaves |
|
364 * @param aError Leaving code. |
|
365 * @return TInt |
|
366 */ |
|
367 TInt RunError( TInt aError ); |
|
368 |
|
369 private: // Data |
|
370 |
|
371 enum TPhase |
|
372 { |
|
373 EIdle, |
|
374 ERetrieve, |
|
375 ECheckRestore, |
|
376 ECheckInitializeCertStore, |
|
377 ECheckRetrieve |
|
378 }; |
|
379 |
|
380 // The state of this active object |
|
381 TPhase iPhase; |
|
382 |
|
383 // Used for saving caller status. Not owned |
|
384 TRequestStatus* iOriginalRequestStatus; |
|
385 |
|
386 //Database session for WimTrustSettingsStore |
|
387 |
|
388 RFs iDBSession; |
|
389 |
|
390 //Database for WimTrustSettingsStore |
|
391 RDbNamedDatabase iDatabase; |
|
392 |
|
393 //Flag to tell if compact operation for dbhas to be done in destructor |
|
394 TBool iCompact; |
|
395 |
|
396 // For file session |
|
397 RFs iFs; |
|
398 |
|
399 // Pointer to CertUtil.Owned |
|
400 CWimCertUtil* iWimCertUtil; |
|
401 |
|
402 // Pointer to current wim specific certificate info |
|
403 const CWimCertInfo* iWimCert; |
|
404 |
|
405 // Pointer to current Symbian specific certificate info |
|
406 const CCTCertInfo* iCert; |
|
407 |
|
408 // Boolean indicating if default applications are added or not |
|
409 TBool iAddApps; |
|
410 |
|
411 // Pointer to whole certificate data buffer |
|
412 HBufC8* iEncodedCertBuf; |
|
413 |
|
414 // Pointer to certificate data buffer |
|
415 TPtr8* iEncodedCertPtr; |
|
416 |
|
417 // Temporal array for certificate infos. |
|
418 // This array is used to fetch certificate infos from WimClient. |
|
419 // Owned. |
|
420 RPointerArray<CWimCertInfo> iCertInfos; |
|
421 }; |
|
422 |
|
423 #endif // CWIMTRUSTSETTINGSSTORE_H |
|
424 |
|
425 // End of File |