sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\secure\t_capsup.cpp sl@0: // Overview: sl@0: // Test support of platform security capabilities. sl@0: // API Information: sl@0: // TCapabilitySet, TSecurityInfo, TSecurityPolicy and various other methods. sl@0: // Details: sl@0: // - Verify the enumeration of each of the capability names. sl@0: // - Test the TCapabilitySet class methods by setting and checking various sl@0: // capabilities. Verify results are as expected. sl@0: // - Test the TSecurityInfo class methods and verify results. sl@0: // - Test the RProcess, RThread and RMessage2 SecureId() methods along with sl@0: // User::CreatorSecureId(). Verify results are as expected. sl@0: // - Test the RProcess, RThread and RMessage2 VendorId() methods along with sl@0: // User::CreatorVendorId(). Verify results are as expected. sl@0: // - Test the RProcess, RThread and RMessage2 HasCapability() methods along sl@0: // with User::CreatorHasCapability(). Verify results are as expected. sl@0: // - Test TSecurityPolicy constructors including macros for compile-time sl@0: // construction. Verify results are as expected. sl@0: // - Test kernel APIs. Verify results are as expected. sl@0: // - Test setting KernelConfigFlags. Ensure that, if __PLATSEC_UNLOCKED__ sl@0: // is not set, the PlatSec flags cannot be unset. sl@0: // - Test the use of platform security diagnostic strings. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #define __INCLUDE_CAPABILITY_NAMES__ sl@0: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "d_sldd.h" sl@0: sl@0: TBool PlatSecEnforcement; sl@0: sl@0: _LIT_SECURE_ID(KTestSecureId,0x101f534d); sl@0: _LIT_SECURE_ID(KTestSecureId2,0x101f534e); sl@0: _LIT_VENDOR_ID(KTestVendorId,0x01234567); sl@0: _LIT_VENDOR_ID(KTestVendorId2,0x01234568); sl@0: sl@0: const TUint32 KTestCapabilities =(1< buf(0); sl@0: TInt len = m.GetDesLength(0); sl@0: TInt r = KErrArgument; sl@0: if(len>0 && len <=buf.MaxSize()) sl@0: { sl@0: r = m.Read(0, buf, 0); sl@0: if(r==KErrNone) sl@0: { sl@0: TSecurityPolicy policy; sl@0: r = policy.Set(buf); sl@0: if(r == KErrNone) sl@0: { sl@0: r = policy.CheckPolicy(m, __PLATSEC_DIAGNOSTIC_STRING("Testing message against policy -- sample additional diagnostic.")); sl@0: if(r) sl@0: r = EPolicyCheckPassed; sl@0: else sl@0: r = EPolicyCheckFailed; sl@0: } sl@0: } sl@0: } sl@0: m.Complete(r); sl@0: break; sl@0: } sl@0: sl@0: case CTestSession::ETestSecurityPolicyAgainstCreator: sl@0: { sl@0: TBuf8 buf(0); sl@0: TInt len = m.GetDesLength(0); sl@0: TInt r = KErrArgument; sl@0: if(len>0 && len <=buf.MaxSize()) sl@0: { sl@0: r = m.Read(0, buf, 0); sl@0: if(r==KErrNone) sl@0: { sl@0: TSecurityPolicy policy; sl@0: r = policy.Set(buf); sl@0: if(r == KErrNone) sl@0: { sl@0: r = policy.CheckPolicyCreator(__PLATSEC_DIAGNOSTIC_STRING("Testing creator against policy -- sample additional diagnostic.")); sl@0: if(r) sl@0: r = EPolicyCheckPassed; sl@0: else sl@0: r = EPolicyCheckFailed; sl@0: } sl@0: } sl@0: } sl@0: m.Complete(r); sl@0: break; sl@0: } sl@0: sl@0: case CTestSession::EShutdown: sl@0: CActiveScheduler::Stop(); sl@0: break; sl@0: sl@0: default: sl@0: m.Complete(KErrNotSupported); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // CTestServer sl@0: // sl@0: sl@0: class CTestServer : public CServer2 sl@0: { sl@0: public: sl@0: CTestServer(TInt aPriority); sl@0: virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; sl@0: }; sl@0: sl@0: CTestServer::CTestServer(TInt aPriority) sl@0: : CServer2(aPriority) sl@0: { sl@0: } sl@0: sl@0: CSession2* CTestServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const sl@0: { sl@0: return new (ELeave) CTestSession(); sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // CTestActiveScheduler sl@0: // sl@0: sl@0: class CTestActiveScheduler : public CActiveScheduler sl@0: { sl@0: public: sl@0: virtual void Error(TInt anError) const; sl@0: }; sl@0: sl@0: void CTestActiveScheduler::Error(TInt anError) const sl@0: { sl@0: User::Panic(_L("TestServer Error"),anError); sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // Server thread sl@0: // sl@0: sl@0: _LIT(KServerName,"T_CAPSUP-server"); sl@0: const TInt KServerRendezvous = KRequestPending+1; sl@0: sl@0: void DoStartServer() sl@0: { sl@0: CTestActiveScheduler* activeScheduler = new (ELeave) CTestActiveScheduler; sl@0: CActiveScheduler::Install(activeScheduler); sl@0: CleanupStack::PushL(activeScheduler); sl@0: sl@0: CTestServer* server = new (ELeave) CTestServer(0); sl@0: CleanupStack::PushL(server); sl@0: sl@0: User::LeaveIfError(server->Start(KServerName)); sl@0: sl@0: RProcess::Rendezvous(KServerRendezvous); sl@0: sl@0: CActiveScheduler::Start(); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: TInt StartServer() sl@0: { sl@0: CTrapCleanup* cleanupStack = CTrapCleanup::New(); sl@0: if(!cleanupStack) sl@0: return KErrNoMemory; sl@0: TRAPD(leaveError,DoStartServer()) sl@0: delete cleanupStack; sl@0: return leaveError; sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // RTestSession sl@0: // sl@0: sl@0: class RTestSession : public RSessionBase sl@0: { sl@0: public: sl@0: inline TInt Connect() sl@0: { return CreateSession(KServerName,TVersion());} sl@0: inline TInt Send(TInt aFunction) sl@0: { return RSessionBase::SendReceive(aFunction); } sl@0: inline TInt Send(TInt aFunction,const TIpcArgs& aArgs) sl@0: { return RSessionBase::SendReceive(aFunction,aArgs); } sl@0: inline void Send(TInt aFunction,TRequestStatus& aStatus) sl@0: { RSessionBase::SendReceive(aFunction,aStatus); } sl@0: inline void Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) sl@0: { RSessionBase::SendReceive(aFunction,aArgs,aStatus); } sl@0: }; sl@0: sl@0: sl@0: sl@0: RTestSession Session; sl@0: sl@0: void CheckCapabilitySetEqual(const TCapabilitySet& a1,const TCapabilitySet& a2) sl@0: { sl@0: TInt i; sl@0: for(i=0; i=-2; j--) // Add each capability in reverse sequence sl@0: { sl@0: s.AddCapability((TCapability)j); sl@0: for(i=ECapability_HardLimit-1; i>=j && i>=0; i--) sl@0: test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities) sl@0: for(; i>=0; i--) sl@0: test(!s.HasCapability((TCapability)i)); sl@0: test(!s.HasCapability(ECapability_Denied)); sl@0: test(s.HasCapability(ECapability_None)); sl@0: } sl@0: sl@0: test.Next(_L("Test RemoveCapability(TCapability)")); sl@0: s.SetAllSupported(); sl@0: for(j=-2; j=-2; j--) // Remove each capability reverse sequence sl@0: { sl@0: s.RemoveCapability((TCapability)j); sl@0: for(i=ECapability_HardLimit-1; i>=j && i >=0; i--) sl@0: test(!s.HasCapability((TCapability)i)); sl@0: for(; i>=0; i--) sl@0: test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities) sl@0: test(!s.HasCapability(ECapability_Denied)); sl@0: test(s.HasCapability(ECapability_None)); sl@0: } sl@0: sl@0: test.Next(_L("Building test sets")); sl@0: TCapabilitySet even; sl@0: even.SetEmpty(); sl@0: for(i=0; i infoPtr(info); sl@0: TInt i; sl@0: sl@0: test.Start(_L("Test TSecurityInfo::SetToCurrentInfo")); sl@0: self.SetToCurrentInfo(); sl@0: test(self.iSecureId==KTestSecureId); sl@0: test(self.iVendorId==KTestVendorId); sl@0: for(i=0; i>i)&1)); sl@0: sl@0: test.Next(_L("Test TSecurityInfo::Set(RProcess)")); sl@0: Mem::FillZ(&info,sizeof(info)); sl@0: TInt32 r = Session.Send(CTestSession::ETestProcessSecurityInfo,TIpcArgs(TUint(RProcess().Id()),&infoPtr)); sl@0: test(r==KErrNone); sl@0: CheckSecurityInfo(self,info); sl@0: sl@0: test.Next(_L("Test TSecurityInfo::Set(RThread)")); sl@0: Mem::FillZ(&info,sizeof(info)); sl@0: r = Session.Send(CTestSession::ETestThreadSecurityInfo,TIpcArgs(TUint(RThread().Id()),&infoPtr)); sl@0: test(r==KErrNone); sl@0: CheckSecurityInfo(self,info); sl@0: sl@0: test.Next(_L("Test TSecurityInfo::Set(RMessagePtr2)")); sl@0: Mem::FillZ(&info,sizeof(info)); sl@0: r = Session.Send(CTestSession::ETestMessageSecurityInfo,TIpcArgs(&infoPtr)); sl@0: test(r==KErrNone); sl@0: CheckSecurityInfo(self,info); sl@0: sl@0: test.Next(_L("Test TSecurityInfo::SetToCreatorInfo")); sl@0: Mem::FillZ(&info,sizeof(info)); sl@0: r = Session.Send(CTestSession::ETestCreatorSecurityInfo,TIpcArgs(&infoPtr)); sl@0: test(r==KErrNone); sl@0: CheckSecurityInfo(self,info); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void TestSecureId() sl@0: { sl@0: test.Start(_L("Test RProcess::SecureId()")); sl@0: TInt r = Session.Send(CTestSession::ETestProcessSecureId,TIpcArgs(TUint(RProcess().Id()))); sl@0: test((TUint32)r==KTestSecureId); sl@0: sl@0: test.Next(_L("Test RThread::SecureId()")); sl@0: r = Session.Send(CTestSession::ETestThreadSecureId,TIpcArgs(TUint(RThread().Id()))); sl@0: test((TUint32)r==KTestSecureId); sl@0: sl@0: test.Next(_L("Test RMessage2::SecureId()")); sl@0: r = Session.Send(CTestSession::ETestMessageSecureId); sl@0: test((TUint32)r==KTestSecureId); sl@0: sl@0: test.Next(_L("Test User::CreatorSecureId()")); sl@0: r = Session.Send(CTestSession::ETestCreatorSecureId); sl@0: test((TUint32)r==KTestSecureId); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void TestVendorId() sl@0: { sl@0: test.Start(_L("Test RProcess::VendorId()")); sl@0: TInt r = Session.Send(CTestSession::ETestProcessVendorId,TIpcArgs(TUint(RProcess().Id()))); sl@0: test((TUint32)r==KTestVendorId); sl@0: sl@0: test.Next(_L("Test RThread::VendorId()")); sl@0: r = Session.Send(CTestSession::ETestThreadVendorId,TIpcArgs(TUint(RThread().Id()))); sl@0: test((TUint32)r==KTestVendorId); sl@0: sl@0: test.Next(_L("Test RMessage2::VendorId()")); sl@0: r = Session.Send(CTestSession::ETestMessageVendorId); sl@0: test((TUint32)r==KTestVendorId); sl@0: sl@0: test.Next(_L("Test User::CreatorVendorId()")); sl@0: r = Session.Send(CTestSession::ETestCreatorVendorId); sl@0: test((TUint32)r==KTestVendorId); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void TestHasCapability() sl@0: { sl@0: TInt failResult=PlatSecEnforcement ? 0 : 1; sl@0: TInt failResultL=PlatSecEnforcement ? KErrPermissionDenied : KErrNone; sl@0: sl@0: test.Start(_L("Test RProcess::HasCapability(TCapability)")); sl@0: TInt r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapabilityLocalServices)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapabilityNetworkServices)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapability_None)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapability_Denied)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test RProcess::HasCapability(TCapability,TCapability)")); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityLocalServices,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityNetworkServices,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityLocalServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityNetworkServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapability_None,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapability_Denied,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test RThread::HasCapability(TCapability)")); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapabilityLocalServices)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapabilityNetworkServices)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapability_None)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapability_Denied)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test RThread::HasCapability(TCapability,TCapability)")); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityLocalServices,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityNetworkServices,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityLocalServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityNetworkServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapability_None,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapability_Denied,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test RMessagePtr2::HasCapability(TCapability)")); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapabilityLocalServices)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapabilityNetworkServices)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapability_None)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapability_Denied)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test RMessagePtr2::HasCapabilityL(TCapability)")); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapabilityLocalServices)); sl@0: test(r==KErrNone); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapabilityNetworkServices)); sl@0: test(r==failResultL); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapability_None)); sl@0: test(r==KErrNone); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapability_Denied)); sl@0: test(r==failResultL); sl@0: sl@0: test.Next(_L("Test RMessagePtr2::HasCapability(TCapability,TCapability)")); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapability_None,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapability_Denied,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test RMessagePtr2::HasCapabilityL(TCapability,TCapability)")); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityLocalServices,ECapabilityWriteUserData)); sl@0: test(r==KErrNone); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityNetworkServices,ECapabilityWriteUserData)); sl@0: test(r==failResultL); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityLocalServices,ECapabilityReadUserData)); sl@0: test(r==failResultL); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityNetworkServices,ECapabilityReadUserData)); sl@0: test(r==failResultL); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapability_None,ECapabilityWriteUserData)); sl@0: test(r==KErrNone); sl@0: r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapability_Denied,ECapabilityWriteUserData)); sl@0: test(r==failResultL); sl@0: sl@0: test.Next(_L("Test User::CreatorHasCapability(TCapability)")); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapabilityLocalServices)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapabilityNetworkServices)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapability_None)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapability_Denied)); sl@0: test(r==failResult); sl@0: sl@0: test.Next(_L("Test User::CreatorHasCapability(TCapability,TCapability)")); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityReadUserData)); sl@0: test(r==failResult); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapability_None,ECapabilityWriteUserData)); sl@0: test(r); sl@0: r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapability_Denied,ECapabilityWriteUserData)); sl@0: test(r==failResult); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: TBool SecurityPoliciesEqual(const TSecurityPolicy& a,const TSecurityPolicy& b) sl@0: { sl@0: return Mem::Compare((TUint8*)&a, sizeof(TSecurityPolicy), (TUint8*)&b, sizeof(TSecurityPolicy))==0; sl@0: } sl@0: sl@0: void TestSecurityPolicy() sl@0: { sl@0: test.Start(_L("Test TSecurityPolicy Constructors")); sl@0: sl@0: TBool failResult=!PlatSecEnforcement; sl@0: sl@0: test.Next(_L("Empty Constructor")); sl@0: { sl@0: TSecurityPolicy empty; sl@0: TPtrC8 ptr = empty.Package(); sl@0: TSecurityPolicy empty2; sl@0: test(empty2.Set(ptr) == KErrNone); sl@0: test(SecurityPoliciesEqual(empty, empty2)); sl@0: sl@0: test(failResult!=!empty.CheckPolicy(RProcess())); sl@0: test(failResult!=!empty.CheckPolicy(RThread())); sl@0: test(failResult!=!empty2.CheckPolicy(RProcess())); sl@0: test(failResult!=!empty2.CheckPolicy(RThread())); sl@0: sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: test.Next(_L("Always Fail Constructor")); sl@0: { sl@0: TSecurityPolicy fail(TSecurityPolicy::EAlwaysFail); sl@0: TPtrC8 ptr = fail.Package(); sl@0: TSecurityPolicy fail2; sl@0: test(fail2.Set(ptr) == KErrNone); sl@0: test(SecurityPoliciesEqual(fail, fail2)); sl@0: sl@0: test(failResult!=!fail.CheckPolicy(RProcess())); sl@0: test(failResult!=!fail.CheckPolicy(RThread())); sl@0: test(failResult!=!fail2.CheckPolicy(RProcess())); sl@0: test(failResult!=!fail2.CheckPolicy(RThread())); sl@0: sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: test.Next(_L("Always Pass Constructor")); sl@0: { sl@0: TSecurityPolicy pass(TSecurityPolicy::EAlwaysPass); sl@0: TPtrC8 ptr = pass.Package(); sl@0: TSecurityPolicy pass2; sl@0: test(pass2.Set(ptr) == KErrNone); sl@0: test(SecurityPoliciesEqual(pass, pass2)); sl@0: sl@0: test(pass.CheckPolicy(RProcess())); sl@0: test(pass.CheckPolicy(RThread())); sl@0: test(pass2.CheckPolicy(RProcess())); sl@0: test(pass2.CheckPolicy(RThread())); sl@0: sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: test.Next(_L("3 Capability Constructor")); sl@0: { sl@0: TSecurityPolicy threeCaps(ECapabilityTCB,ECapabilityDRM,ECapabilityProtServ); sl@0: //Current process has these three sl@0: test(threeCaps.CheckPolicy(RProcess())); sl@0: test(threeCaps.CheckPolicy(RThread())); sl@0: TPtrC8 ptr = threeCaps.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy threeCaps(ECapabilityTCB,ECapabilityProtServ,ECapabilityCommDD); sl@0: //Current process doesn't have ECapabilityCommDD sl@0: test(failResult!=!(threeCaps.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(threeCaps.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = threeCaps.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy threeCaps(ECapabilityCommDD); sl@0: //Current process doesn't have ECapabilityCommDD sl@0: test(failResult!=!(threeCaps.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(threeCaps.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = threeCaps.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy threeCaps(ECapabilityTCB); sl@0: //Current process has TCB + 2 * ECapability_None sl@0: test(threeCaps.CheckPolicy(RProcess())); sl@0: test(threeCaps.CheckPolicy(RThread())); sl@0: sl@0: TPtrC8 ptr = threeCaps.Package(); sl@0: TSecurityPolicy threeCaps2; sl@0: TBuf8 invalid; sl@0: for(TInt i=4; i<=7; i++) sl@0: { sl@0: invalid=ptr; sl@0: invalid[i] = 0; // Set unused capability to be invalid sl@0: test(threeCaps2.Set(invalid)==KErrArgument); sl@0: } sl@0: test(threeCaps2.Set(ptr)==KErrNone); sl@0: test(SecurityPoliciesEqual(threeCaps, threeCaps2)); sl@0: sl@0: test(threeCaps2.CheckPolicy(RProcess())); sl@0: test(threeCaps2.CheckPolicy(RThread())); sl@0: sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: test.Next(_L("7 Capability Constructor")); sl@0: { sl@0: TSecurityPolicy sevenCaps(ECapabilityTCB,ECapabilityWriteUserData,ECapabilitySwEvent,ECapabilityProtServ,ECapabilityNetworkControl,ECapabilityDRM,ECapabilityReadDeviceData); sl@0: //Current process has all 7 of these. sl@0: test(sevenCaps.CheckPolicy(RProcess())); sl@0: test(sevenCaps.CheckPolicy(RThread())); sl@0: TPtrC8 ptr = sevenCaps.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy sevenCaps(ECapabilityTCB,ECapabilityWriteUserData,ECapabilityMultimediaDD,ECapabilityProtServ,ECapabilityNetworkControl,ECapabilityDRM,ECapabilityReadDeviceData); sl@0: //Current process doesn't have MultimediaDD sl@0: test(failResult!=!(sevenCaps.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(sevenCaps.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = sevenCaps.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy sevenCaps(ECapabilityTCB,ECapabilityWriteUserData,ECapabilityMultimediaDD,ECapabilityProtServ,ECapabilityTrustedUI,ECapabilityDRM,ECapabilityReadDeviceData); sl@0: //Current process doesn't have MultiMediaDD or TrustedUI sl@0: test(failResult!=!(sevenCaps.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(sevenCaps.CheckPolicy(RThread()))); sl@0: sl@0: TPtrC8 ptr = sevenCaps.Package(); sl@0: TSecurityPolicy sevenCaps2; sl@0: test(sevenCaps2.Set(ptr)==KErrNone); sl@0: test(SecurityPoliciesEqual(sevenCaps,sevenCaps2)); sl@0: test(failResult!=!(sevenCaps2.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(sevenCaps2.CheckPolicy(RThread()))); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);; sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);; sl@0: } sl@0: sl@0: test.Next(_L("SID + 3 constructor")); sl@0: { sl@0: TSecurityPolicy sid(KTestSecureId, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData); sl@0: //Current process has all three + sid sl@0: test(sid.CheckPolicy(RProcess())); sl@0: test(sid.CheckPolicy(RThread())); sl@0: sl@0: TPtrC8 ptr = sid.Package(); sl@0: TSecurityPolicy sid2; sl@0: test(sid2.Set(ptr)==KErrNone); sl@0: test(SecurityPoliciesEqual(sid,sid2)); sl@0: test(sid2.CheckPolicy(RProcess())); sl@0: test(sid2.CheckPolicy(RThread())); sl@0: sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy sid(KTestSecureId2, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData); sl@0: //Current process has all three caps but not sid sl@0: test(failResult!=!(sid.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(sid.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = sid.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy sid(KTestSecureId, ECapabilityProtServ, ECapabilityWriteDeviceData); sl@0: //Current process has sid but missing ECapabilityWriteDeviceData sl@0: test(failResult!=!(sid.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(sid.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = sid.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy sid(KTestSecureId2, ECapabilityProtServ, ECapabilityWriteDeviceData); sl@0: //Current process is missing sid and ECapabilityWriteDeviceData sl@0: test(failResult!=!(sid.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(sid.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = sid.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: test.Next(_L("VID + 3 constructor")); sl@0: { sl@0: TSecurityPolicy vid(KTestVendorId, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData); sl@0: //Current process has all three + vid sl@0: test(vid.CheckPolicy(RProcess())); sl@0: test(vid.CheckPolicy(RThread())); sl@0: sl@0: TPtrC8 ptr = vid.Package(); sl@0: TSecurityPolicy vid2; sl@0: test(vid2.Set(ptr)==KErrNone); sl@0: test(SecurityPoliciesEqual(vid,vid2)); sl@0: test(vid2.CheckPolicy(RProcess())); sl@0: test(vid2.CheckPolicy(RThread())); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy vid(KTestVendorId2, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData); sl@0: //Current process has all three caps but not vid sl@0: test(failResult!=!(vid.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(vid.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = vid.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy vid(KTestVendorId, ECapabilityProtServ, ECapabilityWriteDeviceData); sl@0: //Current process has vid but missing ECapabilityWriteDeviceData sl@0: test(failResult!=!(vid.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(vid.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = vid.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: { sl@0: TSecurityPolicy vid(KTestVendorId2, ECapabilityProtServ, ECapabilityWriteDeviceData); sl@0: //Current process is missing vid and ECapabilityWriteDeviceData sl@0: test(failResult!=!(vid.CheckPolicy(RProcess()))); sl@0: test(failResult!=!(vid.CheckPolicy(RThread()))); sl@0: TPtrC8 ptr = vid.Package(); sl@0: TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr)); sl@0: test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed); sl@0: } sl@0: sl@0: test.Next(_L("Macros for compile-time construction")); sl@0: { sl@0: static _LIT_SECURITY_POLICY_C7(pc7,1,2,3,4,5,6,7); sl@0: static _LIT_SECURITY_POLICY_C6(pc6,1,2,3,4,5,6); sl@0: static _LIT_SECURITY_POLICY_C5(pc5,1,2,3,4,5); sl@0: static _LIT_SECURITY_POLICY_C4(pc4,1,2,3,4); sl@0: static _LIT_SECURITY_POLICY_C3(pc3,1,2,3); sl@0: static _LIT_SECURITY_POLICY_C2(pc2,1,2); sl@0: static _LIT_SECURITY_POLICY_C1(pc1,1); sl@0: test(SecurityPoliciesEqual(pc7,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6,(TCapability)7))); sl@0: test(SecurityPoliciesEqual(pc6,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6))); sl@0: test(SecurityPoliciesEqual(pc5,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5))); sl@0: test(SecurityPoliciesEqual(pc4,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4))); sl@0: test(SecurityPoliciesEqual(pc3,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3))); sl@0: test(SecurityPoliciesEqual(pc2,TSecurityPolicy((TCapability)1,(TCapability)2))); sl@0: test(SecurityPoliciesEqual(pc1,TSecurityPolicy((TCapability)1))); sl@0: sl@0: static _LIT_SECURITY_POLICY_S3(ps3,0x12345678,1,2,3); sl@0: static _LIT_SECURITY_POLICY_S2(ps2,0x12345678,1,2); sl@0: static _LIT_SECURITY_POLICY_S1(ps1,0x12345678,1); sl@0: static _LIT_SECURITY_POLICY_S0(ps0,0x12345678); sl@0: test(SecurityPoliciesEqual(ps3,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3))); sl@0: test(SecurityPoliciesEqual(ps2,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2))); sl@0: test(SecurityPoliciesEqual(ps1,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1))); sl@0: test(SecurityPoliciesEqual(ps0,TSecurityPolicy(TSecureId(0x12345678)))); sl@0: sl@0: static _LIT_SECURITY_POLICY_V3(pv3,0x12345678,1,2,3); sl@0: static _LIT_SECURITY_POLICY_V2(pv2,0x12345678,1,2); sl@0: static _LIT_SECURITY_POLICY_V1(pv1,0x12345678,1); sl@0: static _LIT_SECURITY_POLICY_V0(pv0,0x12345678); sl@0: test(SecurityPoliciesEqual(pv3,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3))); sl@0: test(SecurityPoliciesEqual(pv2,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2))); sl@0: test(SecurityPoliciesEqual(pv1,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1))); sl@0: test(SecurityPoliciesEqual(pv0,TSecurityPolicy(TVendorId(0x12345678)))); sl@0: sl@0: static _LIT_SECURITY_POLICY_FAIL(fail); sl@0: static _LIT_SECURITY_POLICY_PASS(pass); sl@0: test(SecurityPoliciesEqual(fail,TSecurityPolicy(TSecurityPolicy::EAlwaysFail))); sl@0: test(SecurityPoliciesEqual(pass,TSecurityPolicy(TSecurityPolicy::EAlwaysPass))); sl@0: } sl@0: sl@0: test.Next(_L("Macros for compile-time initialisation")); sl@0: { sl@0: const TStaticSecurityPolicy pc7 = _INIT_SECURITY_POLICY_C7(1,2,3,4,5,6,7); sl@0: const TStaticSecurityPolicy pc6 = _INIT_SECURITY_POLICY_C6(1,2,3,4,5,6); sl@0: const TStaticSecurityPolicy pc5 = _INIT_SECURITY_POLICY_C5(1,2,3,4,5); sl@0: const TStaticSecurityPolicy pc4 = _INIT_SECURITY_POLICY_C4(1,2,3,4); sl@0: const TStaticSecurityPolicy pc3 = _INIT_SECURITY_POLICY_C3(1,2,3); sl@0: const TStaticSecurityPolicy pc2 = _INIT_SECURITY_POLICY_C2(1,2); sl@0: const TStaticSecurityPolicy pc1 = _INIT_SECURITY_POLICY_C1(1); sl@0: test(SecurityPoliciesEqual(pc7,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6,(TCapability)7))); sl@0: test(SecurityPoliciesEqual(pc6,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6))); sl@0: test(SecurityPoliciesEqual(pc5,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5))); sl@0: test(SecurityPoliciesEqual(pc4,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4))); sl@0: test(SecurityPoliciesEqual(pc3,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3))); sl@0: test(SecurityPoliciesEqual(pc2,TSecurityPolicy((TCapability)1,(TCapability)2))); sl@0: test(SecurityPoliciesEqual(pc1,TSecurityPolicy((TCapability)1))); sl@0: sl@0: const TStaticSecurityPolicy ps3 = _INIT_SECURITY_POLICY_S3(0x12345678,1,2,3); sl@0: const TStaticSecurityPolicy ps2 = _INIT_SECURITY_POLICY_S2(0x12345678,1,2); sl@0: const TStaticSecurityPolicy ps1 = _INIT_SECURITY_POLICY_S1(0x12345678,1); sl@0: const TStaticSecurityPolicy ps0 = _INIT_SECURITY_POLICY_S0(0x12345678); sl@0: test(SecurityPoliciesEqual(ps3,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3))); sl@0: test(SecurityPoliciesEqual(ps2,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2))); sl@0: test(SecurityPoliciesEqual(ps1,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1))); sl@0: test(SecurityPoliciesEqual(ps0,TSecurityPolicy(TSecureId(0x12345678)))); sl@0: sl@0: const TStaticSecurityPolicy pv3 = _INIT_SECURITY_POLICY_V3(0x12345678,1,2,3); sl@0: const TStaticSecurityPolicy pv2 = _INIT_SECURITY_POLICY_V2(0x12345678,1,2); sl@0: const TStaticSecurityPolicy pv1 = _INIT_SECURITY_POLICY_V1(0x12345678,1); sl@0: const TStaticSecurityPolicy pv0 = _INIT_SECURITY_POLICY_V0(0x12345678); sl@0: test(SecurityPoliciesEqual(pv3,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3))); sl@0: test(SecurityPoliciesEqual(pv2,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2))); sl@0: test(SecurityPoliciesEqual(pv1,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1))); sl@0: test(SecurityPoliciesEqual(pv0,TSecurityPolicy(TVendorId(0x12345678)))); sl@0: sl@0: const TStaticSecurityPolicy fail = _INIT_SECURITY_POLICY_FAIL; sl@0: const TStaticSecurityPolicy pass = _INIT_SECURITY_POLICY_PASS; sl@0: test(SecurityPoliciesEqual(fail,TSecurityPolicy(TSecurityPolicy::EAlwaysFail))); sl@0: test(SecurityPoliciesEqual(pass,TSecurityPolicy(TSecurityPolicy::EAlwaysPass))); sl@0: sl@0: } sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: #define CHECK_NAME(name) \ sl@0: test(0==TPtrC8((TUint8*)#name).Compare(TPtrC8((TUint8*)CapabilityNames[ECapability##name]))); sl@0: sl@0: void TestCapabilityNames() sl@0: { sl@0: CHECK_NAME(TCB); sl@0: CHECK_NAME(CommDD); sl@0: CHECK_NAME(PowerMgmt); sl@0: CHECK_NAME(MultimediaDD); sl@0: CHECK_NAME(ReadDeviceData); sl@0: CHECK_NAME(WriteDeviceData); sl@0: CHECK_NAME(DRM); sl@0: CHECK_NAME(TrustedUI); sl@0: CHECK_NAME(ProtServ); sl@0: CHECK_NAME(DiskAdmin); sl@0: CHECK_NAME(NetworkControl); sl@0: CHECK_NAME(AllFiles); sl@0: CHECK_NAME(SwEvent); sl@0: CHECK_NAME(NetworkServices); sl@0: CHECK_NAME(LocalServices); sl@0: CHECK_NAME(ReadUserData); sl@0: CHECK_NAME(WriteUserData); sl@0: CHECK_NAME(Location); sl@0: CHECK_NAME(SurroundingsDD); sl@0: CHECK_NAME(UserEnvironment); sl@0: } sl@0: sl@0: sl@0: void TestKernelAPIs() sl@0: { sl@0: RLddTest ldd; sl@0: TInt r=User::LoadLogicalDevice(_L("D_SLDD.LDD")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=ldd.OpenLocal(); sl@0: test(r==KErrNone); sl@0: sl@0: RLddTest::TIds ids; sl@0: memclr(&ids,sizeof(ids)); sl@0: ldd.GetIds(ids); sl@0: test.Printf(_L("Thread VID,SID = %08x,%08x\n\r"),ids.iThreadVID.iId,ids.iThreadSID.iId); sl@0: test.Printf(_L("Process VID,SID = %08x,%08x\n\r"),ids.iProcessVID.iId,ids.iProcessSID.iId); sl@0: test(ids.iThreadVID==KTestVendorId); sl@0: test(ids.iThreadSID==KTestSecureId); sl@0: test(ids.iProcessVID==KTestVendorId); sl@0: test(ids.iProcessSID==KTestSecureId); sl@0: sl@0: // Test kernel-mode TSecurityInfo-getting APIs sl@0: TSecurityInfo infoProcess, infoThread; sl@0: ldd.GetSecureInfos(&infoThread, &infoProcess); sl@0: // Check the vendor & secure IDs are what's expected sl@0: test(infoThread.iVendorId==KTestVendorId); sl@0: test(infoThread.iSecureId==KTestSecureId); sl@0: test(infoProcess.iVendorId==KTestVendorId); sl@0: test(infoProcess.iSecureId==KTestSecureId); sl@0: // Check process caps == thread caps sl@0: TUint32* capsT = (TUint32*)&infoThread.iCaps; sl@0: TUint32* capsP = (TUint32*)&infoProcess.iCaps; sl@0: test(capsT[0]==capsP[0]); sl@0: test(capsT[1]==capsP[1]); sl@0: // Check the caps match what the user API gives sl@0: RProcess this_process; sl@0: for (TInt i=0 ; i<64 ; i++) { sl@0: TCapability cap = (TCapability)i; sl@0: test(infoProcess.iCaps.HasCapability(cap) == this_process.HasCapability(cap)); sl@0: } sl@0: sl@0: sl@0: ldd.Close(); sl@0: } sl@0: sl@0: sl@0: void TestPlatSecUnlocked() sl@0: { sl@0: RLddTest ldd; sl@0: TInt r = User::LoadLogicalDevice(_L("D_SLDD.LDD")); sl@0: test(r == KErrNone || r == KErrAlreadyExists); sl@0: r = ldd.OpenLocal(); sl@0: test_KErrNone(r); sl@0: sl@0: TUint32 flags0, flags; sl@0: TInt enforced; sl@0: sl@0: flags0 = ldd.GetKernelConfigFlags(); sl@0: sl@0: const TUint32 bits = (TUint32)(EKernelConfigTest | EKernelConfigPlatSecEnforcement); sl@0: sl@0: // Different test cases depending on whether __PLATSEC_UNLOCKED__ defined. sl@0: // Ask the kernel whether EKernelConfigPlatSecLocked is set, and hope that sl@0: // it's not lying to us! sl@0: // sl@0: // Best thing to do is to check the log and verify the printf() output. sl@0: // sl@0: sl@0: if (PlatSec::ConfigSetting(PlatSec::EPlatSecLocked)) sl@0: { sl@0: /* sl@0: * Tests for __PLATSEC_UNLOCKED__ not defined sl@0: * sl@0: * The device driver is built with __PLATSEC_FORCED_FLAGS__ set to 0, so we can't use sl@0: * its GetKernelConfigFlags() interface (the accessor functions are inlines) when we're sl@0: * testing for PlatSec locked. Instead, use PlatSec::ConfigSetting(), which makes an sl@0: * exec call to get iKernelConfigFlags. sl@0: */ sl@0: test.Printf(_L("__PLATSEC_UNLOCKED_ does NOT appear to have been used\n")); sl@0: sl@0: /* Check that PlatSecEnforcement is set */ sl@0: enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement); sl@0: test(enforced != 0); sl@0: sl@0: /* Check that the device driver is able to set our test bit */ sl@0: ldd.SetKernelConfigFlags(flags0 | EKernelConfigTest); sl@0: sl@0: flags = ldd.GetKernelConfigFlags(); sl@0: test((flags & EKernelConfigTest) == EKernelConfigTest); sl@0: sl@0: /* Check that the device driver is able to clear our test bit, but not able to clear enforcement bit */ sl@0: ldd.SetKernelConfigFlags(flags0 & ~bits); sl@0: sl@0: enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement); sl@0: test(enforced != 0); sl@0: } sl@0: else sl@0: { sl@0: /* sl@0: * Tests for __PLATSEC_UNLOCKED__ defined sl@0: */ sl@0: test.Printf(_L("__PLATSEC_UNLOCKED_ DOES appear to have been used\n")); sl@0: sl@0: /* Check that the device driver is able to set our test bit and PlatSecEnforcement */ sl@0: ldd.SetKernelConfigFlags(flags0 | bits); sl@0: sl@0: flags = ldd.GetKernelConfigFlags(); sl@0: test((flags & bits) == bits); sl@0: sl@0: /* And verify that the kernel sees the same result */ sl@0: enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement); sl@0: test(enforced != 0); // (yes, "!= 0" is redundant) sl@0: sl@0: /* Check that the device driver is able to clear our test bit and PlatSecEnforcement */ sl@0: ldd.SetKernelConfigFlags(flags0 & ~bits); sl@0: sl@0: flags = ldd.GetKernelConfigFlags(); sl@0: test((flags & bits) == 0); sl@0: sl@0: /* Verify that the kernel sees the same result */ sl@0: enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement); sl@0: test(enforced == 0); sl@0: } sl@0: sl@0: /* Restore original flags value */ sl@0: ldd.SetKernelConfigFlags(flags0); sl@0: sl@0: // Now test handling of iDisabledCapabilities sl@0: sl@0: const TUint32 test_value = 0x31415926; // Just some random number sl@0: sl@0: TCapabilitySet disabled0, disabled; sl@0: disabled0.SetDisabled(); sl@0: sl@0: SCapabilitySet *caps0 = (SCapabilitySet *)&disabled0; sl@0: SCapabilitySet *caps = (SCapabilitySet *)&disabled; sl@0: sl@0: if (PlatSec::ConfigSetting(PlatSec::EPlatSecLocked)) sl@0: { sl@0: /* sl@0: * Tests for __PLATSEC_UNLOCKED__ not defined sl@0: */ sl@0: sl@0: /* Check that the capability set is 0 */ sl@0: int i; sl@0: sl@0: for (i = 0; i < SCapabilitySet::ENCapW; i++) sl@0: { sl@0: test_Equal(0, caps0->iCaps[i]); sl@0: } sl@0: sl@0: /* Check that the device driver is not able to set word 0 of disabled capabilities */ sl@0: ldd.SetDisabledCapabilities0(test_value); sl@0: sl@0: /* sl@0: * It's okay to use SetDisabled() here, since this makes an exec call to get the sl@0: * set of disabled capabilities. sl@0: */ sl@0: disabled.SetDisabled(); sl@0: test_Equal(0, caps->iCaps[0]); sl@0: } sl@0: else sl@0: { sl@0: /* sl@0: * Tests for __PLATSEC_UNLOCKED__ defined sl@0: */ sl@0: sl@0: /* Check that the device driver is able to set word 0 of disabled capabilities */ sl@0: ldd.SetDisabledCapabilities0(test_value); sl@0: sl@0: disabled.SetDisabled(); sl@0: test_Equal(test_value, caps->iCaps[0]); sl@0: } sl@0: sl@0: /* Restore original value */ sl@0: ldd.SetDisabledCapabilities0(caps0->iCaps[0]); sl@0: sl@0: ldd.Close(); sl@0: } sl@0: sl@0: #include sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: PlatSecEnforcement = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement); sl@0: sl@0: TBuf16<512> cmd; sl@0: User::CommandLine(cmd); sl@0: if(cmd.Length() && TChar(cmd[0]).IsDigit()) sl@0: { sl@0: TInt function = -1; sl@0: TInt arg1 = -1; sl@0: TInt arg2 = -1; sl@0: TLex lex(cmd); sl@0: sl@0: lex.Val(function); sl@0: lex.SkipSpace(); sl@0: lex.Val(arg1); sl@0: lex.SkipSpace(); sl@0: lex.Val(arg2); sl@0: return DoTestProcess(function,arg1,arg2); sl@0: } sl@0: sl@0: test.Title(); sl@0: sl@0: if(PlatSecEnforcement) sl@0: test.Printf(_L("PlatSecConfig appears to be ON\n")); sl@0: else sl@0: test.Printf(_L("PlatSecConfig appears to be OFF\n")); sl@0: sl@0: test.Start(_L("Starting test server")); sl@0: RTestProcess server; sl@0: TRequestStatus rendezvous; sl@0: server.Create(~KTestCapabilities,ETestProcessServer,0,0); sl@0: server.Rendezvous(rendezvous); sl@0: server.Resume(); sl@0: User::WaitForRequest(rendezvous); sl@0: test(rendezvous==KServerRendezvous); sl@0: sl@0: test.Next(_L("Openning server session")); sl@0: TInt r = Session.Connect(); sl@0: RDebug::Print(_L("%d"),r); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Test Capability Names")); sl@0: TestCapabilityNames(); sl@0: sl@0: test.Next(_L("Test TCapabilitySet")); sl@0: TestCapabilitySet(); sl@0: sl@0: test.Next(_L("Test TSecurityInfo")); sl@0: TestSecurityInfo(); sl@0: sl@0: test.Next(_L("Test SecureId functions")); sl@0: TestSecureId(); sl@0: sl@0: test.Next(_L("Test VendorId functions")); sl@0: TestVendorId(); sl@0: sl@0: test.Next(_L("Test HasCapability functions")); sl@0: TestHasCapability(); sl@0: sl@0: test.Next(_L("Test TSecurityPolicy")); sl@0: TestSecurityPolicy(); sl@0: sl@0: test.Next(_L("Test Kernel APIs")); sl@0: TestKernelAPIs(); sl@0: sl@0: test.Next(_L("Test __PLATSEC_UNLOCKED__")); sl@0: TestPlatSecUnlocked(); sl@0: sl@0: test.Next(_L("Test diagnostic message suppression")); sl@0: RThread().HasCapability(ECapabilityReadUserData,0); sl@0: test.Printf(_L("There should be a diagnostic message just before this\n")); sl@0: RThread().HasCapability(ECapabilityReadUserData,__PLATSEC_DIAGNOSTIC_STRING("You should see this")); sl@0: test.Printf(_L("There should be a diagnostic message just before this\n")); sl@0: RThread().HasCapability(ECapabilityReadUserData,KSuppressPlatSecDiagnostic); sl@0: test.Printf(_L("There should NOT be a diagnostic message just before this\n")); sl@0: sl@0: test.Next(_L("Closing server session")); sl@0: Session.Send(CTestSession::EShutdown); sl@0: Session.Close(); sl@0: server.Close(); sl@0: sl@0: test.End(); sl@0: return(0); sl@0: } sl@0: