|
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 <centralrepository.h> |
|
18 #include "storagehandler.h" |
|
19 #include "javastoragenames.h" |
|
20 #include "javastorage.h" |
|
21 #include "javastorageexception.h" |
|
22 #include "javasymbianoslayer.h" |
|
23 #include "javauid.h" |
|
24 #include <d32dbms.h> |
|
25 #include "logger.h" |
|
26 #include "j2me/midp2/security/MFunctionGroupBinding.h" |
|
27 #include "j2me/midp2/security/MExtendedProtectionDomain.h" |
|
28 #include "j2me/midp2/security/MFunctionGroup.h" |
|
29 #include "j2me/midp2/security/MPermission.h" |
|
30 #include "midletlist.h" |
|
31 #include "connectionmanager.h" |
|
32 |
|
33 _LIT(KUserDatabaseName, "c:MIDP2SystemAMSUserV2"); |
|
34 _LIT(KMSId, "MSId"); |
|
35 // security preferences table |
|
36 _LIT(KSecurityPreferencesIndexName, "UserMSSecurityPreferencesIndex"); |
|
37 _LIT(KSecurityPreferencesTableName, "UserMSSecurityPreferences"); |
|
38 _LIT(KSecureUid, "secure[102045FE]"); |
|
39 _LIT(KMSName, "MSName"); |
|
40 _LIT(KMSVendor, "MSVendor"); |
|
41 _LIT(KMSVersion, "MSVersion"); |
|
42 _LIT(KMSDomain, "ProtectionDomain"); |
|
43 _LIT(KMSSecurityPrefs, "MSSecurityPrefs"); |
|
44 // custom attributes table |
|
45 _LIT(KCustomAttributesTableName, "MIDletProperties"); |
|
46 _LIT(KCustomAttribsValue, "Value"); |
|
47 |
|
48 const TInt KSecurityPolicyFlags = 0x0200; |
|
49 _LIT(KSecurityPolicy, "midp2_rp"); |
|
50 |
|
51 // This is in the private data cage of javausersettingsconfigurator |
|
52 _LIT(KMidletImportDirectory, "C:\\private\\20022E7A\\data\\"); |
|
53 |
|
54 // Java access point CenRep Id |
|
55 const TInt KJavaAPNRepositoryUid = 0x10206EC5; |
|
56 |
|
57 // CenRep indicator to use the Java default APN |
|
58 const TInt KUseJavaDefaultAPN = -2; |
|
59 |
|
60 // CenRep key for Java default APN key-value pair |
|
61 const TUint32 KJavaDefaultAPNKey = KMaxTUint32; |
|
62 |
|
63 using namespace java::tools::usersettingsconfigurator; |
|
64 using namespace java::storage; |
|
65 using namespace java::util; |
|
66 using namespace MIDP; |
|
67 |
|
68 IMPORT_C MSecurityPolicyV2* GetSecurityPolicyL(TUint32 aFlags, const TDesC& aPolicyName); |
|
69 |
|
70 StorageHandler* StorageHandler::NewL() |
|
71 { |
|
72 StorageHandler* self = new(ELeave) StorageHandler(); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(self); |
|
76 return self; |
|
77 } |
|
78 |
|
79 StorageHandler::StorageHandler() |
|
80 { |
|
81 } |
|
82 |
|
83 void StorageHandler::ConstructL() |
|
84 { |
|
85 User::LeaveIfError(iDbs.Connect()); |
|
86 User::LeaveIfError(iUserDb.Open(iDbs, KUserDatabaseName(), KSecureUid())); |
|
87 User::LeaveIfError(iSecurityPreferencesTable.Open(iUserDb, KSecurityPreferencesTableName)); |
|
88 User::LeaveIfError(iSecurityPreferencesTable.SetIndex(KSecurityPreferencesIndexName)); |
|
89 User::LeaveIfError(iCustomAttributesTable.Open(iUserDb, KCustomAttributesTableName)); |
|
90 // security preferences column identifiers |
|
91 CDbColSet* colSet = iSecurityPreferencesTable.ColSetL(); |
|
92 iSPNameColId = colSet->ColNo(KMSName); |
|
93 iSPVendorColId = colSet->ColNo(KMSVendor); |
|
94 iSPVersionColId = colSet->ColNo(KMSVersion); |
|
95 iSPDomainColId = colSet->ColNo(KMSDomain); |
|
96 iSPPreferencesColId = colSet->ColNo(KMSSecurityPrefs); |
|
97 iSPIdColId = colSet->ColNo(KMSId); |
|
98 // custom attributes column identifiers |
|
99 colSet = iCustomAttributesTable.ColSetL(); |
|
100 iCAIdColId = colSet->ColNo(KMSId); |
|
101 iCAValueColId = colSet->ColNo(KCustomAttribsValue); |
|
102 delete colSet; |
|
103 try |
|
104 { |
|
105 iStorage = JavaStorage::createInstance(); |
|
106 iStorage->open(); |
|
107 } |
|
108 catch (JavaStorageException& aJse) |
|
109 { |
|
110 User::Leave(aJse.mStatus); |
|
111 } |
|
112 iSecurityPolicy = GetSecurityPolicyL(KSecurityPolicyFlags, KSecurityPolicy); |
|
113 } |
|
114 |
|
115 void StorageHandler::ReadSecuritySettingsL(std::vector<MidletSuiteSecuritySettings*>& aMidletSuitesSecuritySettings) |
|
116 { |
|
117 TUint32 cnt = iSecurityPreferencesTable.CountL(); |
|
118 iSecurityPreferencesTable.BeginningL(); |
|
119 for (int i=0; i<cnt; i++) |
|
120 { |
|
121 iSecurityPreferencesTable.NextL(); |
|
122 iSecurityPreferencesTable.GetL(); |
|
123 |
|
124 // alloc the buffers |
|
125 HBufC* name = HBufC::NewLC(iSecurityPreferencesTable.ColLength(iSPNameColId)); |
|
126 TPtr namePtr = name->Des(); |
|
127 HBufC* vendor = HBufC::NewLC(iSecurityPreferencesTable.ColLength(iSPVendorColId)); |
|
128 TPtr vendorPtr = vendor->Des(); |
|
129 HBufC* version = HBufC::NewLC(iSecurityPreferencesTable.ColLength(iSPVersionColId)); |
|
130 TPtr versionPtr = version->Des(); |
|
131 HBufC* domain = HBufC::NewLC(iSecurityPreferencesTable.ColLength(iSPDomainColId)); |
|
132 TPtr domainPtr = domain->Des(); |
|
133 HBufC8* securityPrefs = HBufC8::NewLC(iSecurityPreferencesTable.ColLength(iSPPreferencesColId)); |
|
134 TPtr8 securityPrefsPtr = securityPrefs->Des(); |
|
135 TUint32 suiteUid = iSecurityPreferencesTable.ColUint32(iSPIdColId); |
|
136 |
|
137 // fill in the buffers |
|
138 RDbColReadStream in; |
|
139 in.OpenL(iSecurityPreferencesTable, iSPNameColId); |
|
140 in.ReadL(namePtr, iSecurityPreferencesTable.ColLength(iSPNameColId)); |
|
141 in.Close(); |
|
142 in.OpenL(iSecurityPreferencesTable, iSPVendorColId); |
|
143 in.ReadL(vendorPtr, iSecurityPreferencesTable.ColLength(iSPVendorColId)); |
|
144 in.Close(); |
|
145 in.OpenL(iSecurityPreferencesTable, iSPVersionColId); |
|
146 in.ReadL(versionPtr, iSecurityPreferencesTable.ColLength(iSPVersionColId)); |
|
147 in.Close(); |
|
148 in.OpenL(iSecurityPreferencesTable, iSPDomainColId); |
|
149 in.ReadL(domainPtr, iSecurityPreferencesTable.ColLength(iSPDomainColId)); |
|
150 in.Close(); |
|
151 in.OpenL(iSecurityPreferencesTable, iSPPreferencesColId); |
|
152 in.ReadL(securityPrefsPtr, iSecurityPreferencesTable.ColLength(iSPPreferencesColId)); |
|
153 in.Close(); |
|
154 |
|
155 // process the buffers |
|
156 std::wstring suiteName((wchar_t*) name->Ptr(), name->Length()); |
|
157 std::wstring suiteVendor((wchar_t*) vendor->Ptr(), vendor->Length()); |
|
158 std::wstring suiteVersion((wchar_t*) version->Ptr(), version->Length()); |
|
159 std::string prefs((char *) securityPrefs->Ptr(), securityPrefs->Length()); |
|
160 std::wstring securitySettingsName = L""; |
|
161 std::wstring currentInteractionMode = L""; |
|
162 std::vector<SecuritySettings*> securitySettings; |
|
163 DecodeSecuritySettingsL(domainPtr, std::string((char *) securityPrefs->Ptr(), securityPrefs->Length()), securitySettings); |
|
164 if (securitySettings.size() > 0) |
|
165 { |
|
166 MidletSuiteSecuritySettings* suiteSecuritySettings = |
|
167 new MidletSuiteSecuritySettings(suiteUid, suiteName, suiteVendor, suiteVersion); |
|
168 suiteSecuritySettings->iSecuritySettings = securitySettings; |
|
169 aMidletSuitesSecuritySettings.push_back(suiteSecuritySettings); |
|
170 } |
|
171 |
|
172 // free the buffers |
|
173 CleanupStack::PopAndDestroy(securityPrefs); |
|
174 CleanupStack::PopAndDestroy(domain); |
|
175 CleanupStack::PopAndDestroy(version); |
|
176 CleanupStack::PopAndDestroy(vendor); |
|
177 CleanupStack::PopAndDestroy(name); |
|
178 } |
|
179 } |
|
180 |
|
181 void StorageHandler::WriteSecuritySettingsL(const std::vector<MidletSuiteSecuritySettings*>& aMidletSuitesSecuritySettings) |
|
182 { |
|
183 for (int i=0; i<aMidletSuitesSecuritySettings.size(); i++) |
|
184 { |
|
185 try |
|
186 { |
|
187 // get the UID of the suite |
|
188 JavaStorageApplicationEntry_t query; |
|
189 JavaStorageApplicationList_t queryResult; |
|
190 JavaStorageEntry attr; |
|
191 std::wstring midletSuiteUid = L""; |
|
192 attr.setEntry(ID, L""); |
|
193 query.insert(attr); |
|
194 attr.setEntry(PACKAGE_NAME, aMidletSuitesSecuritySettings[i]->iName); |
|
195 query.insert(attr); |
|
196 attr.setEntry(VENDOR, aMidletSuitesSecuritySettings[i]->iVendor); |
|
197 query.insert(attr); |
|
198 attr.setEntry(VERSION, aMidletSuitesSecuritySettings[i]->iVersion); |
|
199 query.insert(attr); |
|
200 iStorage->search(APPLICATION_PACKAGE_TABLE, query, queryResult); |
|
201 findEntry(queryResult, ID, midletSuiteUid); |
|
202 if (midletSuiteUid.size() > 0) |
|
203 { |
|
204 // write the currentInteractionMode |
|
205 for (int j=0; j<aMidletSuitesSecuritySettings[i]->iSecuritySettings.size(); j++) |
|
206 { |
|
207 // check that the function group exists and the current |
|
208 // interaction mode is found among the allowed interaction modes |
|
209 JavaStorageApplicationEntry_t fgQuery; |
|
210 JavaStorageApplicationList_t fgQueryResult; |
|
211 attr.setEntry(ID, midletSuiteUid); |
|
212 fgQuery.insert(attr); |
|
213 attr.setEntry(FUNCTION_GROUP, aMidletSuitesSecuritySettings[i]->iSecuritySettings[j]->iName); |
|
214 fgQuery.insert(attr); |
|
215 attr.setEntry(ALLOWED_SETTINGS, L""); |
|
216 fgQuery.insert(attr); |
|
217 std::wstring allowedInteractionModes = L""; |
|
218 iStorage->search(MIDP_FUNC_GRP_SETTINGS_TABLE, fgQuery, fgQueryResult); |
|
219 findEntry(fgQueryResult, ALLOWED_SETTINGS, allowedInteractionModes); |
|
220 if (IsInteractionModeAllowed(aMidletSuitesSecuritySettings[i]->iSecuritySettings[j]->iCurrentInteractionMode, |
|
221 allowedInteractionModes)) |
|
222 { |
|
223 JavaStorageApplicationEntry_t newEntry; |
|
224 JavaStorageApplicationEntry_t oldEntry; |
|
225 attr.setEntry(ID, midletSuiteUid); |
|
226 newEntry.insert(attr); |
|
227 oldEntry.insert(attr); |
|
228 attr.setEntry(FUNCTION_GROUP, aMidletSuitesSecuritySettings[i]->iSecuritySettings[j]->iName); |
|
229 newEntry.insert(attr); |
|
230 oldEntry.insert(attr); |
|
231 attr.setEntry(CURRENT_SETTING, aMidletSuitesSecuritySettings[i]->iSecuritySettings[j]->iCurrentInteractionMode); |
|
232 newEntry.insert(attr); |
|
233 iStorage->update(MIDP_FUNC_GRP_SETTINGS_TABLE, newEntry, oldEntry); |
|
234 } |
|
235 } |
|
236 } |
|
237 } |
|
238 catch (JavaStorageException& aJse) |
|
239 { |
|
240 ELOG1(EJavaConverters, "Can not write security settings to storage: %s", aJse.toString().c_str()); |
|
241 } |
|
242 } |
|
243 } |
|
244 |
|
245 void StorageHandler::ReadCustomAttributesL(std::vector<MidletSuiteCustomAttributes*>& aMidletSuitesCustomAttributes) |
|
246 { |
|
247 TUint32 cnt = iCustomAttributesTable.CountL(); |
|
248 iCustomAttributesTable.BeginningL(); |
|
249 for (int i=0; i<cnt; i++) |
|
250 { |
|
251 iCustomAttributesTable.NextL(); |
|
252 iCustomAttributesTable.GetL(); |
|
253 TUint32 suiteUid = iCustomAttributesTable.ColUint32(iCAIdColId); |
|
254 HBufC8* customAttribs = HBufC8::NewLC(iCustomAttributesTable.ColLength(iCAValueColId)); |
|
255 TPtr8 customAttribsPtr = customAttribs->Des(); |
|
256 RDbColReadStream in; |
|
257 in.OpenL(iCustomAttributesTable, iCAValueColId); |
|
258 in.ReadL(customAttribsPtr, iCustomAttributesTable.ColLength(iCAValueColId)); |
|
259 in.Close(); |
|
260 |
|
261 // the custom attributes are stored in the following form: |
|
262 // attrib_count attrib1_name_length attrib1_name attrib1_value_length attrib1_value ... |
|
263 // where attrib_count is 4 bytes |
|
264 // attribX_name_length is 4 bytes |
|
265 // attribX_name is multiple of 4 |
|
266 // attribX_value_length is 4 bytes |
|
267 // attribX_value is multiple of 4 with first 4 bytes as a flag applicable to the value |
|
268 // and the rest of the bytes the actual value |
|
269 const TUint8* ptr = customAttribs->Ptr() + 4; |
|
270 TUint32 attrib_count = *((TUint32*)customAttribs->Ptr()); |
|
271 |
|
272 for (TUint32 i = 0; i < attrib_count; i++) |
|
273 { |
|
274 TPtrC attrib_name; |
|
275 TPtrC attrib_value; |
|
276 |
|
277 // read the attrib_name_length and move the pointer further |
|
278 TUint32 attrib_name_length = *((TUint32*)ptr); |
|
279 ptr += 4; |
|
280 // read the attrib_name and move the pointer further |
|
281 attrib_name.Set((const TUint16*)ptr, attrib_name_length); |
|
282 // skip everything until we hit the multiple of 4 bytes |
|
283 ptr += ((2 * attrib_name_length + (4 - ((2 * attrib_name_length) % 4)))); |
|
284 |
|
285 // read the attrib_value_length and move the pointer further |
|
286 TUint32 attrib_value_length = *((TUint32*)ptr); |
|
287 // skip the 8 bytes (4 bytes for the length and another 4 bytes for the the flag associated with the value) |
|
288 ptr += 8; |
|
289 // read the attrib_value and move the pointer further |
|
290 attrib_value.Set((const TUint16*)ptr, ((2*attrib_value_length) - 4)/2); |
|
291 // skip everything until we hit the multiple of 4 bytes |
|
292 ptr += ((2 * attrib_value_length + (4 - ((2 * attrib_value_length) % 4)))); |
|
293 |
|
294 // map the value to the value known by omj |
|
295 CustomAttribute* customAttribute = NULL; |
|
296 if (attrib_value.Compare(_L("gameactions")) == 0) |
|
297 { |
|
298 customAttribute = new CustomAttribute( |
|
299 std::wstring((wchar_t*)attrib_name.Ptr(), |
|
300 attrib_name.Length()), |
|
301 L"1"); |
|
302 } |
|
303 else if (attrib_value.Compare(_L("no")) == 0) |
|
304 { |
|
305 customAttribute = new CustomAttribute( |
|
306 std::wstring((wchar_t*)attrib_name.Ptr(), |
|
307 attrib_name.Length()), |
|
308 L"0"); |
|
309 } |
|
310 else if (attrib_value.Compare(_L("navigationkeys")) == 0) |
|
311 { |
|
312 customAttribute = new CustomAttribute( |
|
313 std::wstring((wchar_t*)attrib_name.Ptr(), |
|
314 attrib_name.Length()), |
|
315 L"2"); |
|
316 } |
|
317 else |
|
318 { |
|
319 // unknown value -> ignore |
|
320 continue; |
|
321 } |
|
322 |
|
323 std::vector<CustomAttribute*> customAttributes; |
|
324 customAttributes.push_back(customAttribute); |
|
325 MidletSuiteCustomAttributes* suiteCustomAttributes = |
|
326 new MidletSuiteCustomAttributes(suiteUid); |
|
327 suiteCustomAttributes->iCustomAttributes = customAttributes; |
|
328 aMidletSuitesCustomAttributes.push_back(suiteCustomAttributes); |
|
329 } |
|
330 |
|
331 CleanupStack::PopAndDestroy(customAttribs); |
|
332 } |
|
333 } |
|
334 |
|
335 void StorageHandler::WriteCustomAttributesL(const std::vector<MidletSuiteCustomAttributes*>& aMidletSuitesCustomAttributes) |
|
336 { |
|
337 for (int i=0; i<aMidletSuitesCustomAttributes.size(); i++) |
|
338 { |
|
339 for (int j=0; j<aMidletSuitesCustomAttributes[i]->iCustomAttributes.size(); j++) |
|
340 { |
|
341 try |
|
342 { |
|
343 if (aMidletSuitesCustomAttributes[i]->iCustomAttributes[j]->iName |
|
344 != L"Nokia-MIDlet-On-Screen-Keypad") |
|
345 { |
|
346 continue; |
|
347 } |
|
348 // try to update the value |
|
349 TUid tuid; |
|
350 tuid.iUid = aMidletSuitesCustomAttributes[i]->iUid; |
|
351 Uid uid; |
|
352 TUidToUid(tuid, uid); |
|
353 JavaStorageApplicationEntry_t oldEntry; |
|
354 JavaStorageEntry attr; |
|
355 attr.setEntry(ID, uid.toString()); |
|
356 oldEntry.insert(attr); |
|
357 JavaStorageApplicationEntry_t entry; |
|
358 attr.setEntry(ON_SCREEN_KEYPAD, aMidletSuitesCustomAttributes[i]->iCustomAttributes[j]->iValue); |
|
359 entry.insert(attr); |
|
360 iStorage->update(MIDP_PACKAGE_TABLE, entry, oldEntry); |
|
361 } |
|
362 catch (JavaStorageException& aJse) |
|
363 { |
|
364 ELOG1(EJavaConverters, "Can not write custom attributes to storage: %s", aJse.toString().c_str()); |
|
365 } |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 void StorageHandler::readMidletSuitesPropertiesL(std::vector<MidletSuiteSecuritySettings*>& aMidletSuitesSecuritySettings, std::vector<MidletSuiteCustomAttributes*>& aMidletSuitesCustomAttributes) |
|
371 { |
|
372 // read security settings |
|
373 ReadSecuritySettingsL(aMidletSuitesSecuritySettings); |
|
374 |
|
375 // read custom attributes |
|
376 ReadCustomAttributesL(aMidletSuitesCustomAttributes); |
|
377 } |
|
378 |
|
379 void StorageHandler::writeMidletSuitePropertiesL(const std::vector<MidletSuiteSecuritySettings*>& aMidletSuitesSecuritySettings, const std::vector<MidletSuiteCustomAttributes*>& aMidletSuitesCustomAttributes) |
|
380 { |
|
381 // write security settings |
|
382 WriteSecuritySettingsL(aMidletSuitesSecuritySettings); |
|
383 |
|
384 // write custom attributes |
|
385 WriteCustomAttributesL(aMidletSuitesCustomAttributes); |
|
386 } |
|
387 |
|
388 void StorageHandler::convertAPNSettingsL() const |
|
389 { |
|
390 TFileName dataFile(KMidletImportDirectory); |
|
391 dataFile.Append(KMidletExportDataFileName); |
|
392 TUint attributes; |
|
393 RFs fs; |
|
394 TInt err = fs.Connect(); |
|
395 if (KErrNone != err) |
|
396 { |
|
397 ELOG1(EJavaConverters, "Cannot open RFs connection, err %d ", err); |
|
398 return; |
|
399 } |
|
400 |
|
401 err = fs.Att(dataFile, attributes); |
|
402 if (KErrNone != err) |
|
403 { |
|
404 ELOG1(EJavaConverters, "Cannot handle imported file: %d ", err); |
|
405 fs.Close(); |
|
406 return; |
|
407 } |
|
408 |
|
409 TFileName importDirectory(KMidletImportDirectory); |
|
410 |
|
411 CMidletList* midlets = new(ELeave) CMidletList(); |
|
412 TRAP(err, midlets->ImportListL(fs, importDirectory)); |
|
413 |
|
414 if (err == KErrNone) |
|
415 { |
|
416 TUid repUid = TUid::Uid(KJavaAPNRepositoryUid); |
|
417 std::auto_ptr<CRepository> rep(CRepository::NewL(repUid)); |
|
418 |
|
419 JavaStorageApplicationEntry_t matchEntry; |
|
420 JavaStorageApplicationEntry_t updateEntry; |
|
421 JavaStorageEntry attr; |
|
422 |
|
423 for (TInt i = 0; i < midlets->Count(); i++) |
|
424 { |
|
425 const CMidletInfo* oneApp = midlets->GetNext(); |
|
426 TInt apnId = -1; |
|
427 TInt err = rep->Get(oneApp->GetSuiteId(), apnId); |
|
428 |
|
429 if (KErrNone != err) |
|
430 { |
|
431 continue; |
|
432 } |
|
433 |
|
434 if (KUseJavaDefaultAPN == apnId) |
|
435 { |
|
436 rep->Get(KJavaDefaultAPNKey, apnId); |
|
437 } |
|
438 |
|
439 matchEntry.clear(); |
|
440 updateEntry.clear(); |
|
441 |
|
442 try |
|
443 { |
|
444 java::util::Uid appUid; |
|
445 JavaStorageApplicationEntry_t foundEntry; |
|
446 |
|
447 iStorage->read(APPLICATION_TABLE, |
|
448 TUidToUid(oneApp->GetMidletUid(), appUid), foundEntry); |
|
449 |
|
450 attr.setEntry(PACKAGE_ID, L""); |
|
451 JavaStorageApplicationEntry_t::const_iterator finder |
|
452 = foundEntry.find(attr); |
|
453 |
|
454 java::util::Uid suiteUid((*finder).entryValue()); |
|
455 ConnectionManager::setApnIdL(suiteUid, apnId); |
|
456 } |
|
457 catch (JavaStorageException& jse) |
|
458 { |
|
459 ELOG2(EJavaConverters, |
|
460 "Cannot write APN Id: %d of App: %d", |
|
461 apnId, |
|
462 oneApp->GetMidletUid().iUid); |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 midlets->ResetAndDestroy(); |
|
468 fs.Delete(dataFile); |
|
469 fs.Close(); |
|
470 |
|
471 LOG(EJavaConverters, EInfo, "APNs converted"); |
|
472 } |
|
473 |
|
474 StorageHandler::~StorageHandler() |
|
475 { |
|
476 iSecurityPreferencesTable.Close(); |
|
477 iCustomAttributesTable.Close(); |
|
478 iUserDb.Close(); |
|
479 iDbs.Close(); |
|
480 if (iStorage) |
|
481 { |
|
482 iStorage->close(); |
|
483 delete iStorage; |
|
484 iStorage = NULL; |
|
485 } |
|
486 delete iSecurityPolicy; |
|
487 } |
|
488 |
|
489 void StorageHandler::DecodeSecuritySettingsL(const TDesC& aProtectionDomain, const std::string& aEncodedSecuritySettings, std::vector<SecuritySettings*>& aSecuritySettings) |
|
490 { |
|
491 int BITS_PER_BYTE = 8; |
|
492 int BITS_PER_GROUP = 2; |
|
493 int GROUPS_PER_BYTE = (BITS_PER_BYTE/BITS_PER_GROUP); |
|
494 RPointerArray<const MFunctionGroupBinding> bindings; |
|
495 if (aProtectionDomain.Length() > 0) |
|
496 { |
|
497 iSecurityPolicy->ProtectionDomainL(aProtectionDomain).FunctionGroupBindingsL(bindings); |
|
498 } |
|
499 else |
|
500 { |
|
501 iSecurityPolicy->UntrustedProtectionDomainL().FunctionGroupBindingsL(bindings); |
|
502 } |
|
503 TInt count = bindings.Count(); |
|
504 for (TInt i = 0; i < count; i++) |
|
505 { |
|
506 const MFunctionGroupBinding& binding = *(bindings[i]); |
|
507 HBufC* name = binding.FunctionGroup().Name().AllocLC(); |
|
508 std::wstring securitySettingsName = L""; |
|
509 std::wstring currentInteractionMode = L""; |
|
510 // mape the current interaction mode |
|
511 // try to read it from the encoded string -> if it fails, then go on with the default |
|
512 TInt byteIndex = (i * BITS_PER_GROUP) / BITS_PER_BYTE; |
|
513 TInt bitIndex = (i - (byteIndex * GROUPS_PER_BYTE)) * BITS_PER_GROUP; |
|
514 if (byteIndex < aEncodedSecuritySettings.size()) |
|
515 { |
|
516 switch (((aEncodedSecuritySettings[byteIndex] >> bitIndex) & 3)) |
|
517 { |
|
518 case 1: |
|
519 // blanket |
|
520 currentInteractionMode = L"3"; |
|
521 break; |
|
522 case 2: |
|
523 // oneshot |
|
524 currentInteractionMode = L"1"; |
|
525 break; |
|
526 case 3: |
|
527 // session |
|
528 currentInteractionMode = L"2"; |
|
529 break; |
|
530 default: |
|
531 // denied |
|
532 currentInteractionMode = L"4"; |
|
533 } |
|
534 } |
|
535 if (currentInteractionMode.size() == 0) |
|
536 { |
|
537 // get the default one from the legacy policy |
|
538 switch (binding.DefaultInteractionMode()) |
|
539 { |
|
540 case MPermission::EDenied: |
|
541 currentInteractionMode = L"4"; |
|
542 break; |
|
543 case MPermission::EBlanket: |
|
544 currentInteractionMode = L"3"; |
|
545 break; |
|
546 case MPermission::EOneshot: |
|
547 currentInteractionMode = L"1"; |
|
548 break; |
|
549 case MPermission::ESession: |
|
550 currentInteractionMode = L"2"; |
|
551 break; |
|
552 } |
|
553 } |
|
554 if (currentInteractionMode.size() > 0) |
|
555 { |
|
556 aSecuritySettings.push_back(new SecuritySettings( |
|
557 std::wstring((wchar_t*) name->Ptr(), name->Length()), currentInteractionMode)); |
|
558 } |
|
559 CleanupStack::PopAndDestroy(name); |
|
560 } |
|
561 bindings.Close(); |
|
562 } |
|
563 |
|
564 bool StorageHandler::IsInteractionModeAllowed(const std::wstring& aInteractionMode, const std::wstring& aAllowedInteractionModes) |
|
565 { |
|
566 bool res = false; |
|
567 if (aAllowedInteractionModes.size() > 0) |
|
568 { |
|
569 int interactionMode = JavaCommonUtils::wstringToInt(aInteractionMode); |
|
570 // 1 = ONESHOT, 2 = SESSION, 3 = BLANKET, 4 = NO |
|
571 int allowedInteractionModes = JavaCommonUtils::wstringToInt(aAllowedInteractionModes); |
|
572 // allowedInteraction is a 4 bit number with the following representation: |
|
573 // oneshot session blanket no |
|
574 // E.g. 1011 (=11 in decimal) means that oneshot, blanket and no are allowed |
|
575 bool oneshotAllowed = ((allowedInteractionModes & 0x8) == 0x8); |
|
576 bool sessionAllowed = ((allowedInteractionModes & 0x4) == 0x4); |
|
577 bool blanketAllowed = ((allowedInteractionModes & 0x2) == 0x2); |
|
578 bool noAllowed = ((allowedInteractionModes & 0x1) == 0x1); |
|
579 res = (interactionMode == 1 && oneshotAllowed) |
|
580 || (interactionMode == 2 && sessionAllowed) |
|
581 || (interactionMode == 3 && blanketAllowed) |
|
582 || (interactionMode == 4 && noAllowed); |
|
583 } |
|
584 return res; |
|
585 } |
|
586 |
|
587 void StorageHandler::findEntry(const JavaStorageApplicationList_t& queryResult, |
|
588 const std::wstring& eName, |
|
589 std::wstring& eValue) |
|
590 { |
|
591 if (queryResult.size() > 0) |
|
592 { |
|
593 JavaStorageApplicationEntry_t entry = queryResult.front(); |
|
594 JavaStorageEntry findPattern; |
|
595 findPattern.setEntry(eName, L""); |
|
596 JavaStorageApplicationEntry_t::const_iterator findIterator = |
|
597 entry.find(findPattern); |
|
598 if (findIterator != entry.end()) |
|
599 { |
|
600 eValue = findIterator->entryValue(); |
|
601 } |
|
602 } |
|
603 } |
|
604 |
|
605 MidletSuiteSecuritySettings::MidletSuiteSecuritySettings(const TUint32& aUid, |
|
606 const std::wstring& aName, |
|
607 const std::wstring& aVendor, |
|
608 const std::wstring& aVersion) |
|
609 : iUid(aUid), iName(aName), iVendor(aVendor), iVersion(aVersion) |
|
610 { |
|
611 } |
|
612 |
|
613 SecuritySettings::SecuritySettings(const std::wstring& aName, |
|
614 const std::wstring& aCurrentInteractionMode) |
|
615 : iName(aName), iCurrentInteractionMode(aCurrentInteractionMode) |
|
616 { |
|
617 } |
|
618 |
|
619 SecuritySettings& SecuritySettings::operator=(const SecuritySettings& aSecuritySettings) |
|
620 { |
|
621 iName = aSecuritySettings.iName; |
|
622 iCurrentInteractionMode = aSecuritySettings.iCurrentInteractionMode; |
|
623 return *this; |
|
624 } |
|
625 |
|
626 SecuritySettings::SecuritySettings() |
|
627 : iName(L""), iCurrentInteractionMode(L"") |
|
628 { |
|
629 } |
|
630 |
|
631 CustomAttribute::CustomAttribute(const std::wstring& aName, |
|
632 const std::wstring& aValue) |
|
633 : iName(aName), iValue(aValue) |
|
634 { |
|
635 } |
|
636 |
|
637 CustomAttribute& CustomAttribute::operator=(const CustomAttribute& aCustomAttribute) |
|
638 { |
|
639 iName = aCustomAttribute.iName; |
|
640 iValue = aCustomAttribute.iValue; |
|
641 return *this; |
|
642 } |
|
643 |
|
644 CustomAttribute::CustomAttribute() |
|
645 : iName(L""), iValue(L"") |
|
646 { |
|
647 } |
|
648 |
|
649 MidletSuiteCustomAttributes::MidletSuiteCustomAttributes(const TUint32& aMidletSuiteUid) |
|
650 : iUid(aMidletSuiteUid) |
|
651 { |
|
652 } |