sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004-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 "t_testcertfordeletable.h"
|
sl@0
|
20 |
#include "t_certstoredefs.h"
|
sl@0
|
21 |
#include "t_input.h"
|
sl@0
|
22 |
#include "t_certstoreout.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "t_WritableCSDummies.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
CTestAction* CTestCertForDeletable::NewL(RFs& aFs,
|
sl@0
|
28 |
CConsoleBase& aConsole,
|
sl@0
|
29 |
Output& aOut,
|
sl@0
|
30 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
CTestCertForDeletable* self = new(ELeave) CTestCertForDeletable(aFs, aConsole, aOut);
|
sl@0
|
33 |
CleanupStack::PushL(self);
|
sl@0
|
34 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
35 |
CleanupStack::Pop(self);
|
sl@0
|
36 |
return self;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
CTestCertForDeletable::~CTestCertForDeletable()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
delete iCertificate;
|
sl@0
|
42 |
delete iCertificateURL;
|
sl@0
|
43 |
delete iCertificateContent;
|
sl@0
|
44 |
delete iCertificateLabel;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
void CTestCertForDeletable::TestSerializationL( MCTToken& aToken,
|
sl@0
|
48 |
TKeyIdentifier* aIssuerKeyId,
|
sl@0
|
49 |
TKeyIdentifier* aSubjectKeyId,
|
sl@0
|
50 |
const TInt aCertificateId,
|
sl@0
|
51 |
const TDesC8* aIssuerHash )
|
sl@0
|
52 |
{
|
sl@0
|
53 |
CCTCertInfo* cert = CCTCertInfo::NewLC( *iCertificateLabel, // const TDesC&
|
sl@0
|
54 |
iCertificateFormat, // TCertificateFormat
|
sl@0
|
55 |
iOwnerType, // TCertificateOwnerType
|
sl@0
|
56 |
999, // TInt aSize | aCert.Length()
|
sl@0
|
57 |
aSubjectKeyId, // const TKeyIdentifier*
|
sl@0
|
58 |
aIssuerKeyId, // const TKeyIdentifier*
|
sl@0
|
59 |
aToken, // MCTToken&
|
sl@0
|
60 |
aCertificateId, // TInt aCertificateId
|
sl@0
|
61 |
iDeletable, // TBool
|
sl@0
|
62 |
aIssuerHash ); // const TDesC8* aIssuerHash = NULL
|
sl@0
|
63 |
|
sl@0
|
64 |
// cert -> stack
|
sl@0
|
65 |
RFs fs;
|
sl@0
|
66 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
67 |
CleanupClosePushL(fs); // . fs -> stack
|
sl@0
|
68 |
|
sl@0
|
69 |
// this is a name of the file that will be opened as
|
sl@0
|
70 |
// a stream to test externalize/internalize
|
sl@0
|
71 |
TDriveUnit sysDrive (fs.GetSystemDrive());
|
sl@0
|
72 |
TBuf<24> fileName (sysDrive.Name());
|
sl@0
|
73 |
fileName.Append(_L("\\certinfo.dat"));
|
sl@0
|
74 |
|
sl@0
|
75 |
RFileWriteStream write_stream;
|
sl@0
|
76 |
User::LeaveIfError( write_stream.Replace(fs, fileName, EFileWrite) );
|
sl@0
|
77 |
CleanupClosePushL(write_stream); // . . write_stream -> stack
|
sl@0
|
78 |
|
sl@0
|
79 |
cert->ExternalizeL(write_stream);
|
sl@0
|
80 |
CleanupStack::PopAndDestroy(); // . . write_stream <- pop
|
sl@0
|
81 |
|
sl@0
|
82 |
// now internalize back from stream
|
sl@0
|
83 |
RFileReadStream read_stream;
|
sl@0
|
84 |
User::LeaveIfError( read_stream.Open(fs, fileName, EFileRead) );
|
sl@0
|
85 |
CleanupClosePushL(read_stream); // . . read_stream -> stack
|
sl@0
|
86 |
|
sl@0
|
87 |
CCTCertInfo* cert_read =
|
sl@0
|
88 |
CCTCertInfo::NewLC(read_stream, aToken); // does InternalizeL()
|
sl@0
|
89 |
// . . . cert_read -> stack
|
sl@0
|
90 |
// log certinfo params just internalized
|
sl@0
|
91 |
iOut.writeString(_L("Cert attributes after internalize:"));
|
sl@0
|
92 |
iOut.writeNewLine();
|
sl@0
|
93 |
WriteFormat( cert_read->CertificateFormat() );
|
sl@0
|
94 |
iOut.writeString(_L("\tiDeletable = "));
|
sl@0
|
95 |
iDeletable ? iOut.writeString(KTrue) : iOut.writeString(KFalse);
|
sl@0
|
96 |
iOut.writeNewLine();
|
sl@0
|
97 |
iOut.writeNewLine();
|
sl@0
|
98 |
|
sl@0
|
99 |
// set result
|
sl@0
|
100 |
iResultGood = ETrue;
|
sl@0
|
101 |
// check deletable flag is persistent
|
sl@0
|
102 |
if ( cert_read->IsDeletable() != iDeletable )
|
sl@0
|
103 |
{
|
sl@0
|
104 |
iResultGood = EFalse;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
// check format is persistent
|
sl@0
|
107 |
if ( cert_read->CertificateFormat() != iCertificateFormat )
|
sl@0
|
108 |
{
|
sl@0
|
109 |
iResultGood = EFalse;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
// cleanup
|
sl@0
|
113 |
CleanupStack::PopAndDestroy(cert_read); // . . . cert_read <- pop
|
sl@0
|
114 |
CleanupStack::PopAndDestroy(); // . . read_stream <- pop
|
sl@0
|
115 |
CleanupStack::PopAndDestroy(&fs); // . fs <- pop
|
sl@0
|
116 |
CleanupStack::PopAndDestroy(cert); // initial certinfo <- pop
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
void CTestCertForDeletable::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
// COMMON PART
|
sl@0
|
122 |
MCTWritableCertStore& ustore =
|
sl@0
|
123 |
UnifiedCertStore().WritableCertStore(iStoreIndex);
|
sl@0
|
124 |
MCTToken& token = ustore.Token();
|
sl@0
|
125 |
|
sl@0
|
126 |
TKeyIdentifier* issuerKeyId = NULL;
|
sl@0
|
127 |
TKeyIdentifier* subjectKeyId = NULL;
|
sl@0
|
128 |
|
sl@0
|
129 |
if (iOwnerType != ECACertificate)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
issuerKeyId = & iIssuerKeyId;
|
sl@0
|
132 |
subjectKeyId = & iSubjectKeyId;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
const TInt KCertificateId = 0x00000213;
|
sl@0
|
136 |
_LIT8(KSomeHash, "\x70\xe4\xf4\x54\x5f\x8e\xe6\xf2\xbd\x4e\x76\x2b\x8d\xa1\x83\xd8\xe0\x5d\x4a\x7d");
|
sl@0
|
137 |
|
sl@0
|
138 |
// create some certinfo object
|
sl@0
|
139 |
ASSERT(iCertificateLabel);
|
sl@0
|
140 |
|
sl@0
|
141 |
switch (iState)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
case ETestSerialization:
|
sl@0
|
144 |
{
|
sl@0
|
145 |
iOut.writeString(_L("Checking serialization for a certificate..."));
|
sl@0
|
146 |
iOut.writeNewLine();
|
sl@0
|
147 |
|
sl@0
|
148 |
TRAPD( err, TestSerializationL( token, issuerKeyId, subjectKeyId,
|
sl@0
|
149 |
KCertificateId, &KSomeHash) );
|
sl@0
|
150 |
|
sl@0
|
151 |
TRequestStatus* status = &aStatus;
|
sl@0
|
152 |
if (err != KErrNone )
|
sl@0
|
153 |
{
|
sl@0
|
154 |
// TestSerializationL() did leave
|
sl@0
|
155 |
iResult = EFalse;
|
sl@0
|
156 |
iResultGood = EFalse;
|
sl@0
|
157 |
User::RequestComplete(status, err);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else
|
sl@0
|
160 |
{
|
sl@0
|
161 |
// TestSerializationL() passed ok
|
sl@0
|
162 |
iResult = ETrue;
|
sl@0
|
163 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
164 |
}
|
sl@0
|
165 |
// set next state
|
sl@0
|
166 |
iState = EFinished;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
break;
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
case ETestNewCSClasswDeletable: // check mctwritablecertstore
|
sl@0
|
172 |
{
|
sl@0
|
173 |
iOut.writeString(_L("Testing MCTWritableCertStore::Add() w deletable..."));
|
sl@0
|
174 |
iOut.writeNewLine();
|
sl@0
|
175 |
|
sl@0
|
176 |
// create a writablestore supporting new Add()
|
sl@0
|
177 |
TNewCSClasswDeletable storeNew;
|
sl@0
|
178 |
|
sl@0
|
179 |
// call new Add()
|
sl@0
|
180 |
storeNew.Add( *iCertificateLabel,
|
sl@0
|
181 |
iCertificateFormat,
|
sl@0
|
182 |
iOwnerType,
|
sl@0
|
183 |
subjectKeyId,
|
sl@0
|
184 |
issuerKeyId,
|
sl@0
|
185 |
*iCertificateContent, // this is probably unset
|
sl@0
|
186 |
iDeletable,
|
sl@0
|
187 |
aStatus);
|
sl@0
|
188 |
|
sl@0
|
189 |
iResultGood = ETrue;
|
sl@0
|
190 |
iState = EFinished;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
break;
|
sl@0
|
193 |
|
sl@0
|
194 |
|
sl@0
|
195 |
case ETestOldCSClasswoDeletable: // check mctwritablecertstore
|
sl@0
|
196 |
{
|
sl@0
|
197 |
|
sl@0
|
198 |
iOut.writeString(_L("Testing new MCTWritableCertStore::Add() on old class..."));
|
sl@0
|
199 |
iOut.writeNewLine();
|
sl@0
|
200 |
|
sl@0
|
201 |
// create a writablestore that does not have new Add()
|
sl@0
|
202 |
TOldCSClasswoDeletable storeOld;
|
sl@0
|
203 |
|
sl@0
|
204 |
// call new Add(), expect to get KErrNotSupported
|
sl@0
|
205 |
storeOld.Add( *iCertificateLabel,
|
sl@0
|
206 |
iCertificateFormat,
|
sl@0
|
207 |
iOwnerType,
|
sl@0
|
208 |
subjectKeyId,
|
sl@0
|
209 |
issuerKeyId,
|
sl@0
|
210 |
*iCertificateContent, // this is probably unset
|
sl@0
|
211 |
iDeletable,
|
sl@0
|
212 |
aStatus);
|
sl@0
|
213 |
iResultGood = ETrue;
|
sl@0
|
214 |
iState = EFinished;
|
sl@0
|
215 |
|
sl@0
|
216 |
TRequestStatus* status = &aStatus;
|
sl@0
|
217 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
218 |
}
|
sl@0
|
219 |
break;
|
sl@0
|
220 |
|
sl@0
|
221 |
|
sl@0
|
222 |
case EFinished:
|
sl@0
|
223 |
{
|
sl@0
|
224 |
|
sl@0
|
225 |
if (aStatus == KErrNone)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
iResult = ETrue;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
else
|
sl@0
|
230 |
if (aStatus == iExpectedResult)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
iResult = ETrue;
|
sl@0
|
233 |
iResultGood = ETrue;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
else
|
sl@0
|
236 |
{
|
sl@0
|
237 |
iResult = EFalse;
|
sl@0
|
238 |
iResultGood = ETrue;
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
if (aStatus != KErrNoMemory)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
iFinished = ETrue;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
TRequestStatus* status = &aStatus;
|
sl@0
|
247 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
248 |
}
|
sl@0
|
249 |
break;
|
sl@0
|
250 |
|
sl@0
|
251 |
default:
|
sl@0
|
252 |
break;
|
sl@0
|
253 |
|
sl@0
|
254 |
} // switch ()
|
sl@0
|
255 |
|
sl@0
|
256 |
} // CTestCertForDeletable::PerformAction()
|
sl@0
|
257 |
|
sl@0
|
258 |
void CTestCertForDeletable::PerformCancel()
|
sl@0
|
259 |
{
|
sl@0
|
260 |
iState = EFinished;
|
sl@0
|
261 |
MCTWritableCertStore& store = UnifiedCertStore().WritableCertStore(iStoreIndex);
|
sl@0
|
262 |
store.CancelAdd();
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
void CTestCertForDeletable::AfterOOMFailure()
|
sl@0
|
266 |
{
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
void CTestCertForDeletable::Reset()
|
sl@0
|
270 |
{
|
sl@0
|
271 |
iState = EFinished;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
void CTestCertForDeletable::DoReportAction()
|
sl@0
|
275 |
{
|
sl@0
|
276 |
iOut.writeString(_L("\tLabel = "));
|
sl@0
|
277 |
iOut.writeString(*iCertificateLabel);
|
sl@0
|
278 |
iOut.writeNewLine();
|
sl@0
|
279 |
iOut.writeString(_L("\tOwner type = "));
|
sl@0
|
280 |
WriteOwnerType();
|
sl@0
|
281 |
WriteFormat(iCertificateFormat);
|
sl@0
|
282 |
|
sl@0
|
283 |
iOut.writeString(_L("\tSubjectKeyId: "));
|
sl@0
|
284 |
iOut.writeOctetString(iSubjectKeyId);
|
sl@0
|
285 |
iOut.writeNewLine();
|
sl@0
|
286 |
|
sl@0
|
287 |
iOut.writeString(_L("\tiDeletable = "));
|
sl@0
|
288 |
iDeletable ? iOut.writeString(KTrue) : iOut.writeString(KFalse);
|
sl@0
|
289 |
iOut.writeNewLine();
|
sl@0
|
290 |
iOut.writeNewLine();
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
void CTestCertForDeletable::WriteFormat(TCertificateFormat aFormat)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
iOut.writeString(_L("\tFormat = "));
|
sl@0
|
296 |
switch (aFormat)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
case EX509Certificate:
|
sl@0
|
299 |
iOut.writeString(_L("X.509\n"));
|
sl@0
|
300 |
break;
|
sl@0
|
301 |
|
sl@0
|
302 |
case EWTLSCertificate:
|
sl@0
|
303 |
iOut.writeString(_L("WTLS\n"));
|
sl@0
|
304 |
break;
|
sl@0
|
305 |
|
sl@0
|
306 |
case EX968Certificate:
|
sl@0
|
307 |
iOut.writeString(_L("X968\n"));
|
sl@0
|
308 |
break;
|
sl@0
|
309 |
|
sl@0
|
310 |
case EX509CertificateUrl:
|
sl@0
|
311 |
iOut.writeString(_L("X.509 URL\n"));
|
sl@0
|
312 |
break;
|
sl@0
|
313 |
|
sl@0
|
314 |
case EWTLSCertificateUrl:
|
sl@0
|
315 |
iOut.writeString(_L("WTLS URL\n"));
|
sl@0
|
316 |
break;
|
sl@0
|
317 |
|
sl@0
|
318 |
case EX968CertificateUrl:
|
sl@0
|
319 |
iOut.writeString(_L("X968 URL\n"));
|
sl@0
|
320 |
break;
|
sl@0
|
321 |
|
sl@0
|
322 |
default:
|
sl@0
|
323 |
iOut.writeString(_L("Unknown format\n"));
|
sl@0
|
324 |
break;
|
sl@0
|
325 |
}
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
void CTestCertForDeletable::WriteOwnerType()
|
sl@0
|
329 |
{
|
sl@0
|
330 |
switch (iOwnerType)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
case ECACertificate:
|
sl@0
|
333 |
iOut.writeString(_L("CA\n"));
|
sl@0
|
334 |
break;
|
sl@0
|
335 |
|
sl@0
|
336 |
case EUserCertificate:
|
sl@0
|
337 |
iOut.writeString(_L("User"));
|
sl@0
|
338 |
break;
|
sl@0
|
339 |
|
sl@0
|
340 |
case EPeerCertificate:
|
sl@0
|
341 |
iOut.writeString(_L("Peer"));
|
sl@0
|
342 |
break;
|
sl@0
|
343 |
|
sl@0
|
344 |
default:
|
sl@0
|
345 |
iOut.writeString(_L("Unknown"));
|
sl@0
|
346 |
break;
|
sl@0
|
347 |
}
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
CTestCertForDeletable::CTestCertForDeletable(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
351 |
Output& aOut)
|
sl@0
|
352 |
: CCertStoreTestAction(aFs, aConsole, aOut), iState(EFinished)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
void CTestCertForDeletable::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
357 |
{
|
sl@0
|
358 |
CCertStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
359 |
|
sl@0
|
360 |
SetCertFormatL(Input::ParseElement(aTestActionSpec.iActionBody, KCertFormatStart));
|
sl@0
|
361 |
SetCertOwnerTypeL(Input::ParseElement(aTestActionSpec.iActionBody, KCertOwnerTypeStart));
|
sl@0
|
362 |
SetCertLabelL(Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart));
|
sl@0
|
363 |
SetKeyId(iIssuerKeyId, Input::ParseElement(aTestActionSpec.iActionBody, KIssuerKeyStart));
|
sl@0
|
364 |
SetKeyId(iSubjectKeyId, Input::ParseElement(aTestActionSpec.iActionBody, KSubjectKeyStart));
|
sl@0
|
365 |
SetStoreToUse(Input::ParseElement(aTestActionSpec.iActionBody, KStoreToUseStart));
|
sl@0
|
366 |
SetDeletable(Input::ParseElement(aTestActionSpec.iActionBody, KDeletableStart));
|
sl@0
|
367 |
SetSubActionL(Input::ParseElement(aTestActionSpec.iActionBody, KSubActionStart));
|
sl@0
|
368 |
|
sl@0
|
369 |
// Setting the expected result
|
sl@0
|
370 |
HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
|
sl@0
|
371 |
TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
|
sl@0
|
372 |
Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
|
sl@0
|
373 |
CleanupStack::PopAndDestroy(result);
|
sl@0
|
374 |
}
|
sl@0
|
375 |
|
sl@0
|
376 |
void CTestCertForDeletable::SetKeyId(TKeyIdentifier& aKeyIdentifier, const TDesC8& aKeyInfo)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
TInt size = aKeyInfo.Length();
|
sl@0
|
379 |
for (TInt i = 0; i < size; i += 2)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
TInt a = (aKeyInfo[i+1] >= 'a') ? (aKeyInfo[i+1] - 'a' + 10) : (aKeyInfo[i+1] - '0');
|
sl@0
|
382 |
TInt b = (aKeyInfo[i] >= 'a') ? (aKeyInfo[i] - 'a' + 10) : (aKeyInfo[i] - '0');
|
sl@0
|
383 |
aKeyIdentifier.Append(a + b * 16);
|
sl@0
|
384 |
}
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
void CTestCertForDeletable::SetCertFormatL(const TDesC8& aFormat)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
if (aFormat == KX509)
|
sl@0
|
390 |
{
|
sl@0
|
391 |
iCertificateFormat = EX509Certificate;
|
sl@0
|
392 |
}
|
sl@0
|
393 |
else if (aFormat == KWTLS)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
iCertificateFormat = EWTLSCertificate;
|
sl@0
|
396 |
}
|
sl@0
|
397 |
else if (aFormat == KX968)
|
sl@0
|
398 |
{
|
sl@0
|
399 |
iCertificateFormat = EX968Certificate;
|
sl@0
|
400 |
}
|
sl@0
|
401 |
else if (aFormat == KX509URL)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
iCertificateFormat = EX509CertificateUrl;
|
sl@0
|
404 |
}
|
sl@0
|
405 |
else if (aFormat == KWTLSURL)
|
sl@0
|
406 |
{
|
sl@0
|
407 |
iCertificateFormat = EWTLSCertificateUrl;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
else if (aFormat == KX968URL)
|
sl@0
|
410 |
{
|
sl@0
|
411 |
iCertificateFormat = EX968CertificateUrl;
|
sl@0
|
412 |
}
|
sl@0
|
413 |
else if (aFormat == KUnknown)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
iCertificateFormat = EUnknownCertificate;
|
sl@0
|
416 |
}
|
sl@0
|
417 |
else
|
sl@0
|
418 |
{
|
sl@0
|
419 |
iOut.write(_L("Unrecognized cert format: "));
|
sl@0
|
420 |
iOut.writeString(aFormat);
|
sl@0
|
421 |
iOut.writeNewLine();
|
sl@0
|
422 |
User::Leave(KErrArgument);
|
sl@0
|
423 |
}
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
void CTestCertForDeletable::SetCertOwnerTypeL(const TDesC8& aOwnerType)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
if (aOwnerType == KCACert)
|
sl@0
|
429 |
{
|
sl@0
|
430 |
iOwnerType = ECACertificate;
|
sl@0
|
431 |
}
|
sl@0
|
432 |
else if (aOwnerType == KUserCert)
|
sl@0
|
433 |
{
|
sl@0
|
434 |
iOwnerType = EUserCertificate;
|
sl@0
|
435 |
}
|
sl@0
|
436 |
else if (aOwnerType == KPeerCert)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
iOwnerType = EPeerCertificate;
|
sl@0
|
439 |
}
|
sl@0
|
440 |
else if (aOwnerType == KUnknown)
|
sl@0
|
441 |
{
|
sl@0
|
442 |
// set dummy bogus owner type
|
sl@0
|
443 |
iOwnerType = static_cast<TCertificateOwnerType>(EPeerCertificate + 1);
|
sl@0
|
444 |
}
|
sl@0
|
445 |
else
|
sl@0
|
446 |
{
|
sl@0
|
447 |
iOut.write(_L("Unknown cert owner type: "));
|
sl@0
|
448 |
iOut.writeString(aOwnerType);
|
sl@0
|
449 |
iOut.writeNewLine();
|
sl@0
|
450 |
User::Leave(KErrArgument);
|
sl@0
|
451 |
}
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
void CTestCertForDeletable::SetSubActionL(const TDesC8& aStringVal)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
if (aStringVal == KTestSerialization)
|
sl@0
|
457 |
{
|
sl@0
|
458 |
iState = ETestSerialization;
|
sl@0
|
459 |
}
|
sl@0
|
460 |
else if (aStringVal == KTestNewCSClasswDeletable)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
iState = ETestNewCSClasswDeletable;
|
sl@0
|
463 |
}
|
sl@0
|
464 |
else if (aStringVal == KTestOldCSClasswoDeletable)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
iState = ETestOldCSClasswoDeletable;
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
else
|
sl@0
|
470 |
{
|
sl@0
|
471 |
iOut.write(_L("Unknown subaction type: "));
|
sl@0
|
472 |
iOut.writeString(aStringVal);
|
sl@0
|
473 |
iOut.writeNewLine();
|
sl@0
|
474 |
User::Leave(KErrArgument);
|
sl@0
|
475 |
}
|
sl@0
|
476 |
}
|
sl@0
|
477 |
|
sl@0
|
478 |
|
sl@0
|
479 |
void CTestCertForDeletable::SetCertLabelL(const TDesC8& aLabel)
|
sl@0
|
480 |
{
|
sl@0
|
481 |
delete iCertificateLabel;
|
sl@0
|
482 |
iCertificateLabel = NULL;
|
sl@0
|
483 |
iCertificateLabel = HBufC::NewL(aLabel.Length());
|
sl@0
|
484 |
TPtr ptr = iCertificateLabel->Des();
|
sl@0
|
485 |
ptr.Copy(aLabel);
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
|
sl@0
|
489 |
|
sl@0
|
490 |
void CTestCertForDeletable::SetStoreToUse(const TDesC8& aStoreToUse)
|
sl@0
|
491 |
{
|
sl@0
|
492 |
TLex8 lex(aStoreToUse);
|
sl@0
|
493 |
lex.Val(iStoreIndex);
|
sl@0
|
494 |
}
|
sl@0
|
495 |
|
sl@0
|
496 |
void CTestCertForDeletable::SetDeletable(const TDesC8& aStringVal)
|
sl@0
|
497 |
{
|
sl@0
|
498 |
TLex8 lex(aStringVal);
|
sl@0
|
499 |
lex.Val(iDeletable);
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
void CTestCertForDeletable::SetCertificateContentL(const TDesC8& aFileName)
|
sl@0
|
503 |
{
|
sl@0
|
504 |
TFileName fileName;
|
sl@0
|
505 |
fileName.Copy(aFileName);
|
sl@0
|
506 |
RFs fs;
|
sl@0
|
507 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
508 |
CleanupClosePushL(fs);
|
sl@0
|
509 |
__ASSERT_DEBUG(!iCertificateContent, User::Panic(_L("CTestCertForDeletable"), 1));
|
sl@0
|
510 |
TRAPD(err, iCertificateContent = Input::ReadFileL(fileName, fs));
|
sl@0
|
511 |
if (err != KErrNone)
|
sl@0
|
512 |
{
|
sl@0
|
513 |
iConsole.Printf(_L("Error reading file : "));
|
sl@0
|
514 |
iConsole.Printf(fileName);
|
sl@0
|
515 |
iConsole.Printf(_L("\n"));
|
sl@0
|
516 |
User::Leave(err);
|
sl@0
|
517 |
}
|
sl@0
|
518 |
CleanupStack::PopAndDestroy(); // fs
|
sl@0
|
519 |
}
|
sl@0
|
520 |
|
sl@0
|
521 |
void CTestCertForDeletable::ConstructCertL(const TDesC8& aCert)
|
sl@0
|
522 |
{
|
sl@0
|
523 |
TFileName filename;
|
sl@0
|
524 |
filename.Copy(aCert);
|
sl@0
|
525 |
RFs fs;
|
sl@0
|
526 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
527 |
CleanupClosePushL(fs);
|
sl@0
|
528 |
HBufC8* certBuf = 0;
|
sl@0
|
529 |
TRAPD(err, certBuf = Input::ReadFileL(filename, fs));
|
sl@0
|
530 |
if (err != KErrNone)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
iConsole.Printf(_L("Error reading file : "));
|
sl@0
|
533 |
iConsole.Printf(filename);
|
sl@0
|
534 |
iConsole.Printf(_L("\n"));
|
sl@0
|
535 |
User::Leave(err);
|
sl@0
|
536 |
}
|
sl@0
|
537 |
CleanupStack::PushL(certBuf);
|
sl@0
|
538 |
switch (iCertificateFormat)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
case EX509Certificate:
|
sl@0
|
541 |
iCertificate = CX509Certificate::NewL(*certBuf);
|
sl@0
|
542 |
break;
|
sl@0
|
543 |
|
sl@0
|
544 |
case EWTLSCertificate:
|
sl@0
|
545 |
iCertificate = CWTLSCertificate::NewL(*certBuf);
|
sl@0
|
546 |
break;
|
sl@0
|
547 |
|
sl@0
|
548 |
default:
|
sl@0
|
549 |
// Unknown format - do nothing
|
sl@0
|
550 |
break;
|
sl@0
|
551 |
}
|
sl@0
|
552 |
CleanupStack::PopAndDestroy(2); // fs and certBuf
|
sl@0
|
553 |
}
|
sl@0
|
554 |
|
sl@0
|
555 |
void CTestCertForDeletable::DoCheckResult(TInt aError)
|
sl@0
|
556 |
{
|
sl@0
|
557 |
if (iFinished)
|
sl@0
|
558 |
{
|
sl@0
|
559 |
if (iResult && !iResultGood)
|
sl@0
|
560 |
{
|
sl@0
|
561 |
iConsole.Write(_L("\ttestcertfordeletable failed\n"));
|
sl@0
|
562 |
iOut.writeString(_L("\ttestcertfordeletable failed"));
|
sl@0
|
563 |
iOut.writeNewLine();
|
sl@0
|
564 |
iOut.writeNewLine();
|
sl@0
|
565 |
}
|
sl@0
|
566 |
else if (iResult)
|
sl@0
|
567 |
{
|
sl@0
|
568 |
iConsole.Write(_L("\ttestcertfordeletable passed ok\n"));
|
sl@0
|
569 |
iOut.writeString(_L("\ttestcertfordeletable passed ok"));
|
sl@0
|
570 |
iOut.writeNewLine();
|
sl@0
|
571 |
iOut.writeNewLine();
|
sl@0
|
572 |
}
|
sl@0
|
573 |
else
|
sl@0
|
574 |
{
|
sl@0
|
575 |
iConsole.Write(_L("\tcertinfo couldn't be tested\n"));
|
sl@0
|
576 |
iOut.writeString(_L("\tcertinfo couldn't be tested"));
|
sl@0
|
577 |
iOut.writeNewLine();
|
sl@0
|
578 |
iOut.writeString(_L("\t"));
|
sl@0
|
579 |
iOut.writeError(aError);
|
sl@0
|
580 |
if (aError == KErrBadName)
|
sl@0
|
581 |
{
|
sl@0
|
582 |
iOut.writeString(_L(" - Check that the label is unique"));
|
sl@0
|
583 |
}
|
sl@0
|
584 |
if (aError == KErrAccessDenied)
|
sl@0
|
585 |
{
|
sl@0
|
586 |
iOut.writeString(_L(" - Can't open filestream. Access denied."));
|
sl@0
|
587 |
}
|
sl@0
|
588 |
iOut.writeNewLine();
|
sl@0
|
589 |
iOut.writeNewLine();
|
sl@0
|
590 |
}
|
sl@0
|
591 |
}
|
sl@0
|
592 |
}
|