|
1 /* |
|
2 * Copyright (c) 2005-2010 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: Implementation of the CSecModUISyncWrapper class |
|
15 * Implements a synchronous wrapper for easier use of Symbian's |
|
16 * Security Frameworks's API's. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "cpsecmodsyncwrapper.h" |
|
22 #include <ct/ccttokentypeinfo.h> |
|
23 #include <ct/mcttokentype.h> |
|
24 #include <ct/ccttokentype.h> |
|
25 #include <ct/tcttokenobjecthandle.h> |
|
26 #include <mctauthobject.h> |
|
27 #include <unifiedkeystore.h> |
|
28 #include <mctkeystore.h> |
|
29 |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CSecModUISyncWrapper::CSecModUISyncWrapper() |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CSecModUISyncWrapper::CSecModUISyncWrapper() : CActive( EPriorityStandard ) |
|
41 { |
|
42 CActiveScheduler::Add(this); |
|
43 } |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CSecModUISyncWrapper::NewLC |
|
48 // Two-phased constructor. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CSecModUISyncWrapper* CSecModUISyncWrapper::NewLC() |
|
52 { |
|
53 CSecModUISyncWrapper* wrap = new (ELeave) CSecModUISyncWrapper(); |
|
54 CleanupStack::PushL(wrap); |
|
55 return wrap; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CSecModUISyncWrapper::NewL |
|
60 // Two-phased constructor. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CSecModUISyncWrapper* CSecModUISyncWrapper::NewL() |
|
64 { |
|
65 CSecModUISyncWrapper* wrap = CSecModUISyncWrapper::NewLC(); |
|
66 CleanupStack::Pop(wrap); |
|
67 return wrap; |
|
68 } |
|
69 |
|
70 // Destructor |
|
71 CSecModUISyncWrapper::~CSecModUISyncWrapper() |
|
72 { |
|
73 Cancel(); |
|
74 iOperation = EOperationNone; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CSecModUISyncWrapper::Initialize(CUnifiedKeyStore& aKeyStore) |
|
79 // Two-phased constructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 |
|
83 TInt CSecModUISyncWrapper::Initialize(CUnifiedKeyStore& aKeyStore) |
|
84 { |
|
85 if( !IsActive() && !iWait.IsStarted() ) |
|
86 { |
|
87 iOperation = EOperationInit; |
|
88 iObject = STATIC_CAST(TAny*, &aKeyStore); |
|
89 aKeyStore.Initialize(iStatus); |
|
90 SetActive(); |
|
91 iWait.Start(); |
|
92 iOperation = EOperationNone; |
|
93 return iStatus.Int(); |
|
94 } |
|
95 return KErrInUse; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CSecModUIModel::GetAuthObjectInterface(...) |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 TInt CSecModUISyncWrapper::GetAuthObjectInterface( |
|
103 MCTToken& aToken, MCTTokenInterface*& aTokenInterface) |
|
104 { |
|
105 if( !IsActive() && !iWait.IsStarted() ) |
|
106 { |
|
107 iOperation = EOperationGetAOInterface; |
|
108 iObject = STATIC_CAST(TAny*, &aToken); |
|
109 const TUid KUidInterfaceAO = { KCTInterfaceAuthenticationObject }; |
|
110 aToken.GetInterface(KUidInterfaceAO, aTokenInterface, iStatus); |
|
111 iOperation = EOperationGetAOInterface; |
|
112 SetActive(); |
|
113 iWait.Start(); |
|
114 iOperation = EOperationNone; |
|
115 return iStatus.Int(); |
|
116 } |
|
117 return KErrInUse; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CSecModUISyncWrapper::ListAuthObjects(...) |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CSecModUISyncWrapper::ListAuthObjects( |
|
125 MCTAuthenticationObjectList& aAuthObjList, |
|
126 RMPointerArray<MCTAuthenticationObject>& aAuthObjects) |
|
127 { |
|
128 if( !IsActive() && !iWait.IsStarted() ) |
|
129 { |
|
130 iOperation = EOperationListAOs; |
|
131 iObject = STATIC_CAST(TAny*, &aAuthObjList); |
|
132 aAuthObjList.List( aAuthObjects, iStatus ); |
|
133 iOperation = EOperationListAOs; |
|
134 SetActive(); |
|
135 iWait.Start(); |
|
136 iOperation = EOperationNone; |
|
137 return iStatus.Int(); |
|
138 } |
|
139 return KErrInUse; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CSecModUISyncWrapper::ListKeys(...) |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CSecModUISyncWrapper::ListKeys( |
|
147 MCTKeyStore& aKeyStore, |
|
148 RMPointerArray<CCTKeyInfo>& aKeysInfos, |
|
149 const TCTKeyAttributeFilter& aFilter) |
|
150 { |
|
151 if( !IsActive() && !iWait.IsStarted() ) |
|
152 { |
|
153 iOperation = EOperationListKeys; |
|
154 iObject = STATIC_CAST(TAny*, &aKeyStore); |
|
155 aKeyStore.List(aKeysInfos, aFilter, iStatus); |
|
156 SetActive(); |
|
157 iWait.Start(); |
|
158 iOperation = EOperationNone; |
|
159 return iStatus.Int(); |
|
160 } |
|
161 return KErrInUse; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CSecModUISyncWrapper::DeleteKey(...) |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CSecModUISyncWrapper::DeleteKey( |
|
169 CUnifiedKeyStore& aKeyStore, |
|
170 TCTTokenObjectHandle aHandle) |
|
171 { |
|
172 if( !IsActive() && !iWait.IsStarted() ) |
|
173 { |
|
174 iOperation = EOperationDelKey; |
|
175 iObject = STATIC_CAST(TAny*, &aKeyStore); |
|
176 aKeyStore.DeleteKey(aHandle, iStatus); |
|
177 SetActive(); |
|
178 iWait.Start(); |
|
179 iOperation = EOperationNone; |
|
180 return iStatus.Int(); |
|
181 } |
|
182 return KErrInUse; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CSecModUISyncWrapper::ChangeReferenceData(MCTAuthenticationObject& aAuthObject) |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CSecModUISyncWrapper::ChangeReferenceData( |
|
190 MCTAuthenticationObject& aAuthObject) |
|
191 { |
|
192 if( !IsActive() && !iWait.IsStarted() ) |
|
193 { |
|
194 iOperation = EOperationChangeReferenceData; |
|
195 iObject = STATIC_CAST(TAny*, &aAuthObject); |
|
196 aAuthObject.ChangeReferenceData(iStatus); |
|
197 SetActive(); |
|
198 iWait.Start(); |
|
199 iOperation = EOperationNone; |
|
200 return iStatus.Int(); |
|
201 } |
|
202 return KErrInUse; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CSecModUIModel::UnblockAuthObject(MCTAuthenticationObject& aAuthObject) |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CSecModUISyncWrapper::UnblockAuthObject( |
|
210 MCTAuthenticationObject& aAuthObject) |
|
211 { |
|
212 if( !IsActive() && !iWait.IsStarted() ) |
|
213 { |
|
214 iOperation = EOperationUnblockAO; |
|
215 iObject = STATIC_CAST(TAny*, &aAuthObject); |
|
216 aAuthObject.Unblock(iStatus); |
|
217 SetActive(); |
|
218 iWait.Start(); |
|
219 iOperation = EOperationNone; |
|
220 return iStatus.Int(); |
|
221 } |
|
222 return KErrInUse; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CSecModUIModel::EnableAuthObject(MCTAuthenticationObject& aAuthObject) |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TInt CSecModUISyncWrapper::EnableAuthObject( |
|
230 MCTAuthenticationObject& aAuthObject) |
|
231 { |
|
232 if( !IsActive() && !iWait.IsStarted() ) |
|
233 { |
|
234 iOperation = EOperationEnableAO; |
|
235 iObject = STATIC_CAST(TAny*, &aAuthObject); |
|
236 aAuthObject.Enable(iStatus); |
|
237 iOperation = EOperationUnblockAO; |
|
238 SetActive(); |
|
239 iWait.Start(); |
|
240 iOperation = EOperationNone; |
|
241 return iStatus.Int(); |
|
242 } |
|
243 return KErrInUse; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CSecModUIModel::DisableAuthObject(MCTAuthenticationObject& aAuthObject) |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 TInt CSecModUISyncWrapper::DisableAuthObject( |
|
251 MCTAuthenticationObject& aAuthObject) |
|
252 { |
|
253 if( !IsActive() && !iWait.IsStarted() ) |
|
254 { |
|
255 iOperation = EOperationDisableAO; |
|
256 iObject = STATIC_CAST(TAny*, &aAuthObject); |
|
257 aAuthObject.Disable(iStatus); |
|
258 SetActive(); |
|
259 iWait.Start(); |
|
260 iOperation = EOperationNone; |
|
261 return iStatus.Int(); |
|
262 } |
|
263 return KErrInUse; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CSecModUISyncWrapper::CloseAuthObject(MCTAuthenticationObject& aAuthObject) |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 TInt CSecModUISyncWrapper::CloseAuthObject( |
|
271 MCTAuthenticationObject& aAuthObject) |
|
272 { |
|
273 if( !IsActive() && !iWait.IsStarted() ) |
|
274 { |
|
275 iOperation = EOperationCloseAO; |
|
276 iObject = STATIC_CAST(TAny*, &aAuthObject); |
|
277 aAuthObject.Close(iStatus); |
|
278 SetActive(); |
|
279 iWait.Start(); |
|
280 iOperation = EOperationNone; |
|
281 return iStatus.Int(); |
|
282 } |
|
283 return KErrInUse; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CSecModUIModel::TimeRemaining(...) |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 TInt CSecModUISyncWrapper::TimeRemaining( |
|
291 MCTAuthenticationObject& aAuthObject, |
|
292 TInt& aStime ) |
|
293 { |
|
294 if( !IsActive() && !iWait.IsStarted() ) |
|
295 { |
|
296 iOperation = EOperationTimeRemAO; |
|
297 iObject = STATIC_CAST(TAny*, &aAuthObject); |
|
298 aAuthObject.TimeRemaining(aStime, iStatus); |
|
299 SetActive(); |
|
300 iWait.Start(); |
|
301 iOperation = EOperationNone; |
|
302 return iStatus.Int(); |
|
303 } |
|
304 return KErrInUse; |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CSecModUISyncWrapper::DoCancel |
|
309 // Cancels the ongoing operation if possible. |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CSecModUISyncWrapper::DoCancel() |
|
313 { |
|
314 switch ( iOperation ) |
|
315 { |
|
316 case EOperationInit: |
|
317 { |
|
318 STATIC_CAST(CUnifiedKeyStore*, iObject)->CancelInitialize(); |
|
319 break; |
|
320 } |
|
321 case EOperationGetAOInterface: |
|
322 { |
|
323 STATIC_CAST(MCTToken*, iObject)->CancelGetInterface(); |
|
324 break; |
|
325 } |
|
326 case EOperationListAOs: |
|
327 { |
|
328 STATIC_CAST(MCTAuthenticationObjectList*, iObject)->CancelList(); |
|
329 break; |
|
330 } |
|
331 case EOperationListKeys: |
|
332 { |
|
333 STATIC_CAST(MCTKeyStore*, iObject)->CancelList(); |
|
334 break; |
|
335 } |
|
336 case EOperationDelKey: |
|
337 { |
|
338 STATIC_CAST(CUnifiedKeyStore*, iObject)->CancelDeleteKey(); |
|
339 break; |
|
340 } |
|
341 case EOperationChangeReferenceData: |
|
342 { |
|
343 STATIC_CAST(MCTAuthenticationObject*, iObject)-> |
|
344 CancelChangeReferenceData(); |
|
345 break; |
|
346 } |
|
347 case EOperationUnblockAO: |
|
348 { |
|
349 STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelUnblock(); |
|
350 break; |
|
351 } |
|
352 case EOperationEnableAO: |
|
353 { |
|
354 STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelEnable(); |
|
355 break; |
|
356 } |
|
357 case EOperationDisableAO: |
|
358 { |
|
359 STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelDisable(); |
|
360 break; |
|
361 } |
|
362 case EOperationCloseAO: |
|
363 { |
|
364 STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelClose(); |
|
365 break; |
|
366 } |
|
367 case EOperationTimeRemAO: |
|
368 { |
|
369 STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelTimeRemaining(); |
|
370 break; |
|
371 } |
|
372 default: |
|
373 { |
|
374 break; |
|
375 } |
|
376 } |
|
377 if (iWait.IsStarted()) |
|
378 { |
|
379 iWait.AsyncStop(); |
|
380 } |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CSecModUISyncWrapper::RunL |
|
385 // If no errors happened, stop. Show an error note if needed. |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 void CSecModUISyncWrapper::RunL() |
|
389 { |
|
390 iWait.AsyncStop(); |
|
391 } |
|
392 |