blob: acd712590b64b49762e21f797eb5d41fe56e7af6 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_U2F_U2F_REGISTER_H_
#define DEVICE_U2F_U2F_REGISTER_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/containers/flat_set.h"
#include "base/optional.h"
#include "device/u2f/u2f_request.h"
#include "device/u2f/u2f_transport_protocol.h"
namespace service_manager {
class Connector;
};
namespace device {
class RegisterResponseData;
class U2fRegister : public U2fRequest {
public:
using RegisterResponseCallback = base::OnceCallback<void(
U2fReturnCode status_code,
base::Optional<RegisterResponseData> response_data)>;
U2fRegister(std::string relying_party_id,
service_manager::Connector* connector,
const base::flat_set<U2fTransportProtocol>& protocols,
const std::vector<std::vector<uint8_t>>& registered_keys,
const std::vector<uint8_t>& challenge_hash,
const std::vector<uint8_t>& app_param,
bool individual_attestation_ok,
RegisterResponseCallback completion_callback);
~U2fRegister() override;
static std::unique_ptr<U2fRequest> TryRegistration(
std::string relying_party_id,
service_manager::Connector* connector,
const base::flat_set<U2fTransportProtocol>& protocols,
const std::vector<std::vector<uint8_t>>& registered_keys,
const std::vector<uint8_t>& challenge_hash,
const std::vector<uint8_t>& app_param,
bool individual_attestation_ok,
RegisterResponseCallback completion_callback);
private:
void TryDevice() override;
void OnTryDevice(bool is_duplicate_registration,
U2fReturnCode return_code,
const std::vector<uint8_t>& response_data);
// Callback function called when non-empty exclude list was provided. This
// function iterates through all key handles in |registered_keys_| for all
// devices and checks for already registered keys.
void OnTryCheckRegistration(
std::vector<std::vector<uint8_t>>::const_iterator it,
U2fReturnCode return_code,
const std::vector<uint8_t>& response_data);
// Function handling registration flow after all devices were checked for
// already registered keys.
void CompleteNewDeviceRegistration();
// Returns whether |current_device_| has been checked for duplicate
// registration for all key handles provided in |registered_keys_|.
bool CheckedForDuplicateRegistration();
const std::vector<std::vector<uint8_t>> registered_keys_;
std::vector<uint8_t> challenge_hash_;
std::vector<uint8_t> app_param_;
// Indicates whether the token should be signaled that using an individual
// attestation certificate is acceptable.
const bool individual_attestation_ok_;
RegisterResponseCallback completion_callback_;
// List of authenticators that did not create any of the key handles in the
// exclude list.
std::set<std::string> checked_device_id_list_;
base::WeakPtrFactory<U2fRegister> weak_factory_;
};
} // namespace device
#endif // DEVICE_U2F_U2F_REGISTER_H_