198 { |
198 { |
199 } |
199 } |
200 |
200 |
201 // ----------------------------------------------------------------------------- |
201 // ----------------------------------------------------------------------------- |
202 // CDrmStdKeyStorage::ConstructL |
202 // CDrmStdKeyStorage::ConstructL |
203 // |
203 // |
204 // ----------------------------------------------------------------------------- |
204 // ----------------------------------------------------------------------------- |
205 // |
205 // |
206 void CDrmStdKeyStorage::ConstructL() |
206 void CDrmStdKeyStorage::ConstructL() |
207 { |
207 { |
208 |
208 |
209 LOG(_L("CDrmStdKeyStorage::ConstructL ->")); |
209 LOG(_L("CDrmStdKeyStorage::ConstructL ->")); |
210 User::LeaveIfError(iFs.Connect()); |
210 User::LeaveIfError(iFs.Connect()); |
211 iFileMan = CFileMan::NewL(iFs); |
211 iFileMan = CFileMan::NewL(iFs); |
212 |
212 |
213 #ifdef __DRM_OMA2 |
213 #ifdef __DRM_OMA2 |
214 SelectDefaultRootL(); |
214 SelectDefaultRootL(); |
215 #endif |
215 #endif |
216 |
216 |
217 iDeviceSpecificKey.Copy(KDefaultKey); |
217 iDeviceSpecificKey.Copy(KDefaultKey); |
218 |
218 |
219 LOG(_L("CDrmStdKeyStorage::ConstructL <-")); |
219 LOG(_L("CDrmStdKeyStorage::ConstructL <-")); |
220 } |
220 } |
221 |
221 |
222 // ----------------------------------------------------------------------------- |
222 // ----------------------------------------------------------------------------- |
223 // MDrmKeyStorage::~MDrmKeyStorage |
223 // MDrmKeyStorage::~MDrmKeyStorage |
224 // |
224 // |
225 // ----------------------------------------------------------------------------- |
225 // ----------------------------------------------------------------------------- |
226 // |
226 // |
227 |
227 |
228 MDrmKeyStorage::~MDrmKeyStorage() |
228 MDrmKeyStorage::~MDrmKeyStorage() |
229 { |
229 { |
230 } |
230 } |
231 // ----------------------------------------------------------------------------- |
231 // ----------------------------------------------------------------------------- |
232 // DrmStdKeyStorage::~CDrmStdKeyStorage |
232 // DrmStdKeyStorage::~CDrmStdKeyStorage |
233 // |
233 // |
234 // ----------------------------------------------------------------------------- |
234 // ----------------------------------------------------------------------------- |
235 // |
235 // |
236 |
236 |
237 CDrmStdKeyStorage::~CDrmStdKeyStorage() |
237 CDrmStdKeyStorage::~CDrmStdKeyStorage() |
238 { |
238 { |
263 return iKey->N().BitCount(); |
263 return iKey->N().BitCount(); |
264 } |
264 } |
265 |
265 |
266 // ----------------------------------------------------------------------------- |
266 // ----------------------------------------------------------------------------- |
267 // DrmStdKeyStorage::SelectTrustedRootL |
267 // DrmStdKeyStorage::SelectTrustedRootL |
268 // |
268 // |
269 // ----------------------------------------------------------------------------- |
269 // ----------------------------------------------------------------------------- |
270 // |
270 // |
271 void CDrmStdKeyStorage::SelectTrustedRootL( |
271 void CDrmStdKeyStorage::SelectTrustedRootL( |
272 const TDesC8& aRootKeyHash) |
272 const TDesC8& aRootKeyHash) |
273 { |
273 { |
274 TFileName fileName; |
274 TFileName fileName; |
275 TEntry entry; |
275 TEntry entry; |
276 TInt i; |
276 TInt i; |
277 |
277 |
278 LOG(_L("CDrmStdKeyStorage::SelectTrustedRootL ->")); |
278 LOG(_L("CDrmStdKeyStorage::SelectTrustedRootL ->")); |
279 LOG(aRootKeyHash); |
279 LOG(aRootKeyHash); |
280 if (aRootKeyHash.Length() != 0) |
280 if (aRootKeyHash.Length() != 0) |
281 { |
281 { |
282 |
282 |
283 #ifndef RD_MULTIPLE_DRIVE |
283 #ifndef RD_MULTIPLE_DRIVE |
284 |
284 |
285 fileName.Copy(KKeyStoragePath); |
285 fileName.Copy(KKeyStoragePath); |
286 |
286 |
287 #else //RD_MULTIPLE_DRIVE |
287 #else //RD_MULTIPLE_DRIVE |
288 |
288 |
289 TFileName tempPath; |
289 TFileName tempPath; |
290 TInt driveNumber( -1 ); |
290 TInt driveNumber( -1 ); |
291 TChar driveLetter; |
291 TChar driveLetter; |
292 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
292 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
293 iFs.DriveToChar( driveNumber, driveLetter ); |
293 iFs.DriveToChar( driveNumber, driveLetter ); |
294 |
294 |
295 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
295 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
296 |
296 |
297 fileName.Copy(tempPath); |
297 fileName.Copy(tempPath); |
298 |
298 |
299 #endif |
299 #endif |
300 |
300 |
301 for (i = 0; i < SHA1_HASH; i++) |
301 for (i = 0; i < SHA1_HASH; i++) |
302 { |
302 { |
303 fileName.AppendNumFixedWidth(aRootKeyHash[i], EHex, 2); |
303 fileName.AppendNumFixedWidth(aRootKeyHash[i], EHex, 2); |
304 } |
304 } |
305 fileName.Append('\\'); |
305 fileName.Append('\\'); |
306 if (iFs.Entry(fileName, entry) != KErrNone) |
306 if (iFs.Entry(fileName, entry) != KErrNone) |
307 { |
307 { |
308 |
308 |
309 #ifndef RD_MULTIPLE_DRIVE |
309 #ifndef RD_MULTIPLE_DRIVE |
310 |
310 |
311 fileName.Copy(KRomKeyStoragePath); |
311 fileName.Copy(KRomKeyStoragePath); |
312 |
312 |
313 #else //RD_MULTIPLE_DRIVE |
313 #else //RD_MULTIPLE_DRIVE |
314 |
314 |
315 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
315 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
316 iFs.DriveToChar( driveNumber, driveLetter ); |
316 iFs.DriveToChar( driveNumber, driveLetter ); |
317 |
317 |
318 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
318 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
319 |
319 |
320 fileName.Copy(tempPath); |
320 fileName.Copy(tempPath); |
321 |
321 |
322 #endif |
322 #endif |
323 |
323 |
324 for (i = 0; i < SHA1_HASH; i++) |
324 for (i = 0; i < SHA1_HASH; i++) |
325 { |
325 { |
326 fileName.AppendNumFixedWidth(aRootKeyHash[i], EHex, 2); |
326 fileName.AppendNumFixedWidth(aRootKeyHash[i], EHex, 2); |
327 } |
327 } |
328 fileName.Append('\\'); |
328 fileName.Append('\\'); |
330 User::LeaveIfError(iFs.Entry(fileName, entry)); |
330 User::LeaveIfError(iFs.Entry(fileName, entry)); |
331 } |
331 } |
332 User::LeaveIfError(iFs.SetSessionPath(fileName)); |
332 User::LeaveIfError(iFs.SetSessionPath(fileName)); |
333 InitializeKeyL(); |
333 InitializeKeyL(); |
334 CheckRootForCmlaL(); |
334 CheckRootForCmlaL(); |
335 iRootSelected = ETrue; |
335 iRootSelected = ETrue; |
336 } |
336 } |
337 else |
337 else |
338 { |
338 { |
339 SelectDefaultRootL(); |
339 SelectDefaultRootL(); |
340 } |
340 } |
341 LOG(_L("CDrmStdKeyStorage::SelectTrustedRootL <-")); |
341 LOG(_L("CDrmStdKeyStorage::SelectTrustedRootL <-")); |
342 } |
342 } |
343 |
343 |
344 // ----------------------------------------------------------------------------- |
344 // ----------------------------------------------------------------------------- |
345 // DrmStdKeyStorage::SelectDefaultRootL |
345 // DrmStdKeyStorage::SelectDefaultRootL |
346 // |
346 // |
347 // ----------------------------------------------------------------------------- |
347 // ----------------------------------------------------------------------------- |
348 // |
348 // |
349 void CDrmStdKeyStorage::SelectDefaultRootL() |
349 void CDrmStdKeyStorage::SelectDefaultRootL() |
350 { |
350 { |
351 CDir* dir = NULL; |
351 CDir* dir = NULL; |
352 TFileName dirName; |
352 TFileName dirName; |
353 TBool found = EFalse; |
353 TBool found = EFalse; |
354 |
354 |
355 LOG(_L("CDrmStdKeyStorage::SelectDefaultRootL ->")); |
355 LOG(_L("CDrmStdKeyStorage::SelectDefaultRootL ->")); |
356 |
356 |
357 #ifndef RD_MULTIPLE_DRIVE |
357 #ifndef RD_MULTIPLE_DRIVE |
358 |
358 |
359 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
359 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
360 |
360 |
361 #else //RD_MULTIPLE_DRIVE |
361 #else //RD_MULTIPLE_DRIVE |
362 |
362 |
363 TFileName tempPath; |
363 TFileName tempPath; |
364 TInt driveNumber( -1 ); |
364 TInt driveNumber( -1 ); |
365 TChar driveLetter; |
365 TChar driveLetter; |
366 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
366 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
367 iFs.DriveToChar( driveNumber, driveLetter ); |
367 iFs.DriveToChar( driveNumber, driveLetter ); |
368 |
368 |
369 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
369 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
370 |
370 |
371 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
371 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
372 |
372 |
373 #endif |
373 #endif |
374 |
374 |
375 { |
375 { |
376 __UHEAP_MARK; |
376 __UHEAP_MARK; |
377 LOG(_L(" Checking keys on C:")); |
377 LOG(_L(" Checking keys on C:")); |
378 CleanupStack::PushL(dir); |
378 CleanupStack::PushL(dir); |
379 if (dir->Count() >= 1) |
379 if (dir->Count() >= 1) |
380 { |
380 { |
381 |
381 |
382 #ifndef RD_MULTIPLE_DRIVE |
382 #ifndef RD_MULTIPLE_DRIVE |
383 |
383 |
384 dirName.Copy(KKeyStoragePath); |
384 dirName.Copy(KKeyStoragePath); |
385 |
385 |
386 #else //RD_MULTIPLE_DRIVE |
386 #else //RD_MULTIPLE_DRIVE |
387 |
387 |
388 dirName.Copy(tempPath); |
388 dirName.Copy(tempPath); |
389 |
389 |
390 #endif |
390 #endif |
391 |
391 |
392 dirName.Append((*dir)[0].iName); |
392 dirName.Append((*dir)[0].iName); |
393 dirName.Append('\\'); |
393 dirName.Append('\\'); |
394 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
394 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
395 found = ETrue; |
395 found = ETrue; |
396 } |
396 } |
397 CleanupStack::PopAndDestroy(dir); |
397 CleanupStack::PopAndDestroy(dir); |
398 __UHEAP_MARKEND; |
398 __UHEAP_MARKEND; |
399 } |
399 } |
400 |
400 |
401 #ifndef RD_MULTIPLE_DRIVE |
401 #ifndef RD_MULTIPLE_DRIVE |
402 |
402 |
403 if (!found && iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
403 if (!found && iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
404 |
404 |
405 #else //RD_MULTIPLE_DRIVE |
405 #else //RD_MULTIPLE_DRIVE |
406 |
406 |
407 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
407 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
408 iFs.DriveToChar( driveNumber, driveLetter ); |
408 iFs.DriveToChar( driveNumber, driveLetter ); |
409 |
409 |
410 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
410 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
411 |
411 |
412 if (!found && iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
412 if (!found && iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
413 |
413 |
414 #endif |
414 #endif |
415 { |
415 { |
416 LOG(_L(" Checking keys on Z:")); |
416 LOG(_L(" Checking keys on Z:")); |
417 CleanupStack::PushL(dir); |
417 CleanupStack::PushL(dir); |
418 if (dir->Count() < 1) |
418 if (dir->Count() < 1) |
419 { |
419 { |
420 User::Leave(KErrGeneral); |
420 User::Leave(KErrGeneral); |
421 } |
421 } |
422 |
422 |
423 #ifndef RD_MULTIPLE_DRIVE |
423 #ifndef RD_MULTIPLE_DRIVE |
424 |
424 |
425 dirName.Copy(KRomKeyStoragePath); |
425 dirName.Copy(KRomKeyStoragePath); |
426 |
426 |
427 #else //RD_MULTIPLE_DRIVE |
427 #else //RD_MULTIPLE_DRIVE |
428 |
428 |
429 dirName.Copy(tempPath); |
429 dirName.Copy(tempPath); |
430 |
430 |
431 #endif |
431 #endif |
432 |
432 |
433 dirName.Append((*dir)[0].iName); |
433 dirName.Append((*dir)[0].iName); |
434 dirName.Append('\\'); |
434 dirName.Append('\\'); |
435 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
435 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
436 CleanupStack::PopAndDestroy(dir); |
436 CleanupStack::PopAndDestroy(dir); |
437 found = ETrue; |
437 found = ETrue; |
438 } |
438 } |
439 if (!found) |
439 if (!found) |
440 { |
440 { |
441 User::Leave(KErrGeneral); |
441 User::Leave(KErrGeneral); |
442 } |
442 } |
443 InitializeKeyL(); |
443 InitializeKeyL(); |
444 CheckRootForCmlaL(); |
444 CheckRootForCmlaL(); |
445 iRootSelected = ETrue; |
445 iRootSelected = ETrue; |
446 LOG(_L("CDrmStdKeyStorage::SelectDefaultRootL <-")); |
446 LOG(_L("CDrmStdKeyStorage::SelectDefaultRootL <-")); |
447 } |
447 } |
448 |
448 |
449 TBool CDrmStdKeyStorage::SelectedRootIsCmla() |
449 TBool CDrmStdKeyStorage::SelectedRootIsCmla() |
450 { |
450 { |
451 return iRootIsCmla; |
451 return iRootIsCmla; |
452 } |
452 } |
453 |
453 |
454 // ----------------------------------------------------------------------------- |
454 // ----------------------------------------------------------------------------- |
455 // DrmStdKeyStorage::GetTrustedRootsL |
455 // DrmStdKeyStorage::GetTrustedRootsL |
456 // |
456 // |
457 // ----------------------------------------------------------------------------- |
457 // ----------------------------------------------------------------------------- |
458 // |
458 // |
459 |
459 |
460 void CDrmStdKeyStorage::GetTrustedRootsL( |
460 void CDrmStdKeyStorage::GetTrustedRootsL( |
461 RPointerArray<HBufC8>& aRootList) |
461 RPointerArray<HBufC8>& aRootList) |
462 { |
462 { |
463 CDir* dir = NULL; |
463 CDir* dir = NULL; |
464 TInt i; |
464 TInt i; |
465 TInt j; |
465 TInt j; |
466 TBuf8<SHA1_HASH> hash; |
466 TBuf8<SHA1_HASH> hash; |
467 TEntry entry; |
467 TEntry entry; |
468 TUint8 c; |
468 TUint8 c; |
469 TInt r = KErrNone; |
469 TInt r = KErrNone; |
470 |
470 |
471 LOG(_L("CDrmStdKeyStorage::GetTrustedRootsL ->")); |
471 LOG(_L("CDrmStdKeyStorage::GetTrustedRootsL ->")); |
472 aRootList.ResetAndDestroy(); |
472 aRootList.ResetAndDestroy(); |
473 |
473 |
474 #ifndef RD_MULTIPLE_DRIVE |
474 #ifndef RD_MULTIPLE_DRIVE |
475 |
475 |
476 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
476 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
477 |
477 |
478 #else //RD_MULTIPLE_DRIVE |
478 #else //RD_MULTIPLE_DRIVE |
479 |
479 |
480 TFileName tempPath; |
480 TFileName tempPath; |
481 TInt driveNumber( -1 ); |
481 TInt driveNumber( -1 ); |
482 TChar driveLetter; |
482 TChar driveLetter; |
483 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
483 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
484 iFs.DriveToChar( driveNumber, driveLetter ); |
484 iFs.DriveToChar( driveNumber, driveLetter ); |
485 |
485 |
486 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
486 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
487 |
487 |
488 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
488 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
489 |
489 |
490 #endif |
490 #endif |
491 { |
491 { |
492 LOG(_L(" Getting roots on C:")); |
492 LOG(_L(" Getting roots on C:")); |
493 CleanupStack::PushL(dir); |
493 CleanupStack::PushL(dir); |
494 for (i = 0; i < dir->Count(); i++) |
494 for (i = 0; i < dir->Count(); i++) |
615 HBufC8* publicKey = NULL; |
615 HBufC8* publicKey = NULL; |
616 CX509Certificate* cert = NULL; |
616 CX509Certificate* cert = NULL; |
617 CSHA1* hasher = NULL; |
617 CSHA1* hasher = NULL; |
618 TBuf8<SHA1_HASH> publicKeyHash; |
618 TBuf8<SHA1_HASH> publicKeyHash; |
619 TFileName fileName; |
619 TFileName fileName; |
620 |
620 |
621 LOG(_L("CDrmStdKeyStorage::ImportDataL ->")); |
621 LOG(_L("CDrmStdKeyStorage::ImportDataL ->")); |
622 n = aCertificateChain.Count(); |
622 n = aCertificateChain.Count(); |
623 cert = CX509Certificate::NewLC(aCertificateChain[n - 1]); |
623 cert = CX509Certificate::NewLC(aCertificateChain[n - 1]); |
624 publicKey = cert->DataElementEncoding( |
624 publicKey = cert->DataElementEncoding( |
625 CX509Certificate::ESubjectPublicKeyInfo)->AllocL(); |
625 CX509Certificate::ESubjectPublicKeyInfo)->AllocL(); |
626 CleanupStack::PushL(publicKey); |
626 CleanupStack::PushL(publicKey); |
627 hasher = CSHA1::NewL(); |
627 hasher = CSHA1::NewL(); |
628 CleanupStack::PushL(hasher); |
628 CleanupStack::PushL(hasher); |
629 hasher->Update(*publicKey); |
629 hasher->Update(*publicKey); |
630 publicKeyHash.Copy(hasher->Final()); |
630 publicKeyHash.Copy(hasher->Final()); |
631 |
631 |
632 #ifndef RD_MULTIPLE_DRIVE |
632 #ifndef RD_MULTIPLE_DRIVE |
633 |
633 |
634 fileName.Copy(KKeyStoragePath); |
634 fileName.Copy(KKeyStoragePath); |
635 |
635 |
636 #else //RD_MULTIPLE_DRIVE |
636 #else //RD_MULTIPLE_DRIVE |
637 |
637 |
638 TInt driveNumber( -1 ); |
638 TInt driveNumber( -1 ); |
639 TChar driveLetter; |
639 TChar driveLetter; |
640 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
640 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
641 iFs.DriveToChar( driveNumber, driveLetter ); |
641 iFs.DriveToChar( driveNumber, driveLetter ); |
642 |
642 |
643 TFileName keyStorageDir; |
643 TFileName keyStorageDir; |
644 keyStorageDir.Format( KKeyStoragePath, (TUint)driveLetter ); |
644 keyStorageDir.Format( KKeyStoragePath, (TUint)driveLetter ); |
645 |
645 |
646 fileName.Copy(keyStorageDir); |
646 fileName.Copy(keyStorageDir); |
647 |
647 |
648 #endif |
648 #endif |
649 |
649 |
650 for (i = 0; i < SHA1_HASH; i++) |
650 for (i = 0; i < SHA1_HASH; i++) |
651 { |
651 { |
652 fileName.AppendNumFixedWidth(publicKeyHash[i], EHex, 2); |
652 fileName.AppendNumFixedWidth(publicKeyHash[i], EHex, 2); |
653 } |
653 } |
654 fileName.Append('\\'); |
654 fileName.Append('\\'); |
803 } |
803 } |
804 CleanupStack::PopAndDestroy(4); // name, cert, buffer, dir |
804 CleanupStack::PopAndDestroy(4); // name, cert, buffer, dir |
805 LOG(_L("CDrmStdKeyStorage::CheckRootForCmlaL <-")); |
805 LOG(_L("CDrmStdKeyStorage::CheckRootForCmlaL <-")); |
806 __UHEAP_MARKEND; |
806 __UHEAP_MARKEND; |
807 } |
807 } |
808 |
808 |
809 // ----------------------------------------------------------------------------- |
809 // ----------------------------------------------------------------------------- |
810 // CDrmStdKeyStorage::GetRdbSerialNumberL |
810 // CDrmStdKeyStorage::GetRdbSerialNumberL |
811 // ----------------------------------------------------------------------------- |
811 // ----------------------------------------------------------------------------- |
812 // |
812 // |
813 void CDrmStdKeyStorage::GetRdbSerialNumberL( |
813 void CDrmStdKeyStorage::GetRdbSerialNumberL( |
814 TBuf8<KRdbSerialNumberLength>& aSerialNumber) |
814 TBuf8<KRdbSerialNumberLength>& aSerialNumber) |
815 { |
815 { |
816 HBufC8* buffer = NULL; |
816 HBufC8* buffer = NULL; |
817 TUint att; |
817 TUint att; |
818 |
818 |
819 #ifndef RD_MULTIPLE_DRIVE |
819 #ifndef RD_MULTIPLE_DRIVE |
820 |
820 |
821 if (iFs.Att(KSerialNumberFile, att) != KErrNone) |
821 if (iFs.Att(KSerialNumberFile, att) != KErrNone) |
822 |
822 |
823 #else //RD_MULTIPLE_DRIVE |
823 #else //RD_MULTIPLE_DRIVE |
824 |
824 |
825 TInt driveNumber( -1 ); |
825 TInt driveNumber( -1 ); |
826 TChar driveLetter; |
826 TChar driveLetter; |
827 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
827 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
828 iFs.DriveToChar( driveNumber, driveLetter ); |
828 iFs.DriveToChar( driveNumber, driveLetter ); |
829 |
829 |
830 TFileName serialNoFile; |
830 TFileName serialNoFile; |
831 serialNoFile.Format( KSerialNumberFile, (TUint)driveLetter ); |
831 serialNoFile.Format( KSerialNumberFile, (TUint)driveLetter ); |
832 |
832 |
833 if (iFs.Att(serialNoFile, att) != KErrNone) |
833 if (iFs.Att(serialNoFile, att) != KErrNone) |
834 |
834 |
835 #endif |
835 #endif |
836 { |
836 { |
837 GenerateNewRdbSerialNumberL(); |
837 GenerateNewRdbSerialNumberL(); |
838 } |
838 } |
839 |
839 |
840 #ifndef RD_MULTIPLE_DRIVE |
840 #ifndef RD_MULTIPLE_DRIVE |
841 |
841 |
842 ReadFileL(iFs, KSerialNumberFile, buffer); |
842 ReadFileL(iFs, KSerialNumberFile, buffer); |
843 |
843 |
844 #else //RD_MULTIPLE_DRIVE |
844 #else //RD_MULTIPLE_DRIVE |
845 |
845 |
846 ReadFileL(iFs, serialNoFile, buffer); |
846 ReadFileL(iFs, serialNoFile, buffer); |
847 |
847 |
848 #endif |
848 #endif |
849 |
849 |
850 aSerialNumber.Copy(*buffer); |
850 aSerialNumber.Copy(*buffer); |
851 delete buffer; |
851 delete buffer; |
852 } |
852 } |
853 |
853 |
854 // ----------------------------------------------------------------------------- |
854 // ----------------------------------------------------------------------------- |
855 // CDrmStdKeyStorage::GenerateNewRdbSerialNumberL |
855 // CDrmStdKeyStorage::GenerateNewRdbSerialNumberL |
856 // ----------------------------------------------------------------------------- |
856 // ----------------------------------------------------------------------------- |
857 // |
857 // |
858 void CDrmStdKeyStorage::GenerateNewRdbSerialNumberL() |
858 void CDrmStdKeyStorage::GenerateNewRdbSerialNumberL() |
859 { |
859 { |
860 TBuf8<KRdbSerialNumberLength> serialNumber; |
860 TBuf8<KRdbSerialNumberLength> serialNumber; |
861 TPtr8 random( const_cast<TUint8*>(serialNumber.Ptr()), |
861 TPtr8 random( const_cast<TUint8*>(serialNumber.Ptr()), |
862 KRdbSerialNumberLength, |
862 KRdbSerialNumberLength, |
863 KRdbSerialNumberLength ); |
863 KRdbSerialNumberLength ); |
864 |
864 |
865 RandomDataGetL(random,KRdbSerialNumberLength); |
865 RandomDataGetL(random,KRdbSerialNumberLength); |
866 |
866 |
867 #ifndef RD_MULTIPLE_DRIVE |
867 #ifndef RD_MULTIPLE_DRIVE |
868 |
868 |
869 WriteFileL(iFs, KSerialNumberFile, random); |
869 WriteFileL(iFs, KSerialNumberFile, random); |
870 |
870 |
871 #else //RD_MULTIPLE_DRIVE |
871 #else //RD_MULTIPLE_DRIVE |
872 |
872 |
873 TInt driveNumber( -1 ); |
873 TInt driveNumber( -1 ); |
874 TChar driveLetter; |
874 TChar driveLetter; |
875 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
875 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
876 iFs.DriveToChar( driveNumber, driveLetter ); |
876 iFs.DriveToChar( driveNumber, driveLetter ); |
877 |
877 |
878 TFileName serialNoFile; |
878 TFileName serialNoFile; |
879 serialNoFile.Format( KSerialNumberFile, (TUint)driveLetter ); |
879 serialNoFile.Format( KSerialNumberFile, (TUint)driveLetter ); |
880 |
880 |
881 WriteFileL(iFs, serialNoFile, random); |
881 WriteFileL(iFs, serialNoFile, random); |
882 |
882 |
883 #endif |
883 #endif |
884 |
884 |
885 } |
885 } |
886 |
886 |
887 // ----------------------------------------------------------------------------- |
887 // ----------------------------------------------------------------------------- |
888 // CDrmStdKeyStorage::UdtEncryptL |
888 // CDrmStdKeyStorage::UdtEncryptL |
889 // ----------------------------------------------------------------------------- |
889 // ----------------------------------------------------------------------------- |
890 // |
890 // |
891 HBufC8* CDrmStdKeyStorage::UdtEncryptL( |
891 HBufC8* CDrmStdKeyStorage::UdtEncryptL( |
896 CX509Certificate* cert = NULL; |
896 CX509Certificate* cert = NULL; |
897 CRSAPublicKey* key = NULL; |
897 CRSAPublicKey* key = NULL; |
898 TX509KeyFactory factory; |
898 TX509KeyFactory factory; |
899 CRSAPKCS1v15Encryptor* encryptor = NULL; |
899 CRSAPKCS1v15Encryptor* encryptor = NULL; |
900 TPtr8 result(const_cast<TUint8*>(output->Ptr()), 0, 256); |
900 TPtr8 result(const_cast<TUint8*>(output->Ptr()), 0, 256); |
901 |
901 |
902 #ifndef RD_MULTIPLE_DRIVE |
902 #ifndef RD_MULTIPLE_DRIVE |
903 |
903 |
904 ReadFileL(iFs, KUdtCertFileName, buffer); |
904 ReadFileL(iFs, KUdtCertFileName, buffer); |
905 |
905 |
906 #else //RD_MULTIPLE_DRIVE |
906 #else //RD_MULTIPLE_DRIVE |
907 |
907 |
908 TInt driveNumber( -1 ); |
908 TInt driveNumber( -1 ); |
909 TChar driveLetter; |
909 TChar driveLetter; |
910 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
910 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
911 iFs.DriveToChar( driveNumber, driveLetter ); |
911 iFs.DriveToChar( driveNumber, driveLetter ); |
912 |
912 |
913 TFileName udtCertFile; |
913 TFileName udtCertFile; |
914 udtCertFile.Format( KUdtCertFileName, (TUint)driveLetter ); |
914 udtCertFile.Format( KUdtCertFileName, (TUint)driveLetter ); |
915 |
915 |
916 ReadFileL(iFs, udtCertFile, buffer); |
916 ReadFileL(iFs, udtCertFile, buffer); |
917 |
917 |
918 #endif |
918 #endif |
919 |
919 |
920 CleanupStack::PushL(buffer); |
920 CleanupStack::PushL(buffer); |
921 cert = CX509Certificate::NewL(*buffer); |
921 cert = CX509Certificate::NewL(*buffer); |
922 CleanupStack::PushL(cert); |
922 CleanupStack::PushL(cert); |
923 key = factory.RSAPublicKeyL(cert->PublicKey().KeyData()); |
923 key = factory.RSAPublicKeyL(cert->PublicKey().KeyData()); |
924 CleanupStack::PushL(key); |
924 CleanupStack::PushL(key); |
925 |
925 |
926 encryptor = CRSAPKCS1v15Encryptor::NewLC(*key); |
926 encryptor = CRSAPKCS1v15Encryptor::NewLC(*key); |
927 encryptor->EncryptL(aInput, result); |
927 encryptor->EncryptL(aInput, result); |
928 |
928 |
929 CleanupStack::PopAndDestroy(4); // encryptor, key, cert, buffer |
929 CleanupStack::PopAndDestroy(4); // encryptor, key, cert, buffer |
930 CleanupStack::Pop();// output |
930 CleanupStack::Pop();// output |
948 iFs.SessionPath( path ); |
948 iFs.SessionPath( path ); |
949 |
949 |
950 #ifndef RD_MULTIPLE_DRIVE |
950 #ifndef RD_MULTIPLE_DRIVE |
951 |
951 |
952 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
952 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
953 |
953 |
954 #else //RD_MULTIPLE_DRIVE |
954 #else //RD_MULTIPLE_DRIVE |
955 |
955 |
956 TFileName tempPath; |
956 TFileName tempPath; |
957 TInt driveNumber( -1 ); |
957 TInt driveNumber( -1 ); |
958 TChar driveLetter; |
958 TChar driveLetter; |
959 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
959 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
960 iFs.DriveToChar( driveNumber, driveLetter ); |
960 iFs.DriveToChar( driveNumber, driveLetter ); |
961 |
961 |
962 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
962 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
963 |
963 |
964 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
964 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
965 |
965 |
966 #endif |
966 #endif |
967 { |
967 { |
968 CleanupStack::PushL(dir); |
968 CleanupStack::PushL(dir); |
969 for(i = 0; i < dir->Count(); i++) |
969 for(i = 0; i < dir->Count(); i++) |
970 { |
970 { |
971 if ((*dir)[i].IsDir()) |
971 if ((*dir)[i].IsDir()) |
972 { |
972 { |
973 |
973 |
974 #ifndef RD_MULTIPLE_DRIVE |
974 #ifndef RD_MULTIPLE_DRIVE |
975 |
975 |
976 dirName.Copy(KKeyStoragePath); |
976 dirName.Copy(KKeyStoragePath); |
977 |
977 |
978 #else //RD_MULTIPLE_DRIVE |
978 #else //RD_MULTIPLE_DRIVE |
979 |
979 |
980 dirName.Copy(tempPath); |
980 dirName.Copy(tempPath); |
981 |
981 |
982 #endif |
982 #endif |
983 |
983 |
984 dirName.Append((*dir)[i].iName); |
984 dirName.Append((*dir)[i].iName); |
985 dirName.Append('\\'); |
985 dirName.Append('\\'); |
986 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
986 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
987 User::LeaveIfError(iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, rootCerts)); |
987 User::LeaveIfError(iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, rootCerts)); |
988 CleanupStack::PushL(rootCerts); |
988 CleanupStack::PushL(rootCerts); |
993 CleanupStack::PopAndDestroy(); // rootCerts |
993 CleanupStack::PopAndDestroy(); // rootCerts |
994 } |
994 } |
995 } |
995 } |
996 CleanupStack::PopAndDestroy(dir); |
996 CleanupStack::PopAndDestroy(dir); |
997 } |
997 } |
998 |
998 |
999 #ifndef RD_MULTIPLE_DRIVE |
999 #ifndef RD_MULTIPLE_DRIVE |
1000 |
1000 |
1001 if (iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
1001 if (iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
1002 |
1002 |
1003 #else //RD_MULTIPLE_DRIVE |
1003 #else //RD_MULTIPLE_DRIVE |
1004 |
1004 |
1005 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
1005 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
1006 iFs.DriveToChar( driveNumber, driveLetter ); |
1006 iFs.DriveToChar( driveNumber, driveLetter ); |
1007 |
1007 |
1008 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
1008 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
1009 |
1009 |
1010 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
1010 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
1011 |
1011 |
1012 #endif |
1012 #endif |
1013 { |
1013 { |
1014 CleanupStack::PushL(dir); |
1014 CleanupStack::PushL(dir); |
1015 for(i = 0; i < dir->Count(); i++) |
1015 for(i = 0; i < dir->Count(); i++) |
1016 { |
1016 { |
1017 if ((*dir)[i].IsDir()) |
1017 if ((*dir)[i].IsDir()) |
1018 { |
1018 { |
1019 |
1019 |
1020 #ifndef RD_MULTIPLE_DRIVE |
1020 #ifndef RD_MULTIPLE_DRIVE |
1021 |
1021 |
1022 dirName.Copy(KRomKeyStoragePath); |
1022 dirName.Copy(KRomKeyStoragePath); |
1023 |
1023 |
1024 #else //RD_MULTIPLE_DRIVE |
1024 #else //RD_MULTIPLE_DRIVE |
1025 |
1025 |
1026 dirName.Copy(tempPath); |
1026 dirName.Copy(tempPath); |
1027 |
1027 |
1028 #endif |
1028 #endif |
1029 |
1029 |
1030 dirName.Append((*dir)[i].iName); |
1030 dirName.Append((*dir)[i].iName); |
1031 dirName.Append('\\'); |
1031 dirName.Append('\\'); |
1032 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
1032 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
1033 User::LeaveIfError(iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, rootCerts)); |
1033 User::LeaveIfError(iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, rootCerts)); |
1034 CleanupStack::PushL(rootCerts); |
1034 CleanupStack::PushL(rootCerts); |
1054 { |
1054 { |
1055 return *iImei; |
1055 return *iImei; |
1056 } |
1056 } |
1057 |
1057 |
1058 #if (defined __WINS__ || defined WINSCW) |
1058 #if (defined __WINS__ || defined WINSCW) |
1059 // Default IMEI used for emulator |
1059 // Default IMEI used for emulator |
1060 _LIT( KDefaultSerialNumber, "123456789123456789" ); |
1060 _LIT( KDefaultSerialNumber, "123456789123456789" ); |
1061 iImei = KDefaultSerialNumber().AllocL(); |
1061 iImei = KDefaultSerialNumber().AllocL(); |
1062 |
1062 |
1063 return *iImei; |
1063 return *iImei; |
1064 #else |
1064 #else |
1065 |
1065 |
1066 TInt error( KErrNone ); |
1066 TInt error( KErrNone ); |
1067 TInt count( 0 ); |
1067 TInt count( 0 ); |
1068 TInt count2( 0 ); |
1068 TInt count2( 0 ); |
1069 TUint32 caps( 0 ); |
1069 TUint32 caps( 0 ); |
1070 TBool found (EFalse); |
1070 TBool found (EFalse); |
1071 |
1071 |
1072 RTelServer etelServer; |
1072 RTelServer etelServer; |
1073 RMobilePhone phone; |
1073 RMobilePhone phone; |
1074 |
1074 |
1075 TUint KMaxImeiTries = 5; |
1075 TUint KMaxImeiTries = 5; |
1076 |
1076 |
1077 for ( TUint8 i = 0; i < KMaxImeiTries; ++i ) |
1077 for ( TUint8 i = 0; i < KMaxImeiTries; ++i ) |
1078 { |
1078 { |
1079 error = etelServer.Connect(); |
1079 error = etelServer.Connect(); |
1080 if ( error ) |
1080 if ( error ) |
1081 { |
1081 { |
1082 User::After( TTimeIntervalMicroSeconds32( KWaitingTime ) ); |
1082 User::After( TTimeIntervalMicroSeconds32( KWaitingTime ) ); |
1083 } |
1083 } |
1084 else |
1084 else |
1085 { |
1085 { |
1086 break; |
1086 break; |
1087 } |
1087 } |
1088 } |
1088 } |
1089 |
1089 |
1090 User::LeaveIfError( error ); |
1090 User::LeaveIfError( error ); |
1091 CleanupClosePushL( etelServer ); |
1091 CleanupClosePushL( etelServer ); |
1092 |
1092 |
1093 User::LeaveIfError( etelServer.LoadPhoneModule( KMmTsyModuleName ) ); |
1093 User::LeaveIfError( etelServer.LoadPhoneModule( KMmTsyModuleName ) ); |
1094 |
1094 |
1095 TUnloadModule unload; |
1095 TUnloadModule unload; |
1096 unload.iServer = &etelServer; |
1096 unload.iServer = &etelServer; |
1097 unload.iName = &KMmTsyModuleName; |
1097 unload.iName = &KMmTsyModuleName; |
1098 |
1098 |
1099 TCleanupItem item( DoUnloadPhoneModule, &unload ); |
1099 TCleanupItem item( DoUnloadPhoneModule, &unload ); |
1100 CleanupStack::PushL( item ); |
1100 CleanupStack::PushL( item ); |
1101 User::LeaveIfError( etelServer.EnumeratePhones( count ) ); |
1101 User::LeaveIfError( etelServer.EnumeratePhones( count ) ); |
1102 |
1102 |
1103 for ( count2 = 0; count2 < count && !found; ++count2 ) |
1103 for ( count2 = 0; count2 < count && !found; ++count2 ) |
1104 { |
1104 { |
1105 RTelServer::TPhoneInfo phoneInfo; |
1105 RTelServer::TPhoneInfo phoneInfo; |
1106 User::LeaveIfError( etelServer.GetTsyName( count2, phoneInfo.iName ) ); |
1106 User::LeaveIfError( etelServer.GetTsyName( count2, phoneInfo.iName ) ); |
1107 |
1107 |
1108 if ( phoneInfo.iName.CompareF(KMmTsyModuleName()) == 0 ) |
1108 if ( phoneInfo.iName.CompareF(KMmTsyModuleName()) == 0 ) |
1109 { |
1109 { |
1110 User::LeaveIfError( etelServer.GetPhoneInfo( count2, phoneInfo ) ); |
1110 User::LeaveIfError( etelServer.GetPhoneInfo( count2, phoneInfo ) ); |
1111 User::LeaveIfError( phone.Open( etelServer, phoneInfo.iName ) ); |
1111 User::LeaveIfError( phone.Open( etelServer, phoneInfo.iName ) ); |
1112 CleanupClosePushL( phone ); |
1112 CleanupClosePushL( phone ); |
1113 found = ETrue; |
1113 found = ETrue; |
1117 if ( !found ) |
1117 if ( !found ) |
1118 { |
1118 { |
1119 // Not found. |
1119 // Not found. |
1120 User::Leave( KErrNotFound ); |
1120 User::Leave( KErrNotFound ); |
1121 } |
1121 } |
1122 |
1122 |
1123 User::LeaveIfError( phone.GetIdentityCaps( caps ) ); |
1123 User::LeaveIfError( phone.GetIdentityCaps( caps ) ); |
1124 if (!( caps & RMobilePhone::KCapsGetSerialNumber )) |
1124 if (!( caps & RMobilePhone::KCapsGetSerialNumber )) |
1125 { |
1125 { |
1126 User::Leave( KErrNotFound ); |
1126 User::Leave( KErrNotFound ); |
1127 } |
1127 } |
1128 |
1128 |
1129 RMobilePhone::TMobilePhoneIdentityV1 id; |
1129 RMobilePhone::TMobilePhoneIdentityV1 id; |
1130 TRequestStatus status; |
1130 TRequestStatus status; |
1131 |
1131 |
1132 phone.GetPhoneId( status, id ); |
1132 phone.GetPhoneId( status, id ); |
1133 |
1133 |
1134 User::WaitForRequest( status ); |
1134 User::WaitForRequest( status ); |
1135 |
1135 |
1136 User::LeaveIfError( status.Int() ); |
1136 User::LeaveIfError( status.Int() ); |
1137 |
1137 |
1138 iImei = id.iSerialNumber.AllocL(); |
1138 iImei = id.iSerialNumber.AllocL(); |
1139 |
1139 |
1140 CleanupStack::PopAndDestroy( 3 ); // phone, item, etelServer |
1140 CleanupStack::PopAndDestroy( 3 ); // phone, item, etelServer |
1141 |
1141 |
1142 HBufC8* buf = HBufC8::NewL( iImei->Size() ); |
1142 HBufC8* buf = HBufC8::NewL( iImei->Size() ); |
1143 TPtr8 ptr( buf->Des() ); |
1143 TPtr8 ptr( buf->Des() ); |
1144 ptr.Copy( *iImei ); |
1144 ptr.Copy( *iImei ); |
1145 |
1145 |
1146 LOG(_L("IMEI:")); |
1146 LOG(_L("IMEI:")); |
1147 LOGHEX(ptr); |
1147 LOGHEX(ptr); |
1148 delete buf; |
1148 delete buf; |
1149 |
1149 |
1150 return *iImei; |
1150 return *iImei; |
1151 #endif /* __WINS__ , WINSCW */ |
1151 #endif /* __WINS__ , WINSCW */ |
1152 |
1152 |
1153 } |
1153 } |
1154 |
1154 |
1155 |
1155 |
1156 // ----------------------------------------------------------------------------- |
1156 // ----------------------------------------------------------------------------- |
1157 // CDrmStdKeyStorage::RandomDataGetL |
1157 // CDrmStdKeyStorage::RandomDataGetL |
1158 // ----------------------------------------------------------------------------- |
1158 // ----------------------------------------------------------------------------- |
1159 // |
1159 // |
1160 |
1160 |
1161 void CDrmStdKeyStorage::RandomDataGetL( TDes8& aData, const TInt aLength ) |
1161 void CDrmStdKeyStorage::RandomDataGetL( TDes8& aData, const TInt aLength ) |
1162 { |
1162 { |
1163 if ( aLength <= 0 ) |
1163 if ( aLength <= 0 ) |
1164 { |
1164 { |
1165 User::Leave(KErrArgument); |
1165 User::Leave(KErrArgument); |