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 @@
#include "chrome/browser/webauthn/authenticator_request_dialog_model.h"
#include <utility>
#include "base/stl_util.h"
namespace {
......@@ -62,9 +64,9 @@ AuthenticatorTransport ToAuthenticatorTransport(
// AuthenticatorRequestDialogModel::AuthenticatorReference --------------------
AuthenticatorRequestDialogModel::AuthenticatorReference::AuthenticatorReference(
base::StringPiece device_id,
base::StringPiece authenticator_id,
device::FidoTransportProtocol transport)
: device_id(device_id), transport(transport) {}
: authenticator_id(authenticator_id), transport(transport) {}
AuthenticatorRequestDialogModel::AuthenticatorReference::AuthenticatorReference(
AuthenticatorReference&& data) = default;
AuthenticatorRequestDialogModel::AuthenticatorReference&
......@@ -133,7 +135,7 @@ void AuthenticatorRequestDialogModel::StartGuidedFlowForTransport(
SetCurrentStep(Step::kTransportSelection);
break;
case AuthenticatorTransport::kInternal:
SetCurrentStep(Step::kTouchId);
TryTouchId();
break;
case AuthenticatorTransport::kBluetoothLowEnergy:
SetCurrentStep(Step::kBleActivate);
......@@ -173,7 +175,21 @@ void AuthenticatorRequestDialogModel::TryUsbDevice() {
}
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() {
......@@ -209,3 +225,8 @@ void AuthenticatorRequestDialogModel::OnBluetoothPoweredStateChanged(
bool 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 {
~AuthenticatorReference();
std::string device_id;
std::string authenticator_id;
device::FidoTransportProtocol transport;
};
......@@ -183,6 +183,9 @@ class AuthenticatorRequestDialogModel {
// To be called when the Bluetooth adapter powered state changes.
void OnBluetoothPoweredStateChanged(bool powered);
void SetRequestCallback(
device::FidoRequestHandlerBase::RequestCallback request_callback);
std::vector<AuthenticatorReference>& saved_authenticators() {
return saved_authenticators_;
}
......@@ -202,6 +205,7 @@ class AuthenticatorRequestDialogModel {
// that the WebAuthN request for the corresponding authenticators can be
// dispatched lazily after the user interacts with the UI element.
std::vector<AuthenticatorReference> saved_authenticators_;
device::FidoRequestHandlerBase::RequestCallback request_callback_;
DISALLOW_COPY_AND_ASSIGN(AuthenticatorRequestDialogModel);
};
......
......@@ -65,9 +65,13 @@ bool IsWebAuthnUiEnabled() {
bool ShouldDispatchRequestImmediately(
const device::FidoAuthenticator& authenticator) {
// TODO(hongjunchoi): Change this so that requests for BLE and platform
// authenticators are not dispatched immediately if WebAuthN UI is enabled.
// TODO(hongjunchoi): Change this so that requests for BLE authenticators are
// not dispatched immediately if WebAuthN UI is enabled.
if (!IsWebAuthnUiEnabled())
return true;
return authenticator.AuthenticatorTransport() !=
device::FidoTransportProtocol::kInternal;
}
} // namespace
......@@ -137,6 +141,7 @@ void ChromeAuthenticatorRequestDelegate::RegisterActionCallbacks(
transient_dialog_model_holder_ =
std::make_unique<AuthenticatorRequestDialogModel>();
transient_dialog_model_holder_->SetRequestCallback(request_callback);
weak_dialog_model_ = transient_dialog_model_holder_.get();
weak_dialog_model_->AddObserver(this);
}
......@@ -279,7 +284,7 @@ void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorAdded(
}
void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorRemoved(
base::StringPiece device_id) {
base::StringPiece authenticator_id) {
if (!IsWebAuthnUiEnabled())
return;
......@@ -289,8 +294,9 @@ void ChromeAuthenticatorRequestDelegate::FidoAuthenticatorRemoved(
auto& saved_authenticators = weak_dialog_model_->saved_authenticators();
saved_authenticators.erase(
std::remove_if(saved_authenticators.begin(), saved_authenticators.end(),
[device_id](const auto& authenticator_reference) {
return authenticator_reference.device_id == device_id;
[authenticator_id](const auto& authenticator_reference) {
return authenticator_reference.authenticator_id ==
authenticator_id;
}),
saved_authenticators.end());
}
......
......@@ -81,7 +81,7 @@ class ChromeAuthenticatorRequestDelegate
device::FidoRequestHandlerBase::TransportAvailabilityInfo data) override;
void FidoAuthenticatorAdded(const device::FidoAuthenticator& authenticator,
bool* hold_off_request) override;
void FidoAuthenticatorRemoved(base::StringPiece device_id) override;
void FidoAuthenticatorRemoved(base::StringPiece authenticator_id) override;
// AuthenticatorRequestDialogModel::Observer:
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