|
1 /* |
|
2 * Copyright (c) 2008 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: A class that provides logon and logoff functionality. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <unifiedkeystore.h> |
|
20 #include <mctauthobject.h> |
|
21 |
|
22 #include "logonservices.h" |
|
23 #include "pkidefs.h" |
|
24 #include "pkiserviceassert.h" |
|
25 #include "pkiserviceconstants.h" |
|
26 |
|
27 CLogonServices* CLogonServices::NewL(CUnifiedKeyStore& aUnifiedKeyStore) |
|
28 { |
|
29 CLogonServices* self = new (ELeave) CLogonServices(aUnifiedKeyStore); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 |
|
34 return self; |
|
35 } |
|
36 |
|
37 |
|
38 CLogonServices::CLogonServices(CUnifiedKeyStore& aUnifiedKeyStore) |
|
39 :CActive(EPriorityStandard), iUnifiedKeyStore(aUnifiedKeyStore) |
|
40 { |
|
41 CActiveScheduler::Add(this); |
|
42 } |
|
43 |
|
44 |
|
45 void CLogonServices::ConstructL() |
|
46 { |
|
47 } |
|
48 |
|
49 |
|
50 CLogonServices::~CLogonServices() |
|
51 { |
|
52 Cancel(); |
|
53 } |
|
54 |
|
55 |
|
56 void CLogonServices::Logon(TRequestStatus& aClientStatus) |
|
57 { |
|
58 PKISERVICE_ASSERT(iState == ELogonServiceIdle); |
|
59 iState = ELogonServiceListingKeys; |
|
60 |
|
61 iClientStatus = &aClientStatus; |
|
62 *iClientStatus = KRequestPending; |
|
63 |
|
64 if (iAuthenticationObject == NULL) |
|
65 { |
|
66 //First find the User key store |
|
67 TInt keyStoreCount = iUnifiedKeyStore.KeyStoreManagerCount(); |
|
68 TInt i = 0; |
|
69 for (i = 0; i < keyStoreCount; ++i) |
|
70 { |
|
71 MCTKeyStoreManager& keyStore = iUnifiedKeyStore.KeyStoreManager(i); |
|
72 if (keyStore.Token().TokenType().Type().iUid == STORETYPE_USER_KEY_ID) |
|
73 { |
|
74 iUserKeyStore = &keyStore; |
|
75 TCTKeyAttributeFilter filter; |
|
76 iUserKeyStore->List(iKeysList, filter, iStatus); |
|
77 SetActive(); |
|
78 break; |
|
79 } |
|
80 } |
|
81 |
|
82 if (i == keyStoreCount) |
|
83 { |
|
84 iStatus = KRequestPending; |
|
85 SetActive(); |
|
86 |
|
87 TRequestStatus* ownStatus = &iStatus; |
|
88 User::RequestComplete(ownStatus, KPKIErrNotSupported); |
|
89 } |
|
90 } |
|
91 else |
|
92 { |
|
93 //Logon already done |
|
94 iState = ELogonServiceAlreadyLoggedIn; |
|
95 |
|
96 iStatus = KRequestPending; |
|
97 SetActive(); |
|
98 |
|
99 TRequestStatus* ownStatus = &iStatus; |
|
100 User::RequestComplete(ownStatus, KErrNone); |
|
101 } |
|
102 } |
|
103 |
|
104 |
|
105 void CLogonServices::Logoff(TRequestStatus& aClientStatus) |
|
106 { |
|
107 PKISERVICE_ASSERT(iState == ELogonServiceIdle); |
|
108 iState = ELogonServiceClosingAuthentication; |
|
109 |
|
110 iClientStatus = &aClientStatus; |
|
111 *iClientStatus = KRequestPending; |
|
112 |
|
113 if (iAuthenticationObject != NULL) |
|
114 { |
|
115 iAuthenticationObject->Close(iStatus); |
|
116 SetActive(); |
|
117 } |
|
118 else |
|
119 { |
|
120 iStatus = KRequestPending; |
|
121 SetActive(); |
|
122 |
|
123 TRequestStatus* ownStatus = &iStatus; |
|
124 User::RequestComplete(ownStatus, KErrNone); |
|
125 } |
|
126 } |
|
127 |
|
128 |
|
129 void CLogonServices::SetAuthenticationObject(MCTAuthenticationObject* aAuthenticationObject) |
|
130 { |
|
131 if (iAuthenticationObject == NULL) |
|
132 { |
|
133 iAuthenticationObject = aAuthenticationObject; |
|
134 } |
|
135 } |
|
136 |
|
137 |
|
138 void CLogonServices::ChangePassword(TRequestStatus& aClientStatus) |
|
139 { |
|
140 PKISERVICE_ASSERT(iState == ELogonServiceIdle); |
|
141 PKISERVICE_ASSERT(LogonCompleted()); |
|
142 |
|
143 iState = ELogonServiceChangingPassword; |
|
144 iClientStatus = &aClientStatus; |
|
145 *iClientStatus = KRequestPending; |
|
146 |
|
147 iAuthenticationObject->ChangeReferenceData(iStatus); |
|
148 SetActive(); |
|
149 } |
|
150 |
|
151 |
|
152 void CLogonServices::RunL() |
|
153 { |
|
154 if (iStatus.Int() == KErrNone) |
|
155 { |
|
156 switch(iState) |
|
157 { |
|
158 case ELogonServiceAlreadyLoggedIn: |
|
159 iState = ELogonServiceIdle; |
|
160 User::RequestComplete(iClientStatus, KErrNone); |
|
161 break; |
|
162 case ELogonServiceListingKeys: |
|
163 iState = ELogonServiceIdle; |
|
164 if (iKeysList.Count() > 0) |
|
165 { |
|
166 iState = ELogonServiceOpeningAuthentication; |
|
167 |
|
168 CCTKeyInfo* keyInfo = iKeysList[0]; |
|
169 iAuthenticationObject = keyInfo->Protector(); |
|
170 iAuthenticationObject->Open(iStatus); |
|
171 SetActive(); |
|
172 } |
|
173 else |
|
174 { |
|
175 Cleanup(); |
|
176 User::RequestComplete(iClientStatus, KPKIErrKeyStoreEmpty); |
|
177 } |
|
178 break; |
|
179 case ELogonServiceOpeningAuthentication: |
|
180 iState = ELogonServiceIdle; |
|
181 Cleanup(); |
|
182 User::RequestComplete(iClientStatus, KErrNone); |
|
183 break; |
|
184 case ELogonServiceClosingAuthentication: |
|
185 iState = ELogonServiceIdle; |
|
186 iAuthenticationObject = NULL; |
|
187 User::RequestComplete(iClientStatus, KErrNone); |
|
188 break; |
|
189 case ELogonServiceChangingPassword: |
|
190 iState = ELogonServiceIdle; |
|
191 User::RequestComplete(iClientStatus, KErrNone); |
|
192 break; |
|
193 default: |
|
194 PKISERVICE_INVARIANT(); |
|
195 break; |
|
196 } |
|
197 |
|
198 } |
|
199 else |
|
200 { |
|
201 Cleanup(); |
|
202 iState = ELogonServiceIdle; |
|
203 User::RequestComplete(iClientStatus, iStatus.Int()); |
|
204 } |
|
205 } |
|
206 |
|
207 |
|
208 void CLogonServices::DoCancel() |
|
209 { |
|
210 switch(iState) |
|
211 { |
|
212 case ELogonServiceListingKeys: |
|
213 iUserKeyStore->CancelList(); |
|
214 break; |
|
215 case ELogonServiceOpeningAuthentication: |
|
216 iAuthenticationObject->CancelOpen(); |
|
217 iAuthenticationObject = NULL; |
|
218 break; |
|
219 case ELogonServiceClosingAuthentication: |
|
220 if (iAuthenticationObject != NULL) |
|
221 { |
|
222 iAuthenticationObject->CancelClose(); |
|
223 iAuthenticationObject = NULL; |
|
224 } |
|
225 //else do nothing |
|
226 break; |
|
227 case ELogonServiceChangingPassword: |
|
228 iAuthenticationObject->CancelChangeReferenceData(); |
|
229 break; |
|
230 default: |
|
231 PKISERVICE_INVARIANT(); |
|
232 break; |
|
233 } |
|
234 |
|
235 Cleanup(); |
|
236 iState = ELogonServiceIdle; |
|
237 User::RequestComplete(iClientStatus, KErrCancel); |
|
238 } |
|
239 |
|
240 |
|
241 void CLogonServices::Cleanup() |
|
242 { |
|
243 iKeysList.Close(); |
|
244 } |
|
245 |
|
246 |
|
247 TBool CLogonServices::LogonCompleted() const |
|
248 { |
|
249 if (iState == ELogonServiceIdle && |
|
250 iAuthenticationObject != NULL) |
|
251 { |
|
252 return ETrue; |
|
253 } |
|
254 else |
|
255 { |
|
256 return EFalse; |
|
257 } |
|
258 } |