diff -r 6b63ca65093a -r aad866c37519 securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp --- a/securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp Thu May 27 13:44:17 2010 +0300 +++ b/securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp Fri Jun 11 14:28:40 2010 +0300 @@ -15,10 +15,10 @@ * * */ - +#include #include #include -#include +// #include #include #include @@ -40,14 +40,13 @@ #include #include #include "secui.hrh" +#include "SecUi.h" #include "secuisecurityhandler.h" #include "secuicodequerydialog.h" #include "secuisecuritysettings.h" #include "SecUiWait.h" -#include "SecUiLockObserver.h" -#ifdef RD_REMOTELOCK +// #include "SecUiLockObserver.h" #include -#endif // RD_REMOTELOCK #include #include @@ -151,15 +150,11 @@ switch (aEvent) { case RMobilePhone::EPin1Required: -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::HandleEventL() Pin1Required")); -#endif + RDEBUG("RMobilePhone::EPin1Required", 0); aResult = Pin1RequiredL(); break; case RMobilePhone::EPuk1Required: -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::HandleEventL() PUK1Required")); -#endif + RDEBUG("RMobilePhone::EPuk1Required", 0); Puk1RequiredL(); break; case RMobilePhone::EPin2Required: @@ -191,6 +186,7 @@ SimLockEventL(); break; default: + RDEBUG("default", aEvent); break; } RDEBUG("aResult", aResult); @@ -207,9 +203,7 @@ * Series 60 Customer / ETel * Series 60 ETel API *****************************************************/ -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeL()")); -#endif + RDEBUG("0", 0); /* if code is still not initialized, then there's no need to ask it. This fixes the error when the RFS requests the code */ const TUid KCRUidSCPLockCode = @@ -265,7 +259,7 @@ SEC_C_SECURITY_CODE_MIN_LENGTH, SEC_C_SECURITY_CODE_MAX_LENGTH, ESecUiSecretSupported | lAlphaSupported | lCancelSupported - | secCodeType /*aMode*/); + | secCodeType ); RDEBUG("iSecUi_password", 0); RDebug::Print(iSecUi_password); RDEBUG("delete", 0); @@ -352,14 +346,12 @@ // ---------------------------------------------------------- // CSecurityHandler::CancelSecCodeQuery() // Cancels PIN2 and security code queries -// TODO is this used? +// this is used by rfsHandler // ---------------------------------------------------------- // qtdone EXPORT_C void CSecurityHandler::CancelSecCodeQuery() { -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::CancelSecCodeQuery()")); -#endif + RDEBUG("iQueryCanceled", iQueryCanceled); if (!iQueryCanceled) { iQueryCanceled = ETrue; @@ -587,7 +579,10 @@ RDEBUG("StartUp", StartUp); RDEBUG("err", err); if (!StartUp) + { + RDebug::Printf( "%s %s (%u) Leaving because StartUp=0 and err=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, err ); User::LeaveIfError(err); + } TBool isConditionSatisfied = EFalse; TInt tarmFlag = 0; if (FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw )) @@ -597,16 +592,11 @@ if (tRet != KErrNone) { -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL():\ - Warning: failed to get TARM Admin Flag state")); -#endif + RDEBUG("Warning: failed to get TARM Admin Flag state", tRet); } else { -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL(): TARM flag: %d"), tarmFlag ); -#endif + RDEBUG("TARM flag", tarmFlag); } if ((StartUp) || (tarmFlag & KSCPFlagResyncQuery)) @@ -619,8 +609,7 @@ } // Security code at bootup: No "cancel" softkey; Emergency calls enabled. - RMobilePhone::TMobilePhoneSecurityCode secCodeTypeToAsk = - RMobilePhone::ESecurityCodePhonePassword; // for starters + RMobilePhone::TMobilePhoneSecurityCode secCodeTypeToAsk = RMobilePhone::ESecurityCodePhonePassword; RDEBUG("isConditionSatisfied", isConditionSatisfied); if (isConditionSatisfied) { @@ -646,7 +635,6 @@ TInt lType = ESecUiSecretSupported | ESecUiAlphaSupported | lCancelSupported | lEmergencySupported | secCodeTypeToAsk; RDEBUG("lType", lType); - iSecUi_password.Copy(_L("12345")); queryAccepted = iSecQueryUi->SecQueryDialog(_L("PassPhraseRequiredL"), iSecUi_password, SEC_C_SECURITY_CODE_MIN_LENGTH, SEC_C_SECURITY_CODE_MAX_LENGTH, lType); @@ -664,9 +652,7 @@ RDEBUG("wasCancelledOrEmergency", wasCancelledOrEmergency); if (wasCancelledOrEmergency) { -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() DIALOG ERROR")); -#endif + RDEBUG("StartUp", StartUp); if (!StartUp) { RDEBUG("AbortSecurityCode", 0); @@ -738,7 +724,9 @@ KFeatureIdSapDeviceLockEnhancements); RSCPClient scpClient; RDEBUG("scpClient.Connect", 0); - User::LeaveIfError(scpClient.Connect()); + TInt tRet = scpClient.Connect(); + RDEBUG("tRet", tRet); + User::LeaveIfError(tRet); RDEBUG("scpClient.Connect", 1); CleanupClosePushL(scpClient); TSCPSecCode newCode; @@ -776,8 +764,7 @@ // disable autolock in Domestic OS side too if autolock period is 0. if (period == 0) { -#ifdef RD_REMOTELOCK - // If remote lock is enabled, don't disable the domestic OS device lock + // Don't disable the domestic OS device lock // since that would render the RemoteLock useless. TBool remoteLockStatus( EFalse ); @@ -808,23 +795,12 @@ delete remoteLockSettings; remoteLockSettings = NULL; -#else // not defined RD_REMOTELOCK - RDEBUG("iCustomPhone.DisablePhoneLock", 0); - wait = CWait::NewL(); - iCustomPhone.DisablePhoneLock(wait->iStatus, - iSecUi_password); - RDEBUG( "WaitForRequestL", 0 ); - status = wait->WaitForRequestL(); - RDEBUG( "WaitForRequestL status", status ); - delete wait; -#endif // RD_REMOTELOCK } } else // error getting repository { RDEBUG("error getting repository", 0); -#ifdef RD_REMOTELOCK - // If remote lock is enabled, don't disable the domestic OS device lock + // Don't disable the domestic OS device lock // since that would render the RemoteLock useless. TBool remoteLockStatus( EFalse ); @@ -853,18 +829,6 @@ delete remoteLockSettings; remoteLockSettings = NULL; -#else // not defined RD_REMOTELOCK - // could not get the current autolock time... disable autolock in Domestic OS side. - RDEBUG("iCustomPhone.DisablePhoneLock", 0); - wait = CWait::NewL(); - iCustomPhone.DisablePhoneLock(wait->iStatus, - iSecUi_password); - RDEBUG( "WaitForRequestL", 0 ); - status = wait->WaitForRequestL(); - RDEBUG( "WaitForRequestL status", status ); - delete wait; - -#endif // RD_REMOTELOCK } } // no Startup @@ -873,9 +837,7 @@ case KErrGsmSSPasswordAttemptsViolation: case KErrLocked: // security code blocked! -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() ErrGsmSSPasswordAttemptsViolation")); -#endif + RDEBUG("KErrLocked", KErrLocked); CSecuritySettings::ShowResultNoteL(R_SEC_BLOCKED, CAknNoteDialog::EErrorTone); break; @@ -965,7 +927,6 @@ res=KErrNone; codeInfo.iRemainingEntryAttempts=3; #endif - User::LeaveIfError(res); RDEBUG("codeInfo.iRemainingEntryAttempts", @@ -1072,6 +1033,8 @@ // ---------------------------------------------------------- // CSecurityHandler::Puk1Required() // Handles Puk1Required event +// First asks the PUK1, then verifies, then the newPIN + re-type , and then writes . This is odd, but the API needs the PUK and newPIN in same step. +// Afterwards, the PIN1 might be asked (because the initial program still needs it) // ---------------------------------------------------------- // qtdone TInt CSecurityHandler::Puk1RequiredL() @@ -1080,12 +1043,10 @@ * Series 60 Customer / ETel * Series 60 ETel API *****************************************************/ -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::Puk1RequiredL()")); -#endif + RDEBUG("0", 0); TInt queryAccepted = KErrCancel; - RMobilePhone::TMobilePassword iSecUi_password; - RMobilePhone::TMobilePassword aNewPassword; + RMobilePhone::TMobilePassword puk1_password; + RMobilePhone::TMobilePassword aNewPinPassword; RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo; RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo); RMobilePhone::TMobilePhoneSecurityCode blockCodeType; @@ -1096,7 +1057,7 @@ TBool StartUp(ETrue); StartUp = iStartup; - TInt res(KErrNone); + TInt res(KErrCancel); // for the first try wait->SetRequestType(EMobilePhoneGetSecurityCodeInfo); TInt thisTry = 0; @@ -1112,17 +1073,13 @@ res = wait->WaitForRequestL(); RDEBUG("WaitForRequestL res", res); } -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::Puk1RequiredL(): Get Code info result: %d"), res); -#endif + RDEBUG("res", res); //If there's still an error we're doomed. Bail out. User::LeaveIfError(res); -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::Puk1RequiredL(): Show last note")); -#endif - RDEBUG("StartUp", StartUp); + RDEBUG("codeInfo.iRemainingEntryAttempts", + codeInfo.iRemainingEntryAttempts); TInt attempts(codeInfo.iRemainingEntryAttempts); RDEBUG( "attempts", attempts ); //show the last "Code Error" note of PIN verify result here so it won't be left under the PUK1 dialog @@ -1131,12 +1088,9 @@ CSecuritySettings::ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone); - if (attempts == KMaxNumberOfPINAttempts) attempts = -1; - // ask PUK code - /* request PIN using QT */ CSecQueryUi *iSecQueryUi; RDEBUG("CSecQueryUi", 0); iSecQueryUi = CSecQueryUi::NewL(); @@ -1148,23 +1102,69 @@ title.Append(_L("Puk1RequiredL")); title.Append(_L("#")); title.AppendNum(attempts); - queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password, + TInt lSecUiCancelSupported = ESecUiCancelSupported | ESecUiEmergencyNotSupported; + if(StartUp) // TODO how to know whether PUK comes from failing at Starter, or failing at any other PIN (i.e. changing PIN, or changing PIN-request) ??? + lSecUiCancelSupported = ESecUiCancelNotSupported | ESecUiEmergencySupported; + queryAccepted = iSecQueryUi->SecQueryDialog(title, puk1_password, SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH, ESecUiSecretNotSupported | ESecUiAlphaNotSupported - | ESecUiCancelSupported | ESecUiPukRequired); - RDEBUG("iSecUi_password", 0); - RDebug::Print(iSecUi_password); + | lSecUiCancelSupported | ESecUiPukRequired); + RDEBUG("puk1_password", 0); + RDebug::Print(puk1_password); delete iSecQueryUi; RDEBUG("queryAccepted", queryAccepted); if ((queryAccepted == KErrAbort) || (queryAccepted == KErrCancel)) { - CleanupStack::PopAndDestroy(wait); // TODO this is needed ??? + CleanupStack::PopAndDestroy(wait); // this is needed return KErrCancel; } + // send code + // first we verify the puk. For this, we reset the PIN to the same as the PUK + // Hopefully this will never fail in the case "new PIN too long" + RDEBUG("VerifySecurityCode", 0); + iPhone.VerifySecurityCode(wait->iStatus, blockCodeType, puk1_password, puk1_password); + RDEBUG("WaitForRequestL", 0); + res = wait->WaitForRequestL(); + RDEBUG("WaitForRequestL res", res); + CleanupStack::PopAndDestroy(wait); + + TInt returnValue = res; + switch (res) { - // new pin code query + case KErrNone: + // code approved -> note . The process continue and new-pin is requested + CSecuritySettings::ShowResultNoteL(res, + CAknNoteDialog::EConfirmationTone); + break; + case KErrGsm0707IncorrectPassword: + case KErrAccessDenied: + // wrong PUK code -> note -> ask PUK code again + CSecuritySettings::ShowResultNoteL(R_CODE_ERROR, + CAknNoteDialog::EErrorTone); + returnValue = Puk1RequiredL(); + break; + case KErrGsm0707SimWrong: + // sim lock active + // TODO no message ? + break; + case KErrGsmSSPasswordAttemptsViolation: + case KErrLocked: + // sim card rejected. + break; + default: + CSecuritySettings::ShowErrorNoteL(res); + returnValue = Puk1RequiredL(); + break; + } + + // Now the PUK1 is validated. It's time for asking the new PIN1 + RDEBUG("new wait", 0); + wait = CWait::NewL(); + CleanupStack::PushL(wait); + { + // new-pin query CSecQueryUi * iSecQueryUi; RDEBUG("CSecQueryUi", 0); iSecQueryUi = CSecQueryUi::NewL(); @@ -1173,12 +1173,12 @@ // TODO also support Emergency queryAccepted = iSecQueryUi->SecQueryDialog( - _L("Puk1-New|Puk1-Verif"), aNewPassword, - SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH, + _L("PIN1-New|PIN1-Verif"), aNewPinPassword, + SEC_C_PIN_CODE_MIN_LENGTH, SEC_C_PIN_CODE_MAX_LENGTH, ESecUiAlphaNotSupported | ESecUiCancelSupported | ESecUiPukRequired); - RDEBUG("aNewPassword", 0); - RDebug::Print(aNewPassword); + RDEBUG("aNewPinPassword", 0); + RDebug::Print(aNewPinPassword); delete iSecQueryUi; RDEBUG("queryAccepted", queryAccepted); } @@ -1189,16 +1189,16 @@ return KErrCancel; } - // send code + // send code again, now with the user pin RDEBUG("VerifySecurityCode", 0); - iPhone.VerifySecurityCode(wait->iStatus, blockCodeType, aNewPassword, - iSecUi_password); + iPhone.VerifySecurityCode(wait->iStatus, blockCodeType, aNewPinPassword, + puk1_password); RDEBUG("WaitForRequestL", 0); res = wait->WaitForRequestL(); RDEBUG("WaitForRequestL res", res); CleanupStack::PopAndDestroy(wait); - TInt returnValue = res; + returnValue = res; switch (res) { case KErrNone: @@ -1226,7 +1226,7 @@ returnValue = Puk1RequiredL(); break; } - + RDEBUG("returnValue", returnValue); return returnValue; } // @@ -1242,9 +1242,7 @@ * Series 60 ETel API *****************************************************/ -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::Pin2RequiredL() BEGIN")); -#endif + RDEBUG("0", 0); TInt queryAccepted = KErrCancel; RMobilePhone::TMobilePassword iSecUi_password; RMobilePhone::TMobilePassword required_fourth; @@ -1261,7 +1259,6 @@ RDEBUG("WaitForRequestL", 0); TInt ret = wait->WaitForRequestL(); RDEBUG("WaitForRequestL ret", ret); - User::LeaveIfError(ret); RDEBUG("codeInfo.iRemainingEntryAttempts", @@ -1329,9 +1326,6 @@ CSecuritySettings::ShowErrorNoteL(status); break; } -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::Pin2RequiredL(): END")); -#endif } // // ---------------------------------------------------------- @@ -1345,6 +1339,7 @@ * Series 60 Customer / ETel * Series 60 ETel API *****************************************************/ + RDEBUG("0", 0); TInt queryAccepted = KErrCancel; RMobilePhone::TMobilePassword iSecUi_password; RMobilePhone::TMobilePassword aNewPassword; @@ -1357,9 +1352,6 @@ CWait* wait = CWait::NewL(); CleanupStack::PushL(wait); -#if defined(_DEBUG) - RDebug::Print(_L("(SECUI)CSecurityHandler::Puk2RequiredL()")); -#endif // ask PUK2 TInt ret(KErrNone); @@ -1392,7 +1384,7 @@ queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password, SEC_C_PUK2_CODE_MIN_LENGTH, SEC_C_PUK2_CODE_MAX_LENGTH, ESecUiSecretNotSupported | ESecUiAlphaNotSupported - | ESecUiCancelSupported | secCodeType /*aMode*/); + | ESecUiCancelSupported | secCodeType ); RDEBUG("iSecUi_password", 0); RDebug::Print(iSecUi_password); delete iSecQueryUi; @@ -1408,8 +1400,45 @@ return; } + RDEBUG("VerifySecurityCode", 0); + iPhone.VerifySecurityCode(wait->iStatus, secCodeType, iSecUi_password, iSecUi_password); + // this writes the newPIN2 with the value of PUK2. It's ok, since the user forgot it + RDEBUG("WaitForRequestL", 0); + TInt res = wait->WaitForRequestL(); + RDEBUG("WaitForRequestL res", res); + CleanupStack::PopAndDestroy(wait); + + switch (res) { - // new pin code query + case KErrNone: + // code approved -> note + CSecuritySettings::ShowResultNoteL(res, + CAknNoteDialog::EConfirmationTone); + break; + case KErrGsm0707IncorrectPassword: + case KErrAccessDenied: + // wrong PUK2 code -> note -> ask PUK2 code again + CSecuritySettings::ShowResultNoteL(R_CODE_ERROR, + CAknNoteDialog::EErrorTone); + Puk2RequiredL(); + break; + case KErrGsmSSPasswordAttemptsViolation: + case KErrLocked: + // Pin2 features blocked permanently! + CSecuritySettings::ShowResultNoteL(R_PIN2_REJECTED, + CAknNoteDialog::EConfirmationTone); + break; + default: + CSecuritySettings::ShowErrorNoteL(res); + Puk2RequiredL(); + break; + } + + // now the PUK2 is valid. Time to get the new PIN2 + wait = CWait::NewL(); + CleanupStack::PushL(wait); + { + // new pin2 code query CSecQueryUi * iSecQueryUi; RDEBUG("CSecQueryUi", 0); iSecQueryUi = CSecQueryUi::NewL(); @@ -1417,9 +1446,9 @@ // TODO also support Emergency queryAccepted - = iSecQueryUi->SecQueryDialog(_L("Puk2-New|Puk2-Verif"), - aNewPassword, SEC_C_PUK2_CODE_MIN_LENGTH, - SEC_C_PUK2_CODE_MAX_LENGTH, ESecUiAlphaNotSupported + = iSecQueryUi->SecQueryDialog(_L("PIN2-New|PIN2-Verif"), + aNewPassword, SEC_C_PIN2_CODE_MIN_LENGTH, + SEC_C_PIN2_CODE_MAX_LENGTH, ESecUiAlphaNotSupported | ESecUiCancelSupported | secCodeType); RDEBUG("aNewPassword", 0); RDebug::Print(aNewPassword); @@ -1441,7 +1470,7 @@ iPhone.VerifySecurityCode(wait->iStatus, secCodeType, aNewPassword, iSecUi_password); RDEBUG("WaitForRequestL", 0); - TInt res = wait->WaitForRequestL(); + res = wait->WaitForRequestL(); RDEBUG("WaitForRequestL res", res); CleanupStack::PopAndDestroy(wait); @@ -1487,6 +1516,8 @@ TBool wcdmaSupported( FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma)); TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin)); + RDEBUG("wcdmaSupported", wcdmaSupported); + RDEBUG("upinSupported", upinSupported); if (wcdmaSupported || upinSupported) { TInt queryAccepted = KErrCancel; @@ -1570,9 +1601,7 @@ { case KErrNone: // code approved -#if defined(_DEBUG) - RDebug::Print(_L("CSecurityHandler::UPinRequiredL()code approved ")); -#endif + RDEBUG("code approved ", 0); CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE, CAknNoteDialog::EConfirmationTone); break; @@ -1590,13 +1619,13 @@ case KErrLocked: // code blocked; show error note and terminate. if (StartUp) - CSecuritySettings::ShowResultNoteL(R_CODE_ERROR, + CSecuritySettings::ShowResultNoteL(res, CAknNoteDialog::EErrorTone); break; case KErrGsm0707SimWrong: // sim lock active break; - default: + default: // for example, KErrArgument CSecuritySettings::ShowErrorNoteL(res); if (StartUp) { @@ -1783,16 +1812,7 @@ RDEBUG("aStatus", aStatus); RDEBUG("!!!!! this should never be called !!!!", 0); - CTextResolver* textresolver = CTextResolver::NewLC(); - // Resolve the error - TPtrC errorstring; - errorstring.Set(textresolver->ResolveErrorString(aStatus)); - iNoteDlg = new (ELeave) CAknNoteDialog(REINTERPRET_CAST(CEikDialog**,&iNoteDlg)); - iNoteDlg->PrepareLC(R_CODE_ERROR); - iNoteDlg->SetTextL((TDesC&) errorstring); - iNoteDlg->RunDlgLD(CAknNoteDialog::ELongTimeout, - CAknNoteDialog::EErrorTone); - CleanupStack::PopAndDestroy(textresolver); + CSecuritySettings::ShowResultNoteL(aStatus, CAknNoteDialog::EErrorTone); } // End of file