|
1 /* |
|
2 * Copyright (c) 2004-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 /** |
|
20 @file |
|
21 @test |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #include <test/testexecutelog.h> |
|
26 #include "writablesessionstep.h" |
|
27 #include "sisregistrypackage.h" |
|
28 #include "sisregistrywritableentry.h" |
|
29 #include "sisregistrywritablesession.h" |
|
30 #include "installtypes.h" |
|
31 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
32 #include <usif/sts/sts.h> |
|
33 #else |
|
34 #include "integrityservices.h" |
|
35 #endif |
|
36 #include "cleanuputils.h" |
|
37 #include "dessisdataprovider.h" |
|
38 #include "siscontroller.h" |
|
39 #include "application.h" |
|
40 #include "userselections.h" |
|
41 #include "sisregistryaccess_client.h" |
|
42 |
|
43 _LIT(KUid, "uid"); |
|
44 _LIT(KPackage, "package"); |
|
45 _LIT(KVendor, "vendor"); |
|
46 _LIT(KSisFile, "sis"); |
|
47 |
|
48 using namespace Swi; |
|
49 |
|
50 ///////////////////////////////////////////////////////////////////// |
|
51 // CSisRegistryStep |
|
52 ///////////////////////////////////////////////////////////////////// |
|
53 TVerdict CSisRegistryWritableSessionStep::doTestStepPreambleL() |
|
54 { |
|
55 __UHEAP_MARK; |
|
56 |
|
57 // Install an active scheduler |
|
58 CActiveScheduler* s = new (ELeave) CActiveScheduler; |
|
59 s->Install(s); |
|
60 |
|
61 INFO_PRINTF1(_L("Connecting to SisRegistry..")); |
|
62 User::LeaveIfError(iSisRegistry.Connect()); |
|
63 INFO_PRINTF1(_L("Connected!")); |
|
64 StartTimer(); |
|
65 return TestStepResult(); |
|
66 } |
|
67 |
|
68 TVerdict CSisRegistryWritableSessionStep::doTestStepPostambleL() |
|
69 { |
|
70 StopTimerAndPrintResultL(); |
|
71 // Remove the installed active scheduler |
|
72 CActiveScheduler* s = CActiveScheduler::Current(); |
|
73 s->Install(NULL); |
|
74 delete s; |
|
75 INFO_PRINTF1(_L("Disconnecting to SisRegistry..")); |
|
76 iSisRegistry.Close(); |
|
77 |
|
78 __UHEAP_MARKEND; |
|
79 |
|
80 return TestStepResult(); |
|
81 } |
|
82 |
|
83 ///////////////////////////////////////////////////////////////////// |
|
84 // CPoliceSidsStep - tests specific to Sid access methods |
|
85 ///////////////////////////////////////////////////////////////////// |
|
86 CPoliceSidsStep::CPoliceSidsStep() |
|
87 { |
|
88 SetTestStepName(KPoliceSids); |
|
89 } |
|
90 |
|
91 TVerdict CPoliceSidsStep::doTestStepL() |
|
92 { |
|
93 // this test checks that this client would not be permitted to |
|
94 // perform the operations - the drive state update methods are |
|
95 // particularly important - no caps are required and hence policing on sid |
|
96 // is required. |
|
97 // the attempt to delete registry entries is important as a reassurance that |
|
98 // the both capability and sid based policing are enforced |
|
99 TInt res; |
|
100 SetTestStepResult(EPass); |
|
101 TInt drive = 1; |
|
102 // add drive |
|
103 TRAP(res, iSisRegistry.AddDriveL(drive)); |
|
104 INFO_PRINTF3(_L("Add drive %d returned %d"), drive, res); |
|
105 if (res != KErrPermissionDenied) |
|
106 { |
|
107 SetTestStepResult(EFail); |
|
108 } |
|
109 |
|
110 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
111 // remove drive |
|
112 TRAP(res, iSisRegistry.RemoveDriveL(drive)); |
|
113 INFO_PRINTF3(_L("Remove drive %d returned %d"), drive, res); |
|
114 if (res != KErrPermissionDenied) |
|
115 { |
|
116 SetTestStepResult(EFail); |
|
117 } |
|
118 #endif |
|
119 |
|
120 RPointerArray<CSisRegistryPackage> packages; |
|
121 CleanupResetAndDestroy<RPointerArray<CSisRegistryPackage> >::PushL(packages); |
|
122 |
|
123 iSisRegistry.InstalledPackagesL(packages); |
|
124 |
|
125 for(TInt index = 0; index < packages.Count(); index++) |
|
126 { |
|
127 INFO_PRINTF3(_L("(Vendor Name:) %S (Package Name:) %S"), |
|
128 &packages[index]->Vendor(), |
|
129 &packages[index]->Name()); |
|
130 |
|
131 TRAP(res, iSisRegistry.DeleteEntryL(*packages[index], 0)) |
|
132 INFO_PRINTF3(_L("DeleteEntryL %d returned %d"), index, res); |
|
133 |
|
134 if (res != KErrPermissionDenied) |
|
135 { |
|
136 SetTestStepResult(EFail); |
|
137 } |
|
138 } |
|
139 |
|
140 CleanupStack::PopAndDestroy(&packages); |
|
141 |
|
142 SetTestStepResult(EPass); |
|
143 return TestStepResult(); |
|
144 } |
|
145 |
|
146 ///////////////////////////////////////////////////////////////////// |
|
147 // CWritableEntryMethodsStep - tests specific to entry methods |
|
148 ///////////////////////////////////////////////////////////////////// |
|
149 CWritableEntryMethodsStep::CWritableEntryMethodsStep() |
|
150 { |
|
151 SetTestStepName(KWritableEntryMethods); |
|
152 } |
|
153 |
|
154 TVerdict CWritableEntryMethodsStep::doTestStepL() |
|
155 { |
|
156 RPointerArray<CSisRegistryPackage> packages; |
|
157 CleanupResetAndDestroy<RPointerArray<CSisRegistryPackage> >::PushL(packages); |
|
158 |
|
159 iSisRegistry.InstalledPackagesL(packages); |
|
160 |
|
161 for(TInt index = 0; index < packages.Count(); index++) |
|
162 { |
|
163 INFO_PRINTF3(_L("(Vendor Name:) %S (Package Name:) %S"), |
|
164 &packages[index]->Vendor(), |
|
165 &packages[index]->Name()); |
|
166 |
|
167 Swi::RSisRegistryWritableEntry entry; |
|
168 CleanupClosePushL(entry); |
|
169 TInt res = entry.OpenL(iSisRegistry, *packages[index]); |
|
170 if (res == KErrNone) |
|
171 { |
|
172 PrintWritableEntryContents(entry); |
|
173 } |
|
174 CleanupStack::PopAndDestroy(&entry); |
|
175 } |
|
176 |
|
177 CleanupStack::PopAndDestroy(&packages); |
|
178 |
|
179 SetTestStepResult(EPass); |
|
180 return TestStepResult(); |
|
181 } |
|
182 |
|
183 void CWritableEntryMethodsStep::PrintWritableEntryContents(Swi::RSisRegistryWritableEntry &aEntry) |
|
184 { |
|
185 INFO_PRINTF1(_L("-------------------------------------\n")); |
|
186 // get the vendor; package name |
|
187 HBufC* vendor = aEntry.UniqueVendorNameL(); |
|
188 CleanupStack::PushL(vendor); |
|
189 HBufC* package = aEntry.PackageNameL(); |
|
190 CleanupStack::PushL(package); |
|
191 INFO_PRINTF3(_L("Package: %S from Vendor: %S"), package, vendor); |
|
192 CleanupStack::PopAndDestroy(package); |
|
193 CleanupStack::PopAndDestroy(vendor); |
|
194 |
|
195 // get the localised vendor name |
|
196 HBufC* vendorLocal = aEntry.LocalizedVendorNameL(); |
|
197 CleanupStack::PushL(vendorLocal); |
|
198 INFO_PRINTF2(_L("Localised Vendor Name: %S"), vendorLocal); |
|
199 CleanupStack::PopAndDestroy(vendorLocal); |
|
200 |
|
201 // get uid |
|
202 TUid uid = aEntry.UidL(); |
|
203 INFO_PRINTF3(_L("Package Uid: %d 0x%08x"), uid.iUid, uid.iUid); |
|
204 |
|
205 // get the version |
|
206 TVersion packageVersion = aEntry.VersionL(); |
|
207 INFO_PRINTF4(_L("Version %d %d %d"), packageVersion.iMajor, packageVersion.iMinor, packageVersion.iBuild ); |
|
208 |
|
209 // get sids |
|
210 RArray<TUid> sids; |
|
211 CleanupClosePushL(sids); |
|
212 aEntry.SidsL(sids); |
|
213 if (sids.Count() <= 0) |
|
214 { |
|
215 INFO_PRINTF1(_L("No sids installed!")); |
|
216 } |
|
217 else |
|
218 { |
|
219 for (TInt index = 0; index < sids.Count(); index++) |
|
220 { |
|
221 INFO_PRINTF2(_L("Sid: 0x%08x was found!"), sids[index]); |
|
222 } |
|
223 } |
|
224 CleanupStack::PopAndDestroy(&sids); |
|
225 |
|
226 // get language |
|
227 TLanguage language = aEntry.LanguageL(); |
|
228 INFO_PRINTF3(_L("Package Language: %d 0x%08x"), language, language); |
|
229 |
|
230 // get property |
|
231 TInt32 propertyKey = 10; |
|
232 TInt32 propertyValue = aEntry.PropertyL(propertyKey); |
|
233 INFO_PRINTF3(_L("Package property: key %d value %d"), propertyKey, propertyValue); |
|
234 |
|
235 // is present - currenty relies on default value |
|
236 TBool isPresent = aEntry.IsPresentL(); |
|
237 INFO_PRINTF2(_L("Package present is %d"), isPresent); |
|
238 |
|
239 // is signed |
|
240 TBool isSigned = aEntry.IsSignedL(); |
|
241 INFO_PRINTF2(_L("Package signed is %d"), isSigned); |
|
242 |
|
243 if (isSigned) |
|
244 { |
|
245 RPointerArray<HBufC8> certChains; |
|
246 CleanupResetAndDestroy<RPointerArray<HBufC8> >::PushL(certChains); |
|
247 aEntry.CertificateChainsL(certChains); |
|
248 INFO_PRINTF2(_L("Package signed with %d chains"), certChains.Count()); |
|
249 CleanupStack::PopAndDestroy(&certChains); |
|
250 } |
|
251 |
|
252 // check Trust |
|
253 switch(aEntry.TrustL()) |
|
254 { |
|
255 case ESisPackageUnsignedOrSelfSigned: |
|
256 INFO_PRINTF1(_L("Packaged Trust: Unsigned or self signed")); |
|
257 break; |
|
258 case ESisPackageCertificateChainNoTrustAnchor: |
|
259 INFO_PRINTF1(_L("Packaged Trust: Certificate Chain has no trust anchor in Cert store")); |
|
260 break; |
|
261 case ESisPackageCertificateChainValidatedToTrustAnchor: |
|
262 INFO_PRINTF1(_L("Packaged Trust: Certificate Chain Validated to Trust Anchor in Cert store")); |
|
263 break; |
|
264 case ESisPackageChainValidatedToTrustAnchorOCSPTransientError: |
|
265 INFO_PRINTF1(_L("Packaged Trust: Certificate Chain Validated and OCSP Transient Error")); |
|
266 break; |
|
267 case ESisPackageChainValidatedToTrustAnchorAndOCSPValid: |
|
268 INFO_PRINTF1(_L("Packaged Trust: Certificate Chain Validated and OCSP Valid")); |
|
269 break; |
|
270 case ESisPackageBuiltIntoRom: |
|
271 INFO_PRINTF1(_L("Packaged Trust: Built into ROM")); |
|
272 break; |
|
273 case ESisPackageValidationFailed: |
|
274 INFO_PRINTF1(_L("Packaged Trust: Certificate Chain Validation Failed")); |
|
275 break; |
|
276 default: |
|
277 INFO_PRINTF1(_L("Packaged Trust: Unknown")); |
|
278 break; |
|
279 }; |
|
280 |
|
281 // Time at which the trust was established |
|
282 TTime timeStamp = aEntry.TrustTimeStampL(); |
|
283 TBuf <32> dateTimeText; |
|
284 TRAP_IGNORE(timeStamp.FormatL(dateTimeText, _L("%H%:1%T%:2%S on %1%/1%2%/2%3"))); |
|
285 INFO_PRINTF2(_L("Package Trust Established: %S"), &dateTimeText); |
|
286 |
|
287 |
|
288 // is in rom |
|
289 TBool inRom = aEntry.IsInRomL(); |
|
290 INFO_PRINTF2(_L("Package inRom is %d"), inRom); |
|
291 |
|
292 // is an augmentation |
|
293 TBool isAug = aEntry.IsAugmentationL(); |
|
294 INFO_PRINTF2(_L("Package isAug is %d"), isAug); |
|
295 // is preinstalled |
|
296 /* |
|
297 Sis::TInstallType installType = aEntry.InstallTypeL(); |
|
298 INFO_PRINTF3(_L("Package type is %d %S"), |
|
299 installType, &installTypeNames[installType]); |
|
300 */ |
|
301 // get list of files |
|
302 RPointerArray<HBufC> files; |
|
303 CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(files); |
|
304 aEntry.FilesL(files); |
|
305 INFO_PRINTF2(_L("Package has %d files"), files.Count()); |
|
306 for (TInt i=0; i<files.Count(); i++) |
|
307 { |
|
308 INFO_PRINTF3(_L("File %d - file path %S"), i+1, files[i]); |
|
309 } |
|
310 |
|
311 CleanupStack::PopAndDestroy(&files); |
|
312 |
|
313 // get the drive selected by the user |
|
314 TChar setDrive = aEntry.SelectedDriveL(); |
|
315 TUint setdrive(setDrive); |
|
316 INFO_PRINTF2(_L("User selected drive is %c"), setdrive); |
|
317 |
|
318 INFO_PRINTF1(_L("-------------------------------------\n")); |
|
319 } |
|
320 |
|
321 ///////////////////////////////////////////////////////////////////// |
|
322 // CEntryDeleteUidStep - delete a operation |
|
323 ///////////////////////////////////////////////////////////////////// |
|
324 CEntryDeleteStep::CEntryDeleteStep() |
|
325 { |
|
326 SetTestStepName(KEntryDelete); |
|
327 } |
|
328 |
|
329 TVerdict CEntryDeleteStep::doTestStepL() |
|
330 { |
|
331 SetTestStepResult(EFail); |
|
332 |
|
333 RArray<TUid> deleteUids; |
|
334 CleanupClosePushL(deleteUids); |
|
335 GetUidArrayFromConfigL(ConfigSection(), KUid, deleteUids); |
|
336 |
|
337 RArray<TPtrC> deletePackageNames; |
|
338 CleanupClosePushL(deletePackageNames); |
|
339 GetStringArrayFromConfigL(ConfigSection(), KPackage, deletePackageNames); |
|
340 |
|
341 RArray<TPtrC> deleteVendorNames; |
|
342 CleanupClosePushL(deleteVendorNames); |
|
343 GetStringArrayFromConfigL(ConfigSection(), KVendor, deleteVendorNames); |
|
344 |
|
345 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
346 TInt64 transactionID = -1; |
|
347 Usif::RStsSession stsSession; |
|
348 CleanupClosePushL(stsSession); |
|
349 #else |
|
350 TInt64 transactionID = 1; |
|
351 _LIT(KIntegrityServicesPath, "\\sys\\install\\integrityservices\\"); |
|
352 #endif |
|
353 |
|
354 for (TInt index = 0; index < deleteUids.Count(); index++) |
|
355 { |
|
356 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
357 transactionID = stsSession.CreateTransactionL(); |
|
358 #else |
|
359 CIntegrityServices* integrityService = CIntegrityServices::NewLC(transactionID, KIntegrityServicesPath); |
|
360 #endif |
|
361 INFO_PRINTF3(_L("Transaction %d Deleting registry entry with Uid 0x%08x"), |
|
362 I64LOW(transactionID), deleteUids[index]); |
|
363 |
|
364 CSisRegistryPackage* package = CSisRegistryPackage::NewLC(deleteUids[index], deletePackageNames[index], deleteVendorNames[index]); |
|
365 TRAP_IGNORE(iSisRegistry.DeleteEntryL(*package, transactionID)); |
|
366 CleanupStack::PopAndDestroy(package); |
|
367 |
|
368 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
369 stsSession.CommitL(); |
|
370 #else |
|
371 integrityService->CommitL(); |
|
372 CleanupStack::PopAndDestroy(integrityService); |
|
373 #endif |
|
374 // should not be able to find this entry |
|
375 if(!iSisRegistry.IsInstalledL(deleteUids[index])) |
|
376 { |
|
377 SetTestStepResult(EPass); |
|
378 } |
|
379 } |
|
380 |
|
381 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
382 CleanupStack::PopAndDestroy(4, &deleteUids); //deletePackageNames, deleteVendorNames, stsSession |
|
383 #else |
|
384 CleanupStack::PopAndDestroy(3, &deleteUids); //deletePackageNames, deleteVendorNames |
|
385 #endif |
|
386 return TestStepResult(); |
|
387 } |
|
388 |
|
389 ///////////////////////////////////////////////////////////////////// |
|
390 // CAddEntryStep - Adds a registry entry representing a given package |
|
391 ///////////////////////////////////////////////////////////////////// |
|
392 CAddEntryStep::CAddEntryStep() |
|
393 { |
|
394 SetTestStepName(KAddEntryStep); |
|
395 } |
|
396 |
|
397 TVerdict CAddEntryStep::doTestStepL() |
|
398 { |
|
399 TPtrC sisFile; |
|
400 if(!GetStringFromConfig(ConfigSection(), KSisFile, sisFile)) |
|
401 return PrintErrorAndReturnFailL(_L("SIS file couldn't be found in the configuration!")); |
|
402 |
|
403 HBufC8 *controllerData = GetControllerFromSisLC(sisFile); |
|
404 const TInt controllerOffset = 4; |
|
405 // The registry does not store the first 4 bytes of the controller - see CInstallationProcessor |
|
406 TPtrC8 controllerDataPtr = controllerData->Mid(controllerOffset); |
|
407 |
|
408 RSisRegistryAccessSession sras; |
|
409 User::LeaveIfError(sras.Connect()); |
|
410 CleanupClosePushL(sras); |
|
411 sras.AddEntryL(controllerDataPtr, iTimeMeasuredExternally); |
|
412 CleanupStack::PopAndDestroy(2, controllerData); // controllerData, sras |
|
413 return TestStepResult(); |
|
414 } |
|
415 |
|
416 ///////////////////////////////////////////////////////////////////////////// |
|
417 // CUpdateEntryStep - Updates the registry entry representing a given package |
|
418 ///////////////////////////////////////////////////////////////////////////// |
|
419 CUpdateEntryStep::CUpdateEntryStep() |
|
420 { |
|
421 SetTestStepName(KUpdateEntryStep); |
|
422 } |
|
423 |
|
424 TVerdict CUpdateEntryStep::doTestStepL() |
|
425 { |
|
426 TPtrC sisFile; |
|
427 if(!GetStringFromConfig(ConfigSection(), KSisFile, sisFile)) |
|
428 return PrintErrorAndReturnFailL(_L("SIS file couldn't be found in the configuration!")); |
|
429 |
|
430 HBufC8 *controllerData = GetControllerFromSisLC(sisFile); |
|
431 const TInt controllerOffset = 4; |
|
432 // The registry does not store the first 4 bytes of the controller - see CInstallationProcessor |
|
433 TPtrC8 controllerDataPtr = controllerData->Mid(controllerOffset); |
|
434 |
|
435 RSisRegistryAccessSession sras; |
|
436 User::LeaveIfError(sras.Connect()); |
|
437 CleanupClosePushL(sras); |
|
438 sras.UpdateEntryL(controllerDataPtr, iTimeMeasuredExternally); |
|
439 CleanupStack::PopAndDestroy(2, controllerData); // controllerData, sras |
|
440 return TestStepResult(); |
|
441 } |
|
442 |
|
443 ///////////////////////////////////////////////////////////////////////////// |
|
444 // CSingleEntryDeleteStep - Deletes the registry entry representing a given package uid |
|
445 ///////////////////////////////////////////////////////////////////////////// |
|
446 CSingleEntryDeleteStep::CSingleEntryDeleteStep() |
|
447 { |
|
448 SetTestStepName(KDeleteSingleEntry); |
|
449 } |
|
450 |
|
451 TVerdict CSingleEntryDeleteStep::doTestStepL() |
|
452 { |
|
453 TUid uid; |
|
454 if(!GetUidFromConfig(ConfigSection(), KUid, uid)) |
|
455 return PrintErrorAndReturnFailL(_L("Uid is missing in the configuration file!")); |
|
456 |
|
457 TPtrC package; |
|
458 if(!GetStringFromConfig(ConfigSection(), KPackage, package)) |
|
459 return PrintErrorAndReturnFailL(_L("Package couldn't be found in the configuration!")); |
|
460 |
|
461 TPtrC vendor; |
|
462 if(!GetStringFromConfig(ConfigSection(), KVendor, vendor)) |
|
463 return PrintErrorAndReturnFailL(_L("Vendor couldn't be found in the configuration!")); |
|
464 |
|
465 CSisRegistryPackage *sisPackage = CSisRegistryPackage::NewLC(uid, package, vendor); |
|
466 |
|
467 RSisRegistryAccessSession sras; |
|
468 User::LeaveIfError(sras.Connect()); |
|
469 CleanupClosePushL(sras); |
|
470 sras.DeleteEntryL(*sisPackage, iTimeMeasuredExternally); |
|
471 CleanupStack::PopAndDestroy(2, sisPackage); // sisPackage, sras |
|
472 return TestStepResult(); |
|
473 } |
|
474 |
|
475 ///////////////////////////////////////////////////////////////////////////// |
|
476 // CPackageExistsInRomStep - Returns ETrue if any ROM stub in the filesystem has the package uid specified |
|
477 ///////////////////////////////////////////////////////////////////////////// |
|
478 CPackageExistsInRomStep::CPackageExistsInRomStep() |
|
479 { |
|
480 SetTestStepName(KIsPackageExistInRomStep); |
|
481 } |
|
482 |
|
483 TVerdict CPackageExistsInRomStep::doTestStepL() |
|
484 { |
|
485 TUid uid; |
|
486 if(!GetUidFromConfig(ConfigSection(), KUid, uid)) |
|
487 { |
|
488 ERR_PRINTF1(_L("Uid is missing in the configuration file!")); |
|
489 SetTestStepResult(EFail); |
|
490 return TestStepResult(); |
|
491 } |
|
492 TBool ret = iSisRegistry.PackageExistsInRomL(uid); |
|
493 |
|
494 return TestStepResult(); |
|
495 } |
|
496 |
|
497 |
|
498 |