#ifndef DEVICE_FIDO_CROS_AUTHENTICATOR_H_
#define DEVICE_FIDO_CROS_AUTHENTICATOR_H_
#include <string>
#include "base/component_export.h"
#include "base/containers/span.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/dbus/u2f/u2f_interface.pb.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"
#include "device/fido/authenticator_supported_options.h"
#include "device/fido/ctap_get_assertion_request.h"
#include "device/fido/ctap_make_credential_request.h"
#include "device/fido/fido_authenticator.h"
#include "device/fido/fido_transport_protocol.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace device {
class COMPONENT_EXPORT(DEVICE_FIDO) ChromeOSAuthenticator
: public FidoAuthenticator {
public:
struct COMPONENT_EXPORT(DEVICE_FIDO) Config {
bool uv_available;
bool power_button_enabled;
};
ChromeOSAuthenticator(
base::RepeatingCallback<std::string()> generate_request_id_callback,
Config config);
~ChromeOSAuthenticator() override;
static void HasLegacyU2fCredentialForGetAssertionRequest(
const CtapGetAssertionRequest& request,
base::OnceCallback<void(bool has_credential)> callback);
static void IsUVPlatformAuthenticatorAvailable(
base::OnceCallback<void(bool is_available)> callback);
static void IsPowerButtonModeEnabled(
base::OnceCallback<void(bool is_enabled)> callback);
static void IsLacrosSupported(
base::OnceCallback<void(bool supported)> callback);
void InitializeAuthenticator(base::OnceClosure callback) override;
absl::optional<base::span<const int32_t>> GetAlgorithms() override;
void MakeCredential(CtapMakeCredentialRequest request,
MakeCredentialOptions request_options,
MakeCredentialCallback callback) override;
void GetAssertion(CtapGetAssertionRequest request,
CtapGetAssertionOptions options,
GetAssertionCallback callback) override;
void GetPlatformCredentialInfoForRequest(
const CtapGetAssertionRequest& request,
const CtapGetAssertionOptions& options,
GetPlatformCredentialInfoForRequestCallback callback) override;
void Cancel() override;
AuthenticatorType GetType() const override;
std::string GetId() const override;
const AuthenticatorSupportedOptions& Options() const override;
absl::optional<FidoTransportProtocol> AuthenticatorTransport() const override;
void GetTouch(base::OnceClosure callback) override {}
base::WeakPtr<FidoAuthenticator> GetWeakPtr() override;
private:
void OnGetAlgorithmsResponse(
base::OnceClosure callback,
absl::optional<u2f::GetAlgorithmsResponse> response);
void OnIsPowerButtonModeEnabled(base::OnceClosure callback, bool enabled);
void OnHasCredentialInformationForRequest(
GetPlatformCredentialInfoForRequestCallback callback,
absl::optional<u2f::HasCredentialsResponse> response);
void OnMakeCredentialResponse(
CtapMakeCredentialRequest request,
MakeCredentialCallback callback,
absl::optional<u2f::MakeCredentialResponse> response);
void OnGetAssertionResponse(
CtapGetAssertionRequest request,
GetAssertionCallback callback,
absl::optional<u2f::GetAssertionResponse> response);
void OnCancelResponse(
absl::optional<u2f::CancelWebAuthnFlowResponse> response);
std::string current_request_id_;
base::RepeatingCallback<std::string()> generate_request_id_callback_;
const Config config_;
absl::optional<std::vector<int32_t>> supported_algorithms_;
bool u2f_enabled_ = false;
base::WeakPtrFactory<ChromeOSAuthenticator> weak_factory_;
};
}
#endif