49 |
49 |
50 #include "SCPDebug.h" |
50 #include "SCPDebug.h" |
51 #include <featmgr.h> |
51 #include <featmgr.h> |
52 // For Device encryption |
52 // For Device encryption |
53 #include <DevEncEngineConstants.h> |
53 #include <DevEncEngineConstants.h> |
54 #include <DevEncSession.h> |
54 #include <DevEncSessionBase.h> |
55 |
55 |
56 // ==================== LOCAL FUNCTIONS ==================== |
56 // ==================== LOCAL FUNCTIONS ==================== |
57 |
57 |
58 // --------------------------------------------------------- |
58 // --------------------------------------------------------- |
59 // PanicServer Panics the server thread |
59 // PanicServer Panics the server thread |
112 |
112 |
113 iConfiguration.Initialize(); |
113 iConfiguration.Initialize(); |
114 |
114 |
115 // Assign default config flag |
115 // Assign default config flag |
116 iConfiguration.iConfigFlag = KSCPConfigUnknown; |
116 iConfiguration.iConfigFlag = KSCPConfigUnknown; |
|
117 iConfiguration.iConfigChecked = EFalse; |
117 |
118 |
118 // Assign the default codes |
119 // Assign the default codes |
119 iConfiguration.iSecCode.Zero(); |
120 iConfiguration.iSecCode.Zero(); |
120 iConfiguration.iSecCode.Append( KSCPDefaultSecCode ); |
121 iConfiguration.iSecCode.Append( KSCPDefaultSecCode ); |
|
122 |
|
123 // Assign the default codes |
|
124 iConfiguration.iCryptoCode.Zero(); |
|
125 iConfiguration.iCryptoCode.Append( KSCPDefaultSecCode ); |
121 |
126 |
122 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS |
127 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS |
123 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) |
128 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) |
124 { |
129 { |
125 // Reset code block parameters |
130 // Reset code block parameters |
162 } |
167 } |
163 else |
168 else |
164 { |
169 { |
165 Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") )); |
170 Dprint( (_L("CSCPServer::ConstructL(): Configration read OK") )); |
166 } |
171 } |
|
172 |
|
173 |
|
174 //If Configuration is not validated already, validate it |
|
175 |
|
176 if (!iConfiguration.iConfigChecked) |
|
177 { |
|
178 TInt valerr = KErrNone; |
|
179 TRAP( valerr, ValidateConfigurationL( KSCPComplete )); |
|
180 if (valerr != KErrNone) |
|
181 { |
|
182 Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation failed: %d"), valerr )); |
|
183 } |
|
184 else |
|
185 { |
|
186 Dprint( (_L("CSCPServer::ConstructL(): Configuration Validation Passed"))); |
|
187 } |
|
188 } |
|
189 |
|
190 |
167 |
191 |
168 Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") )); |
192 Dprint( (_L("CSCPServer::ConstructL(): Connecting to CenRep") )); |
169 iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings ); |
193 iALPeriodRep = CRepository::NewL( KCRUidSecuritySettings ); |
170 |
194 |
171 // Check for factory settings |
195 // Check for factory settings |
629 // |
653 // |
630 void CSCPServer::ValidateConfigurationL( TInt aMode ) |
654 void CSCPServer::ValidateConfigurationL( TInt aMode ) |
631 { |
655 { |
632 Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") )); |
656 Dprint( (_L("--> CSCPServer::ValidateConfigurationL()") )); |
633 |
657 |
634 if ( iConfiguration.iConfigFlag == KSCPConfigOK ) |
658 RMobilePhone::TMobilePassword storedCode; |
|
659 storedCode.Zero(); |
|
660 User::LeaveIfError(GetCode(storedCode)); |
|
661 |
|
662 |
|
663 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() )); |
|
664 // Check that the ISA code is stored correctly |
|
665 TRAPD( err, CheckISACodeL( storedCode ) ); |
|
666 //Bool for the correction of Defaultlockcode cenrep |
|
667 TBool lCorrectDefaultlockcode = EFalse; |
|
668 |
|
669 Dprint( (_L("CSCPServer::ValidateConfigurationL(): iConfigFlag = %d, iConfigChecked = %d"), iConfiguration.iConfigFlag, iConfiguration.iConfigChecked)); |
|
670 |
|
671 if ((iConfiguration.iConfigFlag == KSCPConfigOK) |
|
672 && (iConfiguration.iConfigChecked) && (err == KErrNone)) |
635 { |
673 { |
636 // The configuration has already been checked, exit |
674 // The configuration has already been checked, exit |
637 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") )); |
675 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Configuration is non-default.") )); |
638 User::Leave( KErrNone ); |
676 User::Leave( KErrNone ); |
639 } |
677 } |
641 { |
679 { |
642 // Return here, must be checked by complete mode |
680 // Return here, must be checked by complete mode |
643 User::Leave( KErrAccessDenied ); |
681 User::Leave( KErrAccessDenied ); |
644 } |
682 } |
645 |
683 |
646 RMobilePhone::TMobilePassword storedCode; |
684 |
647 storedCode.Zero(); |
|
648 |
|
649 User::LeaveIfError( GetCode( storedCode ) ); |
|
650 TInt hashedISAcode; |
685 TInt hashedISAcode; |
651 TSCPSecCode hashedCode; |
686 TSCPSecCode hashedCode; |
652 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS |
687 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS |
653 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) |
688 if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements)) |
654 { |
689 { |
657 hashedCode.Zero(); |
692 hashedCode.Zero(); |
658 hashedCode.AppendNum( hashedISAcode ); |
693 hashedCode.AppendNum( hashedISAcode ); |
659 } |
694 } |
660 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS |
695 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS |
661 |
696 |
662 Dprint( (_L("CSCPServer::ValidateConfigurationL(): Checking code: %s"), storedCode.PtrZ() )); |
697 |
663 |
698 |
664 // Check that the ISA code is stored correctly |
699 |
665 TRAPD( err, CheckISACodeL( storedCode ) ); |
700 if (err != KErrNone) |
|
701 { |
|
702 lCorrectDefaultlockcode = ETrue; |
|
703 } |
666 if ( err == KErrNone ) |
704 if ( err == KErrNone ) |
667 { |
705 { |
668 iConfiguration.iConfigFlag = KSCPConfigOK; |
706 iConfiguration.iConfigFlag = KSCPConfigOK; |
669 } |
707 } |
670 else if ( err == KErrAccessDenied ) |
708 else if ( err == KErrAccessDenied ) |
708 Storing hashed code(%d)"), hashedISAcode )); |
746 Storing hashed code(%d)"), hashedISAcode )); |
709 |
747 |
710 if ( StoreCode( hashedCode ) == KErrNone ) |
748 if ( StoreCode( hashedCode ) == KErrNone ) |
711 { |
749 { |
712 iConfiguration.iConfigFlag = KSCPConfigOK; |
750 iConfiguration.iConfigFlag = KSCPConfigOK; |
|
751 lCorrectDefaultlockcode = ETrue; |
713 } |
752 } |
714 } |
753 } |
715 } |
754 } |
716 } |
755 |
|
756 //If Correction of Defaultlockcode cenrep is required for the mismatch between Config and ISA |
|
757 if (lCorrectDefaultlockcode) |
|
758 { |
|
759 TInt lDefCode = -1; |
|
760 CRepository* lRepository = CRepository::NewL(KCRUidSCPLockCode); |
|
761 CleanupStack::PushL(lRepository); |
|
762 TInt lRet = lRepository->Get(KSCPLockCodeDefaultLockCode, |
|
763 lDefCode); |
|
764 if (lRet == KErrNone && lDefCode != -1) |
|
765 { |
|
766 if (lDefCode == 12345) |
|
767 { |
|
768 //Although lock code is already set, due to some unexpected condition |
|
769 //like C drive wipe, cenrep status is wrongly shown. Correcting it here. |
|
770 lRepository->Set(KSCPLockCodeDefaultLockCode, 0); |
|
771 Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 0") )); |
|
772 } |
|
773 else if (lDefCode == 0) |
|
774 { |
|
775 //If only ISA side is formatted, then the lock code on ISA side is default; |
|
776 //Cenrep status remains wrongly as the lock code is already set. Correcting it here. |
|
777 lRepository->Set(KSCPLockCodeDefaultLockCode, 12345); |
|
778 Dprint( (_L("RSCPClient::ValidateConfigurationL(): Corrected the Default lock code cenrep status to 12345") )); |
|
779 } |
|
780 } |
|
781 CleanupStack::PopAndDestroy(lRepository); |
|
782 } |
|
783 } |
717 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS |
784 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS |
|
785 //Set the flag to True, after config is validated |
|
786 iConfiguration.iConfigChecked = ETrue; |
718 |
787 |
719 TRAPD( err2, iConfiguration.WriteSetupL() ); |
788 TRAPD( err2, iConfiguration.WriteSetupL() ); |
720 if ( err2 != KErrNone ) |
789 if ( err2 != KErrNone ) |
721 { |
790 { |
722 Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\ |
791 Dprint( (_L("CSCPServer::ValidateConfigurationL(): WARNING: failed to write configuration\ |
2473 // Checks if phone memory is encrypted or not. |
2542 // Checks if phone memory is encrypted or not. |
2474 // --------------------------------------------------------- |
2543 // --------------------------------------------------------- |
2475 TBool CSCPServer::IsDeviceMemoryEncrypted() |
2544 TBool CSCPServer::IsDeviceMemoryEncrypted() |
2476 { |
2545 { |
2477 Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted >>")); |
2546 Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted >>")); |
2478 |
|
2479 TBool ret(EFalse); |
2547 TBool ret(EFalse); |
2480 |
|
2481 //First check if the feature is supported on device |
2548 //First check if the feature is supported on device |
2482 TRAPD(ferr, FeatureManager::InitializeLibL()); |
2549 TRAPD(ferr, FeatureManager::InitializeLibL()); |
2483 if (ferr != KErrNone) |
2550 if (ferr != KErrNone) |
2484 { |
2551 { |
2485 Dprint(_L("feature mgr initialization error, %d"), ferr); |
2552 Dprint(_L("feature mgr initialization error, %d"), ferr); |
2487 } |
2554 } |
2488 ret = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature); |
2555 ret = FeatureManager::FeatureSupported( KFeatureIdFfDeviceEncryptionFeature); |
2489 FeatureManager::UnInitializeLib(); |
2556 FeatureManager::UnInitializeLib(); |
2490 |
2557 |
2491 //If feature is supported, check if any drive is encrypted. |
2558 //If feature is supported, check if any drive is encrypted. |
|
2559 |
|
2560 |
|
2561 |
2492 if (ret) |
2562 if (ret) |
2493 { |
2563 { |
2494 CDevEncSession* devEncSession = new CDevEncSession( EDriveC ); |
2564 RLibrary library; |
2495 |
2565 CDevEncSessionBase* devEncSession = NULL; |
|
2566 TInt err = library.Load(KDevEncCommonUtils); |
|
2567 |
|
2568 if (err != KErrNone) |
|
2569 { |
|
2570 Dprint(_L("Error in finding the library... %d"), err); |
|
2571 ret = EFalse; |
|
2572 } |
|
2573 else |
|
2574 { |
|
2575 TLibraryFunction entry = library.Lookup(1); |
|
2576 |
|
2577 if (!entry) |
|
2578 { |
|
2579 Dprint(_L("Error in loading the library...")); |
|
2580 ret = EFalse; |
|
2581 } |
|
2582 else |
|
2583 { |
|
2584 devEncSession = (CDevEncSessionBase*) entry(); |
|
2585 Dprint(_L("Library is found and loaded successfully...")); |
|
2586 } |
|
2587 } |
|
2588 |
2496 if (!devEncSession) |
2589 if (!devEncSession) |
2497 { |
2590 { |
2498 Dprint(_L("Can't instantiate device encryption session..")); |
2591 Dprint(_L("Can't instantiate device encryption session..")); |
2499 return EFalse; |
|
2500 } |
|
2501 |
|
2502 TInt err = devEncSession->Connect(); |
|
2503 if (err == KErrNone) |
|
2504 { |
|
2505 //Session with device encryption is established. Check if any drive is encrypted |
|
2506 TInt encStatus (KErrNone); |
|
2507 TInt err = devEncSession->DiskStatus( encStatus ); |
|
2508 Dprint(_L("err = %d, encstatus = %d"), err, encStatus); |
|
2509 if ( err == KErrNone && encStatus != EDecrypted ) |
|
2510 { |
|
2511 Dprint(_L("Memory is encrypted")); |
|
2512 ret = ETrue; |
|
2513 } |
|
2514 else |
|
2515 { |
|
2516 Dprint(_L("Memory is not encrypted")); |
|
2517 ret = EFalse; |
|
2518 } |
|
2519 } |
|
2520 else |
|
2521 { |
|
2522 Dprint(_L("Error %d while establishing connection with device encryption engine"), err); |
|
2523 ret = EFalse; |
2592 ret = EFalse; |
2524 } |
2593 } |
2525 |
2594 else |
2526 delete devEncSession; devEncSession = NULL; |
2595 { |
2527 } |
2596 devEncSession->SetDrive( EDriveC ); |
|
2597 TInt err = devEncSession->Connect(); |
|
2598 if (err == KErrNone) |
|
2599 { |
|
2600 //Session with device encryption is established. Check if any drive is encrypted |
|
2601 TInt encStatus (KErrNone); |
|
2602 TInt err = devEncSession->DiskStatus( encStatus ); |
|
2603 devEncSession->Close(); |
|
2604 Dprint(_L("err = %d, encstatus = %d"), err, encStatus); |
|
2605 if ( err == KErrNone && encStatus != EDecrypted ) |
|
2606 { |
|
2607 Dprint(_L("Memory is encrypted")); |
|
2608 ret = ETrue; |
|
2609 } |
|
2610 else |
|
2611 { |
|
2612 Dprint(_L("Memory is not encrypted")); |
|
2613 ret = EFalse; |
|
2614 } |
|
2615 } |
|
2616 else |
|
2617 { |
|
2618 Dprint(_L("Error %d while establishing connection with device encryption engine"), err); |
|
2619 ret = EFalse; |
|
2620 } |
|
2621 } |
|
2622 delete devEncSession; devEncSession = NULL; |
|
2623 |
|
2624 if (library.Handle()) |
|
2625 library.Close(); |
|
2626 } |
2528 |
2627 |
2529 Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted, ret = %d <<"), ret); |
2628 Dprint(_L("CSCPServer::IsDeviceMemoryEncrypted, ret = %d <<"), ret); |
2530 return ret; |
2629 return ret; |
2531 } |
2630 } |
2532 |
2631 |