|
1 /* |
|
2 * Copyright (c) 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 "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 #include "Midp2PermissionDB.h" |
|
18 #include "StorageUtils.h" |
|
19 #include "javasymbianoslayer.h" |
|
20 #include "javacommonutils.h" |
|
21 #include "javauid.h" |
|
22 |
|
23 using namespace MIDP; |
|
24 using namespace std; |
|
25 using namespace java::security::legacysupport; |
|
26 using namespace java::util; |
|
27 |
|
28 EXPORT_C Midp2PermissionDB* Midp2PermissionDB::NewL(const TDesC& aMidletSuiteName, |
|
29 const TDesC& aMidletSuiteVendor, |
|
30 const TDesC& aMidletSuiteVersion) |
|
31 { |
|
32 Midp2PermissionDB* self = new(ELeave) Midp2PermissionDB(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(aMidletSuiteName, aMidletSuiteVendor, aMidletSuiteVersion); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 void Midp2PermissionDB::ConstructL(const TDesC& aMidletSuiteName, |
|
40 const TDesC& aMidletSuiteVendor, |
|
41 const TDesC& aMidletSuiteVersion) |
|
42 { |
|
43 MidletSuiteInfo midletSuiteInfo; |
|
44 StorageUtils* storage = StorageUtils::NewL(); |
|
45 CleanupStack::PushL(storage); |
|
46 storage->readMidletSuiteInfoL( |
|
47 wstring((wchar_t*) aMidletSuiteName.Ptr(), aMidletSuiteName.Length()), |
|
48 wstring((wchar_t*) aMidletSuiteVendor.Ptr(), aMidletSuiteVendor.Length()), |
|
49 wstring((wchar_t*) aMidletSuiteVersion.Ptr(), aMidletSuiteVersion.Length()), |
|
50 midletSuiteInfo); |
|
51 CleanupStack::PopAndDestroy(storage); |
|
52 iMidletSuiteUid = midletSuiteInfo.iUid; |
|
53 iMidletSuiteProtectionDomain = midletSuiteInfo.iProtectionDomain; |
|
54 } |
|
55 |
|
56 Midp2PermissionDB::Midp2PermissionDB() |
|
57 { |
|
58 } |
|
59 |
|
60 Midp2PermissionDB::~Midp2PermissionDB() |
|
61 { |
|
62 } |
|
63 |
|
64 EXPORT_C TInt Midp2PermissionDB::GetDomain(TMidp2Domain& aDomain) |
|
65 { |
|
66 if (iMidletSuiteProtectionDomain.compare(L"UTPD") == 0) |
|
67 { |
|
68 aDomain = EDomainUntrusted; |
|
69 } |
|
70 else if (iMidletSuiteProtectionDomain.compare(L"ITPD") == 0) |
|
71 { |
|
72 aDomain = EDomainTTP; |
|
73 } |
|
74 else if (iMidletSuiteProtectionDomain.compare(L"MFD") == 0) |
|
75 { |
|
76 aDomain = EDomainManufacturer; |
|
77 } |
|
78 else if (iMidletSuiteProtectionDomain.compare(L"OPD") == 0) |
|
79 { |
|
80 aDomain = EDomainOperator; |
|
81 } |
|
82 else |
|
83 { |
|
84 return KErrNotFound; |
|
85 } |
|
86 return KErrNone; |
|
87 } |
|
88 |
|
89 EXPORT_C TInt Midp2PermissionDB::GetFunctionGroupPermission( |
|
90 const TMidp2FunctionGroup& aFunctionGroup, |
|
91 TMidp2PermissionType& aPermissionType, |
|
92 TMidp2PermissionMode& aPermissionMode, |
|
93 TUint8& aAllowedModesMask) |
|
94 { |
|
95 |
|
96 if (aFunctionGroup <= EPhoneCall || aFunctionGroup >= ELastFunctionGroupMarker) |
|
97 { |
|
98 return KErrNotFound; |
|
99 } |
|
100 |
|
101 // The allowed modes info is stored as a 4-bit constant: |
|
102 // X(oneshot)X(session)X(blanket)X(no) |
|
103 // e.g. 1011 (=11) means that oneshot, blanket and no are allowed. |
|
104 // The following constants are used to encode/decode the allowed modes |
|
105 // into/from a 4-bit number |
|
106 int NO_MASK = 1; |
|
107 int BLANKET_MASK = 2; |
|
108 int SESSION_MASK = 4; |
|
109 int ONESHOT_MASK = 8; |
|
110 |
|
111 wstring settingsName = wstring((wchar_t*) KJcfFunctionGroups[aFunctionGroup]); |
|
112 MidletSuiteSecuritySettings securitySettings; |
|
113 StorageUtils* storage = NULL; |
|
114 int result = KErrNotFound; |
|
115 TRAP_IGNORE( |
|
116 storage = StorageUtils::NewL(); |
|
117 CleanupStack::PushL(storage); |
|
118 result = storage->readMidletSuiteSecuritySettings(iMidletSuiteUid, settingsName, securitySettings); |
|
119 CleanupStack::PopAndDestroy(storage); |
|
120 ); |
|
121 if (result != KErrNone) |
|
122 { |
|
123 return KErrNotFound; |
|
124 } |
|
125 if (securitySettings.iCurrentInteractionMode <= 0 |
|
126 || securitySettings.iCurrentInteractionMode > 4 |
|
127 || securitySettings.iAllowedInteractionModes <= 0 |
|
128 || securitySettings.iAllowedInteractionModes > 15) |
|
129 { |
|
130 aPermissionType = EAllowed; |
|
131 return KErrNone; |
|
132 } |
|
133 aPermissionType = EUser; |
|
134 // set current interaction mode |
|
135 switch (securitySettings.iCurrentInteractionMode) |
|
136 { |
|
137 case 1: |
|
138 aPermissionMode = EOneShot; |
|
139 break; |
|
140 case 2: |
|
141 aPermissionMode = ESession; |
|
142 break; |
|
143 case 3: |
|
144 aPermissionMode = EBlanket; |
|
145 break; |
|
146 case 4: |
|
147 aPermissionMode = EDenied; |
|
148 break; |
|
149 } |
|
150 // set the allowed interaction modes |
|
151 int tmp = securitySettings.iAllowedInteractionModes & BLANKET_MASK; |
|
152 if (tmp > 0) |
|
153 { |
|
154 aAllowedModesMask |= EBlanket; |
|
155 } |
|
156 tmp = securitySettings.iAllowedInteractionModes & SESSION_MASK; |
|
157 if (tmp > 0) |
|
158 { |
|
159 aAllowedModesMask |= ESession; |
|
160 } |
|
161 tmp = securitySettings.iAllowedInteractionModes & ONESHOT_MASK; |
|
162 if (tmp > 0) |
|
163 { |
|
164 aAllowedModesMask |= EOneShot; |
|
165 } |
|
166 tmp = securitySettings.iAllowedInteractionModes & NO_MASK; |
|
167 if (tmp > 0) |
|
168 { |
|
169 aAllowedModesMask |= EDenied; |
|
170 } |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 EXPORT_C TInt Midp2PermissionDB::SetFunctionGroupPermission(const TMidp2FunctionGroup& aFunctionGroup, |
|
175 const TMidp2PermissionType& /*aPermissionType*/, |
|
176 const TMidp2PermissionMode& aPermissionMode) |
|
177 { |
|
178 |
|
179 if (aFunctionGroup <= EPhoneCall || aFunctionGroup >= ELastFunctionGroupMarker) |
|
180 { |
|
181 return KErrNotFound; |
|
182 } |
|
183 |
|
184 wstring settingsName = wstring((wchar_t*) KJcfFunctionGroups[aFunctionGroup]); |
|
185 int currentInteractionMode; |
|
186 switch (aPermissionMode) |
|
187 { |
|
188 case EOneShot: |
|
189 currentInteractionMode = 1; |
|
190 break; |
|
191 case ESession: |
|
192 currentInteractionMode = 2; |
|
193 break; |
|
194 case EBlanket: |
|
195 currentInteractionMode = 3; |
|
196 break; |
|
197 case EDenied: |
|
198 currentInteractionMode = 4; |
|
199 break; |
|
200 default: |
|
201 // oneshot |
|
202 currentInteractionMode = 1; |
|
203 break; |
|
204 } |
|
205 StorageUtils* storage = NULL; |
|
206 int result = KErrNotFound; |
|
207 TRAP_IGNORE( |
|
208 storage = StorageUtils::NewL(); |
|
209 CleanupStack::PushL(storage); |
|
210 result = storage->writeMidletSuiteSecuritySettings(iMidletSuiteUid, settingsName, currentInteractionMode); |
|
211 if (result == KErrNone) |
|
212 { |
|
213 if (aPermissionMode == EBlanket) |
|
214 { |
|
215 // "blanket mode, if selected by the user, MUST NOT result in any |
|
216 // additional prompts" (MIDP spec) -> mark down that the prompt |
|
217 // in blanket mode was shown |
|
218 storage->writeUserSecuritySettingsPromptFlag(iMidletSuiteUid, settingsName, true /* prompt is blanket mode was shown */); |
|
219 } |
|
220 } |
|
221 CleanupStack::PopAndDestroy(storage); |
|
222 ); |
|
223 return result; |
|
224 } |
|
225 |
|
226 EXPORT_C TInt Midp2PermissionDB::GetDomainFromName(const TDesC& /*aName*/, |
|
227 TMidp2Domain& /*aDomain*/) |
|
228 { |
|
229 return KErrNotSupported; |
|
230 } |
|
231 |
|
232 EXPORT_C TInt Midp2PermissionDB::GetFunctionGroupFromName( |
|
233 const TDesC& /*aName*/, |
|
234 TMidp2FunctionGroup& /*aFunctionGroup*/) |
|
235 { |
|
236 return KErrNotSupported; |
|
237 } |
|
238 |
|
239 EXPORT_C TInt Midp2PermissionDB::GetPermissionFromName( |
|
240 const TDesC& /*aName*/, TMidp2Permission& /*aPermission*/) |
|
241 { |
|
242 return KErrNotSupported; |
|
243 } |
|
244 |
|
245 EXPORT_C void Midp2PermissionDB::ReadMIDP2ConfigSetting( |
|
246 const enum TMidp2ConfigKey& aKey, TInt& aKeyValue) |
|
247 { |
|
248 aKeyValue = (IsFunctionGroupGranted(aKey) ? 1:0); |
|
249 } |
|
250 |
|
251 TBool Midp2PermissionDB::IsFunctionGroupGranted(TInt aFGIndex) |
|
252 { |
|
253 // boundary check |
|
254 if (aFGIndex < 0 || aFGIndex >= ELastFunctionGroupMarker) |
|
255 { |
|
256 return EFalse; |
|
257 } |
|
258 StorageUtils* storage = NULL; |
|
259 std::vector<MidletSuiteSecuritySettings> securitySettings; |
|
260 int result = KErrNotFound; |
|
261 TRAP_IGNORE( |
|
262 storage = StorageUtils::NewL(); |
|
263 CleanupStack::PushL(storage); |
|
264 result = storage->readMidletSuiteSecuritySettings(iMidletSuiteUid, securitySettings); |
|
265 CleanupStack::PopAndDestroy(storage); |
|
266 ); |
|
267 if (result != KErrNone) |
|
268 { |
|
269 return EFalse; |
|
270 } |
|
271 wstring settingsName = wstring((wchar_t*) KJcfFunctionGroups[aFGIndex]); |
|
272 for (int i=0; i<securitySettings.size(); i++) |
|
273 { |
|
274 if (securitySettings[i].iSettingsName == settingsName) |
|
275 { |
|
276 return ETrue; |
|
277 } |
|
278 } |
|
279 return EFalse; |
|
280 } |