1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "content/public/browser/authenticator_request_client_delegate.h"
6 
7 #include <utility>
8 
9 #include "base/callback.h"
10 #include "base/strings/string_piece.h"
11 #include "build/build_config.h"
12 #include "device/fido/features.h"
13 #include "device/fido/fido_discovery_factory.h"
14 
15 #if defined(OS_WIN)
16 #include "device/fido/win/webauthn_api.h"
17 #endif  // defined(OS_WIN)
18 
19 namespace content {
20 
21 AuthenticatorRequestClientDelegate::AuthenticatorRequestClientDelegate() =
22     default;
23 AuthenticatorRequestClientDelegate::~AuthenticatorRequestClientDelegate() =
24     default;
25 
26 base::Optional<std::string>
MaybeGetRelyingPartyIdOverride(const std::string & claimed_relying_party_id,const url::Origin & caller_origin)27 AuthenticatorRequestClientDelegate::MaybeGetRelyingPartyIdOverride(
28     const std::string& claimed_relying_party_id,
29     const url::Origin& caller_origin) {
30   return base::nullopt;
31 }
32 
SetRelyingPartyId(const std::string &)33 void AuthenticatorRequestClientDelegate::SetRelyingPartyId(const std::string&) {
34 }
35 
DoesBlockRequestOnFailure(InterestingFailureReason reason)36 bool AuthenticatorRequestClientDelegate::DoesBlockRequestOnFailure(
37     InterestingFailureReason reason) {
38   return false;
39 }
40 
RegisterActionCallbacks(base::OnceClosure cancel_callback,base::RepeatingClosure start_over_callback,device::FidoRequestHandlerBase::RequestCallback request_callback,base::RepeatingClosure bluetooth_adapter_power_on_callback,device::FidoRequestHandlerBase::BlePairingCallback ble_pairing_callback)41 void AuthenticatorRequestClientDelegate::RegisterActionCallbacks(
42     base::OnceClosure cancel_callback,
43     base::RepeatingClosure start_over_callback,
44     device::FidoRequestHandlerBase::RequestCallback request_callback,
45     base::RepeatingClosure bluetooth_adapter_power_on_callback,
46     device::FidoRequestHandlerBase::BlePairingCallback ble_pairing_callback) {}
47 
ShouldPermitIndividualAttestation(const std::string & relying_party_id)48 bool AuthenticatorRequestClientDelegate::ShouldPermitIndividualAttestation(
49     const std::string& relying_party_id) {
50   return false;
51 }
52 
ShouldReturnAttestation(const std::string & relying_party_id,const device::FidoAuthenticator * authenticator,base::OnceCallback<void (bool)> callback)53 void AuthenticatorRequestClientDelegate::ShouldReturnAttestation(
54     const std::string& relying_party_id,
55     const device::FidoAuthenticator* authenticator,
56     base::OnceCallback<void(bool)> callback) {
57   std::move(callback).Run(true);
58 }
59 
SupportsResidentKeys()60 bool AuthenticatorRequestClientDelegate::SupportsResidentKeys() {
61   return false;
62 }
63 
SetMightCreateResidentCredential(bool v)64 void AuthenticatorRequestClientDelegate::SetMightCreateResidentCredential(
65     bool v) {}
66 
ShouldPermitCableExtension(const url::Origin & origin)67 bool AuthenticatorRequestClientDelegate::ShouldPermitCableExtension(
68     const url::Origin& origin) {
69   return false;
70 }
71 
SetCableTransportInfo(bool cable_extension_provided,bool have_paired_phones,base::Optional<device::QRGeneratorKey> qr_generator_key)72 bool AuthenticatorRequestClientDelegate::SetCableTransportInfo(
73     bool cable_extension_provided,
74     bool have_paired_phones,
75     base::Optional<device::QRGeneratorKey> qr_generator_key) {
76   return false;
77 }
78 
79 std::vector<device::CableDiscoveryData>
GetCablePairings()80 AuthenticatorRequestClientDelegate::GetCablePairings() {
81   return {};
82 }
83 
SelectAccount(std::vector<device::AuthenticatorGetAssertionResponse> responses,base::OnceCallback<void (device::AuthenticatorGetAssertionResponse)> callback)84 void AuthenticatorRequestClientDelegate::SelectAccount(
85     std::vector<device::AuthenticatorGetAssertionResponse> responses,
86     base::OnceCallback<void(device::AuthenticatorGetAssertionResponse)>
87         callback) {
88   // SupportsResidentKeys returned false so this should never be called.
89   NOTREACHED();
90 }
91 
IsFocused()92 bool AuthenticatorRequestClientDelegate::IsFocused() {
93   return true;
94 }
95 
96 #if defined(OS_MACOSX)
97 base::Optional<AuthenticatorRequestClientDelegate::TouchIdAuthenticatorConfig>
GetTouchIdAuthenticatorConfig()98 AuthenticatorRequestClientDelegate::GetTouchIdAuthenticatorConfig() {
99   return base::nullopt;
100 }
101 #endif  // defined(OS_MACOSX)
102 
103 base::Optional<bool> AuthenticatorRequestClientDelegate::
IsUserVerifyingPlatformAuthenticatorAvailableOverride()104     IsUserVerifyingPlatformAuthenticatorAvailableOverride() {
105   return base::nullopt;
106 }
107 
108 device::FidoDiscoveryFactory*
GetDiscoveryFactory()109 AuthenticatorRequestClientDelegate::GetDiscoveryFactory() {
110 #if defined(OS_ANDROID)
111   // Android uses an internal FIDO API to manage device discovery.
112   NOTREACHED();
113   return nullptr;
114 #else
115   if (!discovery_factory_) {
116     discovery_factory_ = std::make_unique<device::FidoDiscoveryFactory>();
117 #if defined(OS_MACOSX)
118     discovery_factory_->set_mac_touch_id_info(GetTouchIdAuthenticatorConfig());
119 #endif  // defined(OS_MACOSX)
120 
121 #if defined(OS_WIN)
122     if (base::FeatureList::IsEnabled(device::kWebAuthUseNativeWinApi)) {
123       discovery_factory_->set_win_webauthn_api(
124           device::WinWebAuthnApi::GetDefault());
125     }
126 #endif  // defined(OS_WIN)
127 
128     CustomizeDiscoveryFactory(discovery_factory_.get());
129   }
130   return discovery_factory_.get();
131 #endif
132 }
133 
UpdateLastTransportUsed(device::FidoTransportProtocol transport)134 void AuthenticatorRequestClientDelegate::UpdateLastTransportUsed(
135     device::FidoTransportProtocol transport) {}
136 
DisableUI()137 void AuthenticatorRequestClientDelegate::DisableUI() {}
138 
IsWebAuthnUIEnabled()139 bool AuthenticatorRequestClientDelegate::IsWebAuthnUIEnabled() {
140   return false;
141 }
142 
OnTransportAvailabilityEnumerated(device::FidoRequestHandlerBase::TransportAvailabilityInfo data)143 void AuthenticatorRequestClientDelegate::OnTransportAvailabilityEnumerated(
144     device::FidoRequestHandlerBase::TransportAvailabilityInfo data) {}
145 
EmbedderControlsAuthenticatorDispatch(const device::FidoAuthenticator & authenticator)146 bool AuthenticatorRequestClientDelegate::EmbedderControlsAuthenticatorDispatch(
147     const device::FidoAuthenticator& authenticator) {
148   return false;
149 }
150 
BluetoothAdapterPowerChanged(bool is_powered_on)151 void AuthenticatorRequestClientDelegate::BluetoothAdapterPowerChanged(
152     bool is_powered_on) {}
153 
FidoAuthenticatorAdded(const device::FidoAuthenticator & authenticator)154 void AuthenticatorRequestClientDelegate::FidoAuthenticatorAdded(
155     const device::FidoAuthenticator& authenticator) {}
156 
FidoAuthenticatorRemoved(base::StringPiece device_id)157 void AuthenticatorRequestClientDelegate::FidoAuthenticatorRemoved(
158     base::StringPiece device_id) {}
159 
FidoAuthenticatorIdChanged(base::StringPiece old_authenticator_id,std::string new_authenticator_id)160 void AuthenticatorRequestClientDelegate::FidoAuthenticatorIdChanged(
161     base::StringPiece old_authenticator_id,
162     std::string new_authenticator_id) {}
163 
FidoAuthenticatorPairingModeChanged(base::StringPiece authenticator_id,bool is_in_pairing_mode,base::string16 display_name)164 void AuthenticatorRequestClientDelegate::FidoAuthenticatorPairingModeChanged(
165     base::StringPiece authenticator_id,
166     bool is_in_pairing_mode,
167     base::string16 display_name) {}
168 
SupportsPIN() const169 bool AuthenticatorRequestClientDelegate::SupportsPIN() const {
170   return false;
171 }
172 
CollectPIN(base::Optional<int> attempts,base::OnceCallback<void (std::string)> provide_pin_cb)173 void AuthenticatorRequestClientDelegate::CollectPIN(
174     base::Optional<int> attempts,
175     base::OnceCallback<void(std::string)> provide_pin_cb) {
176   NOTREACHED();
177 }
178 
FinishCollectToken()179 void AuthenticatorRequestClientDelegate::FinishCollectToken() {
180   NOTREACHED();
181 }
182 
OnRetryUserVerification(int attempts)183 void AuthenticatorRequestClientDelegate::OnRetryUserVerification(int attempts) {
184 }
185 
OnInternalUserVerificationLocked()186 void AuthenticatorRequestClientDelegate::OnInternalUserVerificationLocked() {}
187 
CustomizeDiscoveryFactory(device::FidoDiscoveryFactory * discovery_factory)188 void AuthenticatorRequestClientDelegate::CustomizeDiscoveryFactory(
189     device::FidoDiscoveryFactory* discovery_factory) {}
190 
191 }  // namespace content
192