sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <unifiedkeystore.h>
|
sl@0
|
20 |
#include <e32base.h>
|
sl@0
|
21 |
#include "t_keystore_actions.h"
|
sl@0
|
22 |
#include "t_keystore_defs.h"
|
sl@0
|
23 |
#include "t_input.h"
|
sl@0
|
24 |
#include "t_output.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
const TInt KKeyStoreEmpty = -1199;
|
sl@0
|
27 |
_LIT(KEllipsis, "...");
|
sl@0
|
28 |
|
sl@0
|
29 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
30 |
// CAuthenticationPolicy
|
sl@0
|
31 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
32 |
|
sl@0
|
33 |
CTestAction* CAuthenticationPolicy::NewL(RFs& aFs,
|
sl@0
|
34 |
CConsoleBase& aConsole,
|
sl@0
|
35 |
Output& aOut,
|
sl@0
|
36 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
CTestAction* self = CAuthenticationPolicy::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
39 |
CleanupStack::Pop(self);
|
sl@0
|
40 |
return self;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
CTestAction* CAuthenticationPolicy::NewLC(RFs& aFs,
|
sl@0
|
44 |
CConsoleBase& aConsole,
|
sl@0
|
45 |
Output& aOut,
|
sl@0
|
46 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
CAuthenticationPolicy* self = new (ELeave) CAuthenticationPolicy(aFs, aConsole, aOut);
|
sl@0
|
49 |
CleanupStack::PushL(self);
|
sl@0
|
50 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
51 |
return self;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
CAuthenticationPolicy::~CAuthenticationPolicy()
|
sl@0
|
55 |
{
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
CAuthenticationPolicy::CAuthenticationPolicy(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
|
sl@0
|
59 |
CKeyStoreTestAction(aFs, aConsole, aOut), iState(EInit)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
void CAuthenticationPolicy::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
66 |
|
sl@0
|
67 |
iMode.Copy(Input::ParseElement(aTestActionSpec.iActionBody, KAuthModeStart, KAuthModeEnd));
|
sl@0
|
68 |
|
sl@0
|
69 |
if(iMode.Compare(_L8("get")) == 0)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
iExpectedExpression.Copy(Input::ParseElement(aTestActionSpec.iActionBody, KExpectedExpressionStart, KExpectedExpressionEnd));
|
sl@0
|
72 |
iExpectedFreshness = Input::ParseIntElement(aTestActionSpec.iActionBody, KExpectedFreshnessStart, KExpectedFreshnessEnd);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
void CAuthenticationPolicy::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
switch (iState)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
case EInit:
|
sl@0
|
82 |
{
|
sl@0
|
83 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
84 |
|
sl@0
|
85 |
iFilter.iUsage = EPKCS15UsageAll;
|
sl@0
|
86 |
keyStore->List(iKeys, iFilter, aStatus);
|
sl@0
|
87 |
|
sl@0
|
88 |
iState = EListing;
|
sl@0
|
89 |
|
sl@0
|
90 |
}
|
sl@0
|
91 |
break;
|
sl@0
|
92 |
|
sl@0
|
93 |
case EListing:
|
sl@0
|
94 |
{
|
sl@0
|
95 |
switch(aStatus.Int())
|
sl@0
|
96 |
{
|
sl@0
|
97 |
case KErrNone:
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TCTTokenObjectHandle keyHandle;
|
sl@0
|
100 |
if (iKeys.Count() == 0)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
iConsole.Printf(_L("keyStore empty!!"));
|
sl@0
|
103 |
iState = EFinished;
|
sl@0
|
104 |
TRequestStatus *status = &aStatus;
|
sl@0
|
105 |
User::RequestComplete(status, KKeyStoreEmpty);
|
sl@0
|
106 |
break;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
// Select the key with the label we want!
|
sl@0
|
110 |
for (TInt j = 0; j < iKeys.Count(); j++)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
if (iKeys[j]->Label() == *iLabel)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
keyHandle = iKeys[j]->Handle();
|
sl@0
|
115 |
break;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
}
|
sl@0
|
118 |
if(keyHandle.iObjectId == 0)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
iConsole.Printf(_L("No keys with matching label!!"));
|
sl@0
|
121 |
iState = EFinished;
|
sl@0
|
122 |
TRequestStatus *status = &aStatus;
|
sl@0
|
123 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
128 |
if(iMode.Compare(_L8("set")) == 0)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
keyStore->SetAuthenticationPolicy(keyHandle, *iAuthExpression, iFreshness, aStatus);
|
sl@0
|
131 |
iState = EFinished;
|
sl@0
|
132 |
}
|
sl@0
|
133 |
else if(iMode.Compare(_L8("get")) == 0)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
if(iAuthExpression)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
delete iAuthExpression;
|
sl@0
|
138 |
iAuthExpression = NULL;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
iAuthExpression = HBufC::NewL(1024);
|
sl@0
|
141 |
keyStore->GetAuthenticationPolicy(keyHandle, iAuthExpression, iFreshness, aStatus);
|
sl@0
|
142 |
iState = EGetAuthenticationPolicy;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
else
|
sl@0
|
145 |
{
|
sl@0
|
146 |
iConsole.Printf(_L("Invalid Mode"));
|
sl@0
|
147 |
iState = EFinished;
|
sl@0
|
148 |
TRequestStatus *status = &aStatus;
|
sl@0
|
149 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
150 |
}
|
sl@0
|
151 |
}
|
sl@0
|
152 |
break;
|
sl@0
|
153 |
default:
|
sl@0
|
154 |
{
|
sl@0
|
155 |
iConsole.Printf(_L("keyStore->ExportKey returned: %d\n"), aStatus.Int());
|
sl@0
|
156 |
iState = EFinished;
|
sl@0
|
157 |
TRequestStatus *status = &aStatus;
|
sl@0
|
158 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
159 |
}
|
sl@0
|
160 |
break;
|
sl@0
|
161 |
} // switch
|
sl@0
|
162 |
break;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
case EGetAuthenticationPolicy:
|
sl@0
|
165 |
switch(aStatus.Int())
|
sl@0
|
166 |
{
|
sl@0
|
167 |
case KErrNone:
|
sl@0
|
168 |
{
|
sl@0
|
169 |
TInt err = KErrNone;
|
sl@0
|
170 |
HBufC* expectedExpr = HBufC::NewL(iExpectedExpression.Length());
|
sl@0
|
171 |
expectedExpr->Des().Copy(iExpectedExpression);
|
sl@0
|
172 |
if(iAuthExpression->Des().Compare(*expectedExpr) != 0 ||
|
sl@0
|
173 |
iFreshness != iExpectedFreshness)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
err = KErrArgument;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
iConsole.Printf(_L("Authentication policy returned: %S, %d\n"), iAuthExpression, iFreshness);
|
sl@0
|
178 |
delete expectedExpr;
|
sl@0
|
179 |
iState = EFinished;
|
sl@0
|
180 |
delete iAuthExpression;
|
sl@0
|
181 |
iAuthExpression = NULL;
|
sl@0
|
182 |
TRequestStatus *status = &aStatus;
|
sl@0
|
183 |
User::RequestComplete(status, err);
|
sl@0
|
184 |
break;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
default:
|
sl@0
|
187 |
{
|
sl@0
|
188 |
iConsole.Printf(_L("Setting Authentication policy returned: %d\n"), aStatus.Int());
|
sl@0
|
189 |
iState = EFinished;
|
sl@0
|
190 |
TRequestStatus *status = &aStatus;
|
sl@0
|
191 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
192 |
}
|
sl@0
|
193 |
break;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
break;
|
sl@0
|
196 |
case EFinished:
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TRequestStatus* status = &aStatus;
|
sl@0
|
199 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
200 |
if (aStatus == iExpectedResult)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
iResult = ETrue;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
else
|
sl@0
|
205 |
{
|
sl@0
|
206 |
iResult = EFalse;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
iActionState = EPostrequisite;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
break;
|
sl@0
|
212 |
|
sl@0
|
213 |
default:
|
sl@0
|
214 |
break; // Nothing to do, for the compiler
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
void CAuthenticationPolicy::PerformCancel()
|
sl@0
|
219 |
{
|
sl@0
|
220 |
if (iState == EFinished)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
void CAuthenticationPolicy::Reset()
|
sl@0
|
227 |
{
|
sl@0
|
228 |
iState = EInit;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
void CAuthenticationPolicy::DoReportAction()
|
sl@0
|
232 |
{
|
sl@0
|
233 |
if(iMode.Compare(_L8("set")) == 0)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
_LIT(KSet, "Setting authentication policy...");
|
sl@0
|
236 |
iOut.writeString(KSet);
|
sl@0
|
237 |
}
|
sl@0
|
238 |
else if(iMode.Compare(_L8("get")) == 0)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
_LIT(KGet, "Getting authentication policy...");
|
sl@0
|
241 |
iOut.writeString(KGet);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
iOut.writeString(iLabel->Left(32));
|
sl@0
|
245 |
if (iLabel->Length() > 32)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
iOut.writeString(KEllipsis);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
iOut.writeNewLine();
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
|
sl@0
|
254 |
void CAuthenticationPolicy::DoCheckResult(TInt aError)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
if (iFinished)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
if (aError == KErrNone)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
_LIT(KSuccessful, "Operation Successfull\n");
|
sl@0
|
261 |
iConsole.Write(KSuccessful);
|
sl@0
|
262 |
iOut.writeString(KSuccessful);
|
sl@0
|
263 |
iOut.writeNewLine();
|
sl@0
|
264 |
iOut.writeNewLine();
|
sl@0
|
265 |
}
|
sl@0
|
266 |
else
|
sl@0
|
267 |
{
|
sl@0
|
268 |
if (aError!=iExpectedResult)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
_LIT(KFailed, "!!!Operation Failed!!!\n");
|
sl@0
|
271 |
iConsole.Write(KFailed);
|
sl@0
|
272 |
iOut.writeString(KFailed);
|
sl@0
|
273 |
}
|
sl@0
|
274 |
else
|
sl@0
|
275 |
{
|
sl@0
|
276 |
_LIT(KFailed, "Operation failed, but expected\n");
|
sl@0
|
277 |
iConsole.Write(KFailed);
|
sl@0
|
278 |
iOut.writeString(KFailed);
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
iOut.writeNewLine();
|
sl@0
|
282 |
iOut.writeNewLine();
|
sl@0
|
283 |
}
|
sl@0
|
284 |
}
|
sl@0
|
285 |
}
|