Commit 54b8a92f authored by Tomi Leppänen's avatar Tomi Leppänen

[devicelock] Support asynchronous checkCode. Contributes to JB#45370

Add checkCodeFinished and move authentication code from
enterSecurityCode there. This is needed to support asynchronous
security code checking.
Signed-off-by: Tomi Leppänen's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent 1fa86b11
......@@ -302,38 +302,27 @@ void HostAuthenticator::handleClearSecurityCode(const QString &client)
void HostAuthenticator::enterSecurityCode(const QString &code)
{
int attempts = 0;
switch (m_state) {
case Idle:
return;
case Authenticating:
case RequestingPermission:
qCDebug(daemon, "Security code entered for authentication.");
switch ((attempts = checkCode(code))) {
case Success:
case SecurityCodeExpired:
confirmAuthentication(Authenticator::SecurityCode);
return;
case LockedOut:
lockedOut();
return;
}
break;
case AuthenticatingForChange:
checkCodeFinished(checkCode(code));
return;
case AuthenticatingForChange: {
qCDebug(daemon, "Security code entered for code change authentication.");
switch ((attempts = checkCode(code))) {
int result = checkCode(code);
switch (result) {
case Evaluating:
case Success:
case SecurityCodeExpired:
m_currentCode = code;
enterCodeChangeState(&HostAuthenticationInput::feedback, Authenticator::SecurityCode);
return;
case LockedOut:
lockedOut();
return;
break;
}
break;
checkCodeFinished(result);
return;
}
case EnteringNewSecurityCode:
qCDebug(daemon, "New security code entered.");
m_newCode = code;
......@@ -380,32 +369,19 @@ void HostAuthenticator::enterSecurityCode(const QString &code)
}
case AuthenticatingForClear: {
qCDebug(daemon, "Security code entered for clear authentication.");
if ((attempts = checkCode(code)) == 0) {
if (clearCode(code)) {
securityCodeCleared();
} else {
abortAuthentication(AuthenticationInput::SoftwareError);
}
return;
int result = checkCode(code);
switch (result) {
case Evaluating:
case Success:
m_currentCode = code;
break;
}
break;
checkCodeFinished(result);
return;
}
default:
return;
}
const int maximum = maximumAttempts();
if (maximum > 0 && attempts > 0) {
feedback(AuthenticationInput::IncorrectSecurityCode, qMax(0, maximum - attempts));
if (attempts >= maximum) {
lockedOut();
return;
}
} else {
feedback(AuthenticationInput::IncorrectSecurityCode, -1);
}
}
void HostAuthenticator::requestSecurityCode()
......@@ -435,6 +411,70 @@ void HostAuthenticator::authorize()
}
}
void HostAuthenticator::checkCodeFinished(int result)
{
switch (m_state) {
case Authenticating:
case RequestingPermission:
switch (result) {
case Evaluating:
return;
case Success:
case SecurityCodeExpired:
confirmAuthentication(Authenticator::SecurityCode);
return;
case LockedOut:
lockedOut();
return;
}
break;
case AuthenticatingForChange:
switch (result) {
case Evaluating:
return;
case Success:
case SecurityCodeExpired:
enterCodeChangeState(&HostAuthenticationInput::feedback, Authenticator::SecurityCode);
return;
case LockedOut:
lockedOut();
return;
}
break;
case AuthenticatingForClear: {
switch (result) {
case Evaluating:
return;
case Success:
if (clearCode(m_currentCode)) {
securityCodeCleared();
} else {
abortAuthentication(AuthenticationInput::SoftwareError);
}
m_currentCode.clear();
return;
break;
}
}
default:
return;
}
const int attempts = result;
const int maximum = maximumAttempts();
if (maximum > 0 && attempts > 0) {
feedback(AuthenticationInput::IncorrectSecurityCode, qMax(0, maximum - attempts));
if (attempts >= maximum) {
lockedOut();
return;
}
} else {
feedback(AuthenticationInput::IncorrectSecurityCode, -1);
}
}
void HostAuthenticator::setCodeFinished(int result)
{
switch (result) {
......@@ -588,6 +628,7 @@ void HostAuthenticator::securityCodeCleared()
void HostAuthenticator::securityCodeClearAborted()
{
m_currentCode.clear();
sendToActiveClient(securityCodeInterface, QStringLiteral("ClearAborted"));
authenticationEnded(false);
}
......
......@@ -129,6 +129,7 @@ public:
Authenticator::Methods methods, uint authenticatingPid, AuthenticationInput::Feedback feedback) override;
void authenticationEnded(bool confirmed) override;
void checkCodeFinished(int result);
void setCodeFinished(int result);
// Signals
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment