#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "device/fido/enclave/enclave_protocol_utils.h"
#include <array>
#include "base/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/cbor/reader.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
#include "components/device_event_log/device_event_log.h"
#include "components/sync/protocol/webauthn_credential_specifics.pb.h"
#include "crypto/random.h"
#include "device/fido/attestation_statement.h"
#include "device/fido/authenticator_data.h"
#include "device/fido/enclave/constants.h"
#include "device/fido/enclave/types.h"
#include "device/fido/fido_constants.h"
#include "device/fido/fido_parsing_utils.h"
#include "device/fido/fido_transport_protocol.h"
#include "device/fido/json_request.h"
#include "device/fido/p256_public_key.h"
#include "device/fido/public_key.h"
#include "device/fido/public_key_credential_descriptor.h"
#include "device/fido/public_key_credential_user_entity.h"
namespace device::enclave {
namespace {
constexpr std::array<uint8_t, 16> kAaguid = …;
const size_t kSyncIdSize = …;
const size_t kCredentialIdSize = …;
const char kRequestDataKey[] = …;
const char kRequestClientDataJSONKey[] = …;
const char kRequestClaimedPINKey[] = …;
const char kGetAssertionRequestProtobufKey[] = …;
const char kAddUVKeyPubKey[] = …;
const char kGetAssertionResponseKey[] = …;
const char kGetAssertionResponsePrfKey[] = …;
const char kMakeCredentialResponseEncryptedKey[] = …;
const char kMakeCredentialResponsePubKeyKey[] = …;
const char kMakeCredentialResponsePrfKey[] = …;
const char kGetAssertionCommandName[] = …;
const char kMakeCredentialCommandName[] = …;
const char kAddUVKeyCommandName[] = …;
const char kPrfFirst[] = …;
const char kPrfSecond[] = …;
const cbor::Value::MapValue* cborFindMap(const cbor::Value::MapValue& map,
std::string key) { … }
const std::vector<uint8_t>* cborFindBytestring(const cbor::Value::MapValue& map,
std::string key) { … }
cbor::Value toCbor(const base::Value& json) { … }
const char* ToString(ClientKeyType key_type) { … }
std::optional<AuthenticatorData> ReadAuthenticatorData(
const cbor::Value::MapValue& map) { … }
std::optional<AuthenticatorGetAssertionResponse>
AuthenticatorGetAssertionResponseFromValue(const cbor::Value::MapValue& map) { … }
std::optional<std::vector<uint8_t>> ParsePrfResponse(const cbor::Value& v) { … }
}
ErrorResponse::ErrorResponse(std::string error)
: … { … }
ErrorResponse::ErrorResponse(int ind, int code)
: … { … }
ErrorResponse::ErrorResponse(int ind, std::string error)
: … { … }
ErrorResponse::~ErrorResponse() = default;
ErrorResponse::ErrorResponse(ErrorResponse&) = default;
ErrorResponse::ErrorResponse(ErrorResponse&&) = default;
absl::variant<AuthenticatorGetAssertionResponse, ErrorResponse>
ParseGetAssertionResponse(cbor::Value response_value,
base::span<const uint8_t> credential_id) { … }
absl::variant<std::pair<AuthenticatorMakeCredentialResponse,
sync_pb::WebauthnCredentialSpecifics>,
ErrorResponse>
ParseMakeCredentialResponse(cbor::Value response_value,
const CtapMakeCredentialRequest& request,
int32_t wrapped_secret_version,
bool user_verified) { … }
cbor::Value BuildGetAssertionCommand(
const sync_pb::WebauthnCredentialSpecifics& passkey,
scoped_refptr<JSONRequest> request,
std::string client_data_json,
std::unique_ptr<ClaimedPIN> claimed_pin,
std::optional<std::vector<uint8_t>> wrapped_secret,
std::optional<std::vector<uint8_t>> secret) { … }
cbor::Value BuildMakeCredentialCommand(
scoped_refptr<JSONRequest> request,
std::unique_ptr<ClaimedPIN> claimed_pin,
std::optional<std::vector<uint8_t>> wrapped_secret,
std::optional<std::vector<uint8_t>> secret) { … }
cbor::Value BuildAddUVKeyCommand(base::span<const uint8_t> uv_public_key) { … }
void BuildCommandRequestBody(
cbor::Value command,
SigningCallback signing_callback,
base::span<const uint8_t, crypto::kSHA256Length> handshake_hash,
base::OnceCallback<void(std::optional<std::vector<uint8_t>>)>
complete_callback) { … }
}