|
1 /* |
|
2 * Copyright (c) 2005-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: writeablejavaregistryentry implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 #include <memory> |
|
22 |
|
23 #include "javacommonutils.h" |
|
24 #include "javaregistryentry.h" |
|
25 #include "javastoragenames.h" |
|
26 #include "javasymbianoslayer.h" |
|
27 #include "javauid.h" |
|
28 #include "logger.h" |
|
29 #include "midpauthenticationmodule.h" |
|
30 #include "writeablejavaregistryentry.h" |
|
31 #include "writeablejavaregistrypackageentry.h" |
|
32 |
|
33 using namespace Java; |
|
34 using namespace Java::Manager::Registry; |
|
35 using namespace java::storage; |
|
36 using namespace java::util; |
|
37 using namespace std; |
|
38 |
|
39 // ============================ MEMBER FUNCTIONS ============================= |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CWriteableJavaRegistryEntry::CWriteableJavaRegistryEntry |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CWriteableJavaRegistryEntry::CWriteableJavaRegistryEntry |
|
46 (JavaStorageApplicationEntry_t& aEntry, TJavaRegistryEntryType aType) : |
|
47 iEntry(aEntry), iType(aType) |
|
48 { |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CWriteableJavaRegistryEntry::~CWriteableJavaRegistryEntry |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CWriteableJavaRegistryEntry::~CWriteableJavaRegistryEntry() |
|
56 { |
|
57 iAttributes.ResetAndDestroy(); |
|
58 iCertificates.ResetAndDestroy(); |
|
59 |
|
60 if (iName) |
|
61 { |
|
62 delete iName; |
|
63 iName = NULL; |
|
64 } |
|
65 |
|
66 if (iDrmContentId) |
|
67 { |
|
68 delete iDrmContentId; |
|
69 iDrmContentId = NULL; |
|
70 } |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CWriteableJavaRegistryEntry::Uid |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C TUid CWriteableJavaRegistryEntry::Uid() const |
|
78 { |
|
79 JELOG2(EJavaStorage); |
|
80 TUid uid; |
|
81 wstring value; |
|
82 EntryAttributeValue(iEntry, ID, value); |
|
83 if (value.size() > 0) |
|
84 { |
|
85 java::util::Uid omjUid(value); |
|
86 TInt err = uidToTUid(omjUid, uid); |
|
87 if (KErrNone != err) |
|
88 { |
|
89 ELOG1(EJavaStorage, "Uid to TUid conversion failed: %d", err); |
|
90 uid = TUid::Null(); |
|
91 } |
|
92 } |
|
93 else |
|
94 { |
|
95 uid = TUid::Null(); |
|
96 } |
|
97 return uid; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CWriteableJavaRegistryEntry::Name |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C const TDesC& CWriteableJavaRegistryEntry::Name() const |
|
105 { |
|
106 JELOG2(EJavaStorage); |
|
107 |
|
108 if (!iName) |
|
109 { |
|
110 wstring value = L""; |
|
111 |
|
112 if (EMidp2MidletSuite == iType) |
|
113 { |
|
114 EntryAttributeValue(iEntry, PACKAGE_NAME, value); |
|
115 } |
|
116 else // Application |
|
117 { |
|
118 EntryAttributeValue(iEntry, NAME, value); |
|
119 } |
|
120 |
|
121 if (value.size() > 0) |
|
122 { |
|
123 iName = wstringToBuf(value); |
|
124 } |
|
125 else |
|
126 { |
|
127 return KNullDesC; |
|
128 } |
|
129 } |
|
130 return *iName; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CWriteableJavaRegistryEntry::Type |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C Java::TJavaRegistryEntryType CWriteableJavaRegistryEntry:: |
|
138 Type() const |
|
139 { |
|
140 return iType; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CWriteableJavaRegistryEntry::Drive |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C TDriveNumber CWriteableJavaRegistryEntry::Drive() const |
|
148 { |
|
149 JELOG2(EJavaStorage); |
|
150 |
|
151 wstring value = L""; |
|
152 |
|
153 if (EMidp2MidletSuite == iType) |
|
154 { |
|
155 EntryAttributeValue(iEntry, ROOT_PATH, value); |
|
156 } |
|
157 else // Application |
|
158 { |
|
159 EntryAttributeValue(iEntry, PACKAGE_ID, value); |
|
160 |
|
161 java::util::Uid suiteUid(value); |
|
162 JavaStorageApplicationEntry_t suiteEntry; |
|
163 |
|
164 StorageEntry(suiteUid, APPLICATION_PACKAGE_TABLE, suiteEntry); |
|
165 EntryAttributeValue(suiteEntry, ROOT_PATH, value); |
|
166 |
|
167 suiteEntry.clear(); |
|
168 } |
|
169 |
|
170 // Original implementation returns EDriveC in a case of failure. |
|
171 TInt driveNumber = EDriveC; |
|
172 |
|
173 if (value.size() > 0) |
|
174 { |
|
175 wstring::size_type start = 0; |
|
176 wstring::size_type end = 1; |
|
177 |
|
178 char* driveLetter = 0; |
|
179 |
|
180 try |
|
181 { |
|
182 driveLetter = JavaCommonUtils::wstringToUtf8( |
|
183 value.substr(start, end)); |
|
184 |
|
185 TInt err = RFs::CharToDrive(driveLetter[0], driveNumber); |
|
186 |
|
187 if (KErrNone != err) |
|
188 { |
|
189 WLOG2(EJavaStorage, |
|
190 "Drive number conversion fault: %d. Letter: %c", |
|
191 err, driveLetter[0]); |
|
192 } |
|
193 |
|
194 delete[] driveLetter; |
|
195 } |
|
196 catch (ExceptionBase& e) |
|
197 { |
|
198 ELOG1WSTR( |
|
199 EJavaStorage, |
|
200 "Drive letter UTF-8 conversion failed for string: %s", |
|
201 value.substr(start, end)); |
|
202 } |
|
203 } |
|
204 |
|
205 return (TDriveNumber) driveNumber; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // CWriteableJavaRegistryEntry::NumberOfCertificateChains |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C TInt CWriteableJavaRegistryEntry::NumberOfCertificateChains() const |
|
213 { |
|
214 JELOG2(EJavaStorage); |
|
215 |
|
216 if (iCertificates.Count() == 0) |
|
217 { |
|
218 PopulateCertChains(); |
|
219 } |
|
220 |
|
221 return iCertificates.Count(); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CWriteableJavaRegistryEntry::CertificateChain |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C const TDesC8& CWriteableJavaRegistryEntry:: |
|
229 CertificateChain(TInt aIndex) const |
|
230 { |
|
231 JELOG2(EJavaStorage); |
|
232 |
|
233 if (iCertificates.Count() == 0) |
|
234 { |
|
235 PopulateCertChains(); |
|
236 } |
|
237 |
|
238 if (aIndex < 0 || iCertificates.Count() <= aIndex) |
|
239 { |
|
240 return KNullDesC8; |
|
241 } |
|
242 return *(iCertificates[aIndex]); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // CWriteableJavaRegistryEntry::DrmContentId |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C const TDesC& CWriteableJavaRegistryEntry::DrmContentId() const |
|
250 { |
|
251 JELOG2(EJavaStorage); |
|
252 |
|
253 if (!iDrmContentId) |
|
254 { |
|
255 wstring value = L""; |
|
256 |
|
257 if (EMidp2MidletSuite == iType) |
|
258 { |
|
259 EntryAttributeValue(iEntry, CONTENT_ID, value); |
|
260 } |
|
261 else // Application |
|
262 { |
|
263 EntryAttributeValue(iEntry, PACKAGE_ID, value); |
|
264 java::util::Uid suiteUid(value); |
|
265 JavaStorageApplicationEntry_t suiteEntry; |
|
266 |
|
267 StorageEntry(suiteUid, APPLICATION_PACKAGE_TABLE, suiteEntry); |
|
268 EntryAttributeValue(suiteEntry, CONTENT_ID, value); |
|
269 suiteEntry.clear(); |
|
270 } |
|
271 |
|
272 if (value.size() > 0) |
|
273 { |
|
274 iDrmContentId = wstringToBuf(value); |
|
275 } |
|
276 else |
|
277 { |
|
278 return KNullDesC; |
|
279 } |
|
280 } |
|
281 return *iDrmContentId; |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // CWriteableJavaRegistryEntry::AttributeL |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C const MJavaAttribute* CWriteableJavaRegistryEntry:: |
|
289 AttributeL(const TDesC& aName) const |
|
290 { |
|
291 JELOG2(EJavaStorage); |
|
292 |
|
293 if (0 == aName.Size()) |
|
294 { |
|
295 ELOG(EJavaStorage, "Empty attribute name"); |
|
296 User::Leave(KErrArgument); |
|
297 } |
|
298 |
|
299 // If attributes are not already read. These are manifest attributes |
|
300 // and they are not updated unless application suite is re-installed. |
|
301 if (iAttributes.Count() == 0) |
|
302 { |
|
303 AttributesL(); |
|
304 } |
|
305 |
|
306 CJavaAttribute* regAttr = NULL; |
|
307 |
|
308 for (TInt i = 0; i < iAttributes.Count(); i++) |
|
309 { |
|
310 if (0 == (iAttributes[i])->Name().Compare(aName)) |
|
311 { |
|
312 regAttr = CJavaAttribute::NewL((iAttributes[i])->Name(), |
|
313 (iAttributes[i])->Value(), |
|
314 (iAttributes[i])->Trusted()); |
|
315 break; |
|
316 } |
|
317 } |
|
318 return regAttr; |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // CWriteableJavaRegistryEntry::AttributesL |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C const RPointerArray<MJavaAttribute>& |
|
326 CWriteableJavaRegistryEntry::AttributesL() const |
|
327 { |
|
328 JELOG2(EJavaStorage); |
|
329 |
|
330 // If attributes are already read. These are manifest attributes and they |
|
331 // are not updated unless application suite is reinstalled. |
|
332 if (iAttributes.Count() > 0) |
|
333 { |
|
334 |
|
335 return iAttributes; |
|
336 } |
|
337 |
|
338 wstring value = L""; |
|
339 JavaStorageApplicationList_t attributeList; |
|
340 |
|
341 if (EMidp2MidletSuite == iType) |
|
342 { |
|
343 EntryAttributeValue(iEntry, ID, value); |
|
344 } |
|
345 else // Application |
|
346 { |
|
347 // Get suiteID where application belongs to. |
|
348 EntryAttributeValue(iEntry, PACKAGE_ID, value); |
|
349 } |
|
350 |
|
351 ReadAttributesL(value, attributeList); |
|
352 |
|
353 if (attributeList.size() != 0) |
|
354 { |
|
355 // Populate attributes |
|
356 JavaStorageApplicationList_t::const_iterator attrIter; |
|
357 JavaStorageEntry attr; |
|
358 CJavaAttribute* regAttr = NULL; |
|
359 |
|
360 wstring attrName = L""; |
|
361 wstring attrValue = L""; |
|
362 wstring attrTrusted = L""; |
|
363 |
|
364 for (attrIter = attributeList.begin(); |
|
365 attrIter != attributeList.end(); |
|
366 ++attrIter) |
|
367 { |
|
368 EntryAttributeValue((*attrIter), NAME, attrName); |
|
369 EntryAttributeValue((*attrIter), VALUE, attrValue); |
|
370 EntryAttributeValue((*attrIter), TRUSTED, attrTrusted); |
|
371 |
|
372 if (attrValue.size() > 0 && attrName.size() > 0) |
|
373 { |
|
374 auto_ptr<HBufC> nameBuf(wstringToBuf(attrName)); |
|
375 auto_ptr<HBufC> valueBuf(wstringToBuf(attrValue)); |
|
376 |
|
377 TBool trusted = EFalse; |
|
378 if (attrTrusted == L"1") |
|
379 { |
|
380 trusted = ETrue; |
|
381 } |
|
382 |
|
383 regAttr = CJavaAttribute::NewL( |
|
384 nameBuf->Des(), valueBuf->Des(), trusted); |
|
385 |
|
386 iAttributes.Append(regAttr); |
|
387 |
|
388 nameBuf.reset(0); |
|
389 valueBuf.reset(0); |
|
390 attrName.clear(); |
|
391 attrValue.clear(); |
|
392 attrTrusted.clear(); |
|
393 } |
|
394 // else CJavaAttribute cannot be constructed with empty values. |
|
395 // Using same logic it does not exists if value is not set. |
|
396 } |
|
397 } |
|
398 return iAttributes; |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------------------------- |
|
402 // CWriteableJavaRegistryEntry::ConstructL |
|
403 // --------------------------------------------------------------------------- |
|
404 // |
|
405 EXPORT_C void CWriteableJavaRegistryEntry:: |
|
406 ConstructL(Java::TJavaRegistryEntryType aType) |
|
407 { |
|
408 JELOG2(EJavaStorage); |
|
409 iType = aType; |
|
410 } |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // CWriteableJavaRegistryEntry::ReadAttributesL |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 void CWriteableJavaRegistryEntry::ReadAttributesL(const wstring& aUid, |
|
417 JavaStorageApplicationList_t& aAttributes) const |
|
418 { |
|
419 JavaStorageApplicationEntry_t searchQuery; |
|
420 JavaStorageEntry attr; |
|
421 |
|
422 attr.setEntry(ID, aUid); |
|
423 searchQuery.insert(attr); |
|
424 |
|
425 try |
|
426 { |
|
427 auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
428 js->open(); |
|
429 js->search(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, searchQuery, aAttributes); |
|
430 js->close(); |
|
431 js.reset(0); |
|
432 searchQuery.clear(); |
|
433 } |
|
434 catch (JavaStorageException& aJse) |
|
435 { |
|
436 ELOG1(EJavaStorage, "Attributes read failed: %d", aJse.mStatus); |
|
437 User::Leave(aJse.mStatus); |
|
438 } |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CWriteableJavaRegistryEntry::EntryAttributeValue |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 void CWriteableJavaRegistryEntry::EntryAttributeValue( |
|
446 const JavaStorageApplicationEntry_t& aEntry, |
|
447 const wstring& aName, |
|
448 wstring& aValue) const |
|
449 { |
|
450 JavaStorageEntry attr; |
|
451 attr.setEntry(aName, L""); |
|
452 JavaStorageApplicationEntry_t::const_iterator finder = aEntry.find(attr); |
|
453 |
|
454 if (finder != aEntry.end()) |
|
455 { |
|
456 aValue = (*finder).entryValue(); |
|
457 } |
|
458 else |
|
459 { |
|
460 LOG(EJavaStorage, EInfo, "Entry attribute value not found"); |
|
461 aValue = L""; |
|
462 } |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------------------------- |
|
466 // CWriteableJavaRegistryEntry::StorageEntry |
|
467 // --------------------------------------------------------------------------- |
|
468 // |
|
469 void CWriteableJavaRegistryEntry::StorageEntry( |
|
470 const java::util::Uid& aUid, |
|
471 const string& aTableName, |
|
472 JavaStorageApplicationEntry_t& aStorageEntry) const |
|
473 { |
|
474 try |
|
475 { |
|
476 auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
477 js->open(); |
|
478 js->read(aTableName, aUid, aStorageEntry); |
|
479 js->close(); |
|
480 js.reset(0); |
|
481 } |
|
482 catch (JavaStorageException& jse) |
|
483 { |
|
484 ELOG1(EJavaStorage, "Read failed: %s ", |
|
485 jse.toString().c_str()); |
|
486 } |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------------------------- |
|
490 // CWriteableJavaRegistryEntry::PopulateCertChains |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 void CWriteableJavaRegistryEntry::PopulateCertChains() const |
|
494 { |
|
495 auto_ptr<java::security::MIDPAuthenticationModule>authModule( |
|
496 java::security::MIDPAuthenticationModule::createInstance()); |
|
497 |
|
498 wstring value = L""; |
|
499 |
|
500 if (EMidp2MidletSuite == iType) |
|
501 { |
|
502 EntryAttributeValue(iEntry, ID, value); |
|
503 } |
|
504 else // Application |
|
505 { |
|
506 EntryAttributeValue(iEntry, PACKAGE_ID, value); |
|
507 } |
|
508 |
|
509 java::util::Uid suiteUid(value); |
|
510 std::list<std::string> chains; |
|
511 |
|
512 authModule->getCertChains(suiteUid, chains); |
|
513 |
|
514 list<string>::const_iterator iter; |
|
515 |
|
516 for (iter = chains.begin(); iter != chains.end(); ++iter) |
|
517 { |
|
518 if ((*iter).size() > 0) |
|
519 { |
|
520 string decoded = JavaCommonUtils::base64decode((*iter)); |
|
521 |
|
522 HBufC8* decodedBuf = HBufC8::New(decoded.size()); |
|
523 TPtr8 decodedBufPtr(decodedBuf->Des()); |
|
524 decodedBufPtr.Append( |
|
525 ((const TUint8*)decoded.c_str()), decoded.size()); |
|
526 iCertificates.Append(decodedBuf); |
|
527 } |
|
528 } |
|
529 chains.clear(); |
|
530 } |