sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-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 |
/**
|
sl@0
|
20 |
@file
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "t_unifiedcertstoreremove.h"
|
sl@0
|
24 |
#include "t_certstoredefs.h"
|
sl@0
|
25 |
#include "t_input.h"
|
sl@0
|
26 |
#include "t_certstoreout.h"
|
sl@0
|
27 |
#include <ccertattributefilter.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
31 |
//CDeleteCertificate
|
sl@0
|
32 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
CTestAction* CDeleteCertificate::NewL(RFs& aFs,
|
sl@0
|
36 |
CConsoleBase& aConsole,
|
sl@0
|
37 |
Output& aOut,
|
sl@0
|
38 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
CDeleteCertificate* self = new(ELeave) CDeleteCertificate(aFs, aConsole, aOut);
|
sl@0
|
41 |
CleanupStack::PushL(self);
|
sl@0
|
42 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
43 |
CleanupStack::Pop(self);
|
sl@0
|
44 |
return self;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
CDeleteCertificate::CDeleteCertificate(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
48 |
Output& aOut)
|
sl@0
|
49 |
: CSubscriberAction(aFs, aConsole, aOut), iState(EIdle),iCertDeleteType(NULL)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
void CDeleteCertificate::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
if (aStatus != KErrNone)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iState = EFinished;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
switch (iState)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
case EIdle:
|
sl@0
|
63 |
//get the certs
|
sl@0
|
64 |
if (iCertInfos.Count() > 0)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
iCertInfos.Close(); // JCS added for multiple delete case
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
iState = EGettingCerts;
|
sl@0
|
70 |
//get the certs
|
sl@0
|
71 |
GetCerts(aStatus);
|
sl@0
|
72 |
break;
|
sl@0
|
73 |
|
sl@0
|
74 |
case EGettingCerts:
|
sl@0
|
75 |
{
|
sl@0
|
76 |
if (iNotificationSubscribed)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
if (!iNotifier)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
|
sl@0
|
81 |
iNotifier->StartNotification();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
iState = ECheckNotification;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
else
|
sl@0
|
86 |
{
|
sl@0
|
87 |
iState = EFinished;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
DeleteCert(aStatus);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
break;
|
sl@0
|
92 |
|
sl@0
|
93 |
case ECheckNotification:
|
sl@0
|
94 |
{
|
sl@0
|
95 |
iState = EFinished;
|
sl@0
|
96 |
if (iNotifierFlag)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
TRequestStatus* status = &aStatus;
|
sl@0
|
99 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
else
|
sl@0
|
102 |
{
|
sl@0
|
103 |
iNotifier->SetCompleteStatus(&aStatus);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
break;
|
sl@0
|
108 |
|
sl@0
|
109 |
case EFinished:
|
sl@0
|
110 |
{
|
sl@0
|
111 |
if (aStatus == iExpectedResult)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
iResult = ETrue;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
else
|
sl@0
|
116 |
{
|
sl@0
|
117 |
iResult = EFalse;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
if (aStatus == KErrNoMemory)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
iState = EIdle;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
else
|
sl@0
|
124 |
{
|
sl@0
|
125 |
iFinished = ETrue;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
TRequestStatus* status = &aStatus;
|
sl@0
|
128 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
129 |
}
|
sl@0
|
130 |
break;
|
sl@0
|
131 |
|
sl@0
|
132 |
default:
|
sl@0
|
133 |
User::Invariant();
|
sl@0
|
134 |
}
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
void CDeleteCertificate::PerformCancel()
|
sl@0
|
138 |
{
|
sl@0
|
139 |
switch (iState)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
case EGettingCerts:
|
sl@0
|
142 |
CertStore().CancelList();
|
sl@0
|
143 |
break;
|
sl@0
|
144 |
case ECheckNotification:
|
sl@0
|
145 |
case EIdle:
|
sl@0
|
146 |
case EFinished:
|
sl@0
|
147 |
// We /may/ be deleting a cert in these states - fortunately cancel is lenient
|
sl@0
|
148 |
UnifiedCertStore().CancelRemove();
|
sl@0
|
149 |
break;
|
sl@0
|
150 |
|
sl@0
|
151 |
default:
|
sl@0
|
152 |
User::Invariant();
|
sl@0
|
153 |
}
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
void CDeleteCertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
CSubscriberAction::ConstructL(aTestActionSpec);
|
sl@0
|
159 |
|
sl@0
|
160 |
iFilter = CCertAttributeFilter::NewL();
|
sl@0
|
161 |
TInt pos = 0;
|
sl@0
|
162 |
TInt err1 = KErrNone;
|
sl@0
|
163 |
|
sl@0
|
164 |
TPtrC8 pLabel1 = Input::ParseElement(aTestActionSpec.iActionBody, KCertTypeStart, KCertTypeEnd, pos, err1);
|
sl@0
|
165 |
|
sl@0
|
166 |
if(err1 == KErrNone)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
iCertDeleteType = HBufC8::NewL(pLabel1.Size());
|
sl@0
|
169 |
*iCertDeleteType = pLabel1;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
pos=0;
|
sl@0
|
173 |
TInt err2 = KErrNone;
|
sl@0
|
174 |
TPtrC8 pLabel2 = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err2);
|
sl@0
|
175 |
if (err2 != KErrNone)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
User::Leave(err2);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
iCertLabel.Copy(pLabel2);
|
sl@0
|
181 |
if (iCertLabel.Compare(_L("*.*"))==0) // delete all certs
|
sl@0
|
182 |
{// Check that the flag has been set
|
sl@0
|
183 |
TPtrC8 pDeleteAll = Input::ParseElement(aTestActionSpec.iActionBody, KDeleteAllStart, KDeleteAllEnd, pos, err1);
|
sl@0
|
184 |
if (pDeleteAll!=KNullDesC8)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
TLex8 lexer(pDeleteAll);
|
sl@0
|
187 |
TInt boolVal = 0;
|
sl@0
|
188 |
lexer.Val(boolVal);
|
sl@0
|
189 |
iDeleteAllCerts = (boolVal > 0) ? ETrue : EFalse;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
}
|
sl@0
|
192 |
else if( err1 != KErrNone && err1 != KErrNotFound)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
User::Leave(err1);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
// Set expected result
|
sl@0
|
198 |
HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
|
sl@0
|
199 |
TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
|
sl@0
|
200 |
Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
|
sl@0
|
201 |
CleanupStack::PopAndDestroy(result);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
void CDeleteCertificate::GetCerts(TRequestStatus& aStatus)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
CertStore().List(iCertInfos, *iFilter, aStatus);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
CDeleteCertificate::~CDeleteCertificate()
|
sl@0
|
210 |
{
|
sl@0
|
211 |
delete iCertDeleteType;
|
sl@0
|
212 |
iCertInfos.Close();
|
sl@0
|
213 |
delete iFilter;
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
void CDeleteCertificate::DeleteCert(TRequestStatus& aStatus)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
TInt ix = KErrNotFound;
|
sl@0
|
219 |
TInt count = iCertInfos.Count();
|
sl@0
|
220 |
for (TInt i = count-1; i >= 0 ; i--)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
if (iDeleteAllCerts)
|
sl@0
|
223 |
{// Just delete the first one we come across
|
sl@0
|
224 |
if (i>=0) // Still some certificates to delete
|
sl@0
|
225 |
{ // Set the state back to continue
|
sl@0
|
226 |
iState = EIdle;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
ix = i;
|
sl@0
|
230 |
break;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
// Only delete if there's a label match and the certificate is of specified type
|
sl@0
|
233 |
else if (iCertInfos[i]->Label() == iCertLabel && CheckCertType(*iCertInfos[i]) )
|
sl@0
|
234 |
{
|
sl@0
|
235 |
ix = i;
|
sl@0
|
236 |
break;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
TRequestStatus* status = &aStatus;
|
sl@0
|
241 |
if (ix == KErrNotFound)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
TInt result = KErrNone;
|
sl@0
|
244 |
|
sl@0
|
245 |
if(iDeleteAllCerts)
|
sl@0
|
246 |
result = KErrNone;
|
sl@0
|
247 |
else if(iCertDeleteType == NULL)
|
sl@0
|
248 |
result = KErrNotSupported;
|
sl@0
|
249 |
else
|
sl@0
|
250 |
result = KErrNotFound;
|
sl@0
|
251 |
|
sl@0
|
252 |
User::RequestComplete(status, result);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
else
|
sl@0
|
255 |
{
|
sl@0
|
256 |
iCertInfoToDelete = iCertInfos[ix];
|
sl@0
|
257 |
UnifiedCertStore().Remove(*iCertInfos[ix], aStatus);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
TBool CDeleteCertificate::CheckCertType( CCTCertInfo& aCertInfo )
|
sl@0
|
262 |
{
|
sl@0
|
263 |
if(iCertDeleteType == NULL)
|
sl@0
|
264 |
return EFalse;
|
sl@0
|
265 |
|
sl@0
|
266 |
TBool returnValue = EFalse;
|
sl@0
|
267 |
switch(aCertInfo.CertificateOwnerType())
|
sl@0
|
268 |
{
|
sl@0
|
269 |
case ECACertificate:
|
sl@0
|
270 |
if(iCertDeleteType->Compare(KCACert) == 0 )
|
sl@0
|
271 |
returnValue = ETrue;
|
sl@0
|
272 |
break;
|
sl@0
|
273 |
case EUserCertificate:
|
sl@0
|
274 |
if(iCertDeleteType->Compare(KUserCert) == 0 )
|
sl@0
|
275 |
returnValue = ETrue;
|
sl@0
|
276 |
break;
|
sl@0
|
277 |
case EPeerCertificate:
|
sl@0
|
278 |
if(iCertDeleteType->Compare(KPeerCert) == 0 )
|
sl@0
|
279 |
returnValue = ETrue;
|
sl@0
|
280 |
break;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
return returnValue;
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
void CDeleteCertificate::DoReportAction()
|
sl@0
|
286 |
{
|
sl@0
|
287 |
iOut.writeString(_L("Deleting certificate..."));
|
sl@0
|
288 |
iOut.writeNewLine();
|
sl@0
|
289 |
iOut.writeString(_L("\tLabel = "));
|
sl@0
|
290 |
iOut.writeString(iCertLabel);
|
sl@0
|
291 |
iOut.writeNewLine();
|
sl@0
|
292 |
iOut.writeNewLine();
|
sl@0
|
293 |
}
|
sl@0
|
294 |
|
sl@0
|
295 |
void CDeleteCertificate::DoCheckResult(TInt aError)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
if (iFinished)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
if (aError == KErrNone && iCertInfoToDelete)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
switch (iCertInfoToDelete->CertificateOwnerType())
|
sl@0
|
302 |
{
|
sl@0
|
303 |
case ECACertificate:
|
sl@0
|
304 |
iConsole.Write(_L("\tCA certificate deleted successfully\n"));
|
sl@0
|
305 |
iOut.writeString(_L("\tCA certificate deleted successfully"));
|
sl@0
|
306 |
break;
|
sl@0
|
307 |
|
sl@0
|
308 |
case EUserCertificate:
|
sl@0
|
309 |
iConsole.Write(_L("\tUser certificate deleted successfully\n"));
|
sl@0
|
310 |
iOut.writeString(_L("\tUser certificate deleted successfully"));
|
sl@0
|
311 |
break;
|
sl@0
|
312 |
|
sl@0
|
313 |
case EPeerCertificate:
|
sl@0
|
314 |
iConsole.Write(_L("\tPeer certificate deleted successfully\n"));
|
sl@0
|
315 |
iOut.writeString(_L("\tPeer certificate deleted successfully"));
|
sl@0
|
316 |
break;
|
sl@0
|
317 |
default:
|
sl@0
|
318 |
iConsole.Write(_L("\tUnknown owner certificate deleted successfully\n"));
|
sl@0
|
319 |
iOut.writeString(_L("\tUnknown owner certificate deleted successfully"));
|
sl@0
|
320 |
break;
|
sl@0
|
321 |
}
|
sl@0
|
322 |
}
|
sl@0
|
323 |
iOut.writeNewLine();
|
sl@0
|
324 |
iOut.writeNewLine();
|
sl@0
|
325 |
}
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
void CDeleteCertificate::Reset()
|
sl@0
|
329 |
{
|
sl@0
|
330 |
iState = EIdle;
|
sl@0
|
331 |
iCertInfos.Close();
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
|
sl@0
|
335 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
336 |
//CDeleteRetrieveCertificate
|
sl@0
|
337 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
338 |
CDeleteRetrieveCertificate::CDeleteRetrieveCertificate(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
339 |
Output& aOut)
|
sl@0
|
340 |
: CSubscriberAction(aFs, aConsole, aOut), iState(EIdle)
|
sl@0
|
341 |
{
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
void CDeleteRetrieveCertificate::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
345 |
{
|
sl@0
|
346 |
TRequestStatus* status = &aStatus;
|
sl@0
|
347 |
switch (iState)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
case EIdle:
|
sl@0
|
350 |
//get the certs
|
sl@0
|
351 |
iState = EDeletingCert;
|
sl@0
|
352 |
//get the certs
|
sl@0
|
353 |
GetCerts(aStatus);
|
sl@0
|
354 |
if (aStatus == KErrNoMemory)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
iState = EFinished;
|
sl@0
|
357 |
}
|
sl@0
|
358 |
break;
|
sl@0
|
359 |
|
sl@0
|
360 |
case EDeletingCert:
|
sl@0
|
361 |
{
|
sl@0
|
362 |
if (iNotificationSubscribed)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
iNotifier = CCertStoreChangeNotifier::NewL(iNotifierFlag);
|
sl@0
|
365 |
iNotifier->StartNotification();
|
sl@0
|
366 |
iState = ECheckNotification;
|
sl@0
|
367 |
}
|
sl@0
|
368 |
else
|
sl@0
|
369 |
{
|
sl@0
|
370 |
iState = EGettingCerts;
|
sl@0
|
371 |
}
|
sl@0
|
372 |
//delete the cert
|
sl@0
|
373 |
DeleteCert(aStatus);
|
sl@0
|
374 |
break;
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
case ECheckNotification:
|
sl@0
|
378 |
{
|
sl@0
|
379 |
TInt ret=KErrNone;
|
sl@0
|
380 |
if (!iNotifierFlag)
|
sl@0
|
381 |
{
|
sl@0
|
382 |
ret=KErrGeneral;
|
sl@0
|
383 |
}
|
sl@0
|
384 |
if (ret!=KErrNone)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
iState = EFinished;
|
sl@0
|
387 |
}
|
sl@0
|
388 |
else
|
sl@0
|
389 |
{
|
sl@0
|
390 |
iState = EGettingCerts;
|
sl@0
|
391 |
}
|
sl@0
|
392 |
TRequestStatus* status = &aStatus;
|
sl@0
|
393 |
User::RequestComplete(status, ret);
|
sl@0
|
394 |
}
|
sl@0
|
395 |
break;
|
sl@0
|
396 |
case EGettingCerts:
|
sl@0
|
397 |
{
|
sl@0
|
398 |
iState = EFinished;
|
sl@0
|
399 |
//get the cert
|
sl@0
|
400 |
RetrieveCerts(aStatus);
|
sl@0
|
401 |
break;
|
sl@0
|
402 |
}
|
sl@0
|
403 |
case EFinished:
|
sl@0
|
404 |
{
|
sl@0
|
405 |
if (aStatus == iExpectedResult)
|
sl@0
|
406 |
{
|
sl@0
|
407 |
iResult = ETrue;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
else
|
sl@0
|
410 |
{
|
sl@0
|
411 |
iResult = EFalse;
|
sl@0
|
412 |
}
|
sl@0
|
413 |
if (aStatus == KErrNoMemory)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
iState = EIdle;
|
sl@0
|
416 |
}
|
sl@0
|
417 |
else
|
sl@0
|
418 |
{
|
sl@0
|
419 |
iFinished = ETrue;
|
sl@0
|
420 |
}
|
sl@0
|
421 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
422 |
}
|
sl@0
|
423 |
break;
|
sl@0
|
424 |
default:
|
sl@0
|
425 |
{
|
sl@0
|
426 |
//some kind of error behaviour
|
sl@0
|
427 |
}
|
sl@0
|
428 |
}
|
sl@0
|
429 |
}
|
sl@0
|
430 |
|
sl@0
|
431 |
void CDeleteRetrieveCertificate::PerformCancel()
|
sl@0
|
432 |
{
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
void CDeleteRetrieveCertificate::Reset()
|
sl@0
|
436 |
{
|
sl@0
|
437 |
__ASSERT_DEBUG(EFalse, User::Panic(_L("CDeleteRetrieveCertificate::Reset()"), 1));
|
sl@0
|
438 |
}
|
sl@0
|
439 |
|
sl@0
|
440 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
441 |
//CDeleteCACertificate
|
sl@0
|
442 |
//////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
443 |
|
sl@0
|
444 |
CTestAction* CDeleteRetrieveCACertificate::NewL(RFs& aFs,
|
sl@0
|
445 |
CConsoleBase& aConsole,
|
sl@0
|
446 |
Output& aOut,
|
sl@0
|
447 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
CDeleteRetrieveCACertificate* self =
|
sl@0
|
450 |
new(ELeave) CDeleteRetrieveCACertificate(aFs, aConsole, aOut);
|
sl@0
|
451 |
CleanupStack::PushL(self);
|
sl@0
|
452 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
453 |
CleanupStack::Pop(self);
|
sl@0
|
454 |
return self;
|
sl@0
|
455 |
}
|
sl@0
|
456 |
|
sl@0
|
457 |
CDeleteRetrieveCACertificate::CDeleteRetrieveCACertificate(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
458 |
Output& aOut)
|
sl@0
|
459 |
:CDeleteRetrieveCertificate(aFs, aConsole, aOut)
|
sl@0
|
460 |
{
|
sl@0
|
461 |
}
|
sl@0
|
462 |
|
sl@0
|
463 |
void CDeleteRetrieveCACertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
464 |
{
|
sl@0
|
465 |
CSubscriberAction::ConstructL(aTestActionSpec);
|
sl@0
|
466 |
iCertlisted = new(ELeave) RPointerArray<HBufC8>;
|
sl@0
|
467 |
iFilter = CCertAttributeFilter::NewL();
|
sl@0
|
468 |
TInt pos = 0;
|
sl@0
|
469 |
TInt err = KErrNone;
|
sl@0
|
470 |
TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
|
sl@0
|
471 |
if (err != KErrNone)
|
sl@0
|
472 |
{
|
sl@0
|
473 |
User::Leave(err);
|
sl@0
|
474 |
}
|
sl@0
|
475 |
iCertLabel.Copy(pLabel);
|
sl@0
|
476 |
|
sl@0
|
477 |
// Set expected result
|
sl@0
|
478 |
pos = 0;
|
sl@0
|
479 |
|
sl@0
|
480 |
HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
|
sl@0
|
481 |
TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
|
sl@0
|
482 |
Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
|
sl@0
|
483 |
CleanupStack::PopAndDestroy(result);
|
sl@0
|
484 |
}
|
sl@0
|
485 |
|
sl@0
|
486 |
void CDeleteRetrieveCACertificate::GetCerts(TRequestStatus& aStatus)
|
sl@0
|
487 |
{
|
sl@0
|
488 |
CertStore().List(iCertInfos, *iFilter, aStatus);
|
sl@0
|
489 |
}
|
sl@0
|
490 |
|
sl@0
|
491 |
void CDeleteRetrieveCACertificate::RetrieveCerts(TRequestStatus& aStatus)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
TRequestStatus* status = &aStatus;
|
sl@0
|
494 |
TInt ix = KErrNotFound;
|
sl@0
|
495 |
TInt count = iCertInfos.Count();
|
sl@0
|
496 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
497 |
{
|
sl@0
|
498 |
if (iCertInfos[i]->Label() == iCertLabel)
|
sl@0
|
499 |
{
|
sl@0
|
500 |
ix = i;
|
sl@0
|
501 |
break;
|
sl@0
|
502 |
}
|
sl@0
|
503 |
}
|
sl@0
|
504 |
if (ix == KErrNotFound)
|
sl@0
|
505 |
{
|
sl@0
|
506 |
User::RequestComplete(status, ix);
|
sl@0
|
507 |
}
|
sl@0
|
508 |
else
|
sl@0
|
509 |
{
|
sl@0
|
510 |
iCertInfoToRetrieve = iCertInfos[ix];
|
sl@0
|
511 |
|
sl@0
|
512 |
HBufC8* buf = HBufC8::NewLC(iCertInfoToRetrieve->Size());
|
sl@0
|
513 |
User::LeaveIfError(iCertlisted->Append(buf));
|
sl@0
|
514 |
CleanupStack::Pop();//buf
|
sl@0
|
515 |
__ASSERT_DEBUG(!iBuf, User::Panic(_L("CListCACertificates"), 1));
|
sl@0
|
516 |
iBuf = new(ELeave) TPtr8(buf->Des());
|
sl@0
|
517 |
CertStore().Retrieve(*iCertInfoToRetrieve, *iBuf, aStatus);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
}
|
sl@0
|
520 |
|
sl@0
|
521 |
CDeleteRetrieveCACertificate::~CDeleteRetrieveCACertificate()
|
sl@0
|
522 |
{
|
sl@0
|
523 |
iCertInfos.Close();
|
sl@0
|
524 |
delete iFilter;
|
sl@0
|
525 |
if (iCertlisted)
|
sl@0
|
526 |
{
|
sl@0
|
527 |
iCertlisted->ResetAndDestroy();
|
sl@0
|
528 |
delete iCertlisted;
|
sl@0
|
529 |
}
|
sl@0
|
530 |
delete iBuf;
|
sl@0
|
531 |
}
|
sl@0
|
532 |
|
sl@0
|
533 |
void CDeleteRetrieveCACertificate::DeleteCert(TRequestStatus& aStatus)
|
sl@0
|
534 |
{
|
sl@0
|
535 |
TRequestStatus* status = &aStatus;
|
sl@0
|
536 |
TInt ix = KErrNotFound;
|
sl@0
|
537 |
TInt count = iCertInfos.Count();
|
sl@0
|
538 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
if (iCertInfos[i]->Label() == iCertLabel)
|
sl@0
|
541 |
{
|
sl@0
|
542 |
ix = i;
|
sl@0
|
543 |
break;
|
sl@0
|
544 |
}
|
sl@0
|
545 |
}
|
sl@0
|
546 |
if (ix == KErrNotFound)
|
sl@0
|
547 |
{
|
sl@0
|
548 |
User::RequestComplete(status, ix);
|
sl@0
|
549 |
}
|
sl@0
|
550 |
else
|
sl@0
|
551 |
{
|
sl@0
|
552 |
iCertInfoToDelete = iCertInfos[ix];
|
sl@0
|
553 |
UnifiedCertStore().Remove(*iCertInfoToDelete, aStatus);
|
sl@0
|
554 |
}
|
sl@0
|
555 |
}
|
sl@0
|
556 |
|
sl@0
|
557 |
void CDeleteRetrieveCACertificate::DoReportAction()
|
sl@0
|
558 |
{
|
sl@0
|
559 |
iOut.writeString(_L("Deleting certificate..."));
|
sl@0
|
560 |
iOut.writeNewLine();
|
sl@0
|
561 |
iOut.writeString(_L("\tLabel = "));
|
sl@0
|
562 |
iOut.writeString(iCertLabel);
|
sl@0
|
563 |
iOut.writeNewLine();
|
sl@0
|
564 |
iOut.writeNewLine();
|
sl@0
|
565 |
}
|
sl@0
|
566 |
|
sl@0
|
567 |
void CDeleteRetrieveCACertificate::DoCheckResult(TInt aError)
|
sl@0
|
568 |
{
|
sl@0
|
569 |
if (iFinished)
|
sl@0
|
570 |
{
|
sl@0
|
571 |
if (aError == KErrNone && iResult)
|
sl@0
|
572 |
{
|
sl@0
|
573 |
switch (iCertInfoToDelete->CertificateOwnerType())
|
sl@0
|
574 |
{
|
sl@0
|
575 |
case ECACertificate:
|
sl@0
|
576 |
iConsole.Write(_L("\tCA certificate deleted successfully\n"));
|
sl@0
|
577 |
iOut.writeString(_L("\tCA certificate deleted successfully"));
|
sl@0
|
578 |
break;
|
sl@0
|
579 |
|
sl@0
|
580 |
case EUserCertificate:
|
sl@0
|
581 |
iConsole.Write(_L("\tUser certificate deleted successfully\n"));
|
sl@0
|
582 |
iOut.writeString(_L("\tUser certificate deleted successfully"));
|
sl@0
|
583 |
break;
|
sl@0
|
584 |
|
sl@0
|
585 |
default:
|
sl@0
|
586 |
iConsole.Write(_L("\tUnknown owner certificate deleted successfully\n"));
|
sl@0
|
587 |
iOut.writeString(_L("\tUnknown owner certificate deleted successfully"));
|
sl@0
|
588 |
break;
|
sl@0
|
589 |
}
|
sl@0
|
590 |
}
|
sl@0
|
591 |
else
|
sl@0
|
592 |
{
|
sl@0
|
593 |
if (iResult)
|
sl@0
|
594 |
{
|
sl@0
|
595 |
iConsole.Write(_L("\tCA OK\n"));
|
sl@0
|
596 |
iOut.writeString(_L("\tCA OK"));
|
sl@0
|
597 |
}
|
sl@0
|
598 |
}
|
sl@0
|
599 |
iOut.writeNewLine();
|
sl@0
|
600 |
iOut.writeNewLine();
|
sl@0
|
601 |
}
|
sl@0
|
602 |
}
|
sl@0
|
603 |
|
sl@0
|
604 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
605 |
//CDeleteUserCertificate
|
sl@0
|
606 |
//////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
607 |
CTestAction* CDeleteRetrieveUserCertificate::NewL(RFs& aFs,
|
sl@0
|
608 |
CConsoleBase& aConsole,
|
sl@0
|
609 |
Output& aOut,
|
sl@0
|
610 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
611 |
{
|
sl@0
|
612 |
CDeleteRetrieveUserCertificate* self =
|
sl@0
|
613 |
new(ELeave) CDeleteRetrieveUserCertificate(aFs, aConsole, aOut);
|
sl@0
|
614 |
CleanupStack::PushL(self);
|
sl@0
|
615 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
616 |
CleanupStack::Pop(self);
|
sl@0
|
617 |
return self;
|
sl@0
|
618 |
}
|
sl@0
|
619 |
|
sl@0
|
620 |
CDeleteRetrieveUserCertificate::CDeleteRetrieveUserCertificate(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
621 |
Output& aOut)
|
sl@0
|
622 |
:CDeleteRetrieveCertificate(aFs, aConsole, aOut)
|
sl@0
|
623 |
{
|
sl@0
|
624 |
}
|
sl@0
|
625 |
|
sl@0
|
626 |
void CDeleteRetrieveUserCertificate::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
627 |
{
|
sl@0
|
628 |
CSubscriberAction::ConstructL(aTestActionSpec);
|
sl@0
|
629 |
iCertlisted = new(ELeave) RPointerArray<HBufC8>;
|
sl@0
|
630 |
iFilter = CCertAttributeFilter::NewL();
|
sl@0
|
631 |
TInt pos = 0;
|
sl@0
|
632 |
TInt err = KErrNone;
|
sl@0
|
633 |
TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
|
sl@0
|
634 |
if (err != KErrNone)
|
sl@0
|
635 |
{
|
sl@0
|
636 |
User::Leave(err);
|
sl@0
|
637 |
}
|
sl@0
|
638 |
iCertLabel.Copy(pLabel);
|
sl@0
|
639 |
|
sl@0
|
640 |
// Set expected result
|
sl@0
|
641 |
HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
|
sl@0
|
642 |
TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
|
sl@0
|
643 |
Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
|
sl@0
|
644 |
CleanupStack::PopAndDestroy(result);
|
sl@0
|
645 |
}
|
sl@0
|
646 |
|
sl@0
|
647 |
void CDeleteRetrieveUserCertificate::GetCerts(TRequestStatus& aStatus)
|
sl@0
|
648 |
{
|
sl@0
|
649 |
CertStore().List(iCertInfos, *iFilter, aStatus);
|
sl@0
|
650 |
}
|
sl@0
|
651 |
|
sl@0
|
652 |
void CDeleteRetrieveUserCertificate::RetrieveCerts(TRequestStatus& aStatus)
|
sl@0
|
653 |
{
|
sl@0
|
654 |
TRequestStatus* status = &aStatus;
|
sl@0
|
655 |
TInt ix = KErrNotFound;
|
sl@0
|
656 |
TInt count = iCertInfos.Count();
|
sl@0
|
657 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
658 |
{
|
sl@0
|
659 |
if (iCertInfos[i]->Label() == iCertLabel)
|
sl@0
|
660 |
{
|
sl@0
|
661 |
ix = i;
|
sl@0
|
662 |
break;
|
sl@0
|
663 |
}
|
sl@0
|
664 |
}
|
sl@0
|
665 |
if (ix == KErrNotFound)
|
sl@0
|
666 |
{
|
sl@0
|
667 |
User::RequestComplete(status, ix);
|
sl@0
|
668 |
}
|
sl@0
|
669 |
else
|
sl@0
|
670 |
{
|
sl@0
|
671 |
iCertInfoToRetrieve = iCertInfos[ix];
|
sl@0
|
672 |
|
sl@0
|
673 |
HBufC8* buf = HBufC8::NewLC(iCertInfoToRetrieve->Size());
|
sl@0
|
674 |
User::LeaveIfError(iCertlisted->Append(buf));
|
sl@0
|
675 |
CleanupStack::Pop();//buf
|
sl@0
|
676 |
//__ASSERT_DEBUG(!iBuf, User::Panic(_L("CListCACertificates"), 1));
|
sl@0
|
677 |
iBuf = new(ELeave) TPtr8(buf->Des());
|
sl@0
|
678 |
CertStore().Retrieve(*iCertInfoToRetrieve, *iBuf, aStatus);
|
sl@0
|
679 |
}
|
sl@0
|
680 |
}
|
sl@0
|
681 |
|
sl@0
|
682 |
CDeleteRetrieveUserCertificate::~CDeleteRetrieveUserCertificate()
|
sl@0
|
683 |
{
|
sl@0
|
684 |
iCertInfos.Close();
|
sl@0
|
685 |
delete iFilter;
|
sl@0
|
686 |
if (iCertlisted)
|
sl@0
|
687 |
{
|
sl@0
|
688 |
iCertlisted->ResetAndDestroy();
|
sl@0
|
689 |
delete iCertlisted;
|
sl@0
|
690 |
}
|
sl@0
|
691 |
delete iBuf;
|
sl@0
|
692 |
}
|
sl@0
|
693 |
|
sl@0
|
694 |
void CDeleteRetrieveUserCertificate::DeleteCert(TRequestStatus& aStatus)
|
sl@0
|
695 |
{
|
sl@0
|
696 |
TRequestStatus* status = &aStatus;
|
sl@0
|
697 |
TInt ix = KErrNotFound;
|
sl@0
|
698 |
TInt count = iCertInfos.Count();
|
sl@0
|
699 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
700 |
{
|
sl@0
|
701 |
if (iCertInfos[i]->Label() == iCertLabel)
|
sl@0
|
702 |
{
|
sl@0
|
703 |
ix = i;
|
sl@0
|
704 |
break;
|
sl@0
|
705 |
}
|
sl@0
|
706 |
}
|
sl@0
|
707 |
if (ix == KErrNotFound)
|
sl@0
|
708 |
{
|
sl@0
|
709 |
User::RequestComplete(status, ix);
|
sl@0
|
710 |
}
|
sl@0
|
711 |
else
|
sl@0
|
712 |
{
|
sl@0
|
713 |
CCTCertInfo* certInfo = iCertInfos[ix];
|
sl@0
|
714 |
UnifiedCertStore().Remove(*certInfo, aStatus);
|
sl@0
|
715 |
}
|
sl@0
|
716 |
}
|
sl@0
|
717 |
|
sl@0
|
718 |
void CDeleteRetrieveUserCertificate::DoReportAction()
|
sl@0
|
719 |
{
|
sl@0
|
720 |
iOut.writeString(_L("Deleting user certificate..."));
|
sl@0
|
721 |
iOut.writeNewLine();
|
sl@0
|
722 |
iOut.writeString(_L("\tLabel = "));
|
sl@0
|
723 |
iOut.writeString(iCertLabel);
|
sl@0
|
724 |
iOut.writeNewLine();
|
sl@0
|
725 |
iOut.writeNewLine();
|
sl@0
|
726 |
}
|
sl@0
|
727 |
|
sl@0
|
728 |
void CDeleteRetrieveUserCertificate::DoCheckResult(TInt aError)
|
sl@0
|
729 |
{
|
sl@0
|
730 |
if (iFinished)
|
sl@0
|
731 |
{
|
sl@0
|
732 |
if (aError == KErrNone && iResult)
|
sl@0
|
733 |
{
|
sl@0
|
734 |
iConsole.Write(_L("\tuser cert deleted successfully\n"));
|
sl@0
|
735 |
iOut.writeString(_L("\tuser cert deleted successfully"));
|
sl@0
|
736 |
iOut.writeNewLine();
|
sl@0
|
737 |
iOut.writeNewLine();
|
sl@0
|
738 |
}
|
sl@0
|
739 |
else
|
sl@0
|
740 |
{
|
sl@0
|
741 |
if (iResult)
|
sl@0
|
742 |
{
|
sl@0
|
743 |
iConsole.Write(_L("\tnot retrieved but expected\n"));
|
sl@0
|
744 |
iOut.writeString(_L("\tCA OK"));
|
sl@0
|
745 |
}
|
sl@0
|
746 |
else
|
sl@0
|
747 |
{
|
sl@0
|
748 |
iConsole.Write(_L("\tuser cert deleted successfully\n"));
|
sl@0
|
749 |
iOut.writeString(_L("\tuser cert deleted successfully"));
|
sl@0
|
750 |
iOut.writeNewLine();
|
sl@0
|
751 |
iOut.writeNewLine();
|
sl@0
|
752 |
}
|
sl@0
|
753 |
}
|
sl@0
|
754 |
}
|
sl@0
|
755 |
}
|