#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/devtools/protocol/webauthn_handler.h"
#include <map>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/string_number_conversions.h"
#include "content/browser/devtools/protocol/web_authn.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/webauth/authenticator_environment.h"
#include "content/browser/webauth/virtual_authenticator.h"
#include "content/browser/webauth/virtual_authenticator_manager_impl.h"
#include "device/fido/fido_constants.h"
#include "device/fido/fido_transport_protocol.h"
#include "device/fido/virtual_fido_device.h"
#include "device/fido/virtual_u2f_device.h"
namespace content::protocol {
namespace {
static constexpr char kAuthenticatorNotFound[] = …;
static constexpr char kCableNotSupportedOnU2f[] = …;
static constexpr char kCouldNotCreateCredential[] = …;
static constexpr char kCouldNotStoreLargeBlob[] = …;
static constexpr char kCredentialNotFound[] = …;
static constexpr char kDevToolsNotAttached[] = …;
static constexpr char kErrorCreatingAuthenticator[] = …;
static constexpr char kHandleRequiredForResidentCredential[] = …;
static constexpr char kInvalidCtapVersion[] = …;
static constexpr char kInvalidProtocol[] = …;
static constexpr char kInvalidTransport[] = …;
static constexpr char kInvalidUserHandle[] = …;
static constexpr char kLargeBlobRequiresResidentKey[] = …;
static constexpr char kRequiresCtap2_1[] = …;
static constexpr char kResidentCredentialNotSupported[] = …;
static constexpr char kRpIdRequired[] = …;
static constexpr char kVirtualEnvironmentNotEnabled[] = …;
class GetCredentialCallbackAggregator
: public base::RefCounted<GetCredentialCallbackAggregator> { … };
device::ProtocolVersion ConvertToProtocolVersion(std::string_view protocol) { … }
std::optional<device::Ctap2Version> ConvertToCtap2Version(
std::string_view version) { … }
std::vector<uint8_t> CopyBinaryToVector(const Binary& binary) { … }
std::unique_ptr<WebAuthn::Credential> BuildCredentialFromRegistration(
base::span<const uint8_t> id,
const device::VirtualFidoDevice::RegistrationData* registration) { … }
}
WebAuthnHandler::WebAuthnHandler()
: … { … }
WebAuthnHandler::~WebAuthnHandler() = default;
void WebAuthnHandler::SetRenderer(int process_host_id,
RenderFrameHostImpl* frame_host) { … }
void WebAuthnHandler::Wire(UberDispatcher* dispatcher) { … }
Response WebAuthnHandler::Enable(Maybe<bool> enable_ui) { … }
Response WebAuthnHandler::Disable() { … }
Response WebAuthnHandler::AddVirtualAuthenticator(
std::unique_ptr<WebAuthn::VirtualAuthenticatorOptions> options,
String* out_authenticator_id) { … }
Response WebAuthnHandler::RemoveVirtualAuthenticator(
const String& authenticator_id) { … }
Response WebAuthnHandler::SetResponseOverrideBits(
const String& authenticator_id,
Maybe<bool> is_bogus_signature,
Maybe<bool> is_bad_uv,
Maybe<bool> is_bad_up) { … }
void WebAuthnHandler::AddCredential(
const String& authenticator_id,
std::unique_ptr<WebAuthn::Credential> credential,
std::unique_ptr<AddCredentialCallback> callback) { … }
void WebAuthnHandler::GetCredential(
const String& authenticator_id,
const Binary& credential_id,
std::unique_ptr<GetCredentialCallback> callback) { … }
void WebAuthnHandler::GetCredentials(
const String& authenticator_id,
std::unique_ptr<GetCredentialsCallback> callback) { … }
Response WebAuthnHandler::RemoveCredential(const String& authenticator_id,
const Binary& credential_id) { … }
Response WebAuthnHandler::ClearCredentials(const String& authenticator_id) { … }
Response WebAuthnHandler::SetUserVerified(const String& authenticator_id,
bool is_user_verified) { … }
Response WebAuthnHandler::SetAutomaticPresenceSimulation(
const String& authenticator_id,
bool enabled) { … }
Response WebAuthnHandler::SetCredentialProperties(
const String& authenticator_id,
const Binary& in_credential_id,
Maybe<bool> backup_eligibility,
Maybe<bool> backup_state) { … }
Response WebAuthnHandler::FindAuthenticator(
const String& id,
VirtualAuthenticator** out_authenticator) { … }
void WebAuthnHandler::OnCredentialCreated(
VirtualAuthenticator* authenticator,
const device::VirtualFidoDevice::Credential& credential) { … }
void WebAuthnHandler::OnAssertion(
VirtualAuthenticator* authenticator,
const device::VirtualFidoDevice::Credential& credential) { … }
void WebAuthnHandler::OnAuthenticatorWillBeDestroyed(
VirtualAuthenticator* authenticator) { … }
}