Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed May 3, 2019
1 parent 1fa86b1 commit 54b8a92
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 42 deletions.
125 changes: 83 additions & 42 deletions src/nemo-devicelock/host/hostauthenticator.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -588,6 +628,7 @@ void HostAuthenticator::securityCodeCleared()

void HostAuthenticator::securityCodeClearAborted()
{
m_currentCode.clear();
sendToActiveClient(securityCodeInterface, QStringLiteral("ClearAborted"));
authenticationEnded(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/nemo-devicelock/host/hostauthenticator.h
Expand Up @@ -129,6 +129,7 @@ class HostAuthenticator : public HostAuthenticationInput
Authenticator::Methods methods, uint authenticatingPid, AuthenticationInput::Feedback feedback) override;
void authenticationEnded(bool confirmed) override;

void checkCodeFinished(int result);
void setCodeFinished(int result);

// Signals
Expand Down

0 comments on commit 54b8a92

Please sign in to comment.