1 /* |
|
2 * Copyright (c) 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 <bautils.h> |
|
20 #include <s32file.h> |
|
21 #include <test/testexecutelog.h> |
|
22 |
|
23 #include "authserver/authmgrclient.h" |
|
24 #include "authserver/authclient.h" |
|
25 #include "authserver/identity.h" |
|
26 #include "tAuthSvrStep.h" |
|
27 |
|
28 using namespace AuthServer; |
|
29 |
|
30 class CActiveObj : public CActive |
|
31 { |
|
32 public: |
|
33 CActiveObj(RAuthMgrClient& aClient, CAuthExpression* aExpression, |
|
34 TInt aFresh, TBool aClientSpecific, TUid aClientSid, TBool aIdentityString, TPluginId aPluginId, TIdentityId aId) : |
|
35 CActive(EPriorityNormal), |
|
36 iClient(aClient), |
|
37 iResult(EFail), |
|
38 iRunCount(0), |
|
39 iAe(aExpression), |
|
40 iFresh(aFresh), |
|
41 iClientSpecific(aClientSpecific), |
|
42 iWithString(aIdentityString), |
|
43 iPluginId(aPluginId), |
|
44 iId(aId), |
|
45 iMode(-1) |
|
46 { |
|
47 CActiveScheduler::Add(this); |
|
48 iClientSid = aClientSid; |
|
49 } |
|
50 |
|
51 void Authenticate() |
|
52 { |
|
53 SetActive(); |
|
54 TRequestStatus* status = &iStatus; |
|
55 User::RequestComplete(status, KErrNone); |
|
56 iRunCount = 0; |
|
57 iMode = 0; |
|
58 } |
|
59 |
|
60 void Retrain() |
|
61 { |
|
62 SetActive(); |
|
63 TRequestStatus* status = &iStatus; |
|
64 User::RequestComplete(status, KErrNone); |
|
65 iRunCount = 0; |
|
66 iMode = 1; |
|
67 } |
|
68 |
|
69 void DoCancel() |
|
70 { |
|
71 } |
|
72 |
|
73 TInt RunError(TInt aError) |
|
74 { |
|
75 iErr = aError; |
|
76 CActiveScheduler::Stop(); |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 void RunL() |
|
81 { |
|
82 switch (iRunCount) |
|
83 { |
|
84 case 0: |
|
85 |
|
86 switch (iMode) |
|
87 { |
|
88 |
|
89 case 0: |
|
90 iClient.AuthenticateL(*iAe, iFresh, iClientSpecific, iClientSid, EFalse, KNullDesC(), iIdentity, iStatus); |
|
91 break; |
|
92 |
|
93 case 1: |
|
94 iClient.TrainPlugin(iId, iPluginId, iStatus); |
|
95 break; |
|
96 } |
|
97 |
|
98 SetActive(); |
|
99 break; |
|
100 |
|
101 case 1: |
|
102 |
|
103 iResult = iStatus.Int() == KErrNone ? EPass : EFail; |
|
104 iErr = iStatus.Int(); |
|
105 CActiveScheduler::Stop(); |
|
106 break; |
|
107 |
|
108 default: |
|
109 iResult = EFail; |
|
110 CActiveScheduler::Stop(); |
|
111 |
|
112 } |
|
113 ++iRunCount; |
|
114 } |
|
115 |
|
116 ~CActiveObj() |
|
117 { |
|
118 |
|
119 } |
|
120 |
|
121 RAuthMgrClient& iClient; |
|
122 TVerdict iResult; |
|
123 TInt iRunCount; |
|
124 CAuthExpression* iAe; |
|
125 CIdentity* iIdentity; |
|
126 TInt iErr; |
|
127 TInt iFresh; |
|
128 TBool iClientSpecific; |
|
129 TBool iWithString; |
|
130 TPluginId iPluginId; |
|
131 TIdentityId iId; |
|
132 TInt iMode; |
|
133 TUid iClientSid; |
|
134 }; |
|
135 |
|
136 |
|
137 CTStepClientSidSupport::CTStepClientSidSupport(CTAuthSvrServer& aParent): iParent(aParent) |
|
138 { |
|
139 SetTestStepName(KTStepClientSidSupportCheck); |
|
140 } |
|
141 |
|
142 TVerdict CTStepClientSidSupport::doTestStepPreambleL() |
|
143 { |
|
144 SetTestStepResult(EFail); |
|
145 |
|
146 CTStepActSch::doTestStepPreambleL(); |
|
147 |
|
148 if(GetHexFromConfig(ConfigSection(),_L("plugin1Id"), iPluginId) == EFalse) |
|
149 { |
|
150 INFO_PRINTF1(_L("Plugin Id not specified in the ini file")); |
|
151 return TestStepResult(); |
|
152 } |
|
153 |
|
154 if(GetBoolFromConfig(ConfigSection(),_L("clientSpecificKey"), iClientSpecificKey) == EFalse) |
|
155 { |
|
156 INFO_PRINTF1(_L("Client Specific Key not specified in the ini file")); |
|
157 return TestStepResult(); |
|
158 } |
|
159 |
|
160 if(GetBoolFromConfig(ConfigSection(),_L("withString"), iWithString) == EFalse) |
|
161 { |
|
162 INFO_PRINTF1(_L("Identity String not specified in the ini file")); |
|
163 return TestStepResult(); |
|
164 } |
|
165 |
|
166 TInt clientSid = 0; |
|
167 if(GetHexFromConfig(ConfigSection(),_L("clientSid"), clientSid) == EFalse) |
|
168 { |
|
169 INFO_PRINTF1(_L("Client Sid not specified in the ini file")); |
|
170 return TestStepResult(); |
|
171 } |
|
172 |
|
173 iClientSid.iUid = clientSid; |
|
174 |
|
175 |
|
176 SetTestStepResult(EPass); |
|
177 return TestStepResult(); |
|
178 } |
|
179 |
|
180 TVerdict CTStepClientSidSupport::doTestStepL() |
|
181 { |
|
182 SetTestStepResult(EFail); |
|
183 |
|
184 InitAuthServerFromFileL(); // Set things like 'iSupportsDefaultData' and 'DefaultPlugin' |
|
185 |
|
186 CActiveScheduler::Install(iActSchd); |
|
187 |
|
188 //Connect to the AuthServer |
|
189 AuthServer::RAuthMgrClient authMgrClient1; |
|
190 TInt connectVal = authMgrClient1.Connect(); |
|
191 CleanupClosePushL(authMgrClient1); |
|
192 |
|
193 TPtrC exprString; |
|
194 if(GetStringFromConfig(ConfigSection(),_L("plugin1Id"), exprString) == EFalse) |
|
195 { |
|
196 INFO_PRINTF1(_L("Plugin Id not specified in the ini file")); |
|
197 return TestStepResult(); |
|
198 } |
|
199 |
|
200 CAuthExpression* authExpr = CreateAuthExprLC(exprString); |
|
201 CActiveObj active1(authMgrClient1, authExpr, 20, iClientSpecificKey, iClientSid, iWithString, iPluginId, 0); |
|
202 active1.Authenticate(); |
|
203 CActiveScheduler::Start(); |
|
204 |
|
205 if(EPass != active1.iResult) |
|
206 { |
|
207 ERR_PRINTF3(_L("Authentication Result error = %d, iResult = %d\n"), active1.iErr, active1.iResult); |
|
208 SetTestStepError(active1.iErr); |
|
209 CleanupStack::PopAndDestroy(2, &authMgrClient1); |
|
210 return TestStepResult(); |
|
211 } |
|
212 |
|
213 iIdentity = active1.iIdentity; |
|
214 CleanupStack::PushL(iIdentity); |
|
215 TIdentityId identityId = iIdentity->Id(); |
|
216 |
|
217 // set plugin input train value. |
|
218 InitPluginDataFromFileL(ETrue); |
|
219 |
|
220 CActiveObj active2(authMgrClient1, authExpr, 0, iClientSpecificKey, iClientSid, iWithString, iPluginId, identityId); |
|
221 active2.Retrain(); |
|
222 CActiveScheduler::Start(); |
|
223 |
|
224 if(EPass != active1.iResult) |
|
225 { |
|
226 ERR_PRINTF3(_L("Error encountered while training plugin = %d, iResult = %d\n"), active2.iErr, active2.iResult); |
|
227 SetTestStepError(active2.iErr); |
|
228 CleanupStack::PopAndDestroy(3, &authMgrClient1); |
|
229 return TestStepResult(); |
|
230 } |
|
231 |
|
232 // set plugin inputId value. |
|
233 InitPluginDataFromFileL(EFalse); |
|
234 |
|
235 CActiveObj active3(authMgrClient1, authExpr, 20, iClientSpecificKey, iClientSid, iWithString, iPluginId, 0); |
|
236 active3.Authenticate(); |
|
237 CActiveScheduler::Start(); |
|
238 |
|
239 CleanupStack::Pop(iIdentity); |
|
240 CleanupStack::PopAndDestroy(2, &authMgrClient1); |
|
241 |
|
242 if(EPass != active1.iResult) |
|
243 { |
|
244 ERR_PRINTF3(_L("Authentication Result error = %d, iResult = %d\n"), active3.iErr, active3.iResult); |
|
245 SetTestStepError(active3.iErr); |
|
246 delete iIdentity; |
|
247 return TestStepResult(); |
|
248 } |
|
249 |
|
250 iIdentityAfterRetrain = active3.iIdentity; |
|
251 |
|
252 TBool success = VerifyObtainedResultsWithExpectedL(); |
|
253 if(success) |
|
254 { |
|
255 SetTestStepResult(EPass); |
|
256 } |
|
257 |
|
258 return TestStepResult(); |
|
259 }; |
|
260 |
|
261 TBool CTStepClientSidSupport::VerifyObtainedResultsWithExpectedL() |
|
262 { |
|
263 // required for ReadUserData capability test(when client sid is not equal |
|
264 // to the calling application's sid or zero, ReadUserData is required for |
|
265 // authentication.) |
|
266 if(iClientSid.iUid == 0) |
|
267 { |
|
268 TInt clientSid; |
|
269 if(GetHexFromConfig(ConfigSection(),_L("callingAppSid"), clientSid) == EFalse) |
|
270 { |
|
271 INFO_PRINTF1(_L("Sid of calling application not specified in the ini file")); |
|
272 return TestStepResult(); |
|
273 } |
|
274 |
|
275 iClientSid.iUid = clientSid; |
|
276 } |
|
277 |
|
278 CProtectionKey* protection = iIdentity->Key().ClientKeyL(iClientSid.iUid); |
|
279 |
|
280 const CProtectionKey& obtainedKey = iIdentityAfterRetrain->Key(); |
|
281 TBool success = EFalse; |
|
282 if(protection->KeyData() == obtainedKey.KeyData()) |
|
283 { |
|
284 success = ETrue; |
|
285 } |
|
286 |
|
287 return success; |
|
288 } |
|
289 |
|
290 CTStepClientSidSupport::~CTStepClientSidSupport() |
|
291 { |
|
292 delete iIdentity; |
|
293 delete iIdentityAfterRetrain; |
|
294 } |
|