Commit 502d7a8b authored by Fabian Sommer's avatar Fabian Sommer Committed by Commit Bot

Fix incorrect error when cancelling pin request

Previously, the UI could not distinguish between a failed log in attempt
and the user cancelling the attempt. By saving that the user cancelled
the request, we suppress the error that would otherwise be displayed.

Fixed: 1045029
Change-Id: I758d2934db7da7206d13b6036c0723677ada33ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2017351
Commit-Queue: Fabian Sommer <fabiansommer@google.com>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738164}
parent 271b570b
...@@ -207,6 +207,15 @@ bool LoginScreenController::ValidateParentAccessCode( ...@@ -207,6 +207,15 @@ bool LoginScreenController::ValidateParentAccessCode(
return client_->ValidateParentAccessCode(account_id, code, validation_time); return client_->ValidateParentAccessCode(account_id, code, validation_time);
} }
void LoginScreenController::OnSecurityTokenPinRequestCancelledByUser() {
security_token_pin_request_cancelled_ = true;
std::move(on_request_security_token_ui_closed_).Run();
}
bool LoginScreenController::GetSecurityTokenPinRequestCancelled() const {
return security_token_pin_request_cancelled_;
}
void LoginScreenController::HardlockPod(const AccountId& account_id) { void LoginScreenController::HardlockPod(const AccountId& account_id) {
if (!client_) if (!client_)
return; return;
...@@ -397,13 +406,24 @@ LoginScreenController::GetScopedGuestButtonBlocker() { ...@@ -397,13 +406,24 @@ LoginScreenController::GetScopedGuestButtonBlocker() {
void LoginScreenController::RequestSecurityTokenPin( void LoginScreenController::RequestSecurityTokenPin(
SecurityTokenPinRequest request) { SecurityTokenPinRequest request) {
if (!LockScreen::HasInstance()) { if (LockScreen::HasInstance() && !security_token_pin_request_cancelled_) {
// Corner case: the PIN request is made at inappropriate time, racing with // The caller must ensure that there is no unresolved pin request currently
// the lock screen showing/hiding. // in progress.
on_request_security_token_ui_closed_ =
std::move(request.pin_ui_closed_callback);
// base::Unretained(this) could lead to errors if this controller is
// destroyed before the callback happens. This will be fixed by
// crbug.com/1001288 by using a UI owned by the controller.
request.pin_ui_closed_callback = base::BindOnce(
&LoginScreenController::OnSecurityTokenPinRequestCancelledByUser,
base::Unretained(this));
LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
} else {
// The user closed the PIN UI on a previous request that was part of the
// same smart card login attempt, or the PIN request is made at an
// inappropriate time, racing with the lock screen showing/hiding.
std::move(request.pin_ui_closed_callback).Run(); std::move(request.pin_ui_closed_callback).Run();
return;
} }
LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
} }
void LoginScreenController::ClearSecurityTokenPinRequest() { void LoginScreenController::ClearSecurityTokenPinRequest() {
...@@ -477,6 +497,8 @@ void LoginScreenController::OnAuthenticateComplete( ...@@ -477,6 +497,8 @@ void LoginScreenController::OnAuthenticateComplete(
bool success) { bool success) {
authentication_stage_ = AuthenticationStage::kUserCallback; authentication_stage_ = AuthenticationStage::kUserCallback;
std::move(callback).Run(base::make_optional<bool>(success)); std::move(callback).Run(base::make_optional<bool>(success));
security_token_pin_request_cancelled_ = false;
on_request_security_token_ui_closed_.Reset();
authentication_stage_ = AuthenticationStage::kIdle; authentication_stage_ = AuthenticationStage::kIdle;
} }
......
...@@ -73,6 +73,8 @@ class ASH_EXPORT LoginScreenController : public LoginScreen, ...@@ -73,6 +73,8 @@ class ASH_EXPORT LoginScreenController : public LoginScreen,
bool ValidateParentAccessCode(const AccountId& account_id, bool ValidateParentAccessCode(const AccountId& account_id,
const std::string& code, const std::string& code,
base::Time validation_time); base::Time validation_time);
void OnSecurityTokenPinRequestCancelledByUser();
bool GetSecurityTokenPinRequestCancelled() const;
void HardlockPod(const AccountId& account_id); void HardlockPod(const AccountId& account_id);
void OnFocusPod(const AccountId& account_id); void OnFocusPod(const AccountId& account_id);
void OnNoPodFocused(); void OnNoPodFocused();
...@@ -159,6 +161,12 @@ class ASH_EXPORT LoginScreenController : public LoginScreen, ...@@ -159,6 +161,12 @@ class ASH_EXPORT LoginScreenController : public LoginScreen,
// If set to false, all auth requests will forcibly fail. // If set to false, all auth requests will forcibly fail.
ForceFailAuth force_fail_auth_for_debug_overlay_ = ForceFailAuth::kOff; ForceFailAuth force_fail_auth_for_debug_overlay_ = ForceFailAuth::kOff;
// Original OnUiClosed callback of a pending security token pin request.
// Invoked by OnSecurityTokenPinRequestCancelledByUser.
SecurityTokenPinRequest::OnUiClosed on_request_security_token_ui_closed_;
bool security_token_pin_request_cancelled_ = false;
base::WeakPtrFactory<LoginScreenController> weak_factory_{this}; base::WeakPtrFactory<LoginScreenController> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(LoginScreenController); DISALLOW_COPY_AND_ASSIGN(LoginScreenController);
......
...@@ -1314,7 +1314,18 @@ void LoginAuthUserView::OnChallengeResponseAuthComplete( ...@@ -1314,7 +1314,18 @@ void LoginAuthUserView::OnChallengeResponseAuthComplete(
if (!auth_success.has_value() || !auth_success.value()) { if (!auth_success.has_value() || !auth_success.value()) {
password_view_->Clear(); password_view_->Clear();
password_view_->SetReadOnly(false); password_view_->SetReadOnly(false);
challenge_response_view_->SetState(ChallengeResponseView::State::kFailure); // If the user cancelled the PIN request during ChallengeResponse,
// ChallengeResponse will fail with an unknown error. Since this is
// expected, we do not show this error.
if (Shell::Get()
->login_screen_controller()
->GetSecurityTokenPinRequestCancelled()) {
challenge_response_view_->SetState(
ChallengeResponseView::State::kInitial);
} else {
challenge_response_view_->SetState(
ChallengeResponseView::State::kFailure);
}
} }
on_auth_.Run(auth_success.value_or(false), /*display_error_messages=*/false); on_auth_.Run(auth_success.value_or(false), /*display_error_messages=*/false);
......
...@@ -345,7 +345,8 @@ struct ASH_PUBLIC_EXPORT SecurityTokenPinRequest { ...@@ -345,7 +345,8 @@ struct ASH_PUBLIC_EXPORT SecurityTokenPinRequest {
// Called when the PIN request UI gets closed. Will not be called when the // Called when the PIN request UI gets closed. Will not be called when the
// browser itself requests the UI to be closed. // browser itself requests the UI to be closed.
base::OnceClosure pin_ui_closed_callback; using OnUiClosed = base::OnceClosure;
OnUiClosed pin_ui_closed_callback;
}; };
} // namespace ash } // namespace ash
......
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