Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[devicelock] Ask user to confirm a generated code twice. Fixes JB#38895
  • Loading branch information
adenexter committed Jun 19, 2017
1 parent 98fbfd9 commit 04a7e21
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/nemo-devicelock/host/hostauthenticator.cpp
Expand Up @@ -98,6 +98,8 @@ HostAuthenticator::HostAuthenticator(Authenticator::Methods supportedMethods, QO
: HostAuthenticationInput(QStringLiteral("/authenticator"), supportedMethods, parent)
, m_adaptor(this)
, m_securityCodeAdaptor(this)
, m_repeatsRequired(0)
, m_state(Idle)
{
}

Expand Down Expand Up @@ -260,13 +262,15 @@ void HostAuthenticator::enterSecurityCode(const QString &code)
qCDebug(daemon, "New lock code entered.");
m_newCode = code;
m_state = RepeatingNewSecurityCode;
m_repeatsRequired = 1;
feedback(AuthenticationInput::RepeatNewSecurityCode, -1);
return;
case ExpectingGeneratedSecurityCode:
if (m_generatedCode == code) {
m_newCode = code;
m_state = RepeatingNewSecurityCode;
feedback(AuthenticationInput::RepeatNewSecurityCode, -1);
m_repeatsRequired = 2;
feedback(AuthenticationInput::EnterNewSecurityCode, -1);
} else {
feedback(AuthenticationInput::SecurityCodesDoNotMatch, QVariantMap());
feedback(AuthenticationInput::SuggestSecurityCode, generatedCodeData());
Expand All @@ -289,14 +293,13 @@ void HostAuthenticator::enterSecurityCode(const QString &code)
m_state = AuthenticatingForChange;
feedback(AuthenticationInput::EnterSecurityCode, -1);
}
} else if (--m_repeatsRequired > 0) {
feedback(AuthenticationInput::RepeatNewSecurityCode, -1);
} else {
m_newCode.clear();

return;
setCodeFinished(setCode(m_currentCode, code));
}

m_newCode.clear();

setCodeFinished(setCode(m_currentCode, code));

return;
}
case AuthenticatingForClear: {
Expand Down
1 change: 1 addition & 0 deletions src/nemo-devicelock/host/hostauthenticator.h
Expand Up @@ -172,6 +172,7 @@ class HostAuthenticator : public HostAuthenticationInput
QString m_currentCode;
QString m_newCode;
QString m_generatedCode;
int m_repeatsRequired;
State m_state;
};

Expand Down
7 changes: 6 additions & 1 deletion src/nemo-devicelock/host/hostdevicelock.cpp
Expand Up @@ -72,6 +72,7 @@ HostDeviceLock::HostDeviceLock(Authenticator::Methods supportedMethods, QObject
: HostAuthenticationInput(QStringLiteral("/devicelock/lock"), supportedMethods, parent)
, m_adaptor(this)
, m_settings(SettingsWatcher::instance())
, m_repeatsRequired(0)
, m_state(Idle)
, m_lockState(DeviceLock::Undefined)
{
Expand Down Expand Up @@ -181,13 +182,15 @@ void HostDeviceLock::enterSecurityCode(const QString &code)
case EnteringNewSecurityCode:
m_newCode = code;
m_state = RepeatingNewSecurityCode;
m_repeatsRequired = 1;
feedback(AuthenticationInput::RepeatNewSecurityCode, -1);
break;
case ExpectingGeneratedSecurityCode:
if (m_generatedCode == code) {
m_newCode = code;
m_state = RepeatingNewSecurityCode;
feedback(AuthenticationInput::RepeatNewSecurityCode, -1);
m_repeatsRequired = 2;
feedback(AuthenticationInput::EnterNewSecurityCode, -1);
} else {
feedback(AuthenticationInput::SecurityCodesDoNotMatch, QVariantMap());
feedback(AuthenticationInput::SuggestSecurityCode, generatedCodeData());
Expand All @@ -210,6 +213,8 @@ void HostDeviceLock::enterSecurityCode(const QString &code)
break;
}
break;
} else if (--m_repeatsRequired > 0) {
feedback(AuthenticationInput::RepeatNewSecurityCode, -1);
} else {
setCodeFinished(setCode(m_currentCode, code));
}
Expand Down
1 change: 1 addition & 0 deletions src/nemo-devicelock/host/hostdevicelock.h
Expand Up @@ -137,6 +137,7 @@ class HostDeviceLock : public HostAuthenticationInput
QString m_currentCode;
QString m_newCode;
QString m_generatedCode;
int m_repeatsRequired;
State m_state;
DeviceLock::LockState m_lockState;
};
Expand Down

0 comments on commit 04a7e21

Please sign in to comment.