fido_discovery_factory.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #ifndef DEVICE_FIDO_FIDO_DISCOVERY_FACTORY_H_
  5. #define DEVICE_FIDO_FIDO_DISCOVERY_FACTORY_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/component_export.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "build/build_config.h"
  12. #include "build/chromeos_buildflags.h"
  13. #include "device/fido/cable/cable_discovery_data.h"
  14. #include "device/fido/cable/v2_constants.h"
  15. #include "device/fido/ctap_get_assertion_request.h"
  16. #include "device/fido/fido_constants.h"
  17. #include "device/fido/fido_device_discovery.h"
  18. #include "device/fido/fido_discovery_base.h"
  19. #include "device/fido/fido_request_handler_base.h"
  20. #include "device/fido/fido_transport_protocol.h"
  21. #include "device/fido/hid/fido_hid_discovery.h"
  22. #include "mojo/public/cpp/bindings/remote.h"
  23. #include "services/device/public/mojom/usb_manager.mojom.h"
  24. #include "services/network/public/mojom/network_context.mojom-forward.h"
  25. #include "third_party/abseil-cpp/absl/types/optional.h"
  26. #if BUILDFLAG(IS_MAC)
  27. #include "device/fido/mac/authenticator_config.h"
  28. #endif // BUILDFLAG(IS_MAC)
  29. namespace device {
  30. #if BUILDFLAG(IS_WIN)
  31. class WinWebAuthnApi;
  32. #endif // BUILDFLAG(IS_WIN)
  33. // FidoDiscoveryFactory offers methods to construct instances of
  34. // FidoDiscoveryBase for a given |transport| protocol.
  35. class COMPONENT_EXPORT(DEVICE_FIDO) FidoDiscoveryFactory {
  36. public:
  37. FidoDiscoveryFactory();
  38. virtual ~FidoDiscoveryFactory();
  39. // Instantiates one or more FidoDiscoveryBases for the given transport.
  40. //
  41. // FidoTransportProtocol::kUsbHumanInterfaceDevice is not valid on Android.
  42. virtual std::vector<std::unique_ptr<FidoDiscoveryBase>> Create(
  43. FidoTransportProtocol transport);
  44. // Returns whether the current instance is an override injected by the
  45. // WebAuthn testing API.
  46. virtual bool IsTestOverride();
  47. // set_cable_data configures caBLE obtained via a WebAuthn extension.
  48. virtual void set_cable_data(
  49. FidoRequestType request_type,
  50. std::vector<CableDiscoveryData> cable_data,
  51. const absl::optional<std::array<uint8_t, cablev2::kQRKeySize>>&
  52. qr_generator_key,
  53. std::vector<std::unique_ptr<cablev2::Pairing>> v2_pairings);
  54. // set_android_accessory_params configures values necessary for discovering
  55. // Android AOA devices. The |aoa_request_description| is a string that is sent
  56. // to the device to describe the type of request and may appears in
  57. // permissions UI on the device.
  58. virtual void set_android_accessory_params(
  59. mojo::Remote<device::mojom::UsbDeviceManager>,
  60. std::string aoa_request_description);
  61. void set_network_context(network::mojom::NetworkContext*);
  62. // set_cable_pairing_callback installs a repeating callback that will be
  63. // called when a QR handshake results in a phone wishing to pair with this
  64. // browser.
  65. virtual void set_cable_pairing_callback(
  66. base::RepeatingCallback<void(std::unique_ptr<cablev2::Pairing>)>);
  67. // set_cable_invalidated_pairing_callback installs a repeating callback that
  68. // will be called when a pairing is reported to be invalid by the
  69. // tunnelserver. It is passed the index of the invalid pairing.
  70. virtual void set_cable_invalidated_pairing_callback(
  71. base::RepeatingCallback<void(size_t)>);
  72. // get_cable_contact_callback returns a callback that can be called with
  73. // indexes into the vector of pairings passed to |set_cable_data| in order
  74. // to contact the indexed device. Only a single callback is supported.
  75. virtual base::RepeatingCallback<void(size_t)> get_cable_contact_callback();
  76. void set_hid_ignore_list(base::flat_set<VidPid> hid_ignore_list);
  77. #if BUILDFLAG(IS_MAC)
  78. // Configures the Touch ID authenticator. Set to absl::nullopt to disable it.
  79. void set_mac_touch_id_info(
  80. absl::optional<fido::mac::AuthenticatorConfig> mac_touch_id_config) {
  81. mac_touch_id_config_ = std::move(mac_touch_id_config);
  82. }
  83. #endif // BUILDFLAG(IS_MAC)
  84. #if BUILDFLAG(IS_WIN)
  85. // Instantiates a FidoDiscovery for the native Windows WebAuthn API where
  86. // available. Returns nullptr otherwise.
  87. std::unique_ptr<FidoDiscoveryBase> MaybeCreateWinWebAuthnApiDiscovery();
  88. // Sets the WinWebAuthnApi instance to be used for creating the discovery for
  89. // the Windows authenticator. If none is set,
  90. // MaybeCreateWinWebAuthnApiDiscovery() returns nullptr.
  91. void set_win_webauthn_api(WinWebAuthnApi* api);
  92. WinWebAuthnApi* win_webauthn_api() const;
  93. #endif // BUILDFLAG(IS_WIN)
  94. #if BUILDFLAG(IS_CHROMEOS)
  95. // Sets a callback to generate an identifier when making DBUS requests to
  96. // u2fd.
  97. void set_generate_request_id_callback(base::RepeatingCallback<std::string()>);
  98. // Configures the ChromeOS platform authenticator discovery to instantiate an
  99. // authenticator if the legacy U2F authenticator is enabled by policy.
  100. void set_require_legacy_cros_authenticator(bool value);
  101. // Sets a CtapGetAssertionRequest on the instance for checking if a credential
  102. // exists on the enterprise policy controlled legacy U2F authenticator. If one
  103. // exists and the enterprise policy is active, an authenticator may be
  104. // instantiated even if IsUVPAA() is false (because no PIN has been set).
  105. void set_get_assertion_request_for_legacy_credential_check(
  106. CtapGetAssertionRequest request);
  107. #endif // BUILDFLAG(IS_CHROMEOS)
  108. protected:
  109. static std::vector<std::unique_ptr<FidoDiscoveryBase>> SingleDiscovery(
  110. std::unique_ptr<FidoDiscoveryBase> discovery);
  111. private:
  112. #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
  113. std::unique_ptr<FidoDiscoveryBase> MaybeCreatePlatformDiscovery() const;
  114. #endif
  115. #if BUILDFLAG(IS_MAC)
  116. absl::optional<fido::mac::AuthenticatorConfig> mac_touch_id_config_;
  117. #endif // BUILDFLAG(IS_MAC)
  118. absl::optional<mojo::Remote<device::mojom::UsbDeviceManager>>
  119. usb_device_manager_;
  120. std::string aoa_request_description_;
  121. raw_ptr<network::mojom::NetworkContext> network_context_ = nullptr;
  122. absl::optional<std::vector<CableDiscoveryData>> cable_data_;
  123. absl::optional<std::array<uint8_t, cablev2::kQRKeySize>> qr_generator_key_;
  124. absl::optional<FidoRequestType> request_type_;
  125. std::vector<std::unique_ptr<cablev2::Pairing>> v2_pairings_;
  126. std::unique_ptr<FidoDeviceDiscovery::EventStream<size_t>>
  127. contact_device_stream_;
  128. absl::optional<
  129. base::RepeatingCallback<void(std::unique_ptr<cablev2::Pairing>)>>
  130. cable_pairing_callback_;
  131. absl::optional<base::RepeatingCallback<void(size_t)>>
  132. cable_invalidated_pairing_callback_;
  133. #if BUILDFLAG(IS_WIN)
  134. raw_ptr<WinWebAuthnApi> win_webauthn_api_ = nullptr;
  135. #endif // BUILDFLAG(IS_WIN)
  136. #if BUILDFLAG(IS_CHROMEOS)
  137. base::RepeatingCallback<std::string()> generate_request_id_callback_;
  138. bool require_legacy_cros_authenticator_ = false;
  139. absl::optional<CtapGetAssertionRequest>
  140. get_assertion_request_for_legacy_credential_check_;
  141. #endif // BUILDFLAG(IS_CHROMEOS)
  142. base::flat_set<VidPid> hid_ignore_list_;
  143. };
  144. } // namespace device
  145. #endif // DEVICE_FIDO_FIDO_DISCOVERY_FACTORY_H_