chromium/device/fido/fido_discovery_factory.cc

// Copyright 2018 The Chromium Authors
// 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/containers/contains.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/device_event_log/device_event_log.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/fido/aoa/android_accessory_discovery.h"
#include "device/fido/cable/fido_cable_discovery.h"
#include "device/fido/cable/v2_discovery.h"
#include "device/fido/enclave/enclave_discovery.h"
#include "device/fido/features.h"
#include "device/fido/fido_discovery_base.h"
#include "device/fido/hid/fido_hid_discovery.h"
#include "device/fido/mac/icloud_keychain.h"

#if BUILDFLAG(IS_WIN)
// clang-format off
// rpc.h needs to be included before winuser.h.
#include <rpc.h>
#include <Winuser.h>
//clang-format on

#include "device/fido/win/discovery.h"
#include "device/fido/win/webauthn_api.h"
#endif  // BUILDFLAG(IS_WIN)

#if BUILDFLAG(IS_MAC)
#include "base/process/process_info.h"
#include "device/fido/mac/discovery.h"
#endif  // BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_CHROMEOS)
#include "device/fido/cros/discovery.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace device {

FidoDiscoveryFactory::FidoDiscoveryFactory() = default;
FidoDiscoveryFactory::~FidoDiscoveryFactory() = default;

std::vector<std::unique_ptr<FidoDiscoveryBase>> FidoDiscoveryFactory::Create(
    FidoTransportProtocol transport) {}

std::optional<std::unique_ptr<FidoDiscoveryBase>>
FidoDiscoveryFactory::MaybeCreateEnclaveDiscovery() {}

bool FidoDiscoveryFactory::IsTestOverride() {}

void FidoDiscoveryFactory::set_cable_data(
    FidoRequestType request_type,
    std::vector<CableDiscoveryData> cable_data,
    const std::optional<std::array<uint8_t, cablev2::kQRKeySize>>&
        qr_generator_key) {}

void FidoDiscoveryFactory::set_android_accessory_params(
    mojo::Remote<device::mojom::UsbDeviceManager> usb_device_manager,
    std::string aoa_request_description) {}

void FidoDiscoveryFactory::set_cable_pairing_callback(
    base::RepeatingCallback<void(std::unique_ptr<cablev2::Pairing>)> callback) {}

void FidoDiscoveryFactory::set_cable_invalidated_pairing_callback(
    base::RepeatingCallback<void(std::unique_ptr<cablev2::Pairing>)> callback) {}

void FidoDiscoveryFactory::set_cable_event_callback(
    base::RepeatingCallback<void(cablev2::Event)> callback) {}

base::RepeatingCallback<void(std::unique_ptr<cablev2::Pairing>)>
FidoDiscoveryFactory::get_cable_contact_callback() {}

void FidoDiscoveryFactory::set_hid_ignore_list(
    base::flat_set<VidPid> hid_ignore_list) {}

void FidoDiscoveryFactory::set_enclave_ui_request_stream(
    std::unique_ptr<FidoDiscoveryBase::EventStream<
        std::unique_ptr<enclave::CredentialRequest>>> stream) {}

// static
std::vector<std::unique_ptr<FidoDiscoveryBase>>
FidoDiscoveryFactory::SingleDiscovery(
    std::unique_ptr<FidoDiscoveryBase> discovery) {}

#if BUILDFLAG(IS_WIN)
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.
  WinWebAuthnApi* const api = WinWebAuthnApi::GetDefault();
  return api && api->IsAvailable()
             ? std::make_unique<WinWebAuthnApiAuthenticatorDiscovery>(
                   GetForegroundWindow(), api)
             : nullptr;
}
#endif  // BUILDFLAG(IS_WIN)

#if BUILDFLAG(IS_MAC)
std::vector<std::unique_ptr<FidoDiscoveryBase>>
FidoDiscoveryFactory::MaybeCreatePlatformDiscovery() const {
  std::vector<std::unique_ptr<FidoDiscoveryBase>> ret;
  if (mac_touch_id_config_) {
    ret.emplace_back(std::make_unique<fido::mac::FidoTouchIdDiscovery>(
        *mac_touch_id_config_));
  }
  if (fido::icloud_keychain::IsSupported() && nswindow_ != 0) {
    ret.emplace_back(fido::icloud_keychain::NewDiscovery(nswindow_));
  }
  return ret;
}
#endif

#if BUILDFLAG(IS_CHROMEOS)
std::vector<std::unique_ptr<FidoDiscoveryBase>>
FidoDiscoveryFactory::MaybeCreatePlatformDiscovery() const {
  auto discovery = std::make_unique<FidoChromeOSDiscovery>(
      generate_request_id_callback_,
      std::move(get_assertion_request_for_legacy_credential_check_));
  discovery->set_require_power_button_mode(require_legacy_cros_authenticator_);
  return SingleDiscovery(std::move(discovery));
}

void FidoDiscoveryFactory::set_generate_request_id_callback(
    base::RepeatingCallback<std::string()> callback) {
  generate_request_id_callback_ = std::move(callback);
}

void FidoDiscoveryFactory::set_require_legacy_cros_authenticator(bool value) {
  require_legacy_cros_authenticator_ = value;
}

void FidoDiscoveryFactory::
    set_get_assertion_request_for_legacy_credential_check(
        CtapGetAssertionRequest request) {
  get_assertion_request_for_legacy_credential_check_ = std::move(request);
}
#endif

}  // namespace device