From 04a7e21836da8bae7f5bc7f1feeff32f4dc8432d Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 8 Jun 2017 14:34:28 +1000 Subject: [PATCH] [devicelock] Ask user to confirm a generated code twice. Fixes JB#38895 --- src/nemo-devicelock/host/hostauthenticator.cpp | 17 ++++++++++------- src/nemo-devicelock/host/hostauthenticator.h | 1 + src/nemo-devicelock/host/hostdevicelock.cpp | 7 ++++++- src/nemo-devicelock/host/hostdevicelock.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/nemo-devicelock/host/hostauthenticator.cpp b/src/nemo-devicelock/host/hostauthenticator.cpp index 4b5b894..afef840 100644 --- a/src/nemo-devicelock/host/hostauthenticator.cpp +++ b/src/nemo-devicelock/host/hostauthenticator.cpp @@ -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) { } @@ -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()); @@ -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: { diff --git a/src/nemo-devicelock/host/hostauthenticator.h b/src/nemo-devicelock/host/hostauthenticator.h index f1d59b0..996443d 100644 --- a/src/nemo-devicelock/host/hostauthenticator.h +++ b/src/nemo-devicelock/host/hostauthenticator.h @@ -172,6 +172,7 @@ class HostAuthenticator : public HostAuthenticationInput QString m_currentCode; QString m_newCode; QString m_generatedCode; + int m_repeatsRequired; State m_state; }; diff --git a/src/nemo-devicelock/host/hostdevicelock.cpp b/src/nemo-devicelock/host/hostdevicelock.cpp index 73c9660..8079c35 100644 --- a/src/nemo-devicelock/host/hostdevicelock.cpp +++ b/src/nemo-devicelock/host/hostdevicelock.cpp @@ -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) { @@ -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()); @@ -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)); } diff --git a/src/nemo-devicelock/host/hostdevicelock.h b/src/nemo-devicelock/host/hostdevicelock.h index 63625fb..97c5b69 100644 --- a/src/nemo-devicelock/host/hostdevicelock.h +++ b/src/nemo-devicelock/host/hostdevicelock.h @@ -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; };