1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/TSecureFBS.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,361 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <f32file.h>
1.20 +#include <fbs.h>
1.21 +#include <bitmap.h>
1.22 +#include <bautils.h>
1.23 +#include "../sfbs/UTILS.H"
1.24 +#include "TSecureFBS.h"
1.25 +
1.26 +
1.27 +
1.28 +LOCAL_C RFs fs;
1.29 +
1.30 +//----------------------TEST DATA-------------------------------------
1.31 +//RC_ROM12 is a ROM type mbm
1.32 +//RC_RAM16 is a File Store type mbm
1.33 +//TFBS inside TFBS_RSC is a File Store type mbm
1.34 +//Bitmap for testing purposes
1.35 +_LIT(KBmp1_Z,"z:\\system\\data\\RC_ROM12.mbm");
1.36 +_LIT(KBmp2_Z,"z:\\system\\data\\RC_RAM16.mbm");
1.37 +
1.38 +//Private path in C:
1.39 +_LIT(KBmp2_CP,"c:\\private\\10273364\\RC_RAM16.mbm");
1.40 +//Private path in Z:
1.41 +_LIT(KBmp1_ZP,"z:\\private\\10273364\\RC_ROM12.mbm");
1.42 +_LIT(KBmp2_ZP,"z:\\private\\10273364\\RC_RAM16.mbm");
1.43 +_LIT(KRscHeader_ZP,"z:\\private\\10273364\\RscHeader3.bin");
1.44 +_LIT(KDummyRsc_ZP,"z:\\private\\10273364\\DummyRscFile3.rsc");
1.45 +_LIT(KTbsRsc_ZP,"z:\\private\\10273364\\TFBS_RSC.rsc");
1.46 +_LIT(KInvalid_Bitmap,"z:\\private\\10273364\\invalid.mbm");
1.47 +
1.48 +//Other private path 00999999 used for data caging test
1.49 +_LIT(KBmp1_ZOP,"z:\\private\\00999999\\RC_ROM12.mbm");
1.50 +_LIT(KBmp2_ZOP,"z:\\private\\00999999\\RC_RAM16.mbm");
1.51 +
1.52 +_LIT(KPlatsecBegin,"*PlatSec* ERROR - BEGIN NEGATIVE PLATSEC TESTING");
1.53 +_LIT(KPlatsecEnd,"*PlatSec* ERROR - END NEGATIVE PLATSEC TESTING");
1.54 +//---------------------------------------------------------------------
1.55 +
1.56 +CTFbsSecure::CTFbsSecure(CTestStep* aStep) :
1.57 + CTGraphicsBase(aStep)
1.58 + {
1.59 +
1.60 + }
1.61 +
1.62 +//--------------------UTILITY Function---------------------------------
1.63 +//This function is here to measure the offset in the rsc file
1.64 +TInt CTFbsSecure::FileSizeL(const TDesC& aFileName)
1.65 + {
1.66 + RFile file;
1.67 + User::LeaveIfError(file.Open(fs, aFileName, EFileRead));
1.68 + CleanupClosePushL(file);
1.69 + TInt size = 0;
1.70 + User::LeaveIfError(file.Size(size));
1.71 + CleanupStack::PopAndDestroy(&file);
1.72 + return size;
1.73 + }
1.74 +
1.75 +//--------------------TEST CASE Function-------------------------------
1.76 +/**
1.77 +
1.78 +-Using two type of bitmaps Rom and File Store Bitmap
1.79 +-Testing will focus on File Store type bitmap only
1.80 +-Loading a bitmap in private data cage, expect KErrNone
1.81 +-Loading a bitmap in other private data cage, expect KErrPermissionDenied(-46)
1.82 +-Loading a bitmap from a public path, expect KErrNone
1.83 +-Loading a bitmap from an rsc file inside the private data path
1.84 +*/
1.85 +/**
1.86 + @SYMTestCaseID
1.87 + GRAPHICS-FBSERV-0585
1.88 +
1.89 + @SYMTestCaseDesc
1.90 + TestCase1 for testing data caging properties.
1.91 +
1.92 + @SYMTestActions
1.93 + Using two type of bitmaps Rom and File Store Bitmap.
1.94 + Testing will focus on File Store type bitmap only.
1.95 + Loading a bitmap in private data cage, expect KErrNone.
1.96 + Loading a bitmap in other private data cage, expect KErrPermissionDenied(-46).
1.97 + Loading a bitmap from a public path, expect KErrNone.
1.98 + Loading a bitmap from an rsc file inside the private data path.
1.99 +
1.100 + @SYMTestExpectedResults
1.101 + Test should pass
1.102 +*/
1.103 +void CTFbsSecure::TestCase1()
1.104 + {
1.105 + INFO_PRINTF1(_L("Test Case 1"));
1.106 + TInt skipRomBitmapTests = EFalse;
1.107 + TUint32* romAddress = NULL;
1.108 + if(!CFbsBitmap::IsFileInRom(KBmp1_ZP, romAddress)) //any ROM bitmap
1.109 + {
1.110 + INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
1.111 + &KBmp1_ZP);
1.112 + INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
1.113 + skipRomBitmapTests = ETrue;
1.114 + }
1.115 +
1.116 + TInt ret;
1.117 + if(!skipRomBitmapTests)
1.118 + {
1.119 + //Loading a ROM bitmap from its own private data cage \private\00099999
1.120 + CFbsBitmap bmp1;
1.121 + ret=bmp1.Load(KBmp1_ZP,0);
1.122 + TEST(ret==KErrNone);
1.123 + TEST(bmp1.IsRomBitmap());
1.124 +
1.125 + //Loading a ROM bitmap from other private data cage \private\00999999
1.126 + //This test works if PlatSecEnforcement is ON otherwise it will return KErrNone
1.127 + CFbsBitmap bmp2;
1.128 + ret=bmp2.Load(KBmp1_ZOP,0);
1.129 + if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles))
1.130 + TEST(ret==KErrPermissionDenied);
1.131 + else
1.132 + TEST(ret==KErrNone);
1.133 +
1.134 + //Loading a ROM bitmap from a public data cage \system\data
1.135 + CFbsBitmap bmp3;
1.136 + ret=bmp3.Load(KBmp1_Z,0);
1.137 + TEST(ret==KErrNone);
1.138 + }
1.139 +
1.140 + //Loading a File Store bitmap from its own private data cage \private\00099999
1.141 + CFbsBitmap bmp4;
1.142 + ret=bmp4.Load(KBmp2_ZP,0);
1.143 + TEST(ret==KErrNone);
1.144 + TEST(!bmp4.IsRomBitmap());
1.145 +
1.146 + //Loading a File Store bitmap from other own private data cage \private\00099999
1.147 + CFbsBitmap bmp5;
1.148 + ret=bmp5.Load(KBmp2_ZOP,0);
1.149 + if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles))
1.150 + TEST(ret==KErrPermissionDenied);
1.151 + else
1.152 + TEST(ret==KErrNone);
1.153 +
1.154 + //Loading a File Store bitmap from a public data cage \system\data
1.155 + CFbsBitmap bmp6;
1.156 + ret=bmp6.Load(KBmp2_Z,0);
1.157 + TEST(ret==KErrNone);
1.158 +
1.159 + //Loading a bitmap file from an rsc file inside the private data path
1.160 + CFbsBitmap bmp7;
1.161 + TInt fileoffset=0;
1.162 + //Getting the file offset for the mbm file embedded inside the rsc
1.163 + TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP));
1.164 + TEST(ret==KErrNone);
1.165 + ret=bmp7.Load(KTbsRsc_ZP,0,EFalse,fileoffset);
1.166 + TEST(ret==KErrNone);
1.167 +
1.168 + //Loading a File Store bitmap from own private data cage in C:
1.169 + CFbsBitmap bmp8;
1.170 + ret=bmp8.Load(KBmp2_CP,0);
1.171 + TEST(ret==KErrNone);
1.172 + }
1.173 +
1.174 +/**
1.175 + @SYMTestCaseID
1.176 + GRAPHICS-FBSERV-0586
1.177 +
1.178 + @SYMTestCaseDesc
1.179 + TestCase2 for testing of invalid arguments such as file name,id, file offset
1.180 +
1.181 + @SYMTestActions
1.182 + Test focus on File Store bitmap
1.183 + Loading an invalid bitmap file name expect KErrNotFound
1.184 + Loading a bitmap with invalid id
1.185 + Loading a bitmap with invalid file offset
1.186 +
1.187 + @SYMTestExpectedResults
1.188 + Test should pass
1.189 +*/
1.190 +void CTFbsSecure::TestCase2()
1.191 + {
1.192 + INFO_PRINTF1(_L("Test Case 2"));
1.193 + TInt ret;
1.194 + //Loading an invalid bitmap KInvalid_Bitmap
1.195 + CFbsBitmap bmp1;
1.196 + ret=bmp1.Load(KInvalid_Bitmap,0);
1.197 + TEST(ret==KErrNotFound);
1.198 +
1.199 + //Loading a bitmap with invalid id,KBmp1_ZP only has one bitmap
1.200 + CFbsBitmap bmp2;
1.201 + ret=bmp2.Load(KBmp2_ZP,1);
1.202 + TEST(ret==KErrEof);
1.203 +
1.204 + //Loading a bitmap with invalid File offset
1.205 + CFbsBitmap bmp3;
1.206 + ret=bmp3.Load(KTbsRsc_ZP,0,EFalse,0);
1.207 + TEST(ret==KErrNotSupported);
1.208 + }
1.209 +
1.210 +/**
1.211 +
1.212 +
1.213 +*/
1.214 +/**
1.215 + @SYMTestCaseID
1.216 + GRAPHICS-FBSERV-0587
1.217 +
1.218 + @SYMTestCaseDesc
1.219 + TestCase3 for testing of the sharing of bitmaps using iShareIfLoaded
1.220 + this indirectly test the removal of the FileInfo and yet preserver
1.221 + preserve the same functionality in 9.0 without any regression
1.222 +
1.223 + @SYMTestActions
1.224 + bmp1 load with iShareIfLoaded=ETrue and bmp2 load same file with ETrue
1.225 + Expect the Handle() and DataAddress() to be the same as there will be
1.226 + only one raw memory data stored in the global heap for these 2 instances of
1.227 + the same bitmap
1.228 +
1.229 + bmp3 load with iShareIfLoaded=EFalse and bmp4 load same file with ETrue
1.230 + Expect the Handle() and DataAddress() to be different as bmp1 does not want
1.231 + to share the bitmap,so bmp2 will have its own Handle() and a completely pointer
1.232 + to the bitmap raw data
1.233 +
1.234 + @SYMTestExpectedResults
1.235 + Test should pass
1.236 +*/
1.237 +void CTFbsSecure::TestCase3()
1.238 + {
1.239 + INFO_PRINTF1(_L("Test Case 3"));
1.240 + TInt ret;
1.241 +
1.242 + //Loading first bitmap with ShareIfLoaded
1.243 + CFbsBitmap* bmp1=new (ELeave) CFbsBitmap;
1.244 + ret=bmp1->Load(KBmp2_ZP,0,ETrue);
1.245 + TEST(ret==KErrNone);
1.246 + TEST(!bmp1->IsRomBitmap());
1.247 +
1.248 + //Loading second bitmap with ShareIfLoaded
1.249 + CFbsBitmap* bmp2=new (ELeave) CFbsBitmap;
1.250 + ret-bmp2->Load(KBmp2_ZP,0,ETrue);
1.251 + TEST(ret==KErrNone);
1.252 + TEST(!bmp2->IsRomBitmap());
1.253 +
1.254 + //Test the file sharing properties do exist here
1.255 + TEST(bmp1->Handle()==bmp2->Handle());
1.256 + TEST(bmp1->DataAddress()==bmp2->DataAddress());
1.257 +
1.258 + TInt fileoffset=0;
1.259 + TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP));
1.260 + TEST(ret==KErrNone);
1.261 + //Loading third bitmap with NO ShareIfLoaded
1.262 + CFbsBitmap* bmp3=new (ELeave) CFbsBitmap;
1.263 + ret=bmp3->Load(KTbsRsc_ZP,1,EFalse,fileoffset);
1.264 + TEST(ret==KErrNone);
1.265 + TEST(!bmp3->IsRomBitmap());
1.266 +
1.267 + //Loading fourth bitmap(similar to 3) with ShareIfLoaded
1.268 + CFbsBitmap* bmp4=new (ELeave) CFbsBitmap;
1.269 + ret=bmp4->Load(KTbsRsc_ZP,1,ETrue,fileoffset);
1.270 + TEST(ret==KErrNone);
1.271 + TEST(!bmp4->IsRomBitmap());
1.272 +
1.273 + //Test the file sharing properties does not exist here
1.274 + TEST(bmp3->Handle()!=bmp4->Handle());
1.275 + TEST(bmp3->DataAddress()!=bmp4->DataAddress());
1.276 +
1.277 + delete bmp1;
1.278 + delete bmp2;
1.279 + delete bmp3;
1.280 + delete bmp4;
1.281 +
1.282 + }
1.283 +
1.284 +/**
1.285 +@SYMTestCaseID GRAPHICS-SYSLIB-FBSERV-CT-0002
1.286 +@SYMTestCaseDesc Testing for the secure bitmap loading in FBSERV
1.287 +@SYMTestPriority High
1.288 +@SYMTestActions Testing the loading of a bitmap from its own data cage
1.289 + Testing for permission denied when loading from other private data
1.290 + Testing for invalid arguments
1.291 + Testing for bitmap sharing
1.292 +@SYMTestExpectedResults The test must not fail.
1.293 +@SYMPREQ 280 General Datacaging
1.294 +*/
1.295 +
1.296 +void CTFbsSecure::RunTestCaseL(TInt aCurTestCase)
1.297 + {
1.298 + ((CTFbsSecureStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.299 + switch(aCurTestCase)
1.300 + {
1.301 + case 1:
1.302 + ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0585"));
1.303 + RDebug::Print(KPlatsecBegin);
1.304 + TestCase1();
1.305 + RDebug::Print(KPlatsecEnd);
1.306 + break;
1.307 + case 2:
1.308 + ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0586"));
1.309 + TestCase2();
1.310 + case 3:
1.311 + ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0587"));
1.312 + TestCase3();
1.313 + break;
1.314 + case 4:
1.315 + ((CTFbsSecureStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.316 + ((CTFbsSecureStep*)iStep)->CloseTMSGraphicsStep();
1.317 + TestComplete();
1.318 + break;
1.319 + }
1.320 + ((CTFbsSecureStep*)iStep)->RecordTestResultL();
1.321 + }
1.322 +
1.323 +//--------------
1.324 +__CONSTRUCT_STEP__(FbsSecure)
1.325 +
1.326 +
1.327 +void CTFbsSecureStep::TestSetupL()
1.328 + {
1.329 + User::LeaveIfError(fs.Connect());
1.330 +
1.331 + //Creating secure private path for testing purpose
1.332 + //This should create the private\10099999 directory
1.333 + User::LeaveIfError(fs.CreatePrivatePath(EDriveC));
1.334 +
1.335 + //copying files to the secure path
1.336 + BaflUtils::CopyFile(fs,KBmp2_Z,KBmp2_CP);
1.337 + }
1.338 +
1.339 +void CTFbsSecureStep::TestClose()
1.340 + {
1.341 + //Deleting any bitmaps copied to C:
1.342 + DeleteDataFile(KBmp2_CP);
1.343 + fs.Close();
1.344 + }
1.345 +
1.346 +//This function is here to delete the bitmaps in C after finished with it
1.347 +void CTFbsSecureStep::DeleteDataFile(const TDesC& aFullName)
1.348 + {
1.349 + TEntry entry;
1.350 + if(fs.Entry(aFullName, entry) == KErrNone)
1.351 + {
1.352 + RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
1.353 + TInt err = fs.SetAtt(aFullName, 0, KEntryAttReadOnly);
1.354 + if(err != KErrNone)
1.355 + {
1.356 + RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1.357 + }
1.358 + err = fs.Delete(aFullName);
1.359 + if(err != KErrNone)
1.360 + {
1.361 + RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1.362 + }
1.363 + }
1.364 + }