forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfido_discovery_factory.cc
134 lines (114 loc) · 4.26 KB
/
fido_discovery_factory.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/fido/fido_discovery_factory.h"
#include "base/notreached.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/fido/cable/fido_cable_discovery.h"
#include "device/fido/features.h"
#include "device/fido/fido_discovery_base.h"
// HID is not supported on Android.
#if !defined(OS_ANDROID)
#include "device/fido/hid/fido_hid_discovery.h"
#endif // !defined(OS_ANDROID)
#if defined(OS_WIN)
#include <Winuser.h>
#include "device/fido/win/discovery.h"
#include "device/fido/win/webauthn_api.h"
#endif // defined(OS_WIN)
#if defined(OS_MACOSX)
#include "device/fido/mac/discovery.h"
#endif // defined(OSMACOSX)
#if defined(OS_CHROMEOS)
#include "device/fido/cros/discovery.h"
#endif // defined(OS_CHROMEOS)
namespace device {
namespace {
std::unique_ptr<FidoDiscoveryBase> CreateUsbFidoDiscovery() {
#if defined(OS_ANDROID)
NOTREACHED() << "USB HID not supported on Android.";
return nullptr;
#else
return std::make_unique<FidoHidDiscovery>();
#endif // !defined(OS_ANDROID)
}
} // namespace
FidoDiscoveryFactory::FidoDiscoveryFactory() = default;
FidoDiscoveryFactory::~FidoDiscoveryFactory() = default;
std::unique_ptr<FidoDiscoveryBase> FidoDiscoveryFactory::Create(
FidoTransportProtocol transport) {
switch (transport) {
case FidoTransportProtocol::kUsbHumanInterfaceDevice:
return CreateUsbFidoDiscovery();
case FidoTransportProtocol::kBluetoothLowEnergy:
return nullptr;
case FidoTransportProtocol::kCloudAssistedBluetoothLowEnergy:
if (device::BluetoothAdapterFactory::Get()->IsLowEnergySupported() &&
(cable_data_.has_value() || qr_generator_key_.has_value())) {
return std::make_unique<FidoCableDiscovery>(
cable_data_.value_or(std::vector<CableDiscoveryData>()),
qr_generator_key_, cable_pairing_callback_);
}
return nullptr;
case FidoTransportProtocol::kNearFieldCommunication:
// TODO(https://crbug.com/825949): Add NFC support.
return nullptr;
case FidoTransportProtocol::kInternal:
#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
return MaybeCreatePlatformDiscovery();
#else
return nullptr;
#endif
}
NOTREACHED() << "Unhandled transport type";
return nullptr;
}
void FidoDiscoveryFactory::set_cable_data(
std::vector<CableDiscoveryData> cable_data,
base::Optional<QRGeneratorKey> qr_generator_key) {
cable_data_ = std::move(cable_data);
qr_generator_key_ = std::move(qr_generator_key);
}
void FidoDiscoveryFactory::set_cable_pairing_callback(
base::RepeatingCallback<void(std::unique_ptr<CableDiscoveryData>)>
pairing_callback) {
cable_pairing_callback_.emplace(std::move(pairing_callback));
}
#if defined(OS_WIN)
void FidoDiscoveryFactory::set_win_webauthn_api(WinWebAuthnApi* api) {
win_webauthn_api_ = api;
}
WinWebAuthnApi* FidoDiscoveryFactory::win_webauthn_api() const {
return win_webauthn_api_;
}
std::unique_ptr<FidoDiscoveryBase>
FidoDiscoveryFactory::MaybeCreateWinWebAuthnApiDiscovery() {
// TODO(martinkr): Inject the window from which the request originated.
// Windows uses this parameter to center the dialog over the parent. The
// dialog should be centered over the originating Chrome Window; the
// foreground window may have changed to something else since the request
// was issued.
return win_webauthn_api_ && win_webauthn_api_->IsAvailable()
? std::make_unique<WinWebAuthnApiAuthenticatorDiscovery>(
GetForegroundWindow(), win_webauthn_api_)
: nullptr;
}
#endif // defined(OS_WIN)
#if defined(OS_MACOSX)
std::unique_ptr<FidoDiscoveryBase>
FidoDiscoveryFactory::MaybeCreatePlatformDiscovery() const {
return mac_touch_id_config_
? std::make_unique<fido::mac::FidoTouchIdDiscovery>(
*mac_touch_id_config_)
: nullptr;
}
#endif
#if defined(OS_CHROMEOS)
std::unique_ptr<FidoDiscoveryBase>
FidoDiscoveryFactory::MaybeCreatePlatformDiscovery() const {
return base::FeatureList::IsEnabled(kWebAuthCrosPlatformAuthenticator)
? std::make_unique<FidoChromeOSDiscovery>()
: nullptr;
}
#endif
} // namespace device