Skip to content

Commit

Permalink
Allow implementations to return a locked out condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
adenexter committed Jan 26, 2017
1 parent 4963d65 commit a25a286
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/nemo-devicelock/host/hostauthenticationinput.h
Expand Up @@ -70,7 +70,8 @@ class HostAuthenticationInput : public HostObject
Failure = -1,
SecurityCodeExpired = -2,
SecurityCodeInHistory = -3,
Evaluating = -4
LockedOut = -4,
Evaluating = -5
};

enum Availability {
Expand All @@ -93,8 +94,8 @@ class HostAuthenticationInput : public HostObject
// AuthenticationInput
virtual bool authorizeInput(unsigned long pid);

int maximumAttempts() const;
int currentAttempts() const;
virtual int maximumAttempts() const;
virtual int currentAttempts() const;

virtual void enterSecurityCode(const QString &code) = 0;
void cancel() override = 0;
Expand Down
25 changes: 17 additions & 8 deletions src/nemo-devicelock/host/hostauthenticator.cpp
Expand Up @@ -211,18 +211,28 @@ void HostAuthenticator::enterSecurityCode(const QString &code)
return;
case Authenticating:
qCDebug(daemon, "Lock code entered for authentication.");
if ((attempts = checkCode(code)) == Success) {
switch ((attempts = checkCode(code))) {
case Success:
case SecurityCodeExpired:
confirmAuthentication();
return;
case LockedOut:
abortAuthentication(AuthenticationInput::LockedOut);
return;
}
break;
case AuthenticatingForChange:
qCDebug(daemon, "Lock code entered for code change authentication.");
if ((attempts = checkCode(code)) == Success) {
switch ((attempts = checkCode(code))) {
case Success:
case SecurityCodeExpired:
m_state = EnteringNewSecurityCode;
m_currentCode = code;
feedback(AuthenticationInput::EnterNewSecurityCode, -1);
return;
case LockedOut:
abortAuthentication(AuthenticationInput::LockedOut);
return;
}
break;
case EnteringNewSecurityCode:
Expand All @@ -235,7 +245,6 @@ void HostAuthenticator::enterSecurityCode(const QString &code)
qCDebug(daemon, "New lock code confirmation entered.");
if (m_newCode != code) {
qCDebug(daemon, "Lock codes don't match.");
m_currentCode.clear();
m_newCode.clear();

feedback(AuthenticationInput::SecurityCodesDoNotMatch, -1);
Expand All @@ -251,11 +260,9 @@ void HostAuthenticator::enterSecurityCode(const QString &code)
return;
}

const auto currentCode = m_currentCode;
m_currentCode.clear();
m_newCode.clear();

setCodeFinished(setCode(currentCode, code));
setCodeFinished(setCode(m_currentCode, code));

return;
}
Expand Down Expand Up @@ -293,6 +300,8 @@ void HostAuthenticator::setCodeFinished(int result)
{
switch (result) {
case Success:
m_currentCode.clear();

qCDebug(daemon, "Lock code changed.");
securityCodeChanged(authenticateChallengeCode(m_challengeCode));
break;
Expand All @@ -315,10 +324,10 @@ void HostAuthenticator::setCodeFinished(int result)
}
break;
default:
m_currentCode.clear();
qCDebug(daemon, "Lock code change failed.");

m_state = ChangeError;
authenticationUnavailable(AuthenticationInput::SoftwareError);
abortAuthentication(AuthenticationInput::SoftwareError);
break;
}
}
Expand Down
29 changes: 26 additions & 3 deletions src/nemo-devicelock/host/hostdevicelock.cpp
Expand Up @@ -143,6 +143,9 @@ void HostDeviceLock::enterSecurityCode(const QString &code)
break;
case SecurityCodeInHistory:
break;
case LockedOut:
abortAuthentication(AuthenticationInput::LockedOut);
break;
default: {
const int maximum = maximumAttempts();

Expand Down Expand Up @@ -176,11 +179,9 @@ void HostDeviceLock::enterSecurityCode(const QString &code)
// With disk encryption enabled changing the code can take a few seconds, don't leave
// the user hanging.

const auto currentCode = m_currentCode;
m_currentCode.clear();
m_newCode.clear();

setCodeFinished(setCode(currentCode, code));
setCodeFinished(setCode(m_currentCode, code));
}
break;
case Unlocking:
Expand Down Expand Up @@ -226,6 +227,7 @@ void HostDeviceLock::setCodeFinished(int result)
switch (result) {
case Success:
qCDebug(daemon, "Lock code changed.");
m_currentCode.clear();
if (m_state == ChangingSecurityCode) {
unlockFinished(unlockWithCode(m_newCode));
} else if (m_state == Canceled) {
Expand All @@ -252,6 +254,7 @@ void HostDeviceLock::setCodeFinished(int result)
return;
default:
qCDebug(daemon, "Lock code change failed.");
m_currentCode.clear();
if (m_state == Canceled) {
m_state = Idle;

Expand Down Expand Up @@ -291,6 +294,26 @@ void HostDeviceLock::confirmAuthentication()
unlockingChanged();
}

void HostDeviceLock::abortAuthentication(AuthenticationInput::Error error)
{
m_currentCode.clear();
m_newCode.clear();

switch (m_state) {
case Authenticating:
case Unlocking:
case EnteringNewSecurityCode:
case RepeatingNewSecurityCode:
case ChangingSecurityCode:
m_state = AuthenticationError;
break;
default:
break;
}

HostAuthenticationInput::abortAuthentication(error);
}

void HostDeviceLock::stateChanged()
{
propertyChanged(
Expand Down
3 changes: 2 additions & 1 deletion src/nemo-devicelock/host/hostdevicelock.h
Expand Up @@ -78,7 +78,7 @@ class HostDeviceLock : public HostAuthenticationInput

bool isUnlocking() const;

int automaticLocking() const;
virtual int automaticLocking() const;

void unlock();
void enterSecurityCode(const QString &code) override;
Expand All @@ -93,6 +93,7 @@ class HostDeviceLock : public HostAuthenticationInput
virtual void setState(DeviceLock::LockState state) = 0;

void confirmAuthentication() override;
void abortAuthentication(AuthenticationInput::Error error) override;

void stateChanged();
void availabilityChanged();
Expand Down

0 comments on commit a25a286

Please sign in to comment.