u2f_register_operation.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_FIDO_U2F_REGISTER_OPERATION_H_
  5. #define DEVICE_FIDO_U2F_REGISTER_OPERATION_H_
  6. #include <stdint.h>
  7. #include <vector>
  8. #include "base/component_export.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "device/fido/ctap_make_credential_request.h"
  11. #include "device/fido/device_operation.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. namespace device {
  14. class FidoDevice;
  15. class AuthenticatorMakeCredentialResponse;
  16. class PublicKeyCredentialDescriptor;
  17. // Represents per device registration logic for U2F tokens. Handles regular U2F
  18. // registration as well as the logic of iterating key handles in the exclude
  19. // list and conducting U2F signs to prevent duplicate registration.
  20. // U2fRegistrationOperation is owned by MakeCredentialTask and |request_| is
  21. // also owned by MakeCredentialTask.
  22. class COMPONENT_EXPORT(DEVICE_FIDO) U2fRegisterOperation
  23. : public DeviceOperation<CtapMakeCredentialRequest,
  24. AuthenticatorMakeCredentialResponse> {
  25. public:
  26. U2fRegisterOperation(FidoDevice* device,
  27. const CtapMakeCredentialRequest& request,
  28. DeviceResponseCallback callback);
  29. U2fRegisterOperation(const U2fRegisterOperation&) = delete;
  30. U2fRegisterOperation& operator=(const U2fRegisterOperation&) = delete;
  31. ~U2fRegisterOperation() override;
  32. // DeviceOperation:
  33. void Start() override;
  34. void Cancel() override;
  35. private:
  36. using ExcludeListIterator =
  37. std::vector<PublicKeyCredentialDescriptor>::const_iterator;
  38. void WinkAndTrySign();
  39. void TrySign();
  40. void OnCheckForExcludedKeyHandle(
  41. absl::optional<std::vector<uint8_t>> device_response);
  42. void WinkAndTryRegistration();
  43. void TryRegistration();
  44. void OnRegisterResponseReceived(
  45. absl::optional<std::vector<uint8_t>> device_response);
  46. const std::vector<uint8_t>& excluded_key_handle() const;
  47. size_t current_key_handle_index_ = 0;
  48. bool canceled_ = false;
  49. // probing_alternative_rp_id_ is true if |app_id| is set in |request()| and
  50. // thus the exclude list is being probed a second time with the alternative RP
  51. // ID.
  52. bool probing_alternative_rp_id_ = false;
  53. base::WeakPtrFactory<U2fRegisterOperation> weak_factory_{this};
  54. };
  55. } // namespace device
  56. #endif // DEVICE_FIDO_U2F_REGISTER_OPERATION_H_