|
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 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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CKeyStoreAuthObject.h" |
|
20 #include "cfskeystoreclient.h" |
|
21 #include <ct/logger.h> |
|
22 |
|
23 _LIT(KAuthObjectName, "Software key store authentication object"); |
|
24 |
|
25 CKeyStoreAuthObject* CKeyStoreAuthObject::NewL(CFSKeyStoreClient& aClient) |
|
26 { |
|
27 return new (ELeave) CKeyStoreAuthObject(aClient); |
|
28 } |
|
29 |
|
30 CKeyStoreAuthObject::CKeyStoreAuthObject(CFSKeyStoreClient& aClient) : |
|
31 MCTAuthenticationObject(aClient.Token()), |
|
32 iClient(aClient), |
|
33 iRefCount(0) |
|
34 { |
|
35 LOG1(_L("keystore auth object created, ref count == %d"), iRefCount); |
|
36 } |
|
37 |
|
38 void CKeyStoreAuthObject::AddRef() |
|
39 { |
|
40 ++iRefCount; |
|
41 |
|
42 LOG1(_L("keystore auth object referenced, ref count == %d"), iRefCount); |
|
43 LOG_INC_INDENT(); |
|
44 |
|
45 // The first reference is from the client object: don't reference the token |
|
46 // (it gets one reference "for free" when this object is created), or |
|
47 // reference the client (this would lead to circular reference) |
|
48 if (iRefCount != 1) |
|
49 { |
|
50 // Need to increment the token's reference count here as well as this is |
|
51 // automatically decremented by Release() |
|
52 AddTokenRef(); |
|
53 |
|
54 // This object depends on the client |
|
55 iClient.AddRef(); |
|
56 } |
|
57 |
|
58 LOG_DEC_INDENT(); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Implementation of reference counting. The superclass automatically calls |
|
63 * Release() on the token for us. |
|
64 */ |
|
65 void CKeyStoreAuthObject::DoRelease() |
|
66 { |
|
67 --iRefCount; |
|
68 |
|
69 LOG1(_L("keystore auth object released, ref count == %d"), iRefCount); |
|
70 LOG_INC_INDENT(); |
|
71 |
|
72 ASSERT(iRefCount >= 0); |
|
73 |
|
74 // The first reference is from the client, and didn't result in a call to |
|
75 // iClient.AddRef(), so don't try and release this |
|
76 if (iRefCount != 0) |
|
77 { |
|
78 iClient.Release(); |
|
79 } |
|
80 |
|
81 // No more references, call superclass to delete the object |
|
82 if (iRefCount == 0) |
|
83 { |
|
84 MCTTokenObject::DoRelease(); |
|
85 } |
|
86 |
|
87 LOG_DEC_INDENT(); |
|
88 } |
|
89 |
|
90 /** |
|
91 * Returns the object's human-readable label. |
|
92 */ |
|
93 const TDesC& CKeyStoreAuthObject::Label() const |
|
94 { |
|
95 return KAuthObjectName; |
|
96 } |
|
97 |
|
98 /** |
|
99 * Returns a reference to the associated token. |
|
100 */ |
|
101 MCTToken& CKeyStoreAuthObject::Token() const |
|
102 { |
|
103 return iClient.Token(); |
|
104 } |
|
105 |
|
106 /** |
|
107 * Gets the UID representing the type of the token object. |
|
108 */ |
|
109 TUid CKeyStoreAuthObject::Type() const |
|
110 { |
|
111 return KKeyStoreAuthObjectUID; |
|
112 } |
|
113 |
|
114 /** |
|
115 * Gets a handle for the object. |
|
116 */ |
|
117 TCTTokenObjectHandle CKeyStoreAuthObject::Handle() const |
|
118 { |
|
119 return TCTTokenObjectHandle(Token().Handle(), 0); |
|
120 } |
|
121 |
|
122 /** |
|
123 * Lists all keys useable or manageable by the calling process. |
|
124 */ |
|
125 void CKeyStoreAuthObject::ListProtectedObjects(RMPointerArray<MCTTokenObject>& aObjects, TRequestStatus& aStatus) |
|
126 { |
|
127 iClient.ListProtectedObjects(aObjects, aStatus); |
|
128 } |
|
129 |
|
130 void CKeyStoreAuthObject::CancelListProtectedObjects() |
|
131 { |
|
132 // Synchronous, no cancel |
|
133 } |
|
134 |
|
135 /** |
|
136 * Prompt the user to change the passphrase for all keys in the keystore. |
|
137 */ |
|
138 void CKeyStoreAuthObject::ChangeReferenceData(TRequestStatus &aStatus) |
|
139 { |
|
140 iClient.ChangeReferenceData(aStatus); |
|
141 } |
|
142 |
|
143 void CKeyStoreAuthObject::CancelChangeReferenceData() |
|
144 { |
|
145 iClient.CancelChangeReferenceData(); |
|
146 } |
|
147 |
|
148 /** |
|
149 * Prompt the user to enter the unblocking passphrase and unblock the store. |
|
150 */ |
|
151 void CKeyStoreAuthObject::Unblock(TRequestStatus &aStatus) |
|
152 { |
|
153 // Not supported |
|
154 TRequestStatus* status = &aStatus; |
|
155 User::RequestComplete(status, KErrNotSupported); |
|
156 } |
|
157 |
|
158 void CKeyStoreAuthObject::CancelUnblock() |
|
159 { |
|
160 // not supported, nothing to do |
|
161 } |
|
162 |
|
163 /** |
|
164 * Get the status of this auth object. |
|
165 */ |
|
166 TUint32 CKeyStoreAuthObject::Status() const |
|
167 { |
|
168 return iClient.AuthStatus(); |
|
169 } |
|
170 |
|
171 /** |
|
172 * Disabling this authentication object is not allowed, Disable() and |
|
173 * Enable() complete with KErrNotSupported. |
|
174 */ |
|
175 void CKeyStoreAuthObject::Disable(TRequestStatus &aStatus) |
|
176 { |
|
177 TRequestStatus* status = &aStatus; |
|
178 User::RequestComplete(status, KErrNotSupported); |
|
179 } |
|
180 |
|
181 void CKeyStoreAuthObject::CancelDisable() |
|
182 { |
|
183 } |
|
184 |
|
185 void CKeyStoreAuthObject::Enable(TRequestStatus &aStatus) |
|
186 { |
|
187 TRequestStatus* status = &aStatus; |
|
188 User::RequestComplete(status, KErrNotSupported); |
|
189 } |
|
190 |
|
191 void CKeyStoreAuthObject::CancelEnable() |
|
192 { |
|
193 } |
|
194 |
|
195 /** |
|
196 * Prompt the user to enter the passphrase and open the keystore for this |
|
197 * process. |
|
198 */ |
|
199 void CKeyStoreAuthObject::Open(TRequestStatus& aStatus) |
|
200 { |
|
201 iClient.AuthOpen(aStatus); |
|
202 } |
|
203 |
|
204 void CKeyStoreAuthObject::CancelOpen() |
|
205 { |
|
206 iClient.CancelAuthOpen(); |
|
207 } |
|
208 |
|
209 /** |
|
210 * Close the keystore. |
|
211 */ |
|
212 void CKeyStoreAuthObject::Close(TRequestStatus& aStatus) |
|
213 { |
|
214 iClient.AuthClose(aStatus); |
|
215 } |
|
216 |
|
217 void CKeyStoreAuthObject::CancelClose() |
|
218 { |
|
219 // Synchronous, no cancel |
|
220 } |
|
221 |
|
222 /** |
|
223 * Get time remaining for the keystore. |
|
224 */ |
|
225 void CKeyStoreAuthObject::TimeRemaining(TInt& aTime, TRequestStatus& aStatus) |
|
226 { |
|
227 iClient.TimeRemaining(aTime, aStatus); |
|
228 } |
|
229 |
|
230 void CKeyStoreAuthObject::CancelTimeRemaining() |
|
231 { |
|
232 // Synchronous, no cancel |
|
233 } |
|
234 |
|
235 /** |
|
236 * Set the timeout for the keystore. |
|
237 */ |
|
238 void CKeyStoreAuthObject::SetTimeout(TInt aTime, TRequestStatus& aStatus) |
|
239 { |
|
240 iClient.SetTimeout(aTime, aStatus); |
|
241 } |
|
242 |
|
243 void CKeyStoreAuthObject::CancelSetTimeout() |
|
244 { |
|
245 // Synchronous, no cancel |
|
246 } |
|
247 |
|
248 /** |
|
249 * Get the current timeout for the keystore. |
|
250 */ |
|
251 void CKeyStoreAuthObject::Timeout(TInt& aTime, TRequestStatus& aStatus) |
|
252 { |
|
253 iClient.Timeout(aTime, aStatus); |
|
254 } |
|
255 |
|
256 void CKeyStoreAuthObject::CancelTimeout() |
|
257 { |
|
258 // Synchronous, no cancel |
|
259 } |