Commit 738fec5b authored by Jun Choi's avatar Jun Choi Committed by Commit Bot

Dispatch touchId authenticator request from UI

Once UI for showing users to authenticate using Touch Id authenticator
is rendered, dispatch request to device/fido layer.

Bug: 847985
Change-Id: I9531d412e5c3f6626a6a80bb3b1b6128712c132e
Reviewed-on: https://chromium-review.googlesource.com/1177442
Commit-Queue: Jun Choi <hongjunchoi@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarMartin Kreichgauer <martinkr@google.com>
Cr-Commit-Position: refs/heads/master@{#584226}
parent dd87772c
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/webauthn/authenticator_request_dialog_model.h" #include "chrome/browser/webauthn/authenticator_request_dialog_model.h"
#include <utility>
#include "base/stl_util.h" #include "base/stl_util.h"
namespace { namespace {
...@@ -62,9 +64,9 @@ AuthenticatorTransport ToAuthenticatorTransport( ...@@ -62,9 +64,9 @@ AuthenticatorTransport ToAuthenticatorTransport(
// AuthenticatorRequestDialogModel::AuthenticatorReference -------------------- // AuthenticatorRequestDialogModel::AuthenticatorReference --------------------
AuthenticatorRequestDialogModel::AuthenticatorReference::AuthenticatorReference( AuthenticatorRequestDialogModel::AuthenticatorReference::AuthenticatorReference(
base::StringPiece device_id, base::StringPiece authenticator_id,
device::FidoTransportProtocol transport) device::FidoTransportProtocol transport)
: device_id(device_id), transport(transport) {} : authenticator_id(authenticator_id), transport(transport) {}
AuthenticatorRequestDialogModel::AuthenticatorReference::AuthenticatorReference( AuthenticatorRequestDialogModel::AuthenticatorReference::AuthenticatorReference(
AuthenticatorReference&& data) = default; AuthenticatorReference&& data) = default;
AuthenticatorRequestDialogModel::AuthenticatorReference& AuthenticatorRequestDialogModel::AuthenticatorReference&
...@@ -133,7 +135,7 @@ void AuthenticatorRequestDialogModel::StartGuidedFlowForTransport( ...@@ -133,7 +135,7 @@ void AuthenticatorRequestDialogModel::StartGuidedFlowForTransport(
SetCurrentStep(Step::kTransportSelection); SetCurrentStep(Step::kTransportSelection);
break; break;
case AuthenticatorTransport::kInternal: case AuthenticatorTransport::kInternal:
SetCurrentStep(Step::kTouchId); TryTouchId();
break; break;
case AuthenticatorTransport::kBluetoothLowEnergy: case AuthenticatorTransport::kBluetoothLowEnergy:
SetCurrentStep(Step::kBleActivate); SetCurrentStep(Step::kBleActivate);
...@@ -173,7 +175,21 @@ void AuthenticatorRequestDialogModel::TryUsbDevice() { ...@@ -173,7 +175,21 @@ void AuthenticatorRequestDialogModel::TryUsbDevice() {
} }
void AuthenticatorRequestDialogModel::TryTouchId() { void AuthenticatorRequestDialogModel::TryTouchId() {
DCHECK_EQ(current_step(), Step::kTouchId); SetCurrentStep(Step::kTouchId);
if (!request_callback_)
return;
auto touch_id_authenticator =
std::find_if(saved_authenticators_.begin(), saved_authenticators_.end(),
[](const auto& authenticator) {
return authenticator.transport ==
device::FidoTransportProtocol::kInternal;
});
if (touch_id_authenticator == saved_authenticators_.end())
return;
request_callback_.Run(touch_id_authenticator->authenticator_id);
} }
void AuthenticatorRequestDialogModel::Cancel() { void AuthenticatorRequestDialogModel::Cancel() {
...@@ -209,3 +225,8 @@ void AuthenticatorRequestDialogModel::OnBluetoothPoweredStateChanged( ...@@ -209,3 +225,8 @@ void AuthenticatorRequestDialogModel::OnBluetoothPoweredStateChanged(
bool powered) { bool powered) {
transport_availability_.is_ble_powered = powered; transport_availability_.is_ble_powered = powered;
} }
void AuthenticatorRequestDialogModel::SetRequestCallback(
device::FidoRequestHandlerBase::RequestCallback request_callback) {
request_callback_ = request_callback;
}
...@@ -70,7 +70,7 @@ class AuthenticatorRequestDialogModel { ...@@ -70,7 +70,7 @@ class AuthenticatorRequestDialogModel {
~AuthenticatorReference(); ~AuthenticatorReference();
std::string device_id; std::string authenticator_id;
device::FidoTransportProtocol transport; device::FidoTransportProtocol transport;
}; };
...@@ -183,6 +183,9 @@ class AuthenticatorRequestDialogModel { ...@@ -183,6 +183,9 @@ class AuthenticatorRequestDialogModel {
// To be called when the Bluetooth adapter powered state changes. // To be called when the Bluetooth adapter powered state changes.
void OnBluetoothPoweredStateChanged(bool powered); void OnBluetoothPoweredStateChanged(bool powered);
void SetRequestCallback(
device::FidoRequestHandlerBase::RequestCallback request_callback);
std::vector<AuthenticatorReference>& saved_authenticators() { std::vector<AuthenticatorReference>& saved_authenticators() {
return saved_authenticators_; return saved_authenticators_;
} }
...@@ -202,6 +205,7 @@ class AuthenticatorRequestDialogModel { ...@@ -202,6 +205,7 @@ class AuthenticatorRequestDialogModel {
// that the WebAuthN request for the corresponding authenticators can be // that the WebAuthN request for the corresponding authenticators can be
// dispatched lazily after the user interacts with the UI element. // dispatched lazily after the user interacts with the UI element.
std::vector<AuthenticatorReference> saved_authenticators_; std::vector<AuthenticatorReference> saved_authenticators_;
device::FidoRequestHandlerBase::RequestCallback request_callback_;
DISALLOW_COPY_AND_ASSIGN(AuthenticatorRequestDialogModel); DISALLOW_COPY_AND_ASSIGN(AuthenticatorRequestDialogModel);
}; };
......
...@@ -65,9 +65,13 @@ bool IsWebAuthnUiEnabled() { ...@@ -65,9 +65,13 @@ bool IsWebAuthnUiEnabled() {
bool ShouldDispatchRequestImmediately( bool ShouldDispatchRequestImmediately(
const device::FidoAuthenticator& authenticator) { const device::FidoAuthenticator& authenticator) {
// TODO(hongjunchoi): Change this so that requests for BLE and platform // TODO(hongjunchoi): Change this so that requests for BLE authenticators are
// authenticators are not dispatched immediately if WebAuthN UI is enabled. // not dispatched immediately if WebAuthN UI is enabled.
return true; if (!IsWebAuthnUiEnabled())
return true;
return authenticator.AuthenticatorTransport() !=
device::FidoTransportProtocol::kInternal;
} }
} // namespace } // namespace
...@@ -137,6 +141,7 @@ void ChromeAuthenticatorRequestDelegate::RegisterActionCallbacks( ...@@ -137,6 +141,7 @@ void ChromeAuthenticatorRequestDelegate::RegisterActionCallbacks(
transient_dialog_model_holder_ = transient_dialog_model_holder_ =
std::make_unique<AuthenticatorRequestDialogModel>(); std::make_unique<AuthenticatorRequestDialogModel>();
transient_dialog_model_holder_->SetRequestCallback(request_callback);
weak_dialog_model_ = transient_dialog_model_holder_.get(); weak_dialog_model_ = transient_dialog_model_holder_.get();
weak_dialog_model_->AddObserver(this); weak_dialog_model_->AddObserver(this);
} }
...@@ -279,7 +284,7 @@ void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorAdded( ...@@ -279,7 +284,7 @@ void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorAdded(
} }
void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorRemoved( void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorRemoved(
base::StringPiece device_id) { base::StringPiece authenticator_id) {
if (!IsWebAuthnUiEnabled()) if (!IsWebAuthnUiEnabled())
return; return;
...@@ -289,8 +294,9 @@ void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorRemoved( ...@@ -289,8 +294,9 @@ void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorRemoved(
auto& saved_authenticators = weak_dialog_model_->saved_authenticators(); auto& saved_authenticators = weak_dialog_model_->saved_authenticators();
saved_authenticators.erase( saved_authenticators.erase(
std::remove_if(saved_authenticators.begin(), saved_authenticators.end(), std::remove_if(saved_authenticators.begin(), saved_authenticators.end(),
[device_id](const auto& authenticator_reference) { [authenticator_id](const auto& authenticator_reference) {
return authenticator_reference.device_id == device_id; return authenticator_reference.authenticator_id ==
authenticator_id;
}), }),
saved_authenticators.end()); saved_authenticators.end());
} }
......
...@@ -81,7 +81,7 @@ class ChromeAuthenticatorRequestDelegate ...@@ -81,7 +81,7 @@ class ChromeAuthenticatorRequestDelegate
device::FidoRequestHandlerBase::TransportAvailabilityInfo data) override; device::FidoRequestHandlerBase::TransportAvailabilityInfo data) override;
void FidoAuthenticatorAdded(const device::FidoAuthenticator& authenticator, void FidoAuthenticatorAdded(const device::FidoAuthenticator& authenticator,
bool* hold_off_request) override; bool* hold_off_request) override;
void FidoAuthenticatorRemoved(base::StringPiece device_id) override; void FidoAuthenticatorRemoved(base::StringPiece authenticator_id) override;
// AuthenticatorRequestDialogModel::Observer: // AuthenticatorRequestDialogModel::Observer:
void OnModelDestroyed() override; void OnModelDestroyed() override;
......
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