#ifndef DEVICE_FIDO_CTAP_GET_ASSERTION_REQUEST_H_
#define DEVICE_FIDO_CTAP_GET_ASSERTION_REQUEST_H_
#include <stdint.h>
#include <array>
#include <optional>
#include <string>
#include <vector>
#include "base/component_export.h"
#include "base/containers/span.h"
#include "crypto/sha2.h"
#include "device/fido/cable/cable_discovery_data.h"
#include "device/fido/fido_constants.h"
#include "device/fido/json_request.h"
#include "device/fido/large_blob.h"
#include "device/fido/pin.h"
#include "device/fido/prf_input.h"
#include "device/fido/public_key_credential_descriptor.h"
#if BUILDFLAG(ARKWEB_FIDO)
#include "device/fido/ctap_get_assertion_request_extra.h"
#endif
namespace cbor {
class Value;
}
namespace device {
struct COMPONENT_EXPORT(DEVICE_FIDO) CtapGetAssertionOptions {
CtapGetAssertionOptions();
CtapGetAssertionOptions(const CtapGetAssertionOptions&);
CtapGetAssertionOptions(CtapGetAssertionOptions&&);
~CtapGetAssertionOptions();
scoped_refptr<JSONRequest> json;
std::optional<pin::TokenResponse> pin_uv_auth_token;
std::optional<pin::KeyAgreementResponse> pin_key_agreement;
std::vector<PRFInput> prf_inputs;
bool large_blob_read = false;
std::optional<std::vector<uint8_t>> large_blob_write;
bool is_off_the_record_context = false;
std::vector<FidoTransportProtocol> hints;
};
struct COMPONENT_EXPORT(DEVICE_FIDO) CtapGetAssertionRequest {
public:
using ClientDataHash = std::array<uint8_t, kClientDataHashLength>;
struct ParseOpts {
bool reject_all_extensions = false;
};
struct HMACSecret {
HMACSecret(base::span<const uint8_t, kP256X962Length> public_key_x962,
base::span<const uint8_t> encrypted_salts,
base::span<const uint8_t> salts_auth,
std::optional<PINUVAuthProtocol> pin_protocol);
HMACSecret(const HMACSecret&);
~HMACSecret();
HMACSecret& operator=(const HMACSecret&);
std::array<uint8_t, kP256X962Length> public_key_x962;
std::vector<uint8_t> encrypted_salts;
std::vector<uint8_t> salts_auth;
std::optional<PINUVAuthProtocol> pin_protocol;
};
static std::optional<CtapGetAssertionRequest> Parse(
const cbor::Value::MapValue& request_map) {
return Parse(request_map, ParseOpts());
}
static std::optional<CtapGetAssertionRequest> Parse(
const cbor::Value::MapValue& request_map,
const ParseOpts& opts);
CtapGetAssertionRequest(std::string rp_id, std::string client_data_json);
CtapGetAssertionRequest(const CtapGetAssertionRequest& that);
CtapGetAssertionRequest(CtapGetAssertionRequest&& that);
CtapGetAssertionRequest& operator=(const CtapGetAssertionRequest& other);
CtapGetAssertionRequest& operator=(CtapGetAssertionRequest&& other);
~CtapGetAssertionRequest();
void SetClientDataJson(std::string client_data_json);
std::string rp_id;
std::string client_data_json;
std::array<uint8_t, kClientDataHashLength> client_data_hash;
UserVerificationRequirement user_verification =
UserVerificationRequirement::kDiscouraged;
bool user_presence_required = true;
std::vector<PublicKeyCredentialDescriptor> allow_list;
std::optional<std::vector<uint8_t>> pin_auth;
std::optional<PINUVAuthProtocol> pin_protocol;
std::optional<std::vector<CableDiscoveryData>> cable_extension;
std::optional<std::string> app_id;
std::optional<std::array<uint8_t, crypto::kSHA256Length>>
alternative_application_parameter;
std::optional<HMACSecret> hmac_secret;
bool large_blob_key = false;
bool get_cred_blob = false;
std::vector<PRFInput> prf_inputs;
bool large_blob_extension_read = false;
std::optional<LargeBlob> large_blob_extension_write;
#if BUILDFLAG(ARKWEB_FIDO)
std::optional<CtapGetAssertionRequestExtra> extra;
#endif
};
struct CtapGetNextAssertionRequest {};
COMPONENT_EXPORT(DEVICE_FIDO)
std::pair<CtapRequestCommand, std::optional<cbor::Value>>
AsCTAPRequestValuePair(const CtapGetAssertionRequest&);
COMPONENT_EXPORT(DEVICE_FIDO)
std::pair<CtapRequestCommand, std::optional<cbor::Value>>
AsCTAPRequestValuePair(const CtapGetNextAssertionRequest&);
}
#endif