sl@0: // Copyright (c) 2005-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: // t_prop_define.cpp.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "t_property.h" sl@0: sl@0: TSecureId MySecureId; sl@0: TBool IHaveWriteDeviceData; sl@0: sl@0: _LIT(KSecurityOwnerName, "RProperty Security: Owner Basics"); sl@0: sl@0: class CPropSecurityOwner : public CTestProgram sl@0: { sl@0: public: sl@0: CPropSecurityOwner(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) : sl@0: CTestProgram(KSecurityOwnerName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey), sl@0: iType(aType) sl@0: { sl@0: } sl@0: sl@0: void Run(TUint aCount); sl@0: sl@0: private: sl@0: TUid iCategory; sl@0: TUint iMasterKey; sl@0: TUint iSlaveKey; sl@0: RProperty::TType iType; sl@0: }; sl@0: sl@0: void CPropSecurityOwner::Run(TUint aCount) sl@0: { sl@0: for (TUint i = 0; i < aCount; ++i) sl@0: { sl@0: // Delete() can only be called by the property owner, as defined by the process Security ID, sl@0: // any other process will get a KErrPermissionDenied error. sl@0: RProperty mProp; sl@0: TInt r = mProp.Delete(iCategory, iMasterKey); sl@0: TF_ERROR(r, r == KErrPermissionDenied); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: _LIT(KPropDefineSecurityName, "RProperty Security: Define category security"); sl@0: sl@0: class CPropDefineSecurity : public CTestProgram sl@0: { sl@0: public: sl@0: CPropDefineSecurity(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) : sl@0: CTestProgram(KPropDefineSecurityName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey), sl@0: iType(aType) sl@0: { sl@0: } sl@0: sl@0: void Run(TUint aCount); sl@0: sl@0: private: sl@0: TUid iCategory; sl@0: TUint iMasterKey; sl@0: TUint iSlaveKey; sl@0: RProperty::TType iType; sl@0: }; sl@0: sl@0: void CPropDefineSecurity::Run(TUint aCount) sl@0: { sl@0: for (TUint i = 0; i < aCount; ++i) sl@0: { sl@0: // Test defining in the system category sl@0: RProperty prop; sl@0: TInt r = prop.Define(KUidSystemCategory, iSlaveKey, iType, KPassPolicy, KPassPolicy); sl@0: RDebug::Printf("CPropDefineSecurity define with System Category returns %d",r); sl@0: TF_ERROR(r, r == IHaveWriteDeviceData ? KErrNone : KErrPermissionDenied); sl@0: if(r==KErrNone) sl@0: { sl@0: r = prop.Delete(KUidSystemCategory, iSlaveKey); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: sl@0: // Tesk defining properties with categories above and below security threshold sl@0: TUid categoryA = { KUidSecurityThresholdCategoryValue-1 }; sl@0: r = prop.Define(categoryA, iSlaveKey, iType, KPassPolicy, KPassPolicy); sl@0: RDebug::Printf("CPropDefineSecurity define with Category A returns %d",r); sl@0: TF_ERROR(r, r == (categoryA==MySecureId || IHaveWriteDeviceData) ? KErrNone : KErrPermissionDenied); sl@0: if(r==KErrNone) sl@0: { sl@0: r = prop.Delete(categoryA, iSlaveKey); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: TUid categoryB = { KUidSecurityThresholdCategoryValue }; sl@0: r = prop.Define(categoryB, iSlaveKey, iType, KPassPolicy, KPassPolicy); sl@0: RDebug::Printf("CPropDefineSecurity define with Category B returns %d",r); sl@0: TF_ERROR(r, r == (categoryB==MySecureId) ? KErrNone : KErrPermissionDenied); sl@0: if(r==KErrNone) sl@0: { sl@0: r = prop.Delete(categoryB, iSlaveKey); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: TUid categoryC = { KUidSecurityThresholdCategoryValue+1 }; sl@0: r = prop.Define(categoryC, iSlaveKey, iType, KPassPolicy, KPassPolicy); sl@0: RDebug::Printf("CPropDefineSecurity define with Category C returns %d",r); sl@0: TF_ERROR(r, r == KErrPermissionDenied); sl@0: sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: TSecurityInfo info; sl@0: info.Set(RProcess()); sl@0: MySecureId = info.iSecureId; sl@0: IHaveWriteDeviceData = info.iCaps.HasCapability(ECapabilityWriteDeviceData); sl@0: sl@0: TInt len = User::CommandLineLength(); sl@0: __ASSERT_ALWAYS(len, User::Panic(_L("t_prop_sec: bad args"), 0)); sl@0: sl@0: // Get arguments for the command line sl@0: TInt size = len * sizeof(TUint16); sl@0: HBufC8* hb = HBufC8::NewMax(size); sl@0: __ASSERT_ALWAYS(hb, User::Panic(_L("t_prop_sec: no memory"), 0)); sl@0: TPtr cmd((TUint16*) hb->Ptr(), len); sl@0: User::CommandLine(cmd); sl@0: CPropSecurity::TArgs* args = (CPropSecurity::TArgs*) hb->Ptr(); sl@0: sl@0: CTestProgram::Start(); sl@0: sl@0: CTestProgram* progs[] = sl@0: { sl@0: new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt), sl@0: new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot + 1, RProperty::EByteArray), sl@0: new CPropDefineSecurity(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt), sl@0: NULL sl@0: }; sl@0: sl@0: TInt i; sl@0: TInt n = (sizeof(progs)/sizeof(*progs)) - 1; sl@0: for (i = 0; i < n; ++i) sl@0: { sl@0: __ASSERT_ALWAYS(progs[i], User::Panic(_L("t_property: no memory"), 0)); sl@0: } sl@0: sl@0: CTestProgram::LaunchGroup(progs, 2); sl@0: sl@0: for (i = 0; i < n; ++i) sl@0: { sl@0: delete progs[i]; sl@0: } sl@0: sl@0: CTestProgram::End(); sl@0: sl@0: return KErrNone; sl@0: }