u2f_sign_operation.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_SIGN_OPERATION_H_
  5. #define DEVICE_FIDO_U2F_SIGN_OPERATION_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "base/component_export.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "device/fido/ctap_get_assertion_request.h"
  13. #include "device/fido/device_operation.h"
  14. #include "device/fido/fido_constants.h"
  15. #include "third_party/abseil-cpp/absl/types/optional.h"
  16. namespace device {
  17. class FidoDevice;
  18. class AuthenticatorGetAssertionResponse;
  19. // Represents per device authentication logic for U2F tokens. Handles iterating
  20. // through credentials in the allowed list.
  21. // https://fidoalliance.org/specs/fido-v2.0-rd-20170927/fido-client-to-authenticator-protocol-v2.0-rd-20170927.html#using-the-ctap2-authenticatorgetassertion-command-with-ctap1-u2f-authenticators
  22. class COMPONENT_EXPORT(DEVICE_FIDO) U2fSignOperation
  23. : public DeviceOperation<CtapGetAssertionRequest,
  24. AuthenticatorGetAssertionResponse> {
  25. public:
  26. U2fSignOperation(FidoDevice* device,
  27. const CtapGetAssertionRequest& request,
  28. DeviceResponseCallback callback);
  29. U2fSignOperation(const U2fSignOperation&) = delete;
  30. U2fSignOperation& operator=(const U2fSignOperation&) = delete;
  31. ~U2fSignOperation() override;
  32. // DeviceOperation:
  33. void Start() override;
  34. void Cancel() override;
  35. private:
  36. void WinkAndTrySign();
  37. void TrySign();
  38. void OnSignResponseReceived(
  39. absl::optional<std::vector<uint8_t>> device_response);
  40. void WinkAndTryFakeEnrollment();
  41. void TryFakeEnrollment();
  42. void OnEnrollmentResponseReceived(
  43. absl::optional<std::vector<uint8_t>> device_response);
  44. const std::vector<uint8_t>& key_handle() const;
  45. size_t current_key_handle_index_ = 0;
  46. // app_param_type_ identifies whether we're currently trying the RP ID (the
  47. // primary value) or an RP-provided U2F AppID.
  48. ApplicationParameterType app_param_type_ = ApplicationParameterType::kPrimary;
  49. bool canceled_ = false;
  50. base::WeakPtrFactory<U2fSignOperation> weak_factory_{this};
  51. };
  52. } // namespace device
  53. #endif // DEVICE_FIDO_U2F_SIGN_OPERATION_H_