|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // t_prop_define.cpp.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <e32svr.h> |
|
20 |
|
21 #include "t_property.h" |
|
22 |
|
23 TSecureId MySecureId; |
|
24 TBool IHaveWriteDeviceData; |
|
25 |
|
26 _LIT(KSecurityOwnerName, "RProperty Security: Owner Basics"); |
|
27 |
|
28 class CPropSecurityOwner : public CTestProgram |
|
29 { |
|
30 public: |
|
31 CPropSecurityOwner(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) : |
|
32 CTestProgram(KSecurityOwnerName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey), |
|
33 iType(aType) |
|
34 { |
|
35 } |
|
36 |
|
37 void Run(TUint aCount); |
|
38 |
|
39 private: |
|
40 TUid iCategory; |
|
41 TUint iMasterKey; |
|
42 TUint iSlaveKey; |
|
43 RProperty::TType iType; |
|
44 }; |
|
45 |
|
46 void CPropSecurityOwner::Run(TUint aCount) |
|
47 { |
|
48 for (TUint i = 0; i < aCount; ++i) |
|
49 { |
|
50 // Delete() can only be called by the property owner, as defined by the process Security ID, |
|
51 // any other process will get a KErrPermissionDenied error. |
|
52 RProperty mProp; |
|
53 TInt r = mProp.Delete(iCategory, iMasterKey); |
|
54 TF_ERROR(r, r == KErrPermissionDenied); |
|
55 } |
|
56 } |
|
57 |
|
58 |
|
59 |
|
60 _LIT(KPropDefineSecurityName, "RProperty Security: Define category security"); |
|
61 |
|
62 class CPropDefineSecurity : public CTestProgram |
|
63 { |
|
64 public: |
|
65 CPropDefineSecurity(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) : |
|
66 CTestProgram(KPropDefineSecurityName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey), |
|
67 iType(aType) |
|
68 { |
|
69 } |
|
70 |
|
71 void Run(TUint aCount); |
|
72 |
|
73 private: |
|
74 TUid iCategory; |
|
75 TUint iMasterKey; |
|
76 TUint iSlaveKey; |
|
77 RProperty::TType iType; |
|
78 }; |
|
79 |
|
80 void CPropDefineSecurity::Run(TUint aCount) |
|
81 { |
|
82 for (TUint i = 0; i < aCount; ++i) |
|
83 { |
|
84 // Test defining in the system category |
|
85 RProperty prop; |
|
86 TInt r = prop.Define(KUidSystemCategory, iSlaveKey, iType, KPassPolicy, KPassPolicy); |
|
87 RDebug::Printf("CPropDefineSecurity define with System Category returns %d",r); |
|
88 TF_ERROR(r, r == IHaveWriteDeviceData ? KErrNone : KErrPermissionDenied); |
|
89 if(r==KErrNone) |
|
90 { |
|
91 r = prop.Delete(KUidSystemCategory, iSlaveKey); |
|
92 TF_ERROR(r, r == KErrNone); |
|
93 } |
|
94 |
|
95 // Tesk defining properties with categories above and below security threshold |
|
96 TUid categoryA = { KUidSecurityThresholdCategoryValue-1 }; |
|
97 r = prop.Define(categoryA, iSlaveKey, iType, KPassPolicy, KPassPolicy); |
|
98 RDebug::Printf("CPropDefineSecurity define with Category A returns %d",r); |
|
99 TF_ERROR(r, r == (categoryA==MySecureId || IHaveWriteDeviceData) ? KErrNone : KErrPermissionDenied); |
|
100 if(r==KErrNone) |
|
101 { |
|
102 r = prop.Delete(categoryA, iSlaveKey); |
|
103 TF_ERROR(r, r == KErrNone); |
|
104 } |
|
105 TUid categoryB = { KUidSecurityThresholdCategoryValue }; |
|
106 r = prop.Define(categoryB, iSlaveKey, iType, KPassPolicy, KPassPolicy); |
|
107 RDebug::Printf("CPropDefineSecurity define with Category B returns %d",r); |
|
108 TF_ERROR(r, r == (categoryB==MySecureId) ? KErrNone : KErrPermissionDenied); |
|
109 if(r==KErrNone) |
|
110 { |
|
111 r = prop.Delete(categoryB, iSlaveKey); |
|
112 TF_ERROR(r, r == KErrNone); |
|
113 } |
|
114 TUid categoryC = { KUidSecurityThresholdCategoryValue+1 }; |
|
115 r = prop.Define(categoryC, iSlaveKey, iType, KPassPolicy, KPassPolicy); |
|
116 RDebug::Printf("CPropDefineSecurity define with Category C returns %d",r); |
|
117 TF_ERROR(r, r == KErrPermissionDenied); |
|
118 |
|
119 } |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 GLDEF_C TInt E32Main() |
|
126 { |
|
127 TSecurityInfo info; |
|
128 info.Set(RProcess()); |
|
129 MySecureId = info.iSecureId; |
|
130 IHaveWriteDeviceData = info.iCaps.HasCapability(ECapabilityWriteDeviceData); |
|
131 |
|
132 TInt len = User::CommandLineLength(); |
|
133 __ASSERT_ALWAYS(len, User::Panic(_L("t_prop_sec: bad args"), 0)); |
|
134 |
|
135 // Get arguments for the command line |
|
136 TInt size = len * sizeof(TUint16); |
|
137 HBufC8* hb = HBufC8::NewMax(size); |
|
138 __ASSERT_ALWAYS(hb, User::Panic(_L("t_prop_sec: no memory"), 0)); |
|
139 TPtr cmd((TUint16*) hb->Ptr(), len); |
|
140 User::CommandLine(cmd); |
|
141 CPropSecurity::TArgs* args = (CPropSecurity::TArgs*) hb->Ptr(); |
|
142 |
|
143 CTestProgram::Start(); |
|
144 |
|
145 CTestProgram* progs[] = |
|
146 { |
|
147 new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt), |
|
148 new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot + 1, RProperty::EByteArray), |
|
149 new CPropDefineSecurity(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt), |
|
150 NULL |
|
151 }; |
|
152 |
|
153 TInt i; |
|
154 TInt n = (sizeof(progs)/sizeof(*progs)) - 1; |
|
155 for (i = 0; i < n; ++i) |
|
156 { |
|
157 __ASSERT_ALWAYS(progs[i], User::Panic(_L("t_property: no memory"), 0)); |
|
158 } |
|
159 |
|
160 CTestProgram::LaunchGroup(progs, 2); |
|
161 |
|
162 for (i = 0; i < n; ++i) |
|
163 { |
|
164 delete progs[i]; |
|
165 } |
|
166 |
|
167 CTestProgram::End(); |
|
168 |
|
169 return KErrNone; |
|
170 } |